BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / window / wwwrite.c
index 6007035..3c6140d 100644 (file)
@@ -1,17 +1,38 @@
-#ifndef lint
-static char sccsid[] = "@(#)wwwrite.c  3.22 %G%";
-#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.
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Edward Wang at The University of California, Berkeley.
+ *
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * 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
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
+#ifndef lint
+static char sccsid[] = "@(#)wwwrite.c  3.33 (Berkeley) 6/6/90";
+#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
@@ -44,8 +65,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;
@@ -64,7 +85,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;
                        }
 
@@ -108,14 +129,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;
@@ -127,6 +143,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) {
@@ -148,10 +165,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;
                        }
@@ -164,6 +181,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) {
@@ -191,6 +209,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;
@@ -201,6 +220,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':
@@ -212,26 +232,25 @@ int n;
                        case 'O':
                                w->ww_insert = 0;
                                break;
                        case 'O':
                                w->ww_insert = 0;
                                break;
-                       case 'Y':
-                               w->ww_wstate = 2;
+                       case 'P':
+                               wwinschar(w, w->ww_cur.r, w->ww_cur.c, ' ', 0);
                                break;
                                break;
-                       case 'p':
-                               w->ww_modes |= WWM_REV;
+                       case 'X':
+                               wwupdate();
                                break;
                                break;
-                       case 'q':
-                               w->ww_modes &= ~WWM_REV;
+                       case 'Y':
+                               UPDATE();
+                               w->ww_wstate = 2;
                                break;
                                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;
@@ -245,6 +264,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)