xref: /csrg-svn/lib/libterm/TEST/tc3.c (revision 22071)
1*22071Sdist /*
2*22071Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22071Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22071Sdist  * specifies the terms and conditions for redistribution.
5*22071Sdist  */
6*22071Sdist 
713299Ssam #ifndef lint
8*22071Sdist static char sccsid[] = "@(#)tc3.c	5.1 (Berkeley) 06/05/85";
9*22071Sdist #endif not lint
1013299Ssam 
1113299Ssam /*
1213299Ssam  * tc3 [term]
1313299Ssam  * Dummy program to test out termlib.
1413299Ssam  * Input two numbers and it prints out the tgoto string generated.
1513299Ssam  */
1613299Ssam #include <stdio.h>
1713299Ssam char buf[1024];
1813299Ssam char *getenv(), *tgetstr();
1913299Ssam char *rdchar();
2013299Ssam char *tgoto();
2113299Ssam char *CM;
2213299Ssam char cmbuff[30];
2313299Ssam char *x;
2413299Ssam char *UP;
2513299Ssam char *tgout;
2613299Ssam 
2713299Ssam main(argc, argv) char **argv; {
2813299Ssam 	char *p;
2913299Ssam 	int rc;
3013299Ssam 	int row, col;
3113299Ssam 
3213299Ssam 	if (argc < 2)
3313299Ssam 		p = getenv("TERM");
3413299Ssam 	else
3513299Ssam 		p = argv[1];
3613299Ssam 	rc = tgetent(buf,p);
3713299Ssam 	x = cmbuff;
3813299Ssam 	UP = tgetstr("up", &x);
3913299Ssam 	printf("UP = %x = ", UP); pr(UP); printf("\n");
4013299Ssam 	if (UP && *UP==0)
4113299Ssam 		UP = 0;
4213299Ssam 	CM = tgetstr("cm", &x);
4313299Ssam 	printf("CM = "); pr(CM); printf("\n");
4413299Ssam 	for (;;) {
4513299Ssam 		if (scanf("%d %d", &row, &col) < 2)
4613299Ssam 			exit(0);
4713299Ssam 		tgout = tgoto(CM, row, col);
4813299Ssam 		pr(tgout);
4913299Ssam 		printf("\n");
5013299Ssam 	}
5113299Ssam }
5213299Ssam 
5313299Ssam pr(p)
5413299Ssam register char *p;
5513299Ssam {
5613299Ssam 	for (; *p; p++)
5713299Ssam 		printf("%s", rdchar(*p));
5813299Ssam }
5913299Ssam 
6013299Ssam /*
6113299Ssam  * rdchar: returns a readable representation of an ASCII char, using ^ notation.
6213299Ssam  */
6313299Ssam #include <ctype.h>
6413299Ssam char *rdchar(c)
6513299Ssam char c;
6613299Ssam {
6713299Ssam 	static char ret[4];
6813299Ssam 	register char *p;
6913299Ssam 
7013299Ssam 	/*
7113299Ssam 	 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
7213299Ssam 	 * because we want something to show up on the screen.
7313299Ssam 	 */
7413299Ssam 	ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
7513299Ssam 	c &= 0177;
7613299Ssam 	ret[1] = isprint(c) ? ' ' : '^';
7713299Ssam 	ret[2] = isprint(c) ?  c  : c^0100;
7813299Ssam 	ret[3] = 0;
7913299Ssam 	for (p=ret; *p==' '; p++)
8013299Ssam 		;
8113299Ssam 	return (p);
8213299Ssam }
83