Annotation of 43BSD/ucb/window/wwinit.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)wwinit.c   3.26 5/1/86";
        !             3: #endif
        !             4: 
        !             5: /*
        !             6:  * Copyright (c) 1983 Regents of the University of California,
        !             7:  * All rights reserved.  Redistribution permitted subject to
        !             8:  * the terms of the Berkeley Software License Agreement.
        !             9:  */
        !            10: 
        !            11: #include "ww.h"
        !            12: #include "tt.h"
        !            13: #include <sys/signal.h>
        !            14: #include <fcntl.h>
        !            15: #include "char.h"
        !            16: 
        !            17: wwinit()
        !            18: {
        !            19:        register i, j;
        !            20:        char *kp;
        !            21:        register char **p, **q;
        !            22:        char **env, **termcap = 0;
        !            23:        extern char **environ;
        !            24:        int s;
        !            25: 
        !            26:        wwdtablesize = getdtablesize();
        !            27:        wwhead.ww_forw = &wwhead;
        !            28:        wwhead.ww_back = &wwhead;
        !            29: 
        !            30:        s = sigblock(sigmask(SIGIO));
        !            31:        if (signal(SIGIO, wwrint) == BADSIG)
        !            32:                return -1;
        !            33: 
        !            34:        if (wwgettty(0, &wwoldtty) < 0)
        !            35:                return -1;
        !            36:        wwwintty = wwoldtty;
        !            37:        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        !            38:        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        !            39:        wwnewtty.ww_sgttyb.sg_erase = -1;
        !            40:        wwnewtty.ww_sgttyb.sg_kill = -1;
        !            41:        wwnewtty.ww_sgttyb.sg_flags |= CBREAK;
        !            42:        wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD);
        !            43:        wwnewtty.ww_tchars.t_intrc = -1;
        !            44:        wwnewtty.ww_tchars.t_quitc = -1;
        !            45:        wwnewtty.ww_tchars.t_startc = -1;
        !            46:        wwnewtty.ww_tchars.t_stopc = -1;
        !            47:        wwnewtty.ww_tchars.t_eofc = -1;
        !            48:        wwnewtty.ww_tchars.t_brkc = -1;
        !            49:        wwnewtty.ww_ltchars.t_suspc = -1;
        !            50:        wwnewtty.ww_ltchars.t_dsuspc = -1;
        !            51:        wwnewtty.ww_ltchars.t_rprntc = -1;
        !            52:        wwnewtty.ww_ltchars.t_flushc = -1;
        !            53:        wwnewtty.ww_ltchars.t_werasc = -1;
        !            54:        wwnewtty.ww_ltchars.t_lnextc = -1;
        !            55:        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        !            56:        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
        !            57:        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        !            58:        if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
        !            59:                goto bad;
        !            60: 
        !            61:        if ((wwterm = getenv("TERM")) == 0) {
        !            62:                wwerrno = WWE_BADTERM;
        !            63:                goto bad;
        !            64:        }
        !            65:        if (tgetent(wwtermcap, wwterm) != 1) {
        !            66:                wwerrno = WWE_BADTERM;
        !            67:                goto bad;
        !            68:        }
        !            69:        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
        !            70: 
        !            71:        if (ttinit() < 0)
        !            72:                goto bad;
        !            73:        wwnrow = tt.tt_nrow;
        !            74:        wwncol = tt.tt_ncol;
        !            75:        wwavailmodes = tt.tt_availmodes;
        !            76:        wwwrap = tt.tt_wrap;
        !            77:        (*tt.tt_init)();
        !            78: 
        !            79:        if (wwavailmodes & WWM_REV)
        !            80:                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
        !            81:        else if (wwavailmodes & WWM_UL)
        !            82:                wwcursormodes = WWM_UL;
        !            83: 
        !            84:        if ((wwib = malloc((unsigned) 512)) == 0)
        !            85:                goto bad;
        !            86:        wwibe = wwib + 512;
        !            87:        wwibq = wwibp = wwib;
        !            88: 
        !            89:        if ((wwsmap = wwalloc(0, 0, wwnrow, wwncol, sizeof (char))) == 0)
        !            90:                goto bad;
        !            91:        for (i = 0; i < wwnrow; i++)
        !            92:                for (j = 0; j < wwncol; j++)
        !            93:                        wwsmap[i][j] = WWX_NOBODY;
        !            94: 
        !            95:        wwos = (union ww_char **)
        !            96:                wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char));
        !            97:        if (wwos == 0)
        !            98:                goto bad;
        !            99:        for (i = 0; i < wwnrow; i++)
        !           100:                for (j = 0; j < wwncol; j++)
        !           101:                        wwos[i][j].c_w = ' ';
        !           102:        wwns = (union ww_char **)
        !           103:                wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char));
        !           104:        if (wwns == 0)
        !           105:                goto bad;
        !           106:        for (i = 0; i < wwnrow; i++)
        !           107:                for (j = 0; j < wwncol; j++)
        !           108:                        wwns[i][j].c_w = ' ';
        !           109: 
        !           110:        wwtouched = malloc((unsigned) wwnrow);
        !           111:        if (wwtouched == 0) {
        !           112:                wwerrno = WWE_NOMEM;
        !           113:                goto bad;
        !           114:        }
        !           115:        for (i = 0; i < wwnrow; i++)
        !           116:                wwtouched[i] = 0;
        !           117: 
        !           118:        wwindex[WWX_NOBODY] = &wwnobody;
        !           119:        wwnobody.ww_order = NWW;
        !           120: 
        !           121:        kp = wwkeys;
        !           122:        wwaddcap("kb", &kp);
        !           123:        wwaddcap("ku", &kp);
        !           124:        wwaddcap("kd", &kp);
        !           125:        wwaddcap("kl", &kp);
        !           126:        wwaddcap("kr", &kp);
        !           127:        wwaddcap("kh", &kp);
        !           128:        if ((j = tgetnum("kn")) >= 0) {
        !           129:                char cap[32];
        !           130: 
        !           131:                (void) sprintf(kp, "kn#%d:", j);
        !           132:                for (; *kp; kp++)
        !           133:                        ;
        !           134:                for (i = 1; i <= j; i++) {
        !           135:                        (void) sprintf(cap, "k%d", i);
        !           136:                        wwaddcap(cap, &kp);
        !           137:                        cap[0] = 'l';
        !           138:                        wwaddcap(cap, &kp);
        !           139:                }
        !           140:        }
        !           141:        for (i = 0, p = environ; *p++; i++)
        !           142:                ;
        !           143:        if ((env = (char **)malloc((unsigned)(i + 3) * sizeof (char *))) == 0)
        !           144:                goto bad;
        !           145:        for (p = environ, q = env; *p; p++, q++) {
        !           146:                if (strncmp(*p, "TERM=", 5) == 0)
        !           147:                        *q = WWT_TERM;
        !           148:                else if (strncmp(*p, "TERMCAP=", 8) == 0)
        !           149:                        termcap = q;
        !           150:                else
        !           151:                        *q = *p;
        !           152:        }
        !           153:        *(termcap ? termcap : q++) = wwwintermcap;
        !           154:        *q = 0;
        !           155:        environ = env;
        !           156: 
        !           157:        (void) signal(SIGPIPE, SIG_IGN);
        !           158:        (void) sigsetmask(s);
        !           159:        return 0;
        !           160: bad:
        !           161:        /*
        !           162:         * Don't bother to free storage.  We're supposed
        !           163:         * to exit when wwinit fails anyway.
        !           164:         */
        !           165:        (void) wwsettty(0, &wwoldtty, &wwnewtty);
        !           166:        (void) signal(SIGIO, SIG_DFL);
        !           167:        (void) sigsetmask(s);
        !           168:        return -1;
        !           169: }
        !           170: 
        !           171: wwaddcap(cap, kp)
        !           172: register char *cap;
        !           173: register char **kp;
        !           174: {
        !           175:        char tbuf[512];
        !           176:        char *tp = tbuf;
        !           177:        register char *str, *p;
        !           178: 
        !           179:        if ((str = tgetstr(cap, &tp)) != 0) {
        !           180:                while (*(*kp)++ = *cap++)
        !           181:                        ;
        !           182:                (*kp)[-1] = '=';
        !           183:                while (*str) {
        !           184:                        for (p = unctrl(*str++); *(*kp)++ = *p++;)
        !           185:                                ;
        !           186:                        (*kp)--;
        !           187:                }
        !           188:                *(*kp)++ = ':';
        !           189:                **kp = 0;
        !           190:        }
        !           191: }

unix.superglobalmegacorp.com

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