cleanup of output of control characters
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 27 Aug 1989 21:00:50 +0000 (13:00 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 27 Aug 1989 21:00:50 +0000 (13:00 -0800)
SCCS-vsn: usr.bin/window/tth19.c 3.23
SCCS-vsn: usr.bin/window/tth29.c 3.8
SCCS-vsn: usr.bin/window/tt.h 3.24
SCCS-vsn: usr.bin/window/ttzapple.c 3.7
SCCS-vsn: usr.bin/window/tth19.c 3.23
SCCS-vsn: usr.bin/window/tth29.c 3.8

usr/src/usr.bin/window/tt.h
usr/src/usr.bin/window/tth19.c
usr/src/usr.bin/window/tth29.c
usr/src/usr.bin/window/ttzapple.c

index 23f82c4..261c12f 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)tt.h        3.23 (Berkeley) %G%
+ *     @(#)tt.h        3.24 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -101,7 +101,7 @@ int tttputc();
 
 /*
  * Buffered output without stdio.
 
 /*
  * Buffered output without stdio.
- * These variables have different meanings from the ww_ob* variabels.
+ * These variables have different meanings from the ww_ob* variables.
  * But I'm too lazy to think up different names.
  */
 char tt_ob[512];
  * But I'm too lazy to think up different names.
  */
 char tt_ob[512];
@@ -109,3 +109,10 @@ char *tt_obp;
 char *tt_obe;
 #define ttputc(c)      (tt_obp < tt_obe ? (*tt_obp++ = (c)) \
                                : (ttflush(), *tt_obp++ = (c)))
 char *tt_obe;
 #define ttputc(c)      (tt_obp < tt_obe ? (*tt_obp++ = (c)) \
                                : (ttflush(), *tt_obp++ = (c)))
+
+/*
+ * Convenience macros for the drivers
+ * They require char.h
+ */
+#define ttctrl(c)      ttputc(ctrl(c))
+#define ttesc(c)       (ttctrl('['), ttputc(c))
index ab1ebbd..50f484d 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tth19.c    3.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)tth19.c    3.23 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
+#include "char.h"
 
 /*
 kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
 
 /*
 kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
@@ -50,17 +51,15 @@ extern struct tt_str *gen_VE;
 
 int h19_msp10c;
 
 
 int h19_msp10c;
 
-#define pc(c)  ttputc(c)
-#define esc()  pc('\033')
 #define PAD(ms10) { \
        register i; \
        for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
 #define PAD(ms10) { \
        register i; \
        for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
-               pc('\0'); \
+               ttputc('\0'); \
 }
 #define ICPAD() PAD((NCOL - tt.tt_col) * 1)    /* 0.1 ms per char */
 #define ILPAD() PAD((NROW - tt.tt_row) * 10)   /* 1 ms per char */
 
 }
 #define ICPAD() PAD((NCOL - tt.tt_col) * 1)    /* 0.1 ms per char */
 #define ILPAD() PAD((NROW - tt.tt_row) * 10)   /* 1 ms per char */
 
-#define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc('@') : pc('O'))
+#define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O')
 
 h19_setmodes(new)
 register new;
 
 h19_setmodes(new)
 register new;
@@ -68,28 +67,17 @@ register new;
        register diff;
 
        diff = new ^ tt.tt_modes;
        register diff;
 
        diff = new ^ tt.tt_modes;
-       if (diff & WWM_REV) {
-               esc();
-               if (new & WWM_REV)
-                       pc('p');
-               else
-                       pc('q');
-       }
-       if (diff & WWM_GRP) {
-               esc();
-               if (new & WWM_GRP)
-                       pc('F');
-               else
-                       pc('G');
-       }
+       if (diff & WWM_REV)
+               ttesc(new & WWM_REV ? 'p' : 'q');
+       if (diff & WWM_GRP)
+               ttesc(new & WWM_REV ? 'F' : 'G');
        tt.tt_modes = new;
 }
 
 h19_insline(n)
 {
        while (--n >= 0) {
        tt.tt_modes = new;
 }
 
 h19_insline(n)
 {
        while (--n >= 0) {
-               esc();
-               pc('L');
+               ttesc('L');
                ILPAD();
        }
 }
                ILPAD();
        }
 }
