xref: /original-bsd/lib/libterm/TEST/tc3.c (revision 04dd0305)
1 /*-
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1983, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)tc3.c	8.1 (Berkeley) 06/04/93";
16 #endif /* not lint */
17 
18 /*
19  * tc3 [term]
20  * Dummy program to test out termlib.  Input two numbers (row and col)
21  * and it prints out the tgoto string generated.
22  */
23 #include <stdio.h>
24 char buf[1024];
25 char *getenv(), *tgetstr();
26 char *rdchar();
27 char *tgoto();
28 char *CM;
29 char cmbuff[30];
30 char *x;
31 char *UP;
32 char *tgout;
33 
34 main(argc, argv) char **argv; {
35 	char *p;
36 	int rc;
37 	int row, col;
38 
39 	if (argc < 2)
40 		p = getenv("TERM");
41 	else
42 		p = argv[1];
43 	rc = tgetent(buf,p);
44 	x = cmbuff;
45 	UP = tgetstr("up", &x);
46 	printf("UP = %x = ", UP); pr(UP); printf("\n");
47 	if (UP && *UP==0)
48 		UP = 0;
49 	CM = tgetstr("cm", &x);
50 	printf("CM = "); pr(CM); printf("\n");
51 	for (;;) {
52 		if (scanf("%d %d", &row, &col) < 2)
53 			exit(0);
54 		tgout = tgoto(CM, col, row);
55 		pr(tgout);
56 		printf("\n");
57 	}
58 }
59 
60 pr(p)
61 register char *p;
62 {
63 	for (; *p; p++)
64 		printf("%s", rdchar(*p));
65 }
66 
67 /*
68  * rdchar() returns a readable representation of an ASCII character
69  * using ^ for control, ' for meta.
70  */
71 #include <ctype.h>
72 char *rdchar(c)
73 char c;
74 {
75 	static char ret[4];
76 	register char *p = ret;
77 
78 	if ((c&0377) > 0177)
79 		*p++ = '\'';
80 	c &= 0177;
81 	if (!isprint(c))
82 		*p++ = '^';
83 	*p++ = (isprint(c) ?  c  : c^0100);
84 	*p = 0;
85 	return (ret);
86 }
87