date and time created 85/09/06 17:51:25 by zliu
[unix-history] / usr / src / lib / libterm / TEST / tc3.c
CommitLineData
6468808a
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
a75239ad 7#ifndef lint
6468808a
DF
8static char sccsid[] = "@(#)tc3.c 5.1 (Berkeley) %G%";
9#endif not lint
a75239ad
SL
10
11/*
12 * tc3 [term]
13 * Dummy program to test out termlib.
14 * Input two numbers and it prints out the tgoto string generated.
15 */
16#include <stdio.h>
17char buf[1024];
18char *getenv(), *tgetstr();
19char *rdchar();
20char *tgoto();
21char *CM;
22char cmbuff[30];
23char *x;
24char *UP;
25char *tgout;
26
27main(argc, argv) char **argv; {
28 char *p;
29 int rc;
30 int row, col;
31
32 if (argc < 2)
33 p = getenv("TERM");
34 else
35 p = argv[1];
36 rc = tgetent(buf,p);
37 x = cmbuff;
38 UP = tgetstr("up", &x);
39 printf("UP = %x = ", UP); pr(UP); printf("\n");
40 if (UP && *UP==0)
41 UP = 0;
42 CM = tgetstr("cm", &x);
43 printf("CM = "); pr(CM); printf("\n");
44 for (;;) {
45 if (scanf("%d %d", &row, &col) < 2)
46 exit(0);
47 tgout = tgoto(CM, row, col);
48 pr(tgout);
49 printf("\n");
50 }
51}
52
53pr(p)
54register char *p;
55{
56 for (; *p; p++)
57 printf("%s", rdchar(*p));
58}
59
60/*
61 * rdchar: returns a readable representation of an ASCII char, using ^ notation.
62 */
63#include <ctype.h>
64char *rdchar(c)
65char c;
66{
67 static char ret[4];
68 register char *p;
69
70 /*
71 * Due to a bug in isprint, this prints spaces as ^`, but this is OK
72 * because we want something to show up on the screen.
73 */
74 ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
75 c &= 0177;
76 ret[1] = isprint(c) ? ' ' : '^';
77 ret[2] = isprint(c) ? c : c^0100;
78 ret[3] = 0;
79 for (p=ret; *p==' '; p++)
80 ;
81 return (p);
82}