home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / match1.2 / MoveResidue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.3 KB  |  48 lines

  1. #include "match.h"
  2. /* Moves the text which has not been completely searched at the end of
  3. * the buffer to the beginning of the buffer
  4. * and returns number of bytes moved */
  5. int MoveResidue(DescVec, NPats,Buffer, BuffEnd)
  6. register struct PattDesc **DescVec;
  7. int NPats;
  8. char *Buffer, *BuffEnd;
  9. {
  10.     char *FirstStart;
  11.     register char *Residue;
  12.     /* use this declaration if you don't use "bcopy" */
  13.     register char *f, *t;
  14.     register int i;
  15.     int ResSize;
  16.  
  17.     FirstStart = BuffEnd;
  18.     /* find the earliest point which has not been
  19.     * completely searched */
  20.     for (i=0; i < NPats; i++) {
  21.         FirstStart = 
  22.             min(FirstStart, DescVec[i]-> Start );
  23.     } /* for */
  24.     /* now scan to the beginning of the line containing the
  25.     * unsearched text */
  26.     for (Residue = FirstStart; *Residue != '\n' &&
  27.     Residue >= Buffer; Residue--);
  28.     if (Residue < Buffer)
  29.         Residue = FirstStart;
  30.     else ++Residue;
  31.     /* now move the residue to the beginning of
  32.     * the file */
  33.     ResSize = BuffEnd - Residue + 1;
  34.     /* use this if you don't have "bcopy" */
  35.     t = Buffer; f = Residue;
  36. #ifdef BCOPY
  37.     bcopy(Residue, Buffer, ResSize);
  38. #else
  39.     for(i=ResSize;i;--i)
  40.         *t++ = *f++;
  41. #endif
  42.     /* now fix the status vectors */
  43.     for (i=0; i < NPats; i++) {
  44.         DescVec[i]->Start -= (Residue - Buffer);
  45.     } /* for */
  46.     return(ResSize);
  47. } /* MoveResidue */
  48.