2 * Primitives for displaying the file on the screen,
3 * scrolling either forward or backward.
9 public int hit_eof; /* Keeps track of how many times we hit end of file */
10 public int screen_trashed;
14 extern int top_scroll;
16 extern int sc_width, sc_height;
17 extern int quit_at_eof;
18 extern int plusoption;
19 extern int forw_scroll;
20 extern int back_scroll;
22 extern int ignore_eoi;
28 * Sound the bell to indicate user is trying to move past end of file.
33 if (quiet == NOT_QUIET)
40 * Check to see if the end of file is currently "displayed".
52 * If the bottom line is empty, we are at EOF.
53 * If the bottom line ends at the file length,
54 * we must be just at EOF.
56 pos = position(BOTTOM_PLUS_ONE);
57 if (pos == NULL_POSITION || pos == ch_length())
62 * If the screen is "squished", repaint it.
63 * "Squished" means the first displayed line is not at the top
64 * of the screen; this can happen when we display a short file
77 * Display n lines, scrolling forward,
78 * starting at position pos in the input file.
79 * "force" means display the n lines even if we hit end of file.
80 * "only_last" means display only the last screenful if n > screen size.
81 * "nblank" is the number of blank lines to draw before the first
82 * real line. If nblank > 0, the pos must be NULL_POSITION.
83 * The first real line after the blanks will start at ch_zero().
86 forw(n, pos, force, only_last, nblank)
96 static int first_time = 1;
101 * do_repaint tells us not to display anything till the end,
102 * then just repaint the entire screen.
103 * We repaint if we are supposed to display only the last
104 * screenful and the request is for more than a screenful.
105 * Also if the request exceeds the forward scroll limit
106 * (but not if the request is for exactly a screenful, since
107 * repainting itself involves scrolling forward a screenful).
109 do_repaint = (only_last && n > sc_height-1) ||
110 (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1);
114 if (top_scroll && n >= sc_height - 1 && pos != ch_length())
117 * Start a new screen.
118 * {{ This is not really desirable if we happen
119 * to hit eof in the middle of this screen,
120 * but we don't yet know if that will happen. }}
122 if (top_scroll == 2 || first_time)
132 if (pos != position(BOTTOM_PLUS_ONE) || empty_screen())
135 * This is not contiguous with what is
136 * currently displayed. Clear the screen image
137 * (position table) and start a new screen.
147 } else if (!first_time)
149 putstr("...skipping...\n");
157 * Read the next line of input.
162 * Still drawing blanks; don't get a line
164 * If this is the last blank line, get ready to
165 * read a line starting at ch_zero() next time.
172 * Get the next line from the file.
174 pos = forw_line(pos);
175 if (pos == NULL_POSITION)
178 * End of file: stop here unless the top line
179 * is still empty, or "force" is true.
182 if (!force && position(TOP) != NULL_POSITION)
187 * Add the position of the next line to the position table.
188 * Display the current line on the screen.
195 * If this is the first screen displayed and
196 * we hit an early EOF (i.e. before the requested
197 * number of lines), we "squish" the display down
198 * at the bottom of the screen.
199 * But don't do this if a + option or a -t option
200 * was given. These options can cause us to
201 * start the display after the beginning of the file,
202 * and it is not appropriate to squish in that case.
204 if (first_time && pos == NULL_POSITION && !top_scroll &&
220 else if (eof && !sigs)
229 (void) currline(BOTTOM);
233 * Display n lines, scrolling backward.
236 back(n, pos, force, only_last)
246 do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1));
251 * Get the previous line of input.
253 pos = back_line(pos);
254 if (pos == NULL_POSITION)
257 * Beginning of file: stop here unless "force" is true.
263 * Add the position of the previous line to the position table.
264 * Display the line on the screen.
281 (void) currline(BOTTOM);
285 * Display n more lines, forward.
286 * Start just after the line currently displayed at the bottom of the screen.
289 forward(n, force, only_last)
296 if (quit_at_eof && hit_eof)
299 * If the -e flag is set and we're trying to go
300 * forward from end-of-file, go on to the next file.
307 pos = position(BOTTOM_PLUS_ONE);
308 if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1)))
313 * ignore_eoi is to support A_F_FOREVER.
314 * Back up until there is a line at the bottom
323 back(1, position(TOP), 1, 0);
324 pos = position(BOTTOM_PLUS_ONE);
325 } while (pos == NULL_POSITION);
334 forw(n, pos, force, only_last, 0);
338 * Display n more lines, backward.
339 * Start just before the line currently displayed at the top of the screen.
342 backward(n, force, only_last)
350 if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0))
355 back(n, pos, force, only_last);
359 * Get the backwards scroll limit.
360 * Must call this function instead of just using the value of
361 * back_scroll, because the default case depends on sc_height and
362 * top_scroll, as well as back_scroll.
367 if (back_scroll >= 0)
368 return (back_scroll);
370 return (sc_height - 2);
371 return (10000); /* infinity */