+#ifdef BB_FEATURE_USE_TERMIOS
+ /* Erase the "More" message */
+ putc('\r', stdout);
+ while (--len >= 0)
+ putc(' ', stdout);
+ putc('\r', stdout);
+ fflush(stdout);
+#endif
+ len=0;
+ lines = 0;
+ page_height = terminal_height;
+ please_display_more_prompt = 0;
+ }
+
+ /*
+ * 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;
+ }
+ /* Adjust the terminal height for any overlap, so that
+ * no lines get lost off the top. */
+ if (len >= terminal_width) {
+ div_t result = div( len, terminal_width);
+ if (result.quot) {
+ if (result.rem)
+ page_height-=result.quot;
+ else
+ page_height-=(result.quot-1);
+ }
+ }
+ if (++lines >= page_height) {
+ please_display_more_prompt = 1;
+ }
+ len=0;
+ }
+ /*
+ * 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);
+ len++;
+ }
+ fclose(file);
+ fflush(stdout);