1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 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.133 2007/07/21 17:45:59 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);
358 free_namelist(char **src)
362 for (n = 0; src[n] != 0; ++n)
369 /* Parse the "-e" option-value into a list of names */
371 make_namelist(char *src)
376 unsigned pass, n, nn;
381 } else if (strchr(src, '/') != 0) { /* a filename */
382 FILE *fp = open_input(src);
384 for (pass = 1; pass <= 2; pass++) {
386 while (fgets(buffer, sizeof(buffer), fp) != 0) {
387 if ((s = stripped(buffer)) != 0) {
396 dst = typeCalloc(char *, nn + 1);
401 } else { /* literal list of names */
402 for (pass = 1; pass <= 2; pass++) {
403 for (n = nn = 0, base = src;; n++) {
405 if (mark == ',' || mark == '\0') {
410 if ((s = stripped(base)) != 0)
419 dst = typeCalloc(char *, nn + 1);
422 if (showsummary && (dst != 0)) {
423 fprintf(log_fp, "Entries that will be compiled:\n");
424 for (n = 0; dst[n] != 0; n++)
425 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
431 matches(char **needle, const char *haystack)
432 /* does entry in needle list match |-separated field in haystack? */
438 for (n = 0; needle[n] != 0; n++) {
439 if (_nc_name_match(haystack, needle[n], "|")) {
450 open_tempfile(char *name)
454 int fd = mkstemp(name);
456 result = fdopen(fd, "w");
458 if (tmpnam(name) != 0)
459 result = fopen(name, "w");
465 main(int argc, char *argv[])
467 char my_tmpname[PATH_MAX];
468 int v_opt = -1, debug_level;
469 int smart_defaults = TRUE;
473 int this_opt, last_opt = '?';
475 int outform = F_TERMINFO; /* output format */
476 int sortmode = S_TERMINFO; /* sort_mode */
479 bool formatted = FALSE; /* reformat complex strings? */
480 bool literal = FALSE; /* suppress post-processing? */
481 int numbers = 0; /* format "%'char'" to/from "%{number}" */
482 bool forceresolve = FALSE; /* force resolution */
484 char *tversion = (char *) NULL;
485 const char *source_file = "terminfo";
487 char *outdir = (char *) NULL;
488 bool check_only = FALSE;
489 bool suppress_untranslatable = FALSE;
493 _nc_progname = _nc_rootname(argv[0]);
495 if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) {
496 outform = F_TERMINFO;
497 sortmode = S_TERMINFO;
499 if ((capdump = (strcmp(_nc_progname, PROG_INFOTOCAP) == 0)) != FALSE) {
501 sortmode = S_TERMCAP;
504 use_extended_names(FALSE);
508 * Processing arguments is a little complicated, since someone made a
509 * design decision to allow the numeric values for -w, -v options to
512 while ((this_opt = getopt(argc, argv,
513 "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) {
514 if (isdigit(this_opt)) {
517 v_opt = (v_opt * 10) + (this_opt - '0');
520 width = (width * 10) + (this_opt - '0');
534 sortmode = S_TERMCAP;
538 outform = F_TERMINFO;
539 sortmode = S_TERMINFO;
543 outform = F_VARIABLE;
544 sortmode = S_VARIABLE;
547 smart_defaults = FALSE;
560 puts(curses_version());
566 namelst = make_namelist(optarg);
594 _nc_disable_period = FALSE;
595 suppress_untranslatable = TRUE;
598 _nc_disable_period = TRUE;
601 use_extended_names(TRUE);
610 debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
611 set_trace_level(debug_level);
614 save_check_termtype = _nc_check_termtype2;
615 _nc_check_termtype2 = check_termtype;
619 * Aaargh! immedhook seriously hoses us!
621 * One problem with immedhook is it means we can't do -e. Problem
622 * is that we can't guarantee that for each terminal listed, all the
623 * terminals it depends on will have been kept in core for reference
624 * resolution -- in fact it's certain the primitive types at the end
625 * of reference chains *won't* be in core unless they were explicitly
626 * in the select list themselves.
628 if (namelst && (!infodump && !capdump)) {
629 (void) fprintf(stderr,
630 "Sorry, -e can't be used without -I or -C\n");
632 ExitProgram(EXIT_FAILURE);
634 #endif /* HAVE_BIG_CORE */
637 source_file = argv[optind++];
640 "%s: Too many file names. Usage:\n\t%s %s",
644 ExitProgram(EXIT_FAILURE);
647 if (infodump == TRUE) {
648 /* captoinfo's no-argument case */
649 source_file = "/etc/termcap";
650 if ((termcap = getenv("TERMCAP")) != 0
651 && (namelst = make_namelist(getenv("TERM"))) != 0) {
652 if (access(termcap, F_OK) == 0) {
654 source_file = termcap;
655 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
658 source_file = my_tmpname;
659 fprintf(tmp_fp, "%s\n", termcap);
661 tmp_fp = open_input(source_file);
662 to_remove = source_file;
670 "%s: File name needed. Usage:\n\t%s %s",
675 ExitProgram(EXIT_FAILURE);
680 tmp_fp = open_input(source_file);
687 sortmode, width, debug_level, formatted);
691 sortmode, width, debug_level, FALSE);
693 /* parse entries out of the source file */
694 _nc_set_source(source_file);
696 if (!(check_only || infodump || capdump))
697 _nc_set_writedir(outdir);
698 #endif /* HAVE_BIG_CORE */
699 _nc_read_entry_source(tmp_fp, (char *) NULL,
700 !smart_defaults || literal, FALSE,
701 ((check_only || infodump || capdump)
705 /* do use resolution */
706 if (check_only || (!infodump && !capdump) || forceresolve) {
707 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
709 ExitProgram(EXIT_FAILURE);
714 if (check_only && (capdump || infodump)) {
716 if (matches(namelst, qp->tterm.term_names)) {
717 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
719 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
720 (void) fprintf(stderr,
721 "warning: resolved %s entry is %d bytes long\n",
722 _nc_first_name(qp->tterm.term_names),
728 /* write or dump all entries */
730 if (!infodump && !capdump) {
731 _nc_set_writedir(outdir);
733 if (matches(namelst, qp->tterm.term_names))
737 /* this is in case infotocap() generates warnings */
738 _nc_curr_col = _nc_curr_line = -1;
741 if (matches(namelst, qp->tterm.term_names)) {
742 int j = qp->cend - qp->cstart;
745 /* this is in case infotocap() generates warnings */
746 _nc_set_type(_nc_first_name(qp->tterm.term_names));
748 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
751 (void) putchar(fgetc(tmp_fp));
753 put_translate(fgetc(tmp_fp));
756 dump_entry(&qp->tterm, suppress_untranslatable,
757 limited, numbers, NULL);
758 for (j = 0; j < qp->nuses; j++)
759 dump_uses(qp->uses[j].name, !capdump);
761 if (debug_level != 0 && !limited)
762 printf("# length=%d\n", len);
765 if (!namelst && _nc_tail) {
767 bool in_comment = FALSE;
768 bool trailing_comment = FALSE;
770 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
771 while ((c = fgetc(tmp_fp)) != EOF) {
774 trailing_comment = TRUE;
781 && (in_comment || (oldc == '\n' && c == '\n')))
789 /* Show the directory into which entries were written, and the total
793 && (!(check_only || infodump || capdump))) {
794 int total = _nc_tic_written();
796 fprintf(log_fp, "%d entries written to %s\n",
798 _nc_tic_dir((char *) 0));
800 fprintf(log_fp, "No entries written\n");
803 free_namelist(namelst);
806 ExitProgram(EXIT_SUCCESS);
810 * This bit of legerdemain turns all the terminfo variable names into
811 * references to locations in the arrays Booleans, Numbers, and Strings ---
812 * precisely what's needed (see comp_parse.c).
818 * Check if the alternate character-set capabilities are consistent.
821 check_acs(TERMTYPE *tp)
823 if (VALID_STRING(acs_chars)) {
824 const char *boxes = "lmkjtuvwqxn";
830 memset(mapped, 0, sizeof(mapped));
831 for (p = acs_chars; *p != '\0'; p += 2) {
833 _nc_warning("acsc has odd number of characters");
836 mapped[UChar(p[0])] = p[1];
838 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
839 _nc_warning("acsc refers to 'I', which is probably an error");
841 for (p = boxes, q = missing; *p != '\0'; ++p) {
842 if (!mapped[UChar(p[0])]) {
847 if (*missing != '\0' && strcmp(missing, boxes)) {
848 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
854 * Check if the color capabilities are consistent
857 check_colors(TERMTYPE *tp)
859 if ((max_colors > 0) != (max_pairs > 0)
860 || ((max_colors > max_pairs) && (initialize_pair == 0)))
861 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
862 max_colors, max_pairs);
864 PAIRED(set_foreground, set_background);
865 PAIRED(set_a_foreground, set_a_background);
866 PAIRED(set_color_pair, initialize_pair);
868 if (VALID_STRING(set_foreground)
869 && VALID_STRING(set_a_foreground)
870 && !_nc_capcmp(set_foreground, set_a_foreground))
871 _nc_warning("expected setf/setaf to be different");
873 if (VALID_STRING(set_background)
874 && VALID_STRING(set_a_background)
875 && !_nc_capcmp(set_background, set_a_background))
876 _nc_warning("expected setb/setab to be different");
878 /* see: has_colors() */
879 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
880 && (((set_foreground != NULL)
881 && (set_background != NULL))
882 || ((set_a_foreground != NULL)
883 && (set_a_background != NULL))
884 || set_color_pair)) {
885 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
886 _nc_warning("expected either op/oc string for resetting colors");
891 keypad_final(const char *string)
895 if (VALID_STRING(string)
896 && *string++ == '\033'
898 && strlen(string) == 1) {
906 keypad_index(const char *string)
909 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
913 if ((ch = keypad_final(string)) != '\0') {
914 test = strchr(list, ch);
916 result = (test - list);
922 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
923 * is mapped inconsistently.
926 check_keypad(TERMTYPE *tp)
930 if (VALID_STRING(key_a1) &&
931 VALID_STRING(key_a3) &&
932 VALID_STRING(key_b2) &&
933 VALID_STRING(key_c1) &&
934 VALID_STRING(key_c3)) {
942 final[0] = keypad_final(key_a1);
943 final[1] = keypad_final(key_a3);
944 final[2] = keypad_final(key_b2);
945 final[3] = keypad_final(key_c1);
946 final[4] = keypad_final(key_c3);
949 /* special case: legacy coding using 1,2,3,0,. on the bottom */
950 if (!strcmp(final, "qsrpn"))
953 list[0] = keypad_index(key_a1);
954 list[1] = keypad_index(key_a3);
955 list[2] = keypad_index(key_b2);
956 list[3] = keypad_index(key_c1);
957 list[4] = keypad_index(key_c3);
959 /* check that they're all vt100 keys */
960 for (j = 0; j < 5; ++j) {
966 /* check if they're all in increasing order */
967 for (j = 1; j < 5; ++j) {
968 if (list[j] > list[j - 1]) {
975 for (j = 0, last = -1; j < 5; ++j) {
976 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
977 if (list[k] > last &&
986 strcat(show, " ka1");
989 strcat(show, " ka3");
992 strcat(show, " kb2");
995 strcat(show, " kc1");
998 strcat(show, " kc3");
1003 _nc_warning("vt100 keypad order inconsistent: %s", show);
1006 } else if (VALID_STRING(key_a1) ||
1007 VALID_STRING(key_a3) ||
1008 VALID_STRING(key_b2) ||
1009 VALID_STRING(key_c1) ||
1010 VALID_STRING(key_c3)) {
1012 if (keypad_index(key_a1) >= 0)
1013 strcat(show, " ka1");
1014 if (keypad_index(key_a3) >= 0)
1015 strcat(show, " ka3");
1016 if (keypad_index(key_b2) >= 0)
1017 strcat(show, " kb2");
1018 if (keypad_index(key_c1) >= 0)
1019 strcat(show, " kc1");
1020 if (keypad_index(key_c3) >= 0)
1021 strcat(show, " kc3");
1023 _nc_warning("vt100 keypad map incomplete:%s", show);
1028 * Returns the expected number of parameters for the given capability.
1031 expected_params(const char *name)
1034 static const struct {
1038 { "S0", 1 }, /* 'screen' extension */
1091 { "smgbp", 1 }, /* 2 if smgtp is not given */
1106 int result = 0; /* function-keys, etc., use none */
1108 for (n = 0; n < SIZEOF(table); n++) {
1109 if (!strcmp(name, table[n].name)) {
1110 result = table[n].count;
1119 * Make a quick sanity check for the parameters which are used in the given
1120 * strings. If there are no "%p" tokens, then there should be no other "%"
1124 check_params(TERMTYPE *tp, const char *name, char *value)
1126 int expected = expected_params(name);
1132 #ifdef set_top_margin_parm
1133 if (!strcmp(name, "smgbp")
1134 && set_top_margin_parm == 0)
1138 for (n = 0; n < 10; n++)
1144 _nc_warning("expected character after %% in %s", name);
1146 } else if (*s == 'p') {
1147 if (*++s == '\0' || !isdigit((int) *s)) {
1148 _nc_warning("expected digit after %%p in %s", name);
1162 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1164 if (value == set_attributes || expected < 0) {
1166 } else if (expected != actual) {
1167 _nc_warning("%s uses %d parameters, expected %d", name,
1169 for (n = 1; n < actual; n++) {
1171 _nc_warning("%s omits parameter %d", name, n);
1179 while (*s == '/' || isdigit(UChar(*s)))
1185 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1186 * the latter may have a worst-case delay on the end.
1189 ignore_delays(char *s)
1222 * An sgr string may contain several settings other than the one we're
1223 * interested in, essentially sgr0 + rmacs + whatever. As long as the
1224 * "whatever" is contained in the sgr string, that is close enough for our
1228 similar_sgr(int num, char *a, char *b)
1230 static const char *names[] =
1252 _nc_warning("Did not find delay %s", _nc_visbuf(b));
1254 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
1255 names[num], _nc_visbuf2(1, base_a),
1256 _nc_visbuf2(2, base_b),
1260 } else if (delaying) {
1283 /* ignore delays on the end of the string */
1284 a = ignore_delays(a);
1285 return ((num != 0) || (*a == 0));
1289 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1294 test = TPARM_9(set_attributes,
1306 if (!similar_sgr(num, test, cap)) {
1307 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1309 name, _nc_visbuf2(1, cap),
1310 num, _nc_visbuf2(2, test));
1312 } else if (_nc_capcmp(test, zero)) {
1313 _nc_warning("sgr(%d) present, but not %s", num, name);
1315 } else if (PRESENT(cap)) {
1316 _nc_warning("sgr(%d) missing, but %s present", num, name);
1319 _nc_warning("stack error in sgr(%d) string", num);
1323 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1327 * If tic is compiled with TRACE, we'll be able to see the output from the
1328 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
1329 * the standard error. Use this function to make it simpler to follow the
1330 * resulting debug traces.
1333 show_where(unsigned level)
1335 if (_nc_tracing >= DEBUG_LEVEL(level)) {
1337 _nc_get_type(my_name);
1338 fprintf(stderr, "\"%s\", line %d, '%s' ",
1340 _nc_curr_line, my_name);
1345 #define show_where(level) /* nothing */
1348 /* other sanity-checks (things that we don't want in the normal
1349 * logic that reads a terminfo entry)
1352 check_termtype(TERMTYPE *tp, bool literal)
1354 bool conflict = FALSE;
1356 char fkeys[STRCOUNT];
1359 * A terminal entry may contain more than one keycode assigned to
1360 * a given string (e.g., KEY_END and KEY_LL). But curses will only
1361 * return one (the last one assigned).
1363 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1364 memset(fkeys, 0, sizeof(fkeys));
1365 for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1366 char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1368 if (!VALID_STRING(a))
1370 for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1371 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1372 if (!VALID_STRING(b)
1375 if (!_nc_capcmp(a, b)) {
1380 _nc_warning("Conflicting key definitions (using the last)");
1383 fprintf(stderr, "... %s is the same as %s",
1384 keyname((int) _nc_tinfo_fkeys[j].code),
1385 keyname((int) _nc_tinfo_fkeys[k].code));
1388 fprintf(stderr, ", %s",
1389 keyname((int) _nc_tinfo_fkeys[k].code));
1394 fprintf(stderr, "\n");
1398 for (j = 0; j < NUM_STRINGS(tp); j++) {
1399 char *a = tp->Strings[j];
1400 if (VALID_STRING(a))
1401 check_params(tp, ExtStrname(tp, j, strnames), a);
1409 * These may be mismatched because the terminal description relies on
1410 * restoring the cursor visibility by resetting it.
1412 ANDMISSING(cursor_invisible, cursor_normal);
1413 ANDMISSING(cursor_visible, cursor_normal);
1415 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1416 && !_nc_capcmp(cursor_visible, cursor_normal))
1417 _nc_warning("cursor_visible is same as cursor_normal");
1420 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1421 * given, because the cursor position after the scrolling operation is
1422 * performed is undefined.
1424 ANDMISSING(change_scroll_region, save_cursor);
1425 ANDMISSING(change_scroll_region, restore_cursor);
1427 if (PRESENT(set_attributes)) {
1431 if (PRESENT(exit_attribute_mode)) {
1432 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1434 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1437 _nc_warning("stack error in sgr(0) string");
1440 CHECK_SGR(1, enter_standout_mode);
1441 CHECK_SGR(2, enter_underline_mode);
1442 CHECK_SGR(3, enter_reverse_mode);
1443 CHECK_SGR(4, enter_blink_mode);
1444 CHECK_SGR(5, enter_dim_mode);
1445 CHECK_SGR(6, enter_bold_mode);
1446 CHECK_SGR(7, enter_secure_mode);
1447 CHECK_SGR(8, enter_protected_mode);
1448 CHECK_SGR(9, enter_alt_charset_mode);
1451 _nc_warning("sgr(0) did not return a value");
1453 } else if (PRESENT(exit_attribute_mode) &&
1454 set_attributes != CANCELLED_STRING) {
1455 if (_nc_syntax == SYN_TERMINFO)
1456 _nc_warning("missing sgr string");
1459 if (PRESENT(exit_attribute_mode)) {
1460 char *check_sgr0 = _nc_trim_sgr0(tp);
1462 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1463 _nc_warning("trimmed sgr0 is empty");
1466 if (check_sgr0 != exit_attribute_mode) {
1468 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
1469 _nc_visbuf2(1, exit_attribute_mode),
1470 _nc_visbuf2(2, check_sgr0)));
1474 ("will not trim sgr0\n\toriginal sgr0=%s",
1475 _nc_visbuf(exit_attribute_mode)));
1481 if (!auto_right_margin) {
1483 ("can write to lower-right directly"));
1484 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1486 ("can write to lower-right by suppressing automargin"));
1487 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1488 || PRESENT(insert_character) || PRESENT(parm_ich)) {
1490 ("can write to lower-right by using inserts"));
1493 ("cannot write to lower-right"));
1498 * Some standard applications (e.g., vi) and some non-curses
1499 * applications (e.g., jove) get confused if we have both ich1 and
1500 * smir/rmir. Let's be nice and warn about that, too, even though
1501 * ncurses handles it.
1503 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1504 && PRESENT(parm_ich)) {
1505 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1509 * Finally, do the non-verbose checks
1511 if (save_check_termtype != 0)
1512 save_check_termtype(tp, literal);