@@ -97,8 +85,7 @@ h19_insline(n)
 h19_delline(n)
 {
        while (--n >= 0) {
 h19_delline(n)
 {
        while (--n >= 0) {
-               esc();
-               pc('M');
+               ttesc('M');
                ILPAD();
        }
 }
                ILPAD();
        }
 }
@@ -110,7 +97,7 @@ register char c;
                (*tt.tt_setmodes)(tt.tt_nmodes);
        if (tt.tt_insert)
                H19_SETINSERT(0);
                (*tt.tt_setmodes)(tt.tt_nmodes);
        if (tt.tt_insert)
                H19_SETINSERT(0);
-       pc(c);
+       ttputc(c);
        if (++tt.tt_col == NCOL)
                tt.tt_col = NCOL - 1;
 }
        if (++tt.tt_col == NCOL)
                tt.tt_col = NCOL - 1;
 }
@@ -136,39 +123,35 @@ register char row, col;
                if (tt.tt_col == col)
                        return;
                if (col == 0) {
                if (tt.tt_col == col)
                        return;
                if (col == 0) {
-                       pc('\r');
+                       ttctrl('m');
                        goto out;
                }
                if (tt.tt_col == col - 1) {
                        goto out;
                }
                if (tt.tt_col == col - 1) {
-                       esc();
-                       pc('C');
+                       ttesc('C');
                        goto out;
                }
                if (tt.tt_col == col + 1) {
                        goto out;
                }
                if (tt.tt_col == col + 1) {
-                       pc('\b');
+                       ttctrl('h');
                        goto out;
                }
        }
        if (tt.tt_col == col) {
                if (tt.tt_row == row + 1) {
                        goto out;
                }
        }
        if (tt.tt_col == col) {
                if (tt.tt_row == row + 1) {
-                       esc();
-                       pc('A');
+                       ttesc('A');
                        goto out;
                }
                if (tt.tt_row == row - 1) {
                        goto out;
                }
                if (tt.tt_row == row - 1) {
-                       pc('\n');
+                       ttctrl('j');
                        goto out;
                }
        }
        if (col == 0 && row == 0) {
                        goto out;
                }
        }
        if (col == 0 && row == 0) {
-               esc();
-               pc('H');
+               ttesc('H');
                goto out;
        }
                goto out;
        }
-       esc();
-       pc('Y');
-       pc(' ' + row);
-       pc(' ' + col);
+       ttesc('Y');
+       ttputc(' ' + row);
+       ttputc(' ' + col);
 out:
        tt.tt_col = col;
        tt.tt_row = row;
 out:
        tt.tt_col = col;
        tt.tt_row = row;
@@ -178,10 +161,8 @@ h19_start()
 {
        if (gen_VS)
                ttxputs(gen_VS);
 {
        if (gen_VS)
                ttxputs(gen_VS);
-       esc();
-       pc('w');
-       esc();
-       pc('E');
+       ttesc('w');
+       ttesc('E');
        tt.tt_col = tt.tt_row = 0;
        tt.tt_insert = 0;
        tt.tt_nmodes = tt.tt_modes = 0;
        tt.tt_col = tt.tt_row = 0;
        tt.tt_insert = 0;
        tt.tt_nmodes = tt.tt_modes = 0;
@@ -193,26 +174,22 @@ h19_end()
                H19_SETINSERT(0);
        if (gen_VE)
                ttxputs(gen_VE);
                H19_SETINSERT(0);
        if (gen_VE)
                ttxputs(gen_VE);
-       esc();
-       pc('v');
+       ttesc('v');
 }
 
 h19_clreol()
 {
 }
 
 h19_clreol()
 {
-       esc();
-       pc('K');
+       ttesc('K');
 }
 
 h19_clreos()
 {
 }
 
 h19_clreos()
 {
-       esc();
-       pc('J');
+       ttesc('J');
 }
 
 h19_clear()
 {
 }
 
 h19_clear()
 {
-       esc();
-       pc('E');
+       ttesc('E');
 }
 
 h19_inschar(c)
 }
 
 h19_inschar(c)
