8000 minix/commands/simple/fgrep.c at v3.1.5 · booklin/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
executable file
·
354 lines (314 loc) · 8.86 KB

fgrep.c

File metadata and controls

executable file
·
354 lines (314 loc) · 8.86 KB
/* Loop until a line is found. */
while (1) {
if (input >= max_input && fill_buffer() == 0) { /* EOF */
line = (char *) NULL;
break;
}
/* If match is still equal to max_input after the next loop
* then no match is found. */
match = max_input;
ts = strings;
do {
if (input == buffer) {
if (search_str(ts) < match) match = ts->bufp;
} else if (ts->bufp < match) {
if (ts->bufp >= input || search_str(ts) < match)
match = ts->bufp;
}
} while ((ts = ts->next) != (test_str *) NULL);
/* Determine if and in what line a match is found. Only do
* line number counting if it is necessary or very easy. */
if (vflag) {
line_num++;
line = input;
input = 1 + (char *) memchr(line, '\n', BUF_SIZE);
if (input <= match) break; /* no match in current line */
} else if (nflag) {
do {
line_num++;
line = input;
input = 1 + (char *) memchr(line, '\n', BUF_SIZE);
} while (input < match ||
(input == match && match < max_input));
if (match < max_input) break; /* match found */
} else if (match < max_input) {
/* Match found. */
for (line = match; *--line != '\n';);
line++;
input = 1 + (char *) memchr(match, '\n', BUF_SIZE);
break;
} else
input = max_input;
}
return line;
}
0