Lines Matching full:back
94 unsigned char *back, *front; in main() local
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()
193 print_from(string, front, back); in look()
199 * Binary search for "string" in memory between "front" and "back".
209 * back points to the beginning of a line at or after the first
214 * back = EOF;
218 * p = first newline after halfway point from front to back.
221 * p is the new front. Otherwise it is the new back.
228 * In fact, it returns when the chosen "p" equals "back". This
230 * (back - front), which in turn implies that a linear search will
236 #define SKIP_PAST_NEWLINE(p, back) \ argument
237 while (p < back && *p++ != '\n');
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()
245 SKIP_PAST_NEWLINE(p, back); in binary_search()
251 while (p < back && back > front) { in binary_search()
252 if (compare(string, p, back) == GREATER) in binary_search()
255 back = p; in binary_search()
256 p = front + (back - front) / 2; in binary_search()
257 SKIP_PAST_NEWLINE(p, back); in binary_search()
264 * to back.
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()
285 SKIP_PAST_NEWLINE(front, back); in linear_search()
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()
316 * "back" terminated).
319 compare(wchar_t *s1, unsigned char *s2, unsigned char *back) in compare() argument
324 for (; *s1 && s2 < back && *s2 != '\n'; ++s1, s2 += len2) { in compare()
326 len2 = mbrtowc(&ch2, s2, back - s2, NULL); in compare()