insert mode bug fix and cleanup
[unix-history] / usr / src / usr.bin / window / wwwrite.c
index cf7c419..90cf59b 100644 (file)
@@ -1,11 +1,33 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwwrite.c   3.19 84/04/08";
-#endif
+static char sccsid[] = "@(#)wwwrite.c  3.30 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 #include "char.h"
 
 
 #include "ww.h"
 #include "tt.h"
 #include "char.h"
 
+#define UPDATE() \
+       if (!w->ww_noupdate && w->ww_cur.r >= 0 && w->ww_cur.r < wwnrow && \
+           wwtouched[w->ww_cur.r]) \
+               wwupdate1(w->ww_cur.r, w->ww_cur.r + 1)
+
 /*
  * To support control character expansion, we save the old
  * p and q values in r and s, and point p at the beginning
 /*
  * To support control character expansion, we save the old
  * p and q values in r and s, and point p at the beginning
@@ -26,6 +48,9 @@ int n;
        char *r = 0;
        char *s;
 
        char *r = 0;
        char *s;
 
+#ifdef lint
+       s = 0;                  /* define it before possible use */
+#endif
        if (hascursor = w->ww_hascursor)
                wwcursor(w, 0);
        while (p < q && !w->ww_stopped && (!wwinterrupt() || w->ww_nointr)) {
        if (hascursor = w->ww_hascursor)
                wwcursor(w, 0);
        while (p < q && !w->ww_stopped && (!wwinterrupt() || w->ww_nointr)) {
@@ -35,8 +60,8 @@ int n;
                        r = 0;
                        continue;
                }
                        r = 0;
                        continue;
                }
-               if (w->ww_wstate == 0 && (isprt(*p)
-                   || w->ww_unctrl && isunctrl(*p))) {
+               if (w->ww_wstate == 0 &&
+                   (isprt(*p) || w->ww_unctrl && isunctrl(*p))) {
                        register i;
                        register union ww_char *bp;
                        int col, col1;
                        register i;
                        register union ww_char *bp;
                        int col, col1;
@@ -55,7 +80,7 @@ int n;
                                        q = p + 10;
                                }
                                wwinschar(w, w->ww_cur.r, w->ww_cur.c,
                                        q = p + 10;
                                }
                                wwinschar(w, w->ww_cur.r, w->ww_cur.c,
-                                       *p++ | w->ww_modes << WWC_MSHIFT);
+                                       *p++, w->ww_modes);
                                goto right;
                        }
 
                                goto right;
                        }
 
@@ -99,14 +124,9 @@ int n;
                                                ns[i].c_w = bp[i].c_w
                                                        ^ win[i] << WWC_MSHIFT;
                                        }
                                                ns[i].c_w = bp[i].c_w
                                                        ^ win[i] << WWC_MSHIFT;
                                        }
-                               if (nchanged > 0) {
+                               if (nchanged > 0)
                                        wwtouched[w->ww_cur.r] |= WWU_TOUCHED;
                                        wwtouched[w->ww_cur.r] |= WWU_TOUCHED;
-                                       if (!w->ww_noupdate)
-                                               wwupdate1(w->ww_cur.r,
-                                                       w->ww_cur.r + 1);
-                               }
                        }
                        }
-                       
                chklf:
                        if (w->ww_cur.c >= w->ww_w.r)
                                goto crlf;
                chklf:
                        if (w->ww_cur.c >= w->ww_w.r)
                                goto crlf;
@@ -118,6 +138,7 @@ int n;
                crlf:
                                        w->ww_cur.c = w->ww_w.l;
                lf:
                crlf:
                                        w->ww_cur.c = w->ww_w.l;
                lf:
