written by Bill Joy; add Berkeley specific copyright
[unix-history] / usr / src / lib / libterm / TEST / tc3.c
CommitLineData
6468808a 1/*
31a14b65
KB
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.
6468808a
DF
16 */
17
a75239ad 18#ifndef lint
31a14b65
KB
19char 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
25static char sccsid[] = "@(#)tc3.c 5.2 (Berkeley) %G%";
26#endif /* not lint */
a75239ad
SL
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>
34char buf[1024];
35char *getenv(), *tgetstr();
36char *rdchar();
37char *tgoto();
38char *CM;
39char cmbuff[30];
40char *x;
41char *UP;
42char *tgout;
43
44main(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
70pr(p)
71register 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>
81char *rdchar(c)
82char 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}