File: | src/usr.bin/tic/tic.c |
Warning: | line 705, column 17 Value stored to 'source_file' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* $OpenBSD: tic.c,v 1.35 2023/10/17 09:52:10 nicm Exp $ */ |
2 | |
3 | /**************************************************************************** |
4 | * Copyright 2018-2022,2023 Thomas E. Dickey * |
5 | * Copyright 1998-2017,2018 Free Software Foundation, Inc. * |
6 | * * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a * |
8 | * copy of this software and associated documentation files (the * |
9 | * "Software"), to deal in the Software without restriction, including * |
10 | * without limitation the rights to use, copy, modify, merge, publish, * |
11 | * distribute, distribute with modifications, sublicense, and/or sell * |
12 | * copies of the Software, and to permit persons to whom the Software is * |
13 | * furnished to do so, subject to the following conditions: * |
14 | * * |
15 | * The above copyright notice and this permission notice shall be included * |
16 | * in all copies or substantial portions of the Software. * |
17 | * * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
21 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
24 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
25 | * * |
26 | * Except as contained in this notice, the name(s) of the above copyright * |
27 | * holders shall not be used in advertising or otherwise to promote the * |
28 | * sale, use or other dealings in this Software without prior written * |
29 | * authorization. * |
30 | ****************************************************************************/ |
31 | |
32 | /**************************************************************************** |
33 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
34 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
35 | * and: Thomas E. Dickey 1996 on * |
36 | ****************************************************************************/ |
37 | |
38 | /* |
39 | * tic.c --- Main program for terminfo compiler |
40 | * by Eric S. Raymond |
41 | * and Thomas E Dickey |
42 | * |
43 | */ |
44 | |
45 | #include <progs.priv.h> |
46 | #include <sys/stat.h> |
47 | |
48 | #include <dump_entry.h> |
49 | #include <tparm_type.h> |
50 | #include <hashed_db.h> |
51 | #include <parametrized.h> |
52 | #include <transform.h> |
53 | |
54 | MODULE_ID("$Id: tic.c,v 1.35 2023/10/17 09:52:10 nicm Exp $") |
55 | |
56 | #define STDIN_NAME"<stdin>" "<stdin>" |
57 | |
58 | const char *_nc_progname = "tic"; |
59 | |
60 | static FILE *log_fp; |
61 | static FILE *tmp_fp; |
62 | static bool_Bool capdump = FALSE0; /* running as infotocap? */ |
63 | static bool_Bool infodump = FALSE0; /* running as captoinfo? */ |
64 | static bool_Bool showsummary = FALSE0; |
65 | static unsigned debug_level; |
66 | static char **namelst = 0; |
67 | static const char *to_remove; |
68 | |
69 | #if NCURSES_XNAMES1 |
70 | static bool_Bool using_extensions = FALSE0; |
71 | #endif |
72 | |
73 | static void (*save_check_termtype) (TERMTYPE2 *, bool_Bool); |
74 | static void check_termtype(TERMTYPE2 *tt, bool_Bool); |
75 | |
76 | static const char usage_string[] = "\ |
77 | [-e names] \ |
78 | [-o dir] \ |
79 | [-R name] \ |
80 | [-v[n]] \ |
81 | [-V] \ |
82 | [-w[n]] \ |
83 | [-\ |
84 | 1\ |
85 | a\ |
86 | C\ |
87 | D\ |
88 | c\ |
89 | f\ |
90 | G\ |
91 | g\ |
92 | I\ |
93 | K\ |
94 | L\ |
95 | N\ |
96 | r\ |
97 | s\ |
98 | T\ |
99 | t\ |
100 | U\ |
101 | x\ |
102 | ] \ |
103 | source-file\n"; |
104 | |
105 | #if NO_LEAKS0 |
106 | static void |
107 | free_namelist(char **src) |
108 | { |
109 | if (src != 0) { |
110 | int n; |
111 | for (n = 0; src[n] != 0; ++n) |
112 | free(src[n]); |
113 | free(src); |
114 | } |
115 | } |
116 | #endif |
117 | |
118 | static void |
119 | cleanup(void) |
120 | { |
121 | #if NO_LEAKS0 |
122 | free_namelist(namelst); |
123 | _nc_leaks_dump_entry(); |
124 | #endif |
125 | if (tmp_fp != 0) |
126 | fclose(tmp_fp); |
127 | if (to_remove != 0) { |
128 | int rc; |
129 | |
130 | #if HAVE_REMOVE1 |
131 | rc = remove(to_remove); |
132 | #else |
133 | rc = unlink(to_remove); |
134 | #endif |
135 | if (rc != 0) |
136 | perror(to_remove); |
137 | } |
138 | } |
139 | |
140 | static void |
141 | failed(const char *msg) |
142 | { |
143 | perror(msg); |
144 | ExitProgram(EXIT_FAILURE)exit(1); |
145 | } |
146 | |
147 | static void |
148 | usage(void) |
149 | { |
150 | #define DATA(s) s "\n" |
151 | static const char options_string[] = |
152 | { |
153 | DATA("Options:") |
154 | DATA(" -0 format translation output all capabilities on one line") |
155 | DATA(" -1 format translation output one capability per line") |
156 | #if NCURSES_XNAMES1 |
157 | DATA(" -a retain commented-out capabilities (sets -x also)") |
158 | #endif |
159 | DATA(" -C translate entries to termcap source form") |
160 | DATA(" -D print list of tic's database locations (first must be writable)") |
161 | DATA(" -c check only, validate input without compiling or translating") |
162 | DATA(" -e<names> translate/compile only entries named by comma-separated list") |
163 | DATA(" -f format complex strings for readability") |
164 | DATA(" -G format %{number} to %'char'") |
165 | DATA(" -g format %'char' to %{number}") |
166 | DATA(" -I translate entries to terminfo source form") |
167 | DATA(" -K translate entries to termcap source form with BSD syntax") |
168 | DATA(" -L translate entries to full terminfo source form") |
169 | DATA(" -N disable smart defaults for source translation") |
170 | DATA(" -o<dir> set output directory for compiled entry writes") |
171 | DATA(" -Q[n] dump compiled description") |
172 | DATA(" -q brief listing, removes headers") |
173 | DATA(" -R<name> restrict translation to given terminfo/termcap version") |
174 | DATA(" -r force resolution of all use entries in source translation") |
175 | DATA(" -s print summary statistics") |
176 | DATA(" -T remove size-restrictions on compiled description") |
177 | #if NCURSES_XNAMES1 |
178 | DATA(" -t suppress commented-out capabilities") |
179 | #endif |
180 | DATA(" -U suppress post-processing of entries") |
181 | DATA(" -V print version") |
182 | DATA(" -W wrap long strings according to -w[n] option") |
183 | DATA(" -v[n] set verbosity level") |
184 | DATA(" -w[n] set format width for translation output") |
185 | #if NCURSES_XNAMES1 |
186 | DATA(" -x treat unknown capabilities as user-defined") |
187 | #endif |
188 | DATA("") |
189 | DATA("Parameters:") |
190 | DATA(" <file> file to translate or compile") |
191 | }; |
192 | #undef DATA |
193 | |
194 | fprintf(stderr(&__sF[2]), "Usage: %s %s\n", _nc_progname, usage_string); |
195 | fputs(options_string, stderr(&__sF[2])); |
196 | ExitProgram(EXIT_FAILURE)exit(1); |
197 | } |
198 | |
199 | #define L_BRACE'{' '{' |
200 | #define R_BRACE'}' '}' |
201 | #define S_QUOTE'\'' '\'' |
202 | |
203 | static void |
204 | write_it(ENTRY * ep) |
205 | { |
206 | unsigned n; |
207 | int ch; |
208 | char *s, *d, *t; |
209 | char result[MAX_ENTRY_SIZE32768]; |
210 | |
211 | /* |
212 | * Look for strings that contain %{number}, convert them to %'char', |
213 | * which is shorter and runs a little faster. |
214 | */ |
215 | for (n = 0; n < STRCOUNT414; n++) { |
216 | s = ep->tterm.Strings[n]; |
217 | if (VALID_STRING(s)((s) != (char *)(-1) && (s) != (char *)0) |
218 | && strchr(s, L_BRACE'{') != 0) { |
219 | d = result; |
220 | t = s; |
221 | while ((ch = *t++) != 0) { |
222 | *d++ = (char) ch; |
223 | if (ch == '\\') { |
224 | if ((*d++ = *t++) == '\0') |
225 | break; |
226 | } else if ((ch == '%') |
227 | && (*t == L_BRACE'{')) { |
228 | char *v = 0; |
229 | long value = strtol(t + 1, &v, 0); |
230 | if (v != 0 |
231 | && *v == R_BRACE'}' |
232 | && value > 0 |
233 | && value != '\\' /* FIXME */ |
234 | && value < 127 |
235 | && isprint((int) value)) { |
236 | *d++ = S_QUOTE'\''; |
237 | *d++ = (char) value; |
238 | *d++ = S_QUOTE'\''; |
239 | t = (v + 1); |
240 | } |
241 | } |
242 | } |
243 | *d = 0; |
244 | if (strlen(result) < strlen(s)) |
245 | _nc_STRCPY(s, result, strlen(s) + 1)(void) strlcpy((s),(result),(size_t)(strlen(s) + 1)); |
246 | } |
247 | } |
248 | |
249 | _nc_set_type(_nc_first_name(ep->tterm.term_names)); |
250 | _nc_curr_line = (int) ep->startline; |
251 | _nc_write_entry(&ep->tterm); |
252 | } |
253 | |
254 | static bool_Bool |
255 | immedhook(ENTRY * ep GCC_UNUSED__attribute__((unused))) |
256 | /* write out entries with no use capabilities immediately to save storage */ |
257 | { |
258 | #if !HAVE_BIG_CORE1 |
259 | /* |
260 | * This is strictly a core-economy kluge. The really clean way to handle |
261 | * compilation is to slurp the whole file into core and then do all the |
262 | * name-collision checks and entry writes in one swell foop. But the |
263 | * terminfo master file is large enough that some core-poor systems swap |
264 | * like crazy when you compile it this way...there have been reports of |
265 | * this process taking *three hours*, rather than the twenty seconds or |
266 | * less typical on my development box. |
267 | * |
268 | * So. This hook *immediately* writes out the referenced entry if it |
269 | * has no use capabilities. The compiler main loop refrains from |
270 | * adding the entry to the in-core list when this hook fires. If some |
271 | * other entry later needs to reference an entry that got written |
272 | * immediately, that's OK; the resolution code will fetch it off disk |
273 | * when it can't find it in core. |
274 | * |
275 | * Name collisions will still be detected, just not as cleanly. The |
276 | * write_entry() code complains before overwriting an entry that |
277 | * postdates the time of tic's first call to write_entry(). Thus |
278 | * it will complain about overwriting entries newly made during the |
279 | * tic run, but not about overwriting ones that predate it. |
280 | * |
281 | * The reason this is a hook, and not in line with the rest of the |
282 | * compiler code, is that the support for termcap fallback cannot assume |
283 | * it has anywhere to spool out these entries! |
284 | * |
285 | * The _nc_set_type() call here requires a compensating one in |
286 | * _nc_parse_entry(). |
287 | * |
288 | * If you define HAVE_BIG_CORE, you'll disable this kluge. This will |
289 | * make tic a bit faster (because the resolution code won't have to do |
290 | * disk I/O nearly as often). |
291 | */ |
292 | if (ep->nuses == 0) { |
293 | int oldline = _nc_curr_line; |
294 | |
295 | write_it(ep); |
296 | _nc_curr_line = oldline; |
297 | free(ep->tterm.str_table); |
298 | return (TRUE1); |
299 | } |
300 | #endif /* HAVE_BIG_CORE */ |
301 | return (FALSE0); |
302 | } |
303 | |
304 | static void |
305 | put_translate(int c) |
306 | /* emit a comment char, translating terminfo names to termcap names */ |
307 | { |
308 | static bool_Bool in_name = FALSE0; |
309 | static size_t used; |
310 | |
311 | if (in_name) { |
312 | static size_t have; |
313 | static char *namebuf, *suffix; |
314 | |
315 | if (used + 1 >= have) { |
316 | have += 132; |
317 | if ((namebuf = typeRealloc(char, have, namebuf)(char *)_nc_doalloc(namebuf, (size_t)(have)*sizeof(char))) == NULL((void *)0)) |
318 | failed("put_translate namebuf"); |
319 | if ((suffix = typeRealloc(char, have, suffix)(char *)_nc_doalloc(suffix, (size_t)(have)*sizeof(char))) == NULL((void *)0)) |
320 | failed("put_translate suffix"); |
321 | } |
322 | if (c == '\n' || c == '@') { |
323 | namebuf[used++] = '\0'; |
324 | (void) putchar('<')(!__isthreaded ? __sputc('<', (&__sF[1])) : (putc)('<' , (&__sF[1]))); |
325 | (void) fputs(namebuf, stdout(&__sF[1])); |
326 | putchar(c)(!__isthreaded ? __sputc(c, (&__sF[1])) : (putc)(c, (& __sF[1]))); |
327 | in_name = FALSE0; |
328 | } else if (c != '>') { |
329 | namebuf[used++] = (char) c; |
330 | } else { /* ah! candidate name! */ |
331 | char *up; |
332 | NCURSES_CONSTconst char *tp; |
333 | |
334 | namebuf[used++] = '\0'; |
335 | in_name = FALSE0; |
336 | |
337 | suffix[0] = '\0'; |
338 | if ((up = strchr(namebuf, '#')) != 0 |
339 | || (up = strchr(namebuf, '=')) != 0 |
340 | || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) { |
341 | _nc_STRCPY(suffix, up, have)(void) strlcpy((suffix),(up),(size_t)(have)); |
342 | *up = '\0'; |
343 | } |
344 | |
345 | if ((tp = nametrans(namebuf)) != 0) { |
346 | (void) putchar(':')(!__isthreaded ? __sputc(':', (&__sF[1])) : (putc)(':', ( &__sF[1]))); |
347 | (void) fputs(tp, stdout(&__sF[1])); |
348 | (void) fputs(suffix, stdout(&__sF[1])); |
349 | (void) putchar(':')(!__isthreaded ? __sputc(':', (&__sF[1])) : (putc)(':', ( &__sF[1]))); |
350 | } else { |
351 | /* couldn't find a translation, just dump the name */ |
352 | (void) putchar('<')(!__isthreaded ? __sputc('<', (&__sF[1])) : (putc)('<' , (&__sF[1]))); |
353 | (void) fputs(namebuf, stdout(&__sF[1])); |
354 | (void) fputs(suffix, stdout(&__sF[1])); |
355 | (void) putchar('>')(!__isthreaded ? __sputc('>', (&__sF[1])) : (putc)('>' , (&__sF[1]))); |
356 | } |
357 | } |
358 | } else { |
359 | used = 0; |
360 | if (c == '<') { |
361 | in_name = TRUE1; |
362 | } else { |
363 | putchar(c)(!__isthreaded ? __sputc(c, (&__sF[1])) : (putc)(c, (& __sF[1]))); |
364 | } |
365 | } |
366 | } |
367 | |
368 | /* Returns a string, stripped of leading/trailing whitespace */ |
369 | static char * |
370 | stripped(char *src) |
371 | { |
372 | char *dst = 0; |
373 | |
374 | while (isspace(UChar(*src)((unsigned char)(*src)))) |
375 | src++; |
376 | |
377 | if (*src != '\0') { |
378 | if ((dst = strdup(src)) == NULL((void *)0)) { |
379 | failed("strdup"); |
380 | } else { |
381 | size_t len = strlen(dst); |
382 | while (--len != 0 && isspace(UChar(dst[len])((unsigned char)(dst[len])))) |
383 | dst[len] = '\0'; |
384 | } |
385 | } |
386 | return dst; |
387 | } |
388 | |
389 | static FILE * |
390 | open_tempfile(char *filename) |
391 | { |
392 | FILE *result = 0; |
393 | |
394 | _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX)(void) strlcpy((filename),("/tmp/XXXXXX"),(size_t)(1024)); |
395 | #if HAVE_MKSTEMP1 |
396 | { |
397 | int oldmask = (int) umask(077); |
398 | int fd = mkstemp(filename); |
399 | if (fd >= 0) |
400 | result = fdopen(fd, "w"); |
401 | umask((mode_t) oldmask); |
402 | } |
403 | #else |
404 | if (tmpnam(filename) != 0) |
405 | result = safe_fopen(filename, "w")fopen(filename,"w"); |
406 | #endif |
407 | return result; |
408 | } |
409 | |
410 | static FILE * |
411 | copy_input(FILE *source, const char *filename, char *alt_file) |
412 | { |
413 | char my_altfile[PATH_MAX1024]; |
414 | FILE *result = 0; |
415 | FILE *target; |
416 | int ch; |
417 | |
418 | if (alt_file == NULL((void *)0)) |
419 | alt_file = my_altfile; |
420 | |
421 | if (source == NULL((void *)0)) { |
422 | failed("copy_input (source)"); |
423 | } else if ((target = open_tempfile(alt_file)) == NULL((void *)0)) { |
424 | failed("copy_input (target)"); |
425 | } else { |
426 | clearerr(source)(!__isthreaded ? ((void)((source)->_flags &= ~(0x0040| 0x0020))) : (clearerr)(source)); |
427 | for (;;) { |
428 | ch = fgetc(source); |
429 | if (feof(source)(!__isthreaded ? (((source)->_flags & 0x0020) != 0) : ( feof)(source))) { |
430 | break; |
431 | } else if (ferror(source)(!__isthreaded ? (((source)->_flags & 0x0040) != 0) : ( ferror)(source))) { |
432 | failed(filename); |
433 | } else if (ch == 0) { |
434 | /* don't loop in case someone wants to convert /dev/zero */ |
435 | fprintf(stderr(&__sF[2]), "%s: %s is not a text-file\n", _nc_progname, filename); |
436 | ExitProgram(EXIT_FAILURE)exit(1); |
437 | } |
438 | fputc(ch, target); |
439 | } |
440 | fclose(source); |
441 | /* |
442 | * rewind() does not force the target file's data to disk (not does |
443 | * fflush()...). So open a second stream on the data and then close |
444 | * the one that we were writing on before starting to read from the |
445 | * second stream. |
446 | */ |
447 | result = safe_fopen(alt_file, "r+")fopen(alt_file,"r+"); |
448 | fclose(target); |
449 | to_remove = strdup(alt_file); |
450 | } |
451 | return result; |
452 | } |
453 | |
454 | static FILE * |
455 | open_input(const char *filename, char *alt_file) |
456 | { |
457 | FILE *fp; |
458 | struct stat sb; |
459 | int mode; |
460 | |
461 | if (!strcmp(filename, "-")) { |
462 | fp = copy_input(stdin(&__sF[0]), STDIN_NAME"<stdin>", alt_file); |
463 | } else if (stat(filename, &sb) == -1) { |
464 | fprintf(stderr(&__sF[2]), "%s: %s %s\n", _nc_progname, filename, strerror(errno(*__errno()))); |
465 | ExitProgram(EXIT_FAILURE)exit(1); |
466 | } else if ((mode = (sb.st_mode & S_IFMT0170000)) == S_IFDIR0040000 |
467 | || (mode != S_IFREG0100000 && mode != S_IFCHR0020000 && mode != S_IFIFO0010000)) { |
468 | fprintf(stderr(&__sF[2]), "%s: %s is not a file\n", _nc_progname, filename); |
469 | ExitProgram(EXIT_FAILURE)exit(1); |
470 | } else { |
471 | fp = safe_fopen(filename, "r")fopen(filename,"r"); |
472 | |
473 | if (fp == NULL((void *)0)) { |
474 | fprintf(stderr(&__sF[2]), "%s: Can't open %s\n", _nc_progname, filename); |
475 | ExitProgram(EXIT_FAILURE)exit(1); |
476 | } |
477 | if (mode != S_IFREG0100000) { |
478 | if (alt_file != 0) { |
479 | FILE *fp2 = copy_input(fp, filename, alt_file); |
480 | fp = fp2; |
481 | } else { |
482 | fprintf(stderr(&__sF[2]), "%s: %s is not a file\n", _nc_progname, filename); |
483 | ExitProgram(EXIT_FAILURE)exit(1); |
484 | } |
485 | } |
486 | } |
487 | return fp; |
488 | } |
489 | |
490 | /* Parse the "-e" option-value into a list of names */ |
491 | static char ** |
492 | make_namelist(char *src) |
493 | { |
494 | char **dst = 0; |
495 | |
496 | char *s, *base; |
497 | unsigned pass, n, nn; |
498 | char buffer[BUFSIZ1024]; |
499 | |
500 | if (src == NULL((void *)0)) { |
501 | /* EMPTY */ ; |
502 | } else if (strchr(src, '/') != 0) { /* a filename */ |
503 | FILE *fp = open_input(src, (char *) 0); |
504 | |
505 | for (pass = 1; pass <= 2; pass++) { |
506 | nn = 0; |
507 | while (fgets(buffer, sizeof(buffer), fp) != 0) { |
508 | if ((s = stripped(buffer)) != 0) { |
509 | if (dst != 0) |
510 | dst[nn] = s; |
511 | else |
512 | free(s); |
513 | nn++; |
514 | } |
515 | } |
516 | if (pass == 1) { |
517 | if ((dst = typeCalloc(char *, nn + 1)(char * *)calloc((size_t)(nn + 1),sizeof(char *))) == NULL((void *)0)) |
518 | failed("make_namelist"); |
519 | rewind(fp); |
520 | } |
521 | } |
522 | fclose(fp); |
523 | } else { /* literal list of names */ |
524 | for (pass = 1; pass <= 2; pass++) { |
525 | for (n = nn = 0, base = src;; n++) { |
526 | int mark = src[n]; |
527 | if (mark == ',' || mark == '\0') { |
528 | if (pass == 1) { |
529 | nn++; |
530 | } else { |
531 | src[n] = '\0'; |
532 | if ((s = stripped(base)) != 0) |
533 | dst[nn++] = s; |
534 | base = &src[n + 1]; |
535 | } |
536 | } |
537 | if (mark == '\0') |
538 | break; |
539 | } |
540 | if (pass == 1) { |
541 | if ((dst = typeCalloc(char *, nn + 1)(char * *)calloc((size_t)(nn + 1),sizeof(char *))) == NULL((void *)0)) |
542 | failed("make_namelist"); |
543 | } |
544 | } |
545 | } |
546 | if (showsummary && (dst != 0)) { |
547 | fprintf(log_fp, "Entries that will be compiled:\n"); |
548 | for (n = 0; dst[n] != 0; n++) |
549 | fprintf(log_fp, "%u:%s\n", n + 1, dst[n]); |
550 | } |
551 | return dst; |
552 | } |
553 | |
554 | static bool_Bool |
555 | matches(char **needle, const char *haystack) |
556 | /* does entry in needle list match |-separated field in haystack? */ |
557 | { |
558 | bool_Bool code = FALSE0; |
559 | |
560 | if (needle != 0) { |
561 | size_t n; |
562 | |
563 | for (n = 0; needle[n] != 0; n++) { |
564 | if (_nc_name_match(haystack, needle[n], "|")) { |
565 | code = TRUE1; |
566 | break; |
567 | } |
568 | } |
569 | } else |
570 | code = TRUE1; |
571 | return (code); |
572 | } |
573 | |
574 | static char * |
575 | valid_db_path(const char *nominal) |
576 | { |
577 | struct stat sb; |
578 | #if USE_HASHED_DB0 |
579 | char suffix[] = DBM_SUFFIX; |
580 | size_t need = strlen(nominal) + sizeof(suffix); |
581 | char *result = malloc(need); |
582 | |
583 | if (result == NULL((void *)0)) |
584 | failed("valid_db_path"); |
585 | _nc_STRCPY(result, nominal, need)(void) strlcpy((result),(nominal),(size_t)(need)); |
586 | if (strcmp(result + need - sizeof(suffix), suffix)) { |
587 | _nc_STRCAT(result, suffix, need)(void) strlcat((result),(suffix),(size_t)(need)); |
588 | } |
589 | #else |
590 | char *result = strdup(nominal); |
591 | #endif |
592 | |
593 | DEBUG(1, ("** stat(%s)", result)); |
594 | if (stat(result, &sb) >= 0) { |
595 | #if USE_HASHED_DB0 |
596 | if (!S_ISREG(sb.st_mode)((sb.st_mode & 0170000) == 0100000) |
597 | || access(result, R_OK0x04 | W_OK0x02) != 0) { |
598 | DEBUG(1, ("...not a writable file")); |
599 | free(result); |
600 | result = 0; |
601 | } |
602 | #else |
603 | if (!S_ISDIR(sb.st_mode)((sb.st_mode & 0170000) == 0040000) |
604 | || access(result, R_OK0x04 | W_OK0x02 | X_OK0x01) != 0) { |
605 | DEBUG(1, ("...not a writable directory")); |
606 | free(result); |
607 | result = 0; |
608 | } |
609 | #endif |
610 | } else { |
611 | /* check if parent is directory and is writable */ |
612 | unsigned leaf = _nc_pathlast(result); |
613 | |
614 | DEBUG(1, ("...not found")); |
615 | if (leaf) { |
616 | char save = result[leaf]; |
617 | result[leaf] = 0; |
618 | if (stat(result, &sb) >= 0 |
619 | && S_ISDIR(sb.st_mode)((sb.st_mode & 0170000) == 0040000) |
620 | && access(result, R_OK0x04 | W_OK0x02 | X_OK0x01) == 0) { |
621 | result[leaf] = save; |
622 | } else { |
623 | DEBUG(1, ("...parent directory %s is not writable", result)); |
624 | free(result); |
625 | result = 0; |
626 | } |
627 | } else { |
628 | DEBUG(1, ("... no parent directory")); |
629 | free(result); |
630 | result = 0; |
631 | } |
632 | } |
633 | return result; |
634 | } |
635 | |
636 | /* |
637 | * Show the databases to which tic could write. The location to which it |
638 | * writes is always the first one. If none are writable, print an error |
639 | * message. |
640 | */ |
641 | static void |
642 | show_databases(const char *outdir) |
643 | { |
644 | bool_Bool specific = (outdir != 0) || getenv("TERMINFO") != 0; |
645 | char *result; |
646 | const char *tried = 0; |
647 | |
648 | if (outdir == NULL((void *)0)) { |
649 | outdir = _nc_tic_dir(NULL((void *)0)); |
650 | } |
651 | if ((result = valid_db_path(outdir)) != 0) { |
652 | printf("%s\n", result); |
653 | free(result); |
654 | } else { |
655 | tried = outdir; |
656 | } |
657 | |
658 | if ((outdir = _nc_home_terminfo())) { |
659 | if ((result = valid_db_path(outdir)) != 0) { |
660 | printf("%s\n", result); |
661 | free(result); |
662 | } else if (!specific) { |
663 | tried = outdir; |
664 | } |
665 | } |
666 | |
667 | /* |
668 | * If we can write in neither location, give an error message. |
669 | */ |
670 | if (tried) { |
671 | fflush(stdout(&__sF[1])); |
672 | fprintf(stderr(&__sF[2]), "%s: %s (no permission)\n", _nc_progname, tried); |
673 | ExitProgram(EXIT_FAILURE)exit(1); |
674 | } |
675 | } |
676 | |
677 | static void |
678 | add_digit(int *target, int source) |
679 | { |
680 | *target = (*target * 10) + (source - '0'); |
681 | } |
682 | |
683 | int |
684 | main(int argc, char *argv[]) |
685 | { |
686 | char my_tmpname[PATH_MAX1024]; |
687 | int v_opt = -1; |
688 | int smart_defaults = TRUE1; |
689 | char *termcap; |
690 | ENTRY *qp; |
691 | |
692 | int this_opt, last_opt = '?'; |
693 | |
694 | int outform = F_TERMINFO0; /* output format */ |
695 | int sortmode = S_TERMINFO2; /* sort_mode */ |
696 | |
697 | int width = 60; |
698 | int height = 65535; |
699 | bool_Bool formatted = FALSE0; /* reformat complex strings? */ |
700 | bool_Bool literal = FALSE0; /* suppress post-processing? */ |
701 | int numbers = 0; /* format "%'char'" to/from "%{number}" */ |
702 | bool_Bool forceresolve = FALSE0; /* force resolution */ |
703 | bool_Bool limited = TRUE1; |
704 | char *tversion = (char *) NULL((void *)0); |
705 | const char *source_file = "terminfo"; |
Value stored to 'source_file' during its initialization is never read | |
706 | char *outdir = (char *) NULL((void *)0); |
707 | bool_Bool check_only = FALSE0; |
708 | bool_Bool suppress_untranslatable = FALSE0; |
709 | int quickdump = 0; |
710 | bool_Bool quiet = FALSE0; |
711 | bool_Bool wrap_strings = FALSE0; |
712 | |
713 | if (pledge("stdio rpath wpath cpath", NULL((void *)0)) == -1) { |
714 | perror("pledge"); |
715 | exit(1); |
716 | } |
717 | |
718 | log_fp = stderr(&__sF[2]); |
719 | |
720 | _nc_progname = _nc_rootname(argv[0]); |
721 | atexit(cleanup); |
722 | |
723 | if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO"captoinfo")) != FALSE0) { |
724 | outform = F_TERMINFO0; |
725 | sortmode = S_TERMINFO2; |
726 | } |
727 | if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP"infotocap")) != FALSE0) { |
728 | outform = F_TERMCAP2; |
729 | sortmode = S_TERMCAP4; |
730 | } |
731 | #if NCURSES_XNAMES1 |
732 | /* set this directly to avoid interaction with -v and -D options */ |
733 | _nc_user_definable = FALSE0; |
734 | #endif |
735 | _nc_strict_bsd = 0; |
736 | |
737 | /* |
738 | * Processing arguments is a little complicated, since someone made a |
739 | * design decision to allow the numeric values for -w, -v options to |
740 | * be optional. |
741 | */ |
742 | while ((this_opt = getopt(argc, argv, |
743 | "0123456789CDIKLNQR:TUVWace:fGgo:qrstvwx")) != -1) { |
744 | if (isdigit(this_opt)) { |
745 | switch (last_opt) { |
746 | case 'Q': |
747 | add_digit(&quickdump, this_opt); |
748 | break; |
749 | case 'v': |
750 | add_digit(&v_opt, this_opt); |
751 | break; |
752 | case 'w': |
753 | add_digit(&width, this_opt); |
754 | break; |
755 | default: |
756 | switch (this_opt) { |
757 | case '0': |
758 | last_opt = this_opt; |
759 | width = 65535; |
760 | height = 1; |
761 | break; |
762 | case '1': |
763 | last_opt = this_opt; |
764 | width = 0; |
765 | break; |
766 | default: |
767 | usage(); |
768 | } |
769 | } |
770 | continue; |
771 | } |
772 | switch (this_opt) { |
773 | case 'K': |
774 | _nc_strict_bsd = 1; |
775 | /* the initial version of -K in 20110730 fell-thru here, but the |
776 | * same flag is useful when reading sources -TD |
777 | */ |
778 | break; |
779 | case 'C': |
780 | capdump = TRUE1; |
781 | outform = F_TERMCAP2; |
782 | sortmode = S_TERMCAP4; |
783 | break; |
784 | case 'D': |
785 | debug_level = VtoTrace(v_opt)(unsigned) ((v_opt > 0) ? v_opt : (v_opt == 0)); |
786 | use_verbosity(debug_level)do { _nc_tracing &= ((1 << 13) - 1), _nc_tracing |= ((debug_level) << 13); } while (0); |
787 | show_databases(outdir); |
788 | ExitProgram(EXIT_SUCCESS)exit(0); |
789 | break; |
790 | case 'I': |
791 | infodump = TRUE1; |
792 | outform = F_TERMINFO0; |
793 | sortmode = S_TERMINFO2; |
794 | break; |
795 | case 'L': |
796 | infodump = TRUE1; |
797 | outform = F_VARIABLE1; |
798 | sortmode = S_VARIABLE3; |
799 | break; |
800 | case 'N': |
801 | smart_defaults = FALSE0; |
802 | literal = TRUE1; |
803 | break; |
804 | case 'Q': |
805 | quickdump = 0; |
806 | break; |
807 | case 'R': |
808 | tversion = optarg; |
809 | break; |
810 | case 'T': |
811 | limited = FALSE0; |
812 | break; |
813 | case 'U': |
814 | literal = TRUE1; |
815 | break; |
816 | case 'V': |
817 | puts(curses_version()); |
818 | ExitProgram(EXIT_SUCCESS)exit(0); |
819 | case 'W': |
820 | wrap_strings = TRUE1; |
821 | break; |
822 | case 'c': |
823 | check_only = TRUE1; |
824 | break; |
825 | case 'e': |
826 | namelst = make_namelist(optarg); |
827 | break; |
828 | case 'f': |
829 | formatted = TRUE1; |
830 | break; |
831 | case 'G': |
832 | numbers = 1; |
833 | break; |
834 | case 'g': |
835 | numbers = -1; |
836 | break; |
837 | case 'o': |
838 | outdir = optarg; |
839 | break; |
840 | case 'q': |
841 | quiet = TRUE1; |
842 | break; |
843 | case 'r': |
844 | forceresolve = TRUE1; |
845 | break; |
846 | case 's': |
847 | showsummary = TRUE1; |
848 | break; |
849 | case 'v': |
850 | v_opt = 0; |
851 | break; |
852 | case 'w': |
853 | width = 0; |
854 | break; |
855 | #if NCURSES_XNAMES1 |
856 | case 't': |
857 | _nc_disable_period = FALSE0; |
858 | suppress_untranslatable = TRUE1; |
859 | break; |
860 | case 'a': |
861 | _nc_disable_period = TRUE1; |
862 | /* FALLTHRU */ |
863 | case 'x': |
864 | using_extensions = TRUE1; |
865 | break; |
866 | #endif |
867 | default: |
868 | usage(); |
869 | } |
870 | last_opt = this_opt; |
871 | } |
872 | |
873 | /* |
874 | * If the -v option is set, it may override the $NCURSES_TRACE environment |
875 | * variable, e.g., for -v3 and up. |
876 | */ |
877 | debug_level = VtoTrace(v_opt)(unsigned) ((v_opt > 0) ? v_opt : (v_opt == 0)); |
878 | use_verbosity(debug_level)do { _nc_tracing &= ((1 << 13) - 1), _nc_tracing |= ((debug_level) << 13); } while (0); |
879 | |
880 | /* |
881 | * Do this after setting debug_level, since the function calls START_TRACE, |
882 | * which uses the $NCURSES_TRACE environment variable if _nc_tracing bits |
883 | * for tracing are zero. |
884 | */ |
885 | #if NCURSES_XNAMES1 |
886 | if (using_extensions) { |
887 | use_extended_names(TRUE1); |
888 | } |
889 | #endif |
890 | |
891 | if (_nc_tracing) { |
892 | save_check_termtype = _nc_check_termtype2; |
893 | _nc_check_termtype2 = check_termtype; |
894 | } |
895 | #if !HAVE_BIG_CORE1 |
896 | /* |
897 | * Aaargh! immedhook seriously hoses us! |
898 | * |
899 | * One problem with immedhook is it means we can't do -e. Problem |
900 | * is that we can't guarantee that for each terminal listed, all the |
901 | * terminals it depends on will have been kept in core for reference |
902 | * resolution -- in fact it is certain the primitive types at the end |
903 | * of reference chains *won't* be in core unless they were explicitly |
904 | * in the select list themselves. |
905 | */ |
906 | if (namelst && (!infodump && !capdump)) { |
907 | (void) fprintf(stderr(&__sF[2]), |
908 | "%s: Sorry, -e can't be used without -I or -C\n", |
909 | _nc_progname); |
910 | ExitProgram(EXIT_FAILURE)exit(1); |
911 | } |
912 | #endif /* HAVE_BIG_CORE */ |
913 | |
914 | if (optind < argc) { |
915 | source_file = argv[optind++]; |
916 | if (optind < argc) { |
917 | fprintf(stderr(&__sF[2]), |
918 | "%s: Too many file names. Usage:\n\t%s %s", |
919 | _nc_progname, |
920 | _nc_progname, |
921 | usage_string); |
922 | ExitProgram(EXIT_FAILURE)exit(1); |
923 | } |
924 | } else { |
925 | if (infodump == TRUE1) { |
926 | /* captoinfo's no-argument case */ |
927 | source_file = "/etc/termcap"; |
928 | if ((termcap = getenv("TERMCAP")) != 0 |
929 | && (namelst = make_namelist(getenv("TERM"))) != 0) { |
930 | if (access(termcap, F_OK0) == 0) { |
931 | /* file exists */ |
932 | source_file = termcap; |
933 | } else { |
934 | if ((tmp_fp = open_tempfile(my_tmpname)) != 0) { |
935 | source_file = my_tmpname; |
936 | fprintf(tmp_fp, "%s\n", termcap); |
937 | fclose(tmp_fp); |
938 | tmp_fp = open_input(source_file, (char *) 0); |
939 | to_remove = source_file; |
940 | } else { |
941 | failed("tmpnam"); |
942 | } |
943 | } |
944 | } |
945 | } else { |
946 | /* tic */ |
947 | fprintf(stderr(&__sF[2]), |
948 | "%s: File name needed. Usage:\n\t%s %s", |
949 | _nc_progname, |
950 | _nc_progname, |
951 | usage_string); |
952 | ExitProgram(EXIT_FAILURE)exit(1); |
953 | } |
954 | } |
955 | |
956 | if (tmp_fp == NULL((void *)0)) { |
957 | char my_altfile[PATH_MAX1024]; |
958 | tmp_fp = open_input(source_file, my_altfile); |
959 | if (!strcmp(source_file, "-")) { |
960 | source_file = STDIN_NAME"<stdin>"; |
961 | } |
962 | } |
963 | |
964 | if (infodump || check_only) { |
965 | dump_init(tversion, |
966 | (smart_defaults |
967 | ? outform |
968 | : F_LITERAL4), |
969 | sortmode, |
970 | wrap_strings, width, height, |
971 | debug_level, formatted || check_only, check_only, quickdump); |
972 | } else if (capdump) { |
973 | dump_init(tversion, |
974 | outform, |
975 | sortmode, |
976 | wrap_strings, width, height, |
977 | debug_level, FALSE0, FALSE0, FALSE0); |
978 | } |
979 | |
980 | /* parse entries out of the source file */ |
981 | _nc_set_source(source_file); |
982 | #if !HAVE_BIG_CORE1 |
983 | if (!(check_only || infodump || capdump)) |
984 | _nc_set_writedir(outdir); |
985 | #endif /* HAVE_BIG_CORE */ |
986 | _nc_read_entry_source(tmp_fp, (char *) NULL((void *)0), |
987 | !smart_defaults || literal, FALSE0, |
988 | ((check_only || infodump || capdump) |
989 | ? NULLHOOK(_Bool(*)(ENTRY *))0 |
990 | : immedhook)); |
991 | |
992 | /* do use resolution */ |
993 | if (check_only || (!infodump && !capdump) || forceresolve) { |
994 | if (!_nc_resolve_uses2(TRUE1, literal) && !check_only) { |
995 | ExitProgram(EXIT_FAILURE)exit(1); |
996 | } |
997 | } |
998 | |
999 | /* length check */ |
1000 | if (check_only && limited && (capdump || infodump)) { |
1001 | for_entry_list(qp)for (qp = _nc_head; qp; qp = qp->next) { |
1002 | if (matches(namelst, qp->tterm.term_names)) { |
1003 | int len = fmt_entry(&qp->tterm, NULL((void *)0), FALSE0, TRUE1, infodump, numbers); |
1004 | |
1005 | if (len > (infodump ? MAX_TERMINFO_LENGTH4096 : MAX_TERMCAP_LENGTH1023)) |
1006 | (void) fprintf(stderr(&__sF[2]), |
1007 | "%s: resolved %s entry is %d bytes long\n", |
1008 | _nc_progname, |
1009 | _nc_first_name(qp->tterm.term_names), |
1010 | len); |
1011 | } |
1012 | } |
1013 | } |
1014 | |
1015 | /* write or dump all entries */ |
1016 | if (check_only) { |
1017 | /* this is in case infotocap() generates warnings */ |
1018 | _nc_curr_col = _nc_curr_line = -1; |
1019 | |
1020 | for_entry_list(qp)for (qp = _nc_head; qp; qp = qp->next) { |
1021 | if (matches(namelst, qp->tterm.term_names)) { |
1022 | /* this is in case infotocap() generates warnings */ |
1023 | _nc_set_type(_nc_first_name(qp->tterm.term_names)); |
1024 | _nc_curr_line = (int) qp->startline; |
1025 | repair_acsc(&qp->tterm); |
1026 | dump_entry(&qp->tterm, suppress_untranslatable, |
1027 | limited, numbers, NULL((void *)0)); |
1028 | } |
1029 | } |
1030 | } else { |
1031 | if (!infodump && !capdump) { |
1032 | _nc_set_writedir(outdir); |
1033 | for_entry_list(qp)for (qp = _nc_head; qp; qp = qp->next) { |
1034 | if (matches(namelst, qp->tterm.term_names)) |
1035 | write_it(qp); |
1036 | } |
1037 | } else { |
1038 | /* this is in case infotocap() generates warnings */ |
1039 | _nc_curr_col = _nc_curr_line = -1; |
1040 | |
1041 | for_entry_list(qp)for (qp = _nc_head; qp; qp = qp->next) { |
1042 | if (matches(namelst, qp->tterm.term_names)) { |
1043 | long j = qp->cend - qp->cstart; |
1044 | int len = 0; |
1045 | |
1046 | /* this is in case infotocap() generates warnings */ |
1047 | _nc_set_type(_nc_first_name(qp->tterm.term_names)); |
1048 | |
1049 | if (!quiet) { |
1050 | (void) fseek(tmp_fp, qp->cstart, SEEK_SET0); |
1051 | while (j-- > 0) { |
1052 | int ch = fgetc(tmp_fp); |
1053 | if (ch == EOF(-1) || ferror(tmp_fp)(!__isthreaded ? (((tmp_fp)->_flags & 0x0040) != 0) : ( ferror)(tmp_fp))) { |
1054 | break; |
1055 | } else if (infodump) { |
1056 | (void) putchar(ch)(!__isthreaded ? __sputc(ch, (&__sF[1])) : (putc)(ch, (& __sF[1]))); |
1057 | } else { |
1058 | put_translate(ch); |
1059 | } |
1060 | } |
1061 | } |
1062 | |
1063 | repair_acsc(&qp->tterm); |
1064 | dump_entry(&qp->tterm, suppress_untranslatable, |
1065 | limited, numbers, NULL((void *)0)); |
1066 | for (j = 0; j < (long) qp->nuses; j++) |
1067 | dump_uses(qp->uses[j].name, !capdump); |
1068 | len = show_entry(); |
1069 | if (debug_level != 0 && !limited) |
1070 | printf("# length=%d\n", len); |
1071 | } |
1072 | } |
1073 | if (!namelst && _nc_tail && !quiet) { |
1074 | int c, oldc = '\0'; |
1075 | bool_Bool in_comment = FALSE0; |
1076 | bool_Bool trailing_comment = FALSE0; |
1077 | |
1078 | (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET0); |
1079 | while ((c = fgetc(tmp_fp)) != EOF(-1)) { |
1080 | if (oldc == '\n') { |
1081 | if (c == '#') { |
1082 | trailing_comment = TRUE1; |
1083 | in_comment = TRUE1; |
1084 | } else { |
1085 | in_comment = FALSE0; |
1086 | } |
1087 | } |
1088 | if (trailing_comment |
1089 | && (in_comment || (oldc == '\n' && c == '\n'))) |
1090 | putchar(c)(!__isthreaded ? __sputc(c, (&__sF[1])) : (putc)(c, (& __sF[1]))); |
1091 | oldc = c; |
1092 | } |
1093 | } |
1094 | } |
1095 | } |
1096 | |
1097 | /* Show the directory into which entries were written, and the total |
1098 | * number of entries |
1099 | */ |
1100 | if (showsummary |
1101 | && (!(check_only || infodump || capdump))) { |
1102 | int total = _nc_tic_written(); |
1103 | if (total != 0) |
1104 | fprintf(log_fp, "%d entries written to %s\n", |
1105 | total, |
1106 | _nc_tic_dir(NULL((void *)0))); |
1107 | else |
1108 | fprintf(log_fp, "No entries written\n"); |
1109 | } |
1110 | ExitProgram(EXIT_SUCCESS)exit(0); |
1111 | } |
1112 | |
1113 | /* |
1114 | * This bit of legerdemain turns all the terminfo variable names into |
1115 | * references to locations in the arrays Booleans, Numbers, and Strings --- |
1116 | * precisely what's needed (see comp_parse.c). |
1117 | */ |
1118 | #undef CURtp-> |
1119 | #define CURtp-> tp-> |
1120 | |
1121 | /* |
1122 | * Check if the alternate character-set capabilities are consistent. |
1123 | */ |
1124 | static void |
1125 | check_acs(TERMTYPE2 *tp) |
1126 | { |
1127 | int vt100_smacs = 0; |
1128 | int vt100_rmacs = 0; |
1129 | int vt100_enacs = 0; |
1130 | |
1131 | /* |
1132 | * ena_acs is not always necessary, but if it is present, the enter/exit |
1133 | * capabilities should be. |
1134 | */ |
1135 | ANDMISSING(ena_acs, enter_alt_charset_mode){ if ((((tp-> Strings[155]) != (char *)0) && ((tp-> Strings[155]) != (char *)(-1))) && !(((tp-> Strings [25]) != (char *)0) && ((tp-> Strings[25]) != (char *)(-1)))) _nc_warning("ena_acs" " but no " "enter_alt_charset_mode" ); }; |
1136 | ANDMISSING(ena_acs, exit_alt_charset_mode){ if ((((tp-> Strings[155]) != (char *)0) && ((tp-> Strings[155]) != (char *)(-1))) && !(((tp-> Strings [38]) != (char *)0) && ((tp-> Strings[38]) != (char *)(-1)))) _nc_warning("ena_acs" " but no " "exit_alt_charset_mode" ); }; |
1137 | PAIRED(exit_alt_charset_mode, exit_alt_charset_mode){ if ((((tp-> Strings[38]) != (char *)0) && ((tp-> Strings[38]) != (char *)(-1))) && !(((tp-> Strings [38]) != (char *)0) && ((tp-> Strings[38]) != (char *)(-1)))) _nc_warning("exit_alt_charset_mode" " but no " "exit_alt_charset_mode" ); if ((((tp-> Strings[38]) != (char *)0) && ((tp-> Strings[38]) != (char *)(-1))) && !(((tp-> Strings [38]) != (char *)0) && ((tp-> Strings[38]) != (char *)(-1)))) _nc_warning("exit_alt_charset_mode" " but no " "exit_alt_charset_mode" ); }; |
1138 | |
1139 | /* |
1140 | * vt100-like is frequently used, but perhaps ena_acs is missing, etc. |
1141 | */ |
1142 | if (VALID_STRING(enter_alt_charset_mode)((tp-> Strings[25]) != (char *)(-1) && (tp-> Strings [25]) != (char *)0)) { |
1143 | vt100_smacs = (!strcmp("\033(0", enter_alt_charset_modetp-> Strings[25]) |
1144 | ? 2 |
1145 | : (!strcmp("\016", enter_alt_charset_modetp-> Strings[25]) |
1146 | ? 1 |
1147 | : 0)); |
1148 | } |
1149 | if (VALID_STRING(exit_alt_charset_mode)((tp-> Strings[38]) != (char *)(-1) && (tp-> Strings [38]) != (char *)0)) { |
1150 | vt100_rmacs = (!strcmp("\033(B", exit_alt_charset_modetp-> Strings[38]) |
1151 | ? 2 |
1152 | : (!strcmp("\017", exit_alt_charset_modetp-> Strings[38]) |
1153 | ? 1 |
1154 | : 0)); |
1155 | } |
1156 | if (VALID_STRING(ena_acs)((tp-> Strings[155]) != (char *)(-1) && (tp-> Strings [155]) != (char *)0)) { |
1157 | vt100_enacs = (!strcmp("\033(B\033)0", ena_acstp-> Strings[155]) |
1158 | ? 2 |
1159 | : 0); |
1160 | } |
1161 | if (vt100_rmacs && vt100_smacs && (vt100_rmacs != vt100_smacs)) { |
1162 | _nc_warning("rmacs/smacs are inconsistent"); |
1163 | } |
1164 | if ((vt100_rmacs == 2) && (vt100_smacs == 2) && vt100_enacs) { |
1165 | _nc_warning("rmacs/smacs make enacs redundant"); |
1166 | } |
1167 | if ((vt100_rmacs == 1) && (vt100_smacs == 1) && !vt100_enacs) { |
1168 | _nc_warning("VT100-style rmacs/smacs require enacs"); |
1169 | } |
1170 | |
1171 | if (VALID_STRING(acs_chars)((tp-> Strings[146]) != (char *)(-1) && (tp-> Strings [146]) != (char *)0)) { |
1172 | const char *boxes = "lmkjtuvwqxn"; |
1173 | char mapped[256]; |
1174 | char missing[256]; |
1175 | const char *p; |
1176 | char *q; |
1177 | |
1178 | memset(mapped, 0, sizeof(mapped)); |
1179 | memset(missing, 0, sizeof(missing)); |
1180 | for (p = acs_charstp-> Strings[146]; *p != '\0'; p += 2) { |
1181 | if (p[1] == '\0') { |
1182 | _nc_warning("acsc has odd number of characters"); |
1183 | break; |
1184 | } |
1185 | mapped[UChar(p[0])((unsigned char)(p[0]))] = p[1]; |
1186 | } |
1187 | |
1188 | if (mapped[UChar('I')((unsigned char)('I'))] && !mapped[UChar('i')((unsigned char)('i'))]) { |
1189 | _nc_warning("acsc refers to 'I', which is probably an error"); |
1190 | } |
1191 | |
1192 | for (p = boxes, q = missing; *p != '\0'; ++p) { |
1193 | if (!mapped[UChar(p[0])((unsigned char)(p[0]))]) { |
1194 | *q++ = p[0]; |
1195 | } |
1196 | } |
1197 | *q = '\0'; |
1198 | |
1199 | assert(strlen(missing) <= strlen(boxes))((strlen(missing) <= strlen(boxes)) ? (void)0 : __assert2( "/usr/src/usr.bin/tic/tic.c", 1199, __func__, "strlen(missing) <= strlen(boxes)" )); |
1200 | if (*missing != '\0' && strcmp(missing, boxes)) { |
1201 | _nc_warning("acsc is missing some line-drawing mapping: %s", missing); |
1202 | } |
1203 | } |
1204 | } |
1205 | |
1206 | static char * |
1207 | safe_strdup(const char *value) |
1208 | { |
1209 | if (value == NULL((void *)0)) |
1210 | value = ""; |
1211 | return strdup(value); |
1212 | } |
1213 | |
1214 | static bool_Bool |
1215 | same_color(NCURSES_CONSTconst char *oldcap, NCURSES_CONSTconst char *newcap, int limit) |
1216 | { |
1217 | bool_Bool result = FALSE0; |
1218 | if (limit > 16) |
1219 | limit = 16; |
1220 | if (limit >= 8) { |
1221 | int n; |
1222 | int same; |
1223 | for (n = same = 0; n < limit; ++n) { |
1224 | char *oldvalue = safe_strdup(TIPARM_1(oldcap, n)_nc_tiparm(1,oldcap,n)); |
1225 | char *newvalue = safe_strdup(TIPARM_1(newcap, n)_nc_tiparm(1,newcap,n)); |
1226 | same += !strcmp(oldvalue, newvalue); |
1227 | free(oldvalue); |
1228 | free(newvalue); |
1229 | } |
1230 | result = (same == limit); |
1231 | } |
1232 | return result; |
1233 | } |
1234 | |
1235 | /* |
1236 | * Check if the color capabilities are consistent |
1237 | */ |
1238 | static void |
1239 | check_colors(TERMTYPE2 *tp) |
1240 | { |
1241 | char *value; |
1242 | |
1243 | if ((max_colorstp-> Numbers[13] > 0) != (max_pairstp-> Numbers[14] > 0) |
1244 | || ((max_colorstp-> Numbers[13] > max_pairstp-> Numbers[14]) && !VALID_STRING(initialize_pair)((tp-> Strings[300]) != (char *)(-1) && (tp-> Strings [300]) != (char *)0))) |
1245 | _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)", |
1246 | max_colorstp-> Numbers[13], max_pairstp-> Numbers[14]); |
1247 | |
1248 | PAIRED(set_foreground, set_background){ if ((((tp-> Strings[303]) != (char *)0) && ((tp-> Strings[303]) != (char *)(-1))) && !(((tp-> Strings [302]) != (char *)0) && ((tp-> Strings[302]) != (char *)(-1)))) _nc_warning("set_background" " but no " "set_foreground" ); if ((((tp-> Strings[302]) != (char *)0) && ((tp -> Strings[302]) != (char *)(-1))) && !(((tp-> Strings [303]) != (char *)0) && ((tp-> Strings[303]) != (char *)(-1)))) _nc_warning("set_foreground" " but no " "set_background" ); }; |
1249 | PAIRED(set_a_foreground, set_a_background){ if ((((tp-> Strings[360]) != (char *)0) && ((tp-> Strings[360]) != (char *)(-1))) && !(((tp-> Strings [359]) != (char *)0) && ((tp-> Strings[359]) != (char *)(-1)))) _nc_warning("set_a_background" " but no " "set_a_foreground" ); if ((((tp-> Strings[359]) != (char *)0) && ((tp -> Strings[359]) != (char *)(-1))) && !(((tp-> Strings [360]) != (char *)0) && ((tp-> Strings[360]) != (char *)(-1)))) _nc_warning("set_a_foreground" " but no " "set_a_background" ); }; |
1250 | PAIRED(set_color_pair, initialize_pair){ if ((((tp-> Strings[300]) != (char *)0) && ((tp-> Strings[300]) != (char *)(-1))) && !(((tp-> Strings [301]) != (char *)0) && ((tp-> Strings[301]) != (char *)(-1)))) _nc_warning("initialize_pair" " but no " "set_color_pair" ); if ((((tp-> Strings[301]) != (char *)0) && ((tp -> Strings[301]) != (char *)(-1))) && !(((tp-> Strings [300]) != (char *)0) && ((tp-> Strings[300]) != (char *)(-1)))) _nc_warning("set_color_pair" " but no " "initialize_pair" ); }; |
1251 | |
1252 | if (VALID_STRING(set_foreground)((tp-> Strings[302]) != (char *)(-1) && (tp-> Strings [302]) != (char *)0) |
1253 | && VALID_STRING(set_a_foreground)((tp-> Strings[359]) != (char *)(-1) && (tp-> Strings [359]) != (char *)0)) { |
1254 | if (!_nc_capcmp(set_foregroundtp-> Strings[302], set_a_foregroundtp-> Strings[359])) { |
1255 | _nc_warning("expected setf/setaf to be different"); |
1256 | } else if (same_color(set_foregroundtp-> Strings[302], set_a_foregroundtp-> Strings[359], max_colorstp-> Numbers[13])) { |
1257 | _nc_warning("setf/setaf are equivalent"); |
1258 | } |
1259 | } |
1260 | |
1261 | if (VALID_STRING(set_background)((tp-> Strings[303]) != (char *)(-1) && (tp-> Strings [303]) != (char *)0) |
1262 | && VALID_STRING(set_a_background)((tp-> Strings[360]) != (char *)(-1) && (tp-> Strings [360]) != (char *)0)) { |
1263 | if (!_nc_capcmp(set_backgroundtp-> Strings[303], set_a_backgroundtp-> Strings[360])) { |
1264 | _nc_warning("expected setb/setab to be different"); |
1265 | } else if (same_color(set_backgroundtp-> Strings[303], set_a_backgroundtp-> Strings[360], max_colorstp-> Numbers[13])) { |
1266 | _nc_warning("setb/setab are equivalent"); |
1267 | } |
1268 | } |
1269 | |
1270 | /* see: has_colors() */ |
1271 | if (VALID_NUMERIC(max_colors)((tp-> Numbers[13]) >= 0) && VALID_NUMERIC(max_pairs)((tp-> Numbers[14]) >= 0) |
1272 | && ((VALID_STRING(set_foreground)((tp-> Strings[302]) != (char *)(-1) && (tp-> Strings [302]) != (char *)0) |
1273 | && VALID_STRING(set_background)((tp-> Strings[303]) != (char *)(-1) && (tp-> Strings [303]) != (char *)0)) |
1274 | || (VALID_STRING(set_a_foreground)((tp-> Strings[359]) != (char *)(-1) && (tp-> Strings [359]) != (char *)0) |
1275 | && VALID_STRING(set_a_background)((tp-> Strings[360]) != (char *)(-1) && (tp-> Strings [360]) != (char *)0)) |
1276 | || set_color_pairtp-> Strings[301])) { |
1277 | if (!VALID_STRING(orig_pair)((tp-> Strings[297]) != (char *)(-1) && (tp-> Strings [297]) != (char *)0) && !VALID_STRING(orig_colors)((tp-> Strings[298]) != (char *)(-1) && (tp-> Strings [298]) != (char *)0)) |
1278 | _nc_warning("expected either op/oc string for resetting colors"); |
1279 | } |
1280 | if (can_changetp-> Booleans[27]) { |
1281 | if (!VALID_STRING(initialize_pair)((tp-> Strings[300]) != (char *)(-1) && (tp-> Strings [300]) != (char *)0) && |
1282 | !VALID_STRING(initialize_color)((tp-> Strings[299]) != (char *)(-1) && (tp-> Strings [299]) != (char *)0)) { |
1283 | _nc_warning("expected initc or initp because ccc is given"); |
1284 | } |
1285 | } else { |
1286 | if (VALID_STRING(initialize_pair)((tp-> Strings[300]) != (char *)(-1) && (tp-> Strings [300]) != (char *)0) || |
1287 | VALID_STRING(initialize_color)((tp-> Strings[299]) != (char *)(-1) && (tp-> Strings [299]) != (char *)0)) { |
1288 | _nc_warning("expected ccc because initc is given"); |
1289 | } |
1290 | } |
1291 | value = tigetstr("RGB"); |
1292 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0)) { |
1293 | int r, g, b; |
1294 | char bad; |
1295 | int code = sscanf(value, "%d/%d/%d%c", &r, &g, &b, &bad); |
1296 | if (code != 3 || r <= 0 || g <= 0 || b <= 0) { |
1297 | _nc_warning("unexpected value for RGB capability: %s", value); |
1298 | } |
1299 | } |
1300 | } |
1301 | |
1302 | static int |
1303 | csi_length(const char *value) |
1304 | { |
1305 | int result = 0; |
1306 | |
1307 | if (value[0] == '\033' && value[1] == '[') { |
1308 | result = 2; |
1309 | } else if (UChar(value[0])((unsigned char)(value[0])) == 0x9a) { |
1310 | result = 1; |
1311 | } |
1312 | return result; |
1313 | } |
1314 | |
1315 | static char |
1316 | keypad_final(const char *string) |
1317 | { |
1318 | char result = '\0'; |
1319 | |
1320 | if (VALID_STRING(string)((string) != (char *)(-1) && (string) != (char *)0) |
1321 | && *string++ == '\033' |
1322 | && *string++ == 'O' |
1323 | && strlen(string) == 1) { |
1324 | result = *string; |
1325 | } |
1326 | |
1327 | return result; |
1328 | } |
1329 | |
1330 | static long |
1331 | keypad_index(const char *string) |
1332 | { |
1333 | int ch; |
1334 | long result = -1; |
1335 | |
1336 | if ((ch = keypad_final(string)) != '\0') { |
1337 | const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */ |
1338 | char *test = (strchr) (list, ch); |
1339 | if (test != 0) |
1340 | result = (long) (test - list); |
1341 | } |
1342 | return result; |
1343 | } |
1344 | |
1345 | /* |
1346 | * list[] is down, up, left, right |
1347 | * "left" may be ^H rather than \E[D |
1348 | * "down" may be ^J rather than \E[B |
1349 | * But up/right are generally consistently escape sequences for ANSI terminals. |
1350 | */ |
1351 | static void |
1352 | check_ansi_cursor(char *list[4]) |
1353 | { |
1354 | int j, k; |
1355 | bool_Bool skip[4]; |
1356 | bool_Bool repeated = FALSE0; |
1357 | |
1358 | for (j = 0; j < 4; ++j) { |
1359 | skip[j] = FALSE0; |
1360 | for (k = 0; k < j; ++k) { |
1361 | if (!strcmp(list[j], list[k])) { |
1362 | char *value = _nc_tic_expand(list[k], TRUE1, 0); |
1363 | _nc_warning("repeated cursor control %s", value); |
1364 | repeated = TRUE1; |
1365 | } |
1366 | } |
1367 | } |
1368 | if (!repeated) { |
1369 | char *up = list[1]; |
1370 | size_t prefix = (size_t) csi_length(up); |
1371 | size_t suffix; |
1372 | |
1373 | if (prefix) { |
1374 | suffix = prefix; |
1375 | while (up[suffix] && isdigit(UChar(up[suffix])((unsigned char)(up[suffix])))) |
1376 | ++suffix; |
1377 | } |
1378 | if (prefix && up[suffix] == 'A') { |
1379 | skip[1] = TRUE1; |
1380 | if (!strcmp(list[0], "\n")) |
1381 | skip[0] = TRUE1; |
1382 | if (!strcmp(list[2], "\b")) |
1383 | skip[2] = TRUE1; |
1384 | |
1385 | for (j = 0; j < 4; ++j) { |
1386 | int want; |
1387 | |
1388 | if (skip[j] || strlen(list[j]) == 1) |
1389 | continue; |
1390 | if (memcmp(list[j], up, prefix)) { |
1391 | char *value = _nc_tic_expand(list[j], TRUE1, 0); |
1392 | _nc_warning("inconsistent prefix for %s", value); |
1393 | continue; |
1394 | } |
1395 | if (strlen(list[j]) < suffix) { |
1396 | char *value = _nc_tic_expand(list[j], TRUE1, 0); |
1397 | _nc_warning("inconsistent length for %s, expected %d", |
1398 | value, (int) suffix + 1); |
1399 | continue; |
1400 | } |
1401 | want = "BADC"[j]; |
1402 | if (list[j][suffix] != want) { |
1403 | char *value = _nc_tic_expand(list[j], TRUE1, 0); |
1404 | _nc_warning("inconsistent suffix for %s, expected %c, have %c", |
1405 | value, want, list[j][suffix]); |
1406 | } |
1407 | } |
1408 | } |
1409 | } |
1410 | } |
1411 | |
1412 | #define EXPECTED(name)if (!(((name) != (char *)0) && ((name) != (char *)(-1 )))) _nc_warning("expected " "name") if (!PRESENT(name)(((name) != (char *)0) && ((name) != (char *)(-1)))) _nc_warning("expected " #name) |
1413 | #define UNEXPECTED(name)if ((((name) != (char *)0) && ((name) != (char *)(-1) ))) _nc_warning("unexpected " "name" ", for %s", why) if (PRESENT(name)(((name) != (char *)0) && ((name) != (char *)(-1)))) _nc_warning("unexpected " #name ", for %s", why) |
1414 | |
1415 | static void |
1416 | check_noaddress(TERMTYPE2 *tp, const char *why) |
1417 | { |
1418 | UNEXPECTED(column_address)if ((((tp-> Strings[8]) != (char *)0) && ((tp-> Strings[8]) != (char *)(-1)))) _nc_warning("unexpected " "column_address" ", for %s", why); |
1419 | UNEXPECTED(cursor_address)if ((((tp-> Strings[10]) != (char *)0) && ((tp-> Strings[10]) != (char *)(-1)))) _nc_warning("unexpected " "cursor_address" ", for %s", why); |
1420 | UNEXPECTED(cursor_home)if ((((tp-> Strings[12]) != (char *)0) && ((tp-> Strings[12]) != (char *)(-1)))) _nc_warning("unexpected " "cursor_home" ", for %s", why); |
1421 | UNEXPECTED(cursor_mem_address)if ((((tp-> Strings[15]) != (char *)0) && ((tp-> Strings[15]) != (char *)(-1)))) _nc_warning("unexpected " "cursor_mem_address" ", for %s", why); |
1422 | UNEXPECTED(cursor_to_ll)if ((((tp-> Strings[18]) != (char *)0) && ((tp-> Strings[18]) != (char *)(-1)))) _nc_warning("unexpected " "cursor_to_ll" ", for %s", why); |
1423 | UNEXPECTED(row_address)if ((((tp-> Strings[127]) != (char *)0) && ((tp-> Strings[127]) != (char *)(-1)))) _nc_warning("unexpected " "row_address" ", for %s", why); |
1424 | UNEXPECTED(row_address)if ((((tp-> Strings[127]) != (char *)0) && ((tp-> Strings[127]) != (char *)(-1)))) _nc_warning("unexpected " "row_address" ", for %s", why); |
1425 | } |
1426 | |
1427 | static void |
1428 | check_cursor(TERMTYPE2 *tp) |
1429 | { |
1430 | int count; |
1431 | char *list[4]; |
1432 | |
1433 | if (hard_copytp-> Booleans[7]) { |
1434 | check_noaddress(tp, "hard_copy"); |
1435 | } else if (generic_typetp-> Booleans[6]) { |
1436 | check_noaddress(tp, "generic_type"); |
1437 | } else if (strchr(tp->term_names, '+') == NULL((void *)0)) { |
1438 | int y = 0; |
1439 | int x = 0; |
1440 | if (PRESENT(column_address)(((tp-> Strings[8]) != (char *)0) && ((tp-> Strings [8]) != (char *)(-1)))) |
1441 | ++y; |
1442 | if (PRESENT(cursor_address)(((tp-> Strings[10]) != (char *)0) && ((tp-> Strings [10]) != (char *)(-1)))) |
1443 | y = x = 10; |
1444 | if (PRESENT(cursor_home)(((tp-> Strings[12]) != (char *)0) && ((tp-> Strings [12]) != (char *)(-1)))) |
1445 | ++y, ++x; |
1446 | if (PRESENT(cursor_mem_address)(((tp-> Strings[15]) != (char *)0) && ((tp-> Strings [15]) != (char *)(-1)))) |
1447 | y = x = 10; |
1448 | if (PRESENT(cursor_to_ll)(((tp-> Strings[18]) != (char *)0) && ((tp-> Strings [18]) != (char *)(-1)))) |
1449 | ++y, ++x; |
1450 | if (PRESENT(row_address)(((tp-> Strings[127]) != (char *)0) && ((tp-> Strings [127]) != (char *)(-1)))) |
1451 | ++x; |
1452 | if (PRESENT(cursor_down)(((tp-> Strings[11]) != (char *)0) && ((tp-> Strings [11]) != (char *)(-1)))) |
1453 | ++y; |
1454 | if (PRESENT(cursor_up)(((tp-> Strings[19]) != (char *)0) && ((tp-> Strings [19]) != (char *)(-1)))) |
1455 | ++y; |
1456 | if (PRESENT(cursor_left)(((tp-> Strings[14]) != (char *)0) && ((tp-> Strings [14]) != (char *)(-1)))) |
1457 | ++x; |
1458 | if (PRESENT(cursor_right)(((tp-> Strings[17]) != (char *)0) && ((tp-> Strings [17]) != (char *)(-1)))) |
1459 | ++x; |
1460 | if (x < 2 && y < 2) { |
1461 | _nc_warning("terminal lacks cursor addressing"); |
1462 | } else { |
1463 | if (x < 2) |
1464 | _nc_warning("terminal lacks cursor column-addressing"); |
1465 | if (y < 2) |
1466 | _nc_warning("terminal lacks cursor row-addressing"); |
1467 | } |
1468 | } |
1469 | |
1470 | /* it is rare to have an insert-line feature without a matching delete */ |
1471 | ANDMISSING(parm_insert_line, insert_line){ if ((((tp-> Strings[110]) != (char *)0) && ((tp-> Strings[110]) != (char *)(-1))) && !(((tp-> Strings [53]) != (char *)0) && ((tp-> Strings[53]) != (char *)(-1)))) _nc_warning("parm_insert_line" " but no " "insert_line" ); }; |
1472 | ANDMISSING(parm_delete_line, delete_line){ if ((((tp-> Strings[106]) != (char *)0) && ((tp-> Strings[106]) != (char *)(-1))) && !(((tp-> Strings [22]) != (char *)0) && ((tp-> Strings[22]) != (char *)(-1)))) _nc_warning("parm_delete_line" " but no " "delete_line" ); }; |
1473 | ANDMISSING(parm_insert_line, parm_delete_line){ if ((((tp-> Strings[110]) != (char *)0) && ((tp-> Strings[110]) != (char *)(-1))) && !(((tp-> Strings [106]) != (char *)0) && ((tp-> Strings[106]) != (char *)(-1)))) _nc_warning("parm_insert_line" " but no " "parm_delete_line" ); }; |
1474 | |
1475 | /* if we have a parameterized form, then the non-parameterized is easy */ |
1476 | ANDMISSING(parm_down_cursor, cursor_down){ if ((((tp-> Strings[107]) != (char *)0) && ((tp-> Strings[107]) != (char *)(-1))) && !(((tp-> Strings [11]) != (char *)0) && ((tp-> Strings[11]) != (char *)(-1)))) _nc_warning("parm_down_cursor" " but no " "cursor_down" ); }; |
1477 | ANDMISSING(parm_up_cursor, cursor_up){ if ((((tp-> Strings[114]) != (char *)0) && ((tp-> Strings[114]) != (char *)(-1))) && !(((tp-> Strings [19]) != (char *)0) && ((tp-> Strings[19]) != (char *)(-1)))) _nc_warning("parm_up_cursor" " but no " "cursor_up" ); }; |
1478 | ANDMISSING(parm_left_cursor, cursor_left){ if ((((tp-> Strings[111]) != (char *)0) && ((tp-> Strings[111]) != (char *)(-1))) && !(((tp-> Strings [14]) != (char *)0) && ((tp-> Strings[14]) != (char *)(-1)))) _nc_warning("parm_left_cursor" " but no " "cursor_left" ); }; |
1479 | ANDMISSING(parm_right_cursor, cursor_right){ if ((((tp-> Strings[112]) != (char *)0) && ((tp-> Strings[112]) != (char *)(-1))) && !(((tp-> Strings [17]) != (char *)0) && ((tp-> Strings[17]) != (char *)(-1)))) _nc_warning("parm_right_cursor" " but no " "cursor_right" ); }; |
1480 | |
1481 | /* Given any of a set of cursor movement, the whole set should be present. |
1482 | * Technically this is not true (we could use cursor_address to fill in |
1483 | * unsupported controls), but it is likely. |
1484 | */ |
1485 | count = 0; |
1486 | if (PRESENT(parm_down_cursor)(((tp-> Strings[107]) != (char *)0) && ((tp-> Strings [107]) != (char *)(-1)))) { |
1487 | list[count++] = parm_down_cursortp-> Strings[107]; |
1488 | } |
1489 | if (PRESENT(parm_up_cursor)(((tp-> Strings[114]) != (char *)0) && ((tp-> Strings [114]) != (char *)(-1)))) { |
1490 | list[count++] = parm_up_cursortp-> Strings[114]; |
1491 | } |
1492 | if (PRESENT(parm_left_cursor)(((tp-> Strings[111]) != (char *)0) && ((tp-> Strings [111]) != (char *)(-1)))) { |
1493 | list[count++] = parm_left_cursortp-> Strings[111]; |
1494 | } |
1495 | if (PRESENT(parm_right_cursor)(((tp-> Strings[112]) != (char *)0) && ((tp-> Strings [112]) != (char *)(-1)))) { |
1496 | list[count++] = parm_right_cursortp-> Strings[112]; |
1497 | } |
1498 | if (count == 4) { |
1499 | check_ansi_cursor(list); |
1500 | } else if (count != 0) { |
1501 | EXPECTED(parm_down_cursor)if (!(((tp-> Strings[107]) != (char *)0) && ((tp-> Strings[107]) != (char *)(-1)))) _nc_warning("expected " "parm_down_cursor" ); |
1502 | EXPECTED(parm_up_cursor)if (!(((tp-> Strings[114]) != (char *)0) && ((tp-> Strings[114]) != (char *)(-1)))) _nc_warning("expected " "parm_up_cursor" ); |
1503 | EXPECTED(parm_left_cursor)if (!(((tp-> Strings[111]) != (char *)0) && ((tp-> Strings[111]) != (char *)(-1)))) _nc_warning("expected " "parm_left_cursor" ); |
1504 | EXPECTED(parm_right_cursor)if (!(((tp-> Strings[112]) != (char *)0) && ((tp-> Strings[112]) != (char *)(-1)))) _nc_warning("expected " "parm_right_cursor" ); |
1505 | } |
1506 | |
1507 | count = 0; |
1508 | if (PRESENT(cursor_down)(((tp-> Strings[11]) != (char *)0) && ((tp-> Strings [11]) != (char *)(-1)))) { |
1509 | list[count++] = cursor_downtp-> Strings[11]; |
1510 | } |
1511 | if (PRESENT(cursor_up)(((tp-> Strings[19]) != (char *)0) && ((tp-> Strings [19]) != (char *)(-1)))) { |
1512 | list[count++] = cursor_uptp-> Strings[19]; |
1513 | } |
1514 | if (PRESENT(cursor_left)(((tp-> Strings[14]) != (char *)0) && ((tp-> Strings [14]) != (char *)(-1)))) { |
1515 | list[count++] = cursor_lefttp-> Strings[14]; |
1516 | } |
1517 | if (PRESENT(cursor_right)(((tp-> Strings[17]) != (char *)0) && ((tp-> Strings [17]) != (char *)(-1)))) { |
1518 | list[count++] = cursor_righttp-> Strings[17]; |
1519 | } |
1520 | if (count == 4) { |
1521 | check_ansi_cursor(list); |
1522 | } else if (count != 0) { |
1523 | count = 0; |
1524 | if (PRESENT(cursor_down)(((tp-> Strings[11]) != (char *)0) && ((tp-> Strings [11]) != (char *)(-1))) && strcmp(cursor_downtp-> Strings[11], "\n")) |
1525 | ++count; |
1526 | if (PRESENT(cursor_left)(((tp-> Strings[14]) != (char *)0) && ((tp-> Strings [14]) != (char *)(-1))) && strcmp(cursor_lefttp-> Strings[14], "\b")) |
1527 | ++count; |
1528 | if (PRESENT(cursor_up)(((tp-> Strings[19]) != (char *)0) && ((tp-> Strings [19]) != (char *)(-1))) && strlen(cursor_uptp-> Strings[19]) > 1) |
1529 | ++count; |
1530 | if (PRESENT(cursor_right)(((tp-> Strings[17]) != (char *)0) && ((tp-> Strings [17]) != (char *)(-1))) && strlen(cursor_righttp-> Strings[17]) > 1) |
1531 | ++count; |
1532 | if (count) { |
1533 | EXPECTED(cursor_down)if (!(((tp-> Strings[11]) != (char *)0) && ((tp-> Strings[11]) != (char *)(-1)))) _nc_warning("expected " "cursor_down" ); |
1534 | EXPECTED(cursor_up)if (!(((tp-> Strings[19]) != (char *)0) && ((tp-> Strings[19]) != (char *)(-1)))) _nc_warning("expected " "cursor_up" ); |
1535 | EXPECTED(cursor_left)if (!(((tp-> Strings[14]) != (char *)0) && ((tp-> Strings[14]) != (char *)(-1)))) _nc_warning("expected " "cursor_left" ); |
1536 | EXPECTED(cursor_right)if (!(((tp-> Strings[17]) != (char *)0) && ((tp-> Strings[17]) != (char *)(-1)))) _nc_warning("expected " "cursor_right" ); |
1537 | } |
1538 | } |
1539 | } |
1540 | |
1541 | #define MAX_KP5 5 |
1542 | /* |
1543 | * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad |
1544 | * is mapped inconsistently. |
1545 | */ |
1546 | static void |
1547 | check_keypad(TERMTYPE2 *tp) |
1548 | { |
1549 | char show[80]; |
1550 | |
1551 | if (VALID_STRING(key_a1)((tp-> Strings[139]) != (char *)(-1) && (tp-> Strings [139]) != (char *)0) && |
1552 | VALID_STRING(key_a3)((tp-> Strings[140]) != (char *)(-1) && (tp-> Strings [140]) != (char *)0) && |
1553 | VALID_STRING(key_b2)((tp-> Strings[141]) != (char *)(-1) && (tp-> Strings [141]) != (char *)0) && |
1554 | VALID_STRING(key_c1)((tp-> Strings[142]) != (char *)(-1) && (tp-> Strings [142]) != (char *)0) && |
1555 | VALID_STRING(key_c3)((tp-> Strings[143]) != (char *)(-1) && (tp-> Strings [143]) != (char *)0)) { |
1556 | char final[MAX_KP5 + 1]; |
1557 | long list[MAX_KP5]; |
1558 | int increase = 0; |
1559 | int j; |
1560 | |
1561 | final[0] = keypad_final(key_a1tp-> Strings[139]); |
1562 | final[1] = keypad_final(key_a3tp-> Strings[140]); |
1563 | final[2] = keypad_final(key_b2tp-> Strings[141]); |
1564 | final[3] = keypad_final(key_c1tp-> Strings[142]); |
1565 | final[4] = keypad_final(key_c3tp-> Strings[143]); |
1566 | final[5] = '\0'; |
1567 | |
1568 | /* special case: legacy coding using 1,2,3,0,. on the bottom */ |
1569 | assert(strlen(final) <= MAX_KP)((strlen(final) <= 5) ? (void)0 : __assert2("/usr/src/usr.bin/tic/tic.c" , 1569, __func__, "strlen(final) <= MAX_KP")); |
1570 | if (!strcmp(final, "qsrpn")) |
1571 | return; |
1572 | |
1573 | list[0] = keypad_index(key_a1tp-> Strings[139]); |
1574 | list[1] = keypad_index(key_a3tp-> Strings[140]); |
1575 | list[2] = keypad_index(key_b2tp-> Strings[141]); |
1576 | list[3] = keypad_index(key_c1tp-> Strings[142]); |
1577 | list[4] = keypad_index(key_c3tp-> Strings[143]); |
1578 | |
1579 | /* check that they're all vt100 keys */ |
1580 | for (j = 0; j < MAX_KP5; ++j) { |
1581 | if (list[j] < 0) { |
1582 | return; |
1583 | } |
1584 | } |
1585 | |
1586 | /* check if they're all in increasing order */ |
1587 | for (j = 1; j < MAX_KP5; ++j) { |
1588 | if (list[j] > list[j - 1]) { |
1589 | ++increase; |
1590 | } |
1591 | } |
1592 | |
1593 | if (increase != (MAX_KP5 - 1)) { |
1594 | long last; |
1595 | |
1596 | show[0] = '\0'; |
1597 | |
1598 | for (j = 0, last = -1; j < MAX_KP5; ++j) { |
1599 | int k; |
1600 | int kk; |
1601 | long test; |
1602 | |
1603 | for (k = 0, kk = -1, test = 100; k < 5; ++k) { |
1604 | if (list[k] > last && |
1605 | list[k] < test) { |
1606 | test = list[k]; |
1607 | kk = k; |
1608 | } |
1609 | } |
1610 | last = test; |
1611 | assert(strlen(show) < (MAX_KP * 4))((strlen(show) < (5 * 4)) ? (void)0 : __assert2("/usr/src/usr.bin/tic/tic.c" , 1611, __func__, "strlen(show) < (MAX_KP * 4)")); |
1612 | switch (kk) { |
1613 | case 0: |
1614 | _nc_STRCAT(show, " ka1", sizeof(show))(void) strlcat((show),(" ka1"),(size_t)(sizeof(show))); |
1615 | break; |
1616 | case 1: |
1617 | _nc_STRCAT(show, " ka3", sizeof(show))(void) strlcat((show),(" ka3"),(size_t)(sizeof(show))); |
1618 | break; |
1619 | case 2: |
1620 | _nc_STRCAT(show, " kb2", sizeof(show))(void) strlcat((show),(" kb2"),(size_t)(sizeof(show))); |
1621 | break; |
1622 | case 3: |
1623 | _nc_STRCAT(show, " kc1", sizeof(show))(void) strlcat((show),(" kc1"),(size_t)(sizeof(show))); |
1624 | break; |
1625 | case 4: |
1626 | _nc_STRCAT(show, " kc3", sizeof(show))(void) strlcat((show),(" kc3"),(size_t)(sizeof(show))); |
1627 | break; |
1628 | } |
1629 | } |
1630 | |
1631 | _nc_warning("vt100 keypad order inconsistent: %s", show); |
1632 | } |
1633 | |
1634 | } else if (VALID_STRING(key_a1)((tp-> Strings[139]) != (char *)(-1) && (tp-> Strings [139]) != (char *)0) || |
1635 | VALID_STRING(key_a3)((tp-> Strings[140]) != (char *)(-1) && (tp-> Strings [140]) != (char *)0) || |
1636 | VALID_STRING(key_b2)((tp-> Strings[141]) != (char *)(-1) && (tp-> Strings [141]) != (char *)0) || |
1637 | VALID_STRING(key_c1)((tp-> Strings[142]) != (char *)(-1) && (tp-> Strings [142]) != (char *)0) || |
1638 | VALID_STRING(key_c3)((tp-> Strings[143]) != (char *)(-1) && (tp-> Strings [143]) != (char *)0)) { |
1639 | show[0] = '\0'; |
1640 | if (keypad_index(key_a1tp-> Strings[139]) >= 0) |
1641 | _nc_STRCAT(show, " ka1", sizeof(show))(void) strlcat((show),(" ka1"),(size_t)(sizeof(show))); |
1642 | if (keypad_index(key_a3tp-> Strings[140]) >= 0) |
1643 | _nc_STRCAT(show, " ka3", sizeof(show))(void) strlcat((show),(" ka3"),(size_t)(sizeof(show))); |
1644 | if (keypad_index(key_b2tp-> Strings[141]) >= 0) |
1645 | _nc_STRCAT(show, " kb2", sizeof(show))(void) strlcat((show),(" kb2"),(size_t)(sizeof(show))); |
1646 | if (keypad_index(key_c1tp-> Strings[142]) >= 0) |
1647 | _nc_STRCAT(show, " kc1", sizeof(show))(void) strlcat((show),(" kc1"),(size_t)(sizeof(show))); |
1648 | if (keypad_index(key_c3tp-> Strings[143]) >= 0) |
1649 | _nc_STRCAT(show, " kc3", sizeof(show))(void) strlcat((show),(" kc3"),(size_t)(sizeof(show))); |
1650 | if (*show != '\0') |
1651 | _nc_warning("vt100 keypad map incomplete:%s", show); |
1652 | } |
1653 | |
1654 | /* |
1655 | * These warnings are useful for consistency checks - it is possible that |
1656 | * there are real terminals with mismatches in these |
1657 | */ |
1658 | ANDMISSING(key_ic, key_dc){ if ((((tp-> Strings[77]) != (char *)0) && ((tp-> Strings[77]) != (char *)(-1))) && !(((tp-> Strings [59]) != (char *)0) && ((tp-> Strings[59]) != (char *)(-1)))) _nc_warning("key_ic" " but no " "key_dc"); }; |
1659 | } |
1660 | |
1661 | static void |
1662 | check_printer(TERMTYPE2 *tp) |
1663 | { |
1664 | (void) tp; |
1665 | #if defined(enter_doublewide_modetp-> Strings[309]) && defined(exit_doublewide_modetp-> Strings[320]) |
1666 | PAIRED(enter_doublewide_mode, exit_doublewide_mode){ if ((((tp-> Strings[320]) != (char *)0) && ((tp-> Strings[320]) != (char *)(-1))) && !(((tp-> Strings [309]) != (char *)0) && ((tp-> Strings[309]) != (char *)(-1)))) _nc_warning("exit_doublewide_mode" " but no " "enter_doublewide_mode" ); if ((((tp-> Strings[309]) != (char *)0) && ((tp -> Strings[309]) != (char *)(-1))) && !(((tp-> Strings [320]) != (char *)0) && ((tp-> Strings[320]) != (char *)(-1)))) _nc_warning("enter_doublewide_mode" " but no " "exit_doublewide_mode" ); }; |
1667 | #endif |
1668 | #if defined(enter_italics_modetp-> Strings[311]) && defined(exit_italics_modetp-> Strings[321]) |
1669 | PAIRED(enter_italics_mode, exit_italics_mode){ if ((((tp-> Strings[321]) != (char *)0) && ((tp-> Strings[321]) != (char *)(-1))) && !(((tp-> Strings [311]) != (char *)0) && ((tp-> Strings[311]) != (char *)(-1)))) _nc_warning("exit_italics_mode" " but no " "enter_italics_mode" ); if ((((tp-> Strings[311]) != (char *)0) && ((tp -> Strings[311]) != (char *)(-1))) && !(((tp-> Strings [321]) != (char *)0) && ((tp-> Strings[321]) != (char *)(-1)))) _nc_warning("enter_italics_mode" " but no " "exit_italics_mode" ); }; |
1670 | #endif |
1671 | #if defined(enter_leftward_modetp-> Strings[312]) && defined(exit_leftward_modetp-> Strings[322]) |
1672 | PAIRED(enter_leftward_mode, exit_leftward_mode){ if ((((tp-> Strings[322]) != (char *)0) && ((tp-> Strings[322]) != (char *)(-1))) && !(((tp-> Strings [312]) != (char *)0) && ((tp-> Strings[312]) != (char *)(-1)))) _nc_warning("exit_leftward_mode" " but no " "enter_leftward_mode" ); if ((((tp-> Strings[312]) != (char *)0) && ((tp -> Strings[312]) != (char *)(-1))) && !(((tp-> Strings [322]) != (char *)0) && ((tp-> Strings[322]) != (char *)(-1)))) _nc_warning("enter_leftward_mode" " but no " "exit_leftward_mode" ); }; |
1673 | #endif |
1674 | #if defined(enter_micro_modetp-> Strings[313]) && defined(exit_micro_modetp-> Strings[323]) |
1675 | PAIRED(enter_micro_mode, exit_micro_mode){ if ((((tp-> Strings[323]) != (char *)0) && ((tp-> Strings[323]) != (char *)(-1))) && !(((tp-> Strings [313]) != (char *)0) && ((tp-> Strings[313]) != (char *)(-1)))) _nc_warning("exit_micro_mode" " but no " "enter_micro_mode" ); if ((((tp-> Strings[313]) != (char *)0) && ((tp -> Strings[313]) != (char *)(-1))) && !(((tp-> Strings [323]) != (char *)0) && ((tp-> Strings[323]) != (char *)(-1)))) _nc_warning("enter_micro_mode" " but no " "exit_micro_mode" ); }; |
1676 | #endif |
1677 | #if defined(enter_shadow_modetp-> Strings[316]) && defined(exit_shadow_modetp-> Strings[324]) |
1678 | PAIRED(enter_shadow_mode, exit_shadow_mode){ if ((((tp-> Strings[324]) != (char *)0) && ((tp-> Strings[324]) != (char *)(-1))) && !(((tp-> Strings [316]) != (char *)0) && ((tp-> Strings[316]) != (char *)(-1)))) _nc_warning("exit_shadow_mode" " but no " "enter_shadow_mode" ); if ((((tp-> Strings[316]) != (char *)0) && ((tp -> Strings[316]) != (char *)(-1))) && !(((tp-> Strings [324]) != (char *)0) && ((tp-> Strings[324]) != (char *)(-1)))) _nc_warning("enter_shadow_mode" " but no " "exit_shadow_mode" ); }; |
1679 | #endif |
1680 | #if defined(enter_subscript_modetp-> Strings[317]) && defined(exit_subscript_modetp-> Strings[325]) |
1681 | PAIRED(enter_subscript_mode, exit_subscript_mode){ if ((((tp-> Strings[325]) != (char *)0) && ((tp-> Strings[325]) != (char *)(-1))) && !(((tp-> Strings [317]) != (char *)0) && ((tp-> Strings[317]) != (char *)(-1)))) _nc_warning("exit_subscript_mode" " but no " "enter_subscript_mode" ); if ((((tp-> Strings[317]) != (char *)0) && ((tp -> Strings[317]) != (char *)(-1))) && !(((tp-> Strings [325]) != (char *)0) && ((tp-> Strings[325]) != (char *)(-1)))) _nc_warning("enter_subscript_mode" " but no " "exit_subscript_mode" ); }; |
1682 | #endif |
1683 | #if defined(enter_superscript_modetp-> Strings[318]) && defined(exit_superscript_modetp-> Strings[326]) |
1684 | PAIRED(enter_superscript_mode, exit_superscript_mode){ if ((((tp-> Strings[326]) != (char *)0) && ((tp-> Strings[326]) != (char *)(-1))) && !(((tp-> Strings [318]) != (char *)0) && ((tp-> Strings[318]) != (char *)(-1)))) _nc_warning("exit_superscript_mode" " but no " "enter_superscript_mode" ); if ((((tp-> Strings[318]) != (char *)0) && ((tp -> Strings[318]) != (char *)(-1))) && !(((tp-> Strings [326]) != (char *)0) && ((tp-> Strings[326]) != (char *)(-1)))) _nc_warning("enter_superscript_mode" " but no " "exit_superscript_mode" ); }; |
1685 | #endif |
1686 | #if defined(enter_upward_modetp-> Strings[319]) && defined(exit_upward_modetp-> Strings[327]) |
1687 | PAIRED(enter_upward_mode, exit_upward_mode){ if ((((tp-> Strings[327]) != (char *)0) && ((tp-> Strings[327]) != (char *)(-1))) && !(((tp-> Strings [319]) != (char *)0) && ((tp-> Strings[319]) != (char *)(-1)))) _nc_warning("exit_upward_mode" " but no " "enter_upward_mode" ); if ((((tp-> Strings[319]) != (char *)0) && ((tp -> Strings[319]) != (char *)(-1))) && !(((tp-> Strings [327]) != (char *)0) && ((tp-> Strings[327]) != (char *)(-1)))) _nc_warning("enter_upward_mode" " but no " "exit_upward_mode" ); }; |
1688 | #endif |
1689 | |
1690 | #if defined(start_char_set_deftp-> Strings[347]) && defined(stop_char_set_deftp-> Strings[349]) |
1691 | ANDMISSING(start_char_set_def, stop_char_set_def){ if ((((tp-> Strings[347]) != (char *)0) && ((tp-> Strings[347]) != (char *)(-1))) && !(((tp-> Strings [349]) != (char *)0) && ((tp-> Strings[349]) != (char *)(-1)))) _nc_warning("start_char_set_def" " but no " "stop_char_set_def" ); }; |
1692 | #endif |
1693 | |
1694 | /* |
1695 | * If we have a parameterized form, then the non-parameterized is easy. |
1696 | * note: parameterized/non-parameterized margin settings are unrelated. |
1697 | */ |
1698 | #if defined(parm_down_microtp-> Strings[335]) && defined(micro_downtp-> Strings[329]) |
1699 | ANDMISSING(parm_down_micro, micro_down){ if ((((tp-> Strings[335]) != (char *)0) && ((tp-> Strings[335]) != (char *)(-1))) && !(((tp-> Strings [329]) != (char *)0) && ((tp-> Strings[329]) != (char *)(-1)))) _nc_warning("parm_down_micro" " but no " "micro_down" ); }; |
1700 | #endif |
1701 | #if defined(parm_left_microtp-> Strings[336]) && defined(micro_lefttp-> Strings[330]) |
1702 | ANDMISSING(parm_left_micro, micro_left){ if ((((tp-> Strings[336]) != (char *)0) && ((tp-> Strings[336]) != (char *)(-1))) && !(((tp-> Strings [330]) != (char *)0) && ((tp-> Strings[330]) != (char *)(-1)))) _nc_warning("parm_left_micro" " but no " "micro_left" ); }; |
1703 | #endif |
1704 | #if defined(parm_right_microtp-> Strings[337]) && defined(micro_righttp-> Strings[331]) |
1705 | ANDMISSING(parm_right_micro, micro_right){ if ((((tp-> Strings[337]) != (char *)0) && ((tp-> Strings[337]) != (char *)(-1))) && !(((tp-> Strings [331]) != (char *)0) && ((tp-> Strings[331]) != (char *)(-1)))) _nc_warning("parm_right_micro" " but no " "micro_right" ); }; |
1706 | #endif |
1707 | #if defined(parm_up_microtp-> Strings[338]) && defined(micro_uptp-> Strings[333]) |
1708 | ANDMISSING(parm_up_micro, micro_up){ if ((((tp-> Strings[338]) != (char *)0) && ((tp-> Strings[338]) != (char *)(-1))) && !(((tp-> Strings [333]) != (char *)0) && ((tp-> Strings[333]) != (char *)(-1)))) _nc_warning("parm_up_micro" " but no " "micro_up") ; }; |
1709 | #endif |
1710 | } |
1711 | |
1712 | #if NCURSES_XNAMES1 |
1713 | static bool_Bool |
1714 | uses_SGR_39_49(const char *value) |
1715 | { |
1716 | return (strstr(value, "39;49") != 0 |
1717 | || strstr(value, "49;39") != 0); |
1718 | } |
1719 | |
1720 | /* |
1721 | * Check consistency of termcap extensions related to "screen". |
1722 | */ |
1723 | static void |
1724 | check_screen(TERMTYPE2 *tp) |
1725 | { |
1726 | if (_nc_user_definable) { |
1727 | int have_XT = tigetflag("XT"); |
1728 | int have_XM = tigetflag("XM"); |
1729 | int have_bce = back_color_erasetp-> Booleans[28]; |
1730 | bool_Bool have_kmouse = FALSE0; |
1731 | bool_Bool use_sgr_39_49 = FALSE0; |
1732 | const char *name_39_49 = "orig_pair or orig_colors"; |
1733 | char *name = _nc_first_name(tp->term_names); |
1734 | bool_Bool is_screen = !strncmp(name, "screen", 6); |
1735 | bool_Bool screen_base = (is_screen |
1736 | && strchr(name, '.') == NULL((void *)0)); |
1737 | |
1738 | if (!VALID_BOOLEAN(have_bce)((unsigned char)(have_bce) <= 1)) { |
1739 | have_bce = FALSE0; |
1740 | } |
1741 | if (!VALID_BOOLEAN(have_XM)((unsigned char)(have_XM) <= 1)) { |
1742 | have_XM = FALSE0; |
1743 | } |
1744 | if (!VALID_BOOLEAN(have_XT)((unsigned char)(have_XT) <= 1)) { |
1745 | have_XT = FALSE0; |
1746 | } |
1747 | if (VALID_STRING(key_mouse)((tp-> Strings[355]) != (char *)(-1) && (tp-> Strings [355]) != (char *)0)) { |
1748 | have_kmouse = !strcmp("\033[M", key_mousetp-> Strings[355]); |
1749 | } |
1750 | if (have_bce) { |
1751 | if (VALID_STRING(orig_pair)((tp-> Strings[297]) != (char *)(-1) && (tp-> Strings [297]) != (char *)0)) { |
1752 | name_39_49 = "orig_pair"; |
1753 | use_sgr_39_49 = uses_SGR_39_49(orig_pairtp-> Strings[297]); |
1754 | } |
1755 | if (!use_sgr_39_49 && VALID_STRING(orig_colors)((tp-> Strings[298]) != (char *)(-1) && (tp-> Strings [298]) != (char *)0)) { |
1756 | name_39_49 = "orig_colors"; |
1757 | use_sgr_39_49 = uses_SGR_39_49(orig_colorstp-> Strings[298]); |
1758 | } |
1759 | } |
1760 | |
1761 | if (have_XM && have_XT) { |
1762 | _nc_warning("screen's XT capability conflicts with XM"); |
1763 | } else if (have_XT && screen_base) { |
1764 | _nc_warning("screen's \"screen\" entries should not have XT set"); |
1765 | } else if (have_XT) { |
1766 | char *s; |
1767 | |
1768 | if (!have_kmouse && is_screen) { |
1769 | if (VALID_STRING(key_mouse)((tp-> Strings[355]) != (char *)(-1) && (tp-> Strings [355]) != (char *)0)) { |
1770 | _nc_warning("value of kmous inconsistent with screen's usage"); |
1771 | } else { |
1772 | _nc_warning("expected kmous capability with XT"); |
1773 | } |
1774 | } |
1775 | if (max_colorstp-> Numbers[13] > 0) { |
1776 | if (!have_bce) { |
1777 | _nc_warning("expected bce capability with XT"); |
1778 | } else if (!use_sgr_39_49) { |
1779 | _nc_warning("expected %s capability with XT " |
1780 | "to have 39/49 parameters", name_39_49); |
1781 | } |
1782 | } |
1783 | if (VALID_STRING(to_status_line)((tp-> Strings[135]) != (char *)(-1) && (tp-> Strings [135]) != (char *)0) |
1784 | && (s = strchr(to_status_linetp-> Strings[135], ';')) != NULL((void *)0) |
1785 | && *++s == '\0') |
1786 | _nc_warning("\"tsl\" capability is redundant, given XT"); |
1787 | } else { |
1788 | if (have_kmouse |
1789 | && !have_XM |
1790 | && !screen_base && strchr(name, '+') == NULL((void *)0)) { |
1791 | _nc_warning("expected XT to be set, given kmous"); |
1792 | } |
1793 | } |
1794 | } |
1795 | } |
1796 | #else |
1797 | #define check_screen(tp) /* nothing */ |
1798 | #endif |
1799 | |
1800 | /* |
1801 | * Returns the expected number of parameters for the given capability. |
1802 | */ |
1803 | static int |
1804 | expected_params(const char *name) |
1805 | { |
1806 | #define DATA(name,count) { { name }, count } |
1807 | /* *INDENT-OFF* */ |
1808 | static const struct { |
1809 | const char name[9]; |
1810 | int count; |
1811 | } table[] = { |
1812 | DATA( "S0", 1 ), /* 'screen' extension */ |
1813 | DATA( "birep", 2 ), |
1814 | DATA( "chr", 1 ), |
1815 | DATA( "colornm", 1 ), |
1816 | DATA( "cpi", 1 ), |
1817 | DATA( "csnm", 1 ), |
1818 | DATA( "csr", 2 ), |
1819 | DATA( "cub", 1 ), |
1820 | DATA( "cud", 1 ), |
1821 | DATA( "cuf", 1 ), |
1822 | DATA( "cup", 2 ), |
1823 | DATA( "cuu", 1 ), |
1824 | DATA( "cvr", 1 ), |
1825 | DATA( "cwin", 5 ), |
1826 | DATA( "dch", 1 ), |
1827 | DATA( "defc", 3 ), |
1828 | DATA( "dial", 1 ), |
1829 | DATA( "dispc", 1 ), |
1830 | DATA( "dl", 1 ), |
1831 | DATA( "ech", 1 ), |
1832 | DATA( "getm", 1 ), |
1833 | DATA( "hpa", 1 ), |
1834 | DATA( "ich", 1 ), |
1835 | DATA( "il", 1 ), |
1836 | DATA( "indn", 1 ), |
1837 | DATA( "initc", 4 ), |
1838 | DATA( "initp", 7 ), |
1839 | DATA( "lpi", 1 ), |
1840 | DATA( "mc5p", 1 ), |
1841 | DATA( "mrcup", 2 ), |
1842 | DATA( "mvpa", 1 ), |
1843 | DATA( "pfkey", 2 ), |
1844 | DATA( "pfloc", 2 ), |
1845 | DATA( "pfx", 2 ), |
1846 | DATA( "pfxl", 3 ), |
1847 | DATA( "pln", 2 ), |
1848 | DATA( "qdial", 1 ), |
1849 | DATA( "rcsd", 1 ), |
1850 | DATA( "rep", 2 ), |
1851 | DATA( "rin", 1 ), |
1852 | DATA( "sclk", 3 ), |
1853 | DATA( "scp", 1 ), |
1854 | DATA( "scs", 1 ), |
1855 | DATA( "scsd", 2 ), |
1856 | DATA( "setab", 1 ), |
1857 | DATA( "setaf", 1 ), |
1858 | DATA( "setb", 1 ), |
1859 | DATA( "setcolor", 1 ), |
1860 | DATA( "setf", 1 ), |
1861 | DATA( "sgr", 9 ), |
1862 | DATA( "sgr1", 6 ), |
1863 | DATA( "slength", 1 ), |
1864 | DATA( "slines", 1 ), |
1865 | DATA( "smgbp", 1 ), /* 2 if smgtp is not given */ |
1866 | DATA( "smglp", 1 ), |
1867 | DATA( "smglr", 2 ), |
1868 | DATA( "smgrp", 1 ), |
1869 | DATA( "smgtb", 2 ), |
1870 | DATA( "smgtp", 1 ), |
1871 | DATA( "tsl", 1 ), |
1872 | DATA( "u6", -1 ), |
1873 | DATA( "vpa", 1 ), |
1874 | DATA( "wind", 4 ), |
1875 | DATA( "wingo", 1 ), |
1876 | }; |
1877 | /* *INDENT-ON* */ |
1878 | #undef DATA |
1879 | |
1880 | unsigned n; |
1881 | int result = 0; /* function-keys, etc., use none */ |
1882 | |
1883 | for (n = 0; n < SIZEOF(table)(sizeof(table)/sizeof(table[0])); n++) { |
1884 | if (!strcmp(name, table[n].name)) { |
1885 | result = table[n].count; |
1886 | break; |
1887 | } |
1888 | } |
1889 | |
1890 | return result; |
1891 | } |
1892 | |
1893 | /* |
1894 | * Check for user-capabilities that happen to be used in ncurses' terminal |
1895 | * database. |
1896 | */ |
1897 | #if NCURSES_XNAMES1 |
1898 | static struct user_table_entry const * |
1899 | lookup_user_capability(const char *name) |
1900 | { |
1901 | struct user_table_entry const *result = 0; |
1902 | if (*name != 'k') { |
1903 | result = _nc_find_user_entry(name); |
1904 | } |
1905 | return result; |
1906 | } |
1907 | #endif |
1908 | |
1909 | /* |
1910 | * If a given name is likely to be a user-capability, return the number of |
1911 | * parameters it would be used with. If not, return -1. |
1912 | * |
1913 | * ncurses assumes that u6 could be used for getting the cursor-position, but |
1914 | * that is not implemented. Make a special case for that, to quiet needless |
1915 | * warnings. |
1916 | * |
1917 | * The other string-capability extensions (see terminfo.src) which could have |
1918 | * parameters such as "Ss", "%u", are not used by ncurses. But we check those |
1919 | * anyway, to validate the terminfo database. |
1920 | */ |
1921 | static int |
1922 | is_user_capability(const char *name) |
1923 | { |
1924 | int result = -1; |
1925 | if (name[0] == 'u' && |
1926 | (name[1] >= '0' && name[1] <= '9') && |
1927 | name[2] == '\0') { |
1928 | result = (name[1] == '6') ? 2 : 0; |
1929 | } |
1930 | #if NCURSES_XNAMES1 |
1931 | else if (using_extensions) { |
1932 | struct user_table_entry const *p = lookup_user_capability(name); |
1933 | if (p != 0) { |
1934 | result = (int) p->ute_argc; |
1935 | } |
1936 | } |
1937 | #endif |
1938 | return result; |
1939 | } |
1940 | |
1941 | static bool_Bool |
1942 | line_capability(const char *name) |
1943 | { |
1944 | bool_Bool result = FALSE0; |
1945 | static const char *table[] = |
1946 | { |
1947 | "csr", /* change_scroll_region */ |
1948 | "clear", /* clear_screen */ |
1949 | "ed", /* clr_eos */ |
1950 | "cwin", /* create_window */ |
1951 | "cup", /* cursor_address */ |
1952 | "cud1", /* cursor_down */ |
1953 | "home", /* cursor_home */ |
1954 | "mrcup", /* cursor_mem_address */ |
1955 | "ll", /* cursor_to_ll */ |
1956 | "cuu1", /* cursor_up */ |
1957 | "dl1", /* delete_line */ |
1958 | "hd", /* down_half_line */ |
1959 | "flash", /* flash_screen */ |
1960 | "ff", /* form_feed */ |
1961 | "il1", /* insert_line */ |
1962 | "nel", /* newline */ |
1963 | "dl", /* parm_delete_line */ |
1964 | "cud", /* parm_down_cursor */ |
1965 | "indn", /* parm_index */ |
1966 | "il", /* parm_insert_line */ |
1967 | "rin", /* parm_rindex */ |
1968 | "cuu", /* parm_up_cursor */ |
1969 | "mc0", /* print_screen */ |
1970 | "vpa", /* row_address */ |
1971 | "ind", /* scroll_forward */ |
1972 | "ri", /* scroll_reverse */ |
1973 | "hu", /* up_half_line */ |
1974 | }; |
1975 | size_t n; |
1976 | for (n = 0; n < SIZEOF(table)(sizeof(table)/sizeof(table[0])); ++n) { |
1977 | if (!strcmp(name, table[n])) { |
1978 | result = TRUE1; |
1979 | break; |
1980 | } |
1981 | } |
1982 | return result; |
1983 | } |
1984 | |
1985 | /* |
1986 | * Make a quick sanity check for the parameters which are used in the given |
1987 | * strings. If there are no "%p" tokens, then there should be no other "%" |
1988 | * markers. |
1989 | */ |
1990 | static void |
1991 | check_params(TERMTYPE2 *tp, const char *name, const char *value, int extended) |
1992 | { |
1993 | int expected = expected_params(name); |
1994 | int actual = 0; |
1995 | int n; |
1996 | bool_Bool params[1 + NUM_PARM9]; |
1997 | const char *s = value; |
1998 | |
1999 | #ifdef set_left_margin_parmtp-> Strings[342] |
2000 | if (!strcmp(name, "smgrp") |
2001 | && !VALID_STRING(set_left_margin_parm)((tp-> Strings[342]) != (char *)(-1) && (tp-> Strings [342]) != (char *)0)) |
2002 | expected = 2; |
2003 | #endif |
2004 | #ifdef set_right_margin_parmtp-> Strings[343] |
2005 | if (!strcmp(name, "smglp") |
2006 | && !VALID_STRING(set_right_margin_parm)((tp-> Strings[343]) != (char *)(-1) && (tp-> Strings [343]) != (char *)0)) |
2007 | expected = 2; |
2008 | #endif |
2009 | #ifdef set_top_margin_parmtp-> Strings[345] |
2010 | if (!strcmp(name, "smgbp") |
2011 | && !VALID_STRING(set_top_margin_parm)((tp-> Strings[345]) != (char *)(-1) && (tp-> Strings [345]) != (char *)0)) |
2012 | expected = 2; |
2013 | #endif |
2014 | #ifdef set_bottom_margin_parmtp-> Strings[341] |
2015 | if (!strcmp(name, "smgtp") |
2016 | && !VALID_STRING(set_bottom_margin_parm)((tp-> Strings[341]) != (char *)(-1) && (tp-> Strings [341]) != (char *)0)) |
2017 | expected = 2; |
2018 | #endif |
2019 | |
2020 | for (n = 0; n <= NUM_PARM9; n++) |
2021 | params[n] = FALSE0; |
2022 | |
2023 | while (*s != 0) { |
2024 | if (*s == '%') { |
2025 | if (*++s == '\0') { |
2026 | _nc_warning("expected character after %% in %s", name); |
2027 | break; |
2028 | } else if (*s == 'p') { |
2029 | if (*++s == '\0' || !isdigit((int) *s)) { |
2030 | _nc_warning("expected digit after %%p in %s", name); |
2031 | return; |
2032 | } else { |
2033 | n = (*s - '0'); |
2034 | if (n > actual) |
2035 | actual = n; |
2036 | params[n] = TRUE1; |
2037 | } |
2038 | } |
2039 | } |
2040 | s++; |
2041 | } |
2042 | |
2043 | #if NCURSES_XNAMES1 |
2044 | if (extended) { |
2045 | int check = is_user_capability(name); |
2046 | if (check != actual && (check >= 0 && actual >= 0)) { |
2047 | _nc_warning("extended %s capability has %d parameters, expected %d", |
2048 | name, actual, check); |
2049 | } else if (debug_level > 1) { |
2050 | _nc_warning("extended %s capability has %d parameters, as expected", |
2051 | name, actual); |
2052 | } |
2053 | expected = actual; |
2054 | } |
2055 | #else |
2056 | (void) extended; |
2057 | #endif |
2058 | |
2059 | if (params[0]) { |
2060 | _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name); |
2061 | } |
2062 | if (value == set_attributestp-> Strings[131] || expected < 0) { |
2063 | ; |
2064 | } else if (expected != actual) { |
2065 | _nc_warning("%s uses %d parameters, expected %d", name, |
2066 | actual, expected); |
2067 | for (n = 1; n < actual; n++) { |
2068 | if (!params[n]) |
2069 | _nc_warning("%s omits parameter %d", name, n); |
2070 | } |
2071 | } |
2072 | |
2073 | /* |
2074 | * Counting "%p" markers does not account for termcap expressions which |
2075 | * may not have been fully translated. Also, tparm does its own analysis. |
2076 | * Report differences here. |
2077 | */ |
2078 | _nc_reset_tparm(NULL((void *)0)); |
2079 | if (actual >= 0) { |
2080 | char *p_is_s[NUM_PARM9]; |
2081 | int popcount; |
2082 | int analyzed = _nc_tparm_analyze(NULL((void *)0), value, p_is_s, &popcount); |
2083 | if (analyzed < popcount) { |
2084 | analyzed = popcount; |
2085 | } |
2086 | if (actual != analyzed && expected != analyzed) { |
2087 | #if NCURSES_XNAMES1 |
2088 | int user_cap = is_user_capability(name); |
2089 | if ((user_cap == analyzed) && using_extensions) { |
2090 | ; /* ignore */ |
2091 | } else if (user_cap >= 0) { |
2092 | _nc_warning("tparm will use %d parameters for %s, expected %d", |
2093 | analyzed, name, user_cap); |
2094 | } else |
2095 | #endif |
2096 | { |
2097 | _nc_warning("tparm analyzed %d parameters for %s, expected %d", |
2098 | analyzed, name, actual); |
2099 | } |
2100 | } else if (expected > 0 |
2101 | && actual == expected |
2102 | && guess_tparm_type(expected, p_is_s) == Numbers) { |
2103 | int limit = 1; |
2104 | |
2105 | if (!strcmp(name, "setf") |
2106 | || !strcmp(name, "setb") |
2107 | || !strcmp(name, "setaf") |
2108 | || !strcmp(name, "setab")) { |
2109 | if ((limit = max_colorstp-> Numbers[13]) > 256) |
2110 | limit = 256; |
2111 | } else if (line_capability(name)) { |
2112 | limit = 24; |
2113 | } else if (is_user_capability(name) < 0) { |
2114 | limit = 80; |
2115 | } |
2116 | for (n = 0; n < limit; ++n) { |
2117 | _nc_reset_tparm(NULL((void *)0)); |
2118 | (void) TPARM_9(value, n, n, n, n, n, n, n, n, n)tparm(value,(intptr_t)(n),(intptr_t)(n),(intptr_t)(n),(intptr_t )(n),(intptr_t)(n),(intptr_t)(n),(intptr_t)(n),(intptr_t)(n), (intptr_t)(n)); |
2119 | if (_nc_tparm_err) { |
2120 | _nc_warning("problem%s in tparm(%s, %d, ...)", |
2121 | (_nc_tparm_err == 1) ? "" : "s", |
2122 | name, n); |
2123 | if (debug_level < 2) |
2124 | break; |
2125 | } |
2126 | } |
2127 | } |
2128 | } |
2129 | } |
2130 | |
2131 | /* |
2132 | * Check for DEC VT100 private mode for reverse video. |
2133 | */ |
2134 | static const char * |
2135 | skip_DECSCNM(const char *value, int *flag) |
2136 | { |
2137 | *flag = -1; |
2138 | if (value != 0) { |
2139 | int skip = csi_length(value); |
2140 | if (skip > 0 && |
2141 | value[skip++] == '?' && |
2142 | value[skip++] == '5') { |
2143 | if (value[skip] == 'h') { |
2144 | *flag = 1; |
2145 | } else if (value[skip] == 'l') { |
2146 | *flag = 0; |
2147 | } |
2148 | value += skip + 1; |
2149 | } |
2150 | } |
2151 | return value; |
2152 | } |
2153 | |
2154 | static void |
2155 | check_delays(TERMTYPE2 *tp, const char *name, const char *value) |
2156 | { |
2157 | const char *p, *q; |
2158 | const char *first = 0; |
2159 | const char *last = 0; |
2160 | |
2161 | for (p = value; *p != '\0'; ++p) { |
2162 | if (p[0] == '$' && p[1] == '<') { |
2163 | const char *base = p + 2; |
2164 | const char *mark = 0; |
2165 | bool_Bool mixed = FALSE0; |
2166 | int proportional = 0; |
2167 | int mandatory = 0; |
2168 | |
2169 | first = p; |
2170 | |
2171 | for (q = base; *q != '\0'; ++q) { |
2172 | if (*q == '>') { |
2173 | if (mark == NULL((void *)0)) |
2174 | mark = q; |
2175 | break; |
2176 | } else if (*q == '*' || *q == '/') { |
2177 | if (*q == '*') |
2178 | ++proportional; |
2179 | if (*q == '/') |
2180 | ++mandatory; |
2181 | if (mark == NULL((void *)0)) |
2182 | mark = q; |
2183 | } else if (!(isalnum(UChar(*q)((unsigned char)(*q))) || strchr("+-.", *q) != 0)) { |
2184 | break; |
2185 | } else if (proportional || mandatory) { |
2186 | mixed = TRUE1; |
2187 | } |
2188 | } |
2189 | last = *q ? (q + 1) : q; |
2190 | if (*q != '\0') { |
2191 | float check_f; |
2192 | char check_c; |
2193 | int rc = sscanf(base, "%f%c", &check_f, &check_c); |
2194 | if ((rc != 2) || (mark != NULL((void *)0) && (check_c != *mark)) || mixed) { |
2195 | _nc_warning("syntax error in %s delay '%.*s'", name, |
2196 | (int) (q - base), base); |
2197 | } else if (*name == 'k') { |
2198 | _nc_warning("function-key %s has delay", name); |
2199 | } else if (proportional && !line_capability(name)) { |
2200 | _nc_warning("non-line capability using proportional delay: %s", name); |
2201 | } else if (!xon_xofftp-> Booleans[20] && |
2202 | !mandatory && |
2203 | strchr(_nc_first_name(tp->term_names), '+') == NULL((void *)0)) { |
2204 | _nc_warning("%s in %s is used since no xon/xoff", |
2205 | (proportional |
2206 | ? "proportional delay" |
2207 | : "delay"), |
2208 | name); |
2209 | } |
2210 | } else { |
2211 | p = q - 1; /* restart scan */ |
2212 | } |
2213 | } |
2214 | } |
2215 | |
2216 | if (!strcmp(name, "flash") || |
2217 | !strcmp(name, "beep")) { |
2218 | |
2219 | if (first != 0) { |
2220 | if (first == value || *last == 0) { |
2221 | /* |
2222 | * Delay is on one end or the other. |
2223 | */ |
2224 | _nc_warning("expected delay embedded within %s", name); |
2225 | } |
2226 | } else { |
2227 | int flag; |
2228 | |
2229 | /* |
2230 | * Check for missing delay when using VT100 reverse-video. |
2231 | * A real VT100 might not need this, but terminal emulators do. |
2232 | */ |
2233 | if ((p = skip_DECSCNM(value, &flag)) != 0 && |
2234 | flag > 0 && |
2235 | skip_DECSCNM(p, &flag) != 0 && |
2236 | flag == 0) { |
2237 | _nc_warning("expected a delay in %s", name); |
2238 | } |
2239 | } |
2240 | } |
2241 | } |
2242 | |
2243 | static char * |
2244 | check_1_infotocap(const char *name, NCURSES_CONSTconst char *value, int count) |
2245 | { |
2246 | int k; |
2247 | int ignored; |
2248 | long numbers[1 + NUM_PARM9]; |
2249 | char *strings[1 + NUM_PARM9]; |
2250 | char *p_is_s[NUM_PARM9]; |
2251 | char *result; |
2252 | char blob[NUM_PARM9 * 10]; |
2253 | char *next = blob; |
2254 | TParams expect; |
2255 | TParams actual; |
2256 | int nparam; |
2257 | |
2258 | *next++ = '\0'; |
2259 | for (k = 1; k <= NUM_PARM9; k++) { |
2260 | numbers[k] = count; |
2261 | _nc_SPRINTF(void) (snprintf)(next, |
2262 | _nc_SLIMIT(sizeof(blob) - (size_t) (next - blob))(size_t)(sizeof(blob) - (size_t) (next - blob)), |
2263 | "XYZ%d", count); |
2264 | strings[k] = next; |
2265 | next += strlen(next) + 1; |
2266 | } |
2267 | |
2268 | _nc_reset_tparm(NULL((void *)0)); |
2269 | expect = tparm_type(name); |
2270 | nparam = _nc_tparm_analyze(NULL((void *)0), value, p_is_s, &ignored); |
2271 | actual = guess_tparm_type(nparam, p_is_s); |
2272 | |
2273 | if (expect != actual) { |
2274 | _nc_warning("%s has mismatched parameters", name); |
2275 | actual = Other; |
2276 | } |
2277 | |
2278 | _nc_reset_tparm(NULL((void *)0)); |
2279 | switch (actual) { |
2280 | case Str: |
2281 | result = TPARM_1(value, strings[1])tparm(value,(intptr_t)(strings[1])); |
2282 | break; |
2283 | case Num_Str: |
2284 | result = TPARM_2(value, numbers[1], strings[2])tparm(value,(intptr_t)(numbers[1]),(intptr_t)(strings[2])); |
2285 | break; |
2286 | case Str_Str: |
2287 | result = TPARM_2(value, strings[1], strings[2])tparm(value,(intptr_t)(strings[1]),(intptr_t)(strings[2])); |
2288 | break; |
2289 | case Num_Str_Str: |
2290 | result = TPARM_3(value, numbers[1], strings[2], strings[3])tparm(value,(intptr_t)(numbers[1]),(intptr_t)(strings[2]),(intptr_t )(strings[3])); |
2291 | break; |
2292 | case Numbers: |
2293 | #define myParam(n) numbers[n] |
2294 | result = TIPARM_9(value,_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2295 | myParam(1),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2296 | myParam(2),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2297 | myParam(3),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2298 | myParam(4),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2299 | myParam(5),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2300 | myParam(6),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2301 | myParam(7),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2302 | myParam(8),_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)) |
2303 | myParam(9))_nc_tiparm(9,value,myParam(1),myParam(2),myParam(3),myParam(4 ),myParam(5),myParam(6),myParam(7),myParam(8),myParam(9)); |
2304 | #undef myParam |
2305 | break; |
2306 | case Other: |
2307 | default: |
2308 | #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARGintptr_t) strings[n]) : numbers[n]) |
2309 | result = TPARM_9(value,tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2310 | myParam(1),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2311 | myParam(2),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2312 | myParam(3),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2313 | myParam(4),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2314 | myParam(5),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2315 | myParam(6),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2316 | myParam(7),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2317 | myParam(8),tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))) |
2318 | myParam(9))tparm(value,(intptr_t)(myParam(1)),(intptr_t)(myParam(2)),(intptr_t )(myParam(3)),(intptr_t)(myParam(4)),(intptr_t)(myParam(5)),( intptr_t)(myParam(6)),(intptr_t)(myParam(7)),(intptr_t)(myParam (8)),(intptr_t)(myParam(9))); |
2319 | #undef myParam |
2320 | break; |
2321 | } |
2322 | return strdup(result); |
2323 | } |
2324 | |
2325 | #define IsDelay(ch)((ch) == '.' || isdigit(((unsigned char)(ch)))) ((ch) == '.' || isdigit(UChar(ch)((unsigned char)(ch)))) |
2326 | |
2327 | static const char * |
2328 | parse_delay_value(const char *src, double *delays, int *always) |
2329 | { |
2330 | int star = 0; |
2331 | |
2332 | *delays = 0.0; |
2333 | if (always) |
2334 | *always = 0; |
2335 | |
2336 | while (isdigit(UChar(*src)((unsigned char)(*src)))) { |
2337 | (*delays) = (*delays) * 10 + (*src++ - '0'); |
2338 | } |
2339 | if (*src == '.') { |
2340 | int gotdot = 1; |
2341 | |
2342 | ++src; |
2343 | while (isdigit(UChar(*src)((unsigned char)(*src)))) { |
2344 | gotdot *= 10; |
2345 | (*delays) += (*src++ - '0') / gotdot; |
2346 | } |
2347 | } |
2348 | while (*src == '*' || *src == '/') { |
2349 | if (always == NULL((void *)0) && *src == '/') |
2350 | break; |
2351 | if (*src++ == '*') { |
2352 | star = 1; |
2353 | } else { |
2354 | *always = 1; |
2355 | } |
2356 | } |
2357 | if (star) |
2358 | *delays = -(*delays); |
2359 | return src; |
2360 | } |
2361 | |
2362 | static const char * |
2363 | parse_ti_delay(const char *ti, double *delays) |
2364 | { |
2365 | *delays = 0.0; |
2366 | while (*ti != '\0') { |
2367 | if (*ti == '\\') { |
2368 | ++ti; |
2369 | } |
2370 | if (ti[0] == '$' |
2371 | && ti[1] == '<' |
2372 | && IsDelay(UChar(ti[2]))((((unsigned char)(ti[2]))) == '.' || isdigit(((unsigned char )(((unsigned char)(ti[2]))))))) { |
2373 | int ignored; |
2374 | const char *last = parse_delay_value(ti + 2, delays, &ignored); |
2375 | if (*last == '>') { |
2376 | ti = last; |
2377 | } |
2378 | } else { |
2379 | ++ti; |
2380 | } |
2381 | } |
2382 | return ti; |
2383 | } |
2384 | |
2385 | static const char * |
2386 | parse_tc_delay(const char *tc, double *delays) |
2387 | { |
2388 | return parse_delay_value(tc, delays, (int *) 0); |
2389 | } |
2390 | |
2391 | /* |
2392 | * Compare terminfo- and termcap-strings, factoring out delays. |
2393 | */ |
2394 | static bool_Bool |
2395 | same_ti_tc(const char *ti, const char *tc, bool_Bool * embedded) |
2396 | { |
2397 | bool_Bool same = TRUE1; |
2398 | double ti_delay = 0.0; |
2399 | double tc_delay = 0.0; |
2400 | const char *ti_last; |
2401 | |
2402 | *embedded = FALSE0; |
2403 | ti_last = parse_ti_delay(ti, &ti_delay); |
2404 | tc = parse_tc_delay(tc, &tc_delay); |
2405 | |
2406 | while ((ti < ti_last) && *tc) { |
2407 | if (*ti == '\\' && ispunct(UChar(ti[1])((unsigned char)(ti[1])))) { |
2408 | ++ti; |
2409 | if ((*ti == '^') && !strncmp(tc, "\\136", 4)) { |
2410 | ti += 1; |
2411 | tc += 4; |
2412 | continue; |
2413 | } |
2414 | } else if (ti[0] == '$' && ti[1] == '<') { |
2415 | double no_delay; |
2416 | const char *ss = parse_ti_delay(ti, &no_delay); |
2417 | if (ss != ti) { |
2418 | *embedded = TRUE1; |
2419 | ti = ss; |
2420 | continue; |
2421 | } |
2422 | } |
2423 | if (*tc == '\\' && ispunct(UChar(tc[1])((unsigned char)(tc[1])))) { |
2424 | ++tc; |
2425 | } |
2426 | if (*ti++ != *tc++) { |
2427 | same = FALSE0; |
2428 | break; |
2429 | } |
2430 | } |
2431 | |
2432 | if (*embedded) { |
2433 | if (same) { |
2434 | same = FALSE0; |
2435 | } else { |
2436 | *embedded = FALSE0; /* report only one problem */ |
2437 | } |
2438 | } |
2439 | |
2440 | return same; |
2441 | } |
2442 | |
2443 | /* |
2444 | * Check terminfo to termcap translation. |
2445 | */ |
2446 | static void |
2447 | check_infotocap(TERMTYPE2 *tp, int i, const char *value) |
2448 | { |
2449 | const char *name = ExtStrname(tp, i, strnames)(i >= 414) ? tp->ext_Names[(i - (tp->num_Strings - tp ->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans )] : strnames[i]; |
2450 | char *ti_value = NULL((void *)0); |
2451 | |
2452 | assert(SIZEOF(parametrized) == STRCOUNT)(((sizeof(parametrized)/sizeof(parametrized[0])) == 414) ? (void )0 : __assert2("/usr/src/usr.bin/tic/tic.c", 2452, __func__, "SIZEOF(parametrized) == STRCOUNT" )); |
2453 | if (!VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0) || (ti_value = strdup(value)) == NULL((void *)0)) { |
2454 | _nc_warning("tic-expansion of %s failed", name); |
2455 | } else { |
2456 | char *tc_value; |
2457 | bool_Bool embedded; |
2458 | int params = ((i < (int) SIZEOF(parametrized)(sizeof(parametrized)/sizeof(parametrized[0]))) |
2459 | ? parametrized[i] |
2460 | : ((*value == 'k') |
2461 | ? 0 |
2462 | : has_params(value, FALSE0))); |
2463 | |
2464 | if ((tc_value = _nc_infotocap(name, ti_value, params)) == ABSENT_STRING(char *)0) { |
2465 | _nc_warning("tic-conversion of %s failed", name); |
2466 | } else if (params > 0) { |
2467 | int limit = 5; |
2468 | int count; |
2469 | bool_Bool first = TRUE1; |
2470 | |
2471 | if (!strcmp(name, "setf") |
2472 | || !strcmp(name, "setb") |
2473 | || !strcmp(name, "setaf") |
2474 | || !strcmp(name, "setab")) { |
2475 | if ((limit = max_colorstp-> Numbers[13]) > 256) |
2476 | limit = 256; |
2477 | } |
2478 | for (count = 0; count < limit; ++count) { |
2479 | char *ti_check = check_1_infotocap(name, ti_value, count); |
2480 | char *tc_check = check_1_infotocap(name, tc_value, count); |
2481 | |
2482 | if (strcmp(ti_check, tc_check)) { |
2483 | if (first) { |
2484 | fprintf(stderr(&__sF[2]), "check_infotocap(%s)\n", name); |
2485 | fprintf(stderr(&__sF[2]), "...ti '%s'\n", _nc_visbuf2(0, ti_value)); |
2486 | fprintf(stderr(&__sF[2]), "...tc '%s'\n", _nc_visbuf2(0, tc_value)); |
2487 | first = FALSE0; |
2488 | } |
2489 | _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s", |
2490 | name, count, |
2491 | _nc_visbuf2(0, ti_check), |
2492 | _nc_visbuf2(1, tc_check)); |
2493 | } |
2494 | free(ti_check); |
2495 | free(tc_check); |
2496 | } |
2497 | } else if (params == 0 && !same_ti_tc(ti_value, tc_value, &embedded)) { |
2498 | if (embedded) { |
2499 | _nc_warning("termcap equivalent of %s cannot use embedded delay", name); |
2500 | } else { |
2501 | _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s", |
2502 | name, ti_value, tc_value); |
2503 | } |
2504 | } |
2505 | free(ti_value); |
2506 | } |
2507 | } |
2508 | |
2509 | static char * |
2510 | skip_delay(char *s) |
2511 | { |
2512 | while (*s == '/' || isdigit(UChar(*s)((unsigned char)(*s)))) |
2513 | ++s; |
2514 | return s; |
2515 | } |
2516 | |
2517 | /* |
2518 | * Skip a delay altogether, e.g., when comparing a simple string to sgr, |
2519 | * the latter may have a worst-case delay on the end. |
2520 | */ |
2521 | static char * |
2522 | ignore_delays(char *s) |
2523 | { |
2524 | int delaying = 0; |
2525 | |
2526 | do { |
2527 | switch (*s) { |
2528 | case '$': |
2529 | if (delaying == 0) |
2530 | delaying = 1; |
2531 | break; |
2532 | case '<': |
2533 | if (delaying == 1) |
2534 | delaying = 2; |
2535 | break; |
2536 | case '\0': |
2537 | delaying = 0; |
2538 | break; |
2539 | default: |
2540 | if (delaying) { |
2541 | s = skip_delay(s); |
2542 | if (*s == '>') |
2543 | ++s; |
2544 | delaying = 0; |
2545 | } |
2546 | break; |
2547 | } |
2548 | if (delaying) |
2549 | ++s; |
2550 | } while (delaying); |
2551 | return s; |
2552 | } |
2553 | |
2554 | #define DATA(name) { #name } |
2555 | static const char sgr_names[][11] = |
2556 | { |
2557 | DATA(none), |
2558 | DATA(standout), |
2559 | DATA(underline), |
2560 | DATA(reverse), |
2561 | DATA(blink), |
2562 | DATA(dim), |
2563 | DATA(bold), |
2564 | DATA(invis), |
2565 | DATA(protect), |
2566 | DATA(altcharset), |
2567 | "" |
2568 | }; |
2569 | #undef DATA |
2570 | |
2571 | /* |
2572 | * An sgr string may contain several settings other than the one we're |
2573 | * interested in, essentially sgr0 + rmacs + whatever. As long as the |
2574 | * "whatever" is contained in the sgr string, that is close enough for our |
2575 | * sanity check. |
2576 | */ |
2577 | static bool_Bool |
2578 | similar_sgr(int num, char *a, char *b) |
2579 | { |
2580 | char *base_a = a; |
2581 | char *base_b = b; |
2582 | int delaying = 0; |
2583 | |
2584 | while (*b != 0) { |
2585 | while (*a != *b) { |
2586 | if (*a == 0) { |
2587 | if (num < 0) { |
2588 | ; |
2589 | } else if (b[0] == '$' |
2590 | && b[1] == '<') { |
2591 | _nc_warning("did not find delay %s", _nc_visbuf(b)); |
2592 | } else { |
2593 | _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s", |
2594 | sgr_names[num], _nc_visbuf2(1, base_a), |
2595 | _nc_visbuf2(2, base_b), |
2596 | _nc_visbuf2(3, b)); |
2597 | } |
2598 | return FALSE0; |
2599 | } else if (delaying) { |
2600 | a = skip_delay(a); |
2601 | b = skip_delay(b); |
2602 | } else if ((*b == '0' || (*b == ';')) && *a == 'm') { |
2603 | b++; |
2604 | } else { |
2605 | a++; |
2606 | } |
2607 | } |
2608 | switch (*a) { |
2609 | case '$': |
2610 | if (delaying == 0) |
2611 | delaying = 1; |
2612 | break; |
2613 | case '<': |
2614 | if (delaying == 1) |
2615 | delaying = 2; |
2616 | break; |
2617 | default: |
2618 | delaying = 0; |
2619 | break; |
2620 | } |
2621 | a++; |
2622 | b++; |
2623 | } |
2624 | /* ignore delays on the end of the string */ |
2625 | a = ignore_delays(a); |
2626 | return ((num != 0) || (*a == 0)); |
2627 | } |
2628 | |
2629 | static void |
2630 | check_tparm_err(int num) |
2631 | { |
2632 | if (_nc_tparm_err) |
2633 | _nc_warning("tparam error in sgr(%d): %s", num, sgr_names[num]); |
2634 | } |
2635 | |
2636 | static char * |
2637 | check_sgr(TERMTYPE2 *tp, char *zero, int num, char *cap, const char *name) |
2638 | { |
2639 | char *test; |
2640 | |
2641 | _nc_tparm_err = 0; |
2642 | test = TIPARM_9(set_attributes,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2643 | num == 1,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2644 | num == 2,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2645 | num == 3,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2646 | num == 4,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2647 | num == 5,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2648 | num == 6,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2649 | num == 7,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2650 | num == 8,_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9) |
2651 | num == 9)_nc_tiparm(9,tp-> Strings[131],num == 1,num == 2,num == 3, num == 4,num == 5,num == 6,num == 7,num == 8,num == 9); |
2652 | if (test != 0) { |
2653 | if (PRESENT(cap)(((cap) != (char *)0) && ((cap) != (char *)(-1)))) { |
2654 | if (!similar_sgr(num, test, cap)) { |
2655 | _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s", |
2656 | name, num, |
2657 | name, _nc_visbuf2(1, cap), |
2658 | num, _nc_visbuf2(2, test)); |
2659 | } |
2660 | } else if (_nc_capcmp(test, zero)) { |
2661 | _nc_warning("sgr(%d) present, but not %s", num, name); |
2662 | } |
2663 | } else if (PRESENT(cap)(((cap) != (char *)0) && ((cap) != (char *)(-1)))) { |
2664 | _nc_warning("sgr(%d) missing, but %s present", num, name); |
2665 | } |
2666 | check_tparm_err(num); |
2667 | return test; |
2668 | } |
2669 | |
2670 | #define CHECK_SGR(num,name)check_sgr(tp, zero, num, name, "name") check_sgr(tp, zero, num, name, #name) |
2671 | |
2672 | #ifdef TRACE |
2673 | /* |
2674 | * If tic is compiled with TRACE, we'll be able to see the output from the |
2675 | * DEBUG() macro. But since it doesn't use traceon(), it always goes to |
2676 | * the standard error. Use this function to make it simpler to follow the |
2677 | * resulting debug traces. |
2678 | */ |
2679 | static void |
2680 | show_where(unsigned level) |
2681 | { |
2682 | if (_nc_tracing >= DEBUG_LEVEL(level)((level) << 13)) { |
2683 | char my_name[MAX_NAME_SIZE512]; |
2684 | _nc_get_type(my_name); |
2685 | _tracef("\"%s\", line %d, '%s'", |
2686 | _nc_get_source(), |
2687 | _nc_curr_line, my_name); |
2688 | } |
2689 | } |
2690 | |
2691 | #else |
2692 | #define show_where(level) /* nothing */ |
2693 | #endif |
2694 | |
2695 | typedef struct { |
2696 | int keycode; |
2697 | const char *name; |
2698 | const char *value; |
2699 | } NAME_VALUE; |
2700 | |
2701 | static NAME_VALUE * |
2702 | get_fkey_list(TERMTYPE2 *tp) |
2703 | { |
2704 | NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1)(NAME_VALUE *)malloc((size_t)((tp)->num_Strings + 1)*sizeof (NAME_VALUE)); |
2705 | const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys; |
2706 | int used = 0; |
2707 | unsigned j; |
2708 | |
2709 | if (result == NULL((void *)0)) |
2710 | failed("get_fkey_list"); |
2711 | |
2712 | for (j = 0; all_fkeys[j].code; j++) { |
2713 | char *a = tp->Strings[all_fkeys[j].offset]; |
2714 | if (VALID_STRING(a)((a) != (char *)(-1) && (a) != (char *)0)) { |
2715 | result[used].keycode = (int) all_fkeys[j].code; |
2716 | result[used].name = strnames[all_fkeys[j].offset]; |
2717 | result[used].value = a; |
2718 | ++used; |
2719 | } |
2720 | } |
2721 | #if NCURSES_XNAMES1 |
2722 | for (j = STRCOUNT414; j < NUM_STRINGS(tp)(tp)->num_Strings; ++j) { |
2723 | const char *name = ExtStrname(tp, (int) j, strnames)((int) j >= 414) ? tp->ext_Names[((int) j - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans )] : strnames[(int) j]; |
2724 | if (*name == 'k') { |
2725 | result[used].keycode = -1; |
2726 | result[used].name = name; |
2727 | result[used].value = tp->Strings[j]; |
2728 | ++used; |
2729 | } |
2730 | } |
2731 | #endif |
2732 | result[used].keycode = 0; |
2733 | return result; |
2734 | } |
2735 | |
2736 | static void |
2737 | show_fkey_name(NAME_VALUE * data) |
2738 | { |
2739 | if (data->keycode > 0) { |
2740 | fprintf(stderr(&__sF[2]), " %s", keyname(data->keycode)); |
2741 | fprintf(stderr(&__sF[2]), " (capability \"%s\")", data->name); |
2742 | } else { |
2743 | fprintf(stderr(&__sF[2]), " capability \"%s\"", data->name); |
2744 | } |
2745 | } |
2746 | |
2747 | /* |
2748 | * A terminal entry may contain more than one keycode assigned to a given |
2749 | * string (e.g., KEY_END and KEY_LL). But curses will only return one (the |
2750 | * last one assigned). |
2751 | */ |
2752 | static void |
2753 | check_conflict(TERMTYPE2 *tp) |
2754 | { |
2755 | if (!(_nc_syntax == SYN_TERMCAP1 && capdump)) { |
2756 | char *check = calloc((size_t) (NUM_STRINGS(tp)(tp)->num_Strings + 1), sizeof(char)); |
2757 | NAME_VALUE *given = get_fkey_list(tp); |
2758 | unsigned j, k; |
2759 | bool_Bool conflict = FALSE0; |
2760 | |
2761 | if (check == NULL((void *)0)) |
2762 | failed("check_conflict"); |
2763 | |
2764 | for (j = 0; given[j].keycode; ++j) { |
2765 | const char *a = given[j].value; |
2766 | bool_Bool first = TRUE1; |
2767 | |
2768 | if (!VALID_STRING(a)((a) != (char *)(-1) && (a) != (char *)0)) |
2769 | continue; |
2770 | |
2771 | for (k = j + 1; given[k].keycode; k++) { |
2772 | const char *b = given[k].value; |
2773 | |
2774 | if (!VALID_STRING(b)((b) != (char *)(-1) && (b) != (char *)0)) |
2775 | continue; |
2776 | if (check[k]) |
2777 | continue; |
2778 | |
2779 | if (!_nc_capcmp(a, b)) { |
2780 | check[j] = 1; |
2781 | check[k] = 1; |
2782 | if (first) { |
2783 | if (!conflict) { |
2784 | _nc_warning("conflicting key definitions (using the last)"); |
2785 | conflict = TRUE1; |
2786 | } |
2787 | fprintf(stderr(&__sF[2]), "..."); |
2788 | show_fkey_name(given + j); |
2789 | fprintf(stderr(&__sF[2]), " is the same as"); |
2790 | show_fkey_name(given + k); |
2791 | first = FALSE0; |
2792 | } else { |
2793 | fprintf(stderr(&__sF[2]), ", "); |
2794 | show_fkey_name(given + k); |
2795 | } |
2796 | } |
2797 | } |
2798 | if (!first) |
2799 | fprintf(stderr(&__sF[2]), "\n"); |
2800 | } |
2801 | #if NCURSES_XNAMES1 |
2802 | if (using_extensions) { |
2803 | /* *INDENT-OFF* */ |
2804 | static struct { |
2805 | const char *xcurses; |
2806 | const char *shifted; |
2807 | } table[] = { |
2808 | { "kDC", NULL((void *)0) }, |
2809 | { "kDN", "kind" }, |
2810 | { "kEND", NULL((void *)0) }, |
2811 | { "kHOM", NULL((void *)0) }, |
2812 | { "kLFT", NULL((void *)0) }, |
2813 | { "kNXT", NULL((void *)0) }, |
2814 | { "kPRV", NULL((void *)0) }, |
2815 | { "kRIT", NULL((void *)0) }, |
2816 | { "kUP", "kri" }, |
2817 | { NULL((void *)0), NULL((void *)0) }, |
2818 | }; |
2819 | /* *INDENT-ON* */ |
2820 | /* |
2821 | * SVr4 curses defines the "xcurses" names listed above except for |
2822 | * the special cases in the "shifted" column. When using these |
2823 | * names for xterm's extensions, that was confusing, and resulted |
2824 | * in adding extended capabilities with "2" (shift) suffix. This |
2825 | * check warns about unnecessary use of extensions for this quirk. |
2826 | */ |
2827 | for (j = 0; given[j].keycode; ++j) { |
2828 | const char *find = given[j].name; |
2829 | int value; |
2830 | char ch; |
2831 | |
2832 | if (!VALID_STRING(given[j].value)((given[j].value) != (char *)(-1) && (given[j].value) != (char *)0)) |
2833 | continue; |
2834 | |
2835 | for (k = 0; table[k].xcurses; ++k) { |
2836 | const char *test = table[k].xcurses; |
2837 | size_t size = strlen(test); |
2838 | |
2839 | if (!strncmp(find, test, size) && strcmp(find, test)) { |
2840 | switch (sscanf(find + size, "%d%c", &value, &ch)) { |
2841 | case 1: |
2842 | if (value == 2) { |
2843 | _nc_warning("expected '%s' rather than '%s'", |
2844 | (table[k].shifted |
2845 | ? table[k].shifted |
2846 | : test), find); |
2847 | } else if (value < 2 || value > 15) { |
2848 | _nc_warning("expected numeric 2..15 '%s'", find); |
2849 | } |
2850 | break; |
2851 | default: |
2852 | _nc_warning("expected numeric suffix for '%s'", find); |
2853 | break; |
2854 | } |
2855 | break; |
2856 | } |
2857 | } |
2858 | } |
2859 | } |
2860 | #endif |
2861 | free(given); |
2862 | free(check); |
2863 | } |
2864 | } |
2865 | |
2866 | /* |
2867 | * Exiting a video mode should not duplicate sgr0 |
2868 | */ |
2869 | static void |
2870 | check_exit_attribute(const char *name, char *test, char *trimmed, char *untrimmed) |
2871 | { |
2872 | if (VALID_STRING(test)((test) != (char *)(-1) && (test) != (char *)0) && (trimmed != 0)) { |
2873 | if (similar_sgr(-1, trimmed, test) || |
2874 | similar_sgr(-1, untrimmed, test)) { |
2875 | _nc_warning("%s matches exit_attribute_mode", name); |
2876 | } |
2877 | } |
2878 | } |
2879 | |
2880 | /* |
2881 | * Returns true if the string looks like a standard SGR string. |
2882 | */ |
2883 | static bool_Bool |
2884 | is_sgr_string(char *value) |
2885 | { |
2886 | bool_Bool result = FALSE0; |
2887 | |
2888 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0)) { |
2889 | int skip = csi_length(value); |
2890 | |
2891 | if (skip) { |
2892 | int ch; |
2893 | |
2894 | result = TRUE1; |
2895 | value += skip; |
2896 | while ((ch = UChar(*value++)((unsigned char)(*value++))) != '\0') { |
2897 | if (isdigit(ch) || ch == ';') { |
2898 | ; |
2899 | } else if (ch == 'm' && *value == '\0') { |
2900 | ; |
2901 | } else { |
2902 | result = FALSE0; |
2903 | break; |
2904 | } |
2905 | } |
2906 | } |
2907 | } |
2908 | return result; |
2909 | } |
2910 | |
2911 | /* |
2912 | * Check if the given capability contains a given SGR attribute. |
2913 | */ |
2914 | static void |
2915 | check_sgr_param(TERMTYPE2 *tp, int code, const char *name, char *value) |
2916 | { |
2917 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0)) { |
2918 | int ncv = ((code != 0) ? (1 << (code - 1)) : 0); |
2919 | char *test = tgoto(value, 0, 0); |
2920 | if (is_sgr_string(test)) { |
2921 | int param = 0; |
2922 | int count = 0; |
2923 | int skips = 0; |
2924 | int color = (value == set_a_foregroundtp-> Strings[359] || |
2925 | value == set_a_backgroundtp-> Strings[360] || |
2926 | value == set_foregroundtp-> Strings[302] || |
2927 | value == set_backgroundtp-> Strings[303]); |
2928 | while (*test != 0) { |
2929 | if (isdigit(UChar(*test)((unsigned char)(*test)))) { |
2930 | param = 10 * param + (*test - '0'); |
2931 | ++count; |
2932 | } else { |
2933 | if (count) { |
2934 | /* |
2935 | * Avoid unnecessary warning for xterm 256color codes. |
2936 | */ |
2937 | if (color && (param == 38 || param == 48)) |
2938 | skips = 3; |
2939 | if ((skips-- <= 0) && (param == code)) |
2940 | break; |
2941 | } |
2942 | count = 0; |
2943 | param = 0; |
2944 | } |
2945 | ++test; |
2946 | } |
2947 | if (count != 0 && param == code) { |
2948 | if (code == 0 || |
2949 | no_color_videotp-> Numbers[15] < 0 || |
2950 | !(no_color_videotp-> Numbers[15] & ncv)) { |
2951 | _nc_warning("\"%s\" SGR-attribute used in %s", |
2952 | sgr_names[code], |
2953 | name); |
2954 | } |
2955 | } |
2956 | } |
2957 | } |
2958 | } |
2959 | |
2960 | #if NCURSES_XNAMES1 |
2961 | static int |
2962 | standard_type(const char *name) |
2963 | { |
2964 | int result = -1; |
2965 | const struct name_table_entry *np; |
2966 | |
2967 | if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0) { |
2968 | result = np->nte_type; |
2969 | } |
2970 | return result; |
2971 | } |
2972 | |
2973 | static const char * |
2974 | name_of_type(int type) |
2975 | { |
2976 | const char *result = "unknown"; |
2977 | switch (type) { |
2978 | case BOOLEAN0: |
2979 | result = "boolean"; |
2980 | break; |
2981 | case NUMBER1: |
2982 | result = "number"; |
2983 | break; |
2984 | case STRING2: |
2985 | result = "string"; |
2986 | break; |
2987 | } |
2988 | return result; |
2989 | } |
2990 | |
2991 | static void |
2992 | check_user_capability_type(const char *name, int actual) |
2993 | { |
2994 | if (lookup_user_capability(name) == 0) { |
2995 | int expected = standard_type(name); |
2996 | if (expected >= 0) { |
2997 | _nc_warning("expected %s to be %s, but actually %s", |
2998 | name, |
2999 | name_of_type(actual), |
3000 | name_of_type(expected) |
3001 | ); |
3002 | } else if (*name != 'k') { |
3003 | _nc_warning("undocumented %s capability %s", |
3004 | name_of_type(actual), |
3005 | name); |
3006 | } |
3007 | } |
3008 | } |
3009 | #endif |
3010 | |
3011 | #define IN_DELAY"0123456789*/." "0123456789*/." |
3012 | |
3013 | static bool_Bool |
3014 | check_ANSI_cap(const char *value, int nparams, char final) |
3015 | { |
3016 | bool_Bool result = FALSE0; |
3017 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0) && csi_length(value) > 0) { |
3018 | char *p_is_s[NUM_PARM9]; |
3019 | int popcount; |
3020 | int analyzed = _nc_tparm_analyze(NULL((void *)0), value, p_is_s, &popcount); |
3021 | if (analyzed < popcount) { |
3022 | analyzed = popcount; |
3023 | } |
3024 | if (analyzed == nparams) { |
3025 | bool_Bool numbers = TRUE1; |
3026 | int p; |
3027 | for (p = 0; p < nparams; ++p) { |
3028 | if (p_is_s[p]) { |
3029 | numbers = FALSE0; |
3030 | break; |
3031 | } |
3032 | } |
3033 | if (numbers) { |
3034 | int in_delay = 0; |
3035 | p = (int) strlen(value); |
3036 | while (p-- > 0) { |
3037 | char ch = value[p]; |
3038 | if (ch == final) { |
3039 | result = TRUE1; |
3040 | break; |
3041 | } |
3042 | switch (in_delay) { |
3043 | case 0: |
3044 | if (ch == '>') |
3045 | in_delay = 1; |
3046 | break; |
3047 | case 1: |
3048 | if (strchr(IN_DELAY"0123456789*/.", value[p]) != NULL((void *)0)) |
3049 | break; |
3050 | if (ch != '<') |
3051 | p = 0; |
3052 | in_delay = 2; |
3053 | break; |
3054 | case 2: |
3055 | if (ch != '$') |
3056 | p = 0; |
3057 | in_delay = 0; |
3058 | break; |
3059 | } |
3060 | } |
3061 | } |
3062 | } |
3063 | } |
3064 | return result; |
3065 | } |
3066 | |
3067 | static const char * |
3068 | skip_Delay(const char *value) |
3069 | { |
3070 | const char *result = value; |
3071 | |
3072 | if (*value == '$') { |
3073 | ++result; |
3074 | if (*result++ == '<') { |
3075 | while (strchr(IN_DELAY"0123456789*/.", *result) != NULL((void *)0)) |
3076 | ++result; |
3077 | if (*result++ != '>') { |
3078 | result = value; |
3079 | } |
3080 | } else { |
3081 | result = value; |
3082 | } |
3083 | } |
3084 | return result; |
3085 | } |
3086 | |
3087 | static bool_Bool |
3088 | isValidString(const char *value, const char *expect) |
3089 | { |
3090 | bool_Bool result = FALSE0; |
3091 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0)) { |
3092 | if (!strcmp(value, expect)) |
3093 | result = TRUE1; |
3094 | } |
3095 | return result; |
3096 | } |
3097 | |
3098 | static bool_Bool |
3099 | isValidEscape(const char *value, const char *expect) |
3100 | { |
3101 | bool_Bool result = FALSE0; |
3102 | if (VALID_STRING(value)((value) != (char *)(-1) && (value) != (char *)0)) { |
3103 | if (*value == '\033') { |
3104 | size_t need = strlen(expect); |
3105 | size_t have = strlen(value) - 1; |
3106 | if (have >= need && !strncmp(value + 1, expect, need)) { |
3107 | if (*skip_Delay(value + need + 1) == '\0') { |
3108 | result = TRUE1; |
3109 | } |
3110 | } |
3111 | } |
3112 | } |
3113 | return result; |
3114 | } |
3115 | |
3116 | static int |
3117 | guess_ANSI_VTxx(TERMTYPE2 *tp) |
3118 | { |
3119 | int result = -1; |
3120 | int checks = 0; |
3121 | |
3122 | /* VT100s have scrolling region, but ANSI (ECMA-48) does not specify */ |
3123 | if (check_ANSI_cap(change_scroll_regiontp-> Strings[3], 2, 'r') && |
3124 | (isValidEscape(scroll_forwardtp-> Strings[129], "D") || |
3125 | isValidString(scroll_forwardtp-> Strings[129], "\n") || |
3126 | isValidEscape(scroll_forwardtp-> Strings[129], "6")) && |
3127 | (isValidEscape(scroll_reversetp-> Strings[130], "M") || |
3128 | isValidEscape(scroll_reversetp-> Strings[130], "9"))) { |
3129 | checks |= 2; |
3130 | } |
3131 | if (check_ANSI_cap(cursor_addresstp-> Strings[10], 2, 'H') && |
3132 | check_ANSI_cap(cursor_uptp-> Strings[19], 0, 'A') && |
3133 | (check_ANSI_cap(cursor_downtp-> Strings[11], 0, 'B') || |
3134 | isValidString(cursor_downtp-> Strings[11], "\n")) && |
3135 | check_ANSI_cap(cursor_righttp-> Strings[17], 0, 'C') && |
3136 | (check_ANSI_cap(cursor_lefttp-> Strings[14], 0, 'D') || |
3137 | isValidString(cursor_lefttp-> Strings[14], "\b")) && |
3138 | check_ANSI_cap(clr_eostp-> Strings[7], 0, 'J') && |
3139 | check_ANSI_cap(clr_boltp-> Strings[269], 0, 'K') && |
3140 | check_ANSI_cap(clr_eoltp-> Strings[6], 0, 'K')) { |
3141 | checks |= 1; |
3142 | } |
3143 | if (checks == 3) |
3144 | result = 1; |
3145 | if (checks == 1) |
3146 | result = 0; |
3147 | return result; |
3148 | } |
3149 | |
3150 | /* |
3151 | * u6/u7 and u8/u9 are query/response extensions which most terminals support. |
3152 | * In particular, any ECMA-48 terminal should support these, though the details |
3153 | * for u9 are implementation dependent. |
3154 | */ |
3155 | static void |
3156 | check_user_6789(TERMTYPE2 *tp) |
3157 | { |
3158 | /* |
3159 | * Check if the terminal is known to not |
3160 | */ |
3161 | #define NO_QUERY(longname,shortname)if ((((longname) != (char *)0) && ((longname) != (char *)(-1)))) _nc_warning("shortname" " is not supported") \ |
3162 | if (PRESENT(longname)(((longname) != (char *)0) && ((longname) != (char *) (-1)))) _nc_warning(#shortname " is not supported") |
3163 | if (tigetflag("NQ") > 0) { |
3164 | NO_QUERY(user6, u6)if ((((tp-> Strings[293]) != (char *)0) && ((tp-> Strings[293]) != (char *)(-1)))) _nc_warning("u6" " is not supported" ); |
3165 | NO_QUERY(user7, u7)if ((((tp-> Strings[294]) != (char *)0) && ((tp-> Strings[294]) != (char *)(-1)))) _nc_warning("u7" " is not supported" ); |
3166 | NO_QUERY(user8, u8)if ((((tp-> Strings[295]) != (char *)0) && ((tp-> Strings[295]) != (char *)(-1)))) _nc_warning("u8" " is not supported" ); |
3167 | NO_QUERY(user9, u9)if ((((tp-> Strings[296]) != (char *)0) && ((tp-> Strings[296]) != (char *)(-1)))) _nc_warning("u9" " is not supported" ); |
3168 | return; |
3169 | } |
3170 | |
3171 | PAIRED(user6, user7){ if ((((tp-> Strings[294]) != (char *)0) && ((tp-> Strings[294]) != (char *)(-1))) && !(((tp-> Strings [293]) != (char *)0) && ((tp-> Strings[293]) != (char *)(-1)))) _nc_warning("user7" " but no " "user6"); if ((((tp -> Strings[293]) != (char *)0) && ((tp-> Strings [293]) != (char *)(-1))) && !(((tp-> Strings[294]) != (char *)0) && ((tp-> Strings[294]) != (char *) (-1)))) _nc_warning("user6" " but no " "user7"); }; |
3172 | PAIRED(user8, user9){ if ((((tp-> Strings[296]) != (char *)0) && ((tp-> Strings[296]) != (char *)(-1))) && !(((tp-> Strings [295]) != (char *)0) && ((tp-> Strings[295]) != (char *)(-1)))) _nc_warning("user9" " but no " "user8"); if ((((tp -> Strings[295]) != (char *)0) && ((tp-> Strings [295]) != (char *)(-1))) && !(((tp-> Strings[296]) != (char *)0) && ((tp-> Strings[296]) != (char *) (-1)))) _nc_warning("user8" " but no " "user9"); }; |
3173 | |
3174 | if (strchr(tp->term_names, '+') != NULL((void *)0)) |
3175 | return; |
3176 | |
3177 | switch (guess_ANSI_VTxx(tp)) { |
3178 | case 1: |
3179 | if (!PRESENT(user8)(((tp-> Strings[295]) != (char *)0) && ((tp-> Strings [295]) != (char *)(-1)))) { |
3180 | _nc_warning("expected u8/u9 for device-attributes"); |
3181 | } |
3182 | /* FALLTHRU */ |
3183 | case 0: |
3184 | if (!PRESENT(user6)(((tp-> Strings[293]) != (char *)0) && ((tp-> Strings [293]) != (char *)(-1)))) { |
3185 | _nc_warning("expected u6/u7 for cursor-position"); |
3186 | } |
3187 | break; |
3188 | } |
3189 | } |
3190 | |
3191 | /* other sanity-checks (things that we don't want in the normal |
3192 | * logic that reads a terminfo entry) |
3193 | */ |
3194 | static void |
3195 | check_termtype(TERMTYPE2 *tp, bool_Bool literal) |
3196 | { |
3197 | unsigned j; |
3198 | |
3199 | check_conflict(tp); |
3200 | |
3201 | for_each_string(j, tp)for(j = 0; j < (tp)->num_Strings; j++) { |
3202 | char *a = tp->Strings[j]; |
3203 | if (VALID_STRING(a)((a) != (char *)(-1) && (a) != (char *)0)) { |
3204 | const char *name = ExtStrname(tp, (int) j, strnames)((int) j >= 414) ? tp->ext_Names[((int) j - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans )] : strnames[(int) j]; |
3205 | /* |
3206 | * If we expect parameters, or if there might be parameters, |
3207 | * check for consistent number of parameters. |
3208 | */ |
3209 | if (j >= SIZEOF(parametrized)(sizeof(parametrized)/sizeof(parametrized[0])) || |
3210 | is_user_capability(name) >= 0 || |
3211 | parametrized[j] > 0) { |
3212 | check_params(tp, name, a, (j >= STRCOUNT414)); |
3213 | } |
3214 | check_delays(tp, ExtStrname(tp, (int) j, strnames)((int) j >= 414) ? tp->ext_Names[((int) j - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans )] : strnames[(int) j], a); |
3215 | if (capdump) { |
3216 | check_infotocap(tp, (int) j, a); |
3217 | } |
3218 | } |
3219 | } |
3220 | #if NCURSES_XNAMES1 |
3221 | /* in extended mode, verify that each extension is expected type */ |
3222 | for_each_ext_boolean(j, tp)for(j = 44; (int) j < (int) (tp)->num_Booleans; j++) { |
3223 | check_user_capability_type(ExtBoolname(tp, (int) j, strnames)((int) j >= 44) ? tp->ext_Names[((int) j - (tp->num_Booleans - tp->ext_Booleans))] : strnames[(int) j], BOOLEAN0); |
3224 | } |
3225 | for_each_ext_number(j, tp)for(j = 39; (int) j < (int) (tp)->num_Numbers; j++) { |
3226 | check_user_capability_type(ExtNumname(tp, (int) j, strnames)((int) j >= 39) ? tp->ext_Names[((int) j - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans] : strnames[(int ) j], NUMBER1); |
3227 | } |
3228 | for_each_ext_string(j, tp)for(j = 414; (int) j < (int) (tp)->num_Strings; j++) { |
3229 | check_user_capability_type(ExtStrname(tp, (int) j, strnames)((int) j >= 414) ? tp->ext_Names[((int) j - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans )] : strnames[(int) j], STRING2); |
3230 | } |
3231 | #endif /* NCURSES_XNAMES */ |
3232 | |
3233 | check_acs(tp); |
3234 | check_colors(tp); |
3235 | check_cursor(tp); |
3236 | check_keypad(tp); |
3237 | check_printer(tp); |
3238 | check_screen(tp); |
3239 | check_user_6789(tp); |
3240 | |
3241 | /* |
3242 | * These are probably both or none. |
3243 | */ |
3244 | PAIRED(parm_index, parm_rindex){ if ((((tp-> Strings[113]) != (char *)0) && ((tp-> Strings[113]) != (char *)(-1))) && !(((tp-> Strings [109]) != (char *)0) && ((tp-> Strings[109]) != (char *)(-1)))) _nc_warning("parm_rindex" " but no " "parm_index") ; if ((((tp-> Strings[109]) != (char *)0) && ((tp-> Strings[109]) != (char *)(-1))) && !(((tp-> Strings [113]) != (char *)0) && ((tp-> Strings[113]) != (char *)(-1)))) _nc_warning("parm_index" " but no " "parm_rindex") ; }; |
3245 | PAIRED(parm_ich, parm_dch){ if ((((tp-> Strings[105]) != (char *)0) && ((tp-> Strings[105]) != (char *)(-1))) && !(((tp-> Strings [108]) != (char *)0) && ((tp-> Strings[108]) != (char *)(-1)))) _nc_warning("parm_dch" " but no " "parm_ich"); if ( (((tp-> Strings[108]) != (char *)0) && ((tp-> Strings [108]) != (char *)(-1))) && !(((tp-> Strings[105]) != (char *)0) && ((tp-> Strings[105]) != (char *) (-1)))) _nc_warning("parm_ich" " but no " "parm_dch"); }; |
3246 | |
3247 | /* |
3248 | * These may be mismatched because the terminal description relies on |
3249 | * restoring the cursor visibility by resetting it. |
3250 | */ |
3251 | ANDMISSING(cursor_invisible, cursor_normal){ if ((((tp-> Strings[13]) != (char *)0) && ((tp-> Strings[13]) != (char *)(-1))) && !(((tp-> Strings [16]) != (char *)0) && ((tp-> Strings[16]) != (char *)(-1)))) _nc_warning("cursor_invisible" " but no " "cursor_normal" ); }; |
3252 | ANDMISSING(cursor_visible, cursor_normal){ if ((((tp-> Strings[20]) != (char *)0) && ((tp-> Strings[20]) != (char *)(-1))) && !(((tp-> Strings [16]) != (char *)0) && ((tp-> Strings[16]) != (char *)(-1)))) _nc_warning("cursor_visible" " but no " "cursor_normal" ); }; |
3253 | |
3254 | if (PRESENT(cursor_visible)(((tp-> Strings[20]) != (char *)0) && ((tp-> Strings [20]) != (char *)(-1))) && PRESENT(cursor_normal)(((tp-> Strings[16]) != (char *)0) && ((tp-> Strings [16]) != (char *)(-1))) |
3255 | && !_nc_capcmp(cursor_visibletp-> Strings[20], cursor_normaltp-> Strings[16])) |
3256 | _nc_warning("cursor_visible is same as cursor_normal"); |
3257 | |
3258 | /* |
3259 | * From XSI & O'Reilly, we gather that sc/rc are required if csr is |
3260 | * given, because the cursor position after the scrolling operation is |
3261 | * performed is undefined. |
3262 | */ |
3263 | ANDMISSING(change_scroll_region, save_cursor){ if ((((tp-> Strings[3]) != (char *)0) && ((tp-> Strings[3]) != (char *)(-1))) && !(((tp-> Strings [128]) != (char *)0) && ((tp-> Strings[128]) != (char *)(-1)))) _nc_warning("change_scroll_region" " but no " "save_cursor" ); }; |
3264 | ANDMISSING(change_scroll_region, restore_cursor){ if ((((tp-> Strings[3]) != (char *)0) && ((tp-> Strings[3]) != (char *)(-1))) && !(((tp-> Strings [126]) != (char *)0) && ((tp-> Strings[126]) != (char *)(-1)))) _nc_warning("change_scroll_region" " but no " "restore_cursor" ); }; |
3265 | |
3266 | /* |
3267 | * If we can clear tabs, we should be able to initialize them. |
3268 | */ |
3269 | ANDMISSING(clear_all_tabs, set_tab){ if ((((tp-> Strings[4]) != (char *)0) && ((tp-> Strings[4]) != (char *)(-1))) && !(((tp-> Strings [132]) != (char *)0) && ((tp-> Strings[132]) != (char *)(-1)))) _nc_warning("clear_all_tabs" " but no " "set_tab") ; }; |
3270 | |
3271 | if (PRESENT(set_attributes)(((tp-> Strings[131]) != (char *)0) && ((tp-> Strings [131]) != (char *)(-1)))) { |
3272 | char *zero = 0; |
3273 | |
3274 | _nc_tparm_err = 0; |
3275 | if (PRESENT(exit_attribute_mode)(((tp-> Strings[39]) != (char *)0) && ((tp-> Strings [39]) != (char *)(-1)))) { |
3276 | zero = strdup(CHECK_SGR(0, exit_attribute_mode)check_sgr(tp, zero, 0, tp-> Strings[39], "exit_attribute_mode" )); |
3277 | } else { |
3278 | zero = strdup(TIPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0)_nc_tiparm(9,tp-> Strings[131],0,0,0,0,0,0,0,0,0)); |
3279 | } |
3280 | check_tparm_err(0); |
3281 | |
3282 | if (zero != 0) { |
3283 | CHECK_SGR(1, enter_standout_mode)check_sgr(tp, zero, 1, tp-> Strings[35], "enter_standout_mode" ); |
3284 | CHECK_SGR(2, enter_underline_mode)check_sgr(tp, zero, 2, tp-> Strings[36], "enter_underline_mode" ); |
3285 | CHECK_SGR(3, enter_reverse_mode)check_sgr(tp, zero, 3, tp-> Strings[34], "enter_reverse_mode" ); |
3286 | CHECK_SGR(4, enter_blink_mode)check_sgr(tp, zero, 4, tp-> Strings[26], "enter_blink_mode" ); |
3287 | CHECK_SGR(5, enter_dim_mode)check_sgr(tp, zero, 5, tp-> Strings[30], "enter_dim_mode"); |
3288 | CHECK_SGR(6, enter_bold_mode)check_sgr(tp, zero, 6, tp-> Strings[27], "enter_bold_mode" ); |
3289 | CHECK_SGR(7, enter_secure_mode)check_sgr(tp, zero, 7, tp-> Strings[32], "enter_secure_mode" ); |
3290 | CHECK_SGR(8, enter_protected_mode)check_sgr(tp, zero, 8, tp-> Strings[33], "enter_protected_mode" ); |
3291 | CHECK_SGR(9, enter_alt_charset_mode)check_sgr(tp, zero, 9, tp-> Strings[25], "enter_alt_charset_mode" ); |
3292 | free(zero); |
3293 | } else { |
3294 | _nc_warning("sgr(0) did not return a value"); |
3295 | } |
3296 | } else if (PRESENT(exit_attribute_mode)(((tp-> Strings[39]) != (char *)0) && ((tp-> Strings [39]) != (char *)(-1))) && |
3297 | set_attributestp-> Strings[131] != CANCELLED_STRING(char *)(-1)) { |
3298 | if (_nc_syntax == SYN_TERMINFO0) |
3299 | _nc_warning("missing sgr string"); |
3300 | } |
3301 | #define CHECK_SGR0(name)check_exit_attribute("name", name, check_sgr0, tp-> Strings [39]) check_exit_attribute(#name, name, check_sgr0, exit_attribute_modetp-> Strings[39]) |
3302 | if (PRESENT(exit_attribute_mode)(((tp-> Strings[39]) != (char *)0) && ((tp-> Strings [39]) != (char *)(-1)))) { |
3303 | char *check_sgr0 = _nc_trim_sgr0(tp); |
3304 | |
3305 | if (check_sgr0 == NULL((void *)0) || *check_sgr0 == '\0') { |
3306 | _nc_warning("trimmed sgr0 is empty"); |
3307 | } else { |
3308 | show_where(2); |
3309 | if (check_sgr0 != exit_attribute_modetp-> Strings[39]) { |
3310 | DEBUG(2, |
3311 | ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s", |
3312 | _nc_visbuf2(1, exit_attribute_mode), |
3313 | _nc_visbuf2(2, check_sgr0))); |
3314 | } else { |
3315 | DEBUG(2, |
3316 | ("will not trim sgr0\n\toriginal sgr0=%s", |
3317 | _nc_visbuf(exit_attribute_mode))); |
3318 | } |
3319 | } |
3320 | #if defined(exit_italics_modetp-> Strings[321]) |
3321 | CHECK_SGR0(exit_italics_mode)check_exit_attribute("exit_italics_mode", tp-> Strings[321 ], check_sgr0, tp-> Strings[39]); |
3322 | #endif |
3323 | CHECK_SGR0(exit_standout_mode)check_exit_attribute("exit_standout_mode", tp-> Strings[43 ], check_sgr0, tp-> Strings[39]); |
3324 | CHECK_SGR0(exit_underline_mode)check_exit_attribute("exit_underline_mode", tp-> Strings[44 ], check_sgr0, tp-> Strings[39]); |
3325 | if (check_sgr0 != exit_attribute_modetp-> Strings[39]) { |
3326 | free(check_sgr0); |
3327 | } |
3328 | } |
3329 | #define CHECK_SGR_PARAM(code, name)check_sgr_param(tp, (int)code, "name", name) check_sgr_param(tp, (int)code, #name, name) |
3330 | for (j = 0; *sgr_names[j] != '\0'; ++j) { |
3331 | CHECK_SGR_PARAM(j, set_a_foreground)check_sgr_param(tp, (int)j, "set_a_foreground", tp-> Strings [359]); |
3332 | CHECK_SGR_PARAM(j, set_a_background)check_sgr_param(tp, (int)j, "set_a_background", tp-> Strings [360]); |
3333 | CHECK_SGR_PARAM(j, set_foreground)check_sgr_param(tp, (int)j, "set_foreground", tp-> Strings [302]); |
3334 | CHECK_SGR_PARAM(j, set_background)check_sgr_param(tp, (int)j, "set_background", tp-> Strings [303]); |
3335 | } |
3336 | #ifdef TRACE |
3337 | show_where(2); |
3338 | if (!auto_right_margintp-> Booleans[1]) { |
3339 | DEBUG(2, |
3340 | ("can write to lower-right directly")); |
3341 | } else if (PRESENT(enter_am_mode)(((tp-> Strings[151]) != (char *)0) && ((tp-> Strings [151]) != (char *)(-1))) && PRESENT(exit_am_mode)(((tp-> Strings[152]) != (char *)0) && ((tp-> Strings [152]) != (char *)(-1)))) { |
3342 | DEBUG(2, |
3343 | ("can write to lower-right by suppressing automargin")); |
3344 | } else if ((PRESENT(enter_insert_mode)(((tp-> Strings[31]) != (char *)0) && ((tp-> Strings [31]) != (char *)(-1))) && PRESENT(exit_insert_mode)(((tp-> Strings[42]) != (char *)0) && ((tp-> Strings [42]) != (char *)(-1)))) |
3345 | || PRESENT(insert_character)(((tp-> Strings[52]) != (char *)0) && ((tp-> Strings [52]) != (char *)(-1))) || PRESENT(parm_ich)(((tp-> Strings[108]) != (char *)0) && ((tp-> Strings [108]) != (char *)(-1)))) { |
3346 | DEBUG(2, |
3347 | ("can write to lower-right by using inserts")); |
3348 | } else { |
3349 | DEBUG(2, |
3350 | ("cannot write to lower-right")); |
3351 | } |
3352 | #endif |
3353 | |
3354 | /* |
3355 | * Some standard applications (e.g., vi) and some non-curses |
3356 | * applications (e.g., jove) get confused if we have both ich1 and |
3357 | * smir/rmir. Let's be nice and warn about that, too, even though |
3358 | * ncurses handles it. |
3359 | */ |
3360 | if ((PRESENT(enter_insert_mode)(((tp-> Strings[31]) != (char *)0) && ((tp-> Strings [31]) != (char *)(-1))) || PRESENT(exit_insert_mode)(((tp-> Strings[42]) != (char *)0) && ((tp-> Strings [42]) != (char *)(-1)))) |
3361 | && PRESENT(insert_character)(((tp-> Strings[52]) != (char *)0) && ((tp-> Strings [52]) != (char *)(-1)))) { |
3362 | _nc_warning("non-curses applications may be confused by ich1 with smir/rmir"); |
3363 | } |
3364 | |
3365 | /* |
3366 | * Finally, do the non-verbose checks |
3367 | */ |
3368 | if (save_check_termtype != 0) |
3369 | save_check_termtype(tp, literal); |
3370 | } |