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