+                               UPDATE();
                                if (++w->ww_cur.r >= w->ww_w.b) {
                                        w->ww_cur.r = w->ww_w.b - 1;
                                        if (w->ww_w.b < w->ww_b.b) {
                                if (++w->ww_cur.r >= w->ww_w.b) {
                                        w->ww_cur.r = w->ww_w.b - 1;
                                        if (w->ww_w.b < w->ww_b.b) {
@@ -139,10 +160,10 @@ int n;
                        case '\r':
                                w->ww_cur.c = w->ww_w.l;
                                break;
                        case '\r':
                                w->ww_cur.c = w->ww_w.l;
                                break;
-                       case ctrl(g):
-                               ttputc(ctrl(g));
+                       case ctrl('g'):
+                               ttputc(ctrl('g'));
                                break;
                                break;
-                       case ctrl([):
+                       case ctrl('['):
                                w->ww_wstate = 1;
                                break;
                        }
                                w->ww_wstate = 1;
                                break;
                        }
@@ -155,6 +176,7 @@ int n;
                                break;
                        case 'A':
                up:
                                break;
                        case 'A':
                up:
+                               UPDATE();
                                if (--w->ww_cur.r < w->ww_w.t) {
                                        w->ww_cur.r = w->ww_w.t;
                                        if (w->ww_w.t > w->ww_b.t) {
                                if (--w->ww_cur.r < w->ww_w.t) {
                                        w->ww_cur.r = w->ww_w.t;
                                        if (w->ww_w.t > w->ww_b.t) {
@@ -182,6 +204,7 @@ int n;
                                wwclreos(w, w->ww_w.t, w->ww_w.l);
                                break;
                        case 'H':
                                wwclreos(w, w->ww_w.t, w->ww_w.l);
                                break;
                        case 'H':
+                               UPDATE();
                                w->ww_cur.r = w->ww_w.t;
                                w->ww_cur.c = w->ww_w.l;
                                break;
                                w->ww_cur.r = w->ww_w.t;
                                w->ww_cur.c = w->ww_w.l;
                                break;
@@ -192,6 +215,7 @@ int n;
                                wwclreol(w, w->ww_cur.r, w->ww_cur.c);
                                break;
                        case 'L':
                                wwclreol(w, w->ww_cur.r, w->ww_cur.c);
                                break;
                        case 'L':
+                               UPDATE();
                                wwinsline(w, w->ww_cur.r);
                                break;
                        case 'M':
                                wwinsline(w, w->ww_cur.r);
                                break;
                        case 'M':
@@ -203,26 +227,22 @@ int n;
                        case 'O':
                                w->ww_insert = 0;
                                break;
                        case 'O':
                                w->ww_insert = 0;
                                break;
+                       case 'X':
+                               wwupdate();
+                               break;
                        case 'Y':
                        case 'Y':
+                               UPDATE();
                                w->ww_wstate = 2;
                                break;
                                w->ww_wstate = 2;
                                break;
-                       case 'p':
-                               w->ww_modes |= WWM_REV;
-                               break;
-                       case 'q':
-                               w->ww_modes &= ~WWM_REV;
-                               break;
-                       case 'r':
-                               w->ww_modes |= WWM_UL;
+                       case 'Z':
+                               wwupdate();
+                               xxflush(0);
                                break;
                        case 's':
                                break;
                        case 's':
-                               w->ww_modes &= ~WWM_UL;
+                               w->ww_wstate = 4;
                                break;
                                break;
-                       case 'F':
-                               w->ww_modes |= WWM_GRP;
-                               break;
-                       case 'G':
-                               w->ww_modes &= ~WWM_GRP;
+                       case 'r':
+                               w->ww_wstate = 5;
                                break;
                        }
                        break;
                                break;
                        }
                        break;
@@ -236,6 +256,14 @@ int n;
                                (unsigned)(*p++ - ' ') % w->ww_w.nc;
                        w->ww_wstate = 0;
                        break;
                                (unsigned)(*p++ - ' ') % w->ww_w.nc;
                        w->ww_wstate = 0;
                        break;
+               case 4:
+                       w->ww_modes |= *p++ & wwavailmodes;
+                       w->ww_wstate = 0;
+                       break;
+               case 5:
+                       w->ww_modes &= ~*p++;
+                       w->ww_wstate = 0;
+                       break;
                }
        }
        if (hascursor)
                }
        }
        if (hascursor)