@@ -222,7 +199,7 @@ register char c;
                (*tt.tt_setmodes)(tt.tt_nmodes);
        if (!tt.tt_insert)
                H19_SETINSERT(1);
                (*tt.tt_setmodes)(tt.tt_nmodes);
        if (!tt.tt_insert)
                H19_SETINSERT(1);
-       pc(c);
+       ttputc(c);
        if (tt.tt_insert)
                ICPAD();
        if (++tt.tt_col == NCOL)
        if (tt.tt_insert)
                ICPAD();
        if (++tt.tt_col == NCOL)
@@ -231,26 +208,22 @@ register char c;
 
 h19_delchar(n)
 {
 
 h19_delchar(n)
 {
-       while (--n >= 0) {
-               esc();
-               pc('N');
-       }
+       while (--n >= 0)
+               ttesc('N');
 }
 
 h19_scroll_down(n)
 {
        h19_move(NROW - 1, 0);
        while (--n >= 0)
 }
 
 h19_scroll_down(n)
 {
        h19_move(NROW - 1, 0);
        while (--n >= 0)
-               pc('\n');
+               ttctrl('j');
 }
 
 h19_scroll_up(n)
 {
        h19_move(0, 0);
 }
 
 h19_scroll_up(n)
 {
        h19_move(0, 0);
-       while (--n >= 0) {
-               esc();
-               pc('I');
-       }
+       while (--n >= 0)
+               ttesc('I');
 }
 
 tt_h19()
 }
 
 tt_h19()
index 5a48fbe..4147d5a 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tth29.c    3.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)tth29.c    3.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
+#include "char.h"
 
 /*
  * H29 Driver
 
 /*
  * H29 Driver
@@ -38,9 +39,6 @@ kC|h29|heath-29|z29|zenith-29:\
  *
  */
 
  *
  */
 
-#define pc(c)  ttputc(c)
-#define esc()  pc('\033')
-
 h29_setmodes(new)
 register new;
 {
 h29_setmodes(new)
 register new;
 {
@@ -56,15 +54,14 @@ register new;
                modes += 0x08;
        if (new & WWM_USR)
                modes += 0x10;
                modes += 0x08;
        if (new & WWM_USR)
                modes += 0x10;
-       esc();
-       pc('s');
-       pc(modes);
+       ttesc('s');
+       ttputc(modes);
        if (new & WWM_GRP) {
                if ((tt.tt_modes & WWM_GRP) == 0)
        if (new & WWM_GRP) {
                if ((tt.tt_modes & WWM_GRP) == 0)
-                       esc(), pc('F');
+                       ttesc('F');
        } else
                if (tt.tt_modes & WWM_GRP)
        } else
                if (tt.tt_modes & WWM_GRP)
-                       esc(), pc('G');
+                       ttesc('G');
        tt.tt_modes = new;
 }
 
        tt.tt_modes = new;
 }
 
index 966773c..f0523b4 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttzapple.c 3.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttzapple.c 3.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -39,39 +39,36 @@ zz|zapple|perfect apple:\
 #define NROW           24
 #define TOKEN_MAX      32
 
 #define NROW           24
 #define TOKEN_MAX      32
 
-#define pc(c)  ttputc(c)
-#define esc(c) (pc(ctrl('[')), pc(c))
-
 extern short gen_frame[];
 
 zz_setmodes(new)
 {
        if (new & WWM_REV) {
                if ((tt.tt_modes & WWM_REV) == 0)
 extern short gen_frame[];
 
 zz_setmodes(new)
 {
        if (new & WWM_REV) {
                if ((tt.tt_modes & WWM_REV) == 0)
-                       esc('+');
+                       ttesc('+');
        } else
                if (tt.tt_modes & WWM_REV)
        } else
                if (tt.tt_modes & WWM_REV)
-                       esc('-');
+                       ttesc('-');
        tt.tt_modes = new;
 }
 
 zz_insline(n)
 {
        if (n == 1)
        tt.tt_modes = new;
 }
 
 zz_insline(n)
 {
        if (n == 1)
-               esc('a');
+               ttesc('a');
        else {
        else {
-               esc('A');
-               pc(n + ' ');
+               ttesc('A');
+               ttputc(n + ' ');
        }
 }
 
 zz_delline(n)
 {
        if (n == 1)
        }
 }
 
 zz_delline(n)
 {
        if (n == 1)
-               esc('d');
+               ttesc('d');
        else {
        else {
-               esc('D');
-               pc(n + ' ');
+               ttesc('D');
+               ttputc(n + ' ');
        }
 }
 
        }
 }
 
