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