xref: /csrg-svn/lib/libterm/TEST/tc3.c (revision 61370)
147926Sbostic /*-
2*61370Sbostic  * Copyright (c) 1983, 1993
3*61370Sbostic  *	The Regents of the University of California.  All rights reserved.
436499Sbostic  *
547926Sbostic  * %sccs.include.redist.c%
622071Sdist  */
722071Sdist 
813299Ssam #ifndef lint
9*61370Sbostic static char copyright[] =
10*61370Sbostic "@(#) Copyright (c) 1983, 1993\n\
11*61370Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1236499Sbostic #endif /* not lint */
1313299Ssam 
1436499Sbostic #ifndef lint
15*61370Sbostic static char sccsid[] = "@(#)tc3.c	8.1 (Berkeley) 06/04/93";
1636499Sbostic #endif /* not lint */
1736499Sbostic 
1813299Ssam /*
1913299Ssam  * tc3 [term]
2036934Sjak  * Dummy program to test out termlib.  Input two numbers (row and col)
2136934Sjak  * and it prints out the tgoto string generated.
2213299Ssam  */
2313299Ssam #include <stdio.h>
2413299Ssam char buf[1024];
2513299Ssam char *getenv(), *tgetstr();
2613299Ssam char *rdchar();
2713299Ssam char *tgoto();
2813299Ssam char *CM;
2913299Ssam char cmbuff[30];
3013299Ssam char *x;
3113299Ssam char *UP;
3213299Ssam char *tgout;
3313299Ssam 
main(argc,argv)3413299Ssam main(argc, argv) char **argv; {
3513299Ssam 	char *p;
3613299Ssam 	int rc;
3713299Ssam 	int row, col;
3813299Ssam 
3913299Ssam 	if (argc < 2)
4013299Ssam 		p = getenv("TERM");
4113299Ssam 	else
4213299Ssam 		p = argv[1];
4313299Ssam 	rc = tgetent(buf,p);
4413299Ssam 	x = cmbuff;
4513299Ssam 	UP = tgetstr("up", &x);
4613299Ssam 	printf("UP = %x = ", UP); pr(UP); printf("\n");
4713299Ssam 	if (UP && *UP==0)
4813299Ssam 		UP = 0;
4913299Ssam 	CM = tgetstr("cm", &x);
5013299Ssam 	printf("CM = "); pr(CM); printf("\n");
5113299Ssam 	for (;;) {
5213299Ssam 		if (scanf("%d %d", &row, &col) < 2)
5313299Ssam 			exit(0);
5436934Sjak 		tgout = tgoto(CM, col, row);
5513299Ssam 		pr(tgout);
5613299Ssam 		printf("\n");
5713299Ssam 	}
5813299Ssam }
5913299Ssam 
pr(p)6013299Ssam pr(p)
6113299Ssam register char *p;
6213299Ssam {
6313299Ssam 	for (; *p; p++)
6413299Ssam 		printf("%s", rdchar(*p));
6513299Ssam }
6613299Ssam 
6713299Ssam /*
6836934Sjak  * rdchar() returns a readable representation of an ASCII character
6936934Sjak  * using ^ for control, ' for meta.
7013299Ssam  */
7113299Ssam #include <ctype.h>
rdchar(c)7213299Ssam char *rdchar(c)
7313299Ssam char c;
7413299Ssam {
7513299Ssam 	static char ret[4];
7636934Sjak 	register char *p = ret;
7713299Ssam 
7836934Sjak 	if ((c&0377) > 0177)
7936934Sjak 		*p++ = '\'';
8013299Ssam 	c &= 0177;
8136934Sjak 	if (!isprint(c))
8236934Sjak 		*p++ = '^';
8336934Sjak 	*p++ = (isprint(c) ?  c  : c^0100);
8436934Sjak 	*p = 0;
8536934Sjak 	return (ret);
8613299Ssam }
87