1 /****************************************************************************
2 * Copyright (c) 2005-2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
30 * Author: Thomas E. Dickey
32 * $Id: demo_termcap.c,v 1.6 2007/02/03 18:51:23 tom Exp $
34 * A simple demo of the termcap interface.
37 #include <test.priv.h>
41 #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0)
47 * One of the limitations of the termcap interface is that the library
48 * cannot determine the size of the buffer passed via tgetstr(), nor the
49 * amount of space remaining. This demo simply reuses the whole buffer
50 * for each call; a normal termcap application would try to use the buffer
51 * to hold all of the strings extracted from the terminal entry.
53 char area[1024], *ap = area;
57 if ((str = tgetstr(cap, &ap)) != 0) {
59 * Note that the strings returned are mostly terminfo format, since
60 * ncurses does not convert except for a handful of special cases.
62 printf("str %s = ", cap);
64 int ch = UChar(*str++);
94 fputs("\\072", stdout);
97 fputs("\\\\", stdout);
103 printf("^%c", ch + '@');
105 printf("\\%03o", ch);
110 } else if ((num = tgetnum(cap)) >= 0) {
111 printf("num %s = %d\n", cap, num);
112 } else if ((num = tgetflag(cap)) > 0) {
113 printf("flg %s\n", cap);
119 demo_termcap(const char *name)
123 printf("Terminal type %s\n", name);
124 if (tgetent(buffer, name) >= 0) {
129 for (c1 = 0; c1 < 256; ++c1) {
132 for (c2 = 0; c2 < 256; ++c2) {
144 main(int argc, char *argv[])
150 for (n = 1; n < argc; ++n) {
151 demo_termcap(argv[n]);
153 } else if ((name = getenv("TERM")) != 0) {
156 demo_termcap("dumb");
159 ExitProgram(EXIT_SUCCESS);
163 main(int argc GCC_UNUSED,
164 char *argv[]GCC_UNUSED)
166 printf("This program requires termcap\n");