Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 2 | * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | ****************************************************************************/ |
| 28 | |
| 29 | /**************************************************************************** |
| 30 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 31 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
| 32 | * and: Thomas E. Dickey 1996-on * |
| 33 | ****************************************************************************/ |
| 34 | |
| 35 | /* |
| 36 | * infocmp.c -- decompile an entry, or compare two entries |
| 37 | * written by Eric S. Raymond |
| 38 | * and Thomas E Dickey |
| 39 | */ |
| 40 | |
| 41 | #include <progs.priv.h> |
| 42 | |
| 43 | #include <dump_entry.h> |
| 44 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 45 | MODULE_ID("$Id: infocmp.c,v 1.133 2015/05/27 00:57:41 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 46 | |
| 47 | #define L_CURL "{" |
| 48 | #define R_CURL "}" |
| 49 | |
| 50 | #define MAX_STRING 1024 /* maximum formatted string */ |
| 51 | |
| 52 | const char *_nc_progname = "infocmp"; |
| 53 | |
| 54 | typedef char path[PATH_MAX]; |
| 55 | |
| 56 | /*************************************************************************** |
| 57 | * |
| 58 | * The following control variables, together with the contents of the |
| 59 | * terminfo entries, completely determine the actions of the program. |
| 60 | * |
| 61 | ***************************************************************************/ |
| 62 | |
| 63 | static ENTRY *entries; /* terminfo entries */ |
| 64 | static int termcount; /* count of terminal entries */ |
| 65 | |
| 66 | static bool limited = TRUE; /* "-r" option is not set */ |
| 67 | static bool quiet = FALSE; |
| 68 | static bool literal = FALSE; |
| 69 | static const char *bool_sep = ":"; |
| 70 | static const char *s_absent = "NULL"; |
| 71 | static const char *s_cancel = "NULL"; |
| 72 | static const char *tversion; /* terminfo version selected */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 73 | static unsigned itrace; /* trace flag for debugging */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 74 | static int mwidth = 60; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 75 | static int mheight = 65535; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 76 | static int numbers = 0; /* format "%'char'" to/from "%{number}" */ |
| 77 | static int outform = F_TERMINFO; /* output format */ |
| 78 | static int sortmode; /* sort_mode */ |
| 79 | |
| 80 | /* main comparison mode */ |
| 81 | static int compare; |
| 82 | #define C_DEFAULT 0 /* don't force comparison mode */ |
| 83 | #define C_DIFFERENCE 1 /* list differences between two terminals */ |
| 84 | #define C_COMMON 2 /* list common capabilities */ |
| 85 | #define C_NAND 3 /* list capabilities in neither terminal */ |
| 86 | #define C_USEALL 4 /* generate relative use-form entry */ |
| 87 | static bool ignorepads; /* ignore pad prefixes when diffing */ |
| 88 | |
| 89 | #if NO_LEAKS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 90 | |
| 91 | typedef struct { |
| 92 | ENTRY *head; |
| 93 | ENTRY *tail; |
| 94 | } ENTERED; |
| 95 | |
| 96 | static ENTERED *entered; |
| 97 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 98 | #undef ExitProgram |
| 99 | static void ExitProgram(int code) GCC_NORETURN; |
| 100 | /* prototype is to get gcc to accept the noreturn attribute */ |
| 101 | static void |
| 102 | ExitProgram(int code) |
| 103 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 104 | int n; |
| 105 | |
| 106 | for (n = 0; n < termcount; ++n) { |
| 107 | ENTRY *new_head = _nc_head; |
| 108 | ENTRY *new_tail = _nc_tail; |
| 109 | _nc_head = entered[n].head; |
| 110 | _nc_tail = entered[n].tail; |
| 111 | _nc_free_entries(entered[n].head); |
| 112 | _nc_head = new_head; |
| 113 | _nc_tail = new_tail; |
| 114 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 115 | _nc_leaks_dump_entry(); |
| 116 | free(entries); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 117 | free(entered); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 118 | _nc_free_tic(code); |
| 119 | } |
| 120 | #endif |
| 121 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 122 | static void |
| 123 | failed(const char *s) |
| 124 | { |
| 125 | perror(s); |
| 126 | ExitProgram(EXIT_FAILURE); |
| 127 | } |
| 128 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 129 | static char * |
| 130 | canonical_name(char *ptr, char *buf) |
| 131 | /* extract the terminal type's primary name */ |
| 132 | { |
| 133 | char *bp; |
| 134 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 135 | _nc_STRCPY(buf, ptr, NAMESIZE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 136 | if ((bp = strchr(buf, '|')) != 0) |
| 137 | *bp = '\0'; |
| 138 | |
| 139 | return (buf); |
| 140 | } |
| 141 | |
| 142 | /*************************************************************************** |
| 143 | * |
| 144 | * Predicates for dump function |
| 145 | * |
| 146 | ***************************************************************************/ |
| 147 | |
| 148 | static int |
| 149 | capcmp(PredIdx idx, const char *s, const char *t) |
| 150 | /* capability comparison function */ |
| 151 | { |
| 152 | if (!VALID_STRING(s) && !VALID_STRING(t)) |
| 153 | return (s != t); |
| 154 | else if (!VALID_STRING(s) || !VALID_STRING(t)) |
| 155 | return (1); |
| 156 | |
| 157 | if ((idx == acs_chars_index) || !ignorepads) |
| 158 | return (strcmp(s, t)); |
| 159 | else |
| 160 | return (_nc_capcmp(s, t)); |
| 161 | } |
| 162 | |
| 163 | static int |
| 164 | use_predicate(unsigned type, PredIdx idx) |
| 165 | /* predicate function to use for use decompilation */ |
| 166 | { |
| 167 | ENTRY *ep; |
| 168 | |
| 169 | switch (type) { |
| 170 | case BOOLEAN: |
| 171 | { |
| 172 | int is_set = FALSE; |
| 173 | |
| 174 | /* |
| 175 | * This assumes that multiple use entries are supposed |
| 176 | * to contribute the logical or of their boolean capabilities. |
| 177 | * This is true if we take the semantics of multiple uses to |
| 178 | * be 'each capability gets the first non-default value found |
| 179 | * in the sequence of use entries'. |
| 180 | * |
| 181 | * Note that cancelled or absent booleans are stored as FALSE, |
| 182 | * unlike numbers and strings, whose cancelled/absent state is |
| 183 | * recorded in the terminfo database. |
| 184 | */ |
| 185 | for (ep = &entries[1]; ep < entries + termcount; ep++) |
| 186 | if (ep->tterm.Booleans[idx] == TRUE) { |
| 187 | is_set = entries[0].tterm.Booleans[idx]; |
| 188 | break; |
| 189 | } |
| 190 | if (is_set != entries[0].tterm.Booleans[idx]) |
| 191 | return (!is_set); |
| 192 | else |
| 193 | return (FAIL); |
| 194 | } |
| 195 | |
| 196 | case NUMBER: |
| 197 | { |
| 198 | int value = ABSENT_NUMERIC; |
| 199 | |
| 200 | /* |
| 201 | * We take the semantics of multiple uses to be 'each |
| 202 | * capability gets the first non-default value found |
| 203 | * in the sequence of use entries'. |
| 204 | */ |
| 205 | for (ep = &entries[1]; ep < entries + termcount; ep++) |
| 206 | if (VALID_NUMERIC(ep->tterm.Numbers[idx])) { |
| 207 | value = ep->tterm.Numbers[idx]; |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | if (value != entries[0].tterm.Numbers[idx]) |
| 212 | return (value != ABSENT_NUMERIC); |
| 213 | else |
| 214 | return (FAIL); |
| 215 | } |
| 216 | |
| 217 | case STRING: |
| 218 | { |
| 219 | char *termstr, *usestr = ABSENT_STRING; |
| 220 | |
| 221 | termstr = entries[0].tterm.Strings[idx]; |
| 222 | |
| 223 | /* |
| 224 | * We take the semantics of multiple uses to be 'each |
| 225 | * capability gets the first non-default value found |
| 226 | * in the sequence of use entries'. |
| 227 | */ |
| 228 | for (ep = &entries[1]; ep < entries + termcount; ep++) |
| 229 | if (ep->tterm.Strings[idx]) { |
| 230 | usestr = ep->tterm.Strings[idx]; |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | if (usestr == ABSENT_STRING && termstr == ABSENT_STRING) |
| 235 | return (FAIL); |
| 236 | else if (!usestr || !termstr || capcmp(idx, usestr, termstr)) |
| 237 | return (TRUE); |
| 238 | else |
| 239 | return (FAIL); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | return (FALSE); /* pacify compiler */ |
| 244 | } |
| 245 | |
| 246 | static bool |
| 247 | useeq(ENTRY * e1, ENTRY * e2) |
| 248 | /* are the use references in two entries equivalent? */ |
| 249 | { |
| 250 | unsigned i, j; |
| 251 | |
| 252 | if (e1->nuses != e2->nuses) |
| 253 | return (FALSE); |
| 254 | |
| 255 | /* Ugh...this is quadratic again */ |
| 256 | for (i = 0; i < e1->nuses; i++) { |
| 257 | bool foundmatch = FALSE; |
| 258 | |
| 259 | /* search second entry for given use reference */ |
| 260 | for (j = 0; j < e2->nuses; j++) |
| 261 | if (!strcmp(e1->uses[i].name, e2->uses[j].name)) { |
| 262 | foundmatch = TRUE; |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | if (!foundmatch) |
| 267 | return (FALSE); |
| 268 | } |
| 269 | |
| 270 | return (TRUE); |
| 271 | } |
| 272 | |
| 273 | static bool |
| 274 | entryeq(TERMTYPE *t1, TERMTYPE *t2) |
| 275 | /* are two entries equivalent? */ |
| 276 | { |
| 277 | unsigned i; |
| 278 | |
| 279 | for (i = 0; i < NUM_BOOLEANS(t1); i++) |
| 280 | if (t1->Booleans[i] != t2->Booleans[i]) |
| 281 | return (FALSE); |
| 282 | |
| 283 | for (i = 0; i < NUM_NUMBERS(t1); i++) |
| 284 | if (t1->Numbers[i] != t2->Numbers[i]) |
| 285 | return (FALSE); |
| 286 | |
| 287 | for (i = 0; i < NUM_STRINGS(t1); i++) |
| 288 | if (capcmp((PredIdx) i, t1->Strings[i], t2->Strings[i])) |
| 289 | return (FALSE); |
| 290 | |
| 291 | return (TRUE); |
| 292 | } |
| 293 | |
| 294 | #define TIC_EXPAND(result) _nc_tic_expand(result, outform==F_TERMINFO, numbers) |
| 295 | |
| 296 | static void |
| 297 | print_uses(ENTRY * ep, FILE *fp) |
| 298 | /* print an entry's use references */ |
| 299 | { |
| 300 | unsigned i; |
| 301 | |
| 302 | if (!ep->nuses) |
| 303 | fputs("NULL", fp); |
| 304 | else |
| 305 | for (i = 0; i < ep->nuses; i++) { |
| 306 | fputs(ep->uses[i].name, fp); |
| 307 | if (i < ep->nuses - 1) |
| 308 | fputs(" ", fp); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | static const char * |
| 313 | dump_boolean(int val) |
| 314 | /* display the value of a boolean capability */ |
| 315 | { |
| 316 | switch (val) { |
| 317 | case ABSENT_BOOLEAN: |
| 318 | return (s_absent); |
| 319 | case CANCELLED_BOOLEAN: |
| 320 | return (s_cancel); |
| 321 | case FALSE: |
| 322 | return ("F"); |
| 323 | case TRUE: |
| 324 | return ("T"); |
| 325 | default: |
| 326 | return ("?"); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | static void |
| 331 | dump_numeric(int val, char *buf) |
| 332 | /* display the value of a boolean capability */ |
| 333 | { |
| 334 | switch (val) { |
| 335 | case ABSENT_NUMERIC: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 336 | _nc_STRCPY(buf, s_absent, MAX_STRING); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 337 | break; |
| 338 | case CANCELLED_NUMERIC: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 339 | _nc_STRCPY(buf, s_cancel, MAX_STRING); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 340 | break; |
| 341 | default: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 342 | _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING) "%d", val); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static void |
| 348 | dump_string(char *val, char *buf) |
| 349 | /* display the value of a string capability */ |
| 350 | { |
| 351 | if (val == ABSENT_STRING) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 352 | _nc_STRCPY(buf, s_absent, MAX_STRING); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 353 | else if (val == CANCELLED_STRING) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 354 | _nc_STRCPY(buf, s_cancel, MAX_STRING); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 355 | else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 356 | _nc_SPRINTF(buf, _nc_SLIMIT(MAX_STRING) |
| 357 | "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 361 | /* |
| 362 | * Show "comparing..." message for the given terminal names. |
| 363 | */ |
| 364 | static void |
| 365 | show_comparing(char **names) |
| 366 | { |
| 367 | if (itrace) { |
| 368 | switch (compare) { |
| 369 | case C_DIFFERENCE: |
| 370 | (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname); |
| 371 | break; |
| 372 | |
| 373 | case C_COMMON: |
| 374 | (void) fprintf(stderr, "%s: dumping common capabilities\n", _nc_progname); |
| 375 | break; |
| 376 | |
| 377 | case C_NAND: |
| 378 | (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname); |
| 379 | break; |
| 380 | } |
| 381 | } |
| 382 | if (*names) { |
| 383 | printf("comparing %s", *names++); |
| 384 | if (*names) { |
| 385 | printf(" to %s", *names++); |
| 386 | while (*names) { |
| 387 | printf(", %s", *names++); |
| 388 | } |
| 389 | } |
| 390 | printf(".\n"); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * ncurses stores two types of non-standard capabilities: |
| 396 | * a) capabilities listed past the "STOP-HERE" comment in the Caps file. |
| 397 | * These are used in the terminfo source file to provide data for termcaps, |
| 398 | * e.g., when there is no equivalent capability in terminfo, as well as for |
| 399 | * widely-used non-standard capabilities. |
| 400 | * b) user-definable capabilities, via "tic -x". |
| 401 | * |
| 402 | * However, if "-x" is omitted from the tic command, both types of |
| 403 | * non-standard capability are not loaded into the terminfo database. This |
| 404 | * macro is used for limit-checks against the symbols that tic uses to omit |
| 405 | * the two types of non-standard entry. |
| 406 | */ |
| 407 | #if NCURSES_XNAMES |
| 408 | #define check_user_definable(n,limit) if (!_nc_user_definable && (n) > (limit)) break |
| 409 | #else |
| 410 | #define check_user_definable(n,limit) if ((n) > (limit)) break |
| 411 | #endif |
| 412 | |
| 413 | /* |
| 414 | * Use these macros to simplify loops on C_COMMON and C_NAND: |
| 415 | */ |
| 416 | #define for_each_entry() while (entries[extra].tterm.term_names) |
| 417 | #define next_entry (&(entries[extra++].tterm)) |
| 418 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 419 | static void |
| 420 | compare_predicate(PredType type, PredIdx idx, const char *name) |
| 421 | /* predicate function to use for entry difference reports */ |
| 422 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 423 | ENTRY *e1 = &entries[0]; |
| 424 | ENTRY *e2 = &entries[1]; |
| 425 | char buf1[MAX_STRING]; |
| 426 | char buf2[MAX_STRING]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 427 | int b1, b2; |
| 428 | int n1, n2; |
| 429 | char *s1, *s2; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 430 | bool found; |
| 431 | int extra = 1; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 432 | |
| 433 | switch (type) { |
| 434 | case CMP_BOOLEAN: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 435 | check_user_definable(idx, BOOLWRITE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 436 | b1 = e1->tterm.Booleans[idx]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 437 | switch (compare) { |
| 438 | case C_DIFFERENCE: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 439 | b2 = next_entry->Booleans[idx]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 440 | if (!(b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN) && b1 != b2) |
| 441 | (void) printf("\t%s: %s%s%s.\n", |
| 442 | name, |
| 443 | dump_boolean(b1), |
| 444 | bool_sep, |
| 445 | dump_boolean(b2)); |
| 446 | break; |
| 447 | |
| 448 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 449 | if (b1 != ABSENT_BOOLEAN) { |
| 450 | found = TRUE; |
| 451 | for_each_entry() { |
| 452 | b2 = next_entry->Booleans[idx]; |
| 453 | if (b1 != b2) { |
| 454 | found = FALSE; |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | if (found) { |
| 459 | (void) printf("\t%s= %s.\n", name, dump_boolean(b1)); |
| 460 | } |
| 461 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 462 | break; |
| 463 | |
| 464 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 465 | if (b1 == ABSENT_BOOLEAN) { |
| 466 | found = TRUE; |
| 467 | for_each_entry() { |
| 468 | b2 = next_entry->Booleans[idx]; |
| 469 | if (b1 != b2) { |
| 470 | found = FALSE; |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | if (found) { |
| 475 | (void) printf("\t!%s.\n", name); |
| 476 | } |
| 477 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 478 | break; |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | case CMP_NUMBER: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 483 | check_user_definable(idx, NUMWRITE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 484 | n1 = e1->tterm.Numbers[idx]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 485 | switch (compare) { |
| 486 | case C_DIFFERENCE: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 487 | n2 = next_entry->Numbers[idx]; |
| 488 | if (!((n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)) && n1 != n2) { |
| 489 | dump_numeric(n1, buf1); |
| 490 | dump_numeric(n2, buf2); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 491 | (void) printf("\t%s: %s, %s.\n", name, buf1, buf2); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 492 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 493 | break; |
| 494 | |
| 495 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 496 | if (n1 != ABSENT_NUMERIC) { |
| 497 | found = TRUE; |
| 498 | for_each_entry() { |
| 499 | n2 = next_entry->Numbers[idx]; |
| 500 | if (n1 != n2) { |
| 501 | found = FALSE; |
| 502 | break; |
| 503 | } |
| 504 | } |
| 505 | if (found) { |
| 506 | dump_numeric(n1, buf1); |
| 507 | (void) printf("\t%s= %s.\n", name, buf1); |
| 508 | } |
| 509 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 513 | if (n1 == ABSENT_NUMERIC) { |
| 514 | found = TRUE; |
| 515 | for_each_entry() { |
| 516 | n2 = next_entry->Numbers[idx]; |
| 517 | if (n1 != n2) { |
| 518 | found = FALSE; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | if (found) { |
| 523 | (void) printf("\t!%s.\n", name); |
| 524 | } |
| 525 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | break; |
| 529 | |
| 530 | case CMP_STRING: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 531 | check_user_definable(idx, STRWRITE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 532 | s1 = e1->tterm.Strings[idx]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 533 | switch (compare) { |
| 534 | case C_DIFFERENCE: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 535 | s2 = next_entry->Strings[idx]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 536 | if (capcmp(idx, s1, s2)) { |
| 537 | dump_string(s1, buf1); |
| 538 | dump_string(s2, buf2); |
| 539 | if (strcmp(buf1, buf2)) |
| 540 | (void) printf("\t%s: %s, %s.\n", name, buf1, buf2); |
| 541 | } |
| 542 | break; |
| 543 | |
| 544 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 545 | if (s1 != ABSENT_STRING) { |
| 546 | found = TRUE; |
| 547 | for_each_entry() { |
| 548 | s2 = next_entry->Strings[idx]; |
| 549 | if (capcmp(idx, s1, s2) != 0) { |
| 550 | found = FALSE; |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | if (found) { |
| 555 | (void) printf("\t%s= '%s'.\n", name, TIC_EXPAND(s1)); |
| 556 | } |
| 557 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 561 | if (s1 == ABSENT_STRING) { |
| 562 | found = TRUE; |
| 563 | for_each_entry() { |
| 564 | s2 = next_entry->Strings[idx]; |
| 565 | if (s2 != s1) { |
| 566 | found = FALSE; |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | if (found) { |
| 571 | (void) printf("\t!%s.\n", name); |
| 572 | } |
| 573 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | break; |
| 577 | |
| 578 | case CMP_USE: |
| 579 | /* unlike the other modes, this compares *all* use entries */ |
| 580 | switch (compare) { |
| 581 | case C_DIFFERENCE: |
| 582 | if (!useeq(e1, e2)) { |
| 583 | (void) fputs("\tuse: ", stdout); |
| 584 | print_uses(e1, stdout); |
| 585 | fputs(", ", stdout); |
| 586 | print_uses(e2, stdout); |
| 587 | fputs(".\n", stdout); |
| 588 | } |
| 589 | break; |
| 590 | |
| 591 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 592 | if (e1->nuses) { |
| 593 | found = TRUE; |
| 594 | for_each_entry() { |
| 595 | e2 = &entries[extra++]; |
| 596 | if (e2->nuses != e1->nuses || !useeq(e1, e2)) { |
| 597 | found = FALSE; |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | if (found) { |
| 602 | (void) fputs("\tuse: ", stdout); |
| 603 | print_uses(e1, stdout); |
| 604 | fputs(".\n", stdout); |
| 605 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 606 | } |
| 607 | break; |
| 608 | |
| 609 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 610 | if (!e1->nuses) { |
| 611 | found = TRUE; |
| 612 | for_each_entry() { |
| 613 | e2 = &entries[extra++]; |
| 614 | if (e2->nuses != e1->nuses) { |
| 615 | found = FALSE; |
| 616 | break; |
| 617 | } |
| 618 | } |
| 619 | if (found) { |
| 620 | (void) printf("\t!use.\n"); |
| 621 | } |
| 622 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 623 | break; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /*************************************************************************** |
| 629 | * |
| 630 | * Init string analysis |
| 631 | * |
| 632 | ***************************************************************************/ |
| 633 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 634 | #define DATA(from, to) { { from }, { to } } |
| 635 | #define DATAX() DATA("", "") |
| 636 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 637 | typedef struct { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 638 | const char from[4]; |
| 639 | const char to[12]; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 640 | } assoc; |
| 641 | |
| 642 | static const assoc std_caps[] = |
| 643 | { |
| 644 | /* these are specified by X.364 and iBCS2 */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 645 | DATA("\033c", "RIS"), /* full reset */ |
| 646 | DATA("\0337", "SC"), /* save cursor */ |
| 647 | DATA("\0338", "RC"), /* restore cursor */ |
| 648 | DATA("\033[r", "RSR"), /* not an X.364 mnemonic */ |
| 649 | DATA("\033[m", "SGR0"), /* not an X.364 mnemonic */ |
| 650 | DATA("\033[2J", "ED2"), /* clear page */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 651 | |
| 652 | /* this group is specified by ISO 2022 */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 653 | DATA("\033(0", "ISO DEC G0"), /* enable DEC graphics for G0 */ |
| 654 | DATA("\033(A", "ISO UK G0"), /* enable UK chars for G0 */ |
| 655 | DATA("\033(B", "ISO US G0"), /* enable US chars for G0 */ |
| 656 | DATA("\033)0", "ISO DEC G1"), /* enable DEC graphics for G1 */ |
| 657 | DATA("\033)A", "ISO UK G1"), /* enable UK chars for G1 */ |
| 658 | DATA("\033)B", "ISO US G1"), /* enable US chars for G1 */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 659 | |
| 660 | /* these are DEC private controls widely supported by emulators */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 661 | DATA("\033=", "DECPAM"), /* application keypad mode */ |
| 662 | DATA("\033>", "DECPNM"), /* normal keypad mode */ |
| 663 | DATA("\033<", "DECANSI"), /* enter ANSI mode */ |
| 664 | DATA("\033[!p", "DECSTR"), /* soft reset */ |
| 665 | DATA("\033 F", "S7C1T"), /* 7-bit controls */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 666 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 667 | DATAX() |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static const assoc std_modes[] = |
| 671 | /* ECMA \E[ ... [hl] modes recognized by many emulators */ |
| 672 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 673 | DATA("2", "AM"), /* keyboard action mode */ |
| 674 | DATA("4", "IRM"), /* insert/replace mode */ |
| 675 | DATA("12", "SRM"), /* send/receive mode */ |
| 676 | DATA("20", "LNM"), /* linefeed mode */ |
| 677 | DATAX() |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | static const assoc private_modes[] = |
| 681 | /* DEC \E[ ... [hl] modes recognized by many emulators */ |
| 682 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 683 | DATA("1", "CKM"), /* application cursor keys */ |
| 684 | DATA("2", "ANM"), /* set VT52 mode */ |
| 685 | DATA("3", "COLM"), /* 132-column mode */ |
| 686 | DATA("4", "SCLM"), /* smooth scroll */ |
| 687 | DATA("5", "SCNM"), /* reverse video mode */ |
| 688 | DATA("6", "OM"), /* origin mode */ |
| 689 | DATA("7", "AWM"), /* wraparound mode */ |
| 690 | DATA("8", "ARM"), /* auto-repeat mode */ |
| 691 | DATAX() |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 692 | }; |
| 693 | |
| 694 | static const assoc ecma_highlights[] = |
| 695 | /* recognize ECMA attribute sequences */ |
| 696 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 697 | DATA("0", "NORMAL"), /* normal */ |
| 698 | DATA("1", "+BOLD"), /* bold on */ |
| 699 | DATA("2", "+DIM"), /* dim on */ |
| 700 | DATA("3", "+ITALIC"), /* italic on */ |
| 701 | DATA("4", "+UNDERLINE"), /* underline on */ |
| 702 | DATA("5", "+BLINK"), /* blink on */ |
| 703 | DATA("6", "+FASTBLINK"), /* fastblink on */ |
| 704 | DATA("7", "+REVERSE"), /* reverse on */ |
| 705 | DATA("8", "+INVISIBLE"), /* invisible on */ |
| 706 | DATA("9", "+DELETED"), /* deleted on */ |
| 707 | DATA("10", "MAIN-FONT"), /* select primary font */ |
| 708 | DATA("11", "ALT-FONT-1"), /* select alternate font 1 */ |
| 709 | DATA("12", "ALT-FONT-2"), /* select alternate font 2 */ |
| 710 | DATA("13", "ALT-FONT-3"), /* select alternate font 3 */ |
| 711 | DATA("14", "ALT-FONT-4"), /* select alternate font 4 */ |
| 712 | DATA("15", "ALT-FONT-5"), /* select alternate font 5 */ |
| 713 | DATA("16", "ALT-FONT-6"), /* select alternate font 6 */ |
| 714 | DATA("17", "ALT-FONT-7"), /* select alternate font 7 */ |
| 715 | DATA("18", "ALT-FONT-1"), /* select alternate font 1 */ |
| 716 | DATA("19", "ALT-FONT-1"), /* select alternate font 1 */ |
| 717 | DATA("20", "FRAKTUR"), /* Fraktur font */ |
| 718 | DATA("21", "DOUBLEUNDER"), /* double underline */ |
| 719 | DATA("22", "-DIM"), /* dim off */ |
| 720 | DATA("23", "-ITALIC"), /* italic off */ |
| 721 | DATA("24", "-UNDERLINE"), /* underline off */ |
| 722 | DATA("25", "-BLINK"), /* blink off */ |
| 723 | DATA("26", "-FASTBLINK"), /* fastblink off */ |
| 724 | DATA("27", "-REVERSE"), /* reverse off */ |
| 725 | DATA("28", "-INVISIBLE"), /* invisible off */ |
| 726 | DATA("29", "-DELETED"), /* deleted off */ |
| 727 | DATAX() |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 728 | }; |
| 729 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 730 | #undef DATA |
| 731 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 732 | static int |
| 733 | skip_csi(const char *cap) |
| 734 | { |
| 735 | int result = 0; |
| 736 | if (cap[0] == '\033' && cap[1] == '[') |
| 737 | result = 2; |
| 738 | else if (UChar(cap[0]) == 0233) |
| 739 | result = 1; |
| 740 | return result; |
| 741 | } |
| 742 | |
| 743 | static bool |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 744 | same_param(const char *table, const char *param, size_t length) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 745 | { |
| 746 | bool result = FALSE; |
| 747 | if (strncmp(table, param, length) == 0) { |
| 748 | result = !isdigit(UChar(param[length])); |
| 749 | } |
| 750 | return result; |
| 751 | } |
| 752 | |
| 753 | static char * |
| 754 | lookup_params(const assoc * table, char *dst, char *src) |
| 755 | { |
| 756 | char *result = 0; |
| 757 | const char *ep = strtok(src, ";"); |
| 758 | |
| 759 | if (ep != 0) { |
| 760 | const assoc *ap; |
| 761 | |
| 762 | do { |
| 763 | bool found = FALSE; |
| 764 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 765 | for (ap = table; ap->from[0]; ap++) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 766 | size_t tlen = strlen(ap->from); |
| 767 | |
| 768 | if (same_param(ap->from, ep, tlen)) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 769 | _nc_STRCAT(dst, ap->to, MAX_TERMINFO_LENGTH); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 770 | found = TRUE; |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | if (!found) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 776 | _nc_STRCAT(dst, ep, MAX_TERMINFO_LENGTH); |
| 777 | _nc_STRCAT(dst, ";", MAX_TERMINFO_LENGTH); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 778 | } while |
| 779 | ((ep = strtok((char *) 0, ";"))); |
| 780 | |
| 781 | dst[strlen(dst) - 1] = '\0'; |
| 782 | |
| 783 | result = dst; |
| 784 | } |
| 785 | return result; |
| 786 | } |
| 787 | |
| 788 | static void |
| 789 | analyze_string(const char *name, const char *cap, TERMTYPE *tp) |
| 790 | { |
| 791 | char buf2[MAX_TERMINFO_LENGTH]; |
| 792 | const char *sp; |
| 793 | const assoc *ap; |
| 794 | int tp_lines = tp->Numbers[2]; |
| 795 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 796 | if (!VALID_STRING(cap)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 797 | return; |
| 798 | (void) printf("%s: ", name); |
| 799 | |
| 800 | for (sp = cap; *sp; sp++) { |
| 801 | int i; |
| 802 | int csi; |
| 803 | size_t len = 0; |
| 804 | size_t next; |
| 805 | const char *expansion = 0; |
| 806 | char buf3[MAX_TERMINFO_LENGTH]; |
| 807 | |
| 808 | /* first, check other capabilities in this entry */ |
| 809 | for (i = 0; i < STRCOUNT; i++) { |
| 810 | char *cp = tp->Strings[i]; |
| 811 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 812 | /* don't use function-key capabilities */ |
| 813 | if (strnames[i][0] == 'k' && strnames[i][1] == 'f') |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 814 | continue; |
| 815 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 816 | if (VALID_STRING(cp) && |
| 817 | cp[0] != '\0' && |
| 818 | cp != cap) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 819 | len = strlen(cp); |
| 820 | (void) strncpy(buf2, sp, len); |
| 821 | buf2[len] = '\0'; |
| 822 | |
| 823 | if (_nc_capcmp(cp, buf2)) |
| 824 | continue; |
| 825 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 826 | #define ISRS(s) (!strncmp((s), "is", (size_t) 2) || !strncmp((s), "rs", (size_t) 2)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 827 | /* |
| 828 | * Theoretically we just passed the test for translation |
| 829 | * (equality once the padding is stripped). However, there |
| 830 | * are a few more hoops that need to be jumped so that |
| 831 | * identical pairs of initialization and reset strings |
| 832 | * don't just refer to each other. |
| 833 | */ |
| 834 | if (ISRS(name) || ISRS(strnames[i])) |
| 835 | if (cap < cp) |
| 836 | continue; |
| 837 | #undef ISRS |
| 838 | |
| 839 | expansion = strnames[i]; |
| 840 | break; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | /* now check the standard capabilities */ |
| 845 | if (!expansion) { |
| 846 | csi = skip_csi(sp); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 847 | for (ap = std_caps; ap->from[0]; ap++) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 848 | size_t adj = (size_t) (csi ? 2 : 0); |
| 849 | |
| 850 | len = strlen(ap->from); |
| 851 | if (csi && skip_csi(ap->from) != csi) |
| 852 | continue; |
| 853 | if (len > adj |
| 854 | && strncmp(ap->from + adj, sp + csi, len - adj) == 0) { |
| 855 | expansion = ap->to; |
| 856 | len -= adj; |
| 857 | len += (size_t) csi; |
| 858 | break; |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | /* now check for standard-mode sequences */ |
| 864 | if (!expansion |
| 865 | && (csi = skip_csi(sp)) != 0 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 866 | && (len = (strspn) (sp + csi, "0123456789;")) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 867 | && (len < sizeof(buf3)) |
| 868 | && (next = (size_t) csi + len) |
| 869 | && ((sp[next] == 'h') || (sp[next] == 'l'))) { |
| 870 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 871 | _nc_STRCPY(buf2, |
| 872 | ((sp[next] == 'h') |
| 873 | ? "ECMA+" |
| 874 | : "ECMA-"), |
| 875 | sizeof(buf2)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 876 | (void) strncpy(buf3, sp + csi, len); |
| 877 | buf3[len] = '\0'; |
| 878 | len += (size_t) csi + 1; |
| 879 | |
| 880 | expansion = lookup_params(std_modes, buf2, buf3); |
| 881 | } |
| 882 | |
| 883 | /* now check for private-mode sequences */ |
| 884 | if (!expansion |
| 885 | && (csi = skip_csi(sp)) != 0 |
| 886 | && sp[csi] == '?' |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 887 | && (len = (strspn) (sp + csi + 1, "0123456789;")) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 888 | && (len < sizeof(buf3)) |
| 889 | && (next = (size_t) csi + 1 + len) |
| 890 | && ((sp[next] == 'h') || (sp[next] == 'l'))) { |
| 891 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 892 | _nc_STRCPY(buf2, |
| 893 | ((sp[next] == 'h') |
| 894 | ? "DEC+" |
| 895 | : "DEC-"), |
| 896 | sizeof(buf2)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 897 | (void) strncpy(buf3, sp + csi + 1, len); |
| 898 | buf3[len] = '\0'; |
| 899 | len += (size_t) csi + 2; |
| 900 | |
| 901 | expansion = lookup_params(private_modes, buf2, buf3); |
| 902 | } |
| 903 | |
| 904 | /* now check for ECMA highlight sequences */ |
| 905 | if (!expansion |
| 906 | && (csi = skip_csi(sp)) != 0 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 907 | && (len = (strspn) (sp + csi, "0123456789;")) != 0 |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 908 | && (len < sizeof(buf3)) |
| 909 | && (next = (size_t) csi + len) |
| 910 | && sp[next] == 'm') { |
| 911 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 912 | _nc_STRCPY(buf2, "SGR:", sizeof(buf2)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 913 | (void) strncpy(buf3, sp + csi, len); |
| 914 | buf3[len] = '\0'; |
| 915 | len += (size_t) csi + 1; |
| 916 | |
| 917 | expansion = lookup_params(ecma_highlights, buf2, buf3); |
| 918 | } |
| 919 | |
| 920 | if (!expansion |
| 921 | && (csi = skip_csi(sp)) != 0 |
| 922 | && sp[csi] == 'm') { |
| 923 | len = (size_t) csi + 1; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 924 | _nc_STRCPY(buf2, "SGR:", sizeof(buf2)); |
| 925 | _nc_STRCAT(buf2, ecma_highlights[0].to, sizeof(buf2)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 926 | expansion = buf2; |
| 927 | } |
| 928 | |
| 929 | /* now check for scroll region reset */ |
| 930 | if (!expansion |
| 931 | && (csi = skip_csi(sp)) != 0) { |
| 932 | if (sp[csi] == 'r') { |
| 933 | expansion = "RSR"; |
| 934 | len = 1; |
| 935 | } else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 936 | _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "1;%dr", tp_lines); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 937 | len = strlen(buf2); |
| 938 | if (strncmp(buf2, sp + csi, len) == 0) |
| 939 | expansion = "RSR"; |
| 940 | } |
| 941 | len += (size_t) csi; |
| 942 | } |
| 943 | |
| 944 | /* now check for home-down */ |
| 945 | if (!expansion |
| 946 | && (csi = skip_csi(sp)) != 0) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 947 | _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%d;1H", tp_lines); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 948 | len = strlen(buf2); |
| 949 | if (strncmp(buf2, sp + csi, len) == 0) { |
| 950 | expansion = "LL"; |
| 951 | } else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 952 | _nc_SPRINTF(buf2, _nc_SLIMIT(sizeof(buf2)) "%dH", tp_lines); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 953 | len = strlen(buf2); |
| 954 | if (strncmp(buf2, sp + csi, len) == 0) { |
| 955 | expansion = "LL"; |
| 956 | } |
| 957 | } |
| 958 | len += (size_t) csi; |
| 959 | } |
| 960 | |
| 961 | /* now look at the expansion we got, if any */ |
| 962 | if (expansion) { |
| 963 | printf("{%s}", expansion); |
| 964 | sp += len - 1; |
| 965 | } else { |
| 966 | /* couldn't match anything */ |
| 967 | buf2[0] = *sp; |
| 968 | buf2[1] = '\0'; |
| 969 | fputs(TIC_EXPAND(buf2), stdout); |
| 970 | } |
| 971 | } |
| 972 | putchar('\n'); |
| 973 | } |
| 974 | |
| 975 | /*************************************************************************** |
| 976 | * |
| 977 | * File comparison |
| 978 | * |
| 979 | ***************************************************************************/ |
| 980 | |
| 981 | static void |
| 982 | file_comparison(int argc, char *argv[]) |
| 983 | { |
| 984 | #define MAXCOMPARE 2 |
| 985 | /* someday we may allow comparisons on more files */ |
| 986 | int filecount = 0; |
| 987 | ENTRY *heads[MAXCOMPARE]; |
| 988 | ENTRY *qp, *rp; |
| 989 | int i, n; |
| 990 | |
| 991 | memset(heads, 0, sizeof(heads)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 992 | dump_init((char *) 0, F_LITERAL, S_TERMINFO, 0, 65535, itrace, FALSE, FALSE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 993 | |
| 994 | for (n = 0; n < argc && n < MAXCOMPARE; n++) { |
| 995 | if (freopen(argv[n], "r", stdin) == 0) |
| 996 | _nc_err_abort("Can't open %s", argv[n]); |
| 997 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 998 | #if NO_LEAKS |
| 999 | entered[n].head = _nc_head; |
| 1000 | entered[n].tail = _nc_tail; |
| 1001 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1002 | _nc_head = _nc_tail = 0; |
| 1003 | |
| 1004 | /* parse entries out of the source file */ |
| 1005 | _nc_set_source(argv[n]); |
| 1006 | _nc_read_entry_source(stdin, NULL, TRUE, literal, NULLHOOK); |
| 1007 | |
| 1008 | if (itrace) |
| 1009 | (void) fprintf(stderr, "Resolving file %d...\n", n - 0); |
| 1010 | |
| 1011 | /* maybe do use resolution */ |
| 1012 | if (!_nc_resolve_uses2(!limited, literal)) { |
| 1013 | (void) fprintf(stderr, |
| 1014 | "There are unresolved use entries in %s:\n", |
| 1015 | argv[n]); |
| 1016 | for_entry_list(qp) { |
| 1017 | if (qp->nuses) { |
| 1018 | (void) fputs(qp->tterm.term_names, stderr); |
| 1019 | (void) fputc('\n', stderr); |
| 1020 | } |
| 1021 | } |
| 1022 | ExitProgram(EXIT_FAILURE); |
| 1023 | } |
| 1024 | |
| 1025 | heads[filecount] = _nc_head; |
| 1026 | filecount++; |
| 1027 | } |
| 1028 | |
| 1029 | /* OK, all entries are in core. Ready to do the comparison */ |
| 1030 | if (itrace) |
| 1031 | (void) fprintf(stderr, "Entries are now in core...\n"); |
| 1032 | |
| 1033 | /* The entry-matching loop. Sigh, this is intrinsically quadratic. */ |
| 1034 | for (qp = heads[0]; qp; qp = qp->next) { |
| 1035 | for (rp = heads[1]; rp; rp = rp->next) |
| 1036 | if (_nc_entry_match(qp->tterm.term_names, rp->tterm.term_names)) { |
| 1037 | if (qp->ncrosslinks < MAX_CROSSLINKS) |
| 1038 | qp->crosslinks[qp->ncrosslinks] = rp; |
| 1039 | qp->ncrosslinks++; |
| 1040 | |
| 1041 | if (rp->ncrosslinks < MAX_CROSSLINKS) |
| 1042 | rp->crosslinks[rp->ncrosslinks] = qp; |
| 1043 | rp->ncrosslinks++; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /* now we have two circular lists with crosslinks */ |
| 1048 | if (itrace) |
| 1049 | (void) fprintf(stderr, "Name matches are done...\n"); |
| 1050 | |
| 1051 | for (qp = heads[0]; qp; qp = qp->next) { |
| 1052 | if (qp->ncrosslinks > 1) { |
| 1053 | (void) fprintf(stderr, |
| 1054 | "%s in file 1 (%s) has %d matches in file 2 (%s):\n", |
| 1055 | _nc_first_name(qp->tterm.term_names), |
| 1056 | argv[0], |
| 1057 | qp->ncrosslinks, |
| 1058 | argv[1]); |
| 1059 | for (i = 0; i < qp->ncrosslinks; i++) |
| 1060 | (void) fprintf(stderr, |
| 1061 | "\t%s\n", |
| 1062 | _nc_first_name((qp->crosslinks[i])->tterm.term_names)); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | for (rp = heads[1]; rp; rp = rp->next) { |
| 1067 | if (rp->ncrosslinks > 1) { |
| 1068 | (void) fprintf(stderr, |
| 1069 | "%s in file 2 (%s) has %d matches in file 1 (%s):\n", |
| 1070 | _nc_first_name(rp->tterm.term_names), |
| 1071 | argv[1], |
| 1072 | rp->ncrosslinks, |
| 1073 | argv[0]); |
| 1074 | for (i = 0; i < rp->ncrosslinks; i++) |
| 1075 | (void) fprintf(stderr, |
| 1076 | "\t%s\n", |
| 1077 | _nc_first_name((rp->crosslinks[i])->tterm.term_names)); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | (void) printf("In file 1 (%s) only:\n", argv[0]); |
| 1082 | for (qp = heads[0]; qp; qp = qp->next) |
| 1083 | if (qp->ncrosslinks == 0) |
| 1084 | (void) printf("\t%s\n", |
| 1085 | _nc_first_name(qp->tterm.term_names)); |
| 1086 | |
| 1087 | (void) printf("In file 2 (%s) only:\n", argv[1]); |
| 1088 | for (rp = heads[1]; rp; rp = rp->next) |
| 1089 | if (rp->ncrosslinks == 0) |
| 1090 | (void) printf("\t%s\n", |
| 1091 | _nc_first_name(rp->tterm.term_names)); |
| 1092 | |
| 1093 | (void) printf("The following entries are equivalent:\n"); |
| 1094 | for (qp = heads[0]; qp; qp = qp->next) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1095 | if (qp->ncrosslinks == 1) { |
| 1096 | rp = qp->crosslinks[0]; |
| 1097 | |
| 1098 | repair_acsc(&qp->tterm); |
| 1099 | repair_acsc(&rp->tterm); |
| 1100 | #if NCURSES_XNAMES |
| 1101 | _nc_align_termtype(&qp->tterm, &rp->tterm); |
| 1102 | #endif |
| 1103 | if (entryeq(&qp->tterm, &rp->tterm) && useeq(qp, rp)) { |
| 1104 | char name1[NAMESIZE], name2[NAMESIZE]; |
| 1105 | |
| 1106 | (void) canonical_name(qp->tterm.term_names, name1); |
| 1107 | (void) canonical_name(rp->tterm.term_names, name2); |
| 1108 | |
| 1109 | (void) printf("%s = %s\n", name1, name2); |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | (void) printf("Differing entries:\n"); |
| 1115 | termcount = 2; |
| 1116 | for (qp = heads[0]; qp; qp = qp->next) { |
| 1117 | |
| 1118 | if (qp->ncrosslinks == 1) { |
| 1119 | rp = qp->crosslinks[0]; |
| 1120 | #if NCURSES_XNAMES |
| 1121 | /* sorry - we have to do this on each pass */ |
| 1122 | _nc_align_termtype(&qp->tterm, &rp->tterm); |
| 1123 | #endif |
| 1124 | if (!(entryeq(&qp->tterm, &rp->tterm) && useeq(qp, rp))) { |
| 1125 | char name1[NAMESIZE], name2[NAMESIZE]; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1126 | char *names[3]; |
| 1127 | |
| 1128 | names[0] = name1; |
| 1129 | names[1] = name2; |
| 1130 | names[2] = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1131 | |
| 1132 | entries[0] = *qp; |
| 1133 | entries[1] = *rp; |
| 1134 | |
| 1135 | (void) canonical_name(qp->tterm.term_names, name1); |
| 1136 | (void) canonical_name(rp->tterm.term_names, name2); |
| 1137 | |
| 1138 | switch (compare) { |
| 1139 | case C_DIFFERENCE: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1140 | show_comparing(names); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1141 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1142 | break; |
| 1143 | |
| 1144 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1145 | show_comparing(names); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1146 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1147 | break; |
| 1148 | |
| 1149 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1150 | show_comparing(names); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1151 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1152 | break; |
| 1153 | |
| 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | static void |
| 1161 | usage(void) |
| 1162 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1163 | #define DATA(s) s "\n" |
| 1164 | static const char head[] = |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1165 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1166 | DATA("Usage: infocmp [options] [-A directory] [-B directory] [termname...]") |
| 1167 | DATA("") |
| 1168 | DATA("Options:") |
| 1169 | }; |
| 1170 | #undef DATA |
| 1171 | #define DATA(s) s |
| 1172 | static const char options[][45] = |
| 1173 | { |
| 1174 | " -0 print single-row" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1175 | ," -1 print single-column" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1176 | ," -K use termcap-names and BSD syntax" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1177 | ," -C use termcap-names" |
| 1178 | ," -F compare terminfo-files" |
| 1179 | ," -I use terminfo-names" |
| 1180 | ," -L use long names" |
| 1181 | ," -R subset (see manpage)" |
| 1182 | ," -T eliminate size limits (test)" |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1183 | ," -U do not post-process entries" |
| 1184 | ," -D print database locations" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1185 | ," -V print version" |
| 1186 | #if NCURSES_XNAMES |
| 1187 | ," -a with -F, list commented-out caps" |
| 1188 | #endif |
| 1189 | ," -c list common capabilities" |
| 1190 | ," -d list different capabilities" |
| 1191 | ," -e format output for C initializer" |
| 1192 | ," -E format output as C tables" |
| 1193 | ," -f with -1, format complex strings" |
| 1194 | ," -G format %{number} to %'char'" |
| 1195 | ," -g format %'char' to %{number}" |
| 1196 | ," -i analyze initialization/reset" |
| 1197 | ," -l output terminfo names" |
| 1198 | ," -n list capabilities in neither" |
| 1199 | ," -p ignore padding specifiers" |
| 1200 | ," -q brief listing, removes headers" |
| 1201 | ," -r with -C, output in termcap form" |
| 1202 | ," -r with -F, resolve use-references" |
| 1203 | ," -s [d|i|l|c] sort fields" |
| 1204 | #if NCURSES_XNAMES |
| 1205 | ," -t suppress commented-out capabilities" |
| 1206 | #endif |
| 1207 | ," -u produce source with 'use='" |
| 1208 | ," -v number (verbose)" |
| 1209 | ," -w number (width)" |
| 1210 | #if NCURSES_XNAMES |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1211 | ," -x unknown capabilities are user-defined" |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1212 | #endif |
| 1213 | }; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1214 | #undef DATA |
| 1215 | const size_t last = SIZEOF(options); |
| 1216 | const size_t left = (last + 1) / 2; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1217 | size_t n; |
| 1218 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1219 | fputs(head, stderr); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1220 | for (n = 0; n < left; n++) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1221 | size_t m = n + left; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1222 | if (m < last) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1223 | fprintf(stderr, "%-40.40s%s\n", options[n], options[m]); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1224 | else |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1225 | fprintf(stderr, "%s\n", options[n]); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1226 | } |
| 1227 | ExitProgram(EXIT_FAILURE); |
| 1228 | } |
| 1229 | |
| 1230 | static char * |
| 1231 | any_initializer(const char *fmt, const char *type) |
| 1232 | { |
| 1233 | static char *initializer; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1234 | static size_t need; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1235 | char *s; |
| 1236 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1237 | if (initializer == 0) { |
| 1238 | need = (strlen(entries->tterm.term_names) |
| 1239 | + strlen(type) |
| 1240 | + strlen(fmt)); |
| 1241 | initializer = (char *) malloc(need + 1); |
| 1242 | if (initializer == 0) |
| 1243 | failed("any_initializer"); |
| 1244 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1245 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1246 | _nc_STRCPY(initializer, entries->tterm.term_names, need); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1247 | for (s = initializer; *s != 0 && *s != '|'; s++) { |
| 1248 | if (!isalnum(UChar(*s))) |
| 1249 | *s = '_'; |
| 1250 | } |
| 1251 | *s = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1252 | _nc_SPRINTF(s, _nc_SLIMIT(need) fmt, type); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1253 | return initializer; |
| 1254 | } |
| 1255 | |
| 1256 | static char * |
| 1257 | name_initializer(const char *type) |
| 1258 | { |
| 1259 | return any_initializer("_%s_data", type); |
| 1260 | } |
| 1261 | |
| 1262 | static char * |
| 1263 | string_variable(const char *type) |
| 1264 | { |
| 1265 | return any_initializer("_s_%s", type); |
| 1266 | } |
| 1267 | |
| 1268 | /* dump C initializers for the terminal type */ |
| 1269 | static void |
| 1270 | dump_initializers(TERMTYPE *term) |
| 1271 | { |
| 1272 | unsigned n; |
| 1273 | const char *str = 0; |
| 1274 | |
| 1275 | printf("\nstatic char %s[] = \"%s\";\n\n", |
| 1276 | name_initializer("alias"), entries->tterm.term_names); |
| 1277 | |
| 1278 | for_each_string(n, term) { |
| 1279 | char buf[MAX_STRING], *sp, *tp; |
| 1280 | |
| 1281 | if (VALID_STRING(term->Strings[n])) { |
| 1282 | tp = buf; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1283 | #define TP_LIMIT ((MAX_STRING - 5) - (size_t)(tp - buf)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1284 | *tp++ = '"'; |
| 1285 | for (sp = term->Strings[n]; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1286 | *sp != 0 && TP_LIMIT > 2; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1287 | sp++) { |
| 1288 | if (isascii(UChar(*sp)) |
| 1289 | && isprint(UChar(*sp)) |
| 1290 | && *sp != '\\' |
| 1291 | && *sp != '"') |
| 1292 | *tp++ = *sp; |
| 1293 | else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1294 | _nc_SPRINTF(tp, _nc_SLIMIT(TP_LIMIT) "\\%03o", UChar(*sp)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1295 | tp += 4; |
| 1296 | } |
| 1297 | } |
| 1298 | *tp++ = '"'; |
| 1299 | *tp = '\0'; |
| 1300 | (void) printf("static char %-20s[] = %s;\n", |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1301 | string_variable(ExtStrname(term, (int) n, strnames)), |
| 1302 | buf); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | printf("\n"); |
| 1306 | |
| 1307 | (void) printf("static char %s[] = %s\n", name_initializer("bool"), L_CURL); |
| 1308 | |
| 1309 | for_each_boolean(n, term) { |
| 1310 | switch ((int) (term->Booleans[n])) { |
| 1311 | case TRUE: |
| 1312 | str = "TRUE"; |
| 1313 | break; |
| 1314 | |
| 1315 | case FALSE: |
| 1316 | str = "FALSE"; |
| 1317 | break; |
| 1318 | |
| 1319 | case ABSENT_BOOLEAN: |
| 1320 | str = "ABSENT_BOOLEAN"; |
| 1321 | break; |
| 1322 | |
| 1323 | case CANCELLED_BOOLEAN: |
| 1324 | str = "CANCELLED_BOOLEAN"; |
| 1325 | break; |
| 1326 | } |
| 1327 | (void) printf("\t/* %3u: %-8s */\t%s,\n", |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1328 | n, ExtBoolname(term, (int) n, boolnames), str); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1329 | } |
| 1330 | (void) printf("%s;\n", R_CURL); |
| 1331 | |
| 1332 | (void) printf("static short %s[] = %s\n", name_initializer("number"), L_CURL); |
| 1333 | |
| 1334 | for_each_number(n, term) { |
| 1335 | char buf[BUFSIZ]; |
| 1336 | switch (term->Numbers[n]) { |
| 1337 | case ABSENT_NUMERIC: |
| 1338 | str = "ABSENT_NUMERIC"; |
| 1339 | break; |
| 1340 | case CANCELLED_NUMERIC: |
| 1341 | str = "CANCELLED_NUMERIC"; |
| 1342 | break; |
| 1343 | default: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1344 | _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) "%d", term->Numbers[n]); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1345 | str = buf; |
| 1346 | break; |
| 1347 | } |
| 1348 | (void) printf("\t/* %3u: %-8s */\t%s,\n", n, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1349 | ExtNumname(term, (int) n, numnames), str); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1350 | } |
| 1351 | (void) printf("%s;\n", R_CURL); |
| 1352 | |
| 1353 | (void) printf("static char * %s[] = %s\n", name_initializer("string"), L_CURL); |
| 1354 | |
| 1355 | for_each_string(n, term) { |
| 1356 | |
| 1357 | if (term->Strings[n] == ABSENT_STRING) |
| 1358 | str = "ABSENT_STRING"; |
| 1359 | else if (term->Strings[n] == CANCELLED_STRING) |
| 1360 | str = "CANCELLED_STRING"; |
| 1361 | else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1362 | str = string_variable(ExtStrname(term, (int) n, strnames)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1363 | } |
| 1364 | (void) printf("\t/* %3u: %-8s */\t%s,\n", n, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1365 | ExtStrname(term, (int) n, strnames), str); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1366 | } |
| 1367 | (void) printf("%s;\n", R_CURL); |
| 1368 | |
| 1369 | #if NCURSES_XNAMES |
| 1370 | if ((NUM_BOOLEANS(term) != BOOLCOUNT) |
| 1371 | || (NUM_NUMBERS(term) != NUMCOUNT) |
| 1372 | || (NUM_STRINGS(term) != STRCOUNT)) { |
| 1373 | (void) printf("static char * %s[] = %s\n", |
| 1374 | name_initializer("string_ext"), L_CURL); |
| 1375 | for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) { |
| 1376 | (void) printf("\t/* %3u: bool */\t\"%s\",\n", |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1377 | n, ExtBoolname(term, (int) n, boolnames)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1378 | } |
| 1379 | for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) { |
| 1380 | (void) printf("\t/* %3u: num */\t\"%s\",\n", |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1381 | n, ExtNumname(term, (int) n, numnames)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1382 | } |
| 1383 | for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) { |
| 1384 | (void) printf("\t/* %3u: str */\t\"%s\",\n", |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1385 | n, ExtStrname(term, (int) n, strnames)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1386 | } |
| 1387 | (void) printf("%s;\n", R_CURL); |
| 1388 | } |
| 1389 | #endif |
| 1390 | } |
| 1391 | |
| 1392 | /* dump C initializers for the terminal type */ |
| 1393 | static void |
| 1394 | dump_termtype(TERMTYPE *term) |
| 1395 | { |
| 1396 | (void) printf("\t%s\n\t\t%s,\n", L_CURL, name_initializer("alias")); |
| 1397 | (void) printf("\t\t(char *)0,\t/* pointer to string table */\n"); |
| 1398 | |
| 1399 | (void) printf("\t\t%s,\n", name_initializer("bool")); |
| 1400 | (void) printf("\t\t%s,\n", name_initializer("number")); |
| 1401 | |
| 1402 | (void) printf("\t\t%s,\n", name_initializer("string")); |
| 1403 | |
| 1404 | #if NCURSES_XNAMES |
| 1405 | (void) printf("#if NCURSES_XNAMES\n"); |
| 1406 | (void) printf("\t\t(char *)0,\t/* pointer to extended string table */\n"); |
| 1407 | (void) printf("\t\t%s,\t/* ...corresponding names */\n", |
| 1408 | ((NUM_BOOLEANS(term) != BOOLCOUNT) |
| 1409 | || (NUM_NUMBERS(term) != NUMCOUNT) |
| 1410 | || (NUM_STRINGS(term) != STRCOUNT)) |
| 1411 | ? name_initializer("string_ext") |
| 1412 | : "(char **)0"); |
| 1413 | |
| 1414 | (void) printf("\t\t%d,\t\t/* count total Booleans */\n", NUM_BOOLEANS(term)); |
| 1415 | (void) printf("\t\t%d,\t\t/* count total Numbers */\n", NUM_NUMBERS(term)); |
| 1416 | (void) printf("\t\t%d,\t\t/* count total Strings */\n", NUM_STRINGS(term)); |
| 1417 | |
| 1418 | (void) printf("\t\t%d,\t\t/* count extensions to Booleans */\n", |
| 1419 | NUM_BOOLEANS(term) - BOOLCOUNT); |
| 1420 | (void) printf("\t\t%d,\t\t/* count extensions to Numbers */\n", |
| 1421 | NUM_NUMBERS(term) - NUMCOUNT); |
| 1422 | (void) printf("\t\t%d,\t\t/* count extensions to Strings */\n", |
| 1423 | NUM_STRINGS(term) - STRCOUNT); |
| 1424 | |
| 1425 | (void) printf("#endif /* NCURSES_XNAMES */\n"); |
| 1426 | #else |
| 1427 | (void) term; |
| 1428 | #endif /* NCURSES_XNAMES */ |
| 1429 | (void) printf("\t%s\n", R_CURL); |
| 1430 | } |
| 1431 | |
| 1432 | static int |
| 1433 | optarg_to_number(void) |
| 1434 | { |
| 1435 | char *temp = 0; |
| 1436 | long value = strtol(optarg, &temp, 0); |
| 1437 | |
| 1438 | if (temp == 0 || temp == optarg || *temp != 0) { |
| 1439 | fprintf(stderr, "Expected a number, not \"%s\"\n", optarg); |
| 1440 | ExitProgram(EXIT_FAILURE); |
| 1441 | } |
| 1442 | return (int) value; |
| 1443 | } |
| 1444 | |
| 1445 | static char * |
| 1446 | terminal_env(void) |
| 1447 | { |
| 1448 | char *terminal; |
| 1449 | |
| 1450 | if ((terminal = getenv("TERM")) == 0) { |
| 1451 | (void) fprintf(stderr, |
| 1452 | "%s: environment variable TERM not set\n", |
| 1453 | _nc_progname); |
| 1454 | exit(EXIT_FAILURE); |
| 1455 | } |
| 1456 | return terminal; |
| 1457 | } |
| 1458 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1459 | /* |
| 1460 | * Show the databases that infocmp knows about. The location to which it writes is |
| 1461 | */ |
| 1462 | static void |
| 1463 | show_databases(void) |
| 1464 | { |
| 1465 | DBDIRS state; |
| 1466 | int offset; |
| 1467 | const char *path2; |
| 1468 | |
| 1469 | _nc_first_db(&state, &offset); |
| 1470 | while ((path2 = _nc_next_db(&state, &offset)) != 0) { |
| 1471 | printf("%s\n", path2); |
| 1472 | } |
| 1473 | _nc_last_db(); |
| 1474 | } |
| 1475 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1476 | /*************************************************************************** |
| 1477 | * |
| 1478 | * Main sequence |
| 1479 | * |
| 1480 | ***************************************************************************/ |
| 1481 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1482 | #if NO_LEAKS |
| 1483 | #define MAIN_LEAKS() \ |
| 1484 | free(myargv); \ |
| 1485 | free(tfile); \ |
| 1486 | free(tname) |
| 1487 | #else |
| 1488 | #define MAIN_LEAKS() /* nothing */ |
| 1489 | #endif |
| 1490 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1491 | int |
| 1492 | main(int argc, char *argv[]) |
| 1493 | { |
| 1494 | /* Avoid "local data >32k" error with mwcc */ |
| 1495 | /* Also avoid overflowing smaller stacks on systems like AmigaOS */ |
| 1496 | path *tfile = 0; |
| 1497 | char **tname = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1498 | size_t maxterms; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1499 | |
| 1500 | char **myargv; |
| 1501 | |
| 1502 | char *firstdir, *restdir; |
| 1503 | int c, i, len; |
| 1504 | bool formatted = FALSE; |
| 1505 | bool filecompare = FALSE; |
| 1506 | int initdump = 0; |
| 1507 | bool init_analyze = FALSE; |
| 1508 | bool suppress_untranslatable = FALSE; |
| 1509 | |
| 1510 | /* where is the terminfo database location going to default to? */ |
| 1511 | restdir = firstdir = 0; |
| 1512 | |
| 1513 | #if NCURSES_XNAMES |
| 1514 | use_extended_names(FALSE); |
| 1515 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1516 | _nc_strict_bsd = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1517 | |
| 1518 | _nc_progname = _nc_rootname(argv[0]); |
| 1519 | |
| 1520 | /* make sure we have enough space to add two terminal entries */ |
| 1521 | myargv = typeCalloc(char *, (size_t) (argc + 3)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1522 | if (myargv == 0) |
| 1523 | failed("myargv"); |
| 1524 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1525 | memcpy(myargv, argv, (sizeof(char *) * (size_t) argc)); |
| 1526 | argv = myargv; |
| 1527 | |
| 1528 | while ((c = getopt(argc, |
| 1529 | argv, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1530 | "01A:aB:CcDdEeFfGgIiKLlnpqR:rs:TtUuVv:w:x")) != -1) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1531 | switch (c) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1532 | case '0': |
| 1533 | mwidth = 65535; |
| 1534 | mheight = 1; |
| 1535 | break; |
| 1536 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1537 | case '1': |
| 1538 | mwidth = 0; |
| 1539 | break; |
| 1540 | |
| 1541 | case 'A': |
| 1542 | firstdir = optarg; |
| 1543 | break; |
| 1544 | |
| 1545 | #if NCURSES_XNAMES |
| 1546 | case 'a': |
| 1547 | _nc_disable_period = TRUE; |
| 1548 | use_extended_names(TRUE); |
| 1549 | break; |
| 1550 | #endif |
| 1551 | case 'B': |
| 1552 | restdir = optarg; |
| 1553 | break; |
| 1554 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1555 | case 'K': |
| 1556 | _nc_strict_bsd = 1; |
| 1557 | /* FALLTHRU */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1558 | case 'C': |
| 1559 | outform = F_TERMCAP; |
| 1560 | tversion = "BSD"; |
| 1561 | if (sortmode == S_DEFAULT) |
| 1562 | sortmode = S_TERMCAP; |
| 1563 | break; |
| 1564 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1565 | case 'D': |
| 1566 | show_databases(); |
| 1567 | ExitProgram(EXIT_SUCCESS); |
| 1568 | break; |
| 1569 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1570 | case 'c': |
| 1571 | compare = C_COMMON; |
| 1572 | break; |
| 1573 | |
| 1574 | case 'd': |
| 1575 | compare = C_DIFFERENCE; |
| 1576 | break; |
| 1577 | |
| 1578 | case 'E': |
| 1579 | initdump |= 2; |
| 1580 | break; |
| 1581 | |
| 1582 | case 'e': |
| 1583 | initdump |= 1; |
| 1584 | break; |
| 1585 | |
| 1586 | case 'F': |
| 1587 | filecompare = TRUE; |
| 1588 | break; |
| 1589 | |
| 1590 | case 'f': |
| 1591 | formatted = TRUE; |
| 1592 | break; |
| 1593 | |
| 1594 | case 'G': |
| 1595 | numbers = 1; |
| 1596 | break; |
| 1597 | |
| 1598 | case 'g': |
| 1599 | numbers = -1; |
| 1600 | break; |
| 1601 | |
| 1602 | case 'I': |
| 1603 | outform = F_TERMINFO; |
| 1604 | if (sortmode == S_DEFAULT) |
| 1605 | sortmode = S_VARIABLE; |
| 1606 | tversion = 0; |
| 1607 | break; |
| 1608 | |
| 1609 | case 'i': |
| 1610 | init_analyze = TRUE; |
| 1611 | break; |
| 1612 | |
| 1613 | case 'L': |
| 1614 | outform = F_VARIABLE; |
| 1615 | if (sortmode == S_DEFAULT) |
| 1616 | sortmode = S_VARIABLE; |
| 1617 | break; |
| 1618 | |
| 1619 | case 'l': |
| 1620 | outform = F_TERMINFO; |
| 1621 | break; |
| 1622 | |
| 1623 | case 'n': |
| 1624 | compare = C_NAND; |
| 1625 | break; |
| 1626 | |
| 1627 | case 'p': |
| 1628 | ignorepads = TRUE; |
| 1629 | break; |
| 1630 | |
| 1631 | case 'q': |
| 1632 | quiet = TRUE; |
| 1633 | s_absent = "-"; |
| 1634 | s_cancel = "@"; |
| 1635 | bool_sep = ", "; |
| 1636 | break; |
| 1637 | |
| 1638 | case 'R': |
| 1639 | tversion = optarg; |
| 1640 | break; |
| 1641 | |
| 1642 | case 'r': |
| 1643 | tversion = 0; |
| 1644 | break; |
| 1645 | |
| 1646 | case 's': |
| 1647 | if (*optarg == 'd') |
| 1648 | sortmode = S_NOSORT; |
| 1649 | else if (*optarg == 'i') |
| 1650 | sortmode = S_TERMINFO; |
| 1651 | else if (*optarg == 'l') |
| 1652 | sortmode = S_VARIABLE; |
| 1653 | else if (*optarg == 'c') |
| 1654 | sortmode = S_TERMCAP; |
| 1655 | else { |
| 1656 | (void) fprintf(stderr, |
| 1657 | "%s: unknown sort mode\n", |
| 1658 | _nc_progname); |
| 1659 | ExitProgram(EXIT_FAILURE); |
| 1660 | } |
| 1661 | break; |
| 1662 | |
| 1663 | case 'T': |
| 1664 | limited = FALSE; |
| 1665 | break; |
| 1666 | |
| 1667 | #if NCURSES_XNAMES |
| 1668 | case 't': |
| 1669 | _nc_disable_period = FALSE; |
| 1670 | suppress_untranslatable = TRUE; |
| 1671 | break; |
| 1672 | #endif |
| 1673 | |
| 1674 | case 'U': |
| 1675 | literal = TRUE; |
| 1676 | break; |
| 1677 | |
| 1678 | case 'u': |
| 1679 | compare = C_USEALL; |
| 1680 | break; |
| 1681 | |
| 1682 | case 'V': |
| 1683 | puts(curses_version()); |
| 1684 | ExitProgram(EXIT_SUCCESS); |
| 1685 | |
| 1686 | case 'v': |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1687 | itrace = (unsigned) optarg_to_number(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1688 | set_trace_level(itrace); |
| 1689 | break; |
| 1690 | |
| 1691 | case 'w': |
| 1692 | mwidth = optarg_to_number(); |
| 1693 | break; |
| 1694 | |
| 1695 | #if NCURSES_XNAMES |
| 1696 | case 'x': |
| 1697 | use_extended_names(TRUE); |
| 1698 | break; |
| 1699 | #endif |
| 1700 | |
| 1701 | default: |
| 1702 | usage(); |
| 1703 | } |
| 1704 | } |
| 1705 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1706 | maxterms = (size_t) (argc + 2 - optind); |
| 1707 | if ((tfile = typeMalloc(path, maxterms)) == 0) |
| 1708 | failed("tfile"); |
| 1709 | if ((tname = typeCalloc(char *, maxterms)) == 0) |
| 1710 | failed("tname"); |
| 1711 | if ((entries = typeCalloc(ENTRY, maxterms)) == 0) |
| 1712 | failed("entries"); |
| 1713 | #if NO_LEAKS |
| 1714 | if ((entered = typeCalloc(ENTERED, maxterms)) == 0) |
| 1715 | failed("entered"); |
| 1716 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1717 | |
| 1718 | if (tfile == 0 |
| 1719 | || tname == 0 |
| 1720 | || entries == 0) { |
| 1721 | fprintf(stderr, "%s: not enough memory\n", _nc_progname); |
| 1722 | ExitProgram(EXIT_FAILURE); |
| 1723 | } |
| 1724 | |
| 1725 | /* by default, sort by terminfo name */ |
| 1726 | if (sortmode == S_DEFAULT) |
| 1727 | sortmode = S_TERMINFO; |
| 1728 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1729 | /* make sure we have at least one terminal name to work with */ |
| 1730 | if (optind >= argc) |
| 1731 | argv[argc++] = terminal_env(); |
| 1732 | |
| 1733 | /* if user is after a comparison, make sure we have two entries */ |
| 1734 | if (compare != C_DEFAULT && optind >= argc - 1) |
| 1735 | argv[argc++] = terminal_env(); |
| 1736 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1737 | /* exactly one terminal name with no options means display it */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1738 | /* exactly two terminal names with no options means do -d */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1739 | if (compare == C_DEFAULT) { |
| 1740 | switch (argc - optind) { |
| 1741 | default: |
| 1742 | fprintf(stderr, "%s: too many names to compare\n", _nc_progname); |
| 1743 | ExitProgram(EXIT_FAILURE); |
| 1744 | case 1: |
| 1745 | break; |
| 1746 | case 2: |
| 1747 | compare = C_DIFFERENCE; |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | /* set up for display */ |
| 1753 | dump_init(tversion, outform, sortmode, mwidth, mheight, itrace, |
| 1754 | formatted, FALSE); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1755 | |
| 1756 | if (!filecompare) { |
| 1757 | /* grab the entries */ |
| 1758 | termcount = 0; |
| 1759 | for (; optind < argc; optind++) { |
| 1760 | const char *directory = termcount ? restdir : firstdir; |
| 1761 | int status; |
| 1762 | |
| 1763 | tname[termcount] = argv[optind]; |
| 1764 | |
| 1765 | if (directory) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1766 | #if NCURSES_USE_DATABASE |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1767 | #if MIXEDCASE_FILENAMES |
| 1768 | #define LEAF_FMT "%c" |
| 1769 | #else |
| 1770 | #define LEAF_FMT "%02x" |
| 1771 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1772 | _nc_SPRINTF(tfile[termcount], |
| 1773 | _nc_SLIMIT(sizeof(path)) |
| 1774 | "%s/" LEAF_FMT "/%s", |
| 1775 | directory, |
| 1776 | UChar(*argv[optind]), argv[optind]); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1777 | if (itrace) |
| 1778 | (void) fprintf(stderr, |
| 1779 | "%s: reading entry %s from file %s\n", |
| 1780 | _nc_progname, |
| 1781 | argv[optind], tfile[termcount]); |
| 1782 | |
| 1783 | status = _nc_read_file_entry(tfile[termcount], |
| 1784 | &entries[termcount].tterm); |
| 1785 | #else |
| 1786 | (void) fprintf(stderr, "%s: terminfo files not supported\n", |
| 1787 | _nc_progname); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1788 | MAIN_LEAKS(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1789 | ExitProgram(EXIT_FAILURE); |
| 1790 | #endif |
| 1791 | } else { |
| 1792 | if (itrace) |
| 1793 | (void) fprintf(stderr, |
| 1794 | "%s: reading entry %s from database\n", |
| 1795 | _nc_progname, |
| 1796 | tname[termcount]); |
| 1797 | |
| 1798 | status = _nc_read_entry(tname[termcount], |
| 1799 | tfile[termcount], |
| 1800 | &entries[termcount].tterm); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | if (status <= 0) { |
| 1804 | (void) fprintf(stderr, |
| 1805 | "%s: couldn't open terminfo file %s.\n", |
| 1806 | _nc_progname, |
| 1807 | tfile[termcount]); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1808 | MAIN_LEAKS(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1809 | ExitProgram(EXIT_FAILURE); |
| 1810 | } |
| 1811 | repair_acsc(&entries[termcount].tterm); |
| 1812 | termcount++; |
| 1813 | } |
| 1814 | |
| 1815 | #if NCURSES_XNAMES |
| 1816 | if (termcount > 1) |
| 1817 | _nc_align_termtype(&entries[0].tterm, &entries[1].tterm); |
| 1818 | #endif |
| 1819 | |
| 1820 | /* dump as C initializer for the terminal type */ |
| 1821 | if (initdump) { |
| 1822 | if (initdump & 1) |
| 1823 | dump_termtype(&entries[0].tterm); |
| 1824 | if (initdump & 2) |
| 1825 | dump_initializers(&entries[0].tterm); |
| 1826 | } |
| 1827 | |
| 1828 | /* analyze the init strings */ |
| 1829 | else if (init_analyze) { |
| 1830 | #undef CUR |
| 1831 | #define CUR entries[0].tterm. |
| 1832 | analyze_string("is1", init_1string, &entries[0].tterm); |
| 1833 | analyze_string("is2", init_2string, &entries[0].tterm); |
| 1834 | analyze_string("is3", init_3string, &entries[0].tterm); |
| 1835 | analyze_string("rs1", reset_1string, &entries[0].tterm); |
| 1836 | analyze_string("rs2", reset_2string, &entries[0].tterm); |
| 1837 | analyze_string("rs3", reset_3string, &entries[0].tterm); |
| 1838 | analyze_string("smcup", enter_ca_mode, &entries[0].tterm); |
| 1839 | analyze_string("rmcup", exit_ca_mode, &entries[0].tterm); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1840 | analyze_string("smkx", keypad_xmit, &entries[0].tterm); |
| 1841 | analyze_string("rmkx", keypad_local, &entries[0].tterm); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1842 | #undef CUR |
| 1843 | } else { |
| 1844 | |
| 1845 | /* |
| 1846 | * Here's where the real work gets done |
| 1847 | */ |
| 1848 | switch (compare) { |
| 1849 | case C_DEFAULT: |
| 1850 | if (itrace) |
| 1851 | (void) fprintf(stderr, |
| 1852 | "%s: about to dump %s\n", |
| 1853 | _nc_progname, |
| 1854 | tname[0]); |
| 1855 | (void) printf("#\tReconstructed via infocmp from file: %s\n", |
| 1856 | tfile[0]); |
| 1857 | dump_entry(&entries[0].tterm, |
| 1858 | suppress_untranslatable, |
| 1859 | limited, |
| 1860 | numbers, |
| 1861 | NULL); |
| 1862 | len = show_entry(); |
| 1863 | if (itrace) |
| 1864 | (void) fprintf(stderr, "%s: length %d\n", _nc_progname, len); |
| 1865 | break; |
| 1866 | |
| 1867 | case C_DIFFERENCE: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1868 | show_comparing(tname); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1869 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1870 | break; |
| 1871 | |
| 1872 | case C_COMMON: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1873 | show_comparing(tname); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1874 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1875 | break; |
| 1876 | |
| 1877 | case C_NAND: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1878 | show_comparing(tname); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1879 | compare_entry(compare_predicate, &entries->tterm, quiet); |
| 1880 | break; |
| 1881 | |
| 1882 | case C_USEALL: |
| 1883 | if (itrace) |
| 1884 | (void) fprintf(stderr, "%s: dumping use entry\n", _nc_progname); |
| 1885 | dump_entry(&entries[0].tterm, |
| 1886 | suppress_untranslatable, |
| 1887 | limited, |
| 1888 | numbers, |
| 1889 | use_predicate); |
| 1890 | for (i = 1; i < termcount; i++) |
| 1891 | dump_uses(tname[i], !(outform == F_TERMCAP |
| 1892 | || outform == F_TCONVERR)); |
| 1893 | len = show_entry(); |
| 1894 | if (itrace) |
| 1895 | (void) fprintf(stderr, "%s: length %d\n", _nc_progname, len); |
| 1896 | break; |
| 1897 | } |
| 1898 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1899 | } else if (compare == C_USEALL) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1900 | (void) fprintf(stderr, "Sorry, -u doesn't work with -F\n"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1901 | } else if (compare == C_DEFAULT) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1902 | (void) fprintf(stderr, "Use `tic -[CI] <file>' for this.\n"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1903 | } else if (argc - optind != 2) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1904 | (void) fprintf(stderr, |
| 1905 | "File comparison needs exactly two file arguments.\n"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1906 | } else { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1907 | file_comparison(argc - optind, argv + optind); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1908 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1909 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1910 | MAIN_LEAKS(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1911 | ExitProgram(EXIT_SUCCESS); |
| 1912 | } |
| 1913 | |
| 1914 | /* infocmp.c ends here */ |