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