include var.h and lcmd.c only in some of the parser?.c
[unix-history] / usr / src / usr.bin / window / wwclreol.c
index 5052d66..1fbc811 100644 (file)
@@ -1,31 +1,22 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwclreol.c  3.8 83/09/14";
+static char *sccsid = "@(#)wwclreol.c  3.12 84/01/06";
 #endif
 
 #include "ww.h"
 #include "tt.h"
 
 #endif
 
 #include "ww.h"
 #include "tt.h"
 
-wwclreol(w, line, col)
-struct ww *w;
-{
-       wwclreol1(w, line, col, 0);
-}
-
 /*
  * Clear w to the end of line.
  * If cleared is true, then the screen line has already been cleared
  * previously.
  */
 /*
  * Clear w to the end of line.
  * If cleared is true, then the screen line has already been cleared
  * previously.
  */
-wwclreol1(w, line, col, cleared)
+wwclreol1(w, row, col, cleared)
 register struct ww *w;
 register struct ww *w;
-int line, col;
+int row, col;
 char cleared;
 {
        register i;
 char cleared;
 {
        register i;
-       int row = line - w->ww_scroll;
-       int srow = w->ww_w.t + row;
-       int scol = w->ww_w.l + col;
-       int nblank, ncleared;
+       int gain;
 
        /*
         * Clear the buffer right off
 
        /*
         * Clear the buffer right off
@@ -33,67 +24,86 @@ char cleared;
        {
                register union ww_char *buf;
 
        {
                register union ww_char *buf;
 
-               buf = &w->ww_buf[line][col]; 
-               for (i = w->ww_w.nc - col; --i >= 0;)
+               buf = &w->ww_buf[row][col]; 
+               for (i = w->ww_b.r - col; --i >= 0;)
                        buf++->c_w = ' ';
        }
 
        /*
         * If can't see it, just return.
         */
                        buf++->c_w = ' ';
        }
 
        /*
         * If can't see it, just return.
         */
-       if (srow < w->ww_i.t || srow >= w->ww_i.b
-           || w->ww_i.r <= 0 || w->ww_i.r <= scol)
+       if (row < w->ww_i.t || row >= w->ww_i.b
+           || w->ww_i.r <= 0 || w->ww_i.r <= col)
                return;
 
                return;
 
-       if (scol < w->ww_i.l)
-               scol = w->ww_i.l;
-       col = scol - w->ww_w.l;
+       if (col < w->ww_i.l)
+               col = w->ww_i.l;
 
        /*
         * 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;
                register union ww_char *s;
                register char *smap, *win;
-               register char *touched;
 
 
-               smap = &wwsmap[srow][scol];
-               s = &wwns[srow][scol];
-               touched = &wwtouched[srow];
-               win = &w->ww_win[row][col];
-               ncleared = nblank = 0;
+               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;
+               int ntouched = 0;
 
 
-               for (i = w->ww_i.r - scol; --i >= 0;) {
+               i = col;
+               smap = &wwsmap[row][i];
+               s = wwns[row];
+               win = w->ww_win[row];
+               gain = 0;
+               for (; i < w->ww_i.r; i++) {
                        if (*smap++ != w->ww_index) {
                        if (*smap++ != w->ww_index) {
-                               if (s++->c_w == ' ')
-                                       nblank++;
-                               win++;
-                               continue;
+                               if (s[i].c_w != ' ')
+                                       gain--;
+                       } else if (win[i] == 0) {
+                               if (s[i].c_w != ' ') {
+                                       gain++;
+                                       ntouched++;
+                                       s[i].c_w = ' ';
+                               }
+                       } else {
+                               short c = ' ' | win[i] << WWC_MSHIFT;
+                               if (s[i].c_w == c)
+                                       gain--;
+                               else {
+                                       s[i].c_w = c;
+                                       ntouched++;
+                               }
                        }
                        }
-                       ncleared++; 
-                       *touched = 1;
-                       if (*win == 0) {
-                               nblank++;
-                               s++->c_w = ' ';
-                               win++;
-                       } else
-                               s++->c_w = ' ' | *win++ << WWC_MSHIFT;
                }
                }
+               s += i;
+               for (i = wwncol - i; --i >= 0;)
+                       if (s++->c_w != ' ')
+                               gain--;
+               if (ntouched > 0)
+                       wwtouched[row] |= WWU_TOUCHED;
        }
 
        /*
         * Can/Should we use clear eol?
         */
        }
 
        /*
         * Can/Should we use clear eol?
         */
-       if (!cleared && tt.tt_clreol != 0
-           && ncleared > wwncol - scol - nblank
-           && nblank > (wwncol - scol) / 2) {
+       if (!cleared && tt.tt_clreol != 0 && gain > 4) {
                register union ww_char *s;
 
                /* clear to the end */
                register union ww_char *s;
 
                /* clear to the end */
-               (*tt.tt_move)(srow, scol);
+               (*tt.tt_move)(row, col);
                (*tt.tt_clreol)();
                (*tt.tt_clreol)();
-               s = &wwos[srow][scol];
-               for (i = wwncol - scol; --i >= 0;)
+               s = &wwos[row][col];
+               for (i = wwncol - col; --i >= 0;)
                        s++->c_w = ' ';
        }
 }
                        s++->c_w = ' ';
        }
 }