date and time created 83/08/09 18:37:52 by edward
[unix-history] / usr / src / usr.bin / window / wwinit.c
index 0624298..82f4c07 100644 (file)
@@ -1,26 +1,21 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwinit.c    1.3 83/07/18";
+static char *sccsid = "@(#)wwinit.c    2.1.1.1 83/08/09";
 #endif
 
 #include "ww.h"
 
 #endif
 
 #include "ww.h"
 
-struct ww_tty wwoldtty;
-struct ww_tty wwnewtty = {
-       { 0, 0, -1, -1, 0 },
-       { -1, -1, -1, -1, -1, -1 },
-       { -1, -1, -1, -1, -1, -1 },
-       0, 0, 0
-};
+static char *kp = wwkeys;
 
 wwinit()
 {
 
 wwinit()
 {
-       static char done = 0;
+       register i, j;
+       int kn;
 
 
-       if (done)
-               return 0;
-       done++;
+       wwdtablesize = getdtablesize();
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
+       wwwintty = wwoldtty;
+       wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        wwnewtty.ww_sgttyb.sg_flags = wwoldtty.ww_sgttyb.sg_flags;
        wwnewtty.ww_sgttyb.sg_ispeed = wwoldtty.ww_sgttyb.sg_ispeed;
        wwnewtty.ww_sgttyb.sg_ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
        wwnewtty.ww_sgttyb.sg_flags = wwoldtty.ww_sgttyb.sg_flags;
        wwnewtty.ww_sgttyb.sg_ispeed = wwoldtty.ww_sgttyb.sg_ispeed;
        wwnewtty.ww_sgttyb.sg_ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
@@ -30,11 +25,89 @@ wwinit()
        wwnewtty.ww_sgttyb.sg_flags |= CBREAK;
        wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD);
        wwnewtty.ww_lmode |= LLITOUT;
        wwnewtty.ww_sgttyb.sg_flags |= CBREAK;
        wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD);
        wwnewtty.ww_lmode |= LLITOUT;
-       wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (wwsettty(0, &wwnewtty) < 0)
        if (wwsettty(0, &wwnewtty) < 0)
-               return -1;
-       if (Winit(2, 1) != 0)
-               return -1;
-       WSetRealCursor = 1;
+               goto bad;
+
+       if ((wwterm = getenv("TERM")) == 0)
+               goto bad;
+       if (tgetent(wwtermcap, wwterm) != 1)
+               goto bad;
+       wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
+
+       if (ttinit() < 0)
+               goto bad;
+       wwnrow = tt.tt_nrow;
+       wwncol = tt.tt_ncol;
+       (*tt.tt_reset)();
+       (*tt.tt_clreos)();
+
+       if ((wwsmap = wwalloc(wwnrow, wwncol, sizeof (char))) == 0)
+               goto bad;
+       for (i = 0; i < wwnrow; i++)
+               for (j = 0; j < wwncol; j++)
+                       wwsmap[i][j] = WWX_NOBODY;
+       wwos = (union ww_char **)
+               wwalloc(wwnrow, wwncol, sizeof (union ww_char));
+       if (wwos == 0)
+               goto bad;
+       for (i = 0; i < wwnrow; i++)
+               for (j = 0; j < wwncol; j++)
+                       wwos[i][j].c_w = ' ';
+       wwns = (union ww_char **)
+               wwalloc(wwnrow, wwncol, sizeof (union ww_char));
+       if (wwns == 0)
+               goto bad;
+       for (i = 0; i < wwnrow; i++)
+               for (j = 0; j < wwncol; j++)
+                       wwns[i][j].c_w = ' ';
+
+       wwindex[WWX_NOBODY] = &wwnobody;
+       wwnobody.ww_order = NWW;
+
+       addcap("kb");
+       addcap("ku");
+       addcap("kd");
+       addcap("kl");
+       addcap("kr");
+       addcap("kh");
+       if ((kn = tgetnum("kn")) >= 0) {
+               char cap[5];
+               int i;
+
+               (void) sprintf(kp, "kn#%d:", kn);
+               for (; *kp; kp++)
+                       ;
+               for (i = 1; i <= kn; i++) {
+                       (void) sprintf(cap, "k%d", i);
+                       addcap(cap);
+                       cap[0] = 'l';
+                       addcap(cap);
+               }
+       }
        return 0;
        return 0;
+bad:
+       (void) wwsettty(0, &wwoldtty);
+       return -1;
+}
+
+static
+addcap(cap)
+register char *cap;
+{
+       char tbuf[512];
+       char *tp = tbuf;
+       register char *str, *p;
+
+       if ((str = tgetstr(cap, &tp)) != 0) {
+               while (*kp++ = *cap++)
+                       ;
+               kp[-1] = '=';
+               while (*str) {
+                       for (p = unctrl(*str++); *kp++ = *p++;)
+                               ;
+                       kp--;
+               }
+               *kp++ = ':';
+               *kp = 0;
+       }
 }
 }