1 /****************************************************************************
2 * Copyright (c) 1998-2010,2011 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.152 2011/08/06 17:41:36 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[] = "\
91 free_namelist(char **src)
95 for (n = 0; src[n] != 0; ++n)
103 cleanup(char **namelst GCC_UNUSED)
106 free_namelist(namelst);
110 if (to_remove != 0) {
120 failed(const char *msg)
123 cleanup((char **) 0);
124 ExitProgram(EXIT_FAILURE);
130 static const char *const tbl[] =
133 " -1 format translation output one capability per line",
135 " -a retain commented-out capabilities (sets -x also)",
137 " -K translate entries to termcap source form with BSD syntax",
138 " -C translate entries to termcap source form",
139 " -c check only, validate input without compiling or translating",
140 " -e<names> translate/compile only entries named by comma-separated list",
141 " -f format complex strings for readability",
142 " -G format %{number} to %'char'",
143 " -g format %'char' to %{number}",
144 " -I translate entries to terminfo source form",
145 " -L translate entries to full terminfo source form",
146 " -N disable smart defaults for source translation",
147 " -o<dir> set output directory for compiled entry writes",
148 " -R<name> restrict translation to given terminfo/termcap version",
149 " -r force resolution of all use entries in source translation",
150 " -s print summary statistics",
151 " -T remove size-restrictions on compiled description",
153 " -t suppress commented-out capabilities",
155 " -U suppress post-processing of entries",
157 " -v[n] set verbosity level",
158 " -w[n] set format width for translation output",
160 " -x treat unknown capabilities as user-defined",
164 " <file> file to translate or compile"
168 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
169 for (j = 0; j < SIZEOF(tbl); j++) {
170 fputs(tbl[j], stderr);
173 ExitProgram(EXIT_FAILURE);
178 #define S_QUOTE '\'';
186 char result[MAX_ENTRY_SIZE];
189 * Look for strings that contain %{number}, convert them to %'char',
190 * which is shorter and runs a little faster.
192 for (n = 0; n < STRCOUNT; n++) {
193 s = ep->tterm.Strings[n];
195 && strchr(s, L_BRACE) != 0) {
198 while ((ch = *t++) != 0) {
202 } else if ((ch == '%')
203 && (*t == L_BRACE)) {
205 long value = strtol(t + 1, &v, 0);
209 && value != '\\' /* FIXME */
211 && isprint((int) value)) {
220 if (strlen(result) < strlen(s))
225 _nc_set_type(_nc_first_name(ep->tterm.term_names));
226 _nc_curr_line = (int) ep->startline;
227 _nc_write_entry(&ep->tterm);
231 immedhook(ENTRY * ep GCC_UNUSED)
232 /* write out entries with no use capabilities immediately to save storage */
236 * This is strictly a core-economy kluge. The really clean way to handle
237 * compilation is to slurp the whole file into core and then do all the
238 * name-collision checks and entry writes in one swell foop. But the
239 * terminfo master file is large enough that some core-poor systems swap
240 * like crazy when you compile it this way...there have been reports of
241 * this process taking *three hours*, rather than the twenty seconds or
242 * less typical on my development box.
244 * So. This hook *immediately* writes out the referenced entry if it
245 * has no use capabilities. The compiler main loop refrains from
246 * adding the entry to the in-core list when this hook fires. If some
247 * other entry later needs to reference an entry that got written
248 * immediately, that's OK; the resolution code will fetch it off disk
249 * when it can't find it in core.
251 * Name collisions will still be detected, just not as cleanly. The
252 * write_entry() code complains before overwriting an entry that
253 * postdates the time of tic's first call to write_entry(). Thus
254 * it will complain about overwriting entries newly made during the
255 * tic run, but not about overwriting ones that predate it.
257 * The reason this is a hook, and not in line with the rest of the
258 * compiler code, is that the support for termcap fallback cannot assume
259 * it has anywhere to spool out these entries!
261 * The _nc_set_type() call here requires a compensating one in
264 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
265 * make tic a bit faster (because the resolution code won't have to do
266 * disk I/O nearly as often).
268 if (ep->nuses == 0) {
269 int oldline = _nc_curr_line;
272 _nc_curr_line = oldline;
273 free(ep->tterm.str_table);
276 #endif /* HAVE_BIG_CORE */
282 /* emit a comment char, translating terminfo names to termcap names */
284 static bool in_name = FALSE;
285 static size_t have, used;
286 static char *namebuf, *suffix;
289 if (used + 1 >= have) {
291 namebuf = typeRealloc(char, have, namebuf);
292 suffix = typeRealloc(char, have, suffix);
294 if (c == '\n' || c == '@') {
295 namebuf[used++] = '\0';
297 (void) fputs(namebuf, stdout);
300 } else if (c != '>') {
301 namebuf[used++] = (char) c;
302 } else { /* ah! candidate name! */
304 NCURSES_CONST char *tp;
306 namebuf[used++] = '\0';
310 if ((up = strchr(namebuf, '#')) != 0
311 || (up = strchr(namebuf, '=')) != 0
312 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
313 (void) strcpy(suffix, up);
317 if ((tp = nametrans(namebuf)) != 0) {
319 (void) fputs(tp, stdout);
320 (void) fputs(suffix, stdout);
323 /* couldn't find a translation, just dump the name */
325 (void) fputs(namebuf, stdout);
326 (void) fputs(suffix, stdout);
340 /* Returns a string, stripped of leading/trailing whitespace */
346 while (isspace(UChar(*src)))
352 if ((dst = strdup(src)) == NULL) {
356 while (--len != 0 && isspace(UChar(dst[len])))
364 open_input(const char *filename)
366 FILE *fp = fopen(filename, "r");
370 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
371 ExitProgram(EXIT_FAILURE);
373 if (fstat(fileno(fp), &sb) < 0
374 || (sb.st_mode & S_IFMT) != S_IFREG) {
375 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
376 ExitProgram(EXIT_FAILURE);
381 /* Parse the "-e" option-value into a list of names */
383 make_namelist(char *src)
388 unsigned pass, n, nn;
393 } else if (strchr(src, '/') != 0) { /* a filename */
394 FILE *fp = open_input(src);
396 for (pass = 1; pass <= 2; pass++) {
398 while (fgets(buffer, sizeof(buffer), fp) != 0) {
399 if ((s = stripped(buffer)) != 0) {
408 dst = typeCalloc(char *, nn + 1);
413 } else { /* literal list of names */
414 for (pass = 1; pass <= 2; pass++) {
415 for (n = nn = 0, base = src;; n++) {
417 if (mark == ',' || mark == '\0') {
422 if ((s = stripped(base)) != 0)
431 dst = typeCalloc(char *, nn + 1);
434 if (showsummary && (dst != 0)) {
435 fprintf(log_fp, "Entries that will be compiled:\n");
436 for (n = 0; dst[n] != 0; n++)
437 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
443 matches(char **needle, const char *haystack)
444 /* does entry in needle list match |-separated field in haystack? */
450 for (n = 0; needle[n] != 0; n++) {
451 if (_nc_name_match(haystack, needle[n], "|")) {
462 open_tempfile(char *name)
466 int fd = mkstemp(name);
468 result = fdopen(fd, "w");
470 if (tmpnam(name) != 0)
471 result = fopen(name, "w");
477 main(int argc, char *argv[])
479 char my_tmpname[PATH_MAX];
481 unsigned debug_level;
482 int smart_defaults = TRUE;
486 int this_opt, last_opt = '?';
488 int outform = F_TERMINFO; /* output format */
489 int sortmode = S_TERMINFO; /* sort_mode */
493 bool formatted = FALSE; /* reformat complex strings? */
494 bool literal = FALSE; /* suppress post-processing? */
495 int numbers = 0; /* format "%'char'" to/from "%{number}" */
496 bool forceresolve = FALSE; /* force resolution */
498 char *tversion = (char *) NULL;
499 const char *source_file = "terminfo";
501 char *outdir = (char *) NULL;
502 bool check_only = FALSE;
503 bool suppress_untranslatable = FALSE;
507 _nc_progname = _nc_rootname(argv[0]);
509 if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
510 outform = F_TERMINFO;
511 sortmode = S_TERMINFO;
513 if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
515 sortmode = S_TERMCAP;
518 use_extended_names(FALSE);
523 * Processing arguments is a little complicated, since someone made a
524 * design decision to allow the numeric values for -w, -v options to
527 while ((this_opt = getopt(argc, argv,
528 "0123456789CIKLNR:TUVace:fGgo:rstvwx")) != -1) {
529 if (isdigit(this_opt)) {
532 v_opt = (v_opt * 10) + (this_opt - '0');
535 width = (width * 10) + (this_opt - '0');
561 sortmode = S_TERMCAP;
565 outform = F_TERMINFO;
566 sortmode = S_TERMINFO;
570 outform = F_VARIABLE;
571 sortmode = S_VARIABLE;
574 smart_defaults = FALSE;
587 puts(curses_version());
589 ExitProgram(EXIT_SUCCESS);
594 namelst = make_namelist(optarg);
622 _nc_disable_period = FALSE;
623 suppress_untranslatable = TRUE;
626 _nc_disable_period = TRUE;
629 use_extended_names(TRUE);
638 debug_level = (unsigned) ((v_opt > 0) ? v_opt : (v_opt == 0));
639 set_trace_level(debug_level);
642 save_check_termtype = _nc_check_termtype2;
643 _nc_check_termtype2 = check_termtype;
647 * Aaargh! immedhook seriously hoses us!
649 * One problem with immedhook is it means we can't do -e. Problem
650 * is that we can't guarantee that for each terminal listed, all the
651 * terminals it depends on will have been kept in core for reference
652 * resolution -- in fact it's certain the primitive types at the end
653 * of reference chains *won't* be in core unless they were explicitly
654 * in the select list themselves.
656 if (namelst && (!infodump && !capdump)) {
657 (void) fprintf(stderr,
658 "Sorry, -e can't be used without -I or -C\n");
660 ExitProgram(EXIT_FAILURE);
662 #endif /* HAVE_BIG_CORE */
665 source_file = argv[optind++];
668 "%s: Too many file names. Usage:\n\t%s %s",
672 ExitProgram(EXIT_FAILURE);
675 if (infodump == TRUE) {
676 /* captoinfo's no-argument case */
677 source_file = "/etc/termcap";
678 if ((termcap = getenv("TERMCAP")) != 0
679 && (namelst = make_namelist(getenv("TERM"))) != 0) {
680 if (access(termcap, F_OK) == 0) {
682 source_file = termcap;
683 } else if ((tmp_fp = open_tempfile(strcpy(my_tmpname,
686 source_file = my_tmpname;
687 fprintf(tmp_fp, "%s\n", termcap);
689 tmp_fp = open_input(source_file);
690 to_remove = source_file;
698 "%s: File name needed. Usage:\n\t%s %s",
703 ExitProgram(EXIT_FAILURE);
708 tmp_fp = open_input(source_file);
715 sortmode, width, height, debug_level, formatted);
719 sortmode, width, height, debug_level, FALSE);
721 /* parse entries out of the source file */
722 _nc_set_source(source_file);
724 if (!(check_only || infodump || capdump))
725 _nc_set_writedir(outdir);
726 #endif /* HAVE_BIG_CORE */
727 _nc_read_entry_source(tmp_fp, (char *) NULL,
728 !smart_defaults || literal, FALSE,
729 ((check_only || infodump || capdump)
733 /* do use resolution */
734 if (check_only || (!infodump && !capdump) || forceresolve) {
735 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
737 ExitProgram(EXIT_FAILURE);
742 if (check_only && (capdump || infodump)) {
744 if (matches(namelst, qp->tterm.term_names)) {
745 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
747 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
748 (void) fprintf(stderr,
749 "warning: resolved %s entry is %d bytes long\n",
750 _nc_first_name(qp->tterm.term_names),
756 /* write or dump all entries */
758 if (!infodump && !capdump) {
759 _nc_set_writedir(outdir);
761 if (matches(namelst, qp->tterm.term_names))
765 /* this is in case infotocap() generates warnings */
766 _nc_curr_col = _nc_curr_line = -1;
769 if (matches(namelst, qp->tterm.term_names)) {
770 long j = qp->cend - qp->cstart;
773 /* this is in case infotocap() generates warnings */
774 _nc_set_type(_nc_first_name(qp->tterm.term_names));
776 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
779 (void) putchar(fgetc(tmp_fp));
781 put_translate(fgetc(tmp_fp));
784 repair_acsc(&qp->tterm);
785 dump_entry(&qp->tterm, suppress_untranslatable,
786 limited, numbers, NULL);
787 for (j = 0; j < (long) qp->nuses; j++)
788 dump_uses(qp->uses[j].name, !capdump);
790 if (debug_level != 0 && !limited)
791 printf("# length=%d\n", len);
794 if (!namelst && _nc_tail) {
796 bool in_comment = FALSE;
797 bool trailing_comment = FALSE;
799 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
800 while ((c = fgetc(tmp_fp)) != EOF) {
803 trailing_comment = TRUE;
810 && (in_comment || (oldc == '\n' && c == '\n')))
818 /* Show the directory into which entries were written, and the total
822 && (!(check_only || infodump || capdump))) {
823 int total = _nc_tic_written();
825 fprintf(log_fp, "%d entries written to %s\n",
827 _nc_tic_dir((char *) 0));
829 fprintf(log_fp, "No entries written\n");
832 ExitProgram(EXIT_SUCCESS);
836 * This bit of legerdemain turns all the terminfo variable names into
837 * references to locations in the arrays Booleans, Numbers, and Strings ---
838 * precisely what's needed (see comp_parse.c).
844 * Check if the alternate character-set capabilities are consistent.
847 check_acs(TERMTYPE *tp)
849 if (VALID_STRING(acs_chars)) {
850 const char *boxes = "lmkjtuvwqxn";
856 memset(mapped, 0, sizeof(mapped));
857 for (p = acs_chars; *p != '\0'; p += 2) {
859 _nc_warning("acsc has odd number of characters");
862 mapped[UChar(p[0])] = p[1];
865 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
866 _nc_warning("acsc refers to 'I', which is probably an error");
869 for (p = boxes, q = missing; *p != '\0'; ++p) {
870 if (!mapped[UChar(p[0])]) {
876 assert(strlen(missing) <= strlen(boxes));
877 if (*missing != '\0' && strcmp(missing, boxes)) {
878 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
884 * Check if the color capabilities are consistent
887 check_colors(TERMTYPE *tp)
889 if ((max_colors > 0) != (max_pairs > 0)
890 || ((max_colors > max_pairs) && (initialize_pair == 0)))
891 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
892 max_colors, max_pairs);
894 PAIRED(set_foreground, set_background);
895 PAIRED(set_a_foreground, set_a_background);
896 PAIRED(set_color_pair, initialize_pair);
898 if (VALID_STRING(set_foreground)
899 && VALID_STRING(set_a_foreground)
900 && !_nc_capcmp(set_foreground, set_a_foreground))
901 _nc_warning("expected setf/setaf to be different");
903 if (VALID_STRING(set_background)
904 && VALID_STRING(set_a_background)
905 && !_nc_capcmp(set_background, set_a_background))
906 _nc_warning("expected setb/setab to be different");
908 /* see: has_colors() */
909 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
910 && (((set_foreground != NULL)
911 && (set_background != NULL))
912 || ((set_a_foreground != NULL)
913 && (set_a_background != NULL))
914 || set_color_pair)) {
915 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
916 _nc_warning("expected either op/oc string for resetting colors");
921 keypad_final(const char *string)
925 if (VALID_STRING(string)
926 && *string++ == '\033'
928 && strlen(string) == 1) {
936 keypad_index(const char *string)
939 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
943 if ((ch = keypad_final(string)) != '\0') {
944 test = strchr(list, ch);
946 result = (long) (test - list);
952 * list[] is down, up, left, right
953 * "left" may be ^H rather than \E[D
954 * "down" may be ^J rather than \E[B
955 * But up/right are generally consistently escape sequences for ANSI terminals.
958 check_ansi_cursor(char *list[4])
965 bool repeated = FALSE;
967 for (j = 0; j < 4; ++j) {
969 for (k = 0; k < j; ++k) {
971 && !strcmp(list[j], list[k])) {
972 char *value = _nc_tic_expand(list[k], TRUE, 0);
973 _nc_warning("repeated cursor control %s\n", value);
981 if (UChar(up[0]) == '\033') {
987 } else if (UChar(up[0]) == UChar('\233')) {
992 while (up[suffix] && isdigit(UChar(up[suffix])))
995 if (prefix && up[suffix] == 'A') {
997 if (!strcmp(list[0], "\n"))
999 if (!strcmp(list[2], "\b"))
1002 for (j = 0; j < 4; ++j) {
1003 if (skip[j] || strlen(list[j]) == 1)
1005 if (memcmp(list[j], up, prefix)) {
1006 char *value = _nc_tic_expand(list[j], TRUE, 0);
1007 _nc_warning("inconsistent prefix for %s\n", value);
1010 if (strlen(list[j]) < suffix) {
1011 char *value = _nc_tic_expand(list[j], TRUE, 0);
1012 _nc_warning("inconsistent length for %s, expected %d\n",
1013 value, (int) suffix + 1);
1017 if (list[j][suffix] != want) {
1018 char *value = _nc_tic_expand(list[j], TRUE, 0);
1019 _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
1020 value, want, list[j][suffix]);
1027 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
1030 check_cursor(TERMTYPE *tp)
1035 /* if we have a parameterized form, then the non-parameterized is easy */
1036 ANDMISSING(parm_down_cursor, cursor_down);
1037 ANDMISSING(parm_up_cursor, cursor_up);
1038 ANDMISSING(parm_left_cursor, cursor_left);
1039 ANDMISSING(parm_right_cursor, cursor_right);
1041 /* Given any of a set of cursor movement, the whole set should be present.
1042 * Technically this is not true (we could use cursor_address to fill in
1043 * unsupported controls), but it is likely.
1046 if (PRESENT(parm_down_cursor)) {
1047 list[count++] = parm_down_cursor;
1049 if (PRESENT(parm_up_cursor)) {
1050 list[count++] = parm_up_cursor;
1052 if (PRESENT(parm_left_cursor)) {
1053 list[count++] = parm_left_cursor;
1055 if (PRESENT(parm_right_cursor)) {
1056 list[count++] = parm_right_cursor;
1059 check_ansi_cursor(list);
1060 } else if (count != 0) {
1061 EXPECTED(parm_down_cursor);
1062 EXPECTED(parm_up_cursor);
1063 EXPECTED(parm_left_cursor);
1064 EXPECTED(parm_right_cursor);
1068 if (PRESENT(cursor_down)) {
1069 list[count++] = cursor_down;
1071 if (PRESENT(cursor_up)) {
1072 list[count++] = cursor_up;
1074 if (PRESENT(cursor_left)) {
1075 list[count++] = cursor_left;
1077 if (PRESENT(cursor_right)) {
1078 list[count++] = cursor_right;
1081 check_ansi_cursor(list);
1082 } else if (count != 0) {
1084 if (PRESENT(cursor_down) && strcmp(cursor_down, "\n"))
1086 if (PRESENT(cursor_left) && strcmp(cursor_left, "\b"))
1088 if (PRESENT(cursor_up) && strlen(cursor_up) > 1)
1090 if (PRESENT(cursor_right) && strlen(cursor_right) > 1)
1093 EXPECTED(cursor_down);
1094 EXPECTED(cursor_up);
1095 EXPECTED(cursor_left);
1096 EXPECTED(cursor_right);
1103 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
1104 * is mapped inconsistently.
1107 check_keypad(TERMTYPE *tp)
1111 if (VALID_STRING(key_a1) &&
1112 VALID_STRING(key_a3) &&
1113 VALID_STRING(key_b2) &&
1114 VALID_STRING(key_c1) &&
1115 VALID_STRING(key_c3)) {
1116 char final[MAX_KP + 1];
1123 final[0] = keypad_final(key_a1);
1124 final[1] = keypad_final(key_a3);
1125 final[2] = keypad_final(key_b2);
1126 final[3] = keypad_final(key_c1);
1127 final[4] = keypad_final(key_c3);
1130 /* special case: legacy coding using 1,2,3,0,. on the bottom */
1131 assert(strlen(final) <= MAX_KP);
1132 if (!strcmp(final, "qsrpn"))
1135 list[0] = keypad_index(key_a1);
1136 list[1] = keypad_index(key_a3);
1137 list[2] = keypad_index(key_b2);
1138 list[3] = keypad_index(key_c1);
1139 list[4] = keypad_index(key_c3);
1141 /* check that they're all vt100 keys */
1142 for (j = 0; j < MAX_KP; ++j) {
1148 /* check if they're all in increasing order */
1149 for (j = 1; j < MAX_KP; ++j) {
1150 if (list[j] > list[j - 1]) {
1154 if (increase != (MAX_KP - 1)) {
1157 for (j = 0, last = -1; j < MAX_KP; ++j) {
1158 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
1159 if (list[k] > last &&
1166 assert(strlen(show) < (MAX_KP * 4));
1169 strcat(show, " ka1");
1172 strcat(show, " ka3");
1175 strcat(show, " kb2");
1178 strcat(show, " kc1");
1181 strcat(show, " kc3");
1186 _nc_warning("vt100 keypad order inconsistent: %s", show);
1189 } else if (VALID_STRING(key_a1) ||
1190 VALID_STRING(key_a3) ||
1191 VALID_STRING(key_b2) ||
1192 VALID_STRING(key_c1) ||
1193 VALID_STRING(key_c3)) {
1195 if (keypad_index(key_a1) >= 0)
1196 strcat(show, " ka1");
1197 if (keypad_index(key_a3) >= 0)
1198 strcat(show, " ka3");
1199 if (keypad_index(key_b2) >= 0)
1200 strcat(show, " kb2");
1201 if (keypad_index(key_c1) >= 0)
1202 strcat(show, " kc1");
1203 if (keypad_index(key_c3) >= 0)
1204 strcat(show, " kc3");
1206 _nc_warning("vt100 keypad map incomplete:%s", show);
1211 check_printer(TERMTYPE *tp)
1213 PAIRED(enter_doublewide_mode, exit_doublewide_mode);
1214 PAIRED(enter_italics_mode, exit_italics_mode);
1215 PAIRED(enter_leftward_mode, exit_leftward_mode);
1216 PAIRED(enter_micro_mode, exit_micro_mode);
1217 PAIRED(enter_shadow_mode, exit_shadow_mode);
1218 PAIRED(enter_subscript_mode, exit_subscript_mode);
1219 PAIRED(enter_superscript_mode, exit_superscript_mode);
1220 PAIRED(enter_upward_mode, exit_upward_mode);
1222 ANDMISSING(start_char_set_def, stop_char_set_def);
1224 /* if we have a parameterized form, then the non-parameterized is easy */
1225 ANDMISSING(set_bottom_margin_parm, set_bottom_margin);
1226 ANDMISSING(set_left_margin_parm, set_left_margin);
1227 ANDMISSING(set_right_margin_parm, set_right_margin);
1228 ANDMISSING(set_top_margin_parm, set_top_margin);
1230 ANDMISSING(parm_down_micro, micro_down);
1231 ANDMISSING(parm_left_micro, micro_left);
1232 ANDMISSING(parm_right_micro, micro_right);
1233 ANDMISSING(parm_up_micro, micro_up);
1237 * Returns the expected number of parameters for the given capability.
1240 expected_params(const char *name)
1243 static const struct {
1247 { "S0", 1 }, /* 'screen' extension */
1300 { "smgbp", 1 }, /* 2 if smgtp is not given */
1315 int result = 0; /* function-keys, etc., use none */
1317 for (n = 0; n < SIZEOF(table); n++) {
1318 if (!strcmp(name, table[n].name)) {
1319 result = table[n].count;
1328 * Make a quick sanity check for the parameters which are used in the given
1329 * strings. If there are no "%p" tokens, then there should be no other "%"
1333 check_params(TERMTYPE *tp, const char *name, char *value)
1335 int expected = expected_params(name);
1341 #ifdef set_top_margin_parm
1342 if (!strcmp(name, "smgbp")
1343 && set_top_margin_parm == 0)
1347 for (n = 0; n < 10; n++)
1353 _nc_warning("expected character after %% in %s", name);
1355 } else if (*s == 'p') {
1356 if (*++s == '\0' || !isdigit((int) *s)) {
1357 _nc_warning("expected digit after %%p in %s", name);
1371 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1373 if (value == set_attributes || expected < 0) {
1375 } else if (expected != actual) {
1376 _nc_warning("%s uses %d parameters, expected %d", name,
1378 for (n = 1; n < actual; n++) {
1380 _nc_warning("%s omits parameter %d", name, n);
1388 while (*s == '/' || isdigit(UChar(*s)))
1394 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1395 * the latter may have a worst-case delay on the end.
1398 ignore_delays(char *s)
1431 * An sgr string may contain several settings other than the one we're
1432 * interested in, essentially sgr0 + rmacs + whatever. As long as the
1433 * "whatever" is contained in the sgr string, that is close enough for our
1437 similar_sgr(int num, char *a, char *b)
1439 static const char *names[] =
1461 _nc_warning("Did not find delay %s", _nc_visbuf(b));
1463 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
1464 names[num], _nc_visbuf2(1, base_a),
1465 _nc_visbuf2(2, base_b),
1469 } else if (delaying) {
1472 } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
1494 /* ignore delays on the end of the string */
1495 a = ignore_delays(a);
1496 return ((num != 0) || (*a == 0));
1500 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
1505 test = TPARM_9(set_attributes,
1517 if (!similar_sgr(num, test, cap)) {
1518 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
1520 name, _nc_visbuf2(1, cap),
1521 num, _nc_visbuf2(2, test));
1523 } else if (_nc_capcmp(test, zero)) {
1524 _nc_warning("sgr(%d) present, but not %s", num, name);
1526 } else if (PRESENT(cap)) {
1527 _nc_warning("sgr(%d) missing, but %s present", num, name);
1530 _nc_warning("stack error in sgr(%d) string", num);
1534 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
1538 * If tic is compiled with TRACE, we'll be able to see the output from the
1539 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
1540 * the standard error. Use this function to make it simpler to follow the
1541 * resulting debug traces.
1544 show_where(unsigned level)
1546 if (_nc_tracing >= DEBUG_LEVEL(level)) {
1548 _nc_get_type(my_name);
1549 _tracef("\"%s\", line %d, '%s'",
1551 _nc_curr_line, my_name);
1556 #define show_where(level) /* nothing */
1559 /* other sanity-checks (things that we don't want in the normal
1560 * logic that reads a terminfo entry)
1563 check_termtype(TERMTYPE *tp, bool literal)
1565 bool conflict = FALSE;
1567 char fkeys[STRCOUNT];
1570 * A terminal entry may contain more than one keycode assigned to
1571 * a given string (e.g., KEY_END and KEY_LL). But curses will only
1572 * return one (the last one assigned).
1574 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
1575 memset(fkeys, 0, sizeof(fkeys));
1576 for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
1577 char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
1579 if (!VALID_STRING(a))
1581 for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
1582 char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
1583 if (!VALID_STRING(b)
1586 if (!_nc_capcmp(a, b)) {
1591 _nc_warning("Conflicting key definitions (using the last)");
1594 fprintf(stderr, "... %s is the same as %s",
1595 keyname((int) _nc_tinfo_fkeys[j].code),
1596 keyname((int) _nc_tinfo_fkeys[k].code));
1599 fprintf(stderr, ", %s",
1600 keyname((int) _nc_tinfo_fkeys[k].code));
1605 fprintf(stderr, "\n");
1609 for (j = 0; j < NUM_STRINGS(tp); j++) {
1610 char *a = tp->Strings[j];
1611 if (VALID_STRING(a))
1612 check_params(tp, ExtStrname(tp, (int) j, strnames), a);
1622 * These may be mismatched because the terminal description relies on
1623 * restoring the cursor visibility by resetting it.
1625 ANDMISSING(cursor_invisible, cursor_normal);
1626 ANDMISSING(cursor_visible, cursor_normal);
1628 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
1629 && !_nc_capcmp(cursor_visible, cursor_normal))
1630 _nc_warning("cursor_visible is same as cursor_normal");
1633 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
1634 * given, because the cursor position after the scrolling operation is
1635 * performed is undefined.
1637 ANDMISSING(change_scroll_region, save_cursor);
1638 ANDMISSING(change_scroll_region, restore_cursor);
1641 * If we can clear tabs, we should be able to initialize them.
1643 ANDMISSING(clear_all_tabs, set_tab);
1645 if (PRESENT(set_attributes)) {
1649 if (PRESENT(exit_attribute_mode)) {
1650 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
1652 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
1655 _nc_warning("stack error in sgr(0) string");
1658 CHECK_SGR(1, enter_standout_mode);
1659 CHECK_SGR(2, enter_underline_mode);
1660 CHECK_SGR(3, enter_reverse_mode);
1661 CHECK_SGR(4, enter_blink_mode);
1662 CHECK_SGR(5, enter_dim_mode);
1663 CHECK_SGR(6, enter_bold_mode);
1664 CHECK_SGR(7, enter_secure_mode);
1665 CHECK_SGR(8, enter_protected_mode);
1666 CHECK_SGR(9, enter_alt_charset_mode);
1669 _nc_warning("sgr(0) did not return a value");
1671 } else if (PRESENT(exit_attribute_mode) &&
1672 set_attributes != CANCELLED_STRING) {
1673 if (_nc_syntax == SYN_TERMINFO)
1674 _nc_warning("missing sgr string");
1677 if (PRESENT(exit_attribute_mode)) {
1678 char *check_sgr0 = _nc_trim_sgr0(tp);
1680 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
1681 _nc_warning("trimmed sgr0 is empty");
1684 if (check_sgr0 != exit_attribute_mode) {
1686 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
1687 _nc_visbuf2(1, exit_attribute_mode),
1688 _nc_visbuf2(2, check_sgr0)));
1692 ("will not trim sgr0\n\toriginal sgr0=%s",
1693 _nc_visbuf(exit_attribute_mode)));
1699 if (!auto_right_margin) {
1701 ("can write to lower-right directly"));
1702 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
1704 ("can write to lower-right by suppressing automargin"));
1705 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
1706 || PRESENT(insert_character) || PRESENT(parm_ich)) {
1708 ("can write to lower-right by using inserts"));
1711 ("cannot write to lower-right"));
1716 * Some standard applications (e.g., vi) and some non-curses
1717 * applications (e.g., jove) get confused if we have both ich1 and
1718 * smir/rmir. Let's be nice and warn about that, too, even though
1719 * ncurses handles it.
1721 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1722 && PRESENT(parm_ich)) {
1723 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
1727 * Finally, do the non-verbose checks
1729 if (save_check_termtype != 0)
1730 save_check_termtype(tp, literal);