Lines Matching refs:front

106 	unsigned char *back, *front;
156 if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED)
158 back = front + sb.st_size;
159 match *= (look(key, front, back));
198 look(wchar_t *string, unsigned char *front, unsigned char *back)
201 front = binary_search(string, front, back);
202 front = linear_search(string, front, back);
204 if (front)
205 print_from(string, front, back);
206 return (front ? 0 : 1);
211 * Binary search for "string" in memory between "front" and "back".
218 * front points to the beginning of a line at or before the first
225 * front = NULL;
230 * p = first newline after halfway point from front to back.
233 * p is the new front. Otherwise it is the new back.
238 * since front is always at or before the line to print.
242 * (back - front), which in turn implies that a linear search will
252 binary_search(wchar_t *string, unsigned char *front, unsigned char *back)
256 p = front + (back - front) / 2;
263 while (p < back && back > front) {
265 front = p;
268 p = front + (back - front) / 2;
271 return (front);
275 * Find the first line that starts with string, linearly searching from front
282 * o front points at the first character in a line.
283 * o front is before or at the first line to be printed.
286 linear_search(wchar_t *string, unsigned char *front, unsigned char *back)
288 while (front < back) {
289 switch (compare(string, front, back)) {
291 return (front);
297 SKIP_PAST_NEWLINE(front, back);
303 * Print as many lines as match string, starting at front.
306 print_from(wchar_t *string, unsigned char *front, unsigned char *back)
308 for (; front < back && compare(string, front, back) == EQUAL; ++front) {
309 for (; front < back && *front != '\n'; ++front)
310 if (putchar(*front) == EOF)