1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 2007-2010,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 * $Id: test_arrays.c,v 1.9 2020/02/02 23:34:34 tom Exp $
32 * Author: Thomas E Dickey
34 * Demonstrate the public arrays from the terminfo library.
36 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolnames[];
37 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[];
38 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolfnames[];
39 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numnames[];
40 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numcodes[];
41 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numfnames[];
42 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strnames[];
43 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strcodes[];
44 extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strfnames[];
49 #include <test.priv.h>
52 #if defined(HAVE_CURSES_DATA_BOOLNAMES) || defined(DECL_CURSES_DATA_BOOLNAMES)
61 #define PLAIN(opts, name) if (opts) dump_array(#name, name)
64 dump_array(const char *name, NCURSES_CONST char *const *list)
68 printf("%s:\n", name);
69 for (n = 0; list[n] != 0; ++n) {
70 printf("%5d:%s\n", n, list[n]);
77 PLAIN(opt_T && opt_n, boolnames);
78 PLAIN(opt_C && opt_c, boolcodes);
79 PLAIN(opt_T && opt_f, boolfnames);
81 PLAIN(opt_T && opt_n, numnames);
82 PLAIN(opt_C && opt_c, numcodes);
83 PLAIN(opt_T && opt_f, numfnames);
85 PLAIN(opt_T && opt_n, strnames);
86 PLAIN(opt_C && opt_c, strcodes);
87 PLAIN(opt_T && opt_f, strfnames);
90 #define STRING(opts, name) if (opts) { printf("%s\"%s\"", c++ ? "," : "", name); }
91 #define NUMBER(opts, value) if (opts) { printf("%s%d", c++ ? "," : "", value); }
99 STRING(opt_t, "Index");
100 STRING(opt_t, "Type");
101 STRING(opt_n, "Name");
102 STRING(opt_c, "Code");
103 STRING(opt_f, "FName");
106 for (r = 0; boolnames[r]; ++r) {
109 STRING(opt_t, "bool");
110 STRING(opt_T && opt_n, boolnames[r]);
111 STRING(opt_C && opt_c, boolcodes[r]);
112 STRING(opt_T && opt_f, boolfnames[r]);
116 for (r = 0; numnames[r]; ++r) {
119 STRING(opt_t, "num");
120 STRING(opt_T && opt_n, numnames[r]);
121 STRING(opt_C && opt_c, numcodes[r]);
122 STRING(opt_T && opt_f, numfnames[r]);
126 for (r = 0; strnames[r]; ++r) {
129 STRING(opt_t, "str");
130 STRING(opt_T && opt_n, strnames[r]);
131 STRING(opt_C && opt_c, strcodes[r]);
132 STRING(opt_T && opt_f, strfnames[r]);
140 static const char *msg[] =
142 "Usage: test_arrays [options]",
144 "If no options are given, print all (boolean, numeric, string)",
145 "capability names showing their index within the tables.",
148 " -C print termcap names",
149 " -T print terminfo names",
150 " -c print termcap names",
151 " -f print full terminfo names",
152 " -n print short terminfo names",
153 " -t print the result as CSV table",
156 for (n = 0; n < SIZEOF(msg); ++n) {
157 fprintf(stderr, "%s\n", msg[n]);
159 ExitProgram(EXIT_FAILURE);
163 main(int argc, char *argv[])
167 while ((n = getopt(argc, argv, "CTcfnt")) != -1) {
195 if (!(opt_T || opt_C)) {
196 opt_T = opt_C = TRUE;
198 if (!(opt_c || opt_f || opt_n)) {
199 opt_c = opt_f = opt_n = TRUE;
208 ExitProgram(EXIT_SUCCESS);
213 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
215 printf("This program requires the terminfo arrays\n");
216 ExitProgram(EXIT_FAILURE);
219 #else /* !HAVE_TIGETSTR */
221 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
223 printf("This program requires the terminfo functions such as tigetstr\n");
224 ExitProgram(EXIT_FAILURE);
226 #endif /* HAVE_TIGETSTR */