1 /*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #ifndef lint
31 static char copyright[] =
32 "@(#) Copyright (c) 1983, 1993\n\
33 The Regents of the University of California. All rights reserved.\n";
34 #endif /* not lint */
35
36 #ifndef lint
37 static char sccsid[] = "@(#)tc3.c 8.1 (Berkeley) 6/4/93";
38 #endif /* not lint */
39
40 /*
41 * tc3 [term]
42 * Dummy program to test out termlib. Input two numbers (row and col)
43 * and it prints out the tgoto string generated.
44 */
45 #include <stdio.h>
46 char buf[1024];
47 char *getenv(), *tgetstr();
48 char *rdchar();
49 char *tgoto();
50 char *CM;
51 char cmbuff[30];
52 char *x;
53 char *UP;
54 char *tgout;
55
main(argc,argv)56 main(argc, argv) char **argv; {
57 char *p;
58 int rc;
59 int row, col;
60
61 if (argc < 2)
62 p = getenv("TERM");
63 else
64 p = argv[1];
65 rc = tgetent(buf,p);
66 x = cmbuff;
67 UP = tgetstr("up", &x);
68 printf("UP = %x = ", UP); pr(UP); printf("\n");
69 if (UP && *UP==0)
70 UP = 0;
71 CM = tgetstr("cm", &x);
72 printf("CM = "); pr(CM); printf("\n");
73 for (;;) {
74 if (scanf("%d %d", &row, &col) < 2)
75 exit(0);
76 tgout = tgoto(CM, col, row);
77 pr(tgout);
78 printf("\n");
79 }
80 }
81
pr(p)82 pr(p)
83 register char *p;
84 {
85 for (; *p; p++)
86 printf("%s", rdchar(*p));
87 }
88
89 /*
90 * rdchar() returns a readable representation of an ASCII character
91 * using ^ for control, ' for meta.
92 */
93 #include <ctype.h>
rdchar(c)94 char *rdchar(c)
95 char c;
96 {
97 static char ret[4];
98 register char *p = ret;
99
100 if ((c&0377) > 0177)
101 *p++ = '\'';
102 c &= 0177;
103 if (!isprint(c))
104 *p++ = '^';
105 *p++ = (isprint(c) ? c : c^0100);
106 *p = 0;
107 return (ret);
108 }
109