BSD 4_4 release
[unix-history] / usr / src / usr.bin / window / tth19.c
index eb59b73..b6dbcfe 100644 (file)
@@ -1,9 +1,46 @@
+/*
+ * Copyright (c) 1983, 1993
+ *     The 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, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)tth19.c     3.6 83/08/17";
-#endif
+static char sccsid[] = "@(#)tth19.c    8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 
 #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:
@@ -17,221 +54,195 @@ kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
        es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
 */
 
        es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
 */
 
-char h19_frame[16] = {
-       ' ',      '`'|0x80, 'a'|0x80, 'e'|0x80,
-       '`'|0x80, '`'|0x80, 'f'|0x80, 'v'|0x80,
-       'a'|0x80, 'd'|0x80, 'a'|0x80, 'u'|0x80,
-       'c'|0x80, 't'|0x80, 's'|0x80, 'b'|0x80
+#define NCOL   80
+#define NROW   24
+
+#define G (WWM_GRP << WWC_MSHIFT)
+short h19_frame[16] = {
+       ' ',    '`'|G,  'a'|G,  'e'|G,
+       '`'|G,  '`'|G,  'f'|G,  'v'|G,
+       'a'|G,  'd'|G,  'a'|G,  'u'|G,
+       'c'|G,  't'|G,  's'|G,  'b'|G
 };
 
 };
 
-char h19_row, h19_col;
-char h19_modes, h19_nmodes;
-char h19_insert, h19_ninsert;
-char h19_graphics;
-short h19_msp10c;
-char *h19_VS;
-char *h19_VE;
+extern struct tt_str *gen_VS;
+extern struct tt_str *gen_VE;
+
+int h19_msp10c;
 
 
-#define pc(c)  putchar('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((80 - h19_col) * 1)                /* 0.1 ms per char */
-#define ILPAD() PAD((24 - h19_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 SETINSERT(m) \
-       ((m) != h19_insert \
-               ? (esc(), (h19_insert = (m)) ? pc(@) : pc(O)) : 0)
-#define SETMODES(m) \
-       ((m) != h19_modes \
-               ? (esc(), (h19_modes = (m)) ? pc(p) : pc(q)) : 0)
-#define SETGRAPHICS(m) \
-       ((m) != h19_graphics \
-               ? (esc(), (h19_graphics = (m)) ? pc(F) : pc(G)) : 0)
-
-h19_setinsert(new)
-char new;
-{
-       h19_ninsert = new;
-}
+#define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O')
 
 h19_setmodes(new)
 
 h19_setmodes(new)
