Annotation of 43BSD/contrib/mh/uip/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: 
        !            13: 
        !            14: #if    BUFSIZ<2048
        !            15: #define        TXTSIZ  2048
        !            16: #else
        !            17: #define        TXTSIZ  BUFSIZ
        !            18: #endif
        !            19: 
        !            20: #ifndef        SYS5
        !            21: extern char PC;
        !            22: extern short    ospeed;
        !            23: #else   SYS5
        !            24: char   PC;
        !            25: short  ospeed;
        !            26: #endif SYS5
        !            27: 
        !            28: int     tgetent (), tgetnum ();
        !            29: char   *tgetstr ();
        !            30: 
        !            31: /*  */
        !            32: 
        !            33: static int  initLI = 0;
        !            34: static int  LI = 40;
        !            35: static int  initCO = 0;
        !            36: static int  CO = 80;
        !            37: static char *CL = NULL;
        !            38: static char *SE = NULL;
        !            39: static char *SO = NULL;
        !            40: 
        !            41: static char termcap[TXTSIZ];
        !            42: 
        !            43: /*  */
        !            44: 
        !            45: static  read_termcap () {
        !            46:     register char  *bp,
        !            47:                    *term;
        !            48:     char   *cp,
        !            49:            myterm[TXTSIZ];
        !            50: #ifndef        SYS5
        !            51:     struct sgttyb   sg;
        !            52: #else  SYS5
        !            53:     struct termio   sg;
        !            54: #endif SYS5
        !            55:     static int  inited = 0;
        !            56: 
        !            57:     if (inited++)
        !            58:        return;
        !            59: 
        !            60:     if ((term = getenv ("TERM")) == NULL || tgetent (myterm, term) <= OK)
        !            61:        return;
        !            62: 
        !            63: #ifndef        SYS5
        !            64:     ospeed = ioctl (fileno (stdout), TIOCGETP, (char *) &sg) != NOTOK
        !            65:                ? sg.sg_ospeed : 0;
        !            66: #else  SYS5
        !            67:     ospeed = ioctl (fileno (stdout), TCGETA, &sg) != NOTOK
        !            68:                ? sg.c_cflag & CBAUD : 0;
        !            69: #endif SYS5
        !            70: 
        !            71:     if (!initCO && (CO = tgetnum ("co")) <= 0)
        !            72:        CO = 80;
        !            73:     if (!initLI && (LI = tgetnum ("li")) <= 0)
        !            74:        LI = 24;
        !            75: 
        !            76:     cp = termcap;
        !            77:     CL = tgetstr ("cl", &cp);
        !            78:     if (bp = tgetstr ("pc", &cp))
        !            79:        PC = *bp;
        !            80:     if (tgetnum ("sg") <= 0) {
        !            81:        SE = tgetstr ("se", &cp);
        !            82:        SO = tgetstr ("so", &cp);
        !            83:     }
        !            84: }
        !            85: 
        !            86: /*  */
        !            87: 
        !            88: int     sc_width () {
        !            89: #ifdef TIOCGWINSZ
        !            90:     struct winsize win;
        !            91: 
        !            92:     if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
        !            93:            && (CO = win.ws_col) > 0)
        !            94:        initCO++;
        !            95:     else
        !            96: #endif TIOCGWINSZ
        !            97:        read_termcap ();
        !            98: 
        !            99:     return CO;
        !           100: }
        !           101: 
        !           102: 
        !           103: int     sc_length () {
        !           104: #ifdef TIOCGWINSZ
        !           105:     struct winsize win;
        !           106: 
        !           107:     if (ioctl (fileno (stderr), TIOCGWINSZ, &win) != NOTOK
        !           108:            && (LI = win.ws_row) > 0)
        !           109:        initLI++;
        !           110:     else
        !           111: #endif TIOCGWINSZ
        !           112:        read_termcap ();
        !           113: 
        !           114:     return LI;
        !           115: }
        !           116: 
        !           117: /*  */
        !           118: 
        !           119: static int  outc (c)
        !           120: register char    c;
        !           121: {
        !           122:     (void) putchar (c);
        !           123: }
        !           124: 
        !           125: 
        !           126: void clear_screen () {
        !           127:     read_termcap ();
        !           128: 
        !           129:     if (CL && ospeed)
        !           130:        tputs (CL, LI, outc);
        !           131:     else {
        !           132:        printf ("\f");
        !           133:        if (ospeed)
        !           134:            printf ("\200");
        !           135:     }
        !           136: 
        !           137:     (void) fflush (stdout);
        !           138: }
        !           139: 
        !           140: /*  */
        !           141: 
        !           142: /* VARARGS1 */
        !           143: 
        !           144: int     SOprintf (fmt, a, b, c, d, e, f)
        !           145: char   *fmt,
        !           146:        *a,
        !           147:        *b,
        !           148:        *c,
        !           149:        *d,
        !           150:        *e,
        !           151:        *f;
        !           152: {
        !           153:     read_termcap ();
        !           154:     if (SO == NULL || SE == NULL)
        !           155:        return NOTOK;
        !           156: 
        !           157:     tputs (SO, 1, outc);
        !           158:     printf (fmt, a, b, c, d, e, f);
        !           159:     tputs (SE, 1, outc);
        !           160: 
        !           161:     return OK;
        !           162: }

unix.superglobalmegacorp.com

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