- 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*/
- next_page = 1;
- break;
- }
- if (++lines == terminal_height)
- next_page = 1;
+
+ /*
+ * 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.
+ */
+ wrap = (++len > terminal_width);
+ if (c == '\n' || wrap) {
+ /* Then outputting this character
+ * will move us to a new line. */
+ if (++lines >= terminal_height || input == '\n')
+ please_display_more_prompt = 1;
+ len = 0;
+ }
+ if (c != '\n' && wrap) {
+ /* Then outputting this will also put a character on
+ * the beginning of that new line. Thus we first want to
+ * display the prompt (if any), so we skip the putchar()
+ * and go back to the top of the loop, without reading
+ * a new character. */
+ goto loop_top;