[BusyBox] Re: [PATCH] less applet
Rob Sullivan
cogito.ergo.cogito at gmail.com
Sat May 21 09:10:34 UTC 2005
OK guys, a small problem - when I'm done reading stuff into stdin if
something has been piped or redirected to less, I can't do keyboard
input anymore. Here's my data reading function:
static void data_readlines() {
int i;
char current_line[256];
FILE *fp;
if (inp_stdin)
fp = stdin;
else
fp = bb_xfopen(filename, "rt");
for (i = 0; (!feof(fp)) && (i <= MAXLINES); i++) {
strcpy(current_line, "");
fgets(current_line, 256, fp);
bb_xferror(fp, filename);
flines[i] = (char *) bb_xstrndup(current_line,
(strlen(current_line) + 1) * sizeof(char));
}
num_flines = i - 2;
line_pos = 0;
past_eof = 0;
if (!inp_stdin) {
fclose(fp);
if (N_FLAG)
add_linenumbers();
}
inp_stdin, as you may have guessed, tells the function whether input
is coming from stdin or not.
Subsequent input from stdin fails - both feof and ferror are set, and
clearerr(stdin) or rewind(stdin) don't appear to work. If I try
something like:
scanf("%s", current_line);
puts("Done.");
afterwards, the program just seems to output "Done." without any
waiting for the user.
Any ideas?
Thanks,
Rob
More information about the busybox
mailing list