insert mode bug fix and cleanup
[unix-history] / usr / src / usr.bin / window / wwinit.c
index b62fe0d..be9bfcb 100644 (file)
@@ -3,15 +3,20 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.30 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwinit.c   3.35 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -31,8 +36,12 @@ wwinit()
        wwhead.ww_back = &wwhead;
 
        s = sigblock(sigmask(SIGIO));
        wwhead.ww_back = &wwhead;
 
        s = sigblock(sigmask(SIGIO));
-       if (signal(SIGIO, wwrint) == BADSIG)
+       if (signal(SIGIO, wwrint) == BADSIG ||
+           signal(SIGCHLD, wwchild) == BADSIG ||
+           signal(SIGPIPE, SIG_IGN) == BADSIG) {
+               wwerrno = WWE_SYS;
                return -1;
                return -1;
+       }
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
@@ -71,13 +80,12 @@ wwinit()
        }
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
 
        }
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
 
-       if (ttinit() < 0)
+       if (xxinit() < 0)
                goto bad;
        wwnrow = tt.tt_nrow;
        wwncol = tt.tt_ncol;
        wwavailmodes = tt.tt_availmodes;
        wwwrap = tt.tt_wrap;
                goto bad;
        wwnrow = tt.tt_nrow;
        wwncol = tt.tt_ncol;
        wwavailmodes = tt.tt_availmodes;
        wwwrap = tt.tt_wrap;
-       (*tt.tt_init)();
 
        if (wwavailmodes & WWM_REV)
                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
 
        if (wwavailmodes & WWM_REV)
                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
@@ -118,6 +126,12 @@ wwinit()
        for (i = 0; i < wwnrow; i++)
                wwtouched[i] = 0;
 
        for (i = 0; i < wwnrow; i++)
                wwtouched[i] = 0;
 
+       wwupd = (struct ww_update *) malloc((unsigned) wwnrow * sizeof *wwupd);
+       if (wwupd == 0) {
+               wwerrno = WWE_NOMEM;
+               goto bad;
+       }
+
        wwindex[WWX_NOBODY] = &wwnobody;
        wwnobody.ww_order = NWW;
 
        wwindex[WWX_NOBODY] = &wwnobody;
        wwnobody.ww_order = NWW;
 
@@ -136,7 +150,7 @@ wwinit()
                wwaddcap1(WWT_USR, &kp);
        if (tt.tt_insline && tt.tt_delline || tt.tt_setscroll)
                wwaddcap1(WWT_ALDL, &kp);
                wwaddcap1(WWT_USR, &kp);
        if (tt.tt_insline && tt.tt_delline || tt.tt_setscroll)
                wwaddcap1(WWT_ALDL, &kp);
-       if (tt.tt_hasinsert)
+       if (tt.tt_inschar || tt.tt_insspace)
                wwaddcap1(WWT_IMEI, &kp);
        if (tt.tt_delchar)
                wwaddcap1(WWT_DC, &kp);
                wwaddcap1(WWT_IMEI, &kp);
        if (tt.tt_delchar)
                wwaddcap1(WWT_DC, &kp);
@@ -166,8 +180,10 @@ wwinit()
         */
        (void) setenv("TERM", WWT_TERM, 1);
 
         */
        (void) setenv("TERM", WWT_TERM, 1);
 
-       (void) signal(SIGPIPE, SIG_IGN);
        (void) sigsetmask(s);
        (void) sigsetmask(s);
+       /* catch typeahead before ASYNC was set */
+       (void) kill(getpid(), SIGIO);
+       xxstart();
        return 0;
 bad:
        /*
        return 0;
 bad:
        /*