1 /****************************************************************************
2 * Copyright (c) 1998-2013,2014 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.208 2014/10/18 09:34:29 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 static const char *const tbl[] =
144 " -1 format translation output one capability per line",
146 " -a retain commented-out capabilities (sets -x also)",
148 " -C translate entries to termcap source form",
149 " -D print list of tic's database locations (first must be writable)",
150 " -c check only, validate input without compiling or translating",
151 " -e<names> translate/compile only entries named by comma-separated list",
152 " -f format complex strings for readability",
153 " -G format %{number} to %'char'",
154 " -g format %'char' to %{number}",
155 " -I translate entries to terminfo source form",
156 " -K translate entries to termcap source form with BSD syntax",
157 " -L translate entries to full terminfo source form",
158 " -N disable smart defaults for source translation",
159 " -o<dir> set output directory for compiled entry writes",
160 " -R<name> restrict translation to given terminfo/termcap version",
161 " -r force resolution of all use entries in source translation",
162 " -s print summary statistics",
163 " -T remove size-restrictions on compiled description",
165 " -t suppress commented-out capabilities",
167 " -U suppress post-processing of entries",
169 " -v[n] set verbosity level",
170 " -w[n] set format width for translation output",
172 " -x treat unknown capabilities as user-defined",
176 " <file> file to translate or compile"
180 fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
181 for (j = 0; j < SIZEOF(tbl); j++) {
182 fputs(tbl[j], stderr);
185 ExitProgram(EXIT_FAILURE);
198 char result[MAX_ENTRY_SIZE];
201 * Look for strings that contain %{number}, convert them to %'char',
202 * which is shorter and runs a little faster.
204 for (n = 0; n < STRCOUNT; n++) {
205 s = ep->tterm.Strings[n];
207 && strchr(s, L_BRACE) != 0) {
210 while ((ch = *t++) != 0) {
214 } else if ((ch == '%')
215 && (*t == L_BRACE)) {
217 long value = strtol(t + 1, &v, 0);
221 && value != '\\' /* FIXME */
223 && isprint((int) value)) {
232 if (strlen(result) < strlen(s))
233 _nc_STRCPY(s, result, strlen(s) + 1);
237 _nc_set_type(_nc_first_name(ep->tterm.term_names));
238 _nc_curr_line = (int) ep->startline;
239 _nc_write_entry(&ep->tterm);
243 immedhook(ENTRY * ep GCC_UNUSED)
244 /* write out entries with no use capabilities immediately to save storage */
248 * This is strictly a core-economy kluge. The really clean way to handle
249 * compilation is to slurp the whole file into core and then do all the
250 * name-collision checks and entry writes in one swell foop. But the
251 * terminfo master file is large enough that some core-poor systems swap
252 * like crazy when you compile it this way...there have been reports of
253 * this process taking *three hours*, rather than the twenty seconds or
254 * less typical on my development box.
256 * So. This hook *immediately* writes out the referenced entry if it
257 * has no use capabilities. The compiler main loop refrains from
258 * adding the entry to the in-core list when this hook fires. If some
259 * other entry later needs to reference an entry that got written
260 * immediately, that's OK; the resolution code will fetch it off disk
261 * when it can't find it in core.
263 * Name collisions will still be detected, just not as cleanly. The
264 * write_entry() code complains before overwriting an entry that
265 * postdates the time of tic's first call to write_entry(). Thus
266 * it will complain about overwriting entries newly made during the
267 * tic run, but not about overwriting ones that predate it.
269 * The reason this is a hook, and not in line with the rest of the
270 * compiler code, is that the support for termcap fallback cannot assume
271 * it has anywhere to spool out these entries!
273 * The _nc_set_type() call here requires a compensating one in
276 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
277 * make tic a bit faster (because the resolution code won't have to do
278 * disk I/O nearly as often).
280 if (ep->nuses == 0) {
281 int oldline = _nc_curr_line;
284 _nc_curr_line = oldline;
285 free(ep->tterm.str_table);
288 #endif /* HAVE_BIG_CORE */
294 /* emit a comment char, translating terminfo names to termcap names */
296 static bool in_name = FALSE;
297 static size_t have, used;
298 static char *namebuf, *suffix;
301 if (used + 1 >= have) {
303 if ((namebuf = typeRealloc(char, have, namebuf)) == 0)
304 failed("put_translate namebuf");
305 if ((suffix = typeRealloc(char, have, suffix)) == 0)
306 failed("put_translate suffix");
308 if (c == '\n' || c == '@') {
309 namebuf[used++] = '\0';
311 (void) fputs(namebuf, stdout);
314 } else if (c != '>') {
315 namebuf[used++] = (char) c;
316 } else { /* ah! candidate name! */
318 NCURSES_CONST char *tp;
320 namebuf[used++] = '\0';
324 if ((up = strchr(namebuf, '#')) != 0
325 || (up = strchr(namebuf, '=')) != 0
326 || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
327 _nc_STRCPY(suffix, up, have);
331 if ((tp = nametrans(namebuf)) != 0) {
333 (void) fputs(tp, stdout);
334 (void) fputs(suffix, stdout);
337 /* couldn't find a translation, just dump the name */
339 (void) fputs(namebuf, stdout);
340 (void) fputs(suffix, stdout);
354 /* Returns a string, stripped of leading/trailing whitespace */
360 while (isspace(UChar(*src)))
366 if ((dst = strdup(src)) == NULL) {
370 while (--len != 0 && isspace(UChar(dst[len])))
378 open_tempfile(char *filename)
382 _nc_STRCPY(filename, "/tmp/XXXXXX", PATH_MAX);
385 int oldmask = (int) umask(077);
386 int fd = mkstemp(filename);
388 result = fdopen(fd, "w");
389 umask((mode_t) oldmask);
392 if (tmpnam(filename) != 0)
393 result = fopen(filename, "w");
399 copy_input(FILE *source, const char *filename, char *alt_file)
401 char my_altfile[PATH_MAX];
407 alt_file = my_altfile;
410 failed("copy_input (source)");
411 } else if ((target = open_tempfile(alt_file)) == 0) {
412 failed("copy_input (target)");
419 } else if (ferror(source)) {
421 } else if (ch == 0) {
422 /* don't loop in case someone wants to convert /dev/zero */
423 fprintf(stderr, "%s: %s is not a text-file\n", _nc_progname, filename);
424 ExitProgram(EXIT_FAILURE);
430 * rewind() does not force the target file's data to disk (not does
431 * fflush()...). So open a second stream on the data and then close
432 * the one that we were writing on before starting to read from the
435 result = fopen(alt_file, "r+");
437 to_remove = strdup(alt_file);
443 open_input(const char *filename, char *alt_file)
449 if (!strcmp(filename, "-")) {
450 fp = copy_input(stdin, STDIN_NAME, alt_file);
451 } else if (stat(filename, &sb) < 0) {
452 fprintf(stderr, "%s: %s %s\n", _nc_progname, filename, strerror(errno));
453 ExitProgram(EXIT_FAILURE);
454 } else if ((mode = (sb.st_mode & S_IFMT)) == S_IFDIR
455 || (mode != S_IFREG && mode != S_IFCHR && mode != S_IFIFO)) {
456 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
457 ExitProgram(EXIT_FAILURE);
459 fp = fopen(filename, "r");
462 fprintf(stderr, "%s: Can't open %s\n", _nc_progname, filename);
463 ExitProgram(EXIT_FAILURE);
465 if (mode != S_IFREG) {
467 FILE *fp2 = copy_input(fp, filename, alt_file);
470 fprintf(stderr, "%s: %s is not a file\n", _nc_progname, filename);
471 ExitProgram(EXIT_FAILURE);
478 /* Parse the "-e" option-value into a list of names */
480 make_namelist(char *src)
485 unsigned pass, n, nn;
490 } else if (strchr(src, '/') != 0) { /* a filename */
491 FILE *fp = open_input(src, (char *) 0);
493 for (pass = 1; pass <= 2; pass++) {
495 while (fgets(buffer, sizeof(buffer), fp) != 0) {
496 if ((s = stripped(buffer)) != 0) {
505 if ((dst = typeCalloc(char *, nn + 1)) == 0)
506 failed("make_namelist");
511 } else { /* literal list of names */
512 for (pass = 1; pass <= 2; pass++) {
513 for (n = nn = 0, base = src;; n++) {
515 if (mark == ',' || mark == '\0') {
520 if ((s = stripped(base)) != 0)
529 if ((dst = typeCalloc(char *, nn + 1)) == 0)
530 failed("make_namelist");
534 if (showsummary && (dst != 0)) {
535 fprintf(log_fp, "Entries that will be compiled:\n");
536 for (n = 0; dst[n] != 0; n++)
537 fprintf(log_fp, "%u:%s\n", n + 1, dst[n]);
543 matches(char **needle, const char *haystack)
544 /* does entry in needle list match |-separated field in haystack? */
550 for (n = 0; needle[n] != 0; n++) {
551 if (_nc_name_match(haystack, needle[n], "|")) {
562 valid_db_path(const char *nominal)
566 char suffix[] = DBM_SUFFIX;
567 size_t need = strlen(nominal) + sizeof(suffix);
568 char *result = malloc(need);
571 failed("valid_db_path");
572 _nc_STRCPY(result, nominal, need);
573 if (strcmp(result + need - sizeof(suffix), suffix)) {
574 _nc_STRCAT(result, suffix, need);
577 char *result = strdup(nominal);
580 DEBUG(1, ("** stat(%s)", result));
581 if (stat(result, &sb) >= 0) {
583 if (!S_ISREG(sb.st_mode)
584 || access(result, R_OK | W_OK) != 0) {
585 DEBUG(1, ("...not a writable file"));
590 if (!S_ISDIR(sb.st_mode)
591 || access(result, R_OK | W_OK | X_OK) != 0) {
592 DEBUG(1, ("...not a writable directory"));
598 /* check if parent is directory and is writable */
599 unsigned leaf = _nc_pathlast(result);
601 DEBUG(1, ("...not found"));
603 char save = result[leaf];
605 if (stat(result, &sb) >= 0
606 && S_ISDIR(sb.st_mode)
607 && access(result, R_OK | W_OK | X_OK) == 0) {
610 DEBUG(1, ("...parent directory %s is not writable", result));
615 DEBUG(1, ("... no parent directory"));
624 * Show the databases to which tic could write. The location to which it
625 * writes is always the first one. If none are writable, print an error
629 show_databases(const char *outdir)
631 bool specific = (outdir != 0) || getenv("TERMINFO") != 0;
633 const char *tried = 0;
636 outdir = _nc_tic_dir(0);
638 if ((result = valid_db_path(outdir)) != 0) {
639 printf("%s\n", result);
645 if ((outdir = _nc_home_terminfo())) {
646 if ((result = valid_db_path(outdir)) != 0) {
647 printf("%s\n", result);
649 } else if (!specific) {
655 * If we can write in neither location, give an error message.
659 fprintf(stderr, "%s: %s (no permission)\n", _nc_progname, tried);
660 ExitProgram(EXIT_FAILURE);
664 #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
667 main(int argc, char *argv[])
669 char my_tmpname[PATH_MAX];
670 char my_altfile[PATH_MAX];
672 unsigned debug_level;
673 int smart_defaults = TRUE;
677 int this_opt, last_opt = '?';
679 int outform = F_TERMINFO; /* output format */
680 int sortmode = S_TERMINFO; /* sort_mode */
684 bool formatted = FALSE; /* reformat complex strings? */
685 bool literal = FALSE; /* suppress post-processing? */
686 int numbers = 0; /* format "%'char'" to/from "%{number}" */
687 bool forceresolve = FALSE; /* force resolution */
689 char *tversion = (char *) NULL;
690 const char *source_file = "terminfo";
691 char *outdir = (char *) NULL;
692 bool check_only = FALSE;
693 bool suppress_untranslatable = FALSE;
697 _nc_progname = _nc_rootname(argv[0]);
700 if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) {
701 outform = F_TERMINFO;
702 sortmode = S_TERMINFO;
704 if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) {
706 sortmode = S_TERMCAP;
709 use_extended_names(FALSE);
714 * Processing arguments is a little complicated, since someone made a
715 * design decision to allow the numeric values for -w, -v options to
718 while ((this_opt = getopt(argc, argv,
719 "0123456789CDIKLNR:TUVace:fGgo:rstvwx")) != -1) {
720 if (isdigit(this_opt)) {
723 v_opt = (v_opt * 10) + (this_opt - '0');
726 width = (width * 10) + (this_opt - '0');
748 /* the initial version of -K in 20110730 fell-thru here, but the
749 * same flag is useful when reading sources -TD
755 sortmode = S_TERMCAP;
758 debug_level = VtoTrace(v_opt);
759 set_trace_level(debug_level);
760 show_databases(outdir);
761 ExitProgram(EXIT_SUCCESS);
765 outform = F_TERMINFO;
766 sortmode = S_TERMINFO;
770 outform = F_VARIABLE;
771 sortmode = S_VARIABLE;
774 smart_defaults = FALSE;
787 puts(curses_version());
788 ExitProgram(EXIT_SUCCESS);
793 namelst = make_namelist(optarg);
821 _nc_disable_period = FALSE;
822 suppress_untranslatable = TRUE;
825 _nc_disable_period = TRUE;
828 use_extended_names(TRUE);
837 debug_level = VtoTrace(v_opt);
838 set_trace_level(debug_level);
841 save_check_termtype = _nc_check_termtype2;
842 _nc_check_termtype2 = check_termtype;
846 * Aaargh! immedhook seriously hoses us!
848 * One problem with immedhook is it means we can't do -e. Problem
849 * is that we can't guarantee that for each terminal listed, all the
850 * terminals it depends on will have been kept in core for reference
851 * resolution -- in fact it's certain the primitive types at the end
852 * of reference chains *won't* be in core unless they were explicitly
853 * in the select list themselves.
855 if (namelst && (!infodump && !capdump)) {
856 (void) fprintf(stderr,
857 "%s: Sorry, -e can't be used without -I or -C\n",
859 ExitProgram(EXIT_FAILURE);
861 #endif /* HAVE_BIG_CORE */
864 source_file = argv[optind++];
867 "%s: Too many file names. Usage:\n\t%s %s",
871 ExitProgram(EXIT_FAILURE);
874 if (infodump == TRUE) {
875 /* captoinfo's no-argument case */
876 source_file = "/etc/termcap";
877 if ((termcap = getenv("TERMCAP")) != 0
878 && (namelst = make_namelist(getenv("TERM"))) != 0) {
879 if (access(termcap, F_OK) == 0) {
881 source_file = termcap;
883 if ((tmp_fp = open_tempfile(my_tmpname)) != 0) {
884 source_file = my_tmpname;
885 fprintf(tmp_fp, "%s\n", termcap);
887 tmp_fp = open_input(source_file, (char *) 0);
888 to_remove = source_file;
897 "%s: File name needed. Usage:\n\t%s %s",
901 ExitProgram(EXIT_FAILURE);
906 tmp_fp = open_input(source_file, my_altfile);
907 if (!strcmp(source_file, "-")) {
908 source_file = STDIN_NAME;
917 sortmode, width, height, debug_level, formatted);
918 } else if (capdump) {
921 sortmode, width, height, debug_level, FALSE);
924 /* parse entries out of the source file */
925 _nc_set_source(source_file);
927 if (!(check_only || infodump || capdump))
928 _nc_set_writedir(outdir);
929 #endif /* HAVE_BIG_CORE */
930 _nc_read_entry_source(tmp_fp, (char *) NULL,
931 !smart_defaults || literal, FALSE,
932 ((check_only || infodump || capdump)
936 /* do use resolution */
937 if (check_only || (!infodump && !capdump) || forceresolve) {
938 if (!_nc_resolve_uses2(TRUE, literal) && !check_only) {
939 ExitProgram(EXIT_FAILURE);
944 if (check_only && limited && (capdump || infodump)) {
946 if (matches(namelst, qp->tterm.term_names)) {
947 int len = fmt_entry(&qp->tterm, NULL, FALSE, TRUE, infodump, numbers);
949 if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
950 (void) fprintf(stderr,
951 "warning: resolved %s entry is %d bytes long\n",
952 _nc_first_name(qp->tterm.term_names),
958 /* write or dump all entries */
960 if (!infodump && !capdump) {
961 _nc_set_writedir(outdir);
963 if (matches(namelst, qp->tterm.term_names))
967 /* this is in case infotocap() generates warnings */
968 _nc_curr_col = _nc_curr_line = -1;
971 if (matches(namelst, qp->tterm.term_names)) {
972 long j = qp->cend - qp->cstart;
975 /* this is in case infotocap() generates warnings */
976 _nc_set_type(_nc_first_name(qp->tterm.term_names));
978 (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
981 (void) putchar(fgetc(tmp_fp));
983 put_translate(fgetc(tmp_fp));
986 repair_acsc(&qp->tterm);
987 dump_entry(&qp->tterm, suppress_untranslatable,
988 limited, numbers, NULL);
989 for (j = 0; j < (long) qp->nuses; j++)
990 dump_uses(qp->uses[j].name, !capdump);
992 if (debug_level != 0 && !limited)
993 printf("# length=%d\n", len);
996 if (!namelst && _nc_tail) {
998 bool in_comment = FALSE;
999 bool trailing_comment = FALSE;
1001 (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
1002 while ((c = fgetc(tmp_fp)) != EOF) {
1005 trailing_comment = TRUE;
1011 if (trailing_comment
1012 && (in_comment || (oldc == '\n' && c == '\n')))
1020 /* Show the directory into which entries were written, and the total
1024 && (!(check_only || infodump || capdump))) {
1025 int total = _nc_tic_written();
1027 fprintf(log_fp, "%d entries written to %s\n",
1029 _nc_tic_dir((char *) 0));
1031 fprintf(log_fp, "No entries written\n");
1033 ExitProgram(EXIT_SUCCESS);
1037 * This bit of legerdemain turns all the terminfo variable names into
1038 * references to locations in the arrays Booleans, Numbers, and Strings ---
1039 * precisely what's needed (see comp_parse.c).
1045 * Check if the alternate character-set capabilities are consistent.
1048 check_acs(TERMTYPE *tp)
1050 if (VALID_STRING(acs_chars)) {
1051 const char *boxes = "lmkjtuvwqxn";
1057 memset(mapped, 0, sizeof(mapped));
1058 for (p = acs_chars; *p != '\0'; p += 2) {
1060 _nc_warning("acsc has odd number of characters");
1063 mapped[UChar(p[0])] = p[1];
1066 if (mapped[UChar('I')] && !mapped[UChar('i')]) {
1067 _nc_warning("acsc refers to 'I', which is probably an error");
1070 for (p = boxes, q = missing; *p != '\0'; ++p) {
1071 if (!mapped[UChar(p[0])]) {
1077 assert(strlen(missing) <= strlen(boxes));
1078 if (*missing != '\0' && strcmp(missing, boxes)) {
1079 _nc_warning("acsc is missing some line-drawing mapping: %s", missing);
1085 * Check if the color capabilities are consistent
1088 check_colors(TERMTYPE *tp)
1090 if ((max_colors > 0) != (max_pairs > 0)
1091 || ((max_colors > max_pairs) && (initialize_pair == 0)))
1092 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
1093 max_colors, max_pairs);
1095 PAIRED(set_foreground, set_background);
1096 PAIRED(set_a_foreground, set_a_background);
1097 PAIRED(set_color_pair, initialize_pair);
1099 if (VALID_STRING(set_foreground)
1100 && VALID_STRING(set_a_foreground)
1101 && !_nc_capcmp(set_foreground, set_a_foreground))
1102 _nc_warning("expected setf/setaf to be different");
1104 if (VALID_STRING(set_background)
1105 && VALID_STRING(set_a_background)
1106 && !_nc_capcmp(set_background, set_a_background))
1107 _nc_warning("expected setb/setab to be different");
1109 /* see: has_colors() */
1110 if (VALID_NUMERIC(max_colors) && VALID_NUMERIC(max_pairs)
1111 && (((set_foreground != NULL)
1112 && (set_background != NULL))
1113 || ((set_a_foreground != NULL)
1114 && (set_a_background != NULL))
1115 || set_color_pair)) {
1116 if (!VALID_STRING(orig_pair) && !VALID_STRING(orig_colors))
1117 _nc_warning("expected either op/oc string for resetting colors");
1120 if (!VALID_STRING(initialize_pair) &&
1121 !VALID_STRING(initialize_color)) {
1122 _nc_warning("expected initc or initp because ccc is given");
1125 if (VALID_STRING(initialize_pair) ||
1126 VALID_STRING(initialize_color)) {
1127 _nc_warning("expected ccc because initc is given");
1133 keypad_final(const char *string)
1137 if (VALID_STRING(string)
1138 && *string++ == '\033'
1140 && strlen(string) == 1) {
1148 keypad_index(const char *string)
1151 const char *list = "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
1155 if ((ch = keypad_final(string)) != '\0') {
1156 test = (strchr) (list, ch);
1158 result = (long) (test - list);
1164 * list[] is down, up, left, right
1165 * "left" may be ^H rather than \E[D
1166 * "down" may be ^J rather than \E[B
1167 * But up/right are generally consistently escape sequences for ANSI terminals.
1170 check_ansi_cursor(char *list[4])
1177 bool repeated = FALSE;
1179 for (j = 0; j < 4; ++j) {
1181 for (k = 0; k < j; ++k) {
1183 && !strcmp(list[j], list[k])) {
1184 char *value = _nc_tic_expand(list[k], TRUE, 0);
1185 _nc_warning("repeated cursor control %s\n", value);
1193 if (UChar(up[0]) == '\033') {
1199 } else if (UChar(up[0]) == UChar('\233')) {
1204 while (up[suffix] && isdigit(UChar(up[suffix])))
1207 if (prefix && up[suffix] == 'A') {
1209 if (!strcmp(list[0], "\n"))
1211 if (!strcmp(list[2], "\b"))
1214 for (j = 0; j < 4; ++j) {
1215 if (skip[j] || strlen(list[j]) == 1)
1217 if (memcmp(list[j], up, prefix)) {
1218 char *value = _nc_tic_expand(list[j], TRUE, 0);
1219 _nc_warning("inconsistent prefix for %s\n", value);
1222 if (strlen(list[j]) < suffix) {
1223 char *value = _nc_tic_expand(list[j], TRUE, 0);
1224 _nc_warning("inconsistent length for %s, expected %d\n",
1225 value, (int) suffix + 1);
1229 if (list[j][suffix] != want) {
1230 char *value = _nc_tic_expand(list[j], TRUE, 0);
1231 _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
1232 value, want, list[j][suffix]);
1239 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
1240 #define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
1243 check_noaddress(TERMTYPE *tp, const char *why)
1245 UNEXPECTED(column_address);
1246 UNEXPECTED(cursor_address);
1247 UNEXPECTED(cursor_home);
1248 UNEXPECTED(cursor_mem_address);
1249 UNEXPECTED(cursor_to_ll);
1250 UNEXPECTED(row_address);
1251 UNEXPECTED(row_address);
1255 check_cursor(TERMTYPE *tp)
1261 check_noaddress(tp, "hard_copy");
1262 } else if (generic_type) {
1263 check_noaddress(tp, "generic_type");
1264 } else if (strchr(tp->term_names, '+') == 0) {
1267 if (PRESENT(column_address))
1269 if (PRESENT(cursor_address))
1271 if (PRESENT(cursor_home))
1273 if (PRESENT(cursor_mem_address))
1275 if (PRESENT(cursor_to_ll))
1277 if (PRESENT(row_address))
1279 if (PRESENT(cursor_down))
1281 if (PRESENT(cursor_up))
1283 if (PRESENT(cursor_left))
1285 if (PRESENT(cursor_right))
1287 if (x < 2 && y < 2) {
1288 _nc_warning("terminal lacks cursor addressing");
1291 _nc_warning("terminal lacks cursor column-addressing");
1293 _nc_warning("terminal lacks cursor row-addressing");
1297 /* it is rare to have an insert-line feature without a matching delete */
1298 ANDMISSING(parm_insert_line, insert_line);
1299 ANDMISSING(parm_delete_line, delete_line);
1300 ANDMISSING(parm_insert_line, parm_delete_line);
1302 /* if we have a parameterized form, then the non-parameterized is easy */
1303 ANDMISSING(parm_down_cursor, cursor_down);
1304 ANDMISSING(parm_up_cursor, cursor_up);
1305 ANDMISSING(parm_left_cursor, cursor_left);
1306 ANDMISSING(parm_right_cursor, cursor_right);
1308 /* Given any of a set of cursor movement, the whole set should be present.
1309 * Technically this is not true (we could use cursor_address to fill in
1310 * unsupported controls), but it is likely.
1313 if (PRESENT(parm_down_cursor)) {
1314 list[count++] = parm_down_cursor;
1316 if (PRESENT(parm_up_cursor)) {
1317 list[count++] = parm_up_cursor;
1319 if (PRESENT(parm_left_cursor)) {
1320 list[count++] = parm_left_cursor;
1322 if (PRESENT(parm_right_cursor)) {
1323 list[count++] = parm_right_cursor;
1326 check_ansi_cursor(list);
1327 } else if (count != 0) {
1328 EXPECTED(parm_down_cursor);
1329 EXPECTED(parm_up_cursor);
1330 EXPECTED(parm_left_cursor);
1331 EXPECTED(parm_right_cursor);
1335 if (PRESENT(cursor_down)) {
1336 list[count++] = cursor_down;
1338 if (PRESENT(cursor_up)) {
1339 list[count++] = cursor_up;
1341 if (PRESENT(cursor_left)) {
1342 list[count++] = cursor_left;
1344 if (PRESENT(cursor_right)) {
1345 list[count++] = cursor_right;
1348 check_ansi_cursor(list);
1349 } else if (count != 0) {
1351 if (PRESENT(cursor_down) && strcmp(cursor_down, "\n"))
1353 if (PRESENT(cursor_left) && strcmp(cursor_left, "\b"))
1355 if (PRESENT(cursor_up) && strlen(cursor_up) > 1)
1357 if (PRESENT(cursor_right) && strlen(cursor_right) > 1)
1360 EXPECTED(cursor_down);
1361 EXPECTED(cursor_up);
1362 EXPECTED(cursor_left);
1363 EXPECTED(cursor_right);
1370 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
1371 * is mapped inconsistently.
1374 check_keypad(TERMTYPE *tp)
1378 if (VALID_STRING(key_a1) &&
1379 VALID_STRING(key_a3) &&
1380 VALID_STRING(key_b2) &&
1381 VALID_STRING(key_c1) &&
1382 VALID_STRING(key_c3)) {
1383 char final[MAX_KP + 1];
1390 final[0] = keypad_final(key_a1);
1391 final[1] = keypad_final(key_a3);
1392 final[2] = keypad_final(key_b2);
1393 final[3] = keypad_final(key_c1);
1394 final[4] = keypad_final(key_c3);
1397 /* special case: legacy coding using 1,2,3,0,. on the bottom */
1398 assert(strlen(final) <= MAX_KP);
1399 if (!strcmp(final, "qsrpn"))
1402 list[0] = keypad_index(key_a1);
1403 list[1] = keypad_index(key_a3);
1404 list[2] = keypad_index(key_b2);
1405 list[3] = keypad_index(key_c1);
1406 list[4] = keypad_index(key_c3);
1408 /* check that they're all vt100 keys */
1409 for (j = 0; j < MAX_KP; ++j) {
1415 /* check if they're all in increasing order */
1416 for (j = 1; j < MAX_KP; ++j) {
1417 if (list[j] > list[j - 1]) {
1421 if (increase != (MAX_KP - 1)) {
1424 for (j = 0, last = -1; j < MAX_KP; ++j) {
1425 for (k = 0, kk = -1, test = 100; k < 5; ++k) {
1426 if (list[k] > last &&
1433 assert(strlen(show) < (MAX_KP * 4));
1436 _nc_STRCAT(show, " ka1", sizeof(show));
1439 _nc_STRCAT(show, " ka3", sizeof(show));
1442 _nc_STRCAT(show, " kb2", sizeof(show));
1445 _nc_STRCAT(show, " kc1", sizeof(show));
1448 _nc_STRCAT(show, " kc3", sizeof(show));
1453 _nc_warning("vt100 keypad order inconsistent: %s", show);
1456 } else if (VALID_STRING(key_a1) ||
1457 VALID_STRING(key_a3) ||
1458 VALID_STRING(key_b2) ||
1459 VALID_STRING(key_c1) ||
1460 VALID_STRING(key_c3)) {
1462 if (keypad_index(key_a1) >= 0)
1463 _nc_STRCAT(show, " ka1", sizeof(show));
1464 if (keypad_index(key_a3) >= 0)
1465 _nc_STRCAT(show, " ka3", sizeof(show));
1466 if (keypad_index(key_b2) >= 0)
1467 _nc_STRCAT(show, " kb2", sizeof(show));
1468 if (keypad_index(key_c1) >= 0)
1469 _nc_STRCAT(show, " kc1", sizeof(show));
1470 if (keypad_index(key_c3) >= 0)
1471 _nc_STRCAT(show, " kc3", sizeof(show));
1473 _nc_warning("vt100 keypad map incomplete:%s", show);
1477 * These warnings are useful for consistency checks - it is possible that
1478 * there are real terminals with mismatches in these
1480 ANDMISSING(key_ic, key_dc);
1484 check_printer(TERMTYPE *tp)
1486 PAIRED(enter_doublewide_mode, exit_doublewide_mode);
1487 PAIRED(enter_italics_mode, exit_italics_mode);
1488 PAIRED(enter_leftward_mode, exit_leftward_mode);
1489 PAIRED(enter_micro_mode, exit_micro_mode);
1490 PAIRED(enter_shadow_mode, exit_shadow_mode);
1491 PAIRED(enter_subscript_mode, exit_subscript_mode);
1492 PAIRED(enter_superscript_mode, exit_superscript_mode);
1493 PAIRED(enter_upward_mode, exit_upward_mode);
1495 ANDMISSING(start_char_set_def, stop_char_set_def);
1497 /* if we have a parameterized form, then the non-parameterized is easy */
1498 ANDMISSING(set_bottom_margin_parm, set_bottom_margin);
1499 ANDMISSING(set_left_margin_parm, set_left_margin);
1500 ANDMISSING(set_right_margin_parm, set_right_margin);
1501 ANDMISSING(set_top_margin_parm, set_top_margin);
1503 ANDMISSING(parm_down_micro, micro_down);
1504 ANDMISSING(parm_left_micro, micro_left);
1505 ANDMISSING(parm_right_micro, micro_right);
1506 ANDMISSING(parm_up_micro, micro_up);
1510 uses_SGR_39_49(const char *value)
1512 return (strstr(value, "39;49") != 0
1513 || strstr(value, "49;39") != 0);
1517 * Check consistency of termcap extensions related to "screen".
1520 check_screen(TERMTYPE *tp)
1523 if (_nc_user_definable) {
1524 int have_XT = tigetflag("XT");
1525 int have_XM = tigetflag("XM");
1526 int have_bce = back_color_erase;
1527 bool have_kmouse = FALSE;
1528 bool use_sgr_39_49 = FALSE;
1529 char *name = _nc_first_name(tp->term_names);
1531 if (!VALID_BOOLEAN(have_bce)) {
1534 if (!VALID_BOOLEAN(have_XM)) {
1537 if (!VALID_BOOLEAN(have_XT)) {
1540 if (VALID_STRING(key_mouse)) {
1541 have_kmouse = !strcmp("\033[M", key_mouse);
1543 if (VALID_STRING(orig_colors)) {
1544 use_sgr_39_49 = uses_SGR_39_49(orig_colors);
1545 } else if (VALID_STRING(orig_pair)) {
1546 use_sgr_39_49 = uses_SGR_39_49(orig_pair);
1549 if (have_XM && have_XT) {
1550 _nc_warning("Screen's XT capability conflicts with XM");
1552 && strstr(name, "screen") != 0
1553 && strchr(name, '.') != 0) {
1554 _nc_warning("Screen's \"screen\" entries should not have XT set");
1555 } else if (have_XT) {
1556 if (!have_kmouse && have_bce) {
1557 if (VALID_STRING(key_mouse)) {
1558 _nc_warning("Value of kmous inconsistent with screen's usage");
1560 _nc_warning("Expected kmous capability with XT");
1563 if (!have_bce && max_colors > 0)
1564 _nc_warning("Expected bce capability with XT");
1565 if (!use_sgr_39_49 && have_bce && max_colors > 0)
1566 _nc_warning("Expected orig_colors capability with XT to have 39/49 parameters");
1567 if (VALID_STRING(to_status_line))
1568 _nc_warning("\"tsl\" capability is redundant, given XT");
1570 if (have_kmouse && !have_XM)
1571 _nc_warning("Expected XT to be set, given kmous");
1578 * Returns the expected number of parameters for the given capability.
1581 expected_params(const char *name)
1584 static const struct {
1588 { "S0", 1 }, /* 'screen' extension */
1641 { "smgbp", 1 }, /* 2 if smgtp is not given */
1656 int result = 0; /* function-keys, etc., use none */
1658 for (n = 0; n < SIZEOF(table); n++) {
1659 if (!strcmp(name, table[n].name)) {
1660 result = table[n].count;
1669 * Make a quick sanity check for the parameters which are used in the given
1670 * strings. If there are no "%p" tokens, then there should be no other "%"
1674 check_params(TERMTYPE *tp, const char *name, char *value)
1676 int expected = expected_params(name);
1679 bool params[NUM_PARM];
1682 #ifdef set_top_margin_parm
1683 if (!strcmp(name, "smgbp")
1684 && set_top_margin_parm == 0)
1688 for (n = 0; n < NUM_PARM; n++)
1694 _nc_warning("expected character after %% in %s", name);
1696 } else if (*s == 'p') {
1697 if (*++s == '\0' || !isdigit((int) *s)) {
1698 _nc_warning("expected digit after %%p in %s", name);
1712 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
1714 if (value == set_attributes || expected < 0) {
1716 } else if (expected != actual) {
1717 _nc_warning("%s uses %d parameters, expected %d", name,
1719 for (n = 1; n < actual; n++) {
1721 _nc_warning("%s omits parameter %d", name, n);
1727 check_1_infotocap(const char *name, NCURSES_CONST char *value, int count)
1731 long numbers[1 + NUM_PARM];
1732 char *strings[1 + NUM_PARM];
1733 char *p_is_s[NUM_PARM];
1735 char blob[NUM_PARM * 10];
1739 for (k = 1; k <= NUM_PARM; k++) {
1741 sprintf(next, "XYZ%d", count);
1743 next += strlen(next) + 1;
1746 switch (tparm_type(name)) {
1748 result = TPARM_2(value, numbers[1], strings[2]);
1751 result = TPARM_3(value, numbers[1], strings[2], strings[3]);
1755 (void) _nc_tparm_analyze(value, p_is_s, &ignored);
1756 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
1757 result = TPARM_9(value,
1772 #define IsDelay(ch) ((ch) == '.' || isdigit(UChar(ch)))
1775 parse_delay_value(const char *src, double *delays, int *always)
1783 while (isdigit(UChar(*src))) {
1784 (*delays) = (*delays) * 10 + (*src++ - '0');
1790 while (isdigit(UChar(*src))) {
1792 (*delays) += (*src++ - '0') / gotdot;
1795 while (*src == '*' || *src == '/') {
1796 if (always == 0 && *src == '/')
1798 if (*src++ == '*') {
1805 *delays = -(*delays);
1810 parse_ti_delay(const char *ti, double *delays)
1813 while (*ti != '\0') {
1819 && IsDelay(UChar(ti[2]))) {
1821 const char *last = parse_delay_value(ti + 2, delays, &ignored);
1833 parse_tc_delay(const char *tc, double *delays)
1835 return parse_delay_value(tc, delays, (int *) 0);
1839 * Compare terminfo- and termcap-strings, factoring out delays.
1842 same_ti_tc(const char *ti, const char *tc, bool * embedded)
1845 double ti_delay = 0.0;
1846 double tc_delay = 0.0;
1847 const char *ti_last;
1850 ti_last = parse_ti_delay(ti, &ti_delay);
1851 tc = parse_tc_delay(tc, &tc_delay);
1853 while ((ti < ti_last) && *tc) {
1854 if (*ti == '\\' && ispunct(UChar(ti[1]))) {
1856 if ((*ti == '^') && !strncmp(tc, "\\136", 4)) {
1861 } else if (ti[0] == '$' && ti[1] == '<') {
1863 const char *ss = parse_ti_delay(ti, &no_delay);
1870 if (*tc == '\\' && ispunct(UChar(tc[1]))) {
1873 if (*ti++ != *tc++) {
1883 *embedded = FALSE; /* report only one problem */
1891 * Check terminfo to termcap translation.
1894 check_infotocap(TERMTYPE *tp, int i, const char *value)
1896 const char *name = ExtStrname(tp, i, strnames);
1897 int params = (((i < (int) SIZEOF(parametrized)) &&
1902 : has_params(value)));
1908 if ((ti_value = _nc_tic_expand(value, TRUE, to_char)) == ABSENT_STRING) {
1909 _nc_warning("tic-expansion of %s failed", name);
1910 } else if ((tc_value = _nc_infotocap(name, ti_value, params)) == ABSENT_STRING) {
1911 _nc_warning("tic-conversion of %s failed", name);
1912 } else if (params > 0) {
1917 if (!strcmp(name, "setf")
1918 || !strcmp(name, "setb")
1919 || !strcmp(name, "setaf")
1920 || !strcmp(name, "setab")) {
1923 for (count = 0; count < limit; ++count) {
1924 char *ti_check = check_1_infotocap(name, ti_value, count);
1925 char *tc_check = check_1_infotocap(name, tc_value, count);
1927 if (strcmp(ti_check, tc_check)) {
1929 fprintf(stderr, "check_infotocap(%s)\n", name);
1930 fprintf(stderr, "...ti '%s'\n", ti_value);
1931 fprintf(stderr, "...tc '%s'\n", tc_value);
1934 _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s",
1935 name, count, ti_check, tc_check);
1938 } else if (params == 0 && !same_ti_tc(ti_value, tc_value, &embedded)) {
1940 _nc_warning("termcap equivalent of %s cannot use embedded delay", name);
1942 _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s",
1943 name, ti_value, tc_value);
1951 while (*s == '/' || isdigit(UChar(*s)))
1957 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1958 * the latter may have a worst-case delay on the end.
1961 ignore_delays(char *s)
1994 * An sgr string may contain several settings other than the one we're
1995 * interested in, essentially sgr0 + rmacs + whatever. As long as the
1996 * "whatever" is contained in the sgr string, that is close enough for our
2000 similar_sgr(int num, char *a, char *b)
2002 static const char *names[] =
2024 _nc_warning("Did not find delay %s", _nc_visbuf(b));
2026 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
2027 names[num], _nc_visbuf2(1, base_a),
2028 _nc_visbuf2(2, base_b),
2032 } else if (delaying) {
2035 } else if ((*b == '0' || (*b == ';')) && *a == 'm') {
2057 /* ignore delays on the end of the string */
2058 a = ignore_delays(a);
2059 return ((num != 0) || (*a == 0));
2063 check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name)
2068 test = TPARM_9(set_attributes,
2080 if (!similar_sgr(num, test, cap)) {
2081 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
2083 name, _nc_visbuf2(1, cap),
2084 num, _nc_visbuf2(2, test));
2086 } else if (_nc_capcmp(test, zero)) {
2087 _nc_warning("sgr(%d) present, but not %s", num, name);
2089 } else if (PRESENT(cap)) {
2090 _nc_warning("sgr(%d) missing, but %s present", num, name);
2093 _nc_warning("stack error in sgr(%d) string", num);
2097 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
2101 * If tic is compiled with TRACE, we'll be able to see the output from the
2102 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
2103 * the standard error. Use this function to make it simpler to follow the
2104 * resulting debug traces.
2107 show_where(unsigned level)
2109 if (_nc_tracing >= DEBUG_LEVEL(level)) {
2110 char my_name[MAX_NAME_SIZE];
2111 _nc_get_type(my_name);
2112 _tracef("\"%s\", line %d, '%s'",
2114 _nc_curr_line, my_name);
2119 #define show_where(level) /* nothing */
2129 get_fkey_list(TERMTYPE *tp)
2131 NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1);
2132 const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys;
2137 failed("get_fkey_list");
2139 for (j = 0; all_fkeys[j].code; j++) {
2140 char *a = tp->Strings[all_fkeys[j].offset];
2141 if (VALID_STRING(a)) {
2142 result[used].keycode = (int) all_fkeys[j].code;
2143 result[used].name = strnames[all_fkeys[j].offset];
2144 result[used].value = a;
2149 for (j = STRCOUNT; j < NUM_STRINGS(tp); ++j) {
2150 const char *name = ExtStrname(tp, j, strnames);
2152 result[used].keycode = -1;
2153 result[used].name = name;
2154 result[used].value = tp->Strings[j];
2159 result[used].keycode = 0;
2164 show_fkey_name(NAME_VALUE * data)
2166 if (data->keycode > 0) {
2167 fprintf(stderr, " %s", keyname(data->keycode));
2168 fprintf(stderr, " (capability \"%s\")", data->name);
2170 fprintf(stderr, " capability \"%s\"", data->name);
2175 * A terminal entry may contain more than one keycode assigned to a given
2176 * string (e.g., KEY_END and KEY_LL). But curses will only return one (the
2177 * last one assigned).
2180 check_conflict(TERMTYPE *tp)
2182 bool conflict = FALSE;
2185 if (!(_nc_syntax == SYN_TERMCAP && capdump)) {
2186 char *check = calloc((size_t) (NUM_STRINGS(tp) + 1), sizeof(char));
2187 NAME_VALUE *given = get_fkey_list(tp);
2190 failed("check_termtype");
2192 for (j = 0; given[j].keycode; ++j) {
2193 const char *a = given[j].value;
2196 for (k = j + 1; given[k].keycode; k++) {
2197 const char *b = given[k].value;
2200 if (!_nc_capcmp(a, b)) {
2205 _nc_warning("Conflicting key definitions (using the last)");
2208 fprintf(stderr, "...");
2209 show_fkey_name(given + j);
2210 fprintf(stderr, " is the same as");
2211 show_fkey_name(given + k);
2214 fprintf(stderr, ", ");
2215 show_fkey_name(given + k);
2220 fprintf(stderr, "\n");
2227 /* other sanity-checks (things that we don't want in the normal
2228 * logic that reads a terminfo entry)
2231 check_termtype(TERMTYPE *tp, bool literal)
2237 for_each_string(j, tp) {
2238 char *a = tp->Strings[j];
2239 if (VALID_STRING(a)) {
2240 check_params(tp, ExtStrname(tp, (int) j, strnames), a);
2242 check_infotocap(tp, (int) j, a);
2255 * These may be mismatched because the terminal description relies on
2256 * restoring the cursor visibility by resetting it.
2258 ANDMISSING(cursor_invisible, cursor_normal);
2259 ANDMISSING(cursor_visible, cursor_normal);
2261 if (PRESENT(cursor_visible) && PRESENT(cursor_normal)
2262 && !_nc_capcmp(cursor_visible, cursor_normal))
2263 _nc_warning("cursor_visible is same as cursor_normal");
2266 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
2267 * given, because the cursor position after the scrolling operation is
2268 * performed is undefined.
2270 ANDMISSING(change_scroll_region, save_cursor);
2271 ANDMISSING(change_scroll_region, restore_cursor);
2274 * If we can clear tabs, we should be able to initialize them.
2276 ANDMISSING(clear_all_tabs, set_tab);
2278 if (PRESENT(set_attributes)) {
2282 if (PRESENT(exit_attribute_mode)) {
2283 zero = strdup(CHECK_SGR(0, exit_attribute_mode));
2285 zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0));
2288 _nc_warning("stack error in sgr(0) string");
2291 CHECK_SGR(1, enter_standout_mode);
2292 CHECK_SGR(2, enter_underline_mode);
2293 CHECK_SGR(3, enter_reverse_mode);
2294 CHECK_SGR(4, enter_blink_mode);
2295 CHECK_SGR(5, enter_dim_mode);
2296 CHECK_SGR(6, enter_bold_mode);
2297 CHECK_SGR(7, enter_secure_mode);
2298 CHECK_SGR(8, enter_protected_mode);
2299 CHECK_SGR(9, enter_alt_charset_mode);
2302 _nc_warning("sgr(0) did not return a value");
2304 } else if (PRESENT(exit_attribute_mode) &&
2305 set_attributes != CANCELLED_STRING) {
2306 if (_nc_syntax == SYN_TERMINFO)
2307 _nc_warning("missing sgr string");
2310 if (PRESENT(exit_attribute_mode)) {
2311 char *check_sgr0 = _nc_trim_sgr0(tp);
2313 if (check_sgr0 == 0 || *check_sgr0 == '\0') {
2314 _nc_warning("trimmed sgr0 is empty");
2317 if (check_sgr0 != exit_attribute_mode) {
2319 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
2320 _nc_visbuf2(1, exit_attribute_mode),
2321 _nc_visbuf2(2, check_sgr0)));
2325 ("will not trim sgr0\n\toriginal sgr0=%s",
2326 _nc_visbuf(exit_attribute_mode)));
2332 if (!auto_right_margin) {
2334 ("can write to lower-right directly"));
2335 } else if (PRESENT(enter_am_mode) && PRESENT(exit_am_mode)) {
2337 ("can write to lower-right by suppressing automargin"));
2338 } else if ((PRESENT(enter_insert_mode) && PRESENT(exit_insert_mode))
2339 || PRESENT(insert_character) || PRESENT(parm_ich)) {
2341 ("can write to lower-right by using inserts"));
2344 ("cannot write to lower-right"));
2349 * Some standard applications (e.g., vi) and some non-curses
2350 * applications (e.g., jove) get confused if we have both ich1 and
2351 * smir/rmir. Let's be nice and warn about that, too, even though
2352 * ncurses handles it.
2354 if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
2355 && PRESENT(parm_ich)) {
2356 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
2360 * Finally, do the non-verbose checks
2362 if (save_check_termtype != 0)
2363 save_check_termtype(tp, literal);