Annotation of 41BSD/lib/libcurses/cr_tty.c, revision 1.1

1.1     ! root        1: # include      "curses.ext"
        !             2: # include      "cr_ex.h"
        !             3: 
        !             4: static bool    *sflags[]       = {
        !             5:                        &AM, &BS, &EO, &HZ, &IN, &MI, &NC, &OS, &UL, &XN
        !             6:                };
        !             7: 
        !             8: static char    *xPC,
        !             9:                **sstrs[]       = {
        !            10:                        &AL, &BC, &BT, &CD, &CE, &CL, &CM, &DC, &DL,  &DM, &DO,
        !            11:                        &ED, &EI, &HO, &IC, &IM, &IP, &LL, &MA, &ND, &xPC, &SE,
        !            12:                        &SF, &SO, &SR, &TA, &TE, &TI, &UE, &UP, &US,  &VB, &VS,
        !            13:                        &VE
        !            14:                },
        !            15:                *longname(), *tgoto();
        !            16: 
        !            17: static char    tspace[128],            /* Space for capability strings */
        !            18:                *aoftspace;             /* Address of tspace for relocation */
        !            19: 
        !            20: static int     destcol, destline;
        !            21: 
        !            22: /*
        !            23:  *     This routine does terminal type initialization routines, and
        !            24:  * calculation of flags at entry.  It is almost entirely stolen from
        !            25:  * Bill Joy's ex version 2.6.
        !            26:  */
        !            27: short  ospeed  = -1;
        !            28: 
        !            29: gettmode() {
        !            30: 
        !            31:        if (gtty(_tty_ch, &_tty) < 0)
        !            32:                return;
        !            33:        savetty();
        !            34:        if (stty(_tty_ch, &_tty) < 0)
        !            35:                _tty.sg_flags = _res_flg;
        !            36:        ospeed = _tty.sg_ospeed;
        !            37:        _res_flg = _tty.sg_flags;
        !            38:        UPPERCASE = (_tty.sg_flags & LCASE) != 0;
        !            39:        GT = ((_tty.sg_flags & XTABS) == 0);
        !            40:        NONL = ((_tty.sg_flags & CRMOD) == 0);
        !            41: # ifdef DEBUG
        !            42:        fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
        !            43:        fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
        !            44:        fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
        !            45:        fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
        !            46: # endif
        !            47: }
        !            48: 
        !            49: setterm(type)
        !            50: reg char       *type; {
        !            51: 
        !            52:        reg int unknown;
        !            53:        char    genbuf[1024];
        !            54: 
        !            55: # ifdef DEBUG
        !            56:        fprintf(outf, "SETTERM(\"%s\")\n", type);
        !            57:        fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
        !            58: # endif
        !            59:        if (type[0] == '\0')
        !            60:                type = "xx";
        !            61:        unknown = FALSE;
        !            62:        if (tgetent(genbuf, type) != 1) {
        !            63:                unknown++;
        !            64:                strcpy(genbuf, "xx|dumb:");
        !            65:        }
        !            66: # ifdef DEBUG
        !            67:        fprintf(outf, "SETTERM: tty = %s\n", type);
        !            68: # endif
        !            69:        if (LINES == 0)
        !            70:                LINES = tgetnum("li");
        !            71:        if (LINES <= 5)
        !            72:                LINES = 24;
        !            73:        else if (LINES > 48)
        !            74:                LINES = 48;
        !            75: 
        !            76:        if (COLS == 0)
        !            77:                COLS = tgetnum("co");
        !            78:        if (COLS <= 4)
        !            79:                COLS = 80;
        !            80:        else if (COLS > 1000)
        !            81:                COLS = 1000;
        !            82: # ifdef DEBUG
        !            83:        fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
        !            84: # endif
        !            85:        aoftspace = tspace;
        !            86:        zap();                  /* get terminal description             */
        !            87:        if (tgoto(CM, destcol, destline)[0] == 'O')
        !            88:                CA = FALSE, CM = 0;
        !            89:        else
        !            90:                CA = TRUE;
        !            91:        PC = xPC ? xPC[0] : FALSE;
        !            92:        aoftspace = tspace;
        !            93:        strcpy(ttytype, longname(genbuf, type));
        !            94:        if (unknown)
        !            95:                return ERR;
        !            96:        return OK;
        !            97: }
        !            98: /*
        !            99:  *     This routine gets all the terminal falgs from the termcap database
        !           100:  */
        !           101: zap() {
        !           102: 
        !           103:        reg bool        **fp;
        !           104:        reg char        *namp, ***sp;
        !           105:        extern char     *tgetstr();
        !           106: 
        !           107:        /*
        !           108:         * get boolean flags
        !           109:         */
        !           110:        namp = "ambseohzinmincosulxn\0\0";
        !           111: # ifdef FULLDEBUG
        !           112:        fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
        !           113: # endif
        !           114:        fp = sflags;
        !           115:        do {
        !           116:                *(*fp++) = tgetflag(namp);
        !           117: # ifdef FULLDEBUG
        !           118:                fprintf(outf, "ZAP: %.2s = %d", namp, *(*(fp - 1)));
        !           119: # endif
        !           120:                namp += 2;
        !           121:        } while (*namp);
        !           122: 
        !           123:        /*
        !           124:         * get string values
        !           125:         */
        !           126:        namp = "albcbtcdceclcmdcdldmdoedeihoicimipllmandpcsesfsosrtatetiueupusvbvsve";
        !           127: # ifdef FULLDEBUG
        !           128:        fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
        !           129: # endif
        !           130:        sp = sstrs;
        !           131:        do {
        !           132:                *(*sp++) = tgetstr(namp, &aoftspace);
        !           133: # ifdef FULLDEBUG
        !           134:                fprintf(outf, "ZAP: %.2s = \"%s\"\n", namp, *(*(sp-1)));
        !           135: # endif
        !           136:                namp += 2;
        !           137:        } while (*namp);
        !           138:        if (!SO && US) {
        !           139:                SO = US;
        !           140:                SE = UE;
        !           141:        }
        !           142: }

unix.superglobalmegacorp.com

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