1 /****************************************************************************
2 * Copyright (c) 1998-2018,2019 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.268 2019/02/23 21:49:28 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 unsigned debug_level;
63 static char **namelst = 0;
64 static const char *to_remove;
67 static bool using_extensions = FALSE;
70 static void (*save_check_termtype) (TERMTYPE2 *, bool);
71 static void check_termtype(TERMTYPE2 *tt, bool);
73 static const char usage_string[] = "\
104 free_namelist(char **src)
108 for (n = 0; src[n] != 0; ++n)
121 free_namelist(namelst);
122 _nc_leaks_dump_entry();
126 if (to_remove != 0) {
128 rc = remove(to_remove);
130 rc = unlink(to_remove);
138 failed(const char *msg)
141 ExitProgram(EXIT_FAILURE);
147 #define DATA(s) s "\n"
148 static const char options_string[] =
151 DATA(" -0 format translation output all capabilities on one line")
152 DATA(" -1 format translation output one capability per line")
154 DATA(" -a retain commented-out capabilities (sets -x also)")
156 DATA(" -C translate entries to termcap source form")
157 DATA(" -D print list of tic's database locations (first must be writable)")
158 DATA(" -c check only, validate input without compiling or translating")
159 DATA(" -e<names> translate/compile only entries named by comma-separated list")
160 DATA(" -f format complex strings for readability")
161 DATA(" -G format %{number} to %'char'")
162 DATA(" -g format %'char' to %{number}")
163 DATA(" -I translate entries to terminfo source form")
164 DATA(" -K translate entries to termcap source form with BSD syntax")
165 DATA(" -L translate entries to full terminfo source form")
166 DATA(" -N disable smart defaults for source translation")
167 DATA(" -o<dir> set output directory for compiled entry writes")
168 DATA(" -Q[n] dump compiled description")
169 DATA(" -q brief listing, removes headers")
170 DATA(" -R<name> restrict translation to given terminfo/termcap version")
171 DATA(" -r force resolution of all use entries in source translation")
172 DATA(" -s print summary statistics")
173 DATA(" -T remove size-restrictions on compiled description")
175 DATA(" -t suppress commented-out capabilities")
177 DATA(" -U suppress post-processing of entries")
178 DATA(" -V print version")
179 DATA(" -W wrap long strings according to -w[n] option")
180 DATA(" -v[n] set verbosity level")
181 DATA(" -w[n] set format width for translation output")
183 DATA(" -x treat unknown capabilities as user-defined")
187 DATA(" <file> file to translate or compile")
191 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
192 fputs(options_string, stderr);
193 ExitProgram(EXIT_FAILURE);
206 char result[MAX_ENTRY_SIZE];
209 * Look for strings that contain %{number}, convert them to %'char',
210 * which is shorter and runs a little faster.
212 for (n = 0; n < STRCOUNT; n++) {
213 s = ep->tterm.Strings[n];
215 && strchr(s, L_BRACE) != 0) {
218 while ((ch = *t++) != 0) {
222 } else if ((ch == '%')
223 && (*t == L_BRACE)) {
225 long value = strtol(t + 1, &v, 0);
229 && value != '\\' /* FIXME */
231 && isprint((int) value)) {
240 if (strlen(result) < strlen(s))
241 _nc_STRCPY(s, result, strlen(s) + 1);
245 _nc_set_type(_nc_first_name(ep->tterm.term_names));
246 _nc_curr_line = (int) ep->startline;
247 _nc_write_entry(&ep->tterm);
251 immedhook(ENTRY * ep GCC_UNUSED)
252 /* write out entries with no use capabilities immediately to save storage */
256 * This is strictly a core-economy kluge. The really clean way to handle
257 * compilation is to slurp the whole file into core and then do all the
258 * name-collision checks and entry writes in one swell foop. But the
259 * terminfo master file is large enough that some core-poor systems swap
260 * like crazy when you compile it this way...there have been reports of
261 * this process taking *three hours*, rather than the twenty seconds or
262 * less typical on my development box.
264 * So. This hook *immediately* writes out the referenced entry if it
265 * has no use capabilities. The compiler main loop refrains from
266 * adding the entry to the in-core list when this hook fires. If some
267 * other entry later needs to reference an entry that got written
268 * immediately, that's OK; the resolution code will fetch it off disk
269 * when it can't find it in core.
271 * Name collisions will still be detected, just not as cleanly. The
272 * write_entry() code complains before overwriting an entry that
273 * postdates the time of tic's first call to write_entry(). Thus
274 * it will complain about overwriting entries newly made during the
275 * tic run, but not about overwriting ones that predate it.
277 * The reason this is a hook, and not in line with the rest of the
278 * compiler code, is that the support for termcap fallback cannot assume
279 * it has anywhere to spool out these entries!
281 * The _nc_set_type() call here requires a compensating one in
284 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
285 * make tic a bit faster (because the resolution code won't have to do
286 * disk I/O nearly as often).
288 if (ep->nuses == 0) {
289 int oldline = _nc_curr_line;
292 _nc_curr_line = oldline;
293 free(ep->tterm.str_table);
296 #endif /* HAVE_BIG_CORE */
302 /* emit a comment char, translating terminfo names to termcap names */
304 static bool in_name = FALSE;
305 static size_t have, used;
306 static char *namebuf, *suffix;
309 if (used + 1 >= have) {
311 if ((namebuf = typeRealloc(char, have, namebuf)) == 0)
312 failed("put_translate namebuf");
313 if ((suffix = typeRealloc(char, have, suffix)) == 0)
314 failed("put_translate suffix");
316 if (c == '\n' || c == '@') {
317 namebuf[used++] = '\0';
319 (void) fputs(namebuf, stdout);
322 } else if (c != '>') {
323 namebuf[used++] = (char) c;
324 } else { /* ah! candidate name! */
326 NCURSES_CONST char *tp;
328 namebuf[used++] = '\0';
332 if ((up = strchr(namebuf, '#')) != 0
333 || (up = strchr(namebuf, '=')) != 0
334 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
335 _nc_STRCPY(suffix, up, have);
339 if ((tp = nametrans(namebuf)) != 0) {
341 (void) fputs(tp, stdout);
342 (void) fputs(suffix, stdout);
345 /* couldn't find a translation, just dump the name */
347 (void) fputs(namebuf, stdout);
348 (void) fputs(suffix, stdout);
362 /* Returns a string, stripped of leading/trailing whitespace */
368 while (isspace(UChar(*src)))
374 if ((dst = strdup(src)) == NULL) {
378 while (--len != 0 && isspace(UChar(dst[len])))
386 open_tempfile(char *filename)
390 _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
393 int oldmask = (int) umask(077);
394 int fd = mkstemp(filename);
396 result = fdopen(fd, "w");
397 umask((mode_t) oldmask);
400 if (tmpnam(filename) != 0)
401 result = fopen(filename, "w");
407 copy_input(FILE *source, const char *filename, char *alt_file)
409 char my_altfile[PATH_MAX];
415 alt_file = my_altfile;
418 failed("copy_input (source)");
419 } else if ((target = open_tempfile(alt_file)) == 0) {
420 failed("copy_input (target)");
427 } else if (ferror(source)) {
429 } else if (ch == 0) {
430 /* don't loop in case someone wants to convert /dev/zero */
431 fprintf(stderr, "%s: %s is not a text-file\n", _nc_progname, filename);
432 ExitProgram(EXIT_FAILURE);
438 * rewind() does not force the target file's data to disk (not does
439 * fflush()...). So open a second stream on the data and then close
440 * the one that we were writing on before starting to read from the
443 result = fopen(alt_file, "r+");
445 to_remove = strdup(alt_file);
451 open_input(const char *filename, char *alt_file)
457 if (!strcmp(filename, "-")) {
458 fp = copy_input(stdin, STDIN_NAME, alt_file);
459 } else if (stat(filename, &sb) < 0) {
460 fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
461 ExitProgram(EXIT_FAILURE);
462 } else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
463 || (mode != S_IFREG && mode != S_IFCHR && mode != S_IFIFO)) {
464 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
465 ExitProgram(EXIT_FAILURE);
467 fp = fopen(filename, "r");
470 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
471 ExitProgram(EXIT_FAILURE);
473 if (mode != S_IFREG) {
475 FILE *fp2 = copy_input(fp, filename, alt_file);
478 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
479 ExitProgram(EXIT_FAILURE);
486 /* Parse the "-e" option-value into a list of names */
488 make_namelist(char *src)
493 unsigned pass, n, nn;
498 } else if (strchr(src, '/') != 0) { /* a filename */
499 FILE *fp = open_input(src, (char *) 0);
501 for (pass = 1; pass <= 2; pass++) {
503 while (fgets(buffer, sizeof(buffer), fp) != 0) {
504 if ((s = stripped(buffer)) != 0) {
513 if ((dst = typeCalloc(char *, nn + 1)) == 0)
514 failed("make_namelist");
519 } else { /* literal list of names */
520 for (pass = 1; pass <= 2; pass++) {
521 for (n = nn = 0, base = src;; n++) {
523 if (mark == ',' || mark == '\0') {
528 if ((s = stripped(base)) != 0)
537 if ((dst = typeCalloc(char *, nn + 1)) == 0)
538 failed("make_namelist");
542 if (showsummary && (dst != 0)) {
543 fprintf(log_fp, "Entries that will be compiled:\n");
544 for (n = 0; dst[n] != 0; n++)
545 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
551 matches(char **needle, const char *haystack)
552 /* does entry in needle list match |-separated field in haystack? */
558 for (n = 0; needle[n] != 0; n++) {
559 if (_nc_name_match(haystack, needle[n], "|")) {
570 valid_db_path(const char *nominal)
574 char suffix[] = DBM_SUFFIX;
575 size_t need = strlen(nominal) + sizeof(suffix);
576 char *result = malloc(need);
579 failed("valid_db_path");
580 _nc_STRCPY(result, nominal, need);
581 if (strcmp(result + need - sizeof(suffix), suffix)) {
582 _nc_STRCAT(result, suffix, need);
585 char *result = strdup(nominal);
588 DEBUG(1, ("** stat(%s)", result));
589 if (stat(result, &sb) >= 0) {
591 if (!S_ISREG(sb.st_mode)
592 || access(result, R_OK | W_OK) != 0) {
593 DEBUG(1, ("...not a writable file"));
598 if (!S_ISDIR(sb.st_mode)
599 || access(result, R_OK | W_OK | X_OK) != 0) {
600 DEBUG(1, ("...not a writable directory"));
606 /* check if parent is directory and is writable */
607 unsigned leaf = _nc_pathlast(result);
609 DEBUG(1, ("...not found"));
611 char save = result[leaf];
613 if (stat(result, &sb) >= 0
614 && S_ISDIR(sb.st_mode)
615 && access(result, R_OK | W_OK | X_OK) == 0) {
618 DEBUG(1, ("...parent directory %s is not writable", result));
623 DEBUG(1, ("... no parent directory"));
632 * Show the databases to which tic could write. The location to which it
633 * writes is always the first one. If none are writable, print an error
637 show_databases(const char *outdir)
639 bool specific = (outdir != 0) || getenv("TERMINFO") != 0;
641 const char *tried = 0;
644 outdir = _nc_tic_dir(0);
646 if ((result = valid_db_path(outdir)) != 0) {
647 printf("%s\n", result);
653 if ((outdir = _nc_home_terminfo())) {
654 if ((result = valid_db_path(outdir)) != 0) {
655 printf("%s\n", result);
657 } else if (!specific) {
663 * If we can write in neither location, give an error message.
667 fprintf(stderr, "%s: %s (no permission)\n", _nc_progname, tried);
668 ExitProgram(EXIT_FAILURE);
673 add_digit(int *target, int source)
675 *target = (*target * 10) + (source - '0');
679 main(int argc, char *argv[])
681 char my_tmpname[PATH_MAX];
682 char my_altfile[PATH_MAX];
684 int smart_defaults = TRUE;
688 int this_opt, last_opt = '?';
690 int outform = F_TERMINFO; /* output format */
691 int sortmode = S_TERMINFO; /* sort_mode */
695 bool formatted = FALSE; /* reformat complex strings? */
696 bool literal = FALSE; /* suppress post-processing? */
697 int numbers = 0; /* format "%'char'" to/from "%{number}" */
698 bool forceresolve = FALSE; /* force resolution */
700 char *tversion = (char *) NULL;
701 const char *source_file = "terminfo";
702 char *outdir = (char *) NULL;
703 bool check_only = FALSE;
704 bool suppress_untranslatable = FALSE;
707 bool wrap_strings = FALSE;
711 _nc_progname = _nc_rootname(argv[0]);
714 if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
715 outform = F_TERMINFO;
716 sortmode = S_TERMINFO;
718 if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
720 sortmode = S_TERMCAP;
723 use_extended_names(FALSE);
728 * Processing arguments is a little complicated, since someone made a
729 * design decision to allow the numeric values for -w, -v options to
732 while ((this_opt = getopt(argc, argv,
733 "0123456789CDIKLNQR:TUVWace:fGgo:qrstvwx")) != -1) {
734 if (isdigit(this_opt)) {
737 add_digit(&quickdump, this_opt);
740 add_digit(&v_opt, this_opt);
743 add_digit(&width, this_opt);
765 /* the initial version of -K in 20110730 fell-thru here, but the
766 * same flag is useful when reading sources -TD
772 sortmode = S_TERMCAP;
775 debug_level = VtoTrace(v_opt);
776 set_trace_level(debug_level);
777 show_databases(outdir);
778 ExitProgram(EXIT_SUCCESS);
782 outform = F_TERMINFO;
783 sortmode = S_TERMINFO;
787 outform = F_VARIABLE;
788 sortmode = S_VARIABLE;
791 smart_defaults = FALSE;
807 puts(curses_version());
808 ExitProgram(EXIT_SUCCESS);
816 namelst = make_namelist(optarg);
847 _nc_disable_period = FALSE;
848 suppress_untranslatable = TRUE;
851 _nc_disable_period = TRUE;
854 use_extended_names(TRUE);
855 using_extensions = TRUE;
864 debug_level = VtoTrace(v_opt);
865 set_trace_level(debug_level);
868 save_check_termtype = _nc_check_termtype2;
869 _nc_check_termtype2 = check_termtype;
873 * Aaargh! immedhook seriously hoses us!
875 * One problem with immedhook is it means we can't do -e. Problem
876 * is that we can't guarantee that for each terminal listed, all the
877 * terminals it depends on will have been kept in core for reference
878 * resolution -- in fact it's certain the primitive types at the end
879 * of reference chains *won't* be in core unless they were explicitly
880 * in the select list themselves.
882 if (namelst && (!infodump && !capdump)) {
883 (void) fprintf(stderr,
884 "%s: Sorry, -e can't be used without -I or -C\n",
886 ExitProgram(EXIT_FAILURE);
888 #endif /* HAVE_BIG_CORE */
891 source_file = argv[optind++];
894 "%s: Too many file names. Usage:\n\t%s %s",
898 ExitProgram(EXIT_FAILURE);
901 if (infodump == TRUE) {
902 /* captoinfo's no-argument case */
903 source_file = "/etc/termcap";
904 if ((termcap = getenv("TERMCAP")) != 0
905 && (namelst = make_namelist(getenv("TERM"))) != 0) {
906 if (access(termcap, F_OK) == 0) {
908 source_file = termcap;
910 if ((tmp_fp = open_tempfile(my_tmpname)) != 0) {
911 source_file = my_tmpname;
912 fprintf(tmp_fp, "%s\n", termcap);
914 tmp_fp = open_input(source_file, (char *) 0);
915 to_remove = source_file;
924 "%s: File name needed. Usage:\n\t%s %s",
928 ExitProgram(EXIT_FAILURE);
933 tmp_fp = open_input(source_file, my_altfile);
934 if (!strcmp(source_file, "-")) {
935 source_file = STDIN_NAME;
939 if (infodump || check_only) {
945 wrap_strings, width, height,
946 debug_level, formatted || check_only, check_only, quickdump);
947 } else if (capdump) {
951 wrap_strings, width, height,
952 debug_level, FALSE, FALSE, FALSE);
955 /* parse entries out of the source file */
956 _nc_set_source(source_file);
958 if (!(check_only || infodump || capdump))
959 _nc_set_writedir(outdir);
960 #endif /* HAVE_BIG_CORE */
961 _nc_read_entry_source(tmp_fp, (char *) NULL,
962 !smart_defaults || literal, FALSE,
963 ((check_only || infodump || capdump)
967 /* do use resolution */
968 if (check_only || (!infodump && !capdump) || forceresolve) {
969 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
970 ExitProgram(EXIT_FAILURE);
975 if (check_only && limited && (capdump || infodump)) {
977 if (matches(namelst, qp->tterm.term_names)) {
978 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
980 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
981 (void) fprintf(stderr,
982 "%s: resolved %s entry is %d bytes long\n",
984 _nc_first_name(qp->tterm.term_names),
990 /* write or dump all entries */
992 /* this is in case infotocap() generates warnings */
993 _nc_curr_col = _nc_curr_line = -1;
996 if (matches(namelst, qp->tterm.term_names)) {
997 /* this is in case infotocap() generates warnings */
998 _nc_set_type(_nc_first_name(qp->tterm.term_names));
999 _nc_curr_line = (int) qp->startline;
1000 repair_acsc(&qp->tterm);
1001 dump_entry(&qp->tterm, suppress_untranslatable,
1002 limited, numbers, NULL);
1006 if (!infodump && !capdump) {
1007 _nc_set_writedir(outdir);
1008 for_entry_list(qp) {
1009 if (matches(namelst, qp->tterm.term_names))
1013 /* this is in case infotocap() generates warnings */
1014 _nc_curr_col = _nc_curr_line = -1;
1016 for_entry_list(qp) {
1017 if (matches(namelst, qp->tterm.term_names)) {
1018 long j = qp->cend - qp->cstart;
1021 /* this is in case infotocap() generates warnings */
1022 _nc_set_type(_nc_first_name(qp->tterm.term_names));
1025 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
1028 (void) putchar(fgetc(tmp_fp));
1030 put_translate(fgetc(tmp_fp));
1034 repair_acsc(&qp->tterm);
1035 dump_entry(&qp->tterm, suppress_untranslatable,
1036 limited, numbers, NULL);
1037 for (j = 0; j < (long) qp->nuses; j++)
1038 dump_uses(qp->uses[j].name, !capdump);
1040 if (debug_level != 0 && !limited)
1041 printf("# length=%d\n", len);
1044 if (!namelst && _nc_tail && !quiet) {
1046 bool in_comment = FALSE;
1047 bool trailing_comment = FALSE;
1049 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
1050 while ((c = fgetc(tmp_fp)) != EOF) {
1053 trailing_comment = TRUE;
1059 if (trailing_comment
1060 && (in_comment || (oldc == '\n' && c == '\n')))
1068 /* Show the directory into which entries were written, and the total
1072 && (!(check_only || infodump || capdump))) {
1073 int total = _nc_tic_written();
1075 fprintf(log_fp, "%d entries written to %s\n",
1077 _nc_tic_dir((char *) 0));
1079 fprintf(log_fp, "No entries written\n");
1081 ExitProgram(EXIT_SUCCESS);
1085 * This bit of legerdemain turns all the terminfo variable names into
1086 * references to locations in the arrays Booleans, Numbers, and Strings ---
1087 * precisely what's needed (see comp_parse.c).
1093 * Check if the alternate character-set capabilities are consistent.
1096 check_acs(TERMTYPE2 *tp)
1098 int vt100_smacs = 0;
1099 int vt100_rmacs = 0;
1100 int vt100_enacs = 0;
1103 * ena_acs is not always necessary, but if it is present, the enter/exit
1104 * capabilities should be.
1106 ANDMISSING(ena_acs, enter_alt_charset_mode);
1107 ANDMISSING(ena_acs, exit_alt_charset_mode);
1108 PAIRED(exit_alt_charset_mode, exit_alt_charset_mode);
1111 * vt100-like is frequently used, but perhaps ena_acs is missing, etc.
1113 if (VALID_STRING(enter_alt_charset_mode)) {
1114 vt100_smacs = (!strcmp("\033(0", enter_alt_charset_mode)
1116 : (!strcmp("\016", enter_alt_charset_mode)
1120 if (VALID_STRING(exit_alt_charset_mode)) {
1121 vt100_rmacs = (!strcmp("\033(B", exit_alt_charset_mode)
1123 : (!strcmp("\017", exit_alt_charset_mode)
1127 if (VALID_STRING(ena_acs)) {
1128 vt100_enacs = (!strcmp("\033(B\033)0", ena_acs)
1132 if (vt100_rmacs && vt100_smacs && (vt100_rmacs != vt100_smacs)) {
1133 _nc_warning("rmacs/smacs are inconsistent");
1135 if ((vt100_rmacs == 2) && (vt100_smacs == 2) && vt100_enacs) {
1136 _nc_warning("rmacs/smacs make enacs redundant");
1138 if ((vt100_rmacs == 1) && (vt100_smacs == 1) && !vt100_enacs) {
1139 _nc_warning("VT100-style rmacs/smacs require enacs");
1142 if (VALID_STRING(acs_chars)) {
1143 const char *boxes = "lmkjtuvwqxn";
1149 memset(mapped, 0, sizeof(mapped));
1150 for (p = acs_chars; *p != '\0'; p += 2) {
1152 _nc_warning("acsc has odd number of characters");
1155 mapped[UChar(p[0])] = p[1];
1158 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
1159 _nc_warning("acsc refers to 'I', which is probably an error");
1162 for (p = boxes, q = missing; *p != '\0'; ++p) {
1163 if (!mapped[UChar(p[0])]) {
1169 assert(strlen(missing) <= strlen(boxes));
1170 if (*missing != '\0' && strcmp(missing, boxes)) {
1171 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
1177 same_color(NCURSES_CONST char *oldcap, NCURSES_CONST char *newcap, int limit)
1179 bool result = FALSE;
1185 for (n = same = 0; n < limit; ++n) {
1186 char *oldvalue = strdup(TPARM_1(oldcap, n));
1187 char *newvalue = strdup(TPARM_1(newcap, n));
1188 same += !strcmp(oldvalue, newvalue);
1192 result = (same == limit);
1198 * Check if the color capabilities are consistent
1201 check_colors(TERMTYPE2 *tp)
1203 if ((max_colors > 0) != (max_pairs > 0)
1204 || ((max_colors > max_pairs) && (initialize_pair == 0)))
1205 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
1206 max_colors, max_pairs);
1208 PAIRED(set_foreground, set_background);
1209 PAIRED(set_a_foreground, set_a_background);
1210 PAIRED(set_color_pair, initialize_pair);
1212 if (VALID_STRING(set_foreground)
1213 && VALID_STRING(set_a_foreground)) {
1214 if (!_nc_capcmp(set_foreground, set_a_foreground)) {
1215 _nc_warning("expected setf/setaf to be different");
1216 } else if (same_color(set_foreground, set_a_foreground, max_colors)) {
1217 _nc_warning("setf/setaf are equivalent");
1221 if (VALID_STRING(set_background)
1222 && VALID_STRING(set_a_background)) {
1223 if (!_nc_capcmp(set_background, set_a_background)) {
1224 _nc_warning("expected setb/setab to be different");
1225 } else if (same_color(set_background, set_a_background, max_colors)) {
1226 _nc_warning("setb/setab are equivalent");
1230 /* see: has_colors() */
1231 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
1232 && ((VALID_STRING(set_foreground)
1233 && VALID_STRING(set_background))
1234 || (VALID_STRING(set_a_foreground)
1235 && VALID_STRING(set_a_background))
1236 || set_color_pair)) {
1237 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
1238 _nc_warning("expected either op/oc string for resetting colors");
1241 if (!VALID_STRING(initialize_pair) &&
1242 !VALID_STRING(initialize_color)) {
1243 _nc_warning("expected initc or initp because ccc is given");
1246 if (VALID_STRING(initialize_pair) ||
1247 VALID_STRING(initialize_color)) {
1248 _nc_warning("expected ccc because initc is given");
1254 csi_length(const char *value)
1258 if (value[0] == '\033' && value[1] == '[') {
1260 } else if (UChar(value[0]) == 0x9a) {
1267 keypad_final(const char *string)
1271 if (VALID_STRING(string)
1272 && *string++ == '\033'
1274 && strlen(string) == 1) {
1282 keypad_index(const char *string)
1285 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
1289 if ((ch = keypad_final(string)) != '\0') {
1290 test = (strchr) (list, ch);
1292 result = (long) (test - list);
1298 * list[] is down, up, left, right
1299 * "left" may be ^H rather than \E[D
1300 * "down" may be ^J rather than \E[B
1301 * But up/right are generally consistently escape sequences for ANSI terminals.
1304 check_ansi_cursor(char *list[4])
1310 bool repeated = FALSE;
1312 for (j = 0; j < 4; ++j) {
1314 for (k = 0; k < j; ++k) {
1316 && !strcmp(list[j], list[k])) {
1317 char *value = _nc_tic_expand(list[k], TRUE, 0);
1318 _nc_warning("repeated cursor control %s\n", value);
1325 size_t prefix = (size_t) csi_length(up);
1329 while (up[suffix] && isdigit(UChar(up[suffix])))
1332 if (prefix && up[suffix] == 'A') {
1334 if (!strcmp(list[0], "\n"))
1336 if (!strcmp(list[2], "\b"))
1339 for (j = 0; j < 4; ++j) {
1340 if (skip[j] || strlen(list[j]) == 1)
1342 if (memcmp(list[j], up, prefix)) {
1343 char *value = _nc_tic_expand(list[j], TRUE, 0);
1344 _nc_warning("inconsistent prefix for %s\n", value);
1347 if (strlen(list[j]) < suffix) {
1348 char *value = _nc_tic_expand(list[j], TRUE, 0);
1349 _nc_warning("inconsistent length for %s, expected %d\n",
1350 value, (int) suffix + 1);
1354 if (list[j][suffix] != want) {
1355 char *value = _nc_tic_expand(list[j], TRUE, 0);
1356 _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
1357 value, want, list[j][suffix]);
1364 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
1365 #define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
1368 check_noaddress(TERMTYPE2 *tp, const char *why)
1370 UNEXPECTED(column_address);
1371 UNEXPECTED(cursor_address);
1372 UNEXPECTED(cursor_home);
1373 UNEXPECTED(cursor_mem_address);
1374 UNEXPECTED(cursor_to_ll);
1375 UNEXPECTED(row_address);
1376 UNEXPECTED(row_address);
1380 check_cursor(TERMTYPE2 *tp)
1386 check_noaddress(tp, "hard_copy");
1387 } else if (generic_type) {
1388 check_noaddress(tp, "generic_type");
1389 } else if (strchr(tp->term_names, '+') == 0) {
1392 if (PRESENT(column_address))
1394 if (PRESENT(cursor_address))
1396 if (PRESENT(cursor_home))
1398 if (PRESENT(cursor_mem_address))
1400 if (PRESENT(cursor_to_ll))
1402 if (PRESENT(row_address))
1404 if (PRESENT(cursor_down))
1406 if (PRESENT(cursor_up))
1408 if (PRESENT(cursor_left))
1410 if (PRESENT(cursor_right))
1412 if (x < 2 && y < 2) {
1413 _nc_warning("terminal lacks cursor addressing");
1416 _nc_warning("terminal lacks cursor column-addressing");
1418 _nc_warning("terminal lacks cursor row-addressing");
1422 /* it is rare to have an insert-line feature without a matching delete */
1423 ANDMISSING(parm_insert_line, insert_line);
1424 ANDMISSING(parm_delete_line, delete_line);
1425 ANDMISSING(parm_insert_line, parm_delete_line);
1427 /* if we have a parameterized form, then the non-parameterized is easy */
1428 ANDMISSING(parm_down_cursor, cursor_down);
1429 ANDMISSING(parm_up_cursor, cursor_up);
1430 ANDMISSING(parm_left_cursor, cursor_left);
1431 ANDMISSING(parm_right_cursor, cursor_right);
1433 /* Given any of a set of cursor movement, the whole set should be present.
1434 * Technically this is not true (we could use cursor_address to fill in
1435 * unsupported controls), but it is likely.
1438 if (PRESENT(parm_down_cursor)) {
1439 list[count++] = parm_down_cursor;
1441 if (PRESENT(parm_up_cursor)) {
1442 list[count++] = parm_up_cursor;
1444 if (PRESENT(parm_left_cursor)) {
1445 list[count++] = parm_left_cursor;
1447 if (PRESENT(parm_right_cursor)) {
1448 list[count++] = parm_right_cursor;
1451 check_ansi_cursor(list);
1452 } else if (count != 0) {
1453 EXPECTED(parm_down_cursor);
1454 EXPECTED(parm_up_cursor);
1455 EXPECTED(parm_left_cursor);
1456 EXPECTED(parm_right_cursor);
1460 if (PRESENT(cursor_down)) {
1461 list[count++] = cursor_down;
1463 if (PRESENT(cursor_up)) {
1464 list[count++] = cursor_up;
1466 if (PRESENT(cursor_left)) {
1467 list[count++] = cursor_left;
1469 if (PRESENT(cursor_right)) {
1470 list[count++] = cursor_right;
1473 check_ansi_cursor(list);
1474 } else if (count != 0) {
1476 if (PRESENT(cursor_down) && strcmp(cursor_down, "\n"))
1478 if (PRESENT(cursor_left) && strcmp(cursor_left, "\b"))
1480 if (PRESENT(cursor_up) && strlen(cursor_up) > 1)
1482 if (PRESENT(cursor_right) && strlen(cursor_right) > 1)
1485 EXPECTED(cursor_down);
1486 EXPECTED(cursor_up);
1487 EXPECTED(cursor_left);
1488 EXPECTED(cursor_right);
1495 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
1496 * is mapped inconsistently.
1499 check_keypad(TERMTYPE2 *tp)
1503 if (VALID_STRING(key_a1) &&
1504 VALID_STRING(key_a3) &&
1505 VALID_STRING(key_b2) &&
1506 VALID_STRING(key_c1) &&
1507 VALID_STRING(key_c3)) {
1508 char final[MAX_KP + 1];
1515 final[0] = keypad_final(key_a1);
1516 final[1] = keypad_final(key_a3);
1517 final[2] = keypad_final(key_b2);
1518 final[3] = keypad_final(key_c1);
1519 final[4] = keypad_final(key_c3);
1522 /* special case: legacy coding using 1,2,3,0,. on the bottom */
1523 assert(strlen(final) <= MAX_KP);
1524 if (!strcmp(final, "qsrpn"))
1527 list[0] = keypad_index(key_a1);
1528 list[1] = keypad_index(key_a3);
1529 list[2] = keypad_index(key_b2);
1530 list[3] = keypad_index(key_c1);
1531 list[4] = keypad_index(key_c3);
1533 /* check that they're all vt100 keys */
1534 for (j = 0; j < MAX_KP; ++j) {
1540 /* check if they're all in increasing order */
1541 for (j = 1; j < MAX_KP; ++j) {
1542 if (list[j] > list[j - 1]) {
1546 if (increase != (MAX_KP - 1)) {
1549 for (j = 0, last = -1; j < MAX_KP; ++j) {
1550 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
1551 if (list[k] > last &&
1558 assert(strlen(show) < (MAX_KP * 4));
1561 _nc_STRCAT(show, " ka1", sizeof(show));
1564 _nc_STRCAT(show, " ka3", sizeof(show));
1567 _nc_STRCAT(show, " kb2", sizeof(show));
1570 _nc_STRCAT(show, " kc1", sizeof(show));
1573 _nc_STRCAT(show, " kc3", sizeof(show));
1578 _nc_warning("vt100 keypad order inconsistent: %s", show);
1581 } else if (VALID_STRING(key_a1) ||
1582 VALID_STRING(key_a3) ||
1583 VALID_STRING(key_b2) ||
1584 VALID_STRING(key_c1) ||
1585 VALID_STRING(key_c3)) {
1587 if (keypad_index(key_a1) >= 0)
1588 _nc_STRCAT(show, " ka1", sizeof(show));
1589 if (keypad_index(key_a3) >= 0)
1590 _nc_STRCAT(show, " ka3", sizeof(show));
1591 if (keypad_index(key_b2) >= 0)
1592 _nc_STRCAT(show, " kb2", sizeof(show));
1593 if (keypad_index(key_c1) >= 0)
1594 _nc_STRCAT(show, " kc1", sizeof(show));
1595 if (keypad_index(key_c3) >= 0)
1596 _nc_STRCAT(show, " kc3", sizeof(show));
1598 _nc_warning("vt100 keypad map incomplete:%s", show);
1602 * These warnings are useful for consistency checks - it is possible that
1603 * there are real terminals with mismatches in these
1605 ANDMISSING(key_ic, key_dc);
1609 check_printer(TERMTYPE2 *tp)
1612 #if defined(enter_doublewide_mode) && defined(exit_doublewide_mode)
1613 PAIRED(enter_doublewide_mode, exit_doublewide_mode);
1615 #if defined(enter_italics_mode) && defined(exit_italics_mode)
1616 PAIRED(enter_italics_mode, exit_italics_mode);
1618 #if defined(enter_leftward_mode) && defined(exit_leftward_mode)
1619 PAIRED(enter_leftward_mode, exit_leftward_mode);
1621 #if defined(enter_micro_mode) && defined(exit_micro_mode)
1622 PAIRED(enter_micro_mode, exit_micro_mode);
1624 #if defined(enter_shadow_mode) && defined(exit_shadow_mode)
1625 PAIRED(enter_shadow_mode, exit_shadow_mode);
1627 #if defined(enter_subscript_mode) && defined(exit_subscript_mode)
1628 PAIRED(enter_subscript_mode, exit_subscript_mode);
1630 #if defined(enter_superscript_mode) && defined(exit_superscript_mode)
1631 PAIRED(enter_superscript_mode, exit_superscript_mode);
1633 #if defined(enter_upward_mode) && defined(exit_upward_mode)
1634 PAIRED(enter_upward_mode, exit_upward_mode);
1637 #if defined(start_char_set_def) && defined(stop_char_set_def)
1638 ANDMISSING(start_char_set_def, stop_char_set_def);
1641 /* if we have a parameterized form, then the non-parameterized is easy */
1642 #if defined(set_bottom_margin_parm) && defined(set_bottom_margin)
1643 ANDMISSING(set_bottom_margin_parm, set_bottom_margin);
1645 #if defined(set_left_margin_parm) && defined(set_left_margin)
1646 ANDMISSING(set_left_margin_parm, set_left_margin);
1648 #if defined(set_right_margin_parm) && defined(set_right_margin)
1649 ANDMISSING(set_right_margin_parm, set_right_margin);
1651 #if defined(set_top_margin_parm) && defined(set_top_margin)
1652 ANDMISSING(set_top_margin_parm, set_top_margin);
1655 #if defined(parm_down_micro) && defined(micro_down)
1656 ANDMISSING(parm_down_micro, micro_down);
1658 #if defined(parm_left_micro) && defined(micro_left)
1659 ANDMISSING(parm_left_micro, micro_left);
1661 #if defined(parm_right_micro) && defined(micro_right)
1662 ANDMISSING(parm_right_micro, micro_right);
1664 #if defined(parm_up_micro) && defined(micro_up)
1665 ANDMISSING(parm_up_micro, micro_up);
1670 uses_SGR_39_49(const char *value)
1672 return (strstr(value, "39;49") != 0
1673 || strstr(value, "49;39") != 0);
1677 * Check consistency of termcap extensions related to "screen".
1680 check_screen(TERMTYPE2 *tp)
1683 if (_nc_user_definable) {
1684 int have_XT = tigetflag("XT");
1685 int have_XM = tigetflag("XM");
1686 int have_bce = back_color_erase;
1687 bool have_kmouse = FALSE;
1688 bool use_sgr_39_49 = FALSE;
1689 char *name = _nc_first_name(tp->term_names);
1690 bool is_screen = !strncmp(name, "screen", 6);
1691 bool screen_base = (is_screen
1692 && strchr(name, '.') == 0);
1694 if (!VALID_BOOLEAN(have_bce)) {
1697 if (!VALID_BOOLEAN(have_XM)) {
1700 if (!VALID_BOOLEAN(have_XT)) {
1703 if (VALID_STRING(key_mouse)) {
1704 have_kmouse = !strcmp("\033[M", key_mouse);
1706 if (VALID_STRING(orig_colors)) {
1707 use_sgr_39_49 = uses_SGR_39_49(orig_colors);
1708 } else if (VALID_STRING(orig_pair)) {
1709 use_sgr_39_49 = uses_SGR_39_49(orig_pair);
1712 if (have_XM && have_XT) {
1713 _nc_warning("screen's XT capability conflicts with XM");
1714 } else if (have_XT && screen_base) {
1715 _nc_warning("screen's \"screen\" entries should not have XT set");
1716 } else if (have_XT) {
1717 if (!have_kmouse && is_screen) {
1718 if (VALID_STRING(key_mouse)) {
1719 _nc_warning("value of kmous inconsistent with screen's usage");
1721 _nc_warning("expected kmous capability with XT");
1724 if (!have_bce && max_colors > 0)
1725 _nc_warning("expected bce capability with XT");
1726 if (!use_sgr_39_49 && have_bce && max_colors > 0)
1727 _nc_warning("expected orig_colors capability with XT to have 39/49 parameters");
1728 if (VALID_STRING(to_status_line))
1729 _nc_warning("\"tsl\" capability is redundant, given XT");
1733 && !screen_base && strchr(name, '+') == 0) {
1734 _nc_warning("expected XT to be set, given kmous");
1742 * Returns the expected number of parameters for the given capability.
1745 expected_params(const char *name)
1747 #define DATA(name,count) { { name }, count }
1749 static const struct {
1753 DATA( "S0", 1 ), /* 'screen' extension */
1756 DATA( "colornm", 1 ),
1800 DATA( "setcolor", 1 ),
1804 DATA( "slength", 1 ),
1805 DATA( "slines", 1 ),
1806 DATA( "smgbp", 1 ), /* 2 if smgtp is not given */
1823 int result = 0; /* function-keys, etc., use none */
1825 for (n = 0; n < SIZEOF(table); n++) {
1826 if (!strcmp(name, table[n].name)) {
1827 result = table[n].count;
1842 * These are user-capabilities that happen to be used in ncurses' terminal
1846 lookup_user_capability(const char *name)
1849 #define DATA(name,type,parms) { name, type, parms }
1850 static USERCAPS table[] = {
1851 DATA( "AX", BOOLEAN, 0 ),
1852 DATA( "Cr", STRING, 0 ),
1853 DATA( "Cs", STRING, 1 ),
1854 DATA( "E0", STRING, 0 ),
1855 DATA( "E3", STRING, 0 ),
1856 DATA( "G0", BOOLEAN, 0 ),
1857 DATA( "Ms", STRING, 2 ),
1858 DATA( "RGB", BOOLEAN, 0 ), /* FIXME can be number or string */
1859 DATA( "S0", STRING, 1 ),
1860 DATA( "Se", STRING, 0 ),
1861 DATA( "Smulx", STRING, 1 ),
1862 DATA( "Ss", STRING, 1 ),
1863 DATA( "TS", STRING, 0 ),
1864 DATA( "U8", NUMBER, 0 ),
1865 DATA( "XM", STRING, 1 ),
1866 DATA( "XT", BOOLEAN, 0 ),
1867 DATA( "grbom", STRING, 0 ),
1868 DATA( "gsbom", STRING, 0 ),
1869 DATA( "rmxx", STRING, 0 ),
1870 DATA( "smxx", STRING, 0 ),
1871 DATA( "xm", STRING, 9 ),
1877 USERCAPS *result = 0;
1879 for (n = 0; n < SIZEOF(table); ++n) {
1880 if (!strcmp(name, table[n].name)) {
1890 * If a given name is likely to be a user-capability, return the number of
1891 * parameters it would be used with. If not, return -1.
1893 * ncurses assumes that u6 could be used for getting the cursor-position, but
1894 * that is not implemented. Make a special case for that, to quiet needless
1897 * The other string-capability extensions (see terminfo.src) which could have
1898 * parameters such as "Ss", "%u", are not used by ncurses. But we check those
1899 * anyway, to validate the terminfo database.
1902 is_user_capability(const char *name)
1905 if (name[0] == 'u' &&
1906 (name[1] >= '0' && name[1] <= '9') &&
1908 result = (name[1] == '6') ? 2 : 0;
1909 } else if (using_extensions) {
1910 USERCAPS *p = lookup_user_capability(name);
1912 result = p->n_parms;
1919 * Make a quick sanity check for the parameters which are used in the given
1920 * strings. If there are no "%p" tokens, then there should be no other "%"
1924 check_params(TERMTYPE2 *tp, const char *name, char *value, int extended)
1926 int expected = expected_params(name);
1929 bool params[NUM_PARM];
1932 #ifdef set_top_margin_parm
1933 if (!strcmp(name, "smgbp")
1934 && set_top_margin_parm == 0)
1938 for (n = 0; n < NUM_PARM; n++)
1944 _nc_warning("expected character after %% in %s", name);
1946 } else if (*s == 'p') {
1947 if (*++s == '\0' || !isdigit((int) *s)) {
1948 _nc_warning("expected digit after %%p in %s", name);
1962 int check = is_user_capability(name);
1963 if (check != actual) {
1964 _nc_warning("extended %s capability has %d parameters, expected %d",
1965 name, actual, check);
1966 } else if (debug_level > 1) {
1967 _nc_warning("extended %s capability has %d parameters, as expected",
1974 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1976 if (value == set_attributes || expected < 0) {
1978 } else if (expected != actual) {
1979 _nc_warning("%s uses %d parameters, expected %d", name,
1981 for (n = 1; n < actual; n++) {
1983 _nc_warning("%s omits parameter %d", name, n);
1988 * Counting "%p" markers does not account for termcap expressions which
1989 * may not have been fully translated. Also, tparm does its own analysis.
1990 * Report differences here.
1993 char *p_is_s[NUM_PARM];
1995 int analyzed = _nc_tparm_analyze(value, p_is_s, &popcount);
1996 if (analyzed < popcount) {
1997 analyzed = popcount;
1999 if (actual != analyzed && expected != analyzed) {
2000 int user_cap = is_user_capability(name);
2001 if ((user_cap == analyzed) && using_extensions) {
2003 } else if (user_cap >= 0) {
2004 _nc_warning("tparm will use %d parameters for %s, expected %d",
2005 analyzed, name, user_cap);
2007 _nc_warning("tparm analyzed %d parameters for %s, expected %d",
2008 analyzed, name, actual);
2015 line_capability(const char *name)
2017 bool result = FALSE;
2018 static const char *table[] =
2020 "csr", /* change_scroll_region */
2021 "clear", /* clear_screen */
2023 "cwin", /* create_window */
2024 "cup", /* cursor_address */
2025 "cud1", /* cursor_down */
2026 "home", /* cursor_home */
2027 "mrcup", /* cursor_mem_address */
2028 "ll", /* cursor_to_ll */
2029 "cuu1", /* cursor_up */
2030 "dl1", /* delete_line */
2031 "hd", /* down_half_line */
2032 "flash", /* flash_screen */
2033 "ff", /* form_feed */
2034 "il1", /* insert_line */
2035 "nel", /* newline */
2036 "dl", /* parm_delete_line */
2037 "cud", /* parm_down_cursor */
2038 "indn", /* parm_index */
2039 "il", /* parm_insert_line */
2040 "rin", /* parm_rindex */
2041 "cuu", /* parm_up_cursor */
2042 "mc0", /* print_screen */
2043 "vpa", /* row_address */
2044 "ind", /* scroll_forward */
2045 "ri", /* scroll_reverse */
2046 "hu", /* up_half_line */
2049 for (n = 0; n < SIZEOF(table); ++n) {
2050 if (!strcmp(name, table[n])) {
2059 * Check for DEC VT100 private mode for reverse video.
2062 skip_DECSCNM(const char *value, int *flag)
2066 int skip = csi_length(value);
2068 value[skip++] == '?' &&
2069 value[skip++] == '5') {
2070 if (value[skip] == 'h') {
2072 } else if (value[skip] == 'l') {
2082 check_delays(TERMTYPE2 *tp, const char *name, const char *value)
2085 const char *first = 0;
2086 const char *last = 0;
2088 for (p = value; *p != '\0'; ++p) {
2089 if (p[0] == '$' && p[1] == '<') {
2090 const char *base = p + 2;
2091 const char *mark = 0;
2094 int proportional = 0;
2099 for (q = base; *q != '\0'; ++q) {
2104 } else if (*q == '*' || *q == '/') {
2111 } else if (!(isalnum(UChar(*q)) || strchr("+-.", *q) != 0)) {
2114 } else if (proportional || mandatory) {
2118 last = *q ? (q + 1) : q;
2120 maybe = FALSE; /* just an isolated "$<" */
2124 int rc = sscanf(base, "%f%c", &check_f, &check_c);
2125 if ((rc != 2) || (check_c != *mark) || mixed) {
2126 _nc_warning("syntax error in %s delay '%.*s'", name,
2127 (int) (q - base), base);
2128 } else if (*name == 'k') {
2129 _nc_warning("function-key %s has delay", name);
2130 } else if (proportional && !line_capability(name)) {
2131 _nc_warning("non-line capability using proportional delay: %s", name);
2132 } else if (!xon_xoff &&
2134 strchr(_nc_first_name(tp->term_names), '+') == 0) {
2135 _nc_warning("%s in %s is used since no xon/xoff",
2137 ? "proportional delay"
2142 p = q - 1; /* restart scan */
2147 if (!strcmp(name, "flash") ||
2148 !strcmp(name, "beep")) {
2151 if (first == value || *last == 0) {
2153 * Delay is on one end or the other.
2155 _nc_warning("expected delay embedded within %s", name);
2161 * Check for missing delay when using VT100 reverse-video.
2162 * A real VT100 might not need this, but terminal emulators do.
2164 if ((p = skip_DECSCNM(value, &flag)) != 0 &&
2166 (q = skip_DECSCNM(p, &flag)) != 0 &&
2168 _nc_warning("expected a delay in %s", name);
2175 check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
2179 long numbers[1 + NUM_PARM];
2180 char *strings[1 + NUM_PARM];
2181 char *p_is_s[NUM_PARM];
2183 char blob[NUM_PARM * 10];
2187 for (k = 1; k <= NUM_PARM; k++) {
2190 _nc_SLIMIT(sizeof(blob) - (size_t) (next - blob))
2193 next += strlen(next) + 1;
2196 switch (tparm_type(name)) {
2198 result = TPARM_2(value, numbers[1], strings[2]);
2201 result = TPARM_3(value, numbers[1], strings[2], strings[3]);
2205 (void) _nc_tparm_analyze(value, p_is_s, &ignored);
2206 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
2207 result = TPARM_9(value,
2219 return strdup(result);
2222 #define IsDelay(ch) ((ch) == '.' || isdigit(UChar(ch)))
2225 parse_delay_value(const char *src, double *delays, int *always)
2233 while (isdigit(UChar(*src))) {
2234 (*delays) = (*delays) * 10 + (*src++ - '0');
2240 while (isdigit(UChar(*src))) {
2242 (*delays) += (*src++ - '0') / gotdot;
2245 while (*src == '*' || *src == '/') {
2246 if (always == 0 && *src == '/')
2248 if (*src++ == '*') {
2255 *delays = -(*delays);
2260 parse_ti_delay(const char *ti, double *delays)
2263 while (*ti != '\0') {
2269 && IsDelay(UChar(ti[2]))) {
2271 const char *last = parse_delay_value(ti + 2, delays, &ignored);
2283 parse_tc_delay(const char *tc, double *delays)
2285 return parse_delay_value(tc, delays, (int *) 0);
2289 * Compare terminfo- and termcap-strings, factoring out delays.
2292 same_ti_tc(const char *ti, const char *tc, bool * embedded)
2295 double ti_delay = 0.0;
2296 double tc_delay = 0.0;
2297 const char *ti_last;
2300 ti_last = parse_ti_delay(ti, &ti_delay);
2301 tc = parse_tc_delay(tc, &tc_delay);
2303 while ((ti < ti_last) && *tc) {
2304 if (*ti == '\\' && ispunct(UChar(ti[1]))) {
2306 if ((*ti == '^') && !strncmp(tc, "\\136", 4)) {
2311 } else if (ti[0] == '$' && ti[1] == '<') {
2313 const char *ss = parse_ti_delay(ti, &no_delay);
2320 if (*tc == '\\' && ispunct(UChar(tc[1]))) {
2323 if (*ti++ != *tc++) {
2333 *embedded = FALSE; /* report only one problem */
2341 * Check terminfo to termcap translation.
2344 check_infotocap(TERMTYPE2 *tp, int i, const char *value)
2346 const char *name = ExtStrname(tp, i, strnames);
2347 int params = (((i < (int) SIZEOF(parametrized)) &&
2352 : has_params(value)));
2358 if ((ti_value = _nc_tic_expand(value, TRUE, to_char)) == ABSENT_STRING) {
2359 _nc_warning("tic-expansion of %s failed", name);
2360 } else if ((tc_value = _nc_infotocap(name, ti_value, params)) == ABSENT_STRING) {
2361 _nc_warning("tic-conversion of %s failed", name);
2362 } else if (params > 0) {
2367 if (!strcmp(name, "setf")
2368 || !strcmp(name, "setb")
2369 || !strcmp(name, "setaf")
2370 || !strcmp(name, "setab")) {
2371 if ((limit = max_colors) > 16)
2374 for (count = 0; count < limit; ++count) {
2375 char *ti_check = check_1_infotocap(name, ti_value, count);
2376 char *tc_check = check_1_infotocap(name, tc_value, count);
2378 if (strcmp(ti_check, tc_check)) {
2380 fprintf(stderr, "check_infotocap(%s)\n", name);
2381 fprintf(stderr, "...ti '%s'\n", ti_value);
2382 fprintf(stderr, "...tc '%s'\n", tc_value);
2385 _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s",
2386 name, count, ti_check, tc_check);
2391 } else if (params == 0 && !same_ti_tc(ti_value, tc_value, &embedded)) {
2393 _nc_warning("termcap equivalent of %s cannot use embedded delay", name);
2395 _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s",
2396 name, ti_value, tc_value);
2404 while (*s == '/' || isdigit(UChar(*s)))
2410 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
2411 * the latter may have a worst-case delay on the end.
2414 ignore_delays(char *s)
2446 #define DATA(name) { #name }
2447 static const char sgr_names[][11] =
2464 * An sgr string may contain several settings other than the one we're
2465 * interested in, essentially sgr0 + rmacs + whatever. As long as the
2466 * "whatever" is contained in the sgr string, that is close enough for our
2470 similar_sgr(int num, char *a, char *b)
2481 } else if (b[0] == '$'
2483 _nc_warning("did not find delay %s", _nc_visbuf(b));
2485 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
2486 sgr_names[num], _nc_visbuf2(1, base_a),
2487 _nc_visbuf2(2, base_b),
2491 } else if (delaying) {
2494 } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
2516 /* ignore delays on the end of the string */
2517 a = ignore_delays(a);
2518 return ((num != 0) || (*a == 0));
2522 check_sgr(TERMTYPE2 *tp, char *zero, int num, char *cap, const char *name)
2527 test = TPARM_9(set_attributes,
2539 if (!similar_sgr(num, test, cap)) {
2540 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
2542 name, _nc_visbuf2(1, cap),
2543 num, _nc_visbuf2(2, test));
2545 } else if (_nc_capcmp(test, zero)) {
2546 _nc_warning("sgr(%d) present, but not %s", num, name);
2548 } else if (PRESENT(cap)) {
2549 _nc_warning("sgr(%d) missing, but %s present", num, name);
2552 _nc_warning("stack error in sgr(%d) string", num);
2556 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
2560 * If tic is compiled with TRACE, we'll be able to see the output from the
2561 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
2562 * the standard error. Use this function to make it simpler to follow the
2563 * resulting debug traces.
2566 show_where(unsigned level)
2568 if (_nc_tracing >= DEBUG_LEVEL(level)) {
2569 char my_name[MAX_NAME_SIZE];
2570 _nc_get_type(my_name);
2571 _tracef("\"%s\", line %d, '%s'",
2573 _nc_curr_line, my_name);
2578 #define show_where(level) /* nothing */
2588 get_fkey_list(TERMTYPE2 *tp)
2590 NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1);
2591 const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys;
2596 failed("get_fkey_list");
2598 for (j = 0; all_fkeys[j].code; j++) {
2599 char *a = tp->Strings[all_fkeys[j].offset];
2600 if (VALID_STRING(a)) {
2601 result[used].keycode = (int) all_fkeys[j].code;
2602 result[used].name = strnames[all_fkeys[j].offset];
2603 result[used].value = a;
2608 for (j = STRCOUNT; j < NUM_STRINGS(tp); ++j) {
2609 const char *name = ExtStrname(tp, (int) j, strnames);
2611 result[used].keycode = -1;
2612 result[used].name = name;
2613 result[used].value = tp->Strings[j];
2618 result[used].keycode = 0;
2623 show_fkey_name(NAME_VALUE * data)
2625 if (data->keycode > 0) {
2626 fprintf(stderr, " %s", keyname(data->keycode));
2627 fprintf(stderr, " (capability \"%s\")", data->name);
2629 fprintf(stderr, " capability \"%s\"", data->name);
2634 * A terminal entry may contain more than one keycode assigned to a given
2635 * string (e.g., KEY_END and KEY_LL). But curses will only return one (the
2636 * last one assigned).
2639 check_conflict(TERMTYPE2 *tp)
2641 bool conflict = FALSE;
2644 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
2645 char *check = calloc((size_t) (NUM_STRINGS(tp) + 1), sizeof(char));
2646 NAME_VALUE *given = get_fkey_list(tp);
2649 failed("check_conflict");
2651 for (j = 0; given[j].keycode; ++j) {
2652 const char *a = given[j].value;
2655 if (!VALID_STRING(a))
2658 for (k = j + 1; given[k].keycode; k++) {
2659 const char *b = given[k].value;
2661 if (!VALID_STRING(b))
2666 if (!_nc_capcmp(a, b)) {
2671 _nc_warning("conflicting key definitions (using the last)");
2674 fprintf(stderr, "...");
2675 show_fkey_name(given + j);
2676 fprintf(stderr, " is the same as");
2677 show_fkey_name(given + k);
2680 fprintf(stderr, ", ");
2681 show_fkey_name(given + k);
2686 fprintf(stderr, "\n");
2689 if (using_extensions) {
2692 const char *xcurses;
2693 const char *shifted;
2709 * SVr4 curses defines the "xcurses" names listed above except for
2710 * the special cases in the "shifted" column. When using these
2711 * names for xterm's extensions, that was confusing, and resulted
2712 * in adding extended capabilities with "2" (shift) suffix. This
2713 * check warns about unnecessary use of extensions for this quirk.
2715 for (j = 0; given[j].keycode; ++j) {
2716 const char *find = given[j].name;
2720 if (!VALID_STRING(given[j].value))
2723 for (k = 0; table[k].xcurses; ++k) {
2724 const char *test = table[k].xcurses;
2725 size_t size = strlen(test);
2727 if (!strncmp(find, test, size) && strcmp(find, test)) {
2728 switch (sscanf(find + size, "%d%c", &value, &ch)) {
2731 _nc_warning("expected '%s' rather than '%s'",
2735 } else if (value < 2 || value > 15) {
2736 _nc_warning("expected numeric 2..15 '%s'", find);
2740 _nc_warning("expected numeric suffix for '%s'", find);
2755 * Exiting a video mode should not duplicate sgr0
2758 check_exit_attribute(const char *name, char *test, char *trimmed, char *untrimmed)
2760 if (VALID_STRING(test) && (trimmed != 0)) {
2761 if (similar_sgr(-1, trimmed, test) ||
2762 similar_sgr(-1, untrimmed, test)) {
2763 _nc_warning("%s matches exit_attribute_mode", name);
2769 * Returns true if the string looks like a standard SGR string.
2772 is_sgr_string(char *value)
2774 bool result = FALSE;
2776 if (VALID_STRING(value)) {
2777 int skip = csi_length(value);
2784 while ((ch = UChar(*value++)) != '\0') {
2785 if (isdigit(ch) || ch == ';') {
2787 } else if (ch == 'm' && *value == '\0') {
2800 * Check if the given capability contains a given SGR attribute.
2803 check_sgr_param(TERMTYPE2 *tp, int code, const char *name, char *value)
2805 if (VALID_STRING(value)) {
2806 int ncv = ((code != 0) ? (1 << (code - 1)) : 0);
2807 char *test = tgoto(value, 0, 0);
2808 if (is_sgr_string(test)) {
2812 int color = (value == set_a_foreground ||
2813 value == set_a_background ||
2814 value == set_foreground ||
2815 value == set_background);
2816 while (*test != 0) {
2817 if (isdigit(UChar(*test))) {
2818 param = 10 * param + (*test - '0');
2823 * Avoid unnecessary warning for xterm 256color codes.
2825 if (color && (param == 38 || param == 48))
2827 if ((skips-- <= 0) && (param == code))
2835 if (count != 0 && param == code) {
2837 no_color_video < 0 ||
2838 !(no_color_video & ncv)) {
2839 _nc_warning("\"%s\" SGR-attribute used in %s",
2849 standard_type(const char *name)
2852 const struct name_table_entry *np;
2854 if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0) {
2855 result = np->nte_type;
2861 name_of_type(int type)
2863 const char *result = "unknown";
2879 check_user_capability_type(const char *name, int actual)
2881 USERCAPS *p = lookup_user_capability(name);
2883 if (p->n_type != actual)
2884 _nc_warning("expected %s to be %s, but actually %s",
2886 name_of_type(p->n_type),
2887 name_of_type(actual)
2890 int expected = standard_type(name);
2891 if (expected >= 0) {
2892 _nc_warning("expected %s to be %s, but actually %s",
2894 name_of_type(p->n_type),
2895 name_of_type(expected)
2897 } else if (*name != 'k') {
2898 _nc_warning("undocumented %s capability %s",
2899 name_of_type(actual),
2905 /* other sanity-checks (things that we don't want in the normal
2906 * logic that reads a terminfo entry)
2909 check_termtype(TERMTYPE2 *tp, bool literal)
2915 for_each_string(j, tp) {
2916 char *a = tp->Strings[j];
2917 if (VALID_STRING(a)) {
2918 const char *name = ExtStrname(tp, (int) j, strnames);
2920 * If we expect parameters, or if there might be parameters,
2921 * check for consistent number of parameters.
2923 if (j >= SIZEOF(parametrized) ||
2924 is_user_capability(name) >= 0 ||
2925 parametrized[j] > 0) {
2926 check_params(tp, name, a, (j >= STRCOUNT));
2928 check_delays(tp, ExtStrname(tp, (int) j, strnames), a);
2930 check_infotocap(tp, (int) j, a);
2935 /* in extended mode, verify that each extension is expected type */
2936 for_each_ext_boolean(j, tp) {
2937 check_user_capability_type(ExtBoolname(tp, (int) j, strnames), BOOLEAN);
2939 for_each_ext_number(j, tp) {
2940 check_user_capability_type(ExtNumname(tp, (int) j, strnames), NUMBER);
2942 for_each_ext_string(j, tp) {
2943 check_user_capability_type(ExtStrname(tp, (int) j, strnames), STRING);
2945 #endif /* NCURSES_XNAMES */
2955 * These may be mismatched because the terminal description relies on
2956 * restoring the cursor visibility by resetting it.
2958 ANDMISSING(cursor_invisible, cursor_normal);
2959 ANDMISSING(cursor_visible, cursor_normal);
2961 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
2962 && !_nc_capcmp(cursor_visible, cursor_normal))
2963 _nc_warning("cursor_visible is same as cursor_normal");
2966 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
2967 * given, because the cursor position after the scrolling operation is
2968 * performed is undefined.
2970 ANDMISSING(change_scroll_region, save_cursor);
2971 ANDMISSING(change_scroll_region, restore_cursor);
2974 * If we can clear tabs, we should be able to initialize them.
2976 ANDMISSING(clear_all_tabs, set_tab);
2978 if (PRESENT(set_attributes)) {
2982 if (PRESENT(exit_attribute_mode)) {
2983 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
2985 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
2988 _nc_warning("stack error in sgr(0) string");
2991 CHECK_SGR(1, enter_standout_mode);
2992 CHECK_SGR(2, enter_underline_mode);
2993 CHECK_SGR(3, enter_reverse_mode);
2994 CHECK_SGR(4, enter_blink_mode);
2995 CHECK_SGR(5, enter_dim_mode);
2996 CHECK_SGR(6, enter_bold_mode);
2997 CHECK_SGR(7, enter_secure_mode);
2998 CHECK_SGR(8, enter_protected_mode);
2999 CHECK_SGR(9, enter_alt_charset_mode);
3002 _nc_warning("sgr(0) did not return a value");
3004 } else if (PRESENT(exit_attribute_mode) &&
3005 set_attributes != CANCELLED_STRING) {
3006 if (_nc_syntax == SYN_TERMINFO)
3007 _nc_warning("missing sgr string");
3009 #define CHECK_SGR0(name) check_exit_attribute(#name, name, check_sgr0, exit_attribute_mode)
3010 if (PRESENT(exit_attribute_mode)) {
3011 char *check_sgr0 = _nc_trim_sgr0(tp);
3013 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
3014 _nc_warning("trimmed sgr0 is empty");
3017 if (check_sgr0 != exit_attribute_mode) {
3019 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
3020 _nc_visbuf2(1, exit_attribute_mode),
3021 _nc_visbuf2(2, check_sgr0)));
3024 ("will not trim sgr0\n\toriginal sgr0=%s",
3025 _nc_visbuf(exit_attribute_mode)));
3028 #if defined(exit_italics_mode)
3029 CHECK_SGR0(exit_italics_mode);
3031 CHECK_SGR0(exit_standout_mode);
3032 CHECK_SGR0(exit_underline_mode);
3033 if (check_sgr0 != exit_attribute_mode) {
3037 #define CHECK_SGR_PARAM(code, name) check_sgr_param(tp, (int)code, #name, name)
3038 for (j = 0; *sgr_names[j] != '\0'; ++j) {
3039 CHECK_SGR_PARAM(j, set_a_foreground);
3040 CHECK_SGR_PARAM(j, set_a_background);
3041 CHECK_SGR_PARAM(j, set_foreground);
3042 CHECK_SGR_PARAM(j, set_background);
3046 if (!auto_right_margin) {
3048 ("can write to lower-right directly"));
3049 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
3051 ("can write to lower-right by suppressing automargin"));
3052 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
3053 || PRESENT(insert_character) || PRESENT(parm_ich)) {
3055 ("can write to lower-right by using inserts"));
3058 ("cannot write to lower-right"));
3063 * Some standard applications (e.g., vi) and some non-curses
3064 * applications (e.g., jove) get confused if we have both ich1 and
3065 * smir/rmir. Let's be nice and warn about that, too, even though
3066 * ncurses handles it.
3068 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
3069 && PRESENT(parm_ich)) {
3070 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
3074 * Finally, do the non-verbose checks
3076 if (save_check_termtype != 0)
3077 save_check_termtype(tp, literal);