xref: /original-bsd/lib/libterm/TEST/tc2.c (revision c3e32dec)
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[] = "@(#)tc2.c	8.1 (Berkeley) 06/04/93";
16 #endif /* not lint */
17 
18 /*
19  * tc2 [term]
20  * Dummy program to test out termlib.
21  * Commands are "tcc\n" where t is type (s for string, f for flag,
22  * or n for number) and cc is the name of the capability.
23  */
24 #include <stdio.h>
25 char buf[1024];
26 char *getenv(), *tgetstr();
27 
28 main(argc, argv) char **argv; {
29 	char *p, *q;
30 	int rc;
31 	char b[3], c;
32 	char area[200];
33 
34 	if (argc < 2)
35 		p = getenv("TERM");
36 	else
37 		p = argv[1];
38 	rc = tgetent(buf,p);
39 	for (;;) {
40 		c = getchar();
41 		if (c < 0)
42 			exit(0);
43 		b[0] = getchar();
44 		if (b[0] < ' ')
45 			exit(0);
46 		b[1] = getchar();
47 		b[2] = 0;
48 		getchar();
49 		switch(c) {
50 			case 'f':
51 				printf("%s: %d\n",b,tgetflag(b));
52 				break;
53 			case 'n':
54 				printf("%s: %d\n",b,tgetnum(b));
55 				break;
56 			case 's':
57 				q = area;
58 				printf("%s: %s\n",b,tgetstr(b,&q));
59 				break;
60 			default:
61 				exit(0);
62 		}
63 	}
64 }
65