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: 6: /* 7: * In coordination with the I/O optimization code in Execute, if the Residual 8: * is odd in length, we move it to Buffer+1, otherwise to Buffer+0, to make 9: * sure that [at least] the next read goes down on an even address. A pointer 10: * to a pointer to the current start of data in the buffer is passed in, that 11: * pointer is updated and passed back. 12: */ 13: 14: int MoveResidue(DescVec, NPats, Buffer, BuffStartP, BuffEnd) 15: struct PattDesc *DescVec[]; 16: int NPats; 17: char *Buffer, **BuffStartP, *BuffEnd; 18: { 19: char *FirstStart, *f, *t, *Residue; 20: int ResSize, i; 21: FirstStart = BuffEnd; 22: /* find the earliest point which has not been 23: * completely searched */ 24: for (i=0; i < NPats; i++) { 25: FirstStart = 26: min(FirstStart, DescVec[i]-> Start ); 27: } /* for */ 28: /* now scan to the beginning of the line containing the 29: * unsearched text */ 30: for (Residue = FirstStart; *Residue != '\n' && 31: Residue >= *BuffStartP; Residue--); 32: if (Residue < *BuffStartP) 33: Residue = FirstStart; 34: else ++Residue; 35: ResSize = (BuffEnd - Residue + 1); 36: /* now move the residue to the beginning of 37: * the file */ 38: t = *BuffStartP = ((unsigned) ResSize & 1) ? Buffer+1 : Buffer; 39: f = Residue; 40: for(i=ResSize;i;--i) 41: *t++ = *f++; 42: /* now fix the status vectors */ 43: for (i=0; i < NPats; i++) { 44: DescVec[i]->Start -= (Residue - *BuffStartP); 45: } /* for */ 46: return(ResSize); 47: } /* MoveResidue */