1: 
   2: /* Copyright (c) 1979 Regents of the University of California */
   3: #include "ex.h"
   4: #include "ex_tty.h"
   5: 
   6: /*
   7:  * Terminal type initialization routines,
   8:  * and calculation of flags at entry or after
   9:  * a shell escape which may change them.
  10:  */
  11: short   ospeed = -1;
  12: 
  13: gettmode()
  14: {
  15: 
  16: #ifndef USG3TTY
  17:     if (gtty(1, &tty) < 0)
  18:         return;
  19:     if (ospeed != tty.sg_ospeed)
  20:         value(SLOWOPEN) = tty.sg_ospeed < B1200;
  21:     ospeed = tty.sg_ospeed;
  22:     normf = tty.sg_flags;
  23:     UPPERCASE = (tty.sg_flags & LCASE) != 0;
  24:     GT = (tty.sg_flags & XTABS) != XTABS && !XT;
  25:     NONL = (tty.sg_flags & CRMOD) == 0;
  26: #else
  27:     if (ioctl(1, TCGETA, &tty) < 0)
  28:         return;
  29:     if (ospeed != tty.c_cflag & CBAUD)
  30:         value(SLOWOPEN) = (tty.c_cflag & CBAUD) < B1200;
  31:     ospeed = tty.c_cflag & CBAUD;
  32:     normf = tty;
  33:     UPPERCASE = (tty.c_iflag & IUCLC) != 0;
  34:     GT = (tty.c_oflag & TABDLY) != TAB3 && !XT;
  35:     NONL = (tty.c_oflag & OCRNL) == 0;
  36: #endif
  37: }
  38: 
  39: char *xPC;
  40: char **sstrs[] = {
  41:     &AL, &BC, &BT, &CD, &CE, &CL, &CM, &xCR, &DC, &DL, &DM, &DO, &ED, &EI,
  42:     &HO, &IC, &IM, &IP, &LL, &MA,
  43:     &ND, &xNL, &xPC, &SE, &SF, &SO, &SR, &TA, &TE, &TI, &UP, &VB, &VS, &VE
  44: };
  45: bool *sflags[] = {
  46:     &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI, &NC, &NS, &OS, &UL,
  47:     &XB, &XN, &XT, &XX
  48: };
  49: setterm(type)
  50:     char *type;
  51: {
  52:     char *tgoto();
  53:     register int unknown, i;
  54:     register int l;
  55:     char ltcbuf[TCBUFSIZE];
  56: 
  57:     putpad(TE);
  58:     if (type[0] == 0)
  59:         type = "xx";
  60:     unknown = 0;
  61:     if (tgetent(ltcbuf, type) != 1) {
  62:         unknown++;
  63:         CP(ltcbuf, "uk|dumb:");
  64:     }
  65:     i = LINES = tgetnum("li");
  66:     if (LINES <= 5)
  67:         LINES = 24;
  68:     if (LINES > 48)
  69:         LINES = 48;
  70:     l = LINES;
  71:     if (ospeed < B1200)
  72:         l = 9;  /* including the message line at the bottom */
  73:     else if (ospeed < B2400)
  74:         l = 17;
  75:     aoftspace = tspace;
  76:     zap();
  77: 
  78:     options[WINDOW].ovalue = options[WINDOW].odefault = l - 1;
  79:     options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2);
  80:     COLUMNS = tgetnum("co");
  81:     if (COLUMNS <= 4)
  82:         COLUMNS = 1000;
  83:     if (tgoto(CM, 2, 2)[0] == 'O')  /* OOPS */
  84:         CA = 0, CM = 0;
  85:     else
  86:         CA = 1, costCM = strlen(tgoto(CM, 8, 10));
  87:     PC = xPC ? xPC[0] : 0;
  88:     aoftspace = tspace;
  89:     CP(ttytype, longname(ltcbuf, type));
  90:     if (i <= 0)
  91:         LINES = 2;
  92:     /* proper strings to change tty type */
  93: #ifdef notdef
  94:     /* Taken out because we don't allow it. See ex_set.c for reasons. */
  95:     if (inopen)
  96:         putpad(VE);
  97: #endif
  98:     termreset();
  99:     gettmode();
 100:     value(REDRAW) = AL && DL;
 101:     value(OPTIMIZE) = !CA && !GT;
 102:     if (unknown)
 103:         serror("%s: Unknown terminal type", type);
 104: }
 105: 
 106: zap()
 107: {
 108:     register char *namp;
 109:     register bool **fp;
 110:     register char ***sp;
 111: 
 112:     namp = "ambsdadbeohchzinmincnsosulxbxnxtxx";
 113:     fp = sflags;
 114:     do {
 115:         *(*fp++) = tgetflag(namp);
 116:         namp += 2;
 117:     } while (*namp);
 118:     namp = "albcbtcdceclcmcrdcdldmdoedeihoicimipllmandnlpcsesfsosrtatetiupvbvsve";
 119:     sp = sstrs;
 120:     do {
 121:         *(*sp++) = tgetstr(namp, &aoftspace);
 122:         namp += 2;
 123:     } while (*namp);
 124: }
 125: 
 126: char *
 127: longname(bp, def)
 128:     register char *bp;
 129:     char *def;
 130: {
 131:     register char *cp;
 132: 
 133:     while (*bp && *bp != ':' && *bp != '|')
 134:         bp++;
 135:     if (*bp == '|') {
 136:         bp++;
 137:         cp = bp;
 138:         while (*cp && *cp != ':' && *cp != '|')
 139:             cp++;
 140:         *cp = 0;
 141:         return (bp);
 142:     }
 143:     return (def);
 144: }

Defined functions

gettmode defined in line 13; used 3 times
longname defined in line 126; used 2 times
setterm defined in line 49; used 3 times
zap defined in line 106; used 1 times
  • in line 76

Defined variables

ospeed defined in line 11; used 6 times
sflags defined in line 45; used 1 times
sstrs defined in line 40; used 1 times
xPC defined in line 39; used 3 times
Last modified: 1980-09-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 749
Valid CSS Valid XHTML 1.0 Strict