1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.137 2008/09/13 16:59:24 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)))
345 char *dst = strcpy((char *) malloc(strlen(src) + 1), src);
346 size_t len = strlen(dst);
347 while (--len != 0 && isspace(UChar(dst[len])))
355 open_input(const char *filename)
357 FILE *fp = fopen(filename, "r");
361 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
362 ExitProgram(EXIT_FAILURE);
364 if (fstat(fileno(fp), &sb) < 0
365 || (sb.st_mode & S_IFMT) != S_IFREG) {
366 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
367 ExitProgram(EXIT_FAILURE);
372 /* Parse the "-e" option-value into a list of names */
374 make_namelist(char *src)
379 unsigned pass, n, nn;
384 } else if (strchr(src, '/') != 0) { /* a filename */
385 FILE *fp = open_input(src);
387 for (pass = 1; pass <= 2; pass++) {
389 while (fgets(buffer, sizeof(buffer), fp) != 0) {
390 if ((s = stripped(buffer)) != 0) {
399 dst = typeCalloc(char *, nn + 1);
404 } else { /* literal list of names */
405 for (pass = 1; pass <= 2; pass++) {
406 for (n = nn = 0, base = src;; n++) {
408 if (mark == ',' || mark == '\0') {
413 if ((s = stripped(base)) != 0)
422 dst = typeCalloc(char *, nn + 1);
425 if (showsummary && (dst != 0)) {
426 fprintf(log_fp, "Entries that will be compiled:\n");
427 for (n = 0; dst[n] != 0; n++)
428 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
434 matches(char **needle, const char *haystack)
435 /* does entry in needle list match |-separated field in haystack? */
441 for (n = 0; needle[n] != 0; n++) {
442 if (_nc_name_match(haystack, needle[n], "|")) {
453 open_tempfile(char *name)
457 int fd = mkstemp(name);
459 result = fdopen(fd, "w");
461 if (tmpnam(name) != 0)
462 result = fopen(name, "w");
468 main(int argc, char *argv[])
470 char my_tmpname[PATH_MAX];
471 int v_opt = -1, debug_level;
472 int smart_defaults = TRUE;
476 int this_opt, last_opt = '?';
478 int outform = F_TERMINFO; /* output format */
479 int sortmode = S_TERMINFO; /* sort_mode */
482 bool formatted = FALSE; /* reformat complex strings? */
483 bool literal = FALSE; /* suppress post-processing? */
484 int numbers = 0; /* format "%'char'" to/from "%{number}" */
485 bool forceresolve = FALSE; /* force resolution */
487 char *tversion = (char *) NULL;
488 const char *source_file = "terminfo";
490 char *outdir = (char *) NULL;
491 bool check_only = FALSE;
492 bool suppress_untranslatable = FALSE;
496 _nc_progname = _nc_rootname(argv[0]);
498 if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) {
499 outform = F_TERMINFO;
500 sortmode = S_TERMINFO;
502 if ((capdump = (strcmp(_nc_progname, PROG_INFOTOCAP) == 0)) != FALSE) {
504 sortmode = S_TERMCAP;
507 use_extended_names(FALSE);
511 * Processing arguments is a little complicated, since someone made a
512 * design decision to allow the numeric values for -w, -v options to
515 while ((this_opt = getopt(argc, argv,
516 "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
517 if (isdigit(this_opt)) {
520 v_opt = (v_opt * 10) + (this_opt - '0');
523 width = (width * 10) + (this_opt - '0');
537 sortmode = S_TERMCAP;
541 outform = F_TERMINFO;
542 sortmode = S_TERMINFO;
546 outform = F_VARIABLE;
547 sortmode = S_VARIABLE;
550 smart_defaults = FALSE;
563 puts(curses_version());
565 ExitProgram(EXIT_SUCCESS);
570 namelst = make_namelist(optarg);
598 _nc_disable_period = FALSE;
599 suppress_untranslatable = TRUE;
602 _nc_disable_period = TRUE;
605 use_extended_names(TRUE);
614 debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
615 set_trace_level(debug_level);
618 save_check_termtype = _nc_check_termtype2;
619 _nc_check_termtype2 = check_termtype;
623 * Aaargh! immedhook seriously hoses us!
625 * One problem with immedhook is it means we can't do -e. Problem
626 * is that we can't guarantee that for each terminal listed, all the
627 * terminals it depends on will have been kept in core for reference
628 * resolution -- in fact it's certain the primitive types at the end
629 * of reference chains *won't* be in core unless they were explicitly
630 * in the select list themselves.
632 if (namelst && (!infodump && !capdump)) {
633 (void) fprintf(stderr,
634 "Sorry, -e can't be used without -I or -C\n");
636 ExitProgram(EXIT_FAILURE);
638 #endif /* HAVE_BIG_CORE */
641 source_file = argv[optind++];
644 "%s: Too many file names. Usage:\n\t%s %s",
648 ExitProgram(EXIT_FAILURE);
651 if (infodump == TRUE) {
652 /* captoinfo's no-argument case */
653 source_file = "/etc/termcap";
654 if ((termcap = getenv("TERMCAP")) != 0
655 && (namelst = make_namelist(getenv("TERM"))) != 0) {
656 if (access(termcap, F_OK) == 0) {
658 source_file = termcap;
659 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
662 source_file = my_tmpname;
663 fprintf(tmp_fp, "%s\n", termcap);
665 tmp_fp = open_input(source_file);
666 to_remove = source_file;
674 "%s: File name needed. Usage:\n\t%s %s",
679 ExitProgram(EXIT_FAILURE);
684 tmp_fp = open_input(source_file);
691 sortmode, width, debug_level, formatted);
695 sortmode, width, debug_level, FALSE);
697 /* parse entries out of the source file */
698 _nc_set_source(source_file);
700 if (!(check_only || infodump || capdump))
701 _nc_set_writedir(outdir);
702 #endif /* HAVE_BIG_CORE */
703 _nc_read_entry_source(tmp_fp, (char *) NULL,
704 !smart_defaults || literal, FALSE,
705 ((check_only || infodump || capdump)
709 /* do use resolution */
710 if (check_only || (!infodump && !capdump) || forceresolve) {
711 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
713 ExitProgram(EXIT_FAILURE);
718 if (check_only && (capdump || infodump)) {
720 if (matches(namelst, qp->tterm.term_names)) {
721 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
723 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
724 (void) fprintf(stderr,
725 "warning: resolved %s entry is %d bytes long\n",
726 _nc_first_name(qp->tterm.term_names),
732 /* write or dump all entries */
734 if (!infodump && !capdump) {
735 _nc_set_writedir(outdir);
737 if (matches(namelst, qp->tterm.term_names))
741 /* this is in case infotocap() generates warnings */
742 _nc_curr_col = _nc_curr_line = -1;
745 if (matches(namelst, qp->tterm.term_names)) {
746 int j = qp->cend - qp->cstart;
749 /* this is in case infotocap() generates warnings */
750 _nc_set_type(_nc_first_name(qp->tterm.term_names));
752 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
755 (void) putchar(fgetc(tmp_fp));
757 put_translate(fgetc(tmp_fp));
760 dump_entry(&qp->tterm, suppress_untranslatable,
761 limited, numbers, NULL);
762 for (j = 0; j < (int) qp->nuses; j++)
763 dump_uses(qp->uses[j].name, !capdump);
765 if (debug_level != 0 && !limited)
766 printf("# length=%d\n", len);
769 if (!namelst && _nc_tail) {
771 bool in_comment = FALSE;
772 bool trailing_comment = FALSE;
774 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
775 while ((c = fgetc(tmp_fp)) != EOF) {
778 trailing_comment = TRUE;
785 && (in_comment || (oldc == '\n' && c == '\n')))
793 /* Show the directory into which entries were written, and the total
797 && (!(check_only || infodump || capdump))) {
798 int total = _nc_tic_written();
800 fprintf(log_fp, "%d entries written to %s\n",
802 _nc_tic_dir((char *) 0));
804 fprintf(log_fp, "No entries written\n");
807 ExitProgram(EXIT_SUCCESS);
811 * This bit of legerdemain turns all the terminfo variable names into
812 * references to locations in the arrays Booleans, Numbers, and Strings ---
813 * precisely what's needed (see comp_parse.c).
819 * Check if the alternate character-set capabilities are consistent.
822 check_acs(TERMTYPE *tp)
824 if (VALID_STRING(acs_chars)) {
825 const char *boxes = "lmkjtuvwqxn";
831 memset(mapped, 0, sizeof(mapped));
832 for (p = acs_chars; *p != '\0'; p += 2) {
834 _nc_warning("acsc has odd number of characters");
837 mapped[UChar(p[0])] = p[1];
840 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
841 _nc_warning("acsc refers to 'I', which is probably an error");
844 for (p = boxes, q = missing; *p != '\0'; ++p) {
845 if (!mapped[UChar(p[0])]) {
851 assert(strlen(missing) <= strlen(boxes));
852 if (*missing != '\0' && strcmp(missing, boxes)) {
853 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
859 * Check if the color capabilities are consistent
862 check_colors(TERMTYPE *tp)
864 if ((max_colors > 0) != (max_pairs > 0)
865 || ((max_colors > max_pairs) && (initialize_pair == 0)))
866 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
867 max_colors, max_pairs);
869 PAIRED(set_foreground, set_background);
870 PAIRED(set_a_foreground, set_a_background);
871 PAIRED(set_color_pair, initialize_pair);
873 if (VALID_STRING(set_foreground)
874 && VALID_STRING(set_a_foreground)
875 && !_nc_capcmp(set_foreground, set_a_foreground))
876 _nc_warning("expected setf/setaf to be different");
878 if (VALID_STRING(set_background)
879 && VALID_STRING(set_a_background)
880 && !_nc_capcmp(set_background, set_a_background))
881 _nc_warning("expected setb/setab to be different");
883 /* see: has_colors() */
884 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
885 && (((set_foreground != NULL)
886 && (set_background != NULL))
887 || ((set_a_foreground != NULL)
888 && (set_a_background != NULL))
889 || set_color_pair)) {
890 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
891 _nc_warning("expected either op/oc string for resetting colors");
896 keypad_final(const char *string)
900 if (VALID_STRING(string)
901 && *string++ == '\033'
903 && strlen(string) == 1) {
911 keypad_index(const char *string)
914 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
918 if ((ch = keypad_final(string)) != '\0') {
919 test = strchr(list, ch);
921 result = (test - list);
928 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
929 * is mapped inconsistently.
932 check_keypad(TERMTYPE *tp)
936 if (VALID_STRING(key_a1) &&
937 VALID_STRING(key_a3) &&
938 VALID_STRING(key_b2) &&
939 VALID_STRING(key_c1) &&
940 VALID_STRING(key_c3)) {
941 char final[MAX_KP + 1];
948 final[0] = keypad_final(key_a1);
949 final[1] = keypad_final(key_a3);
950 final[2] = keypad_final(key_b2);
951 final[3] = keypad_final(key_c1);
952 final[4] = keypad_final(key_c3);
955 /* special case: legacy coding using 1,2,3,0,. on the bottom */
956 assert(strlen(final) <= MAX_KP);
957 if (!strcmp(final, "qsrpn"))
960 list[0] = keypad_index(key_a1);
961 list[1] = keypad_index(key_a3);
962 list[2] = keypad_index(key_b2);
963 list[3] = keypad_index(key_c1);
964 list[4] = keypad_index(key_c3);
966 /* check that they're all vt100 keys */
967 for (j = 0; j < MAX_KP; ++j) {
973 /* check if they're all in increasing order */
974 for (j = 1; j < MAX_KP; ++j) {
975 if (list[j] > list[j - 1]) {
979 if (increase != (MAX_KP - 1)) {
982 for (j = 0, last = -1; j < MAX_KP; ++j) {
983 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
984 if (list[k] > last &&
991 assert(strlen(show) < (MAX_KP * 4));
994 strcat(show, " ka1");
997 strcat(show, " ka3");
1000 strcat(show, " kb2");
1003 strcat(show, " kc1");
1006 strcat(show, " kc3");
1011 _nc_warning("vt100 keypad order inconsistent: %s", show);
1014 } else if (VALID_STRING(key_a1) ||
1015 VALID_STRING(key_a3) ||
1016 VALID_STRING(key_b2) ||
1017 VALID_STRING(key_c1) ||
1018 VALID_STRING(key_c3)) {
1020 if (keypad_index(key_a1) >= 0)
1021 strcat(show, " ka1");
1022 if (keypad_index(key_a3) >= 0)
1023 strcat(show, " ka3");
1024 if (keypad_index(key_b2) >= 0)
1025 strcat(show, " kb2");
1026 if (keypad_index(key_c1) >= 0)
1027 strcat(show, " kc1");
1028 if (keypad_index(key_c3) >= 0)
1029 strcat(show, " kc3");
1031 _nc_warning("vt100 keypad map incomplete:%s", show);
1036 * Returns the expected number of parameters for the given capability.
1039 expected_params(const char *name)
1042 static const struct {
1046 { "S0", 1 }, /* 'screen' extension */
1099 { "smgbp", 1 }, /* 2 if smgtp is not given */
1114 int result = 0; /* function-keys, etc., use none */
1116 for (n = 0; n < SIZEOF(table); n++) {
1117 if (!strcmp(name, table[n].name)) {
1118 result = table[n].count;
1127 * Make a quick sanity check for the parameters which are used in the given
1128 * strings. If there are no "%p" tokens, then there should be no other "%"
1132 check_params(TERMTYPE *tp, const char *name, char *value)
1134 int expected = expected_params(name);
1140 #ifdef set_top_margin_parm
1141 if (!strcmp(name, "smgbp")
1142 && set_top_margin_parm == 0)
1146 for (n = 0; n < 10; n++)
1152 _nc_warning("expected character after %% in %s", name);
1154 } else if (*s == 'p') {
1155 if (*++s == '\0' || !isdigit((int) *s)) {
1156 _nc_warning("expected digit after %%p in %s", name);
1170 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1172 if (value == set_attributes || expected < 0) {
1174 } else if (expected != actual) {
1175 _nc_warning("%s uses %d parameters, expected %d", name,
1177 for (n = 1; n < actual; n++) {
1179 _nc_warning("%s omits parameter %d", name, n);
1187 while (*s == '/' || isdigit(UChar(*s)))
1193 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1194 * the latter may have a worst-case delay on the end.
1197 ignore_delays(char *s)
1230 * An sgr string may contain several settings other than the one we're
1231 * interested in, essentially sgr0 + rmacs + whatever. As long as the
1232 * "whatever" is contained in the sgr string, that is close enough for our
1236 similar_sgr(int num, char *a, char *b)
1238 static const char *names[] =
1260 _nc_warning("Did not find delay %s", _nc_visbuf(b));
1262 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
1263 names[num], _nc_visbuf2(1, base_a),
1264 _nc_visbuf2(2, base_b),
1268 } else if (delaying) {
1291 /* ignore delays on the end of the string */
1292 a = ignore_delays(a);
1293 return ((num != 0) || (*a == 0));
1297 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1302 test = TPARM_9(set_attributes,
1314 if (!similar_sgr(num, test, cap)) {
1315 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1317 name, _nc_visbuf2(1, cap),
1318 num, _nc_visbuf2(2, test));
1320 } else if (_nc_capcmp(test, zero)) {
1321 _nc_warning("sgr(%d) present, but not %s", num, name);
1323 } else if (PRESENT(cap)) {
1324 _nc_warning("sgr(%d) missing, but %s present", num, name);
1327 _nc_warning("stack error in sgr(%d) string", num);
1331 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1335 * If tic is compiled with TRACE, we'll be able to see the output from the
1336 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
1337 * the standard error. Use this function to make it simpler to follow the
1338 * resulting debug traces.
1341 show_where(unsigned level)
1343 if (_nc_tracing >= DEBUG_LEVEL(level)) {
1345 _nc_get_type(my_name);
1346 fprintf(stderr, "\"%s\", line %d, '%s' ",
1348 _nc_curr_line, my_name);
1353 #define show_where(level) /* nothing */
1356 /* other sanity-checks (things that we don't want in the normal
1357 * logic that reads a terminfo entry)
1360 check_termtype(TERMTYPE *tp, bool literal)
1362 bool conflict = FALSE;
1364 char fkeys[STRCOUNT];
1367 * A terminal entry may contain more than one keycode assigned to
1368 * a given string (e.g., KEY_END and KEY_LL). But curses will only
1369 * return one (the last one assigned).
1371 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1372 memset(fkeys, 0, sizeof(fkeys));
1373 for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1374 char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1376 if (!VALID_STRING(a))
1378 for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1379 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1380 if (!VALID_STRING(b)
1383 if (!_nc_capcmp(a, b)) {
1388 _nc_warning("Conflicting key definitions (using the last)");
1391 fprintf(stderr, "... %s is the same as %s",
1392 keyname((int) _nc_tinfo_fkeys[j].code),
1393 keyname((int) _nc_tinfo_fkeys[k].code));
1396 fprintf(stderr, ", %s",
1397 keyname((int) _nc_tinfo_fkeys[k].code));
1402 fprintf(stderr, "\n");
1406 for (j = 0; j < NUM_STRINGS(tp); j++) {
1407 char *a = tp->Strings[j];
1408 if (VALID_STRING(a))
1409 check_params(tp, ExtStrname(tp, j, strnames), a);
1417 * These may be mismatched because the terminal description relies on
1418 * restoring the cursor visibility by resetting it.
1420 ANDMISSING(cursor_invisible, cursor_normal);
1421 ANDMISSING(cursor_visible, cursor_normal);
1423 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1424 && !_nc_capcmp(cursor_visible, cursor_normal))
1425 _nc_warning("cursor_visible is same as cursor_normal");
1428 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1429 * given, because the cursor position after the scrolling operation is
1430 * performed is undefined.
1432 ANDMISSING(change_scroll_region, save_cursor);
1433 ANDMISSING(change_scroll_region, restore_cursor);
1435 if (PRESENT(set_attributes)) {
1439 if (PRESENT(exit_attribute_mode)) {
1440 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1442 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1445 _nc_warning("stack error in sgr(0) string");
1448 CHECK_SGR(1, enter_standout_mode);
1449 CHECK_SGR(2, enter_underline_mode);
1450 CHECK_SGR(3, enter_reverse_mode);
1451 CHECK_SGR(4, enter_blink_mode);
1452 CHECK_SGR(5, enter_dim_mode);
1453 CHECK_SGR(6, enter_bold_mode);
1454 CHECK_SGR(7, enter_secure_mode);
1455 CHECK_SGR(8, enter_protected_mode);
1456 CHECK_SGR(9, enter_alt_charset_mode);
1459 _nc_warning("sgr(0) did not return a value");
1461 } else if (PRESENT(exit_attribute_mode) &&
1462 set_attributes != CANCELLED_STRING) {
1463 if (_nc_syntax == SYN_TERMINFO)
1464 _nc_warning("missing sgr string");
1467 if (PRESENT(exit_attribute_mode)) {
1468 char *check_sgr0 = _nc_trim_sgr0(tp);
1470 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1471 _nc_warning("trimmed sgr0 is empty");
1474 if (check_sgr0 != exit_attribute_mode) {
1476 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
1477 _nc_visbuf2(1, exit_attribute_mode),
1478 _nc_visbuf2(2, check_sgr0)));
1482 ("will not trim sgr0\n\toriginal sgr0=%s",
1483 _nc_visbuf(exit_attribute_mode)));
1489 if (!auto_right_margin) {
1491 ("can write to lower-right directly"));
1492 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1494 ("can write to lower-right by suppressing automargin"));
1495 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1496 || PRESENT(insert_character) || PRESENT(parm_ich)) {
1498 ("can write to lower-right by using inserts"));
1501 ("cannot write to lower-right"));
1506 * Some standard applications (e.g., vi) and some non-curses
1507 * applications (e.g., jove) get confused if we have both ich1 and
1508 * smir/rmir. Let's be nice and warn about that, too, even though
1509 * ncurses handles it.
1511 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1512 && PRESENT(parm_ich)) {
1513 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1517 * Finally, do the non-verbose checks
1519 if (save_check_termtype != 0)
1520 save_check_termtype(tp, literal);