home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / udos / fgrep103 / moveresi.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-28  |  1.5 KB  |  49 lines

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