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