ttwrite added
[unix-history] / usr / src / usr.bin / window / wwinit.c
index 83d8b76..dc8c2b2 100644 (file)
@@ -1,32 +1,35 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwinit.c    3.16 84/03/23";
+static char sccsid[] = "@(#)wwinit.c   3.25 %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 <sys/signal.h>
 #include <fcntl.h>
 #include "ww.h"
 #include "tt.h"
 #include <sys/signal.h>
 #include <fcntl.h>
+#include "char.h"
 
 wwinit()
 {
        register i, j;
        char *kp;
        register char **p, **q;
 
 wwinit()
 {
        register i, j;
        char *kp;
        register char **p, **q;
-       char **env, **termcap;
+       char **env, **termcap = 0;
        extern char **environ;
        extern char **environ;
+       int s;
 
 
-#ifndef O_4_1A
        wwdtablesize = getdtablesize();
        wwdtablesize = getdtablesize();
-#else
-#include <sys/param.h>
-       wwdtablesize = NOFILE;
-#endif
        wwhead.ww_forw = &wwhead;
        wwhead.ww_back = &wwhead;
 
        wwhead.ww_forw = &wwhead;
        wwhead.ww_back = &wwhead;
 
+       s = sigblock(sigmask(SIGIO));
        if (signal(SIGIO, wwrint) == BADSIG)
                return -1;
        if (signal(SIGIO, wwrint) == BADSIG)
                return -1;
-       (void) sighold(SIGIO);
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
@@ -52,8 +55,7 @@ wwinit()
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
-
-       if (wwsettty(0, &wwnewtty) < 0)
+       if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
@@ -117,12 +119,12 @@ wwinit()
        wwnobody.ww_order = NWW;
 
        kp = wwkeys;
        wwnobody.ww_order = NWW;
 
        kp = wwkeys;
-       addcap("kb", &kp);
-       addcap("ku", &kp);
-       addcap("kd", &kp);
-       addcap("kl", &kp);
-       addcap("kr", &kp);
-       addcap("kh", &kp);
+       wwaddcap("kb", &kp);
+       wwaddcap("ku", &kp);
+       wwaddcap("kd", &kp);
+       wwaddcap("kl", &kp);
+       wwaddcap("kr", &kp);
+       wwaddcap("kh", &kp);
        if ((j = tgetnum("kn")) >= 0) {
                char cap[32];
                int i;
        if ((j = tgetnum("kn")) >= 0) {
                char cap[32];
                int i;
@@ -132,9 +134,9 @@ wwinit()
                        ;
                for (i = 1; i <= j; i++) {
                        (void) sprintf(cap, "k%d", i);
                        ;
                for (i = 1; i <= j; i++) {
                        (void) sprintf(cap, "k%d", i);
-                       addcap(cap, &kp);
+                       wwaddcap(cap, &kp);
                        cap[0] = 'l';
                        cap[0] = 'l';
-                       addcap(cap, &kp);
+                       wwaddcap(cap, &kp);
                }
        }
        for (i = 0, p = environ; *p++; i++)
                }
        }
        for (i = 0, p = environ; *p++; i++)
@@ -153,21 +155,21 @@ wwinit()
        *q = 0;
        environ = env;
 
        *q = 0;
        environ = env;
 
-       (void) sigrelse(SIGIO);
+       (void) signal(SIGPIPE, SIG_IGN);
+       (void) sigsetmask(s);
        return 0;
 bad:
        /*
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
        return 0;
 bad:
        /*
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
-       (void) wwsettty(0, &wwoldtty);
+       (void) wwsettty(0, &wwoldtty, &wwnewtty);
        (void) signal(SIGIO, SIG_DFL);
        (void) signal(SIGIO, SIG_DFL);
-       (void) sigrelse(SIGIO);
+       (void) sigsetmask(s);
        return -1;
 }
 
        return -1;
 }
 
-static
-addcap(cap, kp)
+wwaddcap(cap, kp)
 register char *cap;
 register char **kp;
 {
 register char *cap;
 register char **kp;
 {