4.3BSD beta release manual page
[unix-history] / usr / src / usr.bin / window / ttgeneric.c
index cc9f664..f82be2f 100644 (file)
@@ -1,23 +1,27 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)ttgeneric.c 3.13 83/08/23";
+static char sccsid[] = "@(#)ttgeneric.c        3.24 %G%";
 #endif
 
 #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.
+ */
+
 #include "ww.h"
 #include "tt.h"
 
 #include "ww.h"
 #include "tt.h"
 
+char PC, *BC, *UP;
+short ospeed;
 char *tgoto();
 
 char *tgoto();
 
-char gen_frame[16] = {
+short gen_frame[16] = {
        ' ', '|', '-', '+',
        '|', '|', '+', '+',
        '-', '+', '-', '+',
        '+', '+', '+', '+'
 };
 
        ' ', '|', '-', '+',
        '|', '|', '+', '+',
        '-', '+', '-', '+',
        '+', '+', '+', '+'
 };
 
-int gen_row, gen_col;
-char gen_modes, gen_nmodes;
-char gen_insert, gen_ninsert;
-
 char *gen_CM;
 char *gen_IM;
 char *gen_IC;
 char *gen_CM;
 char *gen_IM;
 char *gen_IC;
@@ -43,51 +47,39 @@ char *gen_BC;
 char *gen_ND;
 char *gen_HO;
 char *gen_NL;
 char *gen_ND;
 char *gen_HO;
 char *gen_NL;
+char *gen_AS;
+char *gen_AE;
 char gen_MI;
 char gen_MS;
 char gen_AM;
 char gen_OS;
 char gen_BS;
 char gen_MI;
 char gen_MS;
 char gen_AM;
 char gen_OS;
 char gen_BS;
+char gen_DB;
 int gen_CO;
 int gen_LI;
 int gen_UG;
 int gen_SG;
 
 int gen_CO;
 int gen_LI;
 int gen_UG;
 int gen_SG;
 
-#define pc(c) putchar('c')
-#define ps(s) fputs((s), stdout)
+#define ps(s) ttputs(s)
 
 gen_setinsert(new)
 
 gen_setinsert(new)
-{
-       gen_ninsert = new;
-}
-
-gen_setinsert1(new)
 char new;
 {
 char new;
 {
-       if (gen_insert == new)
-               return;
        if (new) {
                if (gen_IM)
                        ps(gen_IM);
        } else
                if (gen_EI)
                        ps(gen_EI);
        if (new) {
                if (gen_IM)
                        ps(gen_IM);
        } else
                if (gen_EI)
                        ps(gen_EI);
-       gen_insert = new;
+       tt.tt_insert = new;
 }
 
 gen_setmodes(new)
 }
 
 gen_setmodes(new)
