Annotation of 42BSD/usr.lib/libtermlib/tc3.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)tc3.c      4.1 (Berkeley) 6/27/83";
                      3: #endif
                      4: 
                      5: /*
                      6:  * tc3 [term]
                      7:  * Dummy program to test out termlib.
                      8:  * Input two numbers and it prints out the tgoto string generated.
                      9:  */
                     10: #include <stdio.h>
                     11: char buf[1024];
                     12: char *getenv(), *tgetstr();
                     13: char *rdchar();
                     14: char *tgoto();
                     15: char *CM;
                     16: char cmbuff[30];
                     17: char *x;
                     18: char *UP;
                     19: char *tgout;
                     20: 
                     21: main(argc, argv) char **argv; {
                     22:        char *p;
                     23:        int rc;
                     24:        int row, col;
                     25: 
                     26:        if (argc < 2)
                     27:                p = getenv("TERM");
                     28:        else
                     29:                p = argv[1];
                     30:        rc = tgetent(buf,p);
                     31:        x = cmbuff;
                     32:        UP = tgetstr("up", &x);
                     33:        printf("UP = %x = ", UP); pr(UP); printf("\n");
                     34:        if (UP && *UP==0)
                     35:                UP = 0;
                     36:        CM = tgetstr("cm", &x);
                     37:        printf("CM = "); pr(CM); printf("\n");
                     38:        for (;;) {
                     39:                if (scanf("%d %d", &row, &col) < 2)
                     40:                        exit(0);
                     41:                tgout = tgoto(CM, row, col);
                     42:                pr(tgout);
                     43:                printf("\n");
                     44:        }
                     45: }
                     46: 
                     47: pr(p)
                     48: register char *p;
                     49: {
                     50:        for (; *p; p++)
                     51:                printf("%s", rdchar(*p));
                     52: }
                     53: 
                     54: /*
                     55:  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
                     56:  */
                     57: #include <ctype.h>
                     58: char *rdchar(c)
                     59: char c;
                     60: {
                     61:        static char ret[4];
                     62:        register char *p;
                     63: 
                     64:        /*
                     65:         * Due to a bug in isprint, this prints spaces as ^`, but this is OK
                     66:         * because we want something to show up on the screen.
                     67:         */
                     68:        ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
                     69:        c &= 0177;
                     70:        ret[1] = isprint(c) ? ' ' : '^';
                     71:        ret[2] = isprint(c) ?  c  : c^0100;
                     72:        ret[3] = 0;
                     73:        for (p=ret; *p==' '; p++)
                     74:                ;
                     75:        return (p);
                     76: }

unix.superglobalmegacorp.com

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