Annotation of 43BSDReno/contrib/mh/sbr/trmsbr.c, revision 1.1

1.1     ! root        1: /* trmsbr.c - minor termcap support (load with -ltermlib) */
        !             2: 
        !             3: #include "../h/mh.h"
        !             4: #include <stdio.h>
        !             5: #ifndef        SYS5
        !             6: #include <sgtty.h>
        !             7: #else  SYS5
        !             8: #include <sys/types.h>
        !             9: #include <termio.h>
        !            10: #include <sys/ioctl.h>
        !            11: #endif SYS5
        !            12: #include <ctype.h>
        !            13: 
        !            14: 
        !            15: #if    BUFSIZ<2048
        !            16: #define        TXTSIZ  2048
        !            17: #else
        !            18: #define        TXTSIZ  BUFSIZ
        !            19: #endif
        !            20: 
        !            21: char   PC;
        !            22: short  ospeed;
        !            23: 
        !            24: int     tgetent (), tgetnum ();
        !            25: char   *tgetstr ();
        !            26: 
        !            27: /*  */
        !            28: 
        !            29: static int  TCinited = 0;
        !            30: static int  initLI = 0;
        !            31: static int  LI = 40;
        !            32: static int  initCO = 0;
        !            33: static int  CO = 80;
        !            34: static char *CL = NULL;
        !            35: static char *SE = NULL;
        !            36: static char *SO = NULL;
        !            37: 
        !            38: static char termcap[TXTSIZ];
        !            39: 
        !            40: /*  */
        !            41: 
        !            42: static void
        !            43: read_termcap()
        !            44: {
        !            45:     register char  *bp,
        !            46:                    *term;
        !            47:     char   *cp,
        !            48:            myterm[TXTSIZ];
        !            49: #ifndef        SYS5
        !            50:     struct sgttyb   sg;
        !            51: #else  SYS5
        !            52:     struct termio   sg;
        !            53: #endif SYS5
        !            54: 
        !            55:     if (TCinited)
        !            56:        return;
        !            57: 
        !            58:     ++TCinited;
        !            59:     if ((term = getenv ("TERM")) == NULL || tgetent (myterm, term) <= OK)
        !            60:        return;
        !            61: 
        !            62: #ifndef        SYS5
        !            63:     ospeed = ioctl (fileno (stdout), TIOCGETP, (char *) &sg) != NOTOK
        !            64:                ? sg.sg_ospeed : 0;
        !            65: #else  SYS5
        !            66:     ospeed = ioctl (fileno (stdout), TCGETA, &sg) != NOTOK
        !            67:                ? sg.c_cflag & CBAUD : 0;
        !            68: #endif SYS5
        !            69: 
        !            70:     if (!initCO && (CO = tgetnum ("co")) <= 0)
        !            71:        CO = 80;
        !            72:     if (!initLI && (LI = tgetnum ("li")) <= 0)
        !            73:        LI = 24;
        !            74: 
        !            75:     cp = termcap;
        !            76:     CL = tgetstr ("cl", &cp);
        !            77:     if (bp = tgetstr ("pc", &cp))
        !            78:        PC = *bp;
        !            79:     if (tgetnum ("sg") <= 0) {
        !            80:        SE = tgetstr ("se", &cp);
        !            81:        SO = tgetstr ("so", &cp);
        !            82:     }
        !            83: }
        !            84: 
        !            85: /*  */
        !            86: 
        !            87: int
        !            88: sc_width()
        !            89: {
        !            90: #ifdef TIOCGWINSZ
        !            91:     struct winsize win;
        !            92: 
        !            93:     if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
        !            94:            && (CO = win.ws_col) > 0)
        !            95:        initCO++;
        !            96:     else
        !            97: #endif TIOCGWINSZ
        !            98:        read_termcap();
        !            99: 
        !           100:     return CO;
        !           101: }
        !           102: 
        !           103: 
        !           104: int
        !           105: sc_length()
        !           106: {
        !           107: #ifdef TIOCGWINSZ
        !           108:     struct winsize win;
        !           109: 
        !           110:     if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
        !           111:            && (LI = win.ws_row) > 0)
        !           112:        initLI++;
        !           113:     else
        !           114: #endif TIOCGWINSZ
        !           115:        read_termcap();
        !           116: 
        !           117:     return LI;
        !           118: }
        !           119: 
        !           120: /*  */
        !           121: 
        !           122: static int
        !           123: outc(c)
        !           124: register char    c;
        !           125: {
        !           126:     (void) putchar (c);
        !           127: }
        !           128: 
        !           129: 
        !           130: void
        !           131: clear_screen()
        !           132: {
        !           133:     read_termcap();
        !           134: 
        !           135:     if (CL && ospeed)
        !           136:        tputs (CL, LI, outc);
        !           137:     else {
        !           138:        printf ("\f");
        !           139:        if (ospeed)
        !           140:            printf ("\200");
        !           141:     }
        !           142: 
        !           143:     (void) fflush (stdout);
        !           144: }
        !           145: 
        !           146: /*  */
        !           147: 
        !           148: /* VARARGS1 */
        !           149: 
        !           150: SOprintf(fmt, a, b, c, d, e, f)
        !           151: char   *fmt,
        !           152:        *a,
        !           153:        *b,
        !           154:        *c,
        !           155:        *d,
        !           156:        *e,
        !           157:        *f;
        !           158: {
        !           159:     read_termcap();
        !           160:     if (SO == NULL || SE == NULL)
        !           161:        return NOTOK;
        !           162: 
        !           163:     tputs (SO, 1, outc);
        !           164:     printf (fmt, a, b, c, d, e, f);
        !           165:     tputs (SE, 1, outc);
        !           166: 
        !           167:     return OK;
        !           168: }
        !           169: 
        !           170: #define MAXTCENT 32
        !           171: static int nTCent;
        !           172: static char *TCid[MAXTCENT];
        !           173: static char *TCent[MAXTCENT];
        !           174: 
        !           175: char *
        !           176: get_termcap(id)
        !           177:        char *id;
        !           178: {
        !           179:        register int i;
        !           180:        char *cp;
        !           181:        static char tcbuf[1024];
        !           182:        static char *tcptr = tcbuf;
        !           183: 
        !           184:        for (i = 0; i < nTCent; ++i)
        !           185:                if (strcmp(TCid[i], id) == 0)
        !           186:                        return (TCent[i]);
        !           187: 
        !           188:        if (nTCent >= MAXTCENT)
        !           189:                return ("");
        !           190: 
        !           191:        TCid[nTCent] = getcpy(id);
        !           192: 
        !           193:        if (TCinited == 0)
        !           194:                read_termcap();
        !           195: 
        !           196:        cp = tgetstr(id, &tcptr);
        !           197:        if (cp == 0) {
        !           198:                /* check for some alternates for the entry */
        !           199:                if (strcmp(id, "mb") == 0 ||
        !           200:                    strcmp(id, "md") == 0 ||
        !           201:                    strcmp(id, "mh") == 0 ||
        !           202:                    strcmp(id, "mr") == 0 ||
        !           203:                    strcmp(id, "us") == 0)
        !           204:                        id = "so";
        !           205:                else if (strcmp(id, "me") == 0 ||
        !           206:                         strcmp(id, "ue") == 0)
        !           207:                        id = "se";
        !           208:                cp = tgetstr(id, &tcptr);
        !           209:                if (cp == 0)
        !           210:                        cp = "";
        !           211:        }
        !           212: 
        !           213:        /* skip leading delay spec */
        !           214:        while (isdigit(*cp))
        !           215:                ++cp;
        !           216:        if (*cp == '.')
        !           217:                if (isdigit(*++cp))
        !           218:                        ++cp;
        !           219:        if (*cp == '*')
        !           220:                ++cp;
        !           221: 
        !           222:        TCent[nTCent] = cp;
        !           223:        ++nTCent;
        !           224:        return (cp);
        !           225: }

unix.superglobalmegacorp.com

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