aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-05-06 16:39:12 -0500
committerRob Landley <rob@landley.net>2015-05-06 16:39:12 -0500
commitdaf36948a9c235d5e70ec343557facfb80edaddd (patch)
tree4e130bb7ec834df7ab47326c590ab6a935f90d9b /toys/pending
parentef55374b9d5e6ea1325f2888fdbb0425e5e73d18 (diff)
downloadtoybox-daf36948a9c235d5e70ec343557facfb80edaddd.tar.gz
Fix more with missing files.
Previously we'd go into an infinite loop because we weren't incrementing optargs. Also add a missing flush so an error on stderr won't overtake the escape code that resets reverse video. Disclaimer: the new behavior isn't exactly like the desktop version; surprisingly they try to open the next file _before_ they prompt. That feels weird to me as a user, and seems like it would lead to a more awkward implementation, but if you're more concerned about authenticity...
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/more.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/toys/pending/more.c b/toys/pending/more.c
index 59392ffe..f0e79079 100644
--- a/toys/pending/more.c
+++ b/toys/pending/more.c
@@ -53,6 +53,7 @@ static int prompt(FILE *cin, const char* fmt, ...)
input_key = tolower(getc(cin));
printf("\33[0m\33[1K\r"); // Reset all attributes, erase to start of line.
if (strchr(" \nrq", input_key)) {
+ fflush(NULL);
return input_key;
}
printf("\33[7m(Enter:Next line Space:Next page Q:Quit R:Show the rest)");
@@ -95,8 +96,8 @@ void more_main()
do {
fp = stdin;
if (*toys.optargs && !(fp = fopen(*toys.optargs, "r"))) {
- perror_msg("'%s'", *toys.optargs);
- continue;
+ perror_msg("%s", *toys.optargs);
+ goto next_file;
}
st.st_size = show_prompt = col = row = 0;
fstat(fileno(fp), &st);
@@ -133,6 +134,7 @@ void more_main()
}
fclose(fp);
+next_file:
if (*toys.optargs && *++toys.optargs) {
input_key = prompt(cin, "--More--(Next file: %s)", *toys.optargs);
if (input_key == 'q') goto stop;