1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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.140 2010/01/02 22:54:01 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[] = "\
90 free_namelist(char **src)
94 for (n = 0; src[n] != 0; ++n)
102 cleanup(char **namelst GCC_UNUSED)
105 free_namelist(namelst);
109 if (to_remove != 0) {
119 failed(const char *msg)
122 cleanup((char **) 0);
123 ExitProgram(EXIT_FAILURE);
129 static const char *const tbl[] =
132 " -1 format translation output one capability per line",
134 " -a retain commented-out capabilities (sets -x also)",
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",
151 " -t suppress commented-out capabilities",
153 " -U suppress post-processing of entries",
155 " -v[n] set verbosity level",
156 " -w[n] set format width for translation output",
158 " -x treat unknown capabilities as user-defined",
162 " <file> file to translate or compile"
166 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
167 for (j = 0; j < SIZEOF(tbl); j++) {
168 fputs(tbl[j], stderr);
171 ExitProgram(EXIT_FAILURE);
176 #define S_QUOTE '\'';
184 char result[MAX_ENTRY_SIZE];
187 * Look for strings that contain %{number}, convert them to %'char',
188 * which is shorter and runs a little faster.
190 for (n = 0; n < STRCOUNT; n++) {
191 s = ep->tterm.Strings[n];
193 && strchr(s, L_BRACE) != 0) {
196 while ((ch = *t++) != 0) {
200 } else if ((ch == '%')
201 && (*t == L_BRACE)) {
203 long value = strtol(t + 1, &v, 0);
207 && value != '\\' /* FIXME */
209 && isprint((int) value)) {
218 if (strlen(result) < strlen(s))
223 _nc_set_type(_nc_first_name(ep->tterm.term_names));
224 _nc_curr_line = ep->startline;
225 _nc_write_entry(&ep->tterm);
229 immedhook(ENTRY * ep GCC_UNUSED)
230 /* write out entries with no use capabilities immediately to save storage */
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.
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.
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.
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!
259 * The _nc_set_type() call here requires a compensating one in
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).
266 if (ep->nuses == 0) {
267 int oldline = _nc_curr_line;
270 _nc_curr_line = oldline;
271 free(ep->tterm.str_table);
274 #endif /* HAVE_BIG_CORE */
280 /* emit a comment char, translating terminfo names to termcap names */
282 static bool in_name = FALSE;
283 static size_t have, used;
284 static char *namebuf, *suffix;
287 if (used + 1 >= have) {
289 namebuf = typeRealloc(char, have, namebuf);
290 suffix = typeRealloc(char, have, suffix);
292 if (c == '\n' || c == '@') {
293 namebuf[used++] = '\0';
295 (void) fputs(namebuf, stdout);
298 } else if (c != '>') {
299 namebuf[used++] = (char) c;
300 } else { /* ah! candidate name! */
302 NCURSES_CONST char *tp;
304 namebuf[used++] = '\0';
308 if ((up = strchr(namebuf, '#')) != 0
309 || (up = strchr(namebuf, '=')) != 0
310 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
311 (void) strcpy(suffix, up);
315 if ((tp = nametrans(namebuf)) != 0) {
317 (void) fputs(tp, stdout);
318 (void) fputs(suffix, stdout);
321 /* couldn't find a translation, just dump the name */
323 (void) fputs(namebuf, stdout);
324 (void) fputs(suffix, stdout);
338 /* Returns a string, stripped of leading/trailing whitespace */
342 while (isspace(UChar(*src)))
348 if ((dst = strdup(src)) == NULL)
351 while (--len != 0 && isspace(UChar(dst[len])))
359 open_input(const char *filename)
361 FILE *fp = fopen(filename, "r");
365 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
366 ExitProgram(EXIT_FAILURE);
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);
376 /* Parse the "-e" option-value into a list of names */
378 make_namelist(char *src)
383 unsigned pass, n, nn;
388 } else if (strchr(src, '/') != 0) { /* a filename */
389 FILE *fp = open_input(src);
391 for (pass = 1; pass <= 2; pass++) {
393 while (fgets(buffer, sizeof(buffer), fp) != 0) {
394 if ((s = stripped(buffer)) != 0) {
403 dst = typeCalloc(char *, nn + 1);
408 } else { /* literal list of names */
409 for (pass = 1; pass <= 2; pass++) {
410 for (n = nn = 0, base = src;; n++) {
412 if (mark == ',' || mark == '\0') {
417 if ((s = stripped(base)) != 0)
426 dst = typeCalloc(char *, nn + 1);
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]);
438 matches(char **needle, const char *haystack)
439 /* does entry in needle list match |-separated field in haystack? */
445 for (n = 0; needle[n] != 0; n++) {
446 if (_nc_name_match(haystack, needle[n], "|")) {
457 open_tempfile(char *name)
461 int fd = mkstemp(name);
463 result = fdopen(fd, "w");
465 if (tmpnam(name) != 0)
466 result = fopen(name, "w");
472 main(int argc, char *argv[])
474 char my_tmpname[PATH_MAX];
475 int v_opt = -1, debug_level;
476 int smart_defaults = TRUE;
480 int this_opt, last_opt = '?';
482 int outform = F_TERMINFO; /* output format */
483 int sortmode = S_TERMINFO; /* sort_mode */
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 */
491 char *tversion = (char *) NULL;
492 const char *source_file = "terminfo";
494 char *outdir = (char *) NULL;
495 bool check_only = FALSE;
496 bool suppress_untranslatable = FALSE;
500 _nc_progname = _nc_rootname(argv[0]);
502 if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
503 outform = F_TERMINFO;
504 sortmode = S_TERMINFO;
506 if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
508 sortmode = S_TERMCAP;
511 use_extended_names(FALSE);
515 * Processing arguments is a little complicated, since someone made a
516 * design decision to allow the numeric values for -w, -v options to
519 while ((this_opt = getopt(argc, argv,
520 "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
521 if (isdigit(this_opt)) {
524 v_opt = (v_opt * 10) + (this_opt - '0');
527 width = (width * 10) + (this_opt - '0');
541 sortmode = S_TERMCAP;
545 outform = F_TERMINFO;
546 sortmode = S_TERMINFO;
550 outform = F_VARIABLE;
551 sortmode = S_VARIABLE;
554 smart_defaults = FALSE;
567 puts(curses_version());
569 ExitProgram(EXIT_SUCCESS);
574 namelst = make_namelist(optarg);
602 _nc_disable_period = FALSE;
603 suppress_untranslatable = TRUE;
606 _nc_disable_period = TRUE;
609 use_extended_names(TRUE);
618 debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
619 set_trace_level(debug_level);
622 save_check_termtype = _nc_check_termtype2;
623 _nc_check_termtype2 = check_termtype;
627 * Aaargh! immedhook seriously hoses us!
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.
636 if (namelst && (!infodump && !capdump)) {
637 (void) fprintf(stderr,
638 "Sorry, -e can't be used without -I or -C\n");
640 ExitProgram(EXIT_FAILURE);
642 #endif /* HAVE_BIG_CORE */
645 source_file = argv[optind++];
648 "%s: Too many file names. Usage:\n\t%s %s",
652 ExitProgram(EXIT_FAILURE);
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) {
662 source_file = termcap;
663 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
666 source_file = my_tmpname;
667 fprintf(tmp_fp, "%s\n", termcap);
669 tmp_fp = open_input(source_file);
670 to_remove = source_file;
678 "%s: File name needed. Usage:\n\t%s %s",
683 ExitProgram(EXIT_FAILURE);
688 tmp_fp = open_input(source_file);
695 sortmode, width, debug_level, formatted);
699 sortmode, width, debug_level, FALSE);
701 /* parse entries out of the source file */
702 _nc_set_source(source_file);
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)
713 /* do use resolution */
714 if (check_only || (!infodump && !capdump) || forceresolve) {
715 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
717 ExitProgram(EXIT_FAILURE);
722 if (check_only && (capdump || infodump)) {
724 if (matches(namelst, qp->tterm.term_names)) {
725 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
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),
736 /* write or dump all entries */
738 if (!infodump && !capdump) {
739 _nc_set_writedir(outdir);
741 if (matches(namelst, qp->tterm.term_names))
745 /* this is in case infotocap() generates warnings */
746 _nc_curr_col = _nc_curr_line = -1;
749 if (matches(namelst, qp->tterm.term_names)) {
750 int j = qp->cend - qp->cstart;
753 /* this is in case infotocap() generates warnings */
754 _nc_set_type(_nc_first_name(qp->tterm.term_names));
756 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
759 (void) putchar(fgetc(tmp_fp));
761 put_translate(fgetc(tmp_fp));
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);
769 if (debug_level != 0 && !limited)
770 printf("# length=%d\n", len);
773 if (!namelst && _nc_tail) {
775 bool in_comment = FALSE;
776 bool trailing_comment = FALSE;
778 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
779 while ((c = fgetc(tmp_fp)) != EOF) {
782 trailing_comment = TRUE;
789 && (in_comment || (oldc == '\n' && c == '\n')))
797 /* Show the directory into which entries were written, and the total
801 && (!(check_only || infodump || capdump))) {
802 int total = _nc_tic_written();
804 fprintf(log_fp, "%d entries written to %s\n",
806 _nc_tic_dir((char *) 0));
808 fprintf(log_fp, "No entries written\n");
811 ExitProgram(EXIT_SUCCESS);
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).
823 * Check if the alternate character-set capabilities are consistent.
826 check_acs(TERMTYPE *tp)
828 if (VALID_STRING(acs_chars)) {
829 const char *boxes = "lmkjtuvwqxn";
835 memset(mapped, 0, sizeof(mapped));
836 for (p = acs_chars; *p != '\0'; p += 2) {
838 _nc_warning("acsc has odd number of characters");
841 mapped[UChar(p[0])] = p[1];
844 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
845 _nc_warning("acsc refers to 'I', which is probably an error");
848 for (p = boxes, q = missing; *p != '\0'; ++p) {
849 if (!mapped[UChar(p[0])]) {
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);
863 * Check if the color capabilities are consistent
866 check_colors(TERMTYPE *tp)
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);
873 PAIRED(set_foreground, set_background);
874 PAIRED(set_a_foreground, set_a_background);
875 PAIRED(set_color_pair, initialize_pair);
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");
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");
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");
900 keypad_final(const char *string)
904 if (VALID_STRING(string)
905 && *string++ == '\033'
907 && strlen(string) == 1) {
915 keypad_index(const char *string)
918 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
922 if ((ch = keypad_final(string)) != '\0') {
923 test = strchr(list, ch);
925 result = (test - list);
932 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
933 * is mapped inconsistently.
936 check_keypad(TERMTYPE *tp)
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];
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);
959 /* special case: legacy coding using 1,2,3,0,. on the bottom */
960 assert(strlen(final) <= MAX_KP);
961 if (!strcmp(final, "qsrpn"))
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);
970 /* check that they're all vt100 keys */
971 for (j = 0; j < MAX_KP; ++j) {
977 /* check if they're all in increasing order */
978 for (j = 1; j < MAX_KP; ++j) {
979 if (list[j] > list[j - 1]) {
983 if (increase != (MAX_KP - 1)) {
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 &&
995 assert(strlen(show) < (MAX_KP * 4));
998 strcat(show, " ka1");
1001 strcat(show, " ka3");
1004 strcat(show, " kb2");
1007 strcat(show, " kc1");
1010 strcat(show, " kc3");
1015 _nc_warning("vt100 keypad order inconsistent: %s", show);
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)) {
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");
1035 _nc_warning("vt100 keypad map incomplete:%s", show);
1040 * Returns the expected number of parameters for the given capability.
1043 expected_params(const char *name)
1046 static const struct {
1050 { "S0", 1 }, /* 'screen' extension */
1103 { "smgbp", 1 }, /* 2 if smgtp is not given */
1118 int result = 0; /* function-keys, etc., use none */
1120 for (n = 0; n < SIZEOF(table); n++) {
1121 if (!strcmp(name, table[n].name)) {
1122 result = table[n].count;
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 "%"
1136 check_params(TERMTYPE *tp, const char *name, char *value)
1138 int expected = expected_params(name);
1144 #ifdef set_top_margin_parm
1145 if (!strcmp(name, "smgbp")
1146 && set_top_margin_parm == 0)
1150 for (n = 0; n < 10; n++)
1156 _nc_warning("expected character after %% in %s", name);
1158 } else if (*s == 'p') {
1159 if (*++s == '\0' || !isdigit((int) *s)) {
1160 _nc_warning("expected digit after %%p in %s", name);
1174 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1176 if (value == set_attributes || expected < 0) {
1178 } else if (expected != actual) {
1179 _nc_warning("%s uses %d parameters, expected %d", name,
1181 for (n = 1; n < actual; n++) {
1183 _nc_warning("%s omits parameter %d", name, n);
1191 while (*s == '/' || isdigit(UChar(*s)))
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.
1201 ignore_delays(char *s)
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
1240 similar_sgr(int num, char *a, char *b)
1242 static const char *names[] =
1264 _nc_warning("Did not find delay %s", _nc_visbuf(b));
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),
1272 } else if (delaying) {
1275 } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
1297 /* ignore delays on the end of the string */
1298 a = ignore_delays(a);
1299 return ((num != 0) || (*a == 0));
1303 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1308 test = TPARM_9(set_attributes,
1320 if (!similar_sgr(num, test, cap)) {
1321 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1323 name, _nc_visbuf2(1, cap),
1324 num, _nc_visbuf2(2, test));
1326 } else if (_nc_capcmp(test, zero)) {
1327 _nc_warning("sgr(%d) present, but not %s", num, name);
1329 } else if (PRESENT(cap)) {
1330 _nc_warning("sgr(%d) missing, but %s present", num, name);
1333 _nc_warning("stack error in sgr(%d) string", num);
1337 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1341 * If tic is compiled with TRACE, we'll be able to see the output from the
1342 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
1343 * the standard error. Use this function to make it simpler to follow the
1344 * resulting debug traces.
1347 show_where(unsigned level)
1349 if (_nc_tracing >= DEBUG_LEVEL(level)) {
1351 _nc_get_type(my_name);
1352 fprintf(stderr, "\"%s\", line %d, '%s' ",
1354 _nc_curr_line, my_name);
1359 #define show_where(level) /* nothing */
1362 /* other sanity-checks (things that we don't want in the normal
1363 * logic that reads a terminfo entry)
1366 check_termtype(TERMTYPE *tp, bool literal)
1368 bool conflict = FALSE;
1370 char fkeys[STRCOUNT];
1373 * A terminal entry may contain more than one keycode assigned to
1374 * a given string (e.g., KEY_END and KEY_LL). But curses will only
1375 * return one (the last one assigned).
1377 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1378 memset(fkeys, 0, sizeof(fkeys));
1379 for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1380 char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1382 if (!VALID_STRING(a))
1384 for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1385 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1386 if (!VALID_STRING(b)
1389 if (!_nc_capcmp(a, b)) {
1394 _nc_warning("Conflicting key definitions (using the last)");
1397 fprintf(stderr, "... %s is the same as %s",
1398 keyname((int) _nc_tinfo_fkeys[j].code),
1399 keyname((int) _nc_tinfo_fkeys[k].code));
1402 fprintf(stderr, ", %s",
1403 keyname((int) _nc_tinfo_fkeys[k].code));
1408 fprintf(stderr, "\n");
1412 for (j = 0; j < NUM_STRINGS(tp); j++) {
1413 char *a = tp->Strings[j];
1414 if (VALID_STRING(a))
1415 check_params(tp, ExtStrname(tp, j, strnames), a);
1423 * These may be mismatched because the terminal description relies on
1424 * restoring the cursor visibility by resetting it.
1426 ANDMISSING(cursor_invisible, cursor_normal);
1427 ANDMISSING(cursor_visible, cursor_normal);
1429 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1430 && !_nc_capcmp(cursor_visible, cursor_normal))
1431 _nc_warning("cursor_visible is same as cursor_normal");
1434 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1435 * given, because the cursor position after the scrolling operation is
1436 * performed is undefined.
1438 ANDMISSING(change_scroll_region, save_cursor);
1439 ANDMISSING(change_scroll_region, restore_cursor);
1441 if (PRESENT(set_attributes)) {
1445 if (PRESENT(exit_attribute_mode)) {
1446 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1448 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1451 _nc_warning("stack error in sgr(0) string");
1454 CHECK_SGR(1, enter_standout_mode);
1455 CHECK_SGR(2, enter_underline_mode);
1456 CHECK_SGR(3, enter_reverse_mode);
1457 CHECK_SGR(4, enter_blink_mode);
1458 CHECK_SGR(5, enter_dim_mode);
1459 CHECK_SGR(6, enter_bold_mode);
1460 CHECK_SGR(7, enter_secure_mode);
1461 CHECK_SGR(8, enter_protected_mode);
1462 CHECK_SGR(9, enter_alt_charset_mode);
1465 _nc_warning("sgr(0) did not return a value");
1467 } else if (PRESENT(exit_attribute_mode) &&
1468 set_attributes != CANCELLED_STRING) {
1469 if (_nc_syntax == SYN_TERMINFO)
1470 _nc_warning("missing sgr string");
1473 if (PRESENT(exit_attribute_mode)) {
1474 char *check_sgr0 = _nc_trim_sgr0(tp);
1476 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1477 _nc_warning("trimmed sgr0 is empty");
1480 if (check_sgr0 != exit_attribute_mode) {
1482 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
1483 _nc_visbuf2(1, exit_attribute_mode),
1484 _nc_visbuf2(2, check_sgr0)));
1488 ("will not trim sgr0\n\toriginal sgr0=%s",
1489 _nc_visbuf(exit_attribute_mode)));
1495 if (!auto_right_margin) {
1497 ("can write to lower-right directly"));
1498 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1500 ("can write to lower-right by suppressing automargin"));
1501 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1502 || PRESENT(insert_character) || PRESENT(parm_ich)) {
1504 ("can write to lower-right by using inserts"));
1507 ("cannot write to lower-right"));
1512 * Some standard applications (e.g., vi) and some non-curses
1513 * applications (e.g., jove) get confused if we have both ich1 and
1514 * smir/rmir. Let's be nice and warn about that, too, even though
1515 * ncurses handles it.
1517 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1518 && PRESENT(parm_ich)) {
1519 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1523 * Finally, do the non-verbose checks
1525 if (save_check_termtype != 0)
1526 save_check_termtype(tp, literal);