use \n at bottom to scroll entire screen,
[unix-history] / usr / src / usr.bin / window / wwclreol.c
index b3558a4..9d20549 100644 (file)
@@ -1,7 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwclreol.c  3.11 83/12/02";
+static char sccsid[] = "@(#)wwclreol.c 3.15 %G%";
 #endif
 
 #endif
 
+/*
+ * Copyright (c) 1983 Regents of the University of California,
+ * All rights reserved.  Redistribution permitted subject to
+ * the terms of the Berkeley Software License Agreement.
+ */
+
 #include "ww.h"
 #include "tt.h"
 
 #include "ww.h"
 #include "tt.h"
 
@@ -16,7 +22,6 @@ int row, col;
 char cleared;
 {
        register i;
 char cleared;
 {
        register i;
-       int nblank, ncleared;
 
        /*
         * Clear the buffer right off
 
        /*
         * Clear the buffer right off
@@ -42,45 +47,65 @@ char cleared;
        /*
         * Now find out how much is actually cleared, and fix wwns.
         */
        /*
         * Now find out how much is actually cleared, and fix wwns.
         */
-       {
+       if (cleared) {
+               register union ww_char *s;
+               register char *smap, *win;
+
+               i = col;
+               smap = &wwsmap[row][i];
+               s = &wwns[row][i];
+               win = &w->ww_win[row][i];
+               for (i = w->ww_i.r - i; --i >= 0;) {
+                       if (*smap++ != w->ww_index)
+                               continue;
+                       s++->c_w = ' ' | *win++ << WWC_MSHIFT;
+               }
+       } else {
                register union ww_char *s;
                register char *smap, *win;
                register union ww_char *s;
                register char *smap, *win;
+               int ntouched = 0;
+               int gain = 0;
 
                i = col;
                smap = &wwsmap[row][i];
                s = wwns[row];
                win = w->ww_win[row];
 
                i = col;
                smap = &wwsmap[row][i];
                s = wwns[row];
                win = w->ww_win[row];
-               ncleared = nblank = 0;
-
                for (; i < w->ww_i.r; i++) {
                        if (*smap++ != w->ww_index) {
                for (; i < w->ww_i.r; i++) {
                        if (*smap++ != w->ww_index) {
-                               if (s[i].c_w == ' ')
-                                       nblank++;
+                               if (s[i].c_w != ' ')
+                                       gain--;
                        } else if (win[i] == 0) {
                        } else if (win[i] == 0) {
-                               nblank++;
                                if (s[i].c_w != ' ') {
                                if (s[i].c_w != ' ') {
-                                       ncleared++; 
+                                       gain++;
+                                       ntouched++;
                                        s[i].c_w = ' ';
                                }
                                        s[i].c_w = ' ';
                                }
-                       } else
-                               s[i].c_w = ' ' | win[i] << WWC_MSHIFT;
+                       } else {
+                               short c = ' ' | win[i] << WWC_MSHIFT;
+                               if (s[i].c_w == c)
+                                       gain--;
+                               else {
+                                       s[i].c_w = c;
+                                       ntouched++;
+                               }
+                       }
                }
                }
-               if (ncleared > 0)
+               s += i;
+               for (i = wwncol - i; --i >= 0;)
+                       if (s++->c_w != ' ')
+                               gain--;
+               if (ntouched > 0)
                        wwtouched[row] |= WWU_TOUCHED;
                        wwtouched[row] |= WWU_TOUCHED;
-       }
-
-       /*
-        * Can/Should we use clear eol?
-        */
-       if (!cleared && tt.tt_clreol != 0
-           && ncleared > wwncol - col - nblank + 4) {
-               register union ww_char *s;
-
-               /* clear to the end */
-               (*tt.tt_move)(row, col);
-               (*tt.tt_clreol)();
-               s = &wwos[row][col];
-               for (i = wwncol - col; --i >= 0;)
-                       s++->c_w = ' ';
+               /*
+                * Can/should we use clear eol?
+                */
+               if (tt.tt_clreol != 0 && gain > 4) {
+                       /* clear to the end */
+                       (*tt.tt_move)(row, col);
+                       (*tt.tt_clreol)();
+                       s = &wwos[row][col];
+                       for (i = wwncol - col; --i >= 0;)
+                               s++->c_w = ' ';
+               }
        }
 }
        }
 }