xref: /csrg-svn/lib/libterm/TEST/tc3.c (revision 36499)
1 /*
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 char copyright[] =
20 "@(#) Copyright (c) 1980 The Regents of the University of California.\n\
21  All rights reserved.\n";
22 #endif /* not lint */
23 
24 #ifndef lint
25 static char sccsid[] = "@(#)tc3.c	5.2 (Berkeley) 01/03/89";
26 #endif /* not lint */
27 
28 /*
29  * tc3 [term]
30  * Dummy program to test out termlib.
31  * Input two numbers and it prints out the tgoto string generated.
32  */
33 #include <stdio.h>
34 char buf[1024];
35 char *getenv(), *tgetstr();
36 char *rdchar();
37 char *tgoto();
38 char *CM;
39 char cmbuff[30];
40 char *x;
41 char *UP;
42 char *tgout;
43 
44 main(argc, argv) char **argv; {
45 	char *p;
46 	int rc;
47 	int row, col;
48 
49 	if (argc < 2)
50 		p = getenv("TERM");
51 	else
52 		p = argv[1];
53 	rc = tgetent(buf,p);
54 	x = cmbuff;
55 	UP = tgetstr("up", &x);
56 	printf("UP = %x = ", UP); pr(UP); printf("\n");
57 	if (UP && *UP==0)
58 		UP = 0;
59 	CM = tgetstr("cm", &x);
60 	printf("CM = "); pr(CM); printf("\n");
61 	for (;;) {
62 		if (scanf("%d %d", &row, &col) < 2)
63 			exit(0);
64 		tgout = tgoto(CM, row, col);
65 		pr(tgout);
66 		printf("\n");
67 	}
68 }
69 
70 pr(p)
71 register char *p;
72 {
73 	for (; *p; p++)
74 		printf("%s", rdchar(*p));
75 }
76 
77 /*
78  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
79  */
80 #include <ctype.h>
81 char *rdchar(c)
82 char c;
83 {
84 	static char ret[4];
85 	register char *p;
86 
87 	/*
88 	 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
89 	 * because we want something to show up on the screen.
90 	 */
91 	ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
92 	c &= 0177;
93 	ret[1] = isprint(c) ? ' ' : '^';
94 	ret[2] = isprint(c) ?  c  : c^0100;
95 	ret[3] = 0;
96 	for (p=ret; *p==' '; p++)
97 		;
98 	return (p);
99 }
100