if a short file, don't move to lower-left corner of the screen,
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 14 Dec 1988 13:58:39 +0000 (05:58 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 14 Dec 1988 13:58:39 +0000 (05:58 -0800)
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

usr/src/usr.bin/more/position.c
usr/src/usr.bin/more/prim.c
usr/src/usr.bin/more/screen.c

index dba7902..8e5d368 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)position.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)position.c 5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -98,6 +98,17 @@ add_back_pos(pos)
        table[0] = 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.
  */
 /*
  * Initialize the position table, done whenever we clear the screen.
  */
index 8358666..d07e552 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)prim.c     5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)prim.c     5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -82,16 +82,15 @@ squish_check()
 
 /*
  * Display n lines, scrolling forward, starting at position pos in the
 
 /*
  * 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;
        register int n;
        off_t pos;
-       int force;
        int only_last;
 {
        int only_last;
 {
+       extern int short_file;
        static int first_time = 1;
        int eof = 0, do_repaint;
 
        static int first_time = 1;
        int eof = 0, do_repaint;
 
@@ -113,7 +112,6 @@ forw(n, pos, force, only_last)
                         */
                        clear();
                        home();
                         */
                        clear();
                        home();
-                       force = 1;
                } else {
                        lower_left();
                        clear_eol();
                } 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);
                if (pos != position(BOTTOM_PLUS_ONE)) {
                        pos_clear();
                        add_forw_pos(pos);
-                       force = 1;
                        if (top_scroll) {
                                clear();
                                home();
                        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) {
                        /*
                /*
                 * 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;
                         */
                        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.
                }
                /*
                 * 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.
  */
 /*
  * Display n lines, scrolling backward.
  */
-back(n, pos, force, only_last)
+back(n, pos, only_last)
        register int n;
        off_t pos;
        register int n;
        off_t pos;
-       int force;
        int only_last;
 {
        int do_repaint;
        int only_last;
 {
        int do_repaint;
@@ -204,14 +203,7 @@ back(n, pos, force, only_last)
                 */
                pos = back_line(pos);
                if (pos == NULL_POSITION)
                 */
                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.
                /*
                 * 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;
        }
                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;   
         */
        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;
        off_t pos;
 {
        hit_eof = 0;
-       forw(sc_height-1, pos, 1, 0);
+       forw(sc_height-1, pos, 0);
        screen_trashed = 0;
 }
 
        screen_trashed = 0;
 }
 
@@ -321,7 +313,7 @@ jump_forw()
        clear();
        pos_clear();
        add_back_pos(pos);
        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.
                 */
                 * The line is currently displayed.  
                 * Just scroll there.
                 */
-               forw(nline, position(BOTTOM_PLUS_ONE), 1, 0);
+               forw(nline, position(BOTTOM_PLUS_ONE), 0);
                return;
        }
 
                return;
        }
 
@@ -463,7 +455,7 @@ jump_loc(pos)
                /*
                 * Note that back() will repaint() if nline > back_scroll.
                 */
                /*
                 * Note that back() will repaint() if nline > back_scroll.
                 */
-               back(nline, npos, 1, 0);
+               back(nline, npos, 0);
                return;
        }
        /*
                return;
        }
        /*
index 504ee5a..d5a652a 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)screen.c   5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)screen.c   5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -211,18 +211,17 @@ get_term()
        /*
         * Get size of the screen.
         */
        /*
         * Get size of the screen.
         */
-       if (sc_height == -1)
 #ifdef TIOCGWINSZ
 #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
 #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
 #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. */
        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);
 }
 
        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()
 {
 lower_left()
 {
-       tputs(sc_lower_left, 1, putchr);
+       if (short_file) {
+               putchr('\r');
+               flush();
+       }
+       else
+               tputs(sc_lower_left, 1, putchr);
 }
 
 /*
 }
 
 /*