From d93758100f2a0e2107957c31450a3e9c6bf278b8 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Thu, 24 Aug 1989 04:43:49 -0800 Subject: [PATCH] insert mode bug fix and cleanup SCCS-vsn: usr.bin/window/wwinschar.c 3.18 SCCS-vsn: usr.bin/window/ttgeneric.c 3.40 SCCS-vsn: usr.bin/window/tth19.c 3.22 SCCS-vsn: usr.bin/window/tt.h 3.23 SCCS-vsn: usr.bin/window/wwupdate.c 3.26 SCCS-vsn: usr.bin/window/wwwrite.c 3.30 SCCS-vsn: usr.bin/window/wwinit.c 3.35 SCCS-vsn: usr.bin/window/xx.c 3.2 SCCS-vsn: usr.bin/window/xx.h 3.2 SCCS-vsn: usr.bin/window/xxflush.c 3.2 SCCS-vsn: usr.bin/window/ttzapple.c 3.5 --- usr/src/usr.bin/window/tt.h | 5 +-- usr/src/usr.bin/window/ttgeneric.c | 65 ++++++++++++++++-------------- usr/src/usr.bin/window/tth19.c | 49 +++++++++++----------- usr/src/usr.bin/window/ttzapple.c | 6 +-- usr/src/usr.bin/window/wwinit.c | 4 +- usr/src/usr.bin/window/wwinschar.c | 2 +- usr/src/usr.bin/window/wwupdate.c | 17 ++++---- usr/src/usr.bin/window/wwwrite.c | 4 +- usr/src/usr.bin/window/xx.c | 34 ++++++++-------- usr/src/usr.bin/window/xx.h | 6 +-- usr/src/usr.bin/window/xxflush.c | 19 ++++----- 11 files changed, 105 insertions(+), 106 deletions(-) diff --git a/usr/src/usr.bin/window/tt.h b/usr/src/usr.bin/window/tt.h index 4b87c0a7a6..23f82c45f3 100644 --- a/usr/src/usr.bin/window/tt.h +++ b/usr/src/usr.bin/window/tt.h @@ -14,7 +14,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#)tt.h 3.22 (Berkeley) %G% + * @(#)tt.h 3.23 (Berkeley) %G% */ /* @@ -30,6 +30,7 @@ struct tt { int (*tt_insline)(); int (*tt_delline)(); int (*tt_inschar)(); + int (*tt_insspace)(); int (*tt_delchar)(); int (*tt_write)(); /* write a whole block */ int (*tt_putc)(); /* write one character */ @@ -39,7 +40,6 @@ struct tt { int (*tt_scroll_down)(); int (*tt_scroll_up)(); int (*tt_setscroll)(); /* set scrolling region */ - int (*tt_setinsert)(); /* set insert mode */ int (*tt_setmodes)(); /* set display modes */ int (*tt_set_token)(); /* define a token */ int (*tt_put_token)(); /* refer to a defined token */ @@ -48,7 +48,6 @@ struct tt { char tt_modes; /* the current display modes */ char tt_nmodes; /* the new modes for next write */ char tt_insert; /* currently in insert mode */ - char tt_ninsert; /* insert mode on next write */ int tt_row; /* cursor row */ int tt_col; /* cursor column */ int tt_scroll_top; /* top of scrolling region */ diff --git a/usr/src/usr.bin/window/ttgeneric.c b/usr/src/usr.bin/window/ttgeneric.c index 0256ee6683..8950d8f223 100644 --- a/usr/src/usr.bin/window/ttgeneric.c +++ b/usr/src/usr.bin/window/ttgeneric.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)ttgeneric.c 3.39 (Berkeley) %G%"; +static char sccsid[] = "@(#)ttgeneric.c 3.40 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -178,18 +178,11 @@ gen_delline(n) gen_putc(c) register char c; { - if (tt.tt_ninsert != tt.tt_insert) - gen_setinsert(tt.tt_ninsert); + if (tt.tt_insert) + gen_setinsert(0); if (tt.tt_nmodes != tt.tt_modes) gen_setmodes(tt.tt_nmodes); - if (tt.tt_insert) { - if (gen_IC) - tttputs(gen_IC, gen_CO - tt.tt_col); - ttputc(c); - if (gen_IP) - tttputs(gen_IP, gen_CO - tt.tt_col); - } else - ttputc(c); + ttputc(c); if (++tt.tt_col == gen_CO) if (gen_XN) tt.tt_col = tt.tt_row = -10; @@ -203,23 +196,12 @@ gen_write(p, n) register char *p; register n; { - if (tt.tt_ninsert != tt.tt_insert) - gen_setinsert(tt.tt_ninsert); + if (tt.tt_insert) + gen_setinsert(0); if (tt.tt_nmodes != tt.tt_modes) gen_setmodes(tt.tt_nmodes); - if (tt.tt_insert && (gen_IC || gen_IP)) { - while (--n >= 0) { - if (gen_IC) - tttputs(gen_IC, gen_CO - tt.tt_col); - ttputc(*p++); - if (gen_IP) - tttputs(gen_IP, gen_CO - tt.tt_col); - tt.tt_col++; - } - } else { - tt.tt_col += n; - ttwrite(p, n); - } + ttwrite(p, n); + tt.tt_col += n; if (tt.tt_col == gen_CO) if (gen_XN) tt.tt_col = tt.tt_row = -10; @@ -286,12 +268,14 @@ gen_start() ttxputs(gen_TI); ttxputs(gen_CL); tt.tt_col = tt.tt_row = 0; - tt.tt_ninsert = tt.tt_insert = 0; + tt.tt_insert = 0; tt.tt_nmodes = tt.tt_modes = 0; } gen_end() { + if (tt.tt_insert) + gen_setinsert(0); if (gen_TE) ttxputs(gen_TE); if (gen_VE) @@ -319,7 +303,28 @@ gen_clear() ttxputs(gen_CL); } -gen_inschar(n) +gen_inschar(c) +register char c; +{ + if (!tt.tt_insert) + gen_setinsert(1); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + if (gen_IC) + tttputs(gen_IC, gen_CO - tt.tt_col); + ttputc(c); + if (gen_IP) + tttputs(gen_IP, gen_CO - tt.tt_col); + if (++tt.tt_col == gen_CO) + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; +} + +gen_insspace(n) { if (gen_ICn) ttpgoto(gen_ICn, 0, n, gen_CO - tt.tt_col); @@ -465,9 +470,9 @@ tt_generic() gen_US = 0; if (gen_IM) - tt.tt_setinsert = gen_setinsert; - else if (gen_IC) tt.tt_inschar = gen_inschar; + else if (gen_IC) + tt.tt_insspace = gen_insspace; if (gen_DC) tt.tt_delchar = gen_delchar; if (gen_AL) diff --git a/usr/src/usr.bin/window/tth19.c b/usr/src/usr.bin/window/tth19.c index 2d32dd3479..ab1ebbddd7 100644 --- a/usr/src/usr.bin/window/tth19.c +++ b/usr/src/usr.bin/window/tth19.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)tth19.c 3.21 (Berkeley) %G%"; +static char sccsid[] = "@(#)tth19.c 3.22 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -62,11 +62,6 @@ int h19_msp10c; #define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc('@') : pc('O')) -h19_setinsert(new) -{ - H19_SETINSERT(new); -} - h19_setmodes(new) register new; { @@ -113,11 +108,9 @@ register char c; { if (tt.tt_nmodes != tt.tt_modes) (*tt.tt_setmodes)(tt.tt_nmodes); - if (tt.tt_ninsert != tt.tt_insert) - H19_SETINSERT(tt.tt_ninsert); - pc(c); if (tt.tt_insert) - ICPAD(); + H19_SETINSERT(0); + pc(c); if (++tt.tt_col == NCOL) tt.tt_col = NCOL - 1; } @@ -128,18 +121,10 @@ register n; { if (tt.tt_nmodes != tt.tt_modes) (*tt.tt_setmodes)(tt.tt_nmodes); - if (tt.tt_ninsert != tt.tt_insert) - H19_SETINSERT(tt.tt_ninsert); - if (tt.tt_insert) { - while (--n >= 0) { - pc(*p++); - ICPAD(); - tt.tt_col++; - } - } else { - tt.tt_col += n; - ttwrite(p, n); - } + if (tt.tt_insert) + H19_SETINSERT(0); + ttwrite(p, n); + tt.tt_col += n; if (tt.tt_col == NCOL) tt.tt_col = NCOL - 1; } @@ -198,12 +183,14 @@ h19_start() esc(); pc('E'); tt.tt_col = tt.tt_row = 0; - tt.tt_ninsert = tt.tt_insert = 0; + tt.tt_insert = 0; tt.tt_nmodes = tt.tt_modes = 0; } h19_end() { + if (tt.tt_insert) + H19_SETINSERT(0); if (gen_VE) ttxputs(gen_VE); esc(); @@ -228,6 +215,20 @@ h19_clear() pc('E'); } +h19_inschar(c) +register char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (!tt.tt_insert) + H19_SETINSERT(1); + pc(c); + if (tt.tt_insert) + ICPAD(); + if (++tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + h19_delchar(n) { while (--n >= 0) { @@ -265,6 +266,7 @@ tt_h19() tt.tt_insline = h19_insline; tt.tt_delline = h19_delline; + tt.tt_inschar = h19_inschar; tt.tt_delchar = h19_delchar; tt.tt_clreol = h19_clreol; tt.tt_clreos = h19_clreos; @@ -274,7 +276,6 @@ tt_h19() tt.tt_putc = h19_putc; tt.tt_scroll_down = h19_scroll_down; tt.tt_scroll_up = h19_scroll_up; - tt.tt_setinsert = h19_setinsert; tt.tt_setmodes = h19_setmodes; tt.tt_ncol = NCOL; diff --git a/usr/src/usr.bin/window/ttzapple.c b/usr/src/usr.bin/window/ttzapple.c index 95bafd2988..79ea82df05 100644 --- a/usr/src/usr.bin/window/ttzapple.c +++ b/usr/src/usr.bin/window/ttzapple.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)ttzapple.c 3.4 (Berkeley) %G%"; +static char sccsid[] = "@(#)ttzapple.c 3.5 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -229,7 +229,7 @@ zz_clear() tt.tt_col = tt.tt_row = 0; } -zz_inschar(n) +zz_insspace(n) { if (n != 1) { esc1(); @@ -334,7 +334,7 @@ zz_put_token(t, s, n) tt_zapple() { - tt.tt_inschar = zz_inschar; + tt.tt_insspace = zz_insspace; tt.tt_delchar = zz_delchar; tt.tt_insline = zz_insline; tt.tt_delline = zz_delline; diff --git a/usr/src/usr.bin/window/wwinit.c b/usr/src/usr.bin/window/wwinit.c index a7ad7b7e1b..be9bfcbb09 100644 --- a/usr/src/usr.bin/window/wwinit.c +++ b/usr/src/usr.bin/window/wwinit.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)wwinit.c 3.34 (Berkeley) %G%"; +static char sccsid[] = "@(#)wwinit.c 3.35 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -150,7 +150,7 @@ wwinit() wwaddcap1(WWT_USR, &kp); if (tt.tt_insline && tt.tt_delline || tt.tt_setscroll) wwaddcap1(WWT_ALDL, &kp); - if (tt.tt_inschar || tt.tt_setinsert) + if (tt.tt_inschar || tt.tt_insspace) wwaddcap1(WWT_IMEI, &kp); if (tt.tt_delchar) wwaddcap1(WWT_DC, &kp); diff --git a/usr/src/usr.bin/window/wwinschar.c b/usr/src/usr.bin/window/wwinschar.c index ebb1fac483..715a2dabeb 100644 --- a/usr/src/usr.bin/window/wwinschar.c +++ b/usr/src/usr.bin/window/wwinschar.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)wwinschar.c 3.17 (Berkeley) %G%"; +static char sccsid[] = "@(#)wwinschar.c 3.18 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" diff --git a/usr/src/usr.bin/window/wwupdate.c b/usr/src/usr.bin/window/wwupdate.c index 2b37e1d2d6..5fda014a5f 100644 --- a/usr/src/usr.bin/window/wwupdate.c +++ b/usr/src/usr.bin/window/wwupdate.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)wwupdate.c 3.25 (Berkeley) %G%"; +static char sccsid[] = "@(#)wwupdate.c 3.26 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -221,28 +221,25 @@ simple: } if (wwwrap && i == wwnrow - 1 && q - buf + c == wwncol) { - if (tt.tt_setinsert) { + if (tt.tt_inschar) { if (q - buf != 1) { xxwrite(i, c, buf + 1, q - buf - 1, m); - xxinschar(i, c, *buf | - m << WWC_MSHIFT); + xxinschar(i, c, *buf, m); } else { xxwrite(i, c - 1, buf, 1, m); xxinschar(i, c - 1, - ns[-2].c_w); + ns[-2].c_c, ns[-2].c_m); } - } else if (tt.tt_inschar) { + } else if (tt.tt_insspace) { if (q - buf != 1) { xxwrite(i, c, buf + 1, q - buf - 1, m); - xxinschar(i, c, *buf | - m << WWC_MSHIFT); + xxinsspace(i, c); xxwrite(i, c, buf, 1, m); } else { xxwrite(i, c - 1, buf, 1, m); - xxinschar(i, c - 1, - ns[-2].c_w); + xxinsspace(i, c - 1); xxwrite(i, c - 1, &ns[-2].c_c, 1, ns[-2].c_m); } diff --git a/usr/src/usr.bin/window/wwwrite.c b/usr/src/usr.bin/window/wwwrite.c index 50b68af72f..90cf59bfe1 100644 --- a/usr/src/usr.bin/window/wwwrite.c +++ b/usr/src/usr.bin/window/wwwrite.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)wwwrite.c 3.29 (Berkeley) %G%"; +static char sccsid[] = "@(#)wwwrite.c 3.30 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -80,7 +80,7 @@ int n; 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; } diff --git a/usr/src/usr.bin/window/xx.c b/usr/src/usr.bin/window/xx.c index d69d8909b1..69382b92f2 100644 --- a/usr/src/usr.bin/window/xx.c +++ b/usr/src/usr.bin/window/xx.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)xx.c 3.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)xx.c 3.2 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -53,8 +53,6 @@ xxend() if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1) /* tt.tt_setscroll is known to be defined */ (*tt.tt_setscroll)(0, tt.tt_nrow - 1); - if (tt.tt_insert) - (*tt.tt_setinsert)(0); if (tt.tt_modes) (*tt.tt_setmodes)(0); if (tt.tt_scroll_down) @@ -121,28 +119,32 @@ xxscroll(dir, top, bot) xp->arg2 = bot; } -xxinschar(row, col, c) +xxinschar(row, col, c, m) +{ + register struct xx *xp; + + xp = xxalloc(); + xp->cmd = xc_inschar; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = c; + xp->arg3 = m; +} + +xxinsspace(row, col) { register struct xx *xp = xx_tail; - int m = c >> WWC_MSHIFT; - if (xxbufp >= xxbufe) - xxflush(0); - c &= WWC_CMASK; - if (xp != 0 && xp->cmd == xc_inschar && - xp->arg0 == row && xp->arg1 + xp->arg2 == col && xp->arg3 == m) { - xp->buf[xp->arg2++] = c; - xxbufp++; + if (xp != 0 && xp->cmd == xc_insspace && xp->arg0 == row && + col >= xp->arg1 && col <= xp->arg1 + xp->arg2) { + xp->arg2++; return; } xp = xxalloc(); - xp->cmd = xc_inschar; + xp->cmd = xc_insspace; xp->arg0 = row; xp->arg1 = col; xp->arg2 = 1; - xp->arg3 = m; - xp->buf = xxbufp++; - *xp->buf = c; } xxdelchar(row, col) diff --git a/usr/src/usr.bin/window/xx.h b/usr/src/usr.bin/window/xx.h index 34d38f2c68..a7e9add71f 100644 --- a/usr/src/usr.bin/window/xx.h +++ b/usr/src/usr.bin/window/xx.h @@ -14,12 +14,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#)xx.h 3.1 (Berkeley) %G% + * @(#)xx.h 3.2 (Berkeley) %G% */ struct xx { - enum { xc_move, xc_scroll, xc_delchar, xc_inschar, xc_clear, xc_clreos, - xc_clreol, xc_write } cmd; + enum { xc_move, xc_scroll, xc_inschar, xc_insspace, xc_delchar, + xc_clear, xc_clreos, xc_clreol, xc_write } cmd; int arg0; int arg1; int arg2; diff --git a/usr/src/usr.bin/window/xxflush.c b/usr/src/usr.bin/window/xxflush.c index 0067fbd47a..d286e39a5d 100644 --- a/usr/src/usr.bin/window/xxflush.c +++ b/usr/src/usr.bin/window/xxflush.c @@ -16,7 +16,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)xxflush.c 3.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)xxflush.c 3.2 (Berkeley) %G%"; #endif /* not lint */ #include "ww.h" @@ -38,20 +38,15 @@ xxflush(intr) xxflush_scroll(xp); break; case xc_inschar: - if (xp->arg1 + xp->arg2 >= tt.tt_ncol) - break; (*tt.tt_move)(xp->arg0, xp->arg1); - if (tt.tt_setinsert) { - tt.tt_nmodes = xp->arg3; - tt.tt_ninsert = 1; - (*tt.tt_write)(xp->buf, xp->arg2); - tt.tt_ninsert = 0; - } else - (*tt.tt_inschar)(xp->arg2); + tt.tt_nmodes = xp->arg3; + (*tt.tt_inschar)(xp->arg2); + break; + case xc_insspace: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_insspace)(xp->arg2); break; case xc_delchar: - if (xp->arg1 + xp->arg2 >= tt.tt_ncol) - break; (*tt.tt_move)(xp->arg0, xp->arg1); (*tt.tt_delchar)(xp->arg2); break; -- 2.20.1