-char new;
-{
-       gen_nmodes = new & tt.tt_availmodes;
-}
-
-gen_setmodes1(new)
 register new;
 {
        register diff;
 
 register new;
 {
        register diff;
 
-       if ((diff = new ^ gen_modes) == 0)
-               return;
+       diff = new ^ tt.tt_modes;
        if (diff & WWM_REV) {
                if (new & WWM_REV) {
                        if (gen_SO)
        if (diff & WWM_REV) {
                if (new & WWM_REV) {
                        if (gen_SO)
@@ -104,130 +96,115 @@ register new;
                        if (gen_UE)
                                ps(gen_UE);
        }
                        if (gen_UE)
                                ps(gen_UE);
        }
-       gen_modes = new;
+       if (diff & WWM_GRP) {
+               if (new & WWM_GRP) {
+                       if (gen_AS)
+                               ps(gen_AS);
+               } else
+                       if (gen_AE)
+                               ps(gen_AE);
+       }
+       tt.tt_modes = new;
 }
 
 gen_insline()
 {
 }
 
 gen_insline()
 {
-       if (gen_modes)                  /* for concept 100 */
-               gen_setmodes1(0);
+       if (tt.tt_modes)                        /* for concept 100 */
+               gen_setmodes(0);
        if (gen_AL)
        if (gen_AL)
-               tt_tputs(gen_AL, gen_LI - gen_row);
+               tttputs(gen_AL, gen_LI - tt.tt_row);
 }
 
 gen_delline()
 {
 }
 
 gen_delline()
 {
-       if (gen_modes)                  /* for concept 100 */
-               gen_setmodes1(0);
+       if (tt.tt_modes)                        /* for concept 100 */
+               gen_setmodes(0);
        if (gen_DL)
        if (gen_DL)
-               tt_tputs(gen_DL, gen_LI - gen_row);
+               tttputs(gen_DL, gen_LI - tt.tt_row);
 }
 
 gen_putc(c)
 register char c;
 {
 }
 
 gen_putc(c)
 register char c;
 {
-       gen_setinsert1(gen_ninsert);
-       gen_setmodes1(gen_nmodes);
-       if (gen_insert) {
+       if (tt.tt_ninsert != tt.tt_insert)
+               gen_setinsert(tt.tt_ninsert);
+       if (tt.tt_nmodes != tt.tt_modes)
+               gen_setmodes(tt.tt_nmodes);
+       if (tt.tt_insert) {
                if (gen_IC)
                if (gen_IC)
-                       tt_tputs(gen_IC, gen_CO - gen_col);
-               putchar(c);
+                       tttputs(gen_IC, gen_CO - tt.tt_col);
+               ttputc(c);
                if (gen_IP)
                if (gen_IP)
-                       tt_tputs(gen_IP, gen_CO - gen_col);
+                       tttputs(gen_IP, gen_CO - tt.tt_col);
        } else
        } else
-               putchar(c);
-       if (++gen_col == gen_CO)
+               ttputc(c);
+       if (++tt.tt_col == gen_CO)
                if (gen_AM)
                if (gen_AM)
-                       gen_col = 0, gen_row++;
+                       tt.tt_col = 0, tt.tt_row++;
                else
                else
-                       gen_col--;
+                       tt.tt_col--;
 }
 
 }
 
-gen_write(start, end)
-register char *start, *end;
-{
-       gen_setinsert1(gen_ninsert);
-       gen_setmodes1(gen_nmodes);
-       if (gen_insert) {
-               while (start <= end) {
-                       if (gen_IC)
-                               tt_tputs(gen_IC, gen_CO - gen_col);
-                       putchar(*start++);
-                       if (gen_IP)
-                               tt_tputs(gen_IP, gen_CO - gen_col);
-                       gen_col++;
-               }
-       } else {
-               gen_col += end - start + 1;
-               while (start <= end)
-                       putchar(*start++);
-       }
-       if (gen_col == gen_CO)
-               if (gen_AM)
-                       gen_col = 0, gen_row++;
-               else
-                       gen_col--;
-}
-
-gen_blank(n)
+gen_write(p, n)
+register char *p;
 register n;
 {
 register n;
 {
-       if (n <= 0)
-               return;
-       gen_setinsert1(gen_ninsert);
-       gen_setmodes1(gen_nmodes);
-       if (gen_insert) {
+       if (tt.tt_ninsert != tt.tt_insert)
+               gen_setinsert(tt.tt_ninsert);
+       if (tt.tt_nmodes != tt.tt_modes)
+               gen_setmodes(tt.tt_nmodes);
+       if (tt.tt_insert) {
                while (--n >= 0) {
                        if (gen_IC)
                while (--n >= 0) {
                        if (gen_IC)
-                               tt_tputs(gen_IC, gen_CO - gen_col);
-                       putchar(' ');
+                               tttputs(gen_IC, gen_CO - tt.tt_col);
+                       ttputc(*p++);
                        if (gen_IP)
                        if (gen_IP)
-                               tt_tputs(gen_IP, gen_CO - gen_col);
-                       gen_col++;
+                               tttputs(gen_IP, gen_CO - tt.tt_col);
+                       tt.tt_col++;
                }
        } else {
                }
        } else {
-               gen_col += n;
+               tt.tt_col += n;
                while (--n >= 0)
                while (--n >= 0)
-                       putchar(' ');
+                       ttputc(*p++);
        }
        }
-       if (gen_col == gen_CO)
+       if (tt.tt_col == gen_CO)
                if (gen_AM)
                if (gen_AM)
-                       gen_col = 0, gen_row++;
+                       tt.tt_col = 0, tt.tt_row++;
                else
                else
-                       gen_col--;
+                       tt.tt_col--;
 }
 
 gen_move(row, col)
 register char row, col;
 {
 }
 
 gen_move(row, col)
 register char row, col;
 {
-       if (gen_row == row && gen_col == col)
+       if (tt.tt_row == row && tt.tt_col == col)
                return;
                return;
-       if (!gen_MI && gen_insert)
+       if (!gen_MI && tt.tt_insert)
                gen_setinsert(0);
                gen_setinsert(0);
-       if (!gen_MS && gen_modes)
+       if (!gen_MS && tt.tt_modes)
                gen_setmodes(0);
                gen_setmodes(0);
-       if (gen_row == row) {
-               if (gen_col == col)
+       if (tt.tt_row == row) {
+               if (tt.tt_col == col)
                        return;
                        return;
-               if (gen_col == col - 1) {
+               if (tt.tt_col == col - 1) {
                        if (gen_ND) {
                                ps(gen_ND);
                                goto out;
                        }
                        if (gen_ND) {
                                ps(gen_ND);
                                goto out;
                        }
-               } else if (gen_col == col + 1) {
+               } else if (tt.tt_col == col + 1) {
                        if (gen_BC) {
                                ps(gen_BC);
                                goto out;
                        }
                }
        }
                        if (gen_BC) {
                                ps(gen_BC);
                                goto out;
                        }
                }
        }
-       if (gen_col == col) {
-               if (gen_row == row + 1) {
+       if (tt.tt_col == col) {
+               if (tt.tt_row == row + 1) {
                        if (gen_UP) {
                                ps(gen_UP);
                                goto out;
                        }
                        if (gen_UP) {
                                ps(gen_UP);
                                goto out;
                        }
-               } else if (gen_row == row + 1) {
+               } else if (tt.tt_row == row + 1) {
                        if (gen_NL) {
                                ps(gen_NL);
                                goto out;
                        if (gen_NL) {
                                ps(gen_NL);
                                goto out;
@@ -240,8 +217,8 @@ register char row, col;
        }
        ps(tgoto(gen_CM, col, row));
 out:
        }
        ps(tgoto(gen_CM, col, row));
 out:
-       gen_col = col;
-       gen_row = row;
+       tt.tt_col = col;
+       tt.tt_row = row;
 }
 
 gen_init()
 }
 
 gen_init()
@@ -252,15 +229,15 @@ gen_init()
                ps(gen_TI);
        if (gen_CL)
                ps(gen_CL);
                ps(gen_TI);
        if (gen_CL)
                ps(gen_CL);
-       gen_col = gen_row = 0;
-       gen_ninsert = gen_insert = 0;
-       gen_nmodes = gen_modes = 0;
+       tt.tt_col = tt.tt_row = 0;
+       tt.tt_ninsert = tt.tt_insert = 0;
+       tt.tt_nmodes = tt.tt_modes = 0;
 }
 
 gen_end()
 {
 }
 
 gen_end()
 {
-       gen_setmodes1(0);
-       gen_setinsert1(0);
+       gen_setmodes(0);
+       gen_setinsert(0);
        if (gen_TE)
                ps(gen_TE);
        if (gen_VE)
        if (gen_TE)
                ps(gen_TE);
        if (gen_VE)
@@ -269,24 +246,24 @@ gen_end()
 
 gen_clreol()
 {
 
 gen_clreol()
 {
-       if (gen_modes)                  /* for concept 100 */
-               gen_setmodes1(0);
+       if (tt.tt_modes)                        /* for concept 100 */
+               gen_setmodes(0);
        if (gen_CE)
        if (gen_CE)
-               tt_tputs(gen_CE, gen_CO - gen_col);
+               tttputs(gen_CE, gen_CO - tt.tt_col);
 }
 
 gen_clreos()
 {
 }
 
 gen_clreos()
 {
-       if (gen_modes)                  /* for concept 100 */
-               gen_setmodes1(0);
+       if (tt.tt_modes)                        /* for concept 100 */
+               gen_setmodes(0);
        if (gen_CD)
        if (gen_CD)
-               tt_tputs(gen_CD, gen_LI - gen_row);
+               tttputs(gen_CD, gen_LI - tt.tt_row);
 }
 
 gen_clear()
 {
 }
 
 gen_clear()
 {
-       if (gen_modes)                  /* for concept 100 */
-               gen_setmodes1(0);
+       if (tt.tt_modes)                        /* for concept 100 */
+               gen_setmodes(0);
        if (gen_CL)
                ps(gen_CL);
 }
        if (gen_CL)
                ps(gen_CL);
 }
@@ -294,41 +271,44 @@ gen_clear()
 gen_delchar()
 {
        if (gen_DC)
 gen_delchar()
 {
        if (gen_DC)
-               tt_tputs(gen_DC, gen_CO - gen_col);
+               tttputs(gen_DC, gen_CO - tt.tt_col);
 }
 
 tt_generic()
 {
 }
 
 tt_generic()
 {
-       gen_CM = tt_xgetstr("cm");              /* may not work */
-       gen_IM = tt_xgetstr("im");
-       gen_IC = tt_tgetstr("ic");
-       gen_IP = tt_tgetstr("ip");
-       gen_EI = tt_xgetstr("ei");
-       gen_DC = tt_tgetstr("dc");
-       gen_AL = tt_tgetstr("al");
-       gen_DL = tt_tgetstr("dl");
-       gen_CE = tt_tgetstr("ce");
-       gen_CD = tt_tgetstr("cd");
-       gen_CL = tt_xgetstr("cl");
-       gen_VS = tt_xgetstr("vs");
-       gen_VE = tt_xgetstr("ve");
-       gen_TI = tt_xgetstr("ti");
-       gen_TE = tt_xgetstr("te");
-       gen_SO = tt_xgetstr("so");
-       gen_SE = tt_xgetstr("se");
-       gen_US = tt_xgetstr("us");
-       gen_UE = tt_xgetstr("ue");
-       gen_UP = tt_xgetstr("up");
-       gen_PC = tt_tgetstr("pc");
-       gen_BC = tt_xgetstr("bc");
-       gen_ND = tt_xgetstr("nd");
-       gen_HO = tt_xgetstr("ho");
-       gen_NL = tt_xgetstr("nl");
+       gen_CM = ttxgetstr("cm");               /* may not work */
+       gen_IM = ttxgetstr("im");
+       gen_IC = tttgetstr("ic");
+       gen_IP = tttgetstr("ip");
+       gen_EI = ttxgetstr("ei");
+       gen_DC = tttgetstr("dc");
+       gen_AL = tttgetstr("al");
+       gen_DL = tttgetstr("dl");
+       gen_CE = tttgetstr("ce");
+       gen_CD = tttgetstr("cd");
+       gen_CL = ttxgetstr("cl");
+       gen_VS = ttxgetstr("vs");
+       gen_VE = ttxgetstr("ve");
+       gen_TI = ttxgetstr("ti");
+       gen_TE = ttxgetstr("te");
+       gen_SO = ttxgetstr("so");
+       gen_SE = ttxgetstr("se");
+       gen_US = ttxgetstr("us");
+       gen_UE = ttxgetstr("ue");
+       gen_UP = ttxgetstr("up");
+       gen_PC = tttgetstr("pc");
+       gen_BC = ttxgetstr("bc");
+       gen_ND = ttxgetstr("nd");
+       gen_HO = ttxgetstr("ho");
+       gen_NL = ttxgetstr("nl");
+       gen_AS = ttxgetstr("as");
+       gen_AE = ttxgetstr("ae");
        gen_MI = tgetflag("mi");
        gen_MS = tgetflag("ms");
        gen_AM = tgetflag("am");
        gen_OS = tgetflag("os");
        gen_BS = tgetflag("bs");
        gen_MI = tgetflag("mi");
        gen_MS = tgetflag("ms");
        gen_AM = tgetflag("am");
        gen_OS = tgetflag("os");
        gen_BS = tgetflag("bs");
+       gen_DB = tgetflag("db");
        gen_CO = tgetnum("co");
        gen_LI = tgetnum("li");
        gen_UG = tgetnum("ug");
        gen_CO = tgetnum("co");
        gen_LI = tgetnum("li");
        gen_UG = tgetnum("ug");
@@ -340,20 +320,13 @@ tt_generic()
        if (gen_NL == 0)
                gen_NL = "\n";
        if (gen_BC == 0 && gen_BS)
        if (gen_NL == 0)
                gen_NL = "\n";
        if (gen_BC == 0 && gen_BS)
-               gen_BC == "\b";
-
-       {
-               extern char PC, *BC, *UP;
-               extern short ospeed;
+               gen_BC = "\b";
 
 
-               PC = gen_PC ? *gen_PC : 0;
-               BC = gen_BC;
-               UP = gen_UP;
-               ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
-       }
+       PC = gen_PC ? *gen_PC : 0;
+       BC = gen_BC;
+       UP = gen_UP;
+       ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
 
 
-       if (gen_IM)
-               tt.tt_setinsert = gen_setinsert;
        if (gen_DC)
                tt.tt_delchar = gen_delchar;
        if (gen_AL)
        if (gen_DC)
                tt.tt_delchar = gen_delchar;
        if (gen_AL)
@@ -374,13 +347,15 @@ tt_generic()
                tt.tt_availmodes |= WWM_REV;
        if (gen_US)
                tt.tt_availmodes |= WWM_UL;
                tt.tt_availmodes |= WWM_REV;
        if (gen_US)
                tt.tt_availmodes |= WWM_UL;
+       if (gen_AS)
+               tt.tt_availmodes |= WWM_GRP;
+       tt.tt_hasinsert = gen_IM != 0;
        tt.tt_wrap = gen_AM;
        tt.tt_wrap = gen_AM;
+       tt.tt_retain = gen_DB;
        tt.tt_ncol = gen_CO;
        tt.tt_nrow = gen_LI;
        tt.tt_init = gen_init;
        tt.tt_end = gen_end;
        tt.tt_ncol = gen_CO;
        tt.tt_nrow = gen_LI;
        tt.tt_init = gen_init;
        tt.tt_end = gen_end;
-       tt.tt_setmodes = gen_setmodes;
-       tt.tt_blank = gen_blank;
        tt.tt_write = gen_write;
        tt.tt_putc = gen_putc;
        tt.tt_move = gen_move;
        tt.tt_write = gen_write;
        tt.tt_putc = gen_putc;
        tt.tt_move = gen_move;