+register new;
 {
 {
-       h19_nmodes = new & WWM_REV;
-}
+       register diff;
 
 
-h19_insline()
-{
-       esc();
-       pc(L);
-       ILPAD();
+       diff = new ^ tt.tt_modes;
+       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_delline()
+h19_insline(n)
 {
 {
-       esc();
-       pc(M);
-       ILPAD();
+       while (--n >= 0) {
+               ttesc('L');
+               ILPAD();
+       }
 }
 
 }
 
-h19_putc(c)
-register char c;
+h19_delline(n)
 {
 {
-       SETMODES(h19_nmodes);
-       SETINSERT(h19_ninsert);
-       if (c & 0x80) {
-               SETGRAPHICS(1);
-               putchar(c & 0x7f);
-       } else {
-               SETGRAPHICS(0);
-               putchar(c);
+       while (--n >= 0) {
+               ttesc('M');
+               ILPAD();
        }
        }
-       if (h19_insert)
-               ICPAD();
-       h19_col++;
 }
 
 }
 
-h19_write(start, end)
-register char *start, *end;
+h19_putc(c)
+register char c;
 {
 {
-       register char c;
-
-       SETMODES(h19_nmodes);
-       SETINSERT(h19_ninsert);
-       if (h19_insert) {
-               while (start <= end) {
-                       if ((c = *start++) & 0x80) {
-                               SETGRAPHICS(1);
-                               putchar(c & 0x7f);
-                       } else {
-                               SETGRAPHICS(0);
-                               putchar(c);
-                       }
-                       ICPAD();
-                       h19_col++;
-               }
-       } else {
-               h19_col += end - start + 1;
-               while (start <= end)
-                       if ((c = *start++) & 0x80) {
-                               SETGRAPHICS(1);
-                               putchar(c & 0x7f);
-                       } else {
-                               SETGRAPHICS(0);
-                               putchar(c);
-                       }
-       }
+       if (tt.tt_nmodes != tt.tt_modes)
+               (*tt.tt_setmodes)(tt.tt_nmodes);
+       if (tt.tt_insert)
+               H19_SETINSERT(0);
+       ttputc(c);
+       if (++tt.tt_col == NCOL)
+               tt.tt_col = NCOL - 1;
 }
 
 }
 
-h19_blank(n)
+h19_write(p, n)
+register char *p;
 register n;
 {
 register n;
 {
-       if (n <= 0)
-               return;
-       SETMODES(h19_nmodes);
-       SETINSERT(h19_ninsert);
-       if (h19_insert) {
-               while (--n >= 0) {
-                       putchar(' ');
-                       ICPAD();
-                       h19_col++;
-               }
-       } else {
-               h19_col += n;
-               while (--n >= 0)
-                       putchar(' ');
-       }
+       if (tt.tt_nmodes != tt.tt_modes)
+               (*tt.tt_setmodes)(tt.tt_nmodes);
+       if (tt.tt_insert)
+               H19_SETINSERT(0);
+       ttwrite(p, n);
+       tt.tt_col += n;
+       if (tt.tt_col == NCOL)
+               tt.tt_col = NCOL - 1;
 }
 
 h19_move(row, col)
 register char row, col;
 {
 }
 
 h19_move(row, col)
 register char row, col;
 {
-       if (h19_row == row) {
-               if (h19_col == col)
+       if (tt.tt_row == row) {
+               if (tt.tt_col == col)
                        return;
                        return;
-               if (h19_col == col - 1) {
-                       esc();
-                       pc(C);
+               if (col == 0) {
+                       ttctrl('m');
+                       goto out;
+               }
+               if (tt.tt_col == col - 1) {
+                       ttesc('C');
                        goto out;
                        goto out;
-               } else if (h19_col == col + 1) {
-                       pc(\b);
+               }
+               if (tt.tt_col == col + 1) {
+                       ttctrl('h');
                        goto out;
                }
        }
                        goto out;
                }
        }
-       if (h19_col == col) {
-               if (h19_row == row + 1) {
-                       esc();
-                       pc(A);
+       if (tt.tt_col == col) {
+               if (tt.tt_row == row + 1) {
+                       ttesc('A');
                        goto out;
                        goto out;
-               } else if (h19_row == row + 1) {
-                       pc(\n);
+               }
+               if (tt.tt_row == row - 1) {
+                       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);
-       putchar(' ' + row);
-       putchar(' ' + col);
+       ttesc('Y');
+       ttputc(' ' + row);
+       ttputc(' ' + col);
 out:
 out:
-       h19_col = col;
-       h19_row = row;
+       tt.tt_col = col;
+       tt.tt_row = row;
 }
 
 }
 
-h19_init()
+h19_start()
 {
 {
-       if (h19_VS)
-               fputs(h19_VS, stdout);
-       esc();
-       pc(w);
-       esc();
-       pc(E);
-       h19_col = h19_row = 0;
-       h19_insert = 0;
-       h19_graphics = 0;
-       h19_modes = 0;
+       if (gen_VS)
+               ttxputs(gen_VS);
+       ttesc('w');
+       ttesc('E');
+       tt.tt_col = tt.tt_row = 0;
+       tt.tt_insert = 0;
+       tt.tt_nmodes = tt.tt_modes = 0;
 }
 
 h19_end()
 {
 }
 
 h19_end()
 {
-       SETMODES(0);
-       SETINSERT(0);
-       SETGRAPHICS(0);
-       if (h19_VE)
-               fputs(h19_VE, stdout);
-       esc();
-       pc(v);
+       if (tt.tt_insert)
+               H19_SETINSERT(0);
+       if (gen_VE)
+               ttxputs(gen_VE);
+       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)
+register char c;
+{
+       if (tt.tt_nmodes != tt.tt_modes)
+               (*tt.tt_setmodes)(tt.tt_nmodes);
+       if (!tt.tt_insert)
+               H19_SETINSERT(1);
+       ttputc(c);
+       if (tt.tt_insert)
+               ICPAD();
+       if (++tt.tt_col == NCOL)
+               tt.tt_col = NCOL - 1;
+}
+
+h19_delchar(n)
+{
+       while (--n >= 0)
+               ttesc('N');
 }
 
 }
 
-h19_delchar()
+h19_scroll_down(n)
 {
 {
-       esc();
-       pc(N);
+       h19_move(NROW - 1, 0);
+       while (--n >= 0)
+               ttctrl('j');
+}
+
+h19_scroll_up(n)
+{
+       h19_move(0, 0);
+       while (--n >= 0)
+               ttesc('I');
 }
 
 tt_h19()
 }
 
 tt_h19()
@@ -239,25 +250,29 @@ tt_h19()
        float cpms = (float) wwbaud / 10000;    /* char per ms */
 
        h19_msp10c = 10 / cpms;                 /* ms per 10 char */
        float cpms = (float) wwbaud / 10000;    /* char per ms */
 
        h19_msp10c = 10 / cpms;                 /* ms per 10 char */
-       h19_VS = tt_xgetstr("vs");
-       h19_VE = tt_xgetstr("ve");
-       tt.tt_setinsert = h19_setinsert;
-       tt.tt_setmodes = h19_setmodes;
+       gen_VS = ttxgetstr("vs");
+       gen_VE = ttxgetstr("ve");
+
+       tt.tt_start = h19_start;
+       tt.tt_end = h19_end;
+
        tt.tt_insline = h19_insline;
        tt.tt_delline = h19_delline;
        tt.tt_insline = h19_insline;
        tt.tt_delline = h19_delline;
+       tt.tt_inschar = h19_inschar;
        tt.tt_delchar = h19_delchar;
        tt.tt_delchar = h19_delchar;
-       tt.tt_blank = h19_blank;
-       tt.tt_init = h19_init;
-       tt.tt_end = h19_end;
        tt.tt_clreol = h19_clreol;
        tt.tt_clreos = h19_clreos;
        tt.tt_clear = h19_clear;
        tt.tt_move = h19_move;
        tt.tt_write = h19_write;
        tt.tt_putc = h19_putc;
        tt.tt_clreol = h19_clreol;
        tt.tt_clreos = h19_clreos;
        tt.tt_clear = h19_clear;
        tt.tt_move = h19_move;
        tt.tt_write = h19_write;
        tt.tt_putc = h19_putc;
-       tt.tt_ncol = 80;
-       tt.tt_nrow = 24;
-       tt.tt_availmodes = WWM_REV;
+       tt.tt_scroll_down = h19_scroll_down;
+       tt.tt_scroll_up = h19_scroll_up;
+       tt.tt_setmodes = h19_setmodes;
+
+       tt.tt_ncol = NCOL;
+       tt.tt_nrow = NROW;
+       tt.tt_availmodes = WWM_REV|WWM_GRP;
        tt.tt_frame = h19_frame;
        return 0;
 }
        tt.tt_frame = h19_frame;
        return 0;
 }