Annotation of coherent/g/usr/bin/vi/tinytcap.c, revision 1.1.1.1

1.1       root        1: /* tinytcap.c */
                      2: 
                      3: /* This file contains functions which simulate the termcap functions.
                      4:  *
                      5:  * It doesn't access a "termcap" file.  Instead, it uses an initialized array
                      6:  * of strings to store the entries.  Any string that doesn't start with a ':'
                      7:  * is taken to be the name of a type of terminal.  Any string that does start
                      8:  * with a ':' is interpretted as the list of fields describing all of the
                      9:  * terminal types that precede it.
                     10:  *
                     11:  * Note: since these are C strings, you can't use special sequences like
                     12:  * ^M or \E in the fields; your C compiler won't understand them.  Also,
                     13:  * at run time there is no way to tell the difference between ':' and '\072'
                     14:  * so I sure hope your terminal definition doesn't require a ':' character.
                     15:  *
                     16:  * getenv(TERM) on VMS checks the SET TERM device setting.  To implement
                     17:  * non-standard terminals set the logical ELVIS_TERM in VMS. (jdc)
                     18:  *
                     19:  * Other possible terminal types are...
                     20:  *     TERM_WYSE925    - "wyse925", a Wyse 50 terminal emulating Televideo 925
                     21:  * ... or you could set $TERMCAP to the terminal's description string, which
                     22:  * $TERM set up to match it.
                     23:  *
                     24:  * Note that you can include several terminal types at the same time.  Elvis
                     25:  * chooses which entry to use at runtime, based primarily on the value of $TERM.
                     26:  */
                     27: 
                     28: 
                     29: #include "config.h"
                     30: extern char *getenv();
                     31: 
                     32: /* decide which terminal descriptions should *always* be included. */
                     33: #if MSDOS
                     34: # define       TERM_NANSI
                     35: # define       TERM_DOSANSI
                     36: # if RAINBOW
                     37: #  define      TERM_RAINBOW
                     38: # endif
                     39: #endif
                     40: 
                     41: #if VMS
                     42: # define       TERM_VT100
                     43: # define       TERM_VT100W
                     44: # define       TERM_VT52
                     45: #endif
                     46: 
                     47: #if AMIGA
                     48: # define       TERM_AMIGA      /* Internal Amiga termcap entry */
                     49: /* # define    TERM_VT52       /* The rest of these are here for those */
                     50: # define       TERM_VT100      /* people who want to use elvis over an */
                     51: /* # define    TERM_NANSI      /* AUX: port (serial.device). */
                     52: /* # define    TERM_DOSANSI    /* Take out all but AMIGA to save memory. */
                     53: /* # define    TERM_MINIX      /* Vanilla ANSI? */
                     54: /* # define    TERM_925        /* Hang a terminal off your Amiga */
                     55: #endif
                     56: 
                     57: #if MINIX || UNIXV
                     58: # define       TERM_MINIX
                     59: #endif
                     60: 
                     61: #if COHERENT
                     62: # define       TERM_COHERENT
                     63: #endif
                     64: 
                     65: #if TOS
                     66: # define       TERM_ATARI
                     67: #endif
                     68: 
                     69: static char *termcap[] =
                     70: {
                     71: #ifdef TERM_AMIGA
                     72: "AA",
                     73: "amiga",
                     74: "Amiga ANSI",
                     75: /* Amiga termcap modified from version 1.3 by Kent Polk */
                     76: ":co#80:li#24:am:bs:bw:xn:\
                     77: :AL=\233%dL:DC=\233%dP:DL=\233%dM:DO=\233%dB:\
                     78: :LE=\233%dD:RI=\233%dC:SF=\233%dS:SR=\233%dT:UP=\233%dA:IC=\233%d@:\
                     79: :ae=\2330m:al=\233L:as=\2333m:bl=\007:bt=\233Z:cd=\233J:\
                     80: :ce=\233K:cl=\013:cm=\233%i%d;%dH:dc=\233P:dl=\233M:do=\233B:\
                     81: :kb=^H:ho=\233H:ic=\233@:is=\23320l:\
                     82: :mb=\2337;2m:md=\2331m:me=\2330m:mh=\2332m:mk=\2338m:mr=\2337m:nd=\233C:\
                     83: :rs=\033c:se=\2330m:sf=\233S:so=\2337m:sb=\233T:sr=\233T:ue=\23323m:\
                     84: :up=\233A:us=\2334m:vb=\007:ve=\233\040p:vi=\2330\040p:\
                     85: :k1=\2330~:k2=\2331~:k3=\2332~:k4=\2333~:k5=\2334~:\
                     86: :k6=\2335~:k7=\2336~:k8=\2337~:k9=\2338~:k0=\2339~:\
                     87: :s1=\23310~:s2=\23311~:s3=\23312~:s4=\23313~:s5=\23314~:\
                     88: :s6=\23315~:s7=\23316~:s8=\23317~:s9=\23318~:s0=\23319~:\
                     89: :kd=\233B:kl=\233D:kn#10:kr=\233C:ku=\233A:le=\233D:\
                     90: :kP=\233T:kN=\233S:kh=\233\040A:kH=\233\040@:",
                     91: #endif
                     92: 
                     93: #ifdef TERM_NANSI
                     94: "fansi",
                     95: "nnansi",
                     96: "nansi",
                     97: "pcbios",
                     98: ":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
                     99: :cm=\033[%i%d;%dH:co#80:do=\033[B:\
                    100: :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
                    101: :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
                    102: :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
                    103: :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
                    104: :kd=#P:kh=#G:kH=#O:kI=#R:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
                    105: :li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
                    106: :ue=\033[m:up=\033[A:us=\033[4m:",
                    107: #endif
                    108: 
                    109: #ifdef TERM_DOSANSI
                    110: #if !ANY_UNIX
                    111: "ansi",
                    112: #endif
                    113: "dosansi",
                    114: ":am:bs:ce=\033[K:cl=\033[2J:\
                    115: :cm=\033[%i%d;%dH:co#80:do=\033[B:\
                    116: :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
                    117: :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
                    118: :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
                    119: :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
                    120: :kd=#P:kh=#G:kH=#O:kI=#R:kl=#K:kN=#Q:kP=#I:kr=#M:ku=#H:\
                    121: :li#25:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
                    122: :ue=\033[m:up=\033[A:us=\033[4m:",
                    123: #endif
                    124: 
                    125: #ifdef TERM_RAINBOW
                    126: "vt220",
                    127: "rainbow",
                    128: ":al=\033[L:dl=\033[M:am:bs:ce=\033[K:cl=\033[2J:\
                    129: :cm=\033[%i%d;%dH:co#80:do=\033[B:kd=\033[B:kl=\033[D:\
                    130: :kr=\033[C:ku=\033[A:kP=\033[5~:kN=\033[6~:kI=\033[2~:\
                    131: :li#24:md=\033[1m:me=\033[m:nd=\033[C:se=\033[m:so=\033[7m:\
                    132: :ue=\033[m:up=\033[A:us=\033[4m:xn:",
                    133: #endif
                    134: 
                    135: #ifdef TERM_VT100
                    136: "vt100-80",
                    137: "vt200-80",
                    138: "vt300-80",
                    139: "vt101-80",
                    140: "vt102-80",
                    141: ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
                    142: :co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
                    143: :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
                    144: :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
                    145: :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
                    146: :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
                    147: :se=\033[m:so=\033[7m:ti=\033[1;24r\033[24;1H:\
                    148: :ue=\033[m:up=\033[A:us=\033[4m:xn:",
                    149: #endif
                    150: 
                    151: #ifdef TERM_VT100W
                    152: "vt100-w",
                    153: "vt200-w",
                    154: "vt300-w",
                    155: "vt101-w",
                    156: "vt102-w",
                    157: "vt100-132",
                    158: "vt200-132",
                    159: "vt300-132",
                    160: "vt101-132",
                    161: "vt102-132",
                    162: ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
                    163: :co#132:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
                    164: :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
                    165: :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
                    166: :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
                    167: :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:nd=\033[C:\
                    168: :se=\033[m:so=\033[7m:ti=\033[1;24r\033[24;1H:\
                    169: :ue=\033[m:up=\033[A:us=\033[4m:xn:",
                    170: #endif
                    171: 
                    172: #ifdef TERM_VT52
                    173: "vt52",
                    174: ":do=\n:le=\b:up=\033A:nd=\033C:cm=\033Y%+ %+ :ti=\033e\033v:\
                    175: :sr=\033I:cd=\033J:ce=\033K:cl=\033H\033J:co#80:li#24:\
                    176: :ku=\033A:kd=\033B:kr=\033C:kl=\033D:kb=\b:pt:am:xn:bs:",
                    177: #endif
                    178: 
                    179: #ifdef TERM_MINIX
                    180: "minix",
                    181: "ansi",
                    182: "AT386",
                    183: ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
                    184: :co#80:dl=\033[M:do=\033[B:k0=\033[20~:k1=\033[1~:\
                    185: :k2=\033[2~:k3=\033[3~:k4=\033[4~:k5=\033[5~:k6=\033[6~:\
                    186: :k7=\033[17~:k8=\033[18~:k9=\033[19~:kd=\033[B:kh=\033[H:\
                    187: :kH=\033[Y:kI=\033[I:kl=\033[D:kN=\033[U:kP=\033[V:\
                    188: :kr=\033[C:ku=\033[A:li#25:md=\033[1m:me=\033[m:nd=\033[C:\
                    189: :se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:us=\033[4m:",
                    190: #endif /* MINIX */
                    191: 
                    192: #ifdef TERM_COHERENT
                    193: "coherent",
                    194: "ansipc",
                    195: ":al=\033[L:am:bs:ce=\033[K:cl=\033[2J:cm=\033[%i%d;%dH:\
                    196: :co#80:dl=\033[M:do=\033[B:k0=\033[0x:k1=\033[1x:k2=\033[2x:\
                    197: :k3=\033[3x:k4=\033[4x:k5=\033[5x:k6=\033[6x:\
                    198: :k7=\033[7x:k8=\033[8x:k9=\033[9x:kd=\033[B:kh=\033[H:\
                    199: :kH=\033[24H:kI=\033[@:kl=\033[D:kN=\033[U:kP=\033[V:\
                    200: :kr=\033[C:ku=\033[A:li#24:md=\033[1m:me=\033[m:\
                    201: :nd=\033[C:se=\033[m:so=\033[7m:ue=\033[m:up=\033[A:\
                    202: :us=\033[4m:",
                    203: #endif /* COHERENT */
                    204: 
                    205: #ifdef TERM_ATARI
                    206: "atari-st",
                    207: "vt52",
                    208: ":al=\033L:am:bs:ce=\033K:cl=\033E:cm=\033Y%i%+ %+ :\
                    209: :co#80:dl=\033M:do=\033B:\
                    210: :k1=#;:k2=#<:k3=#=:k4=#>:k5=#?:k6=#@:k7=#A:k8=#B:k9=#C:k0=#D:\
                    211: :s1=#T:s2=#U:s3=#V:s4=#W:s5=#X:s6=#Y:s7=#Z:s8=#[:s9=#\\:s0=#]:\
                    212: :c1=#^:c2=#_:c3=#`:c4=#a:c5=#b:c6=#c:c7=#d:c8=#e:c9=#f:c0=#g:\
                    213: :a1=#h:a2=#i:a3=#j:a4=#k:a5=#l:a6=#m:a7=#n:a8=#o:a9=#p:a0=#q:\
                    214: kd=#P:kh=#G:kI=#R:kl=#K:kr=#M:ku=#H:li#25:nd=\033C:se=\033q:\
                    215: :so=\033p:te=:ti=\033e\033v:up=\033A:",
                    216: #endif
                    217: 
                    218: #ifdef TERM_925
                    219: "wyse925",
                    220: ":xn@:\
                    221: :hs:am:bs:co#80:li#24:cm=\033=%+ %+ :cl=\033*:cd=\033y:\
                    222: :ce=\033t:is=\033l\033\":\
                    223: :al=\033E:dl=\033R:im=:ei=:ic=\033Q:dc=\033W:\
                    224: :ho=\036:nd=\014:bt=\033I:pt:so=\033G4:se=\033G0:sg#1:us=\033G8:ue=\033G0:ug#1:\
                    225: :up=\013:do=\026:kb=\010:ku=\013:kd=\026:kl=\010:kr=\014:\
                    226: :kh=\036:ma=\026\012\014 :\
                    227: :k1=\001@\r:k2=\001A\r:k3=\001B\r:k4=\001C\r:k5=\001D\r:k6=\001E\r:k7=\001F\r:\
                    228: :k8=\001G\r:k9=\001H\r:k0=\001I\r:ko=ic,dc,al,dl,cl,ce,cd,bt:\
                    229: :ts=\033f:fs=\033g:ds=\033h:sr=\033j:",  /* was :xn: for tvi925 alone*/
                    230: #endif
                    231: 
                    232: (char *)0
                    233: };
                    234: 
                    235: 
                    236: static char *fields;
                    237: 
                    238: 
                    239: /*ARGSUSED*/
                    240: int tgetent(bp, name)
                    241:        char    *bp;    /* buffer for storing the entry -- ignored */
                    242:        char    *name;  /* name of the entry */
                    243: {
                    244:        int     i;
                    245: 
                    246:        /* if TERMCAP is defined, and seems to match, then use it */
                    247:        fields = getenv("TERMCAP");
                    248:        if (fields)
                    249:        {
                    250:                for (i = 0; fields[i] && fields[i] != ':'; i++)
                    251:                {
                    252:                        if (!strncmp(fields + i, name, strlen(name)))
                    253:                        {
                    254:                                return 1;
                    255:                        }
                    256:                }
                    257:        }
                    258: 
                    259:        /* locate the entry in termcap[] */
                    260:        for (i = 0; termcap[i] && strcmp(termcap[i], name); i++)
                    261:        {
                    262:        }
                    263:        if (!termcap[i])
                    264:        {
                    265:                return 0;
                    266:        }
                    267: 
                    268:        /* search forward for fields */
                    269:        while (termcap[i][0] != ':')
                    270:        {
                    271:                i++;
                    272:        }
                    273:        fields = termcap[i];
                    274:        return 1;
                    275: }
                    276: 
                    277: 
                    278: static char *find(id, vtype)
                    279:        char    *id;    /* name of a value to locate */
                    280:        int     vtype;  /* '=' for strings, '#' for numbers, or 0 for bools */
                    281: {
                    282:        int     i;
                    283: 
                    284:        /* search for a ':' followed by the two-letter id */
                    285:        for (i = 0; fields[i]; i++)
                    286:        {
                    287:                if (fields[i] == ':'
                    288:                 && fields[i + 1] == id[0]
                    289:                 && fields[i + 2] == id[1])
                    290:                {
                    291:                        /* if correct type, then return its value */
                    292:                        if (fields[i + 3] == vtype)
                    293:                                return &fields[i + 4];
                    294:                        else
                    295:                                return (char *)0;
                    296:                }
                    297:        }
                    298:        return (char *)0;
                    299: }
                    300: 
                    301: int tgetnum(id)
                    302: char   *id;
                    303: {
                    304:        char * temp;
                    305:        int ret = -1;
                    306: #if COHERENT
                    307:        if (strcmp(id, "co") == 0) {
                    308:                temp = getenv("COLUMNS");
                    309:                if (temp) {
                    310:                        ret = atoi(temp);
                    311:                        goto tgetnumdone;
                    312:        }
                    313: 
                    314:        if (strcmp(id, "li") == 0) {
                    315:                temp = getenv("LINES");
                    316:                if (temp) {
                    317:                        ret = atoi(temp);
                    318:                        goto tgetnumdone;
                    319:        }
                    320: #endif
                    321: 
                    322:        temp = find(id, '#');
                    323:        if (temp) {
                    324:                ret = atoi(temp);
                    325:        }
                    326: 
                    327: tgetnumdone:
                    328:        return ret;
                    329: }
                    330: 
                    331: int tgetflag(id)
                    332: char   *id;
                    333: {
                    334:        if (find(id, ':')) {
                    335:                return 1;
                    336:        }
                    337:        return 0;
                    338: }
                    339: 
                    340: /*ARGSUSED*/
                    341: char *tgetstr(id, bp)
                    342:        char    *id;
                    343:        char    **bp;   /* pointer to pointer to buffer - ignored */
                    344: {
                    345:        char    *cpy;
                    346: 
                    347:        /* find the string */
                    348:        id = find(id, '=');
                    349:        if (!id)
                    350:        {
                    351:                return (char *)0;
                    352:        }
                    353: 
                    354:        /* copy it into the buffer, and terminate it with NUL */
                    355:        for (cpy = *bp; *id != ':'; )
                    356:        {
                    357:                if (id[0] == '\\' && id[1] == 'E')
                    358:                        *cpy++ = '\033', id += 2;
                    359:                else
                    360:                        *cpy++ = *id++;
                    361:        }
                    362:        *cpy++ = '\0';
                    363: 
                    364:        /* update the bp pointer */
                    365:        id = *bp;
                    366:        *bp = cpy;
                    367: 
                    368:        /* return a pointer to the copy of the string */
                    369:        return id;
                    370: }
                    371: 
                    372: /*ARGSUSED*/
                    373: char *tgoto(cm, destcol, destrow)
                    374:        char    *cm;    /* cursor movement string -- ignored */
                    375:        int     destcol;/* destination column, 0 - 79 */
                    376:        int     destrow;/* destination row, 0 - 24 */
                    377: {
                    378:        static char buf[30];
                    379: 
                    380: #ifdef CRUNCH
                    381: # if TOS
                    382:        sprintf(buf, "\033Y%c%c", ' ' + destrow, ' ' + destcol);
                    383: # else
                    384:        sprintf(buf, "\033[%d;%dH", destrow + 1, destcol + 1);
                    385: # endif
                    386: #else
                    387:        if (cm[1] == 'Y' || cm[1] == '=')
                    388:                sprintf(buf, "\033%c%c%c", cm[1], ' ' + destrow, ' ' + destcol);
                    389:        else
                    390:                sprintf(buf, "\033[%d;%dH", destrow + 1, destcol + 1);
                    391: #endif
                    392:        return buf;
                    393: }
                    394: 
                    395: /*ARGSUSED*/
                    396: void tputs(cp, affcnt, outfn)
                    397:        char    *cp;            /* the string to output */
                    398:        int     affcnt;         /* number of affected lines -- ignored */
                    399:        int     (*outfn)();     /* the output function */
                    400: {
                    401:        while (*cp)
                    402:        {
                    403:                (*outfn)(*cp);
                    404:                cp++;
                    405:        }
                    406: }

unix.superglobalmegacorp.com

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