1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
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 ****************************************************************************/
36 * tic.c --- Main program for terminfo compiler
41 #include <progs.priv.h>
44 #include <dump_entry.h>
45 #include <transform.h>
47 MODULE_ID("$Id: tic.c,v 1.131 2006/12/02 22:13:17 tom Exp $")
49 const char *_nc_progname = "tic";
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;
58 static void (*save_check_termtype) (TERMTYPE *, bool);
59 static void check_termtype(TERMTYPE *tt, bool);
61 static const char usage_string[] = "\
103 failed(const char *msg)
107 ExitProgram(EXIT_FAILURE);
113 static const char *const tbl[] =
116 " -1 format translation output one capability per line",
118 " -a retain commented-out capabilities (sets -x also)",
120 " -C translate entries to termcap source form",
121 " -c check only, validate input without compiling or translating",
122 " -e<names> translate/compile only entries named by comma-separated list",
123 " -f format complex strings for readability",
124 " -G format %{number} to %'char'",
125 " -g format %'char' to %{number}",
126 " -I translate entries to terminfo source form",
127 " -L translate entries to full terminfo source form",
128 " -N disable smart defaults for source translation",
129 " -o<dir> set output directory for compiled entry writes",
130 " -R<name> restrict translation to given terminfo/termcap version",
131 " -r force resolution of all use entries in source translation",
132 " -s print summary statistics",
133 " -T remove size-restrictions on compiled description",
135 " -t suppress commented-out capabilities",
137 " -U suppress post-processing of entries",
139 " -v[n] set verbosity level",
140 " -w[n] set format width for translation output",
142 " -x treat unknown capabilities as user-defined",
146 " <file> file to translate or compile"
150 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
151 for (j = 0; j < SIZEOF(tbl); j++) {
152 fputs(tbl[j], stderr);
155 ExitProgram(EXIT_FAILURE);
160 #define S_QUOTE '\'';
168 char result[MAX_ENTRY_SIZE];
171 * Look for strings that contain %{number}, convert them to %'char',
172 * which is shorter and runs a little faster.
174 for (n = 0; n < STRCOUNT; n++) {
175 s = ep->tterm.Strings[n];
177 && strchr(s, L_BRACE) != 0) {
180 while ((ch = *t++) != 0) {
184 } else if ((ch == '%')
185 && (*t == L_BRACE)) {
187 long value = strtol(t + 1, &v, 0);
191 && value != '\\' /* FIXME */
193 && isprint((int) value)) {
202 if (strlen(result) < strlen(s))
207 _nc_set_type(_nc_first_name(ep->tterm.term_names));
208 _nc_curr_line = ep->startline;
209 _nc_write_entry(&ep->tterm);
213 immedhook(ENTRY * ep GCC_UNUSED)
214 /* write out entries with no use capabilities immediately to save storage */
218 * This is strictly a core-economy kluge. The really clean way to handle
219 * compilation is to slurp the whole file into core and then do all the
220 * name-collision checks and entry writes in one swell foop. But the
221 * terminfo master file is large enough that some core-poor systems swap
222 * like crazy when you compile it this way...there have been reports of
223 * this process taking *three hours*, rather than the twenty seconds or
224 * less typical on my development box.
226 * So. This hook *immediately* writes out the referenced entry if it
227 * has no use capabilities. The compiler main loop refrains from
228 * adding the entry to the in-core list when this hook fires. If some
229 * other entry later needs to reference an entry that got written
230 * immediately, that's OK; the resolution code will fetch it off disk
231 * when it can't find it in core.
233 * Name collisions will still be detected, just not as cleanly. The
234 * write_entry() code complains before overwriting an entry that
235 * postdates the time of tic's first call to write_entry(). Thus
236 * it will complain about overwriting entries newly made during the
237 * tic run, but not about overwriting ones that predate it.
239 * The reason this is a hook, and not in line with the rest of the
240 * compiler code, is that the support for termcap fallback cannot assume
241 * it has anywhere to spool out these entries!
243 * The _nc_set_type() call here requires a compensating one in
246 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
247 * make tic a bit faster (because the resolution code won't have to do
248 * disk I/O nearly as often).
250 if (ep->nuses == 0) {
251 int oldline = _nc_curr_line;
254 _nc_curr_line = oldline;
255 free(ep->tterm.str_table);
258 #endif /* HAVE_BIG_CORE */
264 /* emit a comment char, translating terminfo names to termcap names */
266 static bool in_name = FALSE;
267 static size_t have, used;
268 static char *namebuf, *suffix;
271 if (used + 1 >= have) {
273 namebuf = typeRealloc(char, have, namebuf);
274 suffix = typeRealloc(char, have, suffix);
276 if (c == '\n' || c == '@') {
277 namebuf[used++] = '\0';
279 (void) fputs(namebuf, stdout);
282 } else if (c != '>') {
284 } else { /* ah! candidate name! */
286 NCURSES_CONST char *tp;
288 namebuf[used++] = '\0';
292 if ((up = strchr(namebuf, '#')) != 0
293 || (up = strchr(namebuf, '=')) != 0
294 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
295 (void) strcpy(suffix, up);
299 if ((tp = nametrans(namebuf)) != 0) {
301 (void) fputs(tp, stdout);
302 (void) fputs(suffix, stdout);
305 /* couldn't find a translation, just dump the name */
307 (void) fputs(namebuf, stdout);
308 (void) fputs(suffix, stdout);
322 /* Returns a string, stripped of leading/trailing whitespace */
326 while (isspace(UChar(*src)))
329 char *dst = strcpy((char *) malloc(strlen(src) + 1), src);
330 size_t len = strlen(dst);
331 while (--len != 0 && isspace(UChar(dst[len])))
339 open_input(const char *filename)
341 FILE *fp = fopen(filename, "r");
345 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
346 ExitProgram(EXIT_FAILURE);
348 if (fstat(fileno(fp), &sb) < 0
349 || (sb.st_mode & S_IFMT) != S_IFREG) {
350 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
351 ExitProgram(EXIT_FAILURE);
356 /* Parse the "-e" option-value into a list of names */
358 make_namelist(char *src)
360 const char **dst = 0;
363 unsigned pass, n, nn;
368 } else if (strchr(src, '/') != 0) { /* a filename */
369 FILE *fp = open_input(src);
371 for (pass = 1; pass <= 2; pass++) {
373 while (fgets(buffer, sizeof(buffer), fp) != 0) {
374 if ((s = stripped(buffer)) != 0) {
381 dst = typeCalloc(const char *, nn + 1);
386 } else { /* literal list of names */
387 for (pass = 1; pass <= 2; pass++) {
388 for (n = nn = 0, base = src;; n++) {
390 if (mark == ',' || mark == '\0') {
395 if ((s = stripped(base)) != 0)
404 dst = typeCalloc(const char *, nn + 1);
408 fprintf(log_fp, "Entries that will be compiled:\n");
409 for (n = 0; dst[n] != 0; n++)
410 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
416 matches(const char **needle, const char *haystack)
417 /* does entry in needle list match |-separated field in haystack? */
423 for (n = 0; needle[n] != 0; n++) {
424 if (_nc_name_match(haystack, needle[n], "|")) {
435 open_tempfile(char *name)
439 int fd = mkstemp(name);
441 result = fdopen(fd, "w");
443 if (tmpnam(name) != 0)
444 result = fopen(name, "w");
450 main(int argc, char *argv[])
452 char my_tmpname[PATH_MAX];
453 int v_opt = -1, debug_level;
454 int smart_defaults = TRUE;
458 int this_opt, last_opt = '?';
460 int outform = F_TERMINFO; /* output format */
461 int sortmode = S_TERMINFO; /* sort_mode */
464 bool formatted = FALSE; /* reformat complex strings? */
465 bool literal = FALSE; /* suppress post-processing? */
466 int numbers = 0; /* format "%'char'" to/from "%{number}" */
467 bool forceresolve = FALSE; /* force resolution */
469 char *tversion = (char *) NULL;
470 const char *source_file = "terminfo";
471 const char **namelst = 0;
472 char *outdir = (char *) NULL;
473 bool check_only = FALSE;
474 bool suppress_untranslatable = FALSE;
478 _nc_progname = _nc_rootname(argv[0]);
480 if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) {
481 outform = F_TERMINFO;
482 sortmode = S_TERMINFO;
484 if ((capdump = (strcmp(_nc_progname, PROG_INFOTOCAP) == 0)) != FALSE) {
486 sortmode = S_TERMCAP;
489 use_extended_names(FALSE);
493 * Processing arguments is a little complicated, since someone made a
494 * design decision to allow the numeric values for -w, -v options to
497 while ((this_opt = getopt(argc, argv,
498 "0123456789CILNR:TUVace:fGgo:rstvwx")) != EOF) {
499 if (isdigit(this_opt)) {
502 v_opt = (v_opt * 10) + (this_opt - '0');
505 width = (width * 10) + (this_opt - '0');
519 sortmode = S_TERMCAP;
523 outform = F_TERMINFO;
524 sortmode = S_TERMINFO;
528 outform = F_VARIABLE;
529 sortmode = S_VARIABLE;
532 smart_defaults = FALSE;
545 puts(curses_version());
551 namelst = make_namelist(optarg);
579 _nc_disable_period = FALSE;
580 suppress_untranslatable = TRUE;
583 _nc_disable_period = TRUE;
586 use_extended_names(TRUE);
595 debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
596 set_trace_level(debug_level);
599 save_check_termtype = _nc_check_termtype2;
600 _nc_check_termtype2 = check_termtype;
604 * Aaargh! immedhook seriously hoses us!
606 * One problem with immedhook is it means we can't do -e. Problem
607 * is that we can't guarantee that for each terminal listed, all the
608 * terminals it depends on will have been kept in core for reference
609 * resolution -- in fact it's certain the primitive types at the end
610 * of reference chains *won't* be in core unless they were explicitly
611 * in the select list themselves.
613 if (namelst && (!infodump && !capdump)) {
614 (void) fprintf(stderr,
615 "Sorry, -e can't be used without -I or -C\n");
617 ExitProgram(EXIT_FAILURE);
619 #endif /* HAVE_BIG_CORE */
622 source_file = argv[optind++];
625 "%s: Too many file names. Usage:\n\t%s %s",
629 ExitProgram(EXIT_FAILURE);
632 if (infodump == TRUE) {
633 /* captoinfo's no-argument case */
634 source_file = "/etc/termcap";
635 if ((termcap = getenv("TERMCAP")) != 0
636 && (namelst = make_namelist(getenv("TERM"))) != 0) {
637 if (access(termcap, F_OK) == 0) {
639 source_file = termcap;
640 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
643 source_file = my_tmpname;
644 fprintf(tmp_fp, "%s\n", termcap);
646 tmp_fp = open_input(source_file);
647 to_remove = source_file;
655 "%s: File name needed. Usage:\n\t%s %s",
660 ExitProgram(EXIT_FAILURE);
665 tmp_fp = open_input(source_file);
672 sortmode, width, debug_level, formatted);
676 sortmode, width, debug_level, FALSE);
678 /* parse entries out of the source file */
679 _nc_set_source(source_file);
681 if (!(check_only || infodump || capdump))
682 _nc_set_writedir(outdir);
683 #endif /* HAVE_BIG_CORE */
684 _nc_read_entry_source(tmp_fp, (char *) NULL,
685 !smart_defaults || literal, FALSE,
686 ((check_only || infodump || capdump)
690 /* do use resolution */
691 if (check_only || (!infodump && !capdump) || forceresolve) {
692 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
694 ExitProgram(EXIT_FAILURE);
699 if (check_only && (capdump || infodump)) {
701 if (matches(namelst, qp->tterm.term_names)) {
702 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
704 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
705 (void) fprintf(stderr,
706 "warning: resolved %s entry is %d bytes long\n",
707 _nc_first_name(qp->tterm.term_names),
713 /* write or dump all entries */
715 if (!infodump && !capdump) {
716 _nc_set_writedir(outdir);
718 if (matches(namelst, qp->tterm.term_names))
722 /* this is in case infotocap() generates warnings */
723 _nc_curr_col = _nc_curr_line = -1;
726 if (matches(namelst, qp->tterm.term_names)) {
727 int j = qp->cend - qp->cstart;
730 /* this is in case infotocap() generates warnings */
731 _nc_set_type(_nc_first_name(qp->tterm.term_names));
733 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
736 (void) putchar(fgetc(tmp_fp));
738 put_translate(fgetc(tmp_fp));
741 dump_entry(&qp->tterm, suppress_untranslatable,
742 limited, numbers, NULL);
743 for (j = 0; j < qp->nuses; j++)
744 dump_uses(qp->uses[j].name, !capdump);
746 if (debug_level != 0 && !limited)
747 printf("# length=%d\n", len);
750 if (!namelst && _nc_tail) {
752 bool in_comment = FALSE;
753 bool trailing_comment = FALSE;
755 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
756 while ((c = fgetc(tmp_fp)) != EOF) {
759 trailing_comment = TRUE;
766 && (in_comment || (oldc == '\n' && c == '\n')))
774 /* Show the directory into which entries were written, and the total
778 && (!(check_only || infodump || capdump))) {
779 int total = _nc_tic_written();
781 fprintf(log_fp, "%d entries written to %s\n",
783 _nc_tic_dir((char *) 0));
785 fprintf(log_fp, "No entries written\n");
788 ExitProgram(EXIT_SUCCESS);
792 * This bit of legerdemain turns all the terminfo variable names into
793 * references to locations in the arrays Booleans, Numbers, and Strings ---
794 * precisely what's needed (see comp_parse.c).
800 * Check if the alternate character-set capabilities are consistent.
803 check_acs(TERMTYPE *tp)
805 if (VALID_STRING(acs_chars)) {
806 const char *boxes = "lmkjtuvwqxn";
812 memset(mapped, 0, sizeof(mapped));
813 for (p = acs_chars; *p != '\0'; p += 2) {
815 _nc_warning("acsc has odd number of characters");
818 mapped[UChar(p[0])] = p[1];
820 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
821 _nc_warning("acsc refers to 'I', which is probably an error");
823 for (p = boxes, q = missing; *p != '\0'; ++p) {
824 if (!mapped[UChar(p[0])]) {
829 if (*missing != '\0' && strcmp(missing, boxes)) {
830 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
836 * Check if the color capabilities are consistent
839 check_colors(TERMTYPE *tp)
841 if ((max_colors > 0) != (max_pairs > 0)
842 || ((max_colors > max_pairs) && (initialize_pair == 0)))
843 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
844 max_colors, max_pairs);
846 PAIRED(set_foreground, set_background);
847 PAIRED(set_a_foreground, set_a_background);
848 PAIRED(set_color_pair, initialize_pair);
850 if (VALID_STRING(set_foreground)
851 && VALID_STRING(set_a_foreground)
852 && !_nc_capcmp(set_foreground, set_a_foreground))
853 _nc_warning("expected setf/setaf to be different");
855 if (VALID_STRING(set_background)
856 && VALID_STRING(set_a_background)
857 && !_nc_capcmp(set_background, set_a_background))
858 _nc_warning("expected setb/setab to be different");
860 /* see: has_colors() */
861 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
862 && (((set_foreground != NULL)
863 && (set_background != NULL))
864 || ((set_a_foreground != NULL)
865 && (set_a_background != NULL))
866 || set_color_pair)) {
867 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
868 _nc_warning("expected either op/oc string for resetting colors");
873 keypad_final(const char *string)
877 if (VALID_STRING(string)
878 && *string++ == '\033'
880 && strlen(string) == 1) {
888 keypad_index(const char *string)
891 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
895 if ((ch = keypad_final(string)) != '\0') {
896 test = strchr(list, ch);
898 result = (test - list);
904 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
905 * is mapped inconsistently.
908 check_keypad(TERMTYPE *tp)
912 if (VALID_STRING(key_a1) &&
913 VALID_STRING(key_a3) &&
914 VALID_STRING(key_b2) &&
915 VALID_STRING(key_c1) &&
916 VALID_STRING(key_c3)) {
924 final[0] = keypad_final(key_a1);
925 final[1] = keypad_final(key_a3);
926 final[2] = keypad_final(key_b2);
927 final[3] = keypad_final(key_c1);
928 final[4] = keypad_final(key_c3);
931 /* special case: legacy coding using 1,2,3,0,. on the bottom */
932 if (!strcmp(final, "qsrpn"))
935 list[0] = keypad_index(key_a1);
936 list[1] = keypad_index(key_a3);
937 list[2] = keypad_index(key_b2);
938 list[3] = keypad_index(key_c1);
939 list[4] = keypad_index(key_c3);
941 /* check that they're all vt100 keys */
942 for (j = 0; j < 5; ++j) {
948 /* check if they're all in increasing order */
949 for (j = 1; j < 5; ++j) {
950 if (list[j] > list[j - 1]) {
957 for (j = 0, last = -1; j < 5; ++j) {
958 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
959 if (list[k] > last &&
968 strcat(show, " ka1");
971 strcat(show, " ka3");
974 strcat(show, " kb2");
977 strcat(show, " kc1");
980 strcat(show, " kc3");
985 _nc_warning("vt100 keypad order inconsistent: %s", show);
988 } else if (VALID_STRING(key_a1) ||
989 VALID_STRING(key_a3) ||
990 VALID_STRING(key_b2) ||
991 VALID_STRING(key_c1) ||
992 VALID_STRING(key_c3)) {
994 if (keypad_index(key_a1) >= 0)
995 strcat(show, " ka1");
996 if (keypad_index(key_a3) >= 0)
997 strcat(show, " ka3");
998 if (keypad_index(key_b2) >= 0)
999 strcat(show, " kb2");
1000 if (keypad_index(key_c1) >= 0)
1001 strcat(show, " kc1");
1002 if (keypad_index(key_c3) >= 0)
1003 strcat(show, " kc3");
1005 _nc_warning("vt100 keypad map incomplete:%s", show);
1010 * Returns the expected number of parameters for the given capability.
1013 expected_params(const char *name)
1016 static const struct {
1020 { "S0", 1 }, /* 'screen' extension */
1073 { "smgbp", 1 }, /* 2 if smgtp is not given */
1088 int result = 0; /* function-keys, etc., use none */
1090 for (n = 0; n < SIZEOF(table); n++) {
1091 if (!strcmp(name, table[n].name)) {
1092 result = table[n].count;
1101 * Make a quick sanity check for the parameters which are used in the given
1102 * strings. If there are no "%p" tokens, then there should be no other "%"
1106 check_params(TERMTYPE *tp, const char *name, char *value)
1108 int expected = expected_params(name);
1114 #ifdef set_top_margin_parm
1115 if (!strcmp(name, "smgbp")
1116 && set_top_margin_parm == 0)
1120 for (n = 0; n < 10; n++)
1126 _nc_warning("expected character after %% in %s", name);
1128 } else if (*s == 'p') {
1129 if (*++s == '\0' || !isdigit((int) *s)) {
1130 _nc_warning("expected digit after %%p in %s", name);
1144 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1146 if (value == set_attributes || expected < 0) {
1148 } else if (expected != actual) {
1149 _nc_warning("%s uses %d parameters, expected %d", name,
1151 for (n = 1; n < actual; n++) {
1153 _nc_warning("%s omits parameter %d", name, n);
1161 while (*s == '/' || isdigit(UChar(*s)))
1167 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1168 * the latter may have a worst-case delay on the end.
1171 ignore_delays(char *s)
1204 * An sgr string may contain several settings other than the one we're
1205 * interested in, essentially sgr0 + rmacs + whatever. As long as the
1206 * "whatever" is contained in the sgr string, that is close enough for our
1210 similar_sgr(int num, char *a, char *b)
1212 static const char *names[] =
1234 _nc_warning("Did not find delay %s", _nc_visbuf(b));
1236 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
1237 names[num], _nc_visbuf2(1, base_a),
1238 _nc_visbuf2(2, base_b),
1242 } else if (delaying) {
1265 /* ignore delays on the end of the string */
1266 a = ignore_delays(a);
1267 return ((num != 0) || (*a == 0));
1271 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1276 test = TPARM_9(set_attributes,
1288 if (!similar_sgr(num, test, cap)) {
1289 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1291 name, _nc_visbuf2(1, cap),
1292 num, _nc_visbuf2(2, test));
1294 } else if (_nc_capcmp(test, zero)) {
1295 _nc_warning("sgr(%d) present, but not %s", num, name);
1297 } else if (PRESENT(cap)) {
1298 _nc_warning("sgr(%d) missing, but %s present", num, name);
1301 _nc_warning("stack error in sgr(%d) string", num);
1305 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1309 * If tic is compiled with TRACE, we'll be able to see the output from the
1310 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
1311 * the standard error. Use this function to make it simpler to follow the
1312 * resulting debug traces.
1315 show_where(unsigned level)
1317 if (_nc_tracing >= DEBUG_LEVEL(level)) {
1319 _nc_get_type(my_name);
1320 fprintf(stderr, "\"%s\", line %d, '%s' ",
1322 _nc_curr_line, my_name);
1327 #define show_where(level) /* nothing */
1330 /* other sanity-checks (things that we don't want in the normal
1331 * logic that reads a terminfo entry)
1334 check_termtype(TERMTYPE *tp, bool literal)
1336 bool conflict = FALSE;
1338 char fkeys[STRCOUNT];
1341 * A terminal entry may contain more than one keycode assigned to
1342 * a given string (e.g., KEY_END and KEY_LL). But curses will only
1343 * return one (the last one assigned).
1345 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1346 memset(fkeys, 0, sizeof(fkeys));
1347 for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1348 char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1350 if (!VALID_STRING(a))
1352 for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1353 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1354 if (!VALID_STRING(b)
1357 if (!_nc_capcmp(a, b)) {
1362 _nc_warning("Conflicting key definitions (using the last)");
1365 fprintf(stderr, "... %s is the same as %s",
1366 keyname((int) _nc_tinfo_fkeys[j].code),
1367 keyname((int) _nc_tinfo_fkeys[k].code));
1370 fprintf(stderr, ", %s",
1371 keyname((int) _nc_tinfo_fkeys[k].code));
1376 fprintf(stderr, "\n");
1380 for (j = 0; j < NUM_STRINGS(tp); j++) {
1381 char *a = tp->Strings[j];
1382 if (VALID_STRING(a))
1383 check_params(tp, ExtStrname(tp, j, strnames), a);
1391 * These may be mismatched because the terminal description relies on
1392 * restoring the cursor visibility by resetting it.
1394 ANDMISSING(cursor_invisible, cursor_normal);
1395 ANDMISSING(cursor_visible, cursor_normal);
1397 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1398 && !_nc_capcmp(cursor_visible, cursor_normal))
1399 _nc_warning("cursor_visible is same as cursor_normal");
1402 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1403 * given, because the cursor position after the scrolling operation is
1404 * performed is undefined.
1406 ANDMISSING(change_scroll_region, save_cursor);
1407 ANDMISSING(change_scroll_region, restore_cursor);
1409 if (PRESENT(set_attributes)) {
1413 if (PRESENT(exit_attribute_mode)) {
1414 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1416 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1419 _nc_warning("stack error in sgr(0) string");
1422 CHECK_SGR(1, enter_standout_mode);
1423 CHECK_SGR(2, enter_underline_mode);
1424 CHECK_SGR(3, enter_reverse_mode);
1425 CHECK_SGR(4, enter_blink_mode);
1426 CHECK_SGR(5, enter_dim_mode);
1427 CHECK_SGR(6, enter_bold_mode);
1428 CHECK_SGR(7, enter_secure_mode);
1429 CHECK_SGR(8, enter_protected_mode);
1430 CHECK_SGR(9, enter_alt_charset_mode);
1433 _nc_warning("sgr(0) did not return a value");
1435 } else if (PRESENT(exit_attribute_mode) &&
1436 set_attributes != CANCELLED_STRING) {
1437 if (_nc_syntax == SYN_TERMINFO)
1438 _nc_warning("missing sgr string");
1441 if (PRESENT(exit_attribute_mode)) {
1442 char *check_sgr0 = _nc_trim_sgr0(tp);
1444 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1445 _nc_warning("trimmed sgr0 is empty");
1448 if (check_sgr0 != exit_attribute_mode) {
1450 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
1451 _nc_visbuf2(1, exit_attribute_mode),
1452 _nc_visbuf2(2, check_sgr0)));
1456 ("will not trim sgr0\n\toriginal sgr0=%s",
1457 _nc_visbuf(exit_attribute_mode)));
1463 if (!auto_right_margin) {
1465 ("can write to lower-right directly"));
1466 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1468 ("can write to lower-right by suppressing automargin"));
1469 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1470 || PRESENT(insert_character) || PRESENT(parm_ich)) {
1472 ("can write to lower-right by using inserts"));
1475 ("cannot write to lower-right"));
1480 * Some standard applications (e.g., vi) and some non-curses
1481 * applications (e.g., jove) get confused if we have both ich1 and
1482 * smir/rmir. Let's be nice and warn about that, too, even though
1483 * ncurses handles it.
1485 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1486 && PRESENT(parm_ich)) {
1487 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1491 * Finally, do the non-verbose checks
1493 if (save_check_termtype != 0)
1494 save_check_termtype(tp, literal);