home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MEMOLIN2.ZIP / MEMOLINE.C next >
Encoding:
C/C++ Source or Header  |  1988-03-06  |  2.6 KB  |  69 lines

  1. /* 
  2.  *  Program :MEMOLINE.C 
  3.  *  Syntax: ?? MEMOLINE(MemoField,StartLine,NumberOfLines)
  4. */
  5.  
  6.  
  7. /* various defines and external declarations from extend.h,
  8.    a program file distributed on your Clipper disks */
  9.  
  10. #include "nandef.h"
  11. #include "extend.h"
  12.  
  13. #define HARD_CR '\r'
  14. #define SOFT_CR ('\r' | 0x80)
  15. #define LINE_FEED '\n'
  16.  
  17. CLIPPER MEMOLINE()
  18. {
  19.   /* initialize local memvars and functions */
  20.   char *pos1;                   /* position in the source memo */
  21.   char *pos2;                   /* position in the target memo */
  22.   char *str2;                   /* pointer to the target memo */
  23.   unsigned size2;               /* size of source memo */
  24.   unsigned startline;           /* passed starting line number */
  25.   unsigned numoflines;          /* passed number of lines */
  26.   unsigned currentline;         /* keeps track of the current line number */
  27.  
  28.   /* check passed parameters */
  29.   if (PCOUNT >= 3 && ISCHAR(1) && ISNUM(2) && ISNUM(3))
  30.   {
  31.     pos1 = _parc(1);            /* get position in source memo */
  32.     size2 = strlen(pos1) + 1;   /* calculate size of source memo + 1 */
  33.     str2 = _exmgrab(size2);     /* allocate memory for target memo */
  34.     pos2 = str2;                /* position in target memo */
  35.     currentline = 1;            /* initialize line counter */
  36.     startline = _parni(2);      /* get passed start line */
  37.     numoflines = _parni(3);     /* get passed number of lines */
  38.  
  39.     /* skip to specified starting line in the memo */
  40.     while ((currentline < startline) && (*pos1))
  41.     {
  42.       if (*pos1 == LINE_FEED)   /* check for a line feed */
  43.          currentline++;         /* bump line counter if found */
  44.       *pos1++;                  /* bump source pointer */
  45.     }  
  46.  
  47.     /* build target memo field from the current line on */
  48.     while (((currentline - startline) < numoflines) && (*pos1))
  49.     {
  50.       *pos2 = *pos1;            /* add character to target */
  51.       if (*pos2 == LINE_FEED)   /* check for a line feed */
  52.          currentline++;         /* bump line counter if found */
  53.       if (*pos2 == SOFT_CR)     /* check for soft cr */
  54.          *pos2 = HARD_CR;       /* replace with hard cr */
  55.       *pos1++;                  /* bump source pointer */
  56.       *pos2++;                  /* bump target pointer */
  57.     }
  58.  
  59.     *pos2 = '\0';               /* terminate target memo by adding a null */
  60.     _retc(str2);                /* return it to Clipper */
  61.     _exmback(str2,size2);       /* release target memo memory */
  62.   }
  63.   else
  64.     _retc("");                  /* error, return null */
  65. }
  66.  
  67. /* EOF:MEMOLINE.C */
  68. 
  69.