@@ -106,42 +103,42 @@ zz_move(row, col)
                if ((x = col - tt.tt_col) == 0)
                        return;
                if (col == 0) {
                if ((x = col - tt.tt_col) == 0)
                        return;
                if (col == 0) {
-                       pc('\r');
+                       ttctrl('m');
                        goto out;
                }
                switch (x) {
                case 2:
                        goto out;
                }
                switch (x) {
                case 2:
-                       pc(ctrl('f'));
+                       ttctrl('f');
                case 1:
                case 1:
-                       pc(ctrl('f'));
+                       ttctrl('f');
                        goto out;
                case -2:
                        goto out;
                case -2:
-                       pc('\b');
+                       ttctrl('h');
                case -1:
                case -1:
-                       pc('\b');
+                       ttctrl('h');
                        goto out;
                }
                if (col & 7 == 0 && x > 0 && x <= 16) {
                        goto out;
                }
                if (col & 7 == 0 && x > 0 && x <= 16) {
-                       pc('\t');
+                       ttctrl('i');
                        if (x > 8)
                        if (x > 8)
-                               pc('\t');
+                               ttctrl('i');
                        goto out;
                }
                        goto out;
                }
-               esc('<');
-               pc(col + ' ');
+               ttesc('<');
+               ttputc(col + ' ');
                goto out;
        }
        if (tt.tt_col == col) {
                switch (row - tt.tt_row) {
                case 2:
                goto out;
        }
        if (tt.tt_col == col) {
                switch (row - tt.tt_row) {
                case 2:
-                       pc('\n');
+                       ttctrl('j');
                case 1:
                case 1:
-                       pc('\n');
+                       ttctrl('j');
                        goto out;
                case -2:
                        goto out;
                case -2:
-                       pc(ctrl('k'));
+                       ttctrl('k');
                case -1:
                case -1:
-                       pc(ctrl('k'));
+                       ttctrl('k');
                        goto out;
                }
                if (col == 0) {
                        goto out;
                }
                if (col == 0) {
@@ -150,30 +147,30 @@ zz_move(row, col)
                        if (row == NROW - 1)
                                goto ll;
                }
                        if (row == NROW - 1)
                                goto ll;
                }
-               esc('>');
-               pc(row + ' ');
+               ttesc('>');
+               ttputc(row + ' ');
                goto out;
        }
        if (col == 0) {
                if (row == 0) {
 home:
                goto out;
        }
        if (col == 0) {
                if (row == 0) {
 home:
-                       esc('0');
+                       ttesc('0');
                        goto out;
                }
                if (row == tt.tt_row + 1) {
                        goto out;
                }
                if (row == tt.tt_row + 1) {
-                       pc('\r');
-                       pc('\n');
+                       ttctrl('m');
+                       ttctrl('j');
                        goto out;
                }
                if (row == NROW - 1) {
 ll:
                        goto out;
                }
                if (row == NROW - 1) {
 ll:
-                       esc('1');
+                       ttesc('1');
                        goto out;
                }
        }
                        goto out;
                }
        }
-       esc('=');
-       pc(' ' + row);
-       pc(' ' + col);
+       ttesc('=');
+       ttputc(' ' + row);
+       ttputc(' ' + col);
 out:
        tt.tt_col = col;
        tt.tt_row = row;
 out:
        tt.tt_col = col;
        tt.tt_row = row;
