+#endif
+ while ((c = getc(file)) != EOF) {
+ if (please_display_more_prompt) {
+ int len = 0;
+
+ please_display_more_prompt = 0;
+ lines = 0;
+ len = printf("--More-- ");
+ if (file != stdin) {
+#if _FILE_OFFSET_BITS == 64
+ len += printf("(%d%% of %lld bytes)",
+#else
+ len += printf("(%d%% of %ld bytes)",
+#endif
+ (int) (100 *
+ ((double) ftell(file) /
+ (double) st.st_size)),
+ st.st_size);
+ }
+ len += printf("%s",
+#ifdef BB_FEATURE_USE_TERMIOS
+ ""
+#else
+ "\n"
+#endif
+ );
+
+ fflush(stdout);
+
+ /*
+ * We've just displayed the "--More--" prompt, so now we need
+ * to get input from the user.
+ */
+#ifdef BB_FEATURE_USE_TERMIOS
+ input = getc(cin);
+#else
+ input = getc(stdin);
+#endif
+
+#ifdef BB_FEATURE_USE_TERMIOS
+ /* Erase the "More" message */
+ while (--len >= 0)
+ putc('\b', stdout);
+ while (++len <= terminal_width)
+ putc(' ', stdout);
+ while (--len >= 0)
+ putc('\b', stdout);
+ fflush(stdout);
+#endif
+
+ }
+
+ /*
+ * There are two input streams to worry about here:
+ *
+ * c : the character we are reading from the file being "mored"
+ * input : a character received from the keyboard
+ *
+ * If we hit a newline in the _file_ stream, we want to test and
+ * see if any characters have been hit in the _input_ stream. This
+ * allows the user to quit while in the middle of a file.
+ */
+ if (c == '\n') {
+ switch (input) {
+ case 'q':
+ goto end;
+ case '\n':
+ /* increment by just one line if we are at
+ * the end of this line*/
+ please_display_more_prompt = 1;
+ break;
+ }
+ if (++lines == terminal_height)
+ please_display_more_prompt = 1;
+ }
+ /*
+ * If we just read a newline from the file being 'mored' and any
+ * key other than a return is hit, scroll by one page
+ */
+ putc(c, stdout);
+ }
+ fclose(file);
+ fflush(stdout);
+
+ argv++;
+ } while (--argc > 0);
+ end:
+#ifdef BB_FEATURE_USE_TERMIOS
+ gotsig(0);
+#endif
+ return(TRUE);
+}