in 'x' or 'i' mode, ask if mode of "." should be changed
[unix-history] / usr / src / usr.bin / window / wwwrite.c
index 435203e..f931939 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwwrite.c   1.4 83/07/22";
+static char *sccsid = "@(#)wwwrite.c   2.1.1.1 83/08/09";
 #endif
 
 #include "ww.h"
 
 #endif
 
 #include "ww.h"
 
-int wwnwrite = 0;
+int wwnwrite;
+int wwnwritec;
 
 wwwrite(w, p, n)
 register struct ww *w;
 
 wwwrite(w, p, n)
 register struct ww *w;
@@ -12,31 +13,60 @@ register char *p;
 register n;
 {
        register char c;
 register n;
 {
        register char c;
+       int oldn = n;
 
 
-       if (w == 0 || w->ww_win == 0)
+       if (w == 0)
                return -1;
                return -1;
-       wwnwrite += n;
-       while (n-- > 0) {
+       wwnwrite++;
+       wwnwritec += n;
+       while (--n >= 0) {
                c = *p++ & 0x7f;
                switch (w->ww_wstate) {
                case 0:
                        if (c >= ' ' && c < 0x7f) {
                c = *p++ & 0x7f;
                switch (w->ww_wstate) {
                case 0:
                        if (c >= ' ' && c < 0x7f) {
+                               register i, j, cc;
+
                                if (w->ww_insert)
                                if (w->ww_insert)
-                                       Winschars(w->ww_win, 1);
-                               Wputc(c, w->ww_win);
+                                       wwinschar(w, 1);
+                               cc = w->ww_buf[w->ww_scroll + w->ww_cur.r]
+                                       [w->ww_cur.c].c_w = c;
+                               i = wwcurrow(w);
+                               j = wwcurcol(w);
+                               if (wwsmap[i][j] == w->ww_index) {
+                                       cc = wwns[i][j].c_w = cc
+                                               ^ w->ww_win[w->ww_cur.r]
+                                               [w->ww_cur.c] << WWC_MSHIFT;
+                               }
+               right:
+                               if (++w->ww_cur.c >= w->ww_w.nc) {
+                                       w->ww_cur.c = 0;
+                                       goto lf;
+                               }
                                break;
                        }
                        switch (c) {
                        case '\n':
                                break;
                        }
                        switch (c) {
                        case '\n':
-                               Wputc(c, w->ww_win);
-                               if (w->ww_refresh)
-                                       Wrefresh(1);
+                               if (w->ww_mapnl)
+                                       w->ww_cur.c = 0;
+               lf:
+                               if (++w->ww_cur.r >= w->ww_w.nr) {
+                                       w->ww_cur.r = w->ww_w.nr - 1;
+                                       wwdelline(w, 0);
+                               }
                                break;
                        case '\t':
                                break;
                        case '\t':
+                               w->ww_cur.c |= 7;
+                               goto right;
+                               break;
                        case '\b':
                        case '\b':
+                               if (--w->ww_cur.c < 0)
+                                       w->ww_cur.c = 0;
+                               break;
                        case '\r':
                        case '\r':
+                               w->ww_cur.c = 0;
+                               break;
                        case CTRL(g):
                        case CTRL(g):
-                               Wputc(c, w->ww_win);
+                               wwbell();
                                break;
                        case CTRL([):
                                w->ww_wstate = 1;
                                break;
                        case CTRL([):
                                w->ww_wstate = 1;
@@ -50,41 +80,35 @@ register n;
                                w->ww_insert = 1;
                                break;
                        case 'A':
                                w->ww_insert = 1;
                                break;
                        case 'A':
-                               Wcurup(w->ww_win, 1);
+                               if (--w->ww_cur.r < 0)
+                                       w->ww_cur.r = 0;
                                break;
                        case 'B':
                                break;
                        case 'B':
-                               Wcurdown(w->ww_win, 1);
-                               break;
+                               goto lf;
                        case 'C':
                        case 'C':
-                               Wcurright(w->ww_win, 1);
-                               break;
+                               goto right;
                        case 'E':
                        case 'E':
-                               WWcursor(w->ww_win, 0, 0);
-                               Wclear(w->ww_win, 2);
-                               /* always refresh */
-                               Wrefresh(1);
+                               w->ww_cur.c = w->ww_cur.r = 0;
+                               wwclreos(w);
                                break;
                        case 'H':
                                break;
                        case 'H':
-                               WWcursor(w->ww_win, 0, 0);
+                               w->ww_cur.c = w->ww_cur.r = 0;
                                break;
                        case 'J':
                                break;
                        case 'J':
-                               Wclear(w->ww_win, 0);
+                               wwclreos(w);
                                break;
                        case 'K':
                                break;
                        case 'K':
-                               Wclearline(w->ww_win, 0);
+                               wwclreol(w, w->ww_scroll + w->ww_cur.r,
+                                       w->ww_cur.c, 0);
                                break;
                        case 'L':
                                break;
                        case 'L':
-                               Winslines(w->ww_win, 1);
-                               if (w->ww_refresh)
-                                       Wrefresh(1);
+                               wwinsline(w);
                                break;
                        case 'M':
                                break;
                        case 'M':
-                               Wdellines(w->ww_win, 1);
-                               if (w->ww_refresh)
-                                       Wrefresh(1);
+                               wwdelline(w, w->ww_scroll + w->ww_cur.r);
                                break;
                        case 'N':
                                break;
                        case 'N':
-                               Wdelchars(w->ww_win, 1);
+                               wwdelchar(w);
                                break;
                        case 'O':
                                w->ww_insert = 0;
                                break;
                        case 'O':
                                w->ww_insert = 0;
@@ -95,15 +119,14 @@ register n;
                        }
                        break;
                case 2:
                        }
                        break;
                case 2:
-                       WWcursor(w->ww_win, (c - ' ') % w->ww_i.nrow,
-                               w->ww_win->w_cursor.col);
+                       w->ww_cur.r = (c - ' ') % w->ww_w.nr;
                        w->ww_wstate++;
                        break;
                case 3:
                        w->ww_wstate++;
                        break;
                case 3:
-                       WWcursor(w->ww_win, w->ww_win->w_cursor.row,
-                               (c - ' ') % w->ww_i.ncol);
+                       w->ww_cur.c = (c - ' ') % w->ww_w.nc;
                        w->ww_wstate = 0;
                        break;
                }
        }
                        w->ww_wstate = 0;
                        break;
                }
        }
+       return oldn - n;
 }
 }