home *** CD-ROM | disk | FTP | other *** search
- /*
- * Program :MEMOLINE.C
- * Syntax: ?? MEMOLINE(MemoField,StartLine,NumberOfLines)
- */
-
-
- /* various defines and external declarations from extend.h,
- a program file distributed on your Clipper disks */
-
- #include "nandef.h"
- #include "extend.h"
-
- #define HARD_CR '\r'
- #define SOFT_CR ('\r' | 0x80)
- #define LINE_FEED '\n'
-
- CLIPPER MEMOLINE()
- {
- /* initialize local memvars and functions */
- char *pos1; /* position in the source memo */
- char *pos2; /* position in the target memo */
- char *str2; /* pointer to the target memo */
- unsigned size2; /* size of source memo */
- unsigned startline; /* passed starting line number */
- unsigned numoflines; /* passed number of lines */
- unsigned currentline; /* keeps track of the current line number */
-
- /* check passed parameters */
- if (PCOUNT >= 3 && ISCHAR(1) && ISNUM(2) && ISNUM(3))
- {
- pos1 = _parc(1); /* get position in source memo */
- size2 = strlen(pos1) + 1; /* calculate size of source memo + 1 */
- str2 = _exmgrab(size2); /* allocate memory for target memo */
- pos2 = str2; /* position in target memo */
- currentline = 1; /* initialize line counter */
- startline = _parni(2); /* get passed start line */
- numoflines = _parni(3); /* get passed number of lines */
-
- /* skip to specified starting line in the memo */
- while ((currentline < startline) && (*pos1))
- {
- if (*pos1 == LINE_FEED) /* check for a line feed */
- currentline++; /* bump line counter if found */
- *pos1++; /* bump source pointer */
- }
-
- /* build target memo field from the current line on */
- while (((currentline - startline) < numoflines) && (*pos1))
- {
- *pos2 = *pos1; /* add character to target */
- if (*pos2 == LINE_FEED) /* check for a line feed */
- currentline++; /* bump line counter if found */
- if (*pos2 == SOFT_CR) /* check for soft cr */
- *pos2 = HARD_CR; /* replace with hard cr */
- *pos1++; /* bump source pointer */
- *pos2++; /* bump target pointer */
- }
-
- *pos2 = '\0'; /* terminate target memo by adding a null */
- _retc(str2); /* return it to Clipper */
- _exmback(str2,size2); /* release target memo memory */
- }
- else
- _retc(""); /* error, return null */
- }
-
- /* EOF:MEMOLINE.C */