1 /****************************************************************************
2 * Copyright (c) 1998-2015,2016 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
42 #include <progs.priv.h>
45 #include <dump_entry.h>
46 #include <tparm_type.h>
47 #include <hashed_db.h>
48 #include <parametrized.h>
49 #include <transform.h>
51 MODULE_ID("$Id: tic.c,v 1.224 2016/10/01 12:46:54 tom Exp $")
53 #define STDIN_NAME "<stdin>"
55 const char *_nc_progname = "tic";
59 static bool capdump = FALSE; /* running as infotocap? */
60 static bool infodump = FALSE; /* running as captoinfo? */
61 static bool showsummary = FALSE;
62 static char **namelst = 0;
63 static const char *to_remove;
65 static void (*save_check_termtype) (TERMTYPE *, bool);
66 static void check_termtype(TERMTYPE *tt, bool);
68 static const char usage_string[] = "\
99 free_namelist(char **src)
103 for (n = 0; src[n] != 0; ++n)
116 free_namelist(namelst);
120 if (to_remove != 0) {
122 rc = remove(to_remove);
124 rc = unlink(to_remove);
132 failed(const char *msg)
135 ExitProgram(EXIT_FAILURE);
141 #define DATA(s) s "\n"
142 static const char options_string[] =
145 DATA(" -0 format translation output all capabilities on one line")
146 DATA(" -1 format translation output one capability per line")
148 DATA(" -a retain commented-out capabilities (sets -x also)")
150 DATA(" -C translate entries to termcap source form")
151 DATA(" -D print list of tic's database locations (first must be writable)")
152 DATA(" -c check only, validate input without compiling or translating")
153 DATA(" -e<names> translate/compile only entries named by comma-separated list")
154 DATA(" -f format complex strings for readability")
155 DATA(" -G format %{number} to %'char'")
156 DATA(" -g format %'char' to %{number}")
157 DATA(" -I translate entries to terminfo source form")
158 DATA(" -K translate entries to termcap source form with BSD syntax")
159 DATA(" -L translate entries to full terminfo source form")
160 DATA(" -N disable smart defaults for source translation")
161 DATA(" -o<dir> set output directory for compiled entry writes")
162 DATA(" -Q[n] dump compiled description")
163 DATA(" -q brief listing, removes headers")
164 DATA(" -R<name> restrict translation to given terminfo/termcap version")
165 DATA(" -r force resolution of all use entries in source translation")
166 DATA(" -s print summary statistics")
167 DATA(" -T remove size-restrictions on compiled description")
169 DATA(" -t suppress commented-out capabilities")
171 DATA(" -U suppress post-processing of entries")
172 DATA(" -V print version")
173 DATA(" -W wrap long strings according to -w[n] option")
174 DATA(" -v[n] set verbosity level")
175 DATA(" -w[n] set format width for translation output")
177 DATA(" -x treat unknown capabilities as user-defined")
181 DATA(" <file> file to translate or compile")
185 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
186 fputs(options_string, stderr);
187 ExitProgram(EXIT_FAILURE);
200 char result[MAX_ENTRY_SIZE];
203 * Look for strings that contain %{number}, convert them to %'char',
204 * which is shorter and runs a little faster.
206 for (n = 0; n < STRCOUNT; n++) {
207 s = ep->tterm.Strings[n];
209 && strchr(s, L_BRACE) != 0) {
212 while ((ch = *t++) != 0) {
216 } else if ((ch == '%')
217 && (*t == L_BRACE)) {
219 long value = strtol(t + 1, &v, 0);
223 && value != '\\' /* FIXME */
225 && isprint((int) value)) {
234 if (strlen(result) < strlen(s))
235 _nc_STRCPY(s, result, strlen(s) + 1);
239 _nc_set_type(_nc_first_name(ep->tterm.term_names));
240 _nc_curr_line = (int) ep->startline;
241 _nc_write_entry(&ep->tterm);
245 immedhook(ENTRY * ep GCC_UNUSED)
246 /* write out entries with no use capabilities immediately to save storage */
250 * This is strictly a core-economy kluge. The really clean way to handle
251 * compilation is to slurp the whole file into core and then do all the
252 * name-collision checks and entry writes in one swell foop. But the
253 * terminfo master file is large enough that some core-poor systems swap
254 * like crazy when you compile it this way...there have been reports of
255 * this process taking *three hours*, rather than the twenty seconds or
256 * less typical on my development box.
258 * So. This hook *immediately* writes out the referenced entry if it
259 * has no use capabilities. The compiler main loop refrains from
260 * adding the entry to the in-core list when this hook fires. If some
261 * other entry later needs to reference an entry that got written
262 * immediately, that's OK; the resolution code will fetch it off disk
263 * when it can't find it in core.
265 * Name collisions will still be detected, just not as cleanly. The
266 * write_entry() code complains before overwriting an entry that
267 * postdates the time of tic's first call to write_entry(). Thus
268 * it will complain about overwriting entries newly made during the
269 * tic run, but not about overwriting ones that predate it.
271 * The reason this is a hook, and not in line with the rest of the
272 * compiler code, is that the support for termcap fallback cannot assume
273 * it has anywhere to spool out these entries!
275 * The _nc_set_type() call here requires a compensating one in
278 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
279 * make tic a bit faster (because the resolution code won't have to do
280 * disk I/O nearly as often).
282 if (ep->nuses == 0) {
283 int oldline = _nc_curr_line;
286 _nc_curr_line = oldline;
287 free(ep->tterm.str_table);
290 #endif /* HAVE_BIG_CORE */
296 /* emit a comment char, translating terminfo names to termcap names */
298 static bool in_name = FALSE;
299 static size_t have, used;
300 static char *namebuf, *suffix;
303 if (used + 1 >= have) {
305 if ((namebuf = typeRealloc(char, have, namebuf)) == 0)
306 failed("put_translate namebuf");
307 if ((suffix = typeRealloc(char, have, suffix)) == 0)
308 failed("put_translate suffix");
310 if (c == '\n' || c == '@') {
311 namebuf[used++] = '\0';
313 (void) fputs(namebuf, stdout);
316 } else if (c != '>') {
317 namebuf[used++] = (char) c;
318 } else { /* ah! candidate name! */
320 NCURSES_CONST char *tp;
322 namebuf[used++] = '\0';
326 if ((up = strchr(namebuf, '#')) != 0
327 || (up = strchr(namebuf, '=')) != 0
328 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
329 _nc_STRCPY(suffix, up, have);
333 if ((tp = nametrans(namebuf)) != 0) {
335 (void) fputs(tp, stdout);
336 (void) fputs(suffix, stdout);
339 /* couldn't find a translation, just dump the name */
341 (void) fputs(namebuf, stdout);
342 (void) fputs(suffix, stdout);
356 /* Returns a string, stripped of leading/trailing whitespace */
362 while (isspace(UChar(*src)))
368 if ((dst = strdup(src)) == NULL) {
372 while (--len != 0 && isspace(UChar(dst[len])))
380 open_tempfile(char *filename)
384 _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
387 int oldmask = (int) umask(077);
388 int fd = mkstemp(filename);
390 result = fdopen(fd, "w");
391 umask((mode_t) oldmask);
394 if (tmpnam(filename) != 0)
395 result = fopen(filename, "w");
401 copy_input(FILE *source, const char *filename, char *alt_file)
403 char my_altfile[PATH_MAX];
409 alt_file = my_altfile;
412 failed("copy_input (source)");
413 } else if ((target = open_tempfile(alt_file)) == 0) {
414 failed("copy_input (target)");
421 } else if (ferror(source)) {
423 } else if (ch == 0) {
424 /* don't loop in case someone wants to convert /dev/zero */
425 fprintf(stderr, "%s: %s is not a text-file\n", _nc_progname, filename);
426 ExitProgram(EXIT_FAILURE);
432 * rewind() does not force the target file's data to disk (not does
433 * fflush()...). So open a second stream on the data and then close
434 * the one that we were writing on before starting to read from the
437 result = fopen(alt_file, "r+");
439 to_remove = strdup(alt_file);
445 open_input(const char *filename, char *alt_file)
451 if (!strcmp(filename, "-")) {
452 fp = copy_input(stdin, STDIN_NAME, alt_file);
453 } else if (stat(filename, &sb) < 0) {
454 fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
455 ExitProgram(EXIT_FAILURE);
456 } else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
457 || (mode != S_IFREG && mode != S_IFCHR && mode != S_IFIFO)) {
458 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
459 ExitProgram(EXIT_FAILURE);
461 fp = fopen(filename, "r");
464 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
465 ExitProgram(EXIT_FAILURE);
467 if (mode != S_IFREG) {
469 FILE *fp2 = copy_input(fp, filename, alt_file);
472 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
473 ExitProgram(EXIT_FAILURE);
480 /* Parse the "-e" option-value into a list of names */
482 make_namelist(char *src)
487 unsigned pass, n, nn;
492 } else if (strchr(src, '/') != 0) { /* a filename */
493 FILE *fp = open_input(src, (char *) 0);
495 for (pass = 1; pass <= 2; pass++) {
497 while (fgets(buffer, sizeof(buffer), fp) != 0) {
498 if ((s = stripped(buffer)) != 0) {
507 if ((dst = typeCalloc(char *, nn + 1)) == 0)
508 failed("make_namelist");
513 } else { /* literal list of names */
514 for (pass = 1; pass <= 2; pass++) {
515 for (n = nn = 0, base = src;; n++) {
517 if (mark == ',' || mark == '\0') {
522 if ((s = stripped(base)) != 0)
531 if ((dst = typeCalloc(char *, nn + 1)) == 0)
532 failed("make_namelist");
536 if (showsummary && (dst != 0)) {
537 fprintf(log_fp, "Entries that will be compiled:\n");
538 for (n = 0; dst[n] != 0; n++)
539 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
545 matches(char **needle, const char *haystack)
546 /* does entry in needle list match |-separated field in haystack? */
552 for (n = 0; needle[n] != 0; n++) {
553 if (_nc_name_match(haystack, needle[n], "|")) {
564 valid_db_path(const char *nominal)
568 char suffix[] = DBM_SUFFIX;
569 size_t need = strlen(nominal) + sizeof(suffix);
570 char *result = malloc(need);
573 failed("valid_db_path");
574 _nc_STRCPY(result, nominal, need);
575 if (strcmp(result + need - sizeof(suffix), suffix)) {
576 _nc_STRCAT(result, suffix, need);
579 char *result = strdup(nominal);
582 DEBUG(1, ("** stat(%s)", result));
583 if (stat(result, &sb) >= 0) {
585 if (!S_ISREG(sb.st_mode)
586 || access(result, R_OK | W_OK) != 0) {
587 DEBUG(1, ("...not a writable file"));
592 if (!S_ISDIR(sb.st_mode)
593 || access(result, R_OK | W_OK | X_OK) != 0) {
594 DEBUG(1, ("...not a writable directory"));
600 /* check if parent is directory and is writable */
601 unsigned leaf = _nc_pathlast(result);
603 DEBUG(1, ("...not found"));
605 char save = result[leaf];
607 if (stat(result, &sb) >= 0
608 && S_ISDIR(sb.st_mode)
609 && access(result, R_OK | W_OK | X_OK) == 0) {
612 DEBUG(1, ("...parent directory %s is not writable", result));
617 DEBUG(1, ("... no parent directory"));
626 * Show the databases to which tic could write. The location to which it
627 * writes is always the first one. If none are writable, print an error
631 show_databases(const char *outdir)
633 bool specific = (outdir != 0) || getenv("TERMINFO") != 0;
635 const char *tried = 0;
638 outdir = _nc_tic_dir(0);
640 if ((result = valid_db_path(outdir)) != 0) {
641 printf("%s\n", result);
647 if ((outdir = _nc_home_terminfo())) {
648 if ((result = valid_db_path(outdir)) != 0) {
649 printf("%s\n", result);
651 } else if (!specific) {
657 * If we can write in neither location, give an error message.
661 fprintf(stderr, "%s: %s (no permission)\n", _nc_progname, tried);
662 ExitProgram(EXIT_FAILURE);
667 add_digit(int *target, int source)
669 *target = (*target * 10) + (source - '0');
672 #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
675 main(int argc, char *argv[])
677 char my_tmpname[PATH_MAX];
678 char my_altfile[PATH_MAX];
680 unsigned debug_level;
681 int smart_defaults = TRUE;
685 int this_opt, last_opt = '?';
687 int outform = F_TERMINFO; /* output format */
688 int sortmode = S_TERMINFO; /* sort_mode */
692 bool formatted = FALSE; /* reformat complex strings? */
693 bool literal = FALSE; /* suppress post-processing? */
694 int numbers = 0; /* format "%'char'" to/from "%{number}" */
695 bool forceresolve = FALSE; /* force resolution */
697 char *tversion = (char *) NULL;
698 const char *source_file = "terminfo";
699 char *outdir = (char *) NULL;
700 bool check_only = FALSE;
701 bool suppress_untranslatable = FALSE;
704 bool wrap_strings = FALSE;
708 _nc_progname = _nc_rootname(argv[0]);
711 if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
712 outform = F_TERMINFO;
713 sortmode = S_TERMINFO;
715 if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
717 sortmode = S_TERMCAP;
720 use_extended_names(FALSE);
725 * Processing arguments is a little complicated, since someone made a
726 * design decision to allow the numeric values for -w, -v options to
729 while ((this_opt = getopt(argc, argv,
730 "0123456789CDIKLNQR:TUVWace:fGgo:qrstvwx")) != -1) {
731 if (isdigit(this_opt)) {
734 add_digit(&quickdump, this_opt);
737 add_digit(&v_opt, this_opt);
740 add_digit(&width, this_opt);
762 /* the initial version of -K in 20110730 fell-thru here, but the
763 * same flag is useful when reading sources -TD
769 sortmode = S_TERMCAP;
772 debug_level = VtoTrace(v_opt);
773 set_trace_level(debug_level);
774 show_databases(outdir);
775 ExitProgram(EXIT_SUCCESS);
779 outform = F_TERMINFO;
780 sortmode = S_TERMINFO;
784 outform = F_VARIABLE;
785 sortmode = S_VARIABLE;
788 smart_defaults = FALSE;
804 puts(curses_version());
805 ExitProgram(EXIT_SUCCESS);
813 namelst = make_namelist(optarg);
844 _nc_disable_period = FALSE;
845 suppress_untranslatable = TRUE;
848 _nc_disable_period = TRUE;
851 use_extended_names(TRUE);
860 debug_level = VtoTrace(v_opt);
861 set_trace_level(debug_level);
864 save_check_termtype = _nc_check_termtype2;
865 _nc_check_termtype2 = check_termtype;
869 * Aaargh! immedhook seriously hoses us!
871 * One problem with immedhook is it means we can't do -e. Problem
872 * is that we can't guarantee that for each terminal listed, all the
873 * terminals it depends on will have been kept in core for reference
874 * resolution -- in fact it's certain the primitive types at the end
875 * of reference chains *won't* be in core unless they were explicitly
876 * in the select list themselves.
878 if (namelst && (!infodump && !capdump)) {
879 (void) fprintf(stderr,
880 "%s: Sorry, -e can't be used without -I or -C\n",
882 ExitProgram(EXIT_FAILURE);
884 #endif /* HAVE_BIG_CORE */
887 source_file = argv[optind++];
890 "%s: Too many file names. Usage:\n\t%s %s",
894 ExitProgram(EXIT_FAILURE);
897 if (infodump == TRUE) {
898 /* captoinfo's no-argument case */
899 source_file = "/etc/termcap";
900 if ((termcap = getenv("TERMCAP")) != 0
901 && (namelst = make_namelist(getenv("TERM"))) != 0) {
902 if (access(termcap, F_OK) == 0) {
904 source_file = termcap;
906 if ((tmp_fp = open_tempfile(my_tmpname)) != 0) {
907 source_file = my_tmpname;
908 fprintf(tmp_fp, "%s\n", termcap);
910 tmp_fp = open_input(source_file, (char *) 0);
911 to_remove = source_file;
920 "%s: File name needed. Usage:\n\t%s %s",
924 ExitProgram(EXIT_FAILURE);
929 tmp_fp = open_input(source_file, my_altfile);
930 if (!strcmp(source_file, "-")) {
931 source_file = STDIN_NAME;
935 if (infodump || check_only) {
941 wrap_strings, width, height,
942 debug_level, formatted || check_only, check_only, quickdump);
943 } else if (capdump) {
947 wrap_strings, width, height,
948 debug_level, FALSE, FALSE, FALSE);
951 /* parse entries out of the source file */
952 _nc_set_source(source_file);
954 if (!(check_only || infodump || capdump))
955 _nc_set_writedir(outdir);
956 #endif /* HAVE_BIG_CORE */
957 _nc_read_entry_source(tmp_fp, (char *) NULL,
958 !smart_defaults || literal, FALSE,
959 ((check_only || infodump || capdump)
963 /* do use resolution */
964 if (check_only || (!infodump && !capdump) || forceresolve) {
965 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
966 ExitProgram(EXIT_FAILURE);
971 if (check_only && limited && (capdump || infodump)) {
973 if (matches(namelst, qp->tterm.term_names)) {
974 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
976 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
977 (void) fprintf(stderr,
978 "warning: resolved %s entry is %d bytes long\n",
979 _nc_first_name(qp->tterm.term_names),
985 /* write or dump all entries */
987 /* this is in case infotocap() generates warnings */
988 _nc_curr_col = _nc_curr_line = -1;
991 if (matches(namelst, qp->tterm.term_names)) {
992 /* this is in case infotocap() generates warnings */
993 _nc_set_type(_nc_first_name(qp->tterm.term_names));
994 _nc_curr_line = (int) qp->startline;
995 repair_acsc(&qp->tterm);
996 dump_entry(&qp->tterm, suppress_untranslatable,
997 limited, numbers, NULL);
1001 if (!infodump && !capdump) {
1002 _nc_set_writedir(outdir);
1003 for_entry_list(qp) {
1004 if (matches(namelst, qp->tterm.term_names))
1008 /* this is in case infotocap() generates warnings */
1009 _nc_curr_col = _nc_curr_line = -1;
1011 for_entry_list(qp) {
1012 if (matches(namelst, qp->tterm.term_names)) {
1013 long j = qp->cend - qp->cstart;
1016 /* this is in case infotocap() generates warnings */
1017 _nc_set_type(_nc_first_name(qp->tterm.term_names));
1020 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
1023 (void) putchar(fgetc(tmp_fp));
1025 put_translate(fgetc(tmp_fp));
1029 repair_acsc(&qp->tterm);
1030 dump_entry(&qp->tterm, suppress_untranslatable,
1031 limited, numbers, NULL);
1032 for (j = 0; j < (long) qp->nuses; j++)
1033 dump_uses(qp->uses[j].name, !capdump);
1035 if (debug_level != 0 && !limited)
1036 printf("# length=%d\n", len);
1039 if (!namelst && _nc_tail && !quiet) {
1041 bool in_comment = FALSE;
1042 bool trailing_comment = FALSE;
1044 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
1045 while ((c = fgetc(tmp_fp)) != EOF) {
1048 trailing_comment = TRUE;
1054 if (trailing_comment
1055 && (in_comment || (oldc == '\n' && c == '\n')))
1063 /* Show the directory into which entries were written, and the total
1067 && (!(check_only || infodump || capdump))) {
1068 int total = _nc_tic_written();
1070 fprintf(log_fp, "%d entries written to %s\n",
1072 _nc_tic_dir((char *) 0));
1074 fprintf(log_fp, "No entries written\n");
1076 ExitProgram(EXIT_SUCCESS);
1080 * This bit of legerdemain turns all the terminfo variable names into
1081 * references to locations in the arrays Booleans, Numbers, and Strings ---
1082 * precisely what's needed (see comp_parse.c).
1088 * Check if the alternate character-set capabilities are consistent.
1091 check_acs(TERMTYPE *tp)
1093 if (VALID_STRING(acs_chars)) {
1094 const char *boxes = "lmkjtuvwqxn";
1100 memset(mapped, 0, sizeof(mapped));
1101 for (p = acs_chars; *p != '\0'; p += 2) {
1103 _nc_warning("acsc has odd number of characters");
1106 mapped[UChar(p[0])] = p[1];
1109 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
1110 _nc_warning("acsc refers to 'I', which is probably an error");
1113 for (p = boxes, q = missing; *p != '\0'; ++p) {
1114 if (!mapped[UChar(p[0])]) {
1120 assert(strlen(missing) <= strlen(boxes));
1121 if (*missing != '\0' && strcmp(missing, boxes)) {
1122 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
1128 * Check if the color capabilities are consistent
1131 check_colors(TERMTYPE *tp)
1133 if ((max_colors > 0) != (max_pairs > 0)
1134 || ((max_colors > max_pairs) && (initialize_pair == 0)))
1135 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
1136 max_colors, max_pairs);
1138 PAIRED(set_foreground, set_background);
1139 PAIRED(set_a_foreground, set_a_background);
1140 PAIRED(set_color_pair, initialize_pair);
1142 if (VALID_STRING(set_foreground)
1143 && VALID_STRING(set_a_foreground)
1144 && !_nc_capcmp(set_foreground, set_a_foreground))
1145 _nc_warning("expected setf/setaf to be different");
1147 if (VALID_STRING(set_background)
1148 && VALID_STRING(set_a_background)
1149 && !_nc_capcmp(set_background, set_a_background))
1150 _nc_warning("expected setb/setab to be different");
1152 /* see: has_colors() */
1153 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
1154 && (((set_foreground != NULL)
1155 && (set_background != NULL))
1156 || ((set_a_foreground != NULL)
1157 && (set_a_background != NULL))
1158 || set_color_pair)) {
1159 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
1160 _nc_warning("expected either op/oc string for resetting colors");
1163 if (!VALID_STRING(initialize_pair) &&
1164 !VALID_STRING(initialize_color)) {
1165 _nc_warning("expected initc or initp because ccc is given");
1168 if (VALID_STRING(initialize_pair) ||
1169 VALID_STRING(initialize_color)) {
1170 _nc_warning("expected ccc because initc is given");
1176 keypad_final(const char *string)
1180 if (VALID_STRING(string)
1181 && *string++ == '\033'
1183 && strlen(string) == 1) {
1191 keypad_index(const char *string)
1194 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
1198 if ((ch = keypad_final(string)) != '\0') {
1199 test = (strchr) (list, ch);
1201 result = (long) (test - list);
1207 * list[] is down, up, left, right
1208 * "left" may be ^H rather than \E[D
1209 * "down" may be ^J rather than \E[B
1210 * But up/right are generally consistently escape sequences for ANSI terminals.
1213 check_ansi_cursor(char *list[4])
1220 bool repeated = FALSE;
1222 for (j = 0; j < 4; ++j) {
1224 for (k = 0; k < j; ++k) {
1226 && !strcmp(list[j], list[k])) {
1227 char *value = _nc_tic_expand(list[k], TRUE, 0);
1228 _nc_warning("repeated cursor control %s\n", value);
1236 if (UChar(up[0]) == '\033') {
1242 } else if (UChar(up[0]) == UChar('\233')) {
1247 while (up[suffix] && isdigit(UChar(up[suffix])))
1250 if (prefix && up[suffix] == 'A') {
1252 if (!strcmp(list[0], "\n"))
1254 if (!strcmp(list[2], "\b"))
1257 for (j = 0; j < 4; ++j) {
1258 if (skip[j] || strlen(list[j]) == 1)
1260 if (memcmp(list[j], up, prefix)) {
1261 char *value = _nc_tic_expand(list[j], TRUE, 0);
1262 _nc_warning("inconsistent prefix for %s\n", value);
1265 if (strlen(list[j]) < suffix) {
1266 char *value = _nc_tic_expand(list[j], TRUE, 0);
1267 _nc_warning("inconsistent length for %s, expected %d\n",
1268 value, (int) suffix + 1);
1272 if (list[j][suffix] != want) {
1273 char *value = _nc_tic_expand(list[j], TRUE, 0);
1274 _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
1275 value, want, list[j][suffix]);
1282 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
1283 #define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
1286 check_noaddress(TERMTYPE *tp, const char *why)
1288 UNEXPECTED(column_address);
1289 UNEXPECTED(cursor_address);
1290 UNEXPECTED(cursor_home);
1291 UNEXPECTED(cursor_mem_address);
1292 UNEXPECTED(cursor_to_ll);
1293 UNEXPECTED(row_address);
1294 UNEXPECTED(row_address);
1298 check_cursor(TERMTYPE *tp)
1304 check_noaddress(tp, "hard_copy");
1305 } else if (generic_type) {
1306 check_noaddress(tp, "generic_type");
1307 } else if (strchr(tp->term_names, '+') == 0) {
1310 if (PRESENT(column_address))
1312 if (PRESENT(cursor_address))
1314 if (PRESENT(cursor_home))
1316 if (PRESENT(cursor_mem_address))
1318 if (PRESENT(cursor_to_ll))
1320 if (PRESENT(row_address))
1322 if (PRESENT(cursor_down))
1324 if (PRESENT(cursor_up))
1326 if (PRESENT(cursor_left))
1328 if (PRESENT(cursor_right))
1330 if (x < 2 && y < 2) {
1331 _nc_warning("terminal lacks cursor addressing");
1334 _nc_warning("terminal lacks cursor column-addressing");
1336 _nc_warning("terminal lacks cursor row-addressing");
1340 /* it is rare to have an insert-line feature without a matching delete */
1341 ANDMISSING(parm_insert_line, insert_line);
1342 ANDMISSING(parm_delete_line, delete_line);
1343 ANDMISSING(parm_insert_line, parm_delete_line);
1345 /* if we have a parameterized form, then the non-parameterized is easy */
1346 ANDMISSING(parm_down_cursor, cursor_down);
1347 ANDMISSING(parm_up_cursor, cursor_up);
1348 ANDMISSING(parm_left_cursor, cursor_left);
1349 ANDMISSING(parm_right_cursor, cursor_right);
1351 /* Given any of a set of cursor movement, the whole set should be present.
1352 * Technically this is not true (we could use cursor_address to fill in
1353 * unsupported controls), but it is likely.
1356 if (PRESENT(parm_down_cursor)) {
1357 list[count++] = parm_down_cursor;
1359 if (PRESENT(parm_up_cursor)) {
1360 list[count++] = parm_up_cursor;
1362 if (PRESENT(parm_left_cursor)) {
1363 list[count++] = parm_left_cursor;
1365 if (PRESENT(parm_right_cursor)) {
1366 list[count++] = parm_right_cursor;
1369 check_ansi_cursor(list);
1370 } else if (count != 0) {
1371 EXPECTED(parm_down_cursor);
1372 EXPECTED(parm_up_cursor);
1373 EXPECTED(parm_left_cursor);
1374 EXPECTED(parm_right_cursor);
1378 if (PRESENT(cursor_down)) {
1379 list[count++] = cursor_down;
1381 if (PRESENT(cursor_up)) {
1382 list[count++] = cursor_up;
1384 if (PRESENT(cursor_left)) {
1385 list[count++] = cursor_left;
1387 if (PRESENT(cursor_right)) {
1388 list[count++] = cursor_right;
1391 check_ansi_cursor(list);
1392 } else if (count != 0) {
1394 if (PRESENT(cursor_down) && strcmp(cursor_down, "\n"))
1396 if (PRESENT(cursor_left) && strcmp(cursor_left, "\b"))
1398 if (PRESENT(cursor_up) && strlen(cursor_up) > 1)
1400 if (PRESENT(cursor_right) && strlen(cursor_right) > 1)
1403 EXPECTED(cursor_down);
1404 EXPECTED(cursor_up);
1405 EXPECTED(cursor_left);
1406 EXPECTED(cursor_right);
1413 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
1414 * is mapped inconsistently.
1417 check_keypad(TERMTYPE *tp)
1421 if (VALID_STRING(key_a1) &&
1422 VALID_STRING(key_a3) &&
1423 VALID_STRING(key_b2) &&
1424 VALID_STRING(key_c1) &&
1425 VALID_STRING(key_c3)) {
1426 char final[MAX_KP + 1];
1433 final[0] = keypad_final(key_a1);
1434 final[1] = keypad_final(key_a3);
1435 final[2] = keypad_final(key_b2);
1436 final[3] = keypad_final(key_c1);
1437 final[4] = keypad_final(key_c3);
1440 /* special case: legacy coding using 1,2,3,0,. on the bottom */
1441 assert(strlen(final) <= MAX_KP);
1442 if (!strcmp(final, "qsrpn"))
1445 list[0] = keypad_index(key_a1);
1446 list[1] = keypad_index(key_a3);
1447 list[2] = keypad_index(key_b2);
1448 list[3] = keypad_index(key_c1);
1449 list[4] = keypad_index(key_c3);
1451 /* check that they're all vt100 keys */
1452 for (j = 0; j < MAX_KP; ++j) {
1458 /* check if they're all in increasing order */
1459 for (j = 1; j < MAX_KP; ++j) {
1460 if (list[j] > list[j - 1]) {
1464 if (increase != (MAX_KP - 1)) {
1467 for (j = 0, last = -1; j < MAX_KP; ++j) {
1468 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
1469 if (list[k] > last &&
1476 assert(strlen(show) < (MAX_KP * 4));
1479 _nc_STRCAT(show, " ka1", sizeof(show));
1482 _nc_STRCAT(show, " ka3", sizeof(show));
1485 _nc_STRCAT(show, " kb2", sizeof(show));
1488 _nc_STRCAT(show, " kc1", sizeof(show));
1491 _nc_STRCAT(show, " kc3", sizeof(show));
1496 _nc_warning("vt100 keypad order inconsistent: %s", show);
1499 } else if (VALID_STRING(key_a1) ||
1500 VALID_STRING(key_a3) ||
1501 VALID_STRING(key_b2) ||
1502 VALID_STRING(key_c1) ||
1503 VALID_STRING(key_c3)) {
1505 if (keypad_index(key_a1) >= 0)
1506 _nc_STRCAT(show, " ka1", sizeof(show));
1507 if (keypad_index(key_a3) >= 0)
1508 _nc_STRCAT(show, " ka3", sizeof(show));
1509 if (keypad_index(key_b2) >= 0)
1510 _nc_STRCAT(show, " kb2", sizeof(show));
1511 if (keypad_index(key_c1) >= 0)
1512 _nc_STRCAT(show, " kc1", sizeof(show));
1513 if (keypad_index(key_c3) >= 0)
1514 _nc_STRCAT(show, " kc3", sizeof(show));
1516 _nc_warning("vt100 keypad map incomplete:%s", show);
1520 * These warnings are useful for consistency checks - it is possible that
1521 * there are real terminals with mismatches in these
1523 ANDMISSING(key_ic, key_dc);
1527 check_printer(TERMTYPE *tp)
1529 PAIRED(enter_doublewide_mode, exit_doublewide_mode);
1530 PAIRED(enter_italics_mode, exit_italics_mode);
1531 PAIRED(enter_leftward_mode, exit_leftward_mode);
1532 PAIRED(enter_micro_mode, exit_micro_mode);
1533 PAIRED(enter_shadow_mode, exit_shadow_mode);
1534 PAIRED(enter_subscript_mode, exit_subscript_mode);
1535 PAIRED(enter_superscript_mode, exit_superscript_mode);
1536 PAIRED(enter_upward_mode, exit_upward_mode);
1538 ANDMISSING(start_char_set_def, stop_char_set_def);
1540 /* if we have a parameterized form, then the non-parameterized is easy */
1541 ANDMISSING(set_bottom_margin_parm, set_bottom_margin);
1542 ANDMISSING(set_left_margin_parm, set_left_margin);
1543 ANDMISSING(set_right_margin_parm, set_right_margin);
1544 ANDMISSING(set_top_margin_parm, set_top_margin);
1546 ANDMISSING(parm_down_micro, micro_down);
1547 ANDMISSING(parm_left_micro, micro_left);
1548 ANDMISSING(parm_right_micro, micro_right);
1549 ANDMISSING(parm_up_micro, micro_up);
1553 uses_SGR_39_49(const char *value)
1555 return (strstr(value, "39;49") != 0
1556 || strstr(value, "49;39") != 0);
1560 * Check consistency of termcap extensions related to "screen".
1563 check_screen(TERMTYPE *tp)
1566 if (_nc_user_definable) {
1567 int have_XT = tigetflag("XT");
1568 int have_XM = tigetflag("XM");
1569 int have_bce = back_color_erase;
1570 bool have_kmouse = FALSE;
1571 bool use_sgr_39_49 = FALSE;
1572 char *name = _nc_first_name(tp->term_names);
1574 if (!VALID_BOOLEAN(have_bce)) {
1577 if (!VALID_BOOLEAN(have_XM)) {
1580 if (!VALID_BOOLEAN(have_XT)) {
1583 if (VALID_STRING(key_mouse)) {
1584 have_kmouse = !strcmp("\033[M", key_mouse);
1586 if (VALID_STRING(orig_colors)) {
1587 use_sgr_39_49 = uses_SGR_39_49(orig_colors);
1588 } else if (VALID_STRING(orig_pair)) {
1589 use_sgr_39_49 = uses_SGR_39_49(orig_pair);
1592 if (have_XM && have_XT) {
1593 _nc_warning("Screen's XT capability conflicts with XM");
1595 && strstr(name, "screen") != 0
1596 && strchr(name, '.') != 0) {
1597 _nc_warning("Screen's \"screen\" entries should not have XT set");
1598 } else if (have_XT) {
1599 if (!have_kmouse && have_bce) {
1600 if (VALID_STRING(key_mouse)) {
1601 _nc_warning("Value of kmous inconsistent with screen's usage");
1603 _nc_warning("Expected kmous capability with XT");
1606 if (!have_bce && max_colors > 0)
1607 _nc_warning("Expected bce capability with XT");
1608 if (!use_sgr_39_49 && have_bce && max_colors > 0)
1609 _nc_warning("Expected orig_colors capability with XT to have 39/49 parameters");
1610 if (VALID_STRING(to_status_line))
1611 _nc_warning("\"tsl\" capability is redundant, given XT");
1613 if (have_kmouse && !have_XM)
1614 _nc_warning("Expected XT to be set, given kmous");
1621 * Returns the expected number of parameters for the given capability.
1624 expected_params(const char *name)
1626 #define DATA(name,count) { { name }, count }
1628 static const struct {
1632 DATA( "S0", 1 ), /* 'screen' extension */
1635 DATA( "colornm", 1 ),
1679 DATA( "setcolor", 1 ),
1683 DATA( "slength", 1 ),
1684 DATA( "slines", 1 ),
1685 DATA( "smgbp", 1 ), /* 2 if smgtp is not given */
1702 int result = 0; /* function-keys, etc., use none */
1704 for (n = 0; n < SIZEOF(table); n++) {
1705 if (!strcmp(name, table[n].name)) {
1706 result = table[n].count;
1715 * Make a quick sanity check for the parameters which are used in the given
1716 * strings. If there are no "%p" tokens, then there should be no other "%"
1720 check_params(TERMTYPE *tp, const char *name, char *value)
1722 int expected = expected_params(name);
1725 bool params[NUM_PARM];
1728 #ifdef set_top_margin_parm
1729 if (!strcmp(name, "smgbp")
1730 && set_top_margin_parm == 0)
1734 for (n = 0; n < NUM_PARM; n++)
1740 _nc_warning("expected character after %% in %s", name);
1742 } else if (*s == 'p') {
1743 if (*++s == '\0' || !isdigit((int) *s)) {
1744 _nc_warning("expected digit after %%p in %s", name);
1758 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1760 if (value == set_attributes || expected < 0) {
1762 } else if (expected != actual) {
1763 _nc_warning("%s uses %d parameters, expected %d", name,
1765 for (n = 1; n < actual; n++) {
1767 _nc_warning("%s omits parameter %d", name, n);
1773 check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
1777 long numbers[1 + NUM_PARM];
1778 char *strings[1 + NUM_PARM];
1779 char *p_is_s[NUM_PARM];
1781 char blob[NUM_PARM * 10];
1785 for (k = 1; k <= NUM_PARM; k++) {
1788 _nc_SLIMIT(sizeof(blob) - (next - blob))
1791 next += strlen(next) + 1;
1794 switch (tparm_type(name)) {
1796 result = TPARM_2(value, numbers[1], strings[2]);
1799 result = TPARM_3(value, numbers[1], strings[2], strings[3]);
1803 (void) _nc_tparm_analyze(value, p_is_s, &ignored);
1804 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
1805 result = TPARM_9(value,
1820 #define IsDelay(ch) ((ch) == '.' || isdigit(UChar(ch)))
1823 parse_delay_value(const char *src, double *delays, int *always)
1831 while (isdigit(UChar(*src))) {
1832 (*delays) = (*delays) * 10 + (*src++ - '0');
1838 while (isdigit(UChar(*src))) {
1840 (*delays) += (*src++ - '0') / gotdot;
1843 while (*src == '*' || *src == '/') {
1844 if (always == 0 && *src == '/')
1846 if (*src++ == '*') {
1853 *delays = -(*delays);
1858 parse_ti_delay(const char *ti, double *delays)
1861 while (*ti != '\0') {
1867 && IsDelay(UChar(ti[2]))) {
1869 const char *last = parse_delay_value(ti + 2, delays, &ignored);
1881 parse_tc_delay(const char *tc, double *delays)
1883 return parse_delay_value(tc, delays, (int *) 0);
1887 * Compare terminfo- and termcap-strings, factoring out delays.
1890 same_ti_tc(const char *ti, const char *tc, bool * embedded)
1893 double ti_delay = 0.0;
1894 double tc_delay = 0.0;
1895 const char *ti_last;
1898 ti_last = parse_ti_delay(ti, &ti_delay);
1899 tc = parse_tc_delay(tc, &tc_delay);
1901 while ((ti < ti_last) && *tc) {
1902 if (*ti == '\\' && ispunct(UChar(ti[1]))) {
1904 if ((*ti == '^') && !strncmp(tc, "\\136", 4)) {
1909 } else if (ti[0] == '$' && ti[1] == '<') {
1911 const char *ss = parse_ti_delay(ti, &no_delay);
1918 if (*tc == '\\' && ispunct(UChar(tc[1]))) {
1921 if (*ti++ != *tc++) {
1931 *embedded = FALSE; /* report only one problem */
1939 * Check terminfo to termcap translation.
1942 check_infotocap(TERMTYPE *tp, int i, const char *value)
1944 const char *name = ExtStrname(tp, i, strnames);
1945 int params = (((i < (int) SIZEOF(parametrized)) &&
1950 : has_params(value)));
1956 if ((ti_value = _nc_tic_expand(value, TRUE, to_char)) == ABSENT_STRING) {
1957 _nc_warning("tic-expansion of %s failed", name);
1958 } else if ((tc_value = _nc_infotocap(name, ti_value, params)) == ABSENT_STRING) {
1959 _nc_warning("tic-conversion of %s failed", name);
1960 } else if (params > 0) {
1965 if (!strcmp(name, "setf")
1966 || !strcmp(name, "setb")
1967 || !strcmp(name, "setaf")
1968 || !strcmp(name, "setab")) {
1971 for (count = 0; count < limit; ++count) {
1972 char *ti_check = check_1_infotocap(name, ti_value, count);
1973 char *tc_check = check_1_infotocap(name, tc_value, count);
1975 if (strcmp(ti_check, tc_check)) {
1977 fprintf(stderr, "check_infotocap(%s)\n", name);
1978 fprintf(stderr, "...ti '%s'\n", ti_value);
1979 fprintf(stderr, "...tc '%s'\n", tc_value);
1982 _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s",
1983 name, count, ti_check, tc_check);
1986 } else if (params == 0 && !same_ti_tc(ti_value, tc_value, &embedded)) {
1988 _nc_warning("termcap equivalent of %s cannot use embedded delay", name);
1990 _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s",
1991 name, ti_value, tc_value);
1999 while (*s == '/' || isdigit(UChar(*s)))
2005 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
2006 * the latter may have a worst-case delay on the end.
2009 ignore_delays(char *s)
2041 #define DATA(name) { #name }
2042 static const char sgr_names[][11] =
2059 * An sgr string may contain several settings other than the one we're
2060 * interested in, essentially sgr0 + rmacs + whatever. As long as the
2061 * "whatever" is contained in the sgr string, that is close enough for our
2065 similar_sgr(int num, char *a, char *b)
2076 } else if (b[0] == '$'
2078 _nc_warning("Did not find delay %s", _nc_visbuf(b));
2080 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
2081 sgr_names[num], _nc_visbuf2(1, base_a),
2082 _nc_visbuf2(2, base_b),
2086 } else if (delaying) {
2089 } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
2111 /* ignore delays on the end of the string */
2112 a = ignore_delays(a);
2113 return ((num != 0) || (*a == 0));
2117 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
2122 test = TPARM_9(set_attributes,
2134 if (!similar_sgr(num, test, cap)) {
2135 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
2137 name, _nc_visbuf2(1, cap),
2138 num, _nc_visbuf2(2, test));
2140 } else if (_nc_capcmp(test, zero)) {
2141 _nc_warning("sgr(%d) present, but not %s", num, name);
2143 } else if (PRESENT(cap)) {
2144 _nc_warning("sgr(%d) missing, but %s present", num, name);
2147 _nc_warning("stack error in sgr(%d) string", num);
2151 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
2155 * If tic is compiled with TRACE, we'll be able to see the output from the
2156 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
2157 * the standard error. Use this function to make it simpler to follow the
2158 * resulting debug traces.
2161 show_where(unsigned level)
2163 if (_nc_tracing >= DEBUG_LEVEL(level)) {
2164 char my_name[MAX_NAME_SIZE];
2165 _nc_get_type(my_name);
2166 _tracef("\"%s\", line %d, '%s'",
2168 _nc_curr_line, my_name);
2173 #define show_where(level) /* nothing */
2183 get_fkey_list(TERMTYPE *tp)
2185 NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1);
2186 const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys;
2191 failed("get_fkey_list");
2193 for (j = 0; all_fkeys[j].code; j++) {
2194 char *a = tp->Strings[all_fkeys[j].offset];
2195 if (VALID_STRING(a)) {
2196 result[used].keycode = (int) all_fkeys[j].code;
2197 result[used].name = strnames[all_fkeys[j].offset];
2198 result[used].value = a;
2203 for (j = STRCOUNT; j < NUM_STRINGS(tp); ++j) {
2204 const char *name = ExtStrname(tp, (int) j, strnames);
2206 result[used].keycode = -1;
2207 result[used].name = name;
2208 result[used].value = tp->Strings[j];
2213 result[used].keycode = 0;
2218 show_fkey_name(NAME_VALUE * data)
2220 if (data->keycode > 0) {
2221 fprintf(stderr, " %s", keyname(data->keycode));
2222 fprintf(stderr, " (capability \"%s\")", data->name);
2224 fprintf(stderr, " capability \"%s\"", data->name);
2229 * A terminal entry may contain more than one keycode assigned to a given
2230 * string (e.g., KEY_END and KEY_LL). But curses will only return one (the
2231 * last one assigned).
2234 check_conflict(TERMTYPE *tp)
2236 bool conflict = FALSE;
2239 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
2240 char *check = calloc((size_t) (NUM_STRINGS(tp) + 1), sizeof(char));
2241 NAME_VALUE *given = get_fkey_list(tp);
2244 failed("check_termtype");
2246 for (j = 0; given[j].keycode; ++j) {
2247 const char *a = given[j].value;
2250 for (k = j + 1; given[k].keycode; k++) {
2251 const char *b = given[k].value;
2254 if (!_nc_capcmp(a, b)) {
2259 _nc_warning("Conflicting key definitions (using the last)");
2262 fprintf(stderr, "...");
2263 show_fkey_name(given + j);
2264 fprintf(stderr, " is the same as");
2265 show_fkey_name(given + k);
2268 fprintf(stderr, ", ");
2269 show_fkey_name(given + k);
2274 fprintf(stderr, "\n");
2282 * Exiting a video mode should not duplicate sgr0
2285 check_exit_attribute(const char *name, char *test, char *trimmed, char *untrimmed)
2287 if (VALID_STRING(test) && (trimmed != 0)) {
2288 if (similar_sgr(-1, trimmed, test) ||
2289 similar_sgr(-1, untrimmed, test)) {
2290 _nc_warning("%s matches exit_attribute_mode", name);
2296 * Returns true if the string looks like a standard SGR string.
2299 is_sgr_string(char *value)
2301 bool result = FALSE;
2303 if (VALID_STRING(value)) {
2304 if (value[0] == '\033' && value[1] == '[') {
2307 } else if (UChar(value[0]) == 0x9a) {
2313 while ((ch = UChar(*value++)) != '\0') {
2314 if (isdigit(ch) || ch == ';') {
2316 } else if (ch == 'm' && *value == '\0') {
2329 * Check if the given capability contains a given SGR attribute.
2332 check_sgr_param(TERMTYPE *tp, int code, const char *name, char *value)
2334 if (VALID_STRING(value)) {
2335 int ncv = ((code != 0) ? (1 << (code - 1)) : 0);
2336 char *test = tgoto(value, 0, 0);
2337 if (is_sgr_string(test)) {
2341 int color = (value == set_a_foreground ||
2342 value == set_a_background ||
2343 value == set_foreground ||
2344 value == set_background);
2345 while (*test != 0) {
2346 if (isdigit(UChar(*test))) {
2347 param = 10 * param + (*test - '0');
2352 * Avoid unnecessary warning for xterm 256color codes.
2354 if (color && (param == 38 || param == 48))
2356 if ((skips-- <= 0) && (param == code))
2364 if (count != 0 && param == code) {
2366 no_color_video < 0 ||
2367 !(no_color_video & ncv)) {
2368 _nc_warning("\"%s\" SGR-attribute used in %s",
2377 /* other sanity-checks (things that we don't want in the normal
2378 * logic that reads a terminfo entry)
2381 check_termtype(TERMTYPE *tp, bool literal)
2387 for_each_string(j, tp) {
2388 char *a = tp->Strings[j];
2389 if (VALID_STRING(a)) {
2390 check_params(tp, ExtStrname(tp, (int) j, strnames), a);
2392 check_infotocap(tp, (int) j, a);
2405 * These may be mismatched because the terminal description relies on
2406 * restoring the cursor visibility by resetting it.
2408 ANDMISSING(cursor_invisible, cursor_normal);
2409 ANDMISSING(cursor_visible, cursor_normal);
2411 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
2412 && !_nc_capcmp(cursor_visible, cursor_normal))
2413 _nc_warning("cursor_visible is same as cursor_normal");
2416 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
2417 * given, because the cursor position after the scrolling operation is
2418 * performed is undefined.
2420 ANDMISSING(change_scroll_region, save_cursor);
2421 ANDMISSING(change_scroll_region, restore_cursor);
2424 * If we can clear tabs, we should be able to initialize them.
2426 ANDMISSING(clear_all_tabs, set_tab);
2428 if (PRESENT(set_attributes)) {
2432 if (PRESENT(exit_attribute_mode)) {
2433 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
2435 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
2438 _nc_warning("stack error in sgr(0) string");
2441 CHECK_SGR(1, enter_standout_mode);
2442 CHECK_SGR(2, enter_underline_mode);
2443 CHECK_SGR(3, enter_reverse_mode);
2444 CHECK_SGR(4, enter_blink_mode);
2445 CHECK_SGR(5, enter_dim_mode);
2446 CHECK_SGR(6, enter_bold_mode);
2447 CHECK_SGR(7, enter_secure_mode);
2448 CHECK_SGR(8, enter_protected_mode);
2449 CHECK_SGR(9, enter_alt_charset_mode);
2452 _nc_warning("sgr(0) did not return a value");
2454 } else if (PRESENT(exit_attribute_mode) &&
2455 set_attributes != CANCELLED_STRING) {
2456 if (_nc_syntax == SYN_TERMINFO)
2457 _nc_warning("missing sgr string");
2459 #define CHECK_SGR0(name) check_exit_attribute(#name, name, check_sgr0, exit_attribute_mode)
2460 if (PRESENT(exit_attribute_mode)) {
2461 char *check_sgr0 = _nc_trim_sgr0(tp);
2463 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
2464 _nc_warning("trimmed sgr0 is empty");
2467 if (check_sgr0 != exit_attribute_mode) {
2469 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
2470 _nc_visbuf2(1, exit_attribute_mode),
2471 _nc_visbuf2(2, check_sgr0)));
2474 ("will not trim sgr0\n\toriginal sgr0=%s",
2475 _nc_visbuf(exit_attribute_mode)));
2478 CHECK_SGR0(exit_italics_mode);
2479 CHECK_SGR0(exit_standout_mode);
2480 CHECK_SGR0(exit_underline_mode);
2481 if (check_sgr0 != exit_attribute_mode) {
2485 #define CHECK_SGR_PARAM(code, name) check_sgr_param(tp, (int)code, #name, name)
2486 for (j = 0; *sgr_names[j] != '\0'; ++j) {
2487 CHECK_SGR_PARAM(j, set_a_foreground);
2488 CHECK_SGR_PARAM(j, set_a_background);
2489 CHECK_SGR_PARAM(j, set_foreground);
2490 CHECK_SGR_PARAM(j, set_background);
2494 if (!auto_right_margin) {
2496 ("can write to lower-right directly"));
2497 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
2499 ("can write to lower-right by suppressing automargin"));
2500 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
2501 || PRESENT(insert_character) || PRESENT(parm_ich)) {
2503 ("can write to lower-right by using inserts"));
2506 ("cannot write to lower-right"));
2511 * Some standard applications (e.g., vi) and some non-curses
2512 * applications (e.g., jove) get confused if we have both ich1 and
2513 * smir/rmir. Let's be nice and warn about that, too, even though
2514 * ncurses handles it.
2516 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
2517 && PRESENT(parm_ich)) {
2518 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
2522 * Finally, do the non-verbose checks
2524 if (save_check_termtype != 0)
2525 save_check_termtype(tp, literal);