Annotation of researchv8dc/lib/libcurses/cr_tty.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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