@@ -184,49 +181,49 @@ zz_start()
        zz_setmodes(0);
        zz_setscroll(0, NROW - 1);
        zz_clear();
        zz_setmodes(0);
        zz_setscroll(0, NROW - 1);
        zz_clear();
-       esc('T');
-       pc(TOKEN_MAX + ' ');
+       ttesc('T');
+       ttputc(TOKEN_MAX + ' ');
 }
 
 zz_end()
 {
 }
 
 zz_end()
 {
-       esc('T');
-       pc(' ');
+       ttesc('T');
+       ttputc(' ');
 }
 
 zz_clreol()
 {
 }
 
 zz_clreol()
 {
-       esc('2');
+       ttesc('2');
 }
 
 zz_clreos()
 {
 }
 
 zz_clreos()
 {
-       esc('3');
+       ttesc('3');
 }
 
 zz_clear()
 {
 }
 
 zz_clear()
 {
-       esc('4');
+       ttesc('4');
        tt.tt_col = tt.tt_row = 0;
 }
 
 zz_insspace(n)
 {
        if (n == 1)
        tt.tt_col = tt.tt_row = 0;
 }
 
 zz_insspace(n)
 {
        if (n == 1)
-               esc('i');
+               ttesc('i');
        else {
        else {
-               esc('I');
-               pc(n + ' ');
+               ttesc('I');
+               ttputc(n + ' ');
        }
 }
 
 zz_delchar(n)
 {
        if (n == 1)
        }
 }
 
 zz_delchar(n)
 {
        if (n == 1)
-               esc('c');
+               ttesc('c');
        else {
        else {
-               esc('C');
-               pc(n + ' ');
+               ttesc('C');
+               ttputc(n + ' ');
        }
 }
 
        }
 }
 
@@ -234,30 +231,30 @@ zz_scroll_down(n)
 {
        if (n == 1)
                if (tt.tt_row == NROW - 1)
 {
        if (n == 1)
                if (tt.tt_row == NROW - 1)
-                       pc('\n');
+                       ttctrl('j');
                else
                else
-                       esc('f');
+                       ttesc('f');
        else {
        else {
-               esc('F');
-               pc(n + ' ');
+               ttesc('F');
+               ttputc(n + ' ');
        }
 }
 
 zz_scroll_up(n)
 {
        if (n == 1)
        }
 }
 
 zz_scroll_up(n)
 {
        if (n == 1)
-               esc('r');
+               ttesc('r');
        else {
        else {
-               esc('R');
-               pc(n + ' ');
+               ttesc('R');
+               ttputc(n + ' ');
        }
 }
 
 zz_setscroll(top, bot)
 {
        }
 }
 
 zz_setscroll(top, bot)
 {
-       esc('?');
-       pc(top + ' ');
-       pc(bot + ' ');
+       ttesc('?');
+       ttputc(top + ' ');
+       ttputc(bot + ' ');
        tt.tt_scroll_top = top;
        tt.tt_scroll_bot = bot;
 }
        tt.tt_scroll_top = top;
        tt.tt_scroll_bot = bot;
 }
@@ -276,8 +273,8 @@ zz_set_token(t, s, n)
                ttputs(buf);
                tt.tt_col += 3;
        }
                ttputs(buf);
                tt.tt_col += 3;
        }
-       pc(0x80);
-       pc(t + 1);
+       ttputc(0x80);
+       ttputc(t + 1);
        s[n - 1] |= 0x80;
        ttwrite(s, n);
        s[n - 1] &= ~0x80;
        s[n - 1] |= 0x80;
        ttwrite(s, n);
        s[n - 1] &= ~0x80;
@@ -299,7 +296,7 @@ zz_put_token(t, s, n)
                ttputs(buf);
                tt.tt_col += 3;
        }
                ttputs(buf);
                tt.tt_col += 3;
        }
-       pc(t + 0x81);
+       ttputc(t + 0x81);
        tt.tt_col += n;
        if (tt.tt_col == NCOL)
                tt.tt_col = 0, tt.tt_row++;
        tt.tt_col += n;
        if (tt.tt_col == NCOL)
                tt.tt_col = 0, tt.tt_row++;