From: Keith Bostic Date: Wed, 14 Dec 1988 13:58:39 +0000 (-0800) Subject: if a short file, don't move to lower-left corner of the screen, X-Git-Tag: BSD-4_3_Net_1-Snapshot-Development~131 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/4a7551eaee63c882e540eb25bd34981f1abbd031 if a short file, don't move to lower-left corner of the screen, unless editing or movement attempted, including at exit. Correct dumb mistake in window signal handling. Add routine to copy portions of the table. SCCS-vsn: usr.bin/more/prim.c 5.7 SCCS-vsn: usr.bin/more/position.c 5.4 SCCS-vsn: usr.bin/more/screen.c 5.6 --- diff --git a/usr/src/usr.bin/more/position.c b/usr/src/usr.bin/more/position.c index dba7902a8d..8e5d368e5c 100644 --- a/usr/src/usr.bin/more/position.c +++ b/usr/src/usr.bin/more/position.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)position.c 5.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)position.c 5.4 (Berkeley) %G%"; #endif /* not lint */ /* @@ -98,6 +98,17 @@ add_back_pos(pos) table[0] = pos; } +copytable() +{ + register int a, b; + + for (a = 0; a < sc_height && table[a] == NULL_POSITION; a++); + for (b = 0; a < sc_height; a++, b++) { + table[b] = table[a]; + table[a] = NULL_POSITION; + } +} + /* * Initialize the position table, done whenever we clear the screen. */ diff --git a/usr/src/usr.bin/more/prim.c b/usr/src/usr.bin/more/prim.c index 83586668d8..d07e552d6c 100644 --- a/usr/src/usr.bin/more/prim.c +++ b/usr/src/usr.bin/more/prim.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)prim.c 5.6 (Berkeley) %G%"; +static char sccsid[] = "@(#)prim.c 5.7 (Berkeley) %G%"; #endif /* not lint */ /* @@ -82,16 +82,15 @@ squish_check() /* * Display n lines, scrolling forward, starting at position pos in the - * input file. "force" means display the n lines even if we hit end of - * file. "only_last" means display only the last screenful if n > screen - * size. + * input file. "only_last" means display only the last screenful if + * n > screen size. */ -forw(n, pos, force, only_last) +forw(n, pos, only_last) register int n; off_t pos; - int force; int only_last; { + extern int short_file; static int first_time = 1; int eof = 0, do_repaint; @@ -113,7 +112,6 @@ forw(n, pos, force, only_last) */ clear(); home(); - force = 1; } else { lower_left(); clear_eol(); @@ -127,7 +125,6 @@ forw(n, pos, force, only_last) if (pos != position(BOTTOM_PLUS_ONE)) { pos_clear(); add_forw_pos(pos); - force = 1; if (top_scroll) { clear(); home(); @@ -136,20 +133,23 @@ forw(n, pos, force, only_last) } } - while (--n >= 0) { + for (short_file = 0; --n >= 0;) { /* * Read the next line of input. */ pos = forw_line(pos); if (pos == NULL_POSITION) { /* - * End of file: stop here unless the top line - * is still empty, or "force" is true. + * end of file; copy the table if the file was + * too small for an entire screen. */ eof = 1; - if (!force && position(TOP) != NULL_POSITION) - break; - line = NULL; + if (position(TOP) == NULL_POSITION) { + copytable(); + if (!position(TOP)) + short_file = 1; + } + break; } /* * Add the position of the next line to the position table. @@ -186,10 +186,9 @@ forw(n, pos, force, only_last) /* * Display n lines, scrolling backward. */ -back(n, pos, force, only_last) +back(n, pos, only_last) register int n; off_t pos; - int force; int only_last; { int do_repaint; @@ -204,14 +203,7 @@ back(n, pos, force, only_last) */ pos = back_line(pos); if (pos == NULL_POSITION) - { - /* - * Beginning of file: stop here unless "force" is true. - */ - if (!force) - break; - line = NULL; - } + break; /* * Add the position of the previous line to the position table. * Display the line on the screen. @@ -256,7 +248,7 @@ forward(n, only_last) hit_eof++; return; } - forw(n, pos, 0, only_last); + forw(n, pos, only_last); } /* @@ -276,7 +268,7 @@ backward(n, only_last) */ if (pos == NULL_POSITION) return; - back(n, pos, 0, only_last); + back(n, pos, only_last); } /* @@ -286,7 +278,7 @@ prepaint(pos) off_t pos; { hit_eof = 0; - forw(sc_height-1, pos, 1, 0); + forw(sc_height-1, pos, 0); screen_trashed = 0; } @@ -321,7 +313,7 @@ jump_forw() clear(); pos_clear(); add_back_pos(pos); - back(sc_height - 1, pos, 0, 0); + back(sc_height - 1, pos, 0); } /* @@ -417,7 +409,7 @@ jump_loc(pos) * The line is currently displayed. * Just scroll there. */ - forw(nline, position(BOTTOM_PLUS_ONE), 1, 0); + forw(nline, position(BOTTOM_PLUS_ONE), 0); return; } @@ -463,7 +455,7 @@ jump_loc(pos) /* * Note that back() will repaint() if nline > back_scroll. */ - back(nline, npos, 1, 0); + back(nline, npos, 0); return; } /* diff --git a/usr/src/usr.bin/more/screen.c b/usr/src/usr.bin/more/screen.c index 504ee5ada7..d5a652abea 100644 --- a/usr/src/usr.bin/more/screen.c +++ b/usr/src/usr.bin/more/screen.c @@ -18,7 +18,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)screen.c 5.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)screen.c 5.6 (Berkeley) %G%"; #endif /* not lint */ /* @@ -211,18 +211,17 @@ get_term() /* * Get size of the screen. */ - if (sc_height == -1) #ifdef TIOCGWINSZ - if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_row > 0) - sc_height = w.ws_row; + if (ioctl(2, TIOCGWINSZ, &w) == 0 && w.ws_row > 0) + sc_height = w.ws_row; #else #ifdef WIOCGETD - if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_height > 0) - sc_height = w.uw_height/w.uw_vs; + if (ioctl(2, WIOCGETD, &w) == 0 && w.uw_height > 0) + sc_height = w.uw_height/w.uw_vs; #endif #endif - else - sc_height = tgetnum("li"); + else + sc_height = tgetnum("li"); hard = (sc_height < 0 || tgetflag("hc")); if (hard) { /* Oh no, this is a hardcopy terminal. */ @@ -433,12 +432,15 @@ add_line() tputs(sc_addline, sc_height, putchr); } -/* - * Move cursor to lower left corner of screen. - */ +int short_file; /* if file less than a screen */ lower_left() { - tputs(sc_lower_left, 1, putchr); + if (short_file) { + putchr('\r'); + flush(); + } + else + tputs(sc_lower_left, 1, putchr); } /*