Lines Matching full:front
94 unsigned char *back, *front; in main() local
144 if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) in main()
146 back = front + sb.st_size; in main()
147 match *= (look(key, front, back)); in main()
186 look(wchar_t *string, unsigned char *front, unsigned char *back) in look() argument
189 front = binary_search(string, front, back); in look()
190 front = linear_search(string, front, back); in look()
192 if (front) in look()
193 print_from(string, front, back); in look()
194 return (front ? 0 : 1); in look()
199 * Binary search for "string" in memory between "front" and "back".
206 * front points to the beginning of a line at or before the first
213 * front = NULL;
218 * p = first newline after halfway point from front to back.
221 * p is the new front. Otherwise it is the new back.
226 * since front is always at or before the line to print.
230 * (back - front), which in turn implies that a linear search will
240 binary_search(wchar_t *string, unsigned char *front, unsigned char *back) in binary_search() argument
244 p = front + (back - front) / 2; in binary_search()
251 while (p < back && back > front) { in binary_search()
253 front = p; in binary_search()
256 p = front + (back - front) / 2; in binary_search()
259 return (front); in binary_search()
263 * Find the first line that starts with string, linearly searching from front
270 * o front points at the first character in a line.
271 * o front is before or at the first line to be printed.
274 linear_search(wchar_t *string, unsigned char *front, unsigned char *back) in linear_search() argument
276 while (front < back) { in linear_search()
277 switch (compare(string, front, back)) { in linear_search()
279 return (front); in linear_search()
285 SKIP_PAST_NEWLINE(front, back); in linear_search()
291 * Print as many lines as match string, starting at front.
294 print_from(wchar_t *string, unsigned char *front, unsigned char *back) in print_from() argument
296 for (; front < back && compare(string, front, back) == EQUAL; ++front) { in print_from()
297 for (; front < back && *front != '\n'; ++front) in print_from()
298 if (putchar(*front) == EOF) in print_from()