libncurses: updated to 6.0
[tomato.git] / release / src / router / libncurses / test / test_vid_puts.c
blob9896d1b6cc5c9f038796557046f1180d48d2f86d
1 /****************************************************************************
2 * Copyright (c) 2013,2014 Free Software Foundation, Inc. *
3 * *
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: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
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. *
22 * *
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 *
26 * authorization. *
27 ****************************************************************************/
29 * $Id: test_vid_puts.c,v 1.6 2014/07/19 23:09:28 tom Exp $
31 * Demonstrate the vid_puts and vid_attr functions.
32 * Thomas Dickey - 2013/01/12
35 #define USE_TINFO
36 #include <test.priv.h>
38 #if USE_WIDEC_SUPPORT && HAVE_SETUPTERM && HAVE_VID_PUTS
40 #define valid(s) ((s != 0) && s != (char *)-1)
42 static FILE *my_fp;
43 static bool p_opt = FALSE;
45 static
46 TPUTS_PROTO(outc, c)
48 int rc = c;
50 rc = putc(c, my_fp);
51 TPUTS_RETURN(rc);
54 static bool
55 outs(const char *s)
57 if (valid(s)) {
58 tputs(s, 1, outc);
59 return TRUE;
61 return FALSE;
64 static void
65 cleanup(void)
67 outs(exit_attribute_mode);
68 if (!outs(orig_colors))
69 outs(orig_pair);
70 outs(cursor_normal);
73 static void
74 change_attr(chtype attr)
76 if (p_opt) {
77 vid_puts(attr, (short) 0, (void *) 0, outc);
78 } else {
79 vid_attr(attr, (short) 0, (void *) 0);
83 static void
84 test_vid_puts(void)
86 fprintf(my_fp, "Name: ");
87 change_attr(A_BOLD);
88 fputs("Bold", my_fp);
89 change_attr(A_REVERSE);
90 fputs(" Reverse", my_fp);
91 change_attr(A_NORMAL);
92 fputs("\n", my_fp);
95 static void
96 usage(void)
98 static const char *tbl[] =
100 "Usage: test_vid_puts [options]"
102 ,"Options:"
103 ," -e use stderr (default stdout)"
104 ," -p use vid_puts (default vid_attr)"
106 unsigned n;
107 for (n = 0; n < SIZEOF(tbl); ++n)
108 fprintf(stderr, "%s\n", tbl[n]);
109 ExitProgram(EXIT_FAILURE);
113 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
115 int ch;
117 my_fp = stdout;
119 while ((ch = getopt(argc, argv, "ep")) != -1) {
120 switch (ch) {
121 case 'e':
122 my_fp = stderr;
123 break;
124 case 'p':
125 p_opt = TRUE;
126 break;
127 default:
128 usage();
129 break;
132 if (optind < argc)
133 usage();
135 setupterm((char *) 0, 1, (int *) 0);
136 test_vid_puts();
137 cleanup();
138 ExitProgram(EXIT_SUCCESS);
141 #else
143 main(void)
145 printf("This program requires the wide-ncurses terminfo library\n");
146 ExitProgram(EXIT_FAILURE);
148 #endif