1 /* $NetBSD: forwback.c,v 1.4 2013/09/04 19:44:21 tron Exp $ */
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
14 * Primitives for displaying the file on the screen,
15 * scrolling either forward or backward.
21 public int screen_trashed
;
23 public int no_back_scroll
= 0;
24 public int forw_prompt
;
27 extern int top_scroll
;
29 extern int sc_width
, sc_height
;
31 extern int plusoption
;
32 extern int forw_scroll
;
33 extern int back_scroll
;
34 extern int ignore_eoi
;
36 extern int final_attr
;
39 extern char *tagoption
;
42 static void eof_bell
__P((void));
43 static void eof_check
__P((void));
46 * Sound the bell to indicate user is trying to move past end of file.
51 if (quiet
== NOT_QUIET
)
58 * Check to see if the end of file is currently displayed.
68 if (ch_length() == NULL_POSITION
)
70 * If the file length is not known,
71 * we can't possibly be displaying EOF.
76 * If the bottom line is empty, we are at EOF.
77 * If the bottom line ends at the file length,
78 * we must be just at EOF.
80 pos
= position(BOTTOM_PLUS_ONE
);
81 return (pos
== NULL_POSITION
|| pos
== ch_length());
85 * Check to see if the entire file is currently displayed.
88 entire_file_displayed()
92 /* Make sure last line of file is displayed. */
96 /* Make sure first line of file is displayed. */
98 return (pos
== NULL_POSITION
|| pos
== 0);
102 * If the screen is "squished", repaint it.
103 * "Squished" means the first displayed line is not at the top
104 * of the screen; this can happen when we display a short file
105 * for the first time.
117 * Display n lines, scrolling forward,
118 * starting at position pos in the input file.
119 * "force" means display the n lines even if we hit end of file.
120 * "only_last" means display only the last screenful if n > screen size.
121 * "nblank" is the number of blank lines to draw before the first
122 * real line. If nblank > 0, the pos must be NULL_POSITION.
123 * The first real line after the blanks will start at ch_zero().
126 forw(n
, pos
, force
, only_last
, nblank
)
136 static int first_time
= 1;
141 * do_repaint tells us not to display anything till the end,
142 * then just repaint the entire screen.
143 * We repaint if we are supposed to display only the last
144 * screenful and the request is for more than a screenful.
145 * Also if the request exceeds the forward scroll limit
146 * (but not if the request is for exactly a screenful, since
147 * repainting itself involves scrolling forward a screenful).
149 do_repaint
= (only_last
&& n
> sc_height
-1) ||
150 (forw_scroll
>= 0 && n
> forw_scroll
&& n
!= sc_height
-1);
154 if (top_scroll
&& n
>= sc_height
- 1 && pos
!= ch_length())
157 * Start a new screen.
158 * {{ This is not really desirable if we happen
159 * to hit eof in the middle of this screen,
160 * but we don't yet know if that will happen. }}
169 if (pos
!= position(BOTTOM_PLUS_ONE
) || empty_screen())
172 * This is not contiguous with what is
173 * currently displayed. Clear the screen image
174 * (position table) and start a new screen.
183 } else if (!first_time
)
185 putstr("...skipping...\n");
193 * Read the next line of input.
198 * Still drawing blanks; don't get a line
200 * If this is the last blank line, get ready to
201 * read a line starting at ch_zero() next time.
208 * Get the next line from the file.
210 pos
= forw_line(pos
);
211 if (pos
== NULL_POSITION
)
214 * End of file: stop here unless the top line
215 * is still empty, or "force" is true.
216 * Even if force is true, stop when the last
217 * line in the file reaches the top of screen.
220 if (!force
&& position(TOP
) != NULL_POSITION
)
222 if (!empty_lines(0, 0) &&
223 !empty_lines(1, 1) &&
224 empty_lines(2, sc_height
-1))
229 * Add the position of the next line to the position table.
230 * Display the current line on the screen.
237 * If this is the first screen displayed and
238 * we hit an early EOF (i.e. before the requested
239 * number of lines), we "squish" the display down
240 * at the bottom of the screen.
241 * But don't do this if a + option or a -t option
242 * was given. These options can cause us to
243 * start the display after the beginning of the file,
244 * and it is not appropriate to squish in that case.
246 if ((first_time
|| more_mode
) &&
247 pos
== NULL_POSITION
&& !top_scroll
&&
259 * Can't call clear_eol here. The cursor might be at end of line
260 * on an ignaw terminal, so clear_eol would clear the last char
261 * of the current line instead of all of the next line.
262 * If we really need to do this on clear_bg terminals, we need
263 * to find a better way.
266 if (clear_bg
&& apply_at_specials(final_attr
) != AT_NORMAL
)
269 * Writing the last character on the last line
270 * of the display may have scrolled the screen.
271 * If we were in standout mode, clear_bg terminals
272 * will fill the new line with the standout color.
273 * Now we're in normal mode again, so clear the line.
286 (void) currline(BOTTOM
);
290 * Display n lines, scrolling backward.
293 back(n
, pos
, force
, only_last
)
303 do_repaint
= (n
> get_back_scroll() || (only_last
&& n
> sc_height
-1));
307 * Get the previous line of input.
309 pos
= back_line(pos
);
310 if (pos
== NULL_POSITION
)
313 * Beginning of file: stop here unless "force" is true.
319 * Add the position of the previous line to the position table.
320 * Display the line on the screen.
338 (void) currline(BOTTOM
);
342 * Display n more lines, forward.
343 * Start just after the line currently displayed at the bottom of the screen.
346 forward(n
, force
, only_last
)
353 if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE
))
356 * If the -e flag is set and we're trying to go
357 * forward from end-of-file, go on to the next file.
364 pos
= position(BOTTOM_PLUS_ONE
);
365 if (pos
== NULL_POSITION
&& (!force
|| empty_lines(2, sc_height
-1)))
370 * ignore_eoi is to support A_F_FOREVER.
371 * Back up until there is a line at the bottom
380 back(1, position(TOP
), 1, 0);
381 pos
= position(BOTTOM_PLUS_ONE
);
382 } while (pos
== NULL_POSITION
);
390 forw(n
, pos
, force
, only_last
, 0);
394 * Display n more lines, backward.
395 * Start just before the line currently displayed at the top of the screen.
398 backward(n
, force
, only_last
)
406 if (pos
== NULL_POSITION
&& (!force
|| position(BOTTOM
) == 0))
411 back(n
, pos
, force
, only_last
);
415 * Get the backwards scroll limit.
416 * Must call this function instead of just using the value of
417 * back_scroll, because the default case depends on sc_height and
418 * top_scroll, as well as back_scroll.
425 if (back_scroll
>= 0)
426 return (back_scroll
);
428 return (sc_height
- 2);
429 return (10000); /* infinity */