]> ncurses.scripts.mit.edu Git - ncurses.git/blob - progs/tic.c
ncurses 5.7 - patch 20091219
[ncurses.git] / progs / tic.c
1 /****************************************************************************
2  * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Thomas E. Dickey                        1996 on                 *
33  ****************************************************************************/
34
35 /*
36  *      tic.c --- Main program for terminfo compiler
37  *                      by Eric S. Raymond
38  *
39  */
40
41 #include <progs.priv.h>
42 #include <sys/stat.h>
43
44 #include <dump_entry.h>
45 #include <transform.h>
46
47 MODULE_ID("$Id: tic.c,v 1.139 2009/12/12 17:30:12 Nicholas.Marriott Exp $")
48
49 const char *_nc_progname = "tic";
50
51 static FILE *log_fp;
52 static FILE *tmp_fp;
53 static bool capdump = FALSE;    /* running as infotocap? */
54 static bool infodump = FALSE;   /* running as captoinfo? */
55 static bool showsummary = FALSE;
56 static const char *to_remove;
57
58 static void (*save_check_termtype) (TERMTYPE *, bool);
59 static void check_termtype(TERMTYPE *tt, bool);
60
61 static const char usage_string[] = "\
62 [-e names] \
63 [-o dir] \
64 [-R name] \
65 [-v[n]] \
66 [-V] \
67 [-w[n]] \
68 [-\
69 1\
70 a\
71 C\
72 c\
73 f\
74 G\
75 g\
76 I\
77 L\
78 N\
79 r\
80 s\
81 T\
82 t\
83 U\
84 x\
85 ] \
86 source-file\n";
87
88 #if NO_LEAKS
89 static void
90 free_namelist(char **src)
91 {
92     if (src != 0) {
93         int n;
94         for (n = 0; src[n] != 0; ++n)
95             free(src[n]);
96         free(src);
97     }
98 }
99 #endif
100
101 static void
102 cleanup(char **namelst GCC_UNUSED)
103 {
104 #if NO_LEAKS
105     free_namelist(namelst);
106 #endif
107     if (tmp_fp != 0)
108         fclose(tmp_fp);
109     if (to_remove != 0) {
110 #if HAVE_REMOVE
111         remove(to_remove);
112 #else
113         unlink(to_remove);
114 #endif
115     }
116 }
117
118 static void
119 failed(const char *msg)
120 {
121     perror(msg);
122     cleanup((char **) 0);
123     ExitProgram(EXIT_FAILURE);
124 }
125
126 static void
127 usage(void)
128 {
129     static const char *const tbl[] =
130     {
131         "Options:",
132         "  -1         format translation output one capability per line",
133 #if NCURSES_XNAMES
134         "  -a         retain commented-out capabilities (sets -x also)",
135 #endif
136         "  -C         translate entries to termcap source form",
137         "  -c         check only, validate input without compiling or translating",
138         "  -e<names>  translate/compile only entries named by comma-separated list",
139         "  -f         format complex strings for readability",
140         "  -G         format %{number} to %'char'",
141         "  -g         format %'char' to %{number}",
142         "  -I         translate entries to terminfo source form",
143         "  -L         translate entries to full terminfo source form",
144         "  -N         disable smart defaults for source translation",
145         "  -o<dir>    set output directory for compiled entry writes",
146         "  -R<name>   restrict translation to given terminfo/termcap version",
147         "  -r         force resolution of all use entries in source translation",
148         "  -s         print summary statistics",
149         "  -T         remove size-restrictions on compiled description",
150 #if NCURSES_XNAMES
151         "  -t         suppress commented-out capabilities",
152 #endif
153         "  -U         suppress post-processing of entries",
154         "  -V         print version",
155         "  -v[n]      set verbosity level",
156         "  -w[n]      set format width for translation output",
157 #if NCURSES_XNAMES
158         "  -x         treat unknown capabilities as user-defined",
159 #endif
160         "",
161         "Parameters:",
162         "  <file>     file to translate or compile"
163     };
164     size_t j;
165
166     fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
167     for (j = 0; j < SIZEOF(tbl); j++) {
168         fputs(tbl[j], stderr);
169         putc('\n', stderr);
170     }
171     ExitProgram(EXIT_FAILURE);
172 }
173
174 #define L_BRACE '{'
175 #define R_BRACE '}'
176 #define S_QUOTE '\'';
177
178 static void
179 write_it(ENTRY * ep)
180 {
181     unsigned n;
182     int ch;
183     char *s, *d, *t;
184     char result[MAX_ENTRY_SIZE];
185
186     /*
187      * Look for strings that contain %{number}, convert them to %'char',
188      * which is shorter and runs a little faster.
189      */
190     for (n = 0; n < STRCOUNT; n++) {
191         s = ep->tterm.Strings[n];
192         if (VALID_STRING(s)
193             && strchr(s, L_BRACE) != 0) {
194             d = result;
195             t = s;
196             while ((ch = *t++) != 0) {
197                 *d++ = (char) ch;
198                 if (ch == '\\') {
199                     *d++ = *t++;
200                 } else if ((ch == '%')
201                            && (*t == L_BRACE)) {
202                     char *v = 0;
203                     long value = strtol(t + 1, &v, 0);
204                     if (v != 0
205                         && *v == R_BRACE
206                         && value > 0
207                         && value != '\\'        /* FIXME */
208                         && value < 127
209                         && isprint((int) value)) {
210                         *d++ = S_QUOTE;
211                         *d++ = (char) value;
212                         *d++ = S_QUOTE;
213                         t = (v + 1);
214                     }
215                 }
216             }
217             *d = 0;
218             if (strlen(result) < strlen(s))
219                 strcpy(s, result);
220         }
221     }
222
223     _nc_set_type(_nc_first_name(ep->tterm.term_names));
224     _nc_curr_line = ep->startline;
225     _nc_write_entry(&ep->tterm);
226 }
227
228 static bool
229 immedhook(ENTRY * ep GCC_UNUSED)
230 /* write out entries with no use capabilities immediately to save storage */
231 {
232 #if !HAVE_BIG_CORE
233     /*
234      * This is strictly a core-economy kluge.  The really clean way to handle
235      * compilation is to slurp the whole file into core and then do all the
236      * name-collision checks and entry writes in one swell foop.  But the
237      * terminfo master file is large enough that some core-poor systems swap
238      * like crazy when you compile it this way...there have been reports of
239      * this process taking *three hours*, rather than the twenty seconds or
240      * less typical on my development box.
241      *
242      * So.  This hook *immediately* writes out the referenced entry if it
243      * has no use capabilities.  The compiler main loop refrains from
244      * adding the entry to the in-core list when this hook fires.  If some
245      * other entry later needs to reference an entry that got written
246      * immediately, that's OK; the resolution code will fetch it off disk
247      * when it can't find it in core.
248      *
249      * Name collisions will still be detected, just not as cleanly.  The
250      * write_entry() code complains before overwriting an entry that
251      * postdates the time of tic's first call to write_entry().  Thus
252      * it will complain about overwriting entries newly made during the
253      * tic run, but not about overwriting ones that predate it.
254      *
255      * The reason this is a hook, and not in line with the rest of the
256      * compiler code, is that the support for termcap fallback cannot assume
257      * it has anywhere to spool out these entries!
258      *
259      * The _nc_set_type() call here requires a compensating one in
260      * _nc_parse_entry().
261      *
262      * If you define HAVE_BIG_CORE, you'll disable this kluge.  This will
263      * make tic a bit faster (because the resolution code won't have to do
264      * disk I/O nearly as often).
265      */
266     if (ep->nuses == 0) {
267         int oldline = _nc_curr_line;
268
269         write_it(ep);
270         _nc_curr_line = oldline;
271         free(ep->tterm.str_table);
272         return (TRUE);
273     }
274 #endif /* HAVE_BIG_CORE */
275     return (FALSE);
276 }
277
278 static void
279 put_translate(int c)
280 /* emit a comment char, translating terminfo names to termcap names */
281 {
282     static bool in_name = FALSE;
283     static size_t have, used;
284     static char *namebuf, *suffix;
285
286     if (in_name) {
287         if (used + 1 >= have) {
288             have += 132;
289             namebuf = typeRealloc(char, have, namebuf);
290             suffix = typeRealloc(char, have, suffix);
291         }
292         if (c == '\n' || c == '@') {
293             namebuf[used++] = '\0';
294             (void) putchar('<');
295             (void) fputs(namebuf, stdout);
296             putchar(c);
297             in_name = FALSE;
298         } else if (c != '>') {
299             namebuf[used++] = (char) c;
300         } else {                /* ah! candidate name! */
301             char *up;
302             NCURSES_CONST char *tp;
303
304             namebuf[used++] = '\0';
305             in_name = FALSE;
306
307             suffix[0] = '\0';
308             if ((up = strchr(namebuf, '#')) != 0
309                 || (up = strchr(namebuf, '=')) != 0
310                 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
311                 (void) strcpy(suffix, up);
312                 *up = '\0';
313             }
314
315             if ((tp = nametrans(namebuf)) != 0) {
316                 (void) putchar(':');
317                 (void) fputs(tp, stdout);
318                 (void) fputs(suffix, stdout);
319                 (void) putchar(':');
320             } else {
321                 /* couldn't find a translation, just dump the name */
322                 (void) putchar('<');
323                 (void) fputs(namebuf, stdout);
324                 (void) fputs(suffix, stdout);
325                 (void) putchar('>');
326             }
327         }
328     } else {
329         used = 0;
330         if (c == '<') {
331             in_name = TRUE;
332         } else {
333             putchar(c);
334         }
335     }
336 }
337
338 /* Returns a string, stripped of leading/trailing whitespace */
339 static char *
340 stripped(char *src)
341 {
342     while (isspace(UChar(*src)))
343         src++;
344     if (*src != '\0') {
345         char *dst;
346         size_t len;
347
348         if ((dst = strdup(src)) == NULL)
349             failed("strdup");
350         len = strlen(dst);
351         while (--len != 0 && isspace(UChar(dst[len])))
352             dst[len] = '\0';
353         return dst;
354     }
355     return 0;
356 }
357
358 static FILE *
359 open_input(const char *filename)
360 {
361     FILE *fp = fopen(filename, "r");
362     struct stat sb;
363
364     if (fp == 0) {
365         fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
366         ExitProgram(EXIT_FAILURE);
367     }
368     if (fstat(fileno(fp), &sb) < 0
369         || (sb.st_mode & S_IFMT) != S_IFREG) {
370         fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
371         ExitProgram(EXIT_FAILURE);
372     }
373     return fp;
374 }
375
376 /* Parse the "-e" option-value into a list of names */
377 static char **
378 make_namelist(char *src)
379 {
380     char **dst = 0;
381
382     char *s, *base;
383     unsigned pass, n, nn;
384     char buffer[BUFSIZ];
385
386     if (src == 0) {
387         /* EMPTY */ ;
388     } else if (strchr(src, '/') != 0) {         /* a filename */
389         FILE *fp = open_input(src);
390
391         for (pass = 1; pass <= 2; pass++) {
392             nn = 0;
393             while (fgets(buffer, sizeof(buffer), fp) != 0) {
394                 if ((s = stripped(buffer)) != 0) {
395                     if (dst != 0)
396                         dst[nn] = s;
397                     else
398                         free(s);
399                     nn++;
400                 }
401             }
402             if (pass == 1) {
403                 dst = typeCalloc(char *, nn + 1);
404                 rewind(fp);
405             }
406         }
407         fclose(fp);
408     } else {                    /* literal list of names */
409         for (pass = 1; pass <= 2; pass++) {
410             for (n = nn = 0, base = src;; n++) {
411                 int mark = src[n];
412                 if (mark == ',' || mark == '\0') {
413                     if (pass == 1) {
414                         nn++;
415                     } else {
416                         src[n] = '\0';
417                         if ((s = stripped(base)) != 0)
418                             dst[nn++] = s;
419                         base = &src[n + 1];
420                     }
421                 }
422                 if (mark == '\0')
423                     break;
424             }
425             if (pass == 1)
426                 dst = typeCalloc(char *, nn + 1);
427         }
428     }
429     if (showsummary && (dst != 0)) {
430         fprintf(log_fp, "Entries that will be compiled:\n");
431         for (n = 0; dst[n] != 0; n++)
432             fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
433     }
434     return dst;
435 }
436
437 static bool
438 matches(char **needle, const char *haystack)
439 /* does entry in needle list match |-separated field in haystack? */
440 {
441     bool code = FALSE;
442     size_t n;
443
444     if (needle != 0) {
445         for (n = 0; needle[n] != 0; n++) {
446             if (_nc_name_match(haystack, needle[n], "|")) {
447                 code = TRUE;
448                 break;
449             }
450         }
451     } else
452         code = TRUE;
453     return (code);
454 }
455
456 static FILE *
457 open_tempfile(char *name)
458 {
459     FILE *result = 0;
460 #if HAVE_MKSTEMP
461     int fd = mkstemp(name);
462     if (fd >= 0)
463         result = fdopen(fd, "w");
464 #else
465     if (tmpnam(name) != 0)
466         result = fopen(name, "w");
467 #endif
468     return result;
469 }
470
471 int
472 main(int argc, char *argv[])
473 {
474     char my_tmpname[PATH_MAX];
475     int v_opt = -1, debug_level;
476     int smart_defaults = TRUE;
477     char *termcap;
478     ENTRY *qp;
479
480     int this_opt, last_opt = '?';
481
482     int outform = F_TERMINFO;   /* output format */
483     int sortmode = S_TERMINFO;  /* sort_mode */
484
485     int width = 60;
486     bool formatted = FALSE;     /* reformat complex strings? */
487     bool literal = FALSE;       /* suppress post-processing? */
488     int numbers = 0;            /* format "%'char'" to/from "%{number}" */
489     bool forceresolve = FALSE;  /* force resolution */
490     bool limited = TRUE;
491     char *tversion = (char *) NULL;
492     const char *source_file = "terminfo";
493     char **namelst = 0;
494     char *outdir = (char *) NULL;
495     bool check_only = FALSE;
496     bool suppress_untranslatable = FALSE;
497
498     log_fp = stderr;
499
500     _nc_progname = _nc_rootname(argv[0]);
501
502     if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
503         outform = F_TERMINFO;
504         sortmode = S_TERMINFO;
505     }
506     if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
507         outform = F_TERMCAP;
508         sortmode = S_TERMCAP;
509     }
510 #if NCURSES_XNAMES
511     use_extended_names(FALSE);
512 #endif
513
514     /*
515      * Processing arguments is a little complicated, since someone made a
516      * design decision to allow the numeric values for -w, -v options to
517      * be optional.
518      */
519     while ((this_opt = getopt(argc, argv,
520                               "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
521         if (isdigit(this_opt)) {
522             switch (last_opt) {
523             case 'v':
524                 v_opt = (v_opt * 10) + (this_opt - '0');
525                 break;
526             case 'w':
527                 width = (width * 10) + (this_opt - '0');
528                 break;
529             default:
530                 if (this_opt != '1')
531                     usage();
532                 last_opt = this_opt;
533                 width = 0;
534             }
535             continue;
536         }
537         switch (this_opt) {
538         case 'C':
539             capdump = TRUE;
540             outform = F_TERMCAP;
541             sortmode = S_TERMCAP;
542             break;
543         case 'I':
544             infodump = TRUE;
545             outform = F_TERMINFO;
546             sortmode = S_TERMINFO;
547             break;
548         case 'L':
549             infodump = TRUE;
550             outform = F_VARIABLE;
551             sortmode = S_VARIABLE;
552             break;
553         case 'N':
554             smart_defaults = FALSE;
555             literal = TRUE;
556             break;
557         case 'R':
558             tversion = optarg;
559             break;
560         case 'T':
561             limited = FALSE;
562             break;
563         case 'U':
564             literal = TRUE;
565             break;
566         case 'V':
567             puts(curses_version());
568             cleanup(namelst);
569             ExitProgram(EXIT_SUCCESS);
570         case 'c':
571             check_only = TRUE;
572             break;
573         case 'e':
574             namelst = make_namelist(optarg);
575             break;
576         case 'f':
577             formatted = TRUE;
578             break;
579         case 'G':
580             numbers = 1;
581             break;
582         case 'g':
583             numbers = -1;
584             break;
585         case 'o':
586             outdir = optarg;
587             break;
588         case 'r':
589             forceresolve = TRUE;
590             break;
591         case 's':
592             showsummary = TRUE;
593             break;
594         case 'v':
595             v_opt = 0;
596             break;
597         case 'w':
598             width = 0;
599             break;
600 #if NCURSES_XNAMES
601         case 't':
602             _nc_disable_period = FALSE;
603             suppress_untranslatable = TRUE;
604             break;
605         case 'a':
606             _nc_disable_period = TRUE;
607             /* FALLTHRU */
608         case 'x':
609             use_extended_names(TRUE);
610             break;
611 #endif
612         default:
613             usage();
614         }
615         last_opt = this_opt;
616     }
617
618     debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
619     set_trace_level(debug_level);
620
621     if (_nc_tracing) {
622         save_check_termtype = _nc_check_termtype2;
623         _nc_check_termtype2 = check_termtype;
624     }
625 #if !HAVE_BIG_CORE
626     /*
627      * Aaargh! immedhook seriously hoses us!
628      *
629      * One problem with immedhook is it means we can't do -e.  Problem
630      * is that we can't guarantee that for each terminal listed, all the
631      * terminals it depends on will have been kept in core for reference
632      * resolution -- in fact it's certain the primitive types at the end
633      * of reference chains *won't* be in core unless they were explicitly
634      * in the select list themselves.
635      */
636     if (namelst && (!infodump && !capdump)) {
637         (void) fprintf(stderr,
638                        "Sorry, -e can't be used without -I or -C\n");
639         cleanup(namelst);
640         ExitProgram(EXIT_FAILURE);
641     }
642 #endif /* HAVE_BIG_CORE */
643
644     if (optind < argc) {
645         source_file = argv[optind++];
646         if (optind < argc) {
647             fprintf(stderr,
648                     "%s: Too many file names.  Usage:\n\t%s %s",
649                     _nc_progname,
650                     _nc_progname,
651                     usage_string);
652             ExitProgram(EXIT_FAILURE);
653         }
654     } else {
655         if (infodump == TRUE) {
656             /* captoinfo's no-argument case */
657             source_file = "/etc/termcap";
658             if ((termcap = getenv("TERMCAP")) != 0
659                 && (namelst = make_namelist(getenv("TERM"))) != 0) {
660                 if (access(termcap, F_OK) == 0) {
661                     /* file exists */
662                     source_file = termcap;
663                 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
664                                                           "/tmp/XXXXXX")))
665                            != 0) {
666                     source_file = my_tmpname;
667                     fprintf(tmp_fp, "%s\n", termcap);
668                     fclose(tmp_fp);
669                     tmp_fp = open_input(source_file);
670                     to_remove = source_file;
671                 } else {
672                     failed("tmpnam");
673                 }
674             }
675         } else {
676             /* tic */
677             fprintf(stderr,
678                     "%s: File name needed.  Usage:\n\t%s %s",
679                     _nc_progname,
680                     _nc_progname,
681                     usage_string);
682             cleanup(namelst);
683             ExitProgram(EXIT_FAILURE);
684         }
685     }
686
687     if (tmp_fp == 0)
688         tmp_fp = open_input(source_file);
689
690     if (infodump)
691         dump_init(tversion,
692                   smart_defaults
693                   ? outform
694                   : F_LITERAL,
695                   sortmode, width, debug_level, formatted);
696     else if (capdump)
697         dump_init(tversion,
698                   outform,
699                   sortmode, width, debug_level, FALSE);
700
701     /* parse entries out of the source file */
702     _nc_set_source(source_file);
703 #if !HAVE_BIG_CORE
704     if (!(check_only || infodump || capdump))
705         _nc_set_writedir(outdir);
706 #endif /* HAVE_BIG_CORE */
707     _nc_read_entry_source(tmp_fp, (char *) NULL,
708                           !smart_defaults || literal, FALSE,
709                           ((check_only || infodump || capdump)
710                            ? NULLHOOK
711                            : immedhook));
712
713     /* do use resolution */
714     if (check_only || (!infodump && !capdump) || forceresolve) {
715         if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
716             cleanup(namelst);
717             ExitProgram(EXIT_FAILURE);
718         }
719     }
720
721     /* length check */
722     if (check_only && (capdump || infodump)) {
723         for_entry_list(qp) {
724             if (matches(namelst, qp->tterm.term_names)) {
725                 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
726
727                 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
728                     (void) fprintf(stderr,
729                                    "warning: resolved %s entry is %d bytes long\n",
730                                    _nc_first_name(qp->tterm.term_names),
731                                    len);
732             }
733         }
734     }
735
736     /* write or dump all entries */
737     if (!check_only) {
738         if (!infodump && !capdump) {
739             _nc_set_writedir(outdir);
740             for_entry_list(qp) {
741                 if (matches(namelst, qp->tterm.term_names))
742                     write_it(qp);
743             }
744         } else {
745             /* this is in case infotocap() generates warnings */
746             _nc_curr_col = _nc_curr_line = -1;
747
748             for_entry_list(qp) {
749                 if (matches(namelst, qp->tterm.term_names)) {
750                     int j = qp->cend - qp->cstart;
751                     int len = 0;
752
753                     /* this is in case infotocap() generates warnings */
754                     _nc_set_type(_nc_first_name(qp->tterm.term_names));
755
756                     (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
757                     while (j-- > 0) {
758                         if (infodump)
759                             (void) putchar(fgetc(tmp_fp));
760                         else
761                             put_translate(fgetc(tmp_fp));
762                     }
763
764                     dump_entry(&qp->tterm, suppress_untranslatable,
765                                limited, numbers, NULL);
766                     for (j = 0; j < (int) qp->nuses; j++)
767                         dump_uses(qp->uses[j].name, !capdump);
768                     len = show_entry();
769                     if (debug_level != 0 && !limited)
770                         printf("# length=%d\n", len);
771                 }
772             }
773             if (!namelst && _nc_tail) {
774                 int c, oldc = '\0';
775                 bool in_comment = FALSE;
776                 bool trailing_comment = FALSE;
777
778                 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
779                 while ((c = fgetc(tmp_fp)) != EOF) {
780                     if (oldc == '\n') {
781                         if (c == '#') {
782                             trailing_comment = TRUE;
783                             in_comment = TRUE;
784                         } else {
785                             in_comment = FALSE;
786                         }
787                     }
788                     if (trailing_comment
789                         && (in_comment || (oldc == '\n' && c == '\n')))
790                         putchar(c);
791                     oldc = c;
792                 }
793             }
794         }
795     }
796
797     /* Show the directory into which entries were written, and the total
798      * number of entries
799      */
800     if (showsummary
801         && (!(check_only || infodump || capdump))) {
802         int total = _nc_tic_written();
803         if (total != 0)
804             fprintf(log_fp, "%d entries written to %s\n",
805                     total,
806                     _nc_tic_dir((char *) 0));
807         else
808             fprintf(log_fp, "No entries written\n");
809     }
810     cleanup(namelst);
811     ExitProgram(EXIT_SUCCESS);
812 }
813
814 /*
815  * This bit of legerdemain turns all the terminfo variable names into
816  * references to locations in the arrays Booleans, Numbers, and Strings ---
817  * precisely what's needed (see comp_parse.c).
818  */
819 #undef CUR
820 #define CUR tp->
821
822 /*
823  * Check if the alternate character-set capabilities are consistent.
824  */
825 static void
826 check_acs(TERMTYPE *tp)
827 {
828     if (VALID_STRING(acs_chars)) {
829         const char *boxes = "lmkjtuvwqxn";
830         char mapped[256];
831         char missing[256];
832         const char *p;
833         char *q;
834
835         memset(mapped, 0, sizeof(mapped));
836         for (p = acs_chars; *p != '\0'; p += 2) {
837             if (p[1] == '\0') {
838                 _nc_warning("acsc has odd number of characters");
839                 break;
840             }
841             mapped[UChar(p[0])] = p[1];
842         }
843
844         if (mapped[UChar('I')] && !mapped[UChar('i')]) {
845             _nc_warning("acsc refers to 'I', which is probably an error");
846         }
847
848         for (p = boxes, q = missing; *p != '\0'; ++p) {
849             if (!mapped[UChar(p[0])]) {
850                 *q++ = p[0];
851             }
852         }
853         *q = '\0';
854
855         assert(strlen(missing) <= strlen(boxes));
856         if (*missing != '\0' && strcmp(missing, boxes)) {
857             _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
858         }
859     }
860 }
861
862 /*
863  * Check if the color capabilities are consistent
864  */
865 static void
866 check_colors(TERMTYPE *tp)
867 {
868     if ((max_colors > 0) != (max_pairs > 0)
869         || ((max_colors > max_pairs) && (initialize_pair == 0)))
870         _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
871                     max_colors, max_pairs);
872
873     PAIRED(set_foreground, set_background);
874     PAIRED(set_a_foreground, set_a_background);
875     PAIRED(set_color_pair, initialize_pair);
876
877     if (VALID_STRING(set_foreground)
878         && VALID_STRING(set_a_foreground)
879         && !_nc_capcmp(set_foreground, set_a_foreground))
880         _nc_warning("expected setf/setaf to be different");
881
882     if (VALID_STRING(set_background)
883         && VALID_STRING(set_a_background)
884         && !_nc_capcmp(set_background, set_a_background))
885         _nc_warning("expected setb/setab to be different");
886
887     /* see: has_colors() */
888     if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
889         && (((set_foreground != NULL)
890              && (set_background != NULL))
891             || ((set_a_foreground != NULL)
892                 && (set_a_background != NULL))
893             || set_color_pair)) {
894         if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
895             _nc_warning("expected either op/oc string for resetting colors");
896     }
897 }
898
899 static char
900 keypad_final(const char *string)
901 {
902     char result = '\0';
903
904     if (VALID_STRING(string)
905         && *string++ == '\033'
906         && *string++ == 'O'
907         && strlen(string) == 1) {
908         result = *string;
909     }
910
911     return result;
912 }
913
914 static int
915 keypad_index(const char *string)
916 {
917     char *test;
918     const char *list = "PQRSwxymtuvlqrsPpn";    /* app-keypad except "Enter" */
919     int ch;
920     int result = -1;
921
922     if ((ch = keypad_final(string)) != '\0') {
923         test = strchr(list, ch);
924         if (test != 0)
925             result = (test - list);
926     }
927     return result;
928 }
929
930 #define MAX_KP 5
931 /*
932  * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
933  * is mapped inconsistently.
934  */
935 static void
936 check_keypad(TERMTYPE *tp)
937 {
938     char show[80];
939
940     if (VALID_STRING(key_a1) &&
941         VALID_STRING(key_a3) &&
942         VALID_STRING(key_b2) &&
943         VALID_STRING(key_c1) &&
944         VALID_STRING(key_c3)) {
945         char final[MAX_KP + 1];
946         int list[MAX_KP];
947         int increase = 0;
948         int j, k, kk;
949         int last;
950         int test;
951
952         final[0] = keypad_final(key_a1);
953         final[1] = keypad_final(key_a3);
954         final[2] = keypad_final(key_b2);
955         final[3] = keypad_final(key_c1);
956         final[4] = keypad_final(key_c3);
957         final[5] = '\0';
958
959         /* special case: legacy coding using 1,2,3,0,. on the bottom */
960         assert(strlen(final) <= MAX_KP);
961         if (!strcmp(final, "qsrpn"))
962             return;
963
964         list[0] = keypad_index(key_a1);
965         list[1] = keypad_index(key_a3);
966         list[2] = keypad_index(key_b2);
967         list[3] = keypad_index(key_c1);
968         list[4] = keypad_index(key_c3);
969
970         /* check that they're all vt100 keys */
971         for (j = 0; j < MAX_KP; ++j) {
972             if (list[j] < 0) {
973                 return;
974             }
975         }
976
977         /* check if they're all in increasing order */
978         for (j = 1; j < MAX_KP; ++j) {
979             if (list[j] > list[j - 1]) {
980                 ++increase;
981             }
982         }
983         if (increase != (MAX_KP - 1)) {
984             show[0] = '\0';
985
986             for (j = 0, last = -1; j < MAX_KP; ++j) {
987                 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
988                     if (list[k] > last &&
989                         list[k] < test) {
990                         test = list[k];
991                         kk = k;
992                     }
993                 }
994                 last = test;
995                 assert(strlen(show) < (MAX_KP * 4));
996                 switch (kk) {
997                 case 0:
998                     strcat(show, " ka1");
999                     break;
1000                 case 1:
1001                     strcat(show, " ka3");
1002                     break;
1003                 case 2:
1004                     strcat(show, " kb2");
1005                     break;
1006                 case 3:
1007                     strcat(show, " kc1");
1008                     break;
1009                 case 4:
1010                     strcat(show, " kc3");
1011                     break;
1012                 }
1013             }
1014
1015             _nc_warning("vt100 keypad order inconsistent: %s", show);
1016         }
1017
1018     } else if (VALID_STRING(key_a1) ||
1019                VALID_STRING(key_a3) ||
1020                VALID_STRING(key_b2) ||
1021                VALID_STRING(key_c1) ||
1022                VALID_STRING(key_c3)) {
1023         show[0] = '\0';
1024         if (keypad_index(key_a1) >= 0)
1025             strcat(show, " ka1");
1026         if (keypad_index(key_a3) >= 0)
1027             strcat(show, " ka3");
1028         if (keypad_index(key_b2) >= 0)
1029             strcat(show, " kb2");
1030         if (keypad_index(key_c1) >= 0)
1031             strcat(show, " kc1");
1032         if (keypad_index(key_c3) >= 0)
1033             strcat(show, " kc3");
1034         if (*show != '\0')
1035             _nc_warning("vt100 keypad map incomplete:%s", show);
1036     }
1037 }
1038
1039 /*
1040  * Returns the expected number of parameters for the given capability.
1041  */
1042 static int
1043 expected_params(const char *name)
1044 {
1045     /* *INDENT-OFF* */
1046     static const struct {
1047         const char *name;
1048         int count;
1049     } table[] = {
1050         { "S0",                 1 },    /* 'screen' extension */
1051         { "birep",              2 },
1052         { "chr",                1 },
1053         { "colornm",            1 },
1054         { "cpi",                1 },
1055         { "csnm",               1 },
1056         { "csr",                2 },
1057         { "cub",                1 },
1058         { "cud",                1 },
1059         { "cuf",                1 },
1060         { "cup",                2 },
1061         { "cuu",                1 },
1062         { "cvr",                1 },
1063         { "cwin",               5 },
1064         { "dch",                1 },
1065         { "defc",               3 },
1066         { "dial",               1 },
1067         { "dispc",              1 },
1068         { "dl",                 1 },
1069         { "ech",                1 },
1070         { "getm",               1 },
1071         { "hpa",                1 },
1072         { "ich",                1 },
1073         { "il",                 1 },
1074         { "indn",               1 },
1075         { "initc",              4 },
1076         { "initp",              7 },
1077         { "lpi",                1 },
1078         { "mc5p",               1 },
1079         { "mrcup",              2 },
1080         { "mvpa",               1 },
1081         { "pfkey",              2 },
1082         { "pfloc",              2 },
1083         { "pfx",                2 },
1084         { "pfxl",               3 },
1085         { "pln",                2 },
1086         { "qdial",              1 },
1087         { "rcsd",               1 },
1088         { "rep",                2 },
1089         { "rin",                1 },
1090         { "sclk",               3 },
1091         { "scp",                1 },
1092         { "scs",                1 },
1093         { "scsd",               2 },
1094         { "setab",              1 },
1095         { "setaf",              1 },
1096         { "setb",               1 },
1097         { "setcolor",           1 },
1098         { "setf",               1 },
1099         { "sgr",                9 },
1100         { "sgr1",               6 },
1101         { "slength",            1 },
1102         { "slines",             1 },
1103         { "smgbp",              1 },    /* 2 if smgtp is not given */
1104         { "smglp",              1 },
1105         { "smglr",              2 },
1106         { "smgrp",              1 },
1107         { "smgtb",              2 },
1108         { "smgtp",              1 },
1109         { "tsl",                1 },
1110         { "u6",                 -1 },
1111         { "vpa",                1 },
1112         { "wind",               4 },
1113         { "wingo",              1 },
1114     };
1115     /* *INDENT-ON* */
1116
1117     unsigned n;
1118     int result = 0;             /* function-keys, etc., use none */
1119
1120     for (n = 0; n < SIZEOF(table); n++) {
1121         if (!strcmp(name, table[n].name)) {
1122             result = table[n].count;
1123             break;
1124         }
1125     }
1126
1127     return result;
1128 }
1129
1130 /*
1131  * Make a quick sanity check for the parameters which are used in the given
1132  * strings.  If there are no "%p" tokens, then there should be no other "%"
1133  * markers.
1134  */
1135 static void
1136 check_params(TERMTYPE *tp, const char *name, char *value)
1137 {
1138     int expected = expected_params(name);
1139     int actual = 0;
1140     int n;
1141     bool params[10];
1142     char *s = value;
1143
1144 #ifdef set_top_margin_parm
1145     if (!strcmp(name, "smgbp")
1146         && set_top_margin_parm == 0)
1147         expected = 2;
1148 #endif
1149
1150     for (n = 0; n < 10; n++)
1151         params[n] = FALSE;
1152
1153     while (*s != 0) {
1154         if (*s == '%') {
1155             if (*++s == '\0') {
1156                 _nc_warning("expected character after %% in %s", name);
1157                 break;
1158             } else if (*s == 'p') {
1159                 if (*++s == '\0' || !isdigit((int) *s)) {
1160                     _nc_warning("expected digit after %%p in %s", name);
1161                     return;
1162                 } else {
1163                     n = (*s - '0');
1164                     if (n > actual)
1165                         actual = n;
1166                     params[n] = TRUE;
1167                 }
1168             }
1169         }
1170         s++;
1171     }
1172
1173     if (params[0]) {
1174         _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1175     }
1176     if (value == set_attributes || expected < 0) {
1177         ;
1178     } else if (expected != actual) {
1179         _nc_warning("%s uses %d parameters, expected %d", name,
1180                     actual, expected);
1181         for (n = 1; n < actual; n++) {
1182             if (!params[n])
1183                 _nc_warning("%s omits parameter %d", name, n);
1184         }
1185     }
1186 }
1187
1188 static char *
1189 skip_delay(char *s)
1190 {
1191     while (*s == '/' || isdigit(UChar(*s)))
1192         ++s;
1193     return s;
1194 }
1195
1196 /*
1197  * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1198  * the latter may have a worst-case delay on the end.
1199  */
1200 static char *
1201 ignore_delays(char *s)
1202 {
1203     int delaying = 0;
1204
1205     do {
1206         switch (*s) {
1207         case '$':
1208             if (delaying == 0)
1209                 delaying = 1;
1210             break;
1211         case '<':
1212             if (delaying == 1)
1213                 delaying = 2;
1214             break;
1215         case '\0':
1216             delaying = 0;
1217             break;
1218         default:
1219             if (delaying) {
1220                 s = skip_delay(s);
1221                 if (*s == '>')
1222                     ++s;
1223                 delaying = 0;
1224             }
1225             break;
1226         }
1227         if (delaying)
1228             ++s;
1229     } while (delaying);
1230     return s;
1231 }
1232
1233 /*
1234  * An sgr string may contain several settings other than the one we're
1235  * interested in, essentially sgr0 + rmacs + whatever.  As long as the
1236  * "whatever" is contained in the sgr string, that is close enough for our
1237  * sanity check.
1238  */
1239 static bool
1240 similar_sgr(int num, char *a, char *b)
1241 {
1242     static const char *names[] =
1243     {
1244         "none"
1245         ,"standout"
1246         ,"underline"
1247         ,"reverse"
1248         ,"blink"
1249         ,"dim"
1250         ,"bold"
1251         ,"invis"
1252         ,"protect"
1253         ,"altcharset"
1254     };
1255     char *base_a = a;
1256     char *base_b = b;
1257     int delaying = 0;
1258
1259     while (*b != 0) {
1260         while (*a != *b) {
1261             if (*a == 0) {
1262                 if (b[0] == '$'
1263                     && b[1] == '<') {
1264                     _nc_warning("Did not find delay %s", _nc_visbuf(b));
1265                 } else {
1266                     _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
1267                                 names[num], _nc_visbuf2(1, base_a),
1268                                 _nc_visbuf2(2, base_b),
1269                                 _nc_visbuf2(3, b));
1270                 }
1271                 return FALSE;
1272             } else if (delaying) {
1273                 a = skip_delay(a);
1274                 b = skip_delay(b);
1275             } else {
1276                 a++;
1277             }
1278         }
1279         switch (*a) {
1280         case '$':
1281             if (delaying == 0)
1282                 delaying = 1;
1283             break;
1284         case '<':
1285             if (delaying == 1)
1286                 delaying = 2;
1287             break;
1288         default:
1289             delaying = 0;
1290             break;
1291         }
1292         a++;
1293         b++;
1294     }
1295     /* ignore delays on the end of the string */
1296     a = ignore_delays(a);
1297     return ((num != 0) || (*a == 0));
1298 }
1299
1300 static char *
1301 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1302 {
1303     char *test;
1304
1305     _nc_tparm_err = 0;
1306     test = TPARM_9(set_attributes,
1307                    num == 1,
1308                    num == 2,
1309                    num == 3,
1310                    num == 4,
1311                    num == 5,
1312                    num == 6,
1313                    num == 7,
1314                    num == 8,
1315                    num == 9);
1316     if (test != 0) {
1317         if (PRESENT(cap)) {
1318             if (!similar_sgr(num, test, cap)) {
1319                 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1320                             name, num,
1321                             name, _nc_visbuf2(1, cap),
1322                             num, _nc_visbuf2(2, test));
1323             }
1324         } else if (_nc_capcmp(test, zero)) {
1325             _nc_warning("sgr(%d) present, but not %s", num, name);
1326         }
1327     } else if (PRESENT(cap)) {
1328         _nc_warning("sgr(%d) missing, but %s present", num, name);
1329     }
1330     if (_nc_tparm_err)
1331         _nc_warning("stack error in sgr(%d) string", num);
1332     return test;
1333 }
1334
1335 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1336
1337 #ifdef TRACE
1338 /*
1339  * If tic is compiled with TRACE, we'll be able to see the output from the
1340  * DEBUG() macro.  But since it doesn't use traceon(), it always goes to
1341  * the standard error.  Use this function to make it simpler to follow the
1342  * resulting debug traces.
1343  */
1344 static void
1345 show_where(unsigned level)
1346 {
1347     if (_nc_tracing >= DEBUG_LEVEL(level)) {
1348         char my_name[256];
1349         _nc_get_type(my_name);
1350         fprintf(stderr, "\"%s\", line %d, '%s' ",
1351                 _nc_get_source(),
1352                 _nc_curr_line, my_name);
1353     }
1354 }
1355
1356 #else
1357 #define show_where(level)       /* nothing */
1358 #endif
1359
1360 /* other sanity-checks (things that we don't want in the normal
1361  * logic that reads a terminfo entry)
1362  */
1363 static void
1364 check_termtype(TERMTYPE *tp, bool literal)
1365 {
1366     bool conflict = FALSE;
1367     unsigned j, k;
1368     char fkeys[STRCOUNT];
1369
1370     /*
1371      * A terminal entry may contain more than one keycode assigned to
1372      * a given string (e.g., KEY_END and KEY_LL).  But curses will only
1373      * return one (the last one assigned).
1374      */
1375     if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1376         memset(fkeys, 0, sizeof(fkeys));
1377         for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1378             char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1379             bool first = TRUE;
1380             if (!VALID_STRING(a))
1381                 continue;
1382             for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1383                 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1384                 if (!VALID_STRING(b)
1385                     || fkeys[k])
1386                     continue;
1387                 if (!_nc_capcmp(a, b)) {
1388                     fkeys[j] = 1;
1389                     fkeys[k] = 1;
1390                     if (first) {
1391                         if (!conflict) {
1392                             _nc_warning("Conflicting key definitions (using the last)");
1393                             conflict = TRUE;
1394                         }
1395                         fprintf(stderr, "... %s is the same as %s",
1396                                 keyname((int) _nc_tinfo_fkeys[j].code),
1397                                 keyname((int) _nc_tinfo_fkeys[k].code));
1398                         first = FALSE;
1399                     } else {
1400                         fprintf(stderr, ", %s",
1401                                 keyname((int) _nc_tinfo_fkeys[k].code));
1402                     }
1403                 }
1404             }
1405             if (!first)
1406                 fprintf(stderr, "\n");
1407         }
1408     }
1409
1410     for (j = 0; j < NUM_STRINGS(tp); j++) {
1411         char *a = tp->Strings[j];
1412         if (VALID_STRING(a))
1413             check_params(tp, ExtStrname(tp, j, strnames), a);
1414     }
1415
1416     check_acs(tp);
1417     check_colors(tp);
1418     check_keypad(tp);
1419
1420     /*
1421      * These may be mismatched because the terminal description relies on
1422      * restoring the cursor visibility by resetting it.
1423      */
1424     ANDMISSING(cursor_invisible, cursor_normal);
1425     ANDMISSING(cursor_visible, cursor_normal);
1426
1427     if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1428         && !_nc_capcmp(cursor_visible, cursor_normal))
1429         _nc_warning("cursor_visible is same as cursor_normal");
1430
1431     /*
1432      * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1433      * given, because the cursor position after the scrolling operation is
1434      * performed is undefined.
1435      */
1436     ANDMISSING(change_scroll_region, save_cursor);
1437     ANDMISSING(change_scroll_region, restore_cursor);
1438
1439     if (PRESENT(set_attributes)) {
1440         char *zero = 0;
1441
1442         _nc_tparm_err = 0;
1443         if (PRESENT(exit_attribute_mode)) {
1444             zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1445         } else {
1446             zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1447         }
1448         if (_nc_tparm_err)
1449             _nc_warning("stack error in sgr(0) string");
1450
1451         if (zero != 0) {
1452             CHECK_SGR(1, enter_standout_mode);
1453             CHECK_SGR(2, enter_underline_mode);
1454             CHECK_SGR(3, enter_reverse_mode);
1455             CHECK_SGR(4, enter_blink_mode);
1456             CHECK_SGR(5, enter_dim_mode);
1457             CHECK_SGR(6, enter_bold_mode);
1458             CHECK_SGR(7, enter_secure_mode);
1459             CHECK_SGR(8, enter_protected_mode);
1460             CHECK_SGR(9, enter_alt_charset_mode);
1461             free(zero);
1462         } else {
1463             _nc_warning("sgr(0) did not return a value");
1464         }
1465     } else if (PRESENT(exit_attribute_mode) &&
1466                set_attributes != CANCELLED_STRING) {
1467         if (_nc_syntax == SYN_TERMINFO)
1468             _nc_warning("missing sgr string");
1469     }
1470
1471     if (PRESENT(exit_attribute_mode)) {
1472         char *check_sgr0 = _nc_trim_sgr0(tp);
1473
1474         if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1475             _nc_warning("trimmed sgr0 is empty");
1476         } else {
1477             show_where(2);
1478             if (check_sgr0 != exit_attribute_mode) {
1479                 DEBUG(2,
1480                       ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed  sgr0=%s",
1481                        _nc_visbuf2(1, exit_attribute_mode),
1482                        _nc_visbuf2(2, check_sgr0)));
1483                 free(check_sgr0);
1484             } else {
1485                 DEBUG(2,
1486                       ("will not trim sgr0\n\toriginal sgr0=%s",
1487                        _nc_visbuf(exit_attribute_mode)));
1488             }
1489         }
1490     }
1491 #ifdef TRACE
1492     show_where(2);
1493     if (!auto_right_margin) {
1494         DEBUG(2,
1495               ("can write to lower-right directly"));
1496     } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1497         DEBUG(2,
1498               ("can write to lower-right by suppressing automargin"));
1499     } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1500                || PRESENT(insert_character) || PRESENT(parm_ich)) {
1501         DEBUG(2,
1502               ("can write to lower-right by using inserts"));
1503     } else {
1504         DEBUG(2,
1505               ("cannot write to lower-right"));
1506     }
1507 #endif
1508
1509     /*
1510      * Some standard applications (e.g., vi) and some non-curses
1511      * applications (e.g., jove) get confused if we have both ich1 and
1512      * smir/rmir.  Let's be nice and warn about that, too, even though
1513      * ncurses handles it.
1514      */
1515     if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1516         && PRESENT(parm_ich)) {
1517         _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1518     }
1519
1520     /*
1521      * Finally, do the non-verbose checks
1522      */
1523     if (save_check_termtype != 0)
1524         save_check_termtype(tp, literal);
1525 }