Annotation of 43BSDReno/usr.bin/window/wwinit.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Edward Wang at The University of California, Berkeley.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted provided
        !             9:  * that: (1) source distributions retain this entire copyright notice and
        !            10:  * comment, and (2) distributions including binaries display the following
        !            11:  * acknowledgement:  ``This product includes software developed by the
        !            12:  * University of California, Berkeley and its contributors'' in the
        !            13:  * documentation or other materials provided with the distribution and in
        !            14:  * all advertising materials mentioning features or use of this software.
        !            15:  * Neither the name of the University nor the names of its contributors may
        !            16:  * be used to endorse or promote products derived from this software without
        !            17:  * specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)wwinit.c   3.39 (Berkeley) 6/6/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: #include "ww.h"
        !            28: #include "tt.h"
        !            29: #include <sys/signal.h>
        !            30: #include <fcntl.h>
        !            31: #include "char.h"
        !            32: 
        !            33: wwinit()
        !            34: {
        !            35:        register i, j;
        !            36:        char *kp;
        !            37:        int s;
        !            38: 
        !            39:        wwdtablesize = getdtablesize();
        !            40:        wwhead.ww_forw = &wwhead;
        !            41:        wwhead.ww_back = &wwhead;
        !            42: 
        !            43:        s = sigblock(sigmask(SIGIO));
        !            44:        if (signal(SIGIO, wwrint) == BADSIG ||
        !            45:            signal(SIGCHLD, wwchild) == BADSIG ||
        !            46:            signal(SIGPIPE, SIG_IGN) == BADSIG) {
        !            47:                wwerrno = WWE_SYS;
        !            48:                return -1;
        !            49:        }
        !            50: 
        !            51:        if (wwgettty(0, &wwoldtty) < 0)
        !            52:                return -1;
        !            53:        wwwintty = wwoldtty;
        !            54: #ifndef POSIX_TTY
        !            55:        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        !            56:        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        !            57:        wwnewtty.ww_sgttyb.sg_erase = -1;
        !            58:        wwnewtty.ww_sgttyb.sg_kill = -1;
        !            59:        wwnewtty.ww_sgttyb.sg_flags |= CBREAK;
        !            60:        wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD);
        !            61:        wwnewtty.ww_tchars.t_intrc = -1;
        !            62:        wwnewtty.ww_tchars.t_quitc = -1;
        !            63:        wwnewtty.ww_tchars.t_startc = -1;
        !            64:        wwnewtty.ww_tchars.t_stopc = -1;
        !            65:        wwnewtty.ww_tchars.t_eofc = -1;
        !            66:        wwnewtty.ww_tchars.t_brkc = -1;
        !            67:        wwnewtty.ww_ltchars.t_suspc = -1;
        !            68:        wwnewtty.ww_ltchars.t_dsuspc = -1;
        !            69:        wwnewtty.ww_ltchars.t_rprntc = -1;
        !            70:        wwnewtty.ww_ltchars.t_flushc = -1;
        !            71:        wwnewtty.ww_ltchars.t_werasc = -1;
        !            72:        wwnewtty.ww_ltchars.t_lnextc = -1;
        !            73:        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        !            74:        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
        !            75: #else
        !            76:        wwwintty.ww_termios.c_oflag &= ~OXTABS;
        !            77:        wwnewtty.ww_termios = wwoldtty.ww_termios;
        !            78:        wwnewtty.ww_termios.c_iflag &=
        !            79:                ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
        !            80:        wwnewtty.ww_termios.c_iflag |= INPCK;
        !            81:        wwnewtty.ww_termios.c_oflag = 0;
        !            82:        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        !            83:        wwnewtty.ww_termios.c_cflag |= CS8;
        !            84:        wwnewtty.ww_termios.c_lflag = 0;
        !            85:        for (i = 0; i < NCC; i++)
        !            86:                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
        !            87: #endif
        !            88:        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        !            89:        if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
        !            90:                goto bad;
        !            91: 
        !            92:        if ((wwterm = getenv("TERM")) == 0) {
        !            93:                wwerrno = WWE_BADTERM;
        !            94:                goto bad;
        !            95:        }
        !            96:        if (tgetent(wwtermcap, wwterm) != 1) {
        !            97:                wwerrno = WWE_BADTERM;
        !            98:                goto bad;
        !            99:        }
        !           100: #ifndef POSIX_TTY
        !           101:        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
        !           102: #else
        !           103: #ifdef CBAUD
        !           104:        wwbaud = wwbaudmap[wwoldtty.ww_termios.c_cflag & CBAUD];
        !           105: #else
        !           106:        wwbaud = wwoldtty.ww_termios.c_ospeed;
        !           107: #endif
        !           108: #endif
        !           109: 
        !           110:        if (xxinit() < 0)
        !           111:                goto bad;
        !           112:        wwnrow = tt.tt_nrow;
        !           113:        wwncol = tt.tt_ncol;
        !           114:        wwavailmodes = tt.tt_availmodes;
        !           115:        wwwrap = tt.tt_wrap;
        !           116: 
        !           117:        if (wwavailmodes & WWM_REV)
        !           118:                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
        !           119:        else if (wwavailmodes & WWM_UL)
        !           120:                wwcursormodes = WWM_UL;
        !           121: 
        !           122:        if ((wwib = malloc((unsigned) 512)) == 0)
        !           123:                goto bad;
        !           124:        wwibe = wwib + 512;
        !           125:        wwibq = wwibp = wwib;
        !           126: 
        !           127:        if ((wwsmap = wwalloc(0, 0, wwnrow, wwncol, sizeof (char))) == 0)
        !           128:                goto bad;
        !           129:        for (i = 0; i < wwnrow; i++)
        !           130:                for (j = 0; j < wwncol; j++)
        !           131:                        wwsmap[i][j] = WWX_NOBODY;
        !           132: 
        !           133:        wwos = (union ww_char **)
        !           134:                wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char));
        !           135:        if (wwos == 0)
        !           136:                goto bad;
        !           137:        for (i = 0; i < wwnrow; i++)
        !           138:                for (j = 0; j < wwncol; j++)
        !           139:                        wwos[i][j].c_w = ' ';
        !           140:        wwns = (union ww_char **)
        !           141:                wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char));
        !           142:        if (wwns == 0)
        !           143:                goto bad;
        !           144:        for (i = 0; i < wwnrow; i++)
        !           145:                for (j = 0; j < wwncol; j++)
        !           146:                        wwns[i][j].c_w = ' ';
        !           147: 
        !           148:        wwtouched = malloc((unsigned) wwnrow);
        !           149:        if (wwtouched == 0) {
        !           150:                wwerrno = WWE_NOMEM;
        !           151:                goto bad;
        !           152:        }
        !           153:        for (i = 0; i < wwnrow; i++)
        !           154:                wwtouched[i] = 0;
        !           155: 
        !           156:        wwupd = (struct ww_update *) malloc((unsigned) wwnrow * sizeof *wwupd);
        !           157:        if (wwupd == 0) {
        !           158:                wwerrno = WWE_NOMEM;
        !           159:                goto bad;
        !           160:        }
        !           161: 
        !           162:        wwindex[WWX_NOBODY] = &wwnobody;
        !           163:        wwnobody.ww_order = NWW;
        !           164: 
        !           165:        kp = wwwintermcap;
        !           166:        if (wwavailmodes & WWM_REV)
        !           167:                wwaddcap1(WWT_REV, &kp);
        !           168:        if (wwavailmodes & WWM_BLK)
        !           169:                wwaddcap1(WWT_BLK, &kp);
        !           170:        if (wwavailmodes & WWM_UL)
        !           171:                wwaddcap1(WWT_UL, &kp);
        !           172:        if (wwavailmodes & WWM_GRP)
        !           173:                wwaddcap1(WWT_GRP, &kp);
        !           174:        if (wwavailmodes & WWM_DIM)
        !           175:                wwaddcap1(WWT_DIM, &kp);
        !           176:        if (wwavailmodes & WWM_USR)
        !           177:                wwaddcap1(WWT_USR, &kp);
        !           178:        if (tt.tt_insline && tt.tt_delline || tt.tt_setscroll)
        !           179:                wwaddcap1(WWT_ALDL, &kp);
        !           180:        if (tt.tt_inschar)
        !           181:                wwaddcap1(WWT_IMEI, &kp);
        !           182:        if (tt.tt_insspace)
        !           183:                wwaddcap1(WWT_IC, &kp);
        !           184:        if (tt.tt_delchar)
        !           185:                wwaddcap1(WWT_DC, &kp);
        !           186:        wwaddcap("kb", &kp);
        !           187:        wwaddcap("ku", &kp);
        !           188:        wwaddcap("kd", &kp);
        !           189:        wwaddcap("kl", &kp);
        !           190:        wwaddcap("kr", &kp);
        !           191:        wwaddcap("kh", &kp);
        !           192:        if ((j = tgetnum("kn")) >= 0) {
        !           193:                char cap[32];
        !           194: 
        !           195:                (void) sprintf(kp, "kn#%d:", j);
        !           196:                for (; *kp; kp++)
        !           197:                        ;
        !           198:                for (i = 1; i <= j; i++) {
        !           199:                        (void) sprintf(cap, "k%d", i);
        !           200:                        wwaddcap(cap, &kp);
        !           201:                        cap[0] = 'l';
        !           202:                        wwaddcap(cap, &kp);
        !           203:                }
        !           204:        }
        !           205:        /*
        !           206:         * It's ok to do this here even if setenv() is destructive
        !           207:         * since tt_init() has already made its own copy of it and
        !           208:         * wwterm now points to the copy.
        !           209:         */
        !           210:        (void) setenv("TERM", WWT_TERM, 1);
        !           211: 
        !           212:        (void) sigsetmask(s);
        !           213:        /* catch typeahead before ASYNC was set */
        !           214:        (void) kill(getpid(), SIGIO);
        !           215:        xxstart();
        !           216:        return 0;
        !           217: bad:
        !           218:        /*
        !           219:         * Don't bother to free storage.  We're supposed
        !           220:         * to exit when wwinit fails anyway.
        !           221:         */
        !           222:        (void) wwsettty(0, &wwoldtty, &wwnewtty);
        !           223:        (void) signal(SIGIO, SIG_DFL);
        !           224:        (void) sigsetmask(s);
        !           225:        return -1;
        !           226: }
        !           227: 
        !           228: wwaddcap(cap, kp)
        !           229:        register char *cap;
        !           230:        register char **kp;
        !           231: {
        !           232:        char tbuf[512];
        !           233:        char *tp = tbuf;
        !           234:        register char *str, *p;
        !           235: 
        !           236:        if ((str = tgetstr(cap, &tp)) != 0) {
        !           237:                while (*(*kp)++ = *cap++)
        !           238:                        ;
        !           239:                (*kp)[-1] = '=';
        !           240:                while (*str) {
        !           241:                        for (p = unctrl(*str++); *(*kp)++ = *p++;)
        !           242:                                ;
        !           243:                        (*kp)--;
        !           244:                }
        !           245:                *(*kp)++ = ':';
        !           246:                **kp = 0;
        !           247:        }
        !           248: }
        !           249: 
        !           250: wwaddcap1(cap, kp)
        !           251:        register char *cap;
        !           252:        register char **kp;
        !           253: {
        !           254:        while (*(*kp)++ = *cap++)
        !           255:                ;
        !           256:        (*kp)--;
        !           257: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.