OSDN Git Service

initial commit
[openbsd-octeon/openbsd-octeon.git] / src / lib / libocurses / TEST / tc3.c
1 /*-
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 /*
31  * tc3 [term]
32  * Dummy program to test out termlib.  Input two numbers (row and col)
33  * and it prints out the tgoto string generated.
34  */
35 #include <stdio.h>
36 char buf[1024];
37 char *getenv(), *tgetstr();
38 char *rdchar();
39 char *tgoto();
40 char *CM;
41 char cmbuff[30];
42 char *x;
43 char *UP;
44 char *tgout;
45
46 main(argc, argv) char **argv; {
47         char *p;
48         int rc;
49         int row, col;
50
51         if (argc < 2)
52                 p = getenv("TERM");
53         else
54                 p = argv[1];
55         rc = tgetent(buf,p);
56         x = cmbuff;
57         UP = tgetstr("up", &x);
58         printf("UP = %x = ", UP); pr(UP); printf("\n");
59         if (UP && *UP==0)
60                 UP = 0;
61         CM = tgetstr("cm", &x);
62         printf("CM = "); pr(CM); printf("\n");
63         for (;;) {
64                 if (scanf("%d %d", &row, &col) < 2)
65                         exit(0);
66                 tgout = tgoto(CM, col, row);
67                 pr(tgout);
68                 printf("\n");
69         }
70 }
71
72 pr(p)
73 register char *p;
74 {
75         for (; *p; p++)
76                 printf("%s", rdchar(*p));
77 }
78
79 /*
80  * rdchar() returns a readable representation of an ASCII character
81  * using ^ for control, ' for meta.
82  */
83 #include <ctype.h>
84 char *rdchar(c)
85 char c;
86 {
87         static char ret[4];
88         register char *p = ret;
89
90         if ((c&0377) > 0177)
91                 *p++ = '\'';
92         c &= 0177;
93         if (!isprint(c))
94                 *p++ = '^';
95         *p++ = (isprint(c) ?  c  : c^0100);
96         *p = 0;
97         return (ret);
98 }