MoveResidue.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "bm.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. struct PattDesc *DescVec[];
  7. int NPats;
  8. char *Buffer, *BuffEnd;
  9. {
  10. char *FirstStart, *Residue;
  11. /* use this declaration if you don't use "bcopy" */
  12. register char *f, *t;
  13. int ResSize, i;
  14. FirstStart = BuffEnd;
  15. /* find the earliest point which has not been
  16. * completely searched */
  17. for (i=0; i < NPats; i++) {
  18. FirstStart =
  19. min(FirstStart, DescVec[i]-> Start );
  20. } /* for */
  21. /* now scan to the beginning of the line containing the
  22. * unsearched text */
  23. for (Residue = FirstStart; *Residue != '\n' &&
  24. Residue >= Buffer; Residue--);
  25. if (Residue < Buffer)
  26. Residue = FirstStart;
  27. else ++Residue;
  28. ResSize = (BuffEnd - Residue + 1);
  29. /* now move the residue to the beginning of
  30. * the file */
  31. /* use this if you don't have "bcopy" */
  32. t = Buffer; f = Residue;
  33. for(i=ResSize;i;--i)
  34. *t++ = *f++;
  35. /* use this if you do have "bcopy"
  36. bcopy(Residue, Buffer, ResSize);
  37. */
  38. /* now fix the status vectors */
  39. for (i=0; i < NPats; i++) {
  40. DescVec[i]->Start -= (Residue - Buffer );
  41. } /* for */
  42. return(ResSize);
  43. } /* MoveResidue */