Annotation of 43BSDReno/contrib/jove/term.c, revision 1.1.1.1

1.1       root        1: /***************************************************************************
                      2:  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
                      3:  * is provided to you without charge, and with no warranty.  You may give  *
                      4:  * away copies of JOVE, including sources, provided that this notice is    *
                      5:  * included in all the files.                                              *
                      6:  ***************************************************************************/
                      7: 
                      8: #include "jove.h"
                      9: #include "fp.h"
                     10: #include "disp.h"
                     11: #include <ctype.h>
                     12: #include <errno.h>
                     13: 
                     14: #ifndef MAC    /* most of the file... */
                     15: 
                     16: # ifdef        STDARGS
                     17: #  include <stdarg.h>
                     18: # else
                     19: #  include <varargs.h>
                     20: # endif
                     21: 
                     22: #ifndef MSDOS
                     23: # ifdef SYSV
                     24: #   include <termio.h>
                     25: # else
                     26: #   include <sgtty.h>
                     27: # endif /* SYSV */
                     28: #endif /* MSDOS */
                     29: 
                     30: #ifdef IPROCS
                     31: # include <signal.h>
                     32: #endif
                     33: 
                     34: #include "termcap.h"
                     35: 
                     36: /* Termcap definitions */
                     37: 
                     38: #ifndef IBMPC
                     39: char   *CS,
                     40:        *SO,
                     41:        *SE,
                     42:        *CM,
                     43:        *CL,
                     44:        *CE,
                     45:        *HO,
                     46:        *AL,
                     47:        *DL,
                     48:        *VS,
                     49:        *VE,
                     50:        *KS,
                     51:        *KE,
                     52:        *TI,
                     53:        *TE,
                     54:        *IC,
                     55:        *DC,
                     56:        *IM,
                     57:        *EI,
                     58:        *LL,
                     59:        *M_IC,  /* Insert char with arg */
                     60:        *M_DC,  /* Delete char with arg */
                     61:        *M_AL,  /* Insert line with arg */
                     62:        *M_DL,  /* Delete line with arg */
                     63:        *SF,    /* Scroll forward */
                     64:        *SR,
                     65:        *SP,    /* Send Cursor Position */
                     66:        *VB,
                     67:        *BL,
                     68:        *IP,    /* insert pad after character inserted */
                     69:        *lPC,
                     70:        *NL,
                     71:        *DO;
                     72: #endif
                     73: 
                     74: int    LI,
                     75:        ILI,    /* Internal lines, i.e., 23 of LI is 24. */
                     76:        CO,
                     77: 
                     78:        UL,
                     79:        MI,
                     80:        SG,     /* number of magic cookies left by SO and SE */
                     81:        XS,     /* whether standout is braindamaged */
                     82:        HZ,     /* Hazeltine tilde kludge */
                     83: 
                     84:        TABS,
                     85:        UPlen,
                     86:        HOlen,
                     87:        LLlen;
                     88: 
                     89: #ifdef notdef
                     90:        /*
                     91:         * Are you sure about this one Jon?  On the SYSV system I tried this
                     92:         * on I got a multiple definition of PC because it was already
                     93:         * defined in -ltermcap.  Similarly for BC and UP ...
                     94:         */
                     95: # ifdef SYSVR2 /* release 2, at least */
                     96: char   PC;
                     97: # endif /* SYSVR2 */
                     98: #endif
                     99: 
                    100: #ifndef IBMPC
                    101: private char   tspace[256];
                    102: 
                    103: /* The ordering of ts and meas must agree !! */
                    104: private const char     ts[] =
                    105:        "vsvealdlspcssosecmclcehoupbcicimdceillsfsrvbksketiteALDLICDCpcipblnldo";
                    106: private char   **const meas[] = {
                    107:        &VS, &VE, &AL, &DL, &SP, &CS, &SO, &SE,
                    108:        &CM, &CL, &CE, &HO, &UP, &BC, &IC, &IM,
                    109:        &DC, &EI, &LL, &SF, &SR, &VB, &KS, &KE,
                    110:        &TI, &TE, &M_AL, &M_DL, &M_IC, &M_DC,
                    111:        &lPC, &IP, &BL, &NL, &DO, 0
                    112: };
                    113: 
                    114: private void
                    115: TermError()
                    116: {
                    117:        flusho();
                    118:        _exit(1);
                    119: }
                    120: 
                    121: void
                    122: getTERM()
                    123: {
                    124:        extern char     *getenv(), *tgetstr() ;
                    125:        char    termbuf[13],
                    126:                *termname = NULL,
                    127:                *termp = tspace,
                    128:                tbuff[2048];    /* Good grief! */
                    129:        const char      *tsp = ts;
                    130:        int     i;
                    131: 
                    132:        termname = getenv("TERM");
                    133:        if ((termname == NULL) || (*termname == '\0') ||
                    134:            (strcmp(termname, "dumb") == 0) ||
                    135:            (strcmp(termname, "unknown") == 0) ||
                    136:            (strcmp(termname, "network") == 0)) {
                    137:                putstr("Enter terminal type (e.g, vt100): ");
                    138:                flusho();
                    139:                termbuf[read(0, termbuf, sizeof(termbuf)) - 1] = '\0';
                    140:                if (termbuf[0] == 0)
                    141:                        TermError();
                    142: 
                    143:                termname = termbuf;
                    144:        }
                    145: 
                    146:        if (tgetent(tbuff, termname) < 1) {
                    147:                writef("[\"%s\" unknown terminal type?]", termname);
                    148:                TermError();
                    149:        }
                    150:        if ((CO = tgetnum("co")) == -1) {
                    151: wimperr:
                    152:                writef("You can't run JOVE on a %s terminal.\n", termname);
                    153:                TermError();
                    154:                /*NOTREACHED*/
                    155:        }
                    156: 
                    157:        else if (CO > MAXCOLS)
                    158:                CO = MAXCOLS;
                    159: 
                    160:        if ((LI = tgetnum("li")) == -1)
                    161:                goto wimperr;
                    162: 
                    163:        if ((SG = tgetnum("sg")) == -1)
                    164:                SG = 0;                 /* Used for mode line only */
                    165: 
                    166:        if ((XS = tgetflag("xs")) == -1)
                    167:                XS = 0;                 /* Used for mode line only */
                    168: 
                    169:        if ((HZ = tgetflag("hz")) == -1)
                    170:                HZ = 0;                 /* Hazeltine tilde kludge */
                    171: 
                    172:        for (i = 0; meas[i]; i++) {
                    173:                static char     nm[3] = "xx";
                    174: 
                    175:                nm[0] = *tsp++;
                    176:                nm[1] = *tsp++;
                    177:                *(meas[i]) = (char *) tgetstr(nm, &termp);
                    178:                if (termp > tspace + sizeof(tspace))
                    179:                        goto wimperr;
                    180:        }
                    181:        if (lPC)
                    182:                PC = *lPC;
                    183:        if (XS)
                    184:                SO = SE = 0;
                    185: 
                    186:        if (CS && !SR)
                    187:                CS = SR = SF = 0;
                    188: 
                    189:        if (CS && !SF)
                    190:                SF = "\n";
                    191: 
                    192:        if (IM && (*IM == 0))
                    193:                IM = 0;
                    194:        else
                    195:                MI = tgetflag("mi");
                    196: 
                    197:        UL = tgetflag("ul");
                    198: 
                    199:        if (NL == 0)
                    200:                NL = "\n";
                    201:        else {                  /* strip stupid padding information */
                    202:                while (isdigit(*NL))
                    203:                        NL += 1;
                    204:                if (*NL == '*')
                    205:                        NL += 1;
                    206:        }
                    207:        if (!DO)
                    208:                DO = NL;
                    209: 
                    210:        if (BL == 0)
                    211:                BL = "\007";
                    212: 
                    213:        if (tgetflag("km") > 0)         /* has meta-key */
                    214:                MetaKey = YES;
                    215: 
                    216: #ifdef ID_CHAR
                    217:        disp_opt_init();
                    218: #endif
                    219:        if ((CanScroll = ((AL && DL) || CS)) != 0)
                    220:                IDline_setup(termname);
                    221: }
                    222: 
                    223: #else
                    224: 
                    225: void
                    226: InitCM()
                    227: {
                    228: }
                    229: 
                    230: int EGA;
                    231: 
                    232: void
                    233: getTERM()
                    234: {
                    235:        char    *getenv(), *tgetstr() ;
                    236:        char    *termname;
                    237:        void    init_43(), init_term();
                    238:        unsigned char lpp(), chpl();
                    239: 
                    240:        if (getenv("EGA") || (!stricmp(getenv("TERM"), "EGA"))) {
                    241:           termname = "ega";
                    242:           init_43();
                    243:           EGA = 1;
                    244:        }
                    245:        else {
                    246:           termname = "ibmpc";
                    247:           init_term();
                    248:           EGA = 0;
                    249:        }
                    250: 
                    251:        CO = chpl();
                    252:        LI = lpp();
                    253: 
                    254:        SG = 0;                 /* Used for mode line only */
                    255:        XS = 0;                 /* Used for mode line only */
                    256: 
                    257:        CanScroll = 1;
                    258: }
                    259: 
                    260: #endif /* IBMPC */
                    261: 
                    262: #else /* MAC */
                    263: int    LI,
                    264:        ILI,    /* Internal lines, i.e., 23 of LI is 24. */
                    265:        CO,
                    266:        TABS,
                    267:        SG;
                    268: 
                    269: void getTERM()
                    270: {
                    271:        SG = 0;
                    272:        CanScroll = 1;
                    273: }
                    274: 
                    275: #endif /* MAC */
                    276: 
                    277: /* put a string with padding */
                    278: 
                    279: #ifndef IBMPC
                    280: private void
                    281: tputc(c)
                    282: int    c;
                    283: {
                    284:        jputchar(c);
                    285: }
                    286: #endif /* IBMPC */
                    287: 
                    288: #ifndef MAC
                    289: void
                    290: putpad(str, lines)
                    291: char   *str;
                    292: int    lines;
                    293: {
                    294: #ifndef IBMPC
                    295:        if (str)
                    296:                tputs(str, lines, tputc);
                    297: #else /* IBMPC */
                    298:        write_emif(str);
                    299: #endif /* IBMPC */
                    300: }
                    301: 
                    302: void
                    303: putargpad(str, arg, lines)
                    304: char   *str;
                    305: int    arg,
                    306:        lines;
                    307: {
                    308: #ifndef        IBMPC
                    309:        if (str) {
                    310:                tputs(
                    311: #ifdef TERMINFO
                    312:                        tparm(str, arg),
                    313: #else  /* TERMINFO */
                    314:                        tgoto(str, 0, arg),     /* fudge */
                    315: #endif /* TERMINFO */
                    316:                        lines, tputc);
                    317:        }
                    318: #else  /* IBMPC */
                    319:        /* This code is only a guess: I don't know if any M_* termcap
                    320:         * attributes are defined for the PC.  If they are not used,
                    321:         * this routine is not called.  Perhaps this routine should
                    322:         * simply abort.
                    323:         */
                    324:        if (str) {
                    325:                char    buf[16];        /* hope that this is long enough */
                    326: 
                    327:                swritef(buf, str, arg); /* hope only %d appears in str */
                    328:                write_em(buf);
                    329:        }
                    330: #endif /* IBMPC */
                    331: }
                    332: 
                    333: #endif /* MAC */
                    334: 
                    335: /* Determine the number of characters to buffer at each baud rate.  The
                    336:    lower the number, the quicker the response when new input arrives.  Of
                    337:    course the lower the number, the more prone the program is to stop in
                    338:    output.  Decide what matters most to you. This sets BufSize to the right
                    339:    number or chars, and initializes `stdout'.  */
                    340: 
                    341: void
                    342: settout(ttbuf)
                    343: char   *ttbuf;
                    344: {
                    345:        int     speed_chars;
                    346:        static const int speeds[] = {
                    347:                1,      /* 0    */
                    348:                1,      /* 50   */
                    349:                1,      /* 75   */
                    350:                1,      /* 110  */
                    351:                1,      /* 134  */
                    352:                1,      /* 150  */
                    353:                1,      /* 200  */
                    354:                2,      /* 300  */
                    355:                4,      /* 600  */
                    356:                8,      /* 1200 */
                    357:                16,     /* 1800 */
                    358:                32,     /* 2400 */
                    359:                128,    /* 4800 */
                    360:                256,    /* 9600 */
                    361:                512,    /* EXTA */
                    362:                1024    /* EXT  */
                    363:        };
                    364: 
                    365: #if (defined(MSDOS) || defined(MAC))
                    366:        speed_chars = 256;
                    367: #else
                    368:        speed_chars = speeds[ospeed];
                    369: #endif
                    370:        flusho();               /* flush the one character buffer */
                    371:        BufSize = min(MAXTTYBUF, speed_chars * max(LI / 24, 1));
                    372:        stdout = fd_open("/dev/tty", F_WRITE|F_LOCKED, 1, ttbuf, BufSize);
                    373: }

unix.superglobalmegacorp.com

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