1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/****************************************************************************
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 2007-2010,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/*
* $Id: test_arrays.c,v 1.13 2022/12/10 23:23:27 tom Exp $
*
* Author: Thomas E Dickey
*
* Demonstrate the public arrays from the terminfo library.
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolnames[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolfnames[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numnames[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numcodes[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numfnames[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strnames[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strcodes[];
extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strfnames[];
*/
#define USE_TINFO
#include <test.priv.h>
#if HAVE_TIGETSTR
#if defined(HAVE_CURSES_DATA_BOOLNAMES) || defined(DECL_CURSES_DATA_BOOLNAMES)
static bool opt_C;
static bool opt_T;
static bool opt_c;
static bool opt_f;
static bool opt_n;
static bool opt_t;
#define PLAIN(opts, name) if (opts) dump_array(#name, name)
static void
dump_array(const char *name, NCURSES_CONST char *const *list)
{
int n;
printf("%s:\n", name);
for (n = 0; list[n] != 0; ++n) {
printf("%5d:%s\n", n, list[n]);
}
}
static void
dump_plain(void)
{
PLAIN(opt_T && opt_n, boolnames);
PLAIN(opt_C && opt_c, boolcodes);
PLAIN(opt_T && opt_f, boolfnames);
PLAIN(opt_T && opt_n, numnames);
PLAIN(opt_C && opt_c, numcodes);
PLAIN(opt_T && opt_f, numfnames);
PLAIN(opt_T && opt_n, strnames);
PLAIN(opt_C && opt_c, strcodes);
PLAIN(opt_T && opt_f, strfnames);
}
#define STRING(opts, name) if (opts) { printf("%s\"%s\"", c++ ? "," : "", name); }
#define NUMBER(opts, value) if (opts) { printf("%s%d", c++ ? "," : "", value); }
static void
dump_table(void)
{
int c = 0;
int r;
STRING(opt_t, "Index");
STRING(opt_t, "Type");
STRING(opt_n, "Name");
STRING(opt_c, "Code");
STRING(opt_f, "FName");
printf("\n");
for (r = 0; boolnames[r]; ++r) {
c = 0;
NUMBER(opt_t, r);
STRING(opt_t, "bool");
STRING(opt_T && opt_n, boolnames[r]);
STRING(opt_C && opt_c, boolcodes[r]);
STRING(opt_T && opt_f, boolfnames[r]);
printf("\n");
}
for (r = 0; numnames[r]; ++r) {
c = 0;
NUMBER(opt_t, r);
STRING(opt_t, "num");
STRING(opt_T && opt_n, numnames[r]);
STRING(opt_C && opt_c, numcodes[r]);
STRING(opt_T && opt_f, numfnames[r]);
printf("\n");
}
for (r = 0; strnames[r]; ++r) {
c = 0;
NUMBER(opt_t, r);
STRING(opt_t, "str");
STRING(opt_T && opt_n, strnames[r]);
STRING(opt_C && opt_c, strcodes[r]);
STRING(opt_T && opt_f, strfnames[r]);
printf("\n");
}
}
static void
usage(int ok)
{
static const char *msg[] =
{
"Usage: test_arrays [options]"
,""
,"If no options are given, print all (boolean, numeric, string)"
,"capability names showing their index within the tables."
,""
,USAGE_COMMON
,"Options:"
," -C print termcap names"
," -T print terminfo names"
," -c print termcap names"
," -f print full terminfo names"
," -n print short terminfo names"
," -t print the result as CSV table"
};
unsigned n;
for (n = 0; n < SIZEOF(msg); ++n) {
fprintf(stderr, "%s\n", msg[n]);
}
ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* *INDENT-OFF* */
VERSION_COMMON()
/* *INDENT-ON* */
int
main(int argc, char *argv[])
{
int ch;
while ((ch = getopt(argc, argv, OPTS_COMMON "CTcfnt")) != -1) {
switch (ch) {
case 'C':
opt_C = TRUE;
break;
case 'T':
opt_T = TRUE;
break;
case 'c':
opt_c = TRUE;
break;
case 'f':
opt_f = TRUE;
break;
case 'n':
opt_n = TRUE;
break;
case 't':
opt_t = TRUE;
break;
case OPTS_VERSION:
show_version(argv);
ExitProgram(EXIT_SUCCESS);
default:
usage(ch == OPTS_USAGE);
/* NOTREACHED */
}
}
if (optind < argc)
usage(FALSE);
if (!(opt_T || opt_C)) {
opt_T = opt_C = TRUE;
}
if (!(opt_c || opt_f || opt_n)) {
opt_c = opt_f = opt_n = TRUE;
}
if (opt_t) {
dump_table();
} else {
dump_plain();
}
ExitProgram(EXIT_SUCCESS);
}
#else
int
main(void)
{
printf("This program requires the terminfo arrays\n");
ExitProgram(EXIT_FAILURE);
}
#endif
#else /* !HAVE_TIGETSTR */
int
main(void)
{
printf("This program requires the terminfo functions such as tigetstr\n");
ExitProgram(EXIT_FAILURE);
}
#endif /* HAVE_TIGETSTR */
|