1 /****************************************************************************
2 * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996 on *
33 ****************************************************************************/
36 * tic.c --- Main program for terminfo compiler
42 #include <progs.priv.h>
45 #include <dump_entry.h>
46 #include <tparm_type.h>
47 #include <hashed_db.h>
48 #include <parametrized.h>
49 #include <transform.h>
51 MODULE_ID("$Id: tic.c,v 1.221 2016/01/02 20:04:37 tom Exp $")
53 #define STDIN_NAME "<stdin>"
55 const char *_nc_progname
= "tic";
59 static bool capdump
= FALSE
; /* running as infotocap? */
60 static bool infodump
= FALSE
; /* running as captoinfo? */
61 static bool showsummary
= FALSE
;
62 static char **namelst
= 0;
63 static const char *to_remove
;
65 static void (*save_check_termtype
) (TERMTYPE
*, bool);
66 static void check_termtype(TERMTYPE
*tt
, bool);
68 static const char usage_string
[] = "\
99 free_namelist(char **src
)
103 for (n
= 0; src
[n
] != 0; ++n
)
116 free_namelist(namelst
);
120 if (to_remove
!= 0) {
122 rc
= remove(to_remove
);
124 rc
= unlink(to_remove
);
132 failed(const char *msg
)
135 ExitProgram(EXIT_FAILURE
);
141 #define DATA(s) s "\n"
142 static const char options_string
[] =
145 DATA(" -0 format translation output all capabilities on one line")
146 DATA(" -1 format translation output one capability per line")
148 DATA(" -a retain commented-out capabilities (sets -x also)")
150 DATA(" -C translate entries to termcap source form")
151 DATA(" -D print list of tic's database locations (first must be writable)")
152 DATA(" -c check only, validate input without compiling or translating")
153 DATA(" -e<names> translate/compile only entries named by comma-separated list")
154 DATA(" -f format complex strings for readability")
155 DATA(" -G format %{number} to %'char'")
156 DATA(" -g format %'char' to %{number}")
157 DATA(" -I translate entries to terminfo source form")
158 DATA(" -K translate entries to termcap source form with BSD syntax")
159 DATA(" -L translate entries to full terminfo source form")
160 DATA(" -N disable smart defaults for source translation")
161 DATA(" -o<dir> set output directory for compiled entry writes")
162 DATA(" -Q[n] dump compiled description")
163 DATA(" -q brief listing, removes headers")
164 DATA(" -R<name> restrict translation to given terminfo/termcap version")
165 DATA(" -r force resolution of all use entries in source translation")
166 DATA(" -s print summary statistics")
167 DATA(" -T remove size-restrictions on compiled description")
169 DATA(" -t suppress commented-out capabilities")
171 DATA(" -U suppress post-processing of entries")
172 DATA(" -V print version")
173 DATA(" -v[n] set verbosity level")
174 DATA(" -w[n] set format width for translation output")
176 DATA(" -x treat unknown capabilities as user-defined")
180 DATA(" <file> file to translate or compile")
184 fprintf(stderr
, "Usage: %s %s\n", _nc_progname
, usage_string
);
185 fputs(options_string
, stderr
);
186 ExitProgram(EXIT_FAILURE
);
199 char result
[MAX_ENTRY_SIZE
];
202 * Look for strings that contain %{number}, convert them to %'char',
203 * which is shorter and runs a little faster.
205 for (n
= 0; n
< STRCOUNT
; n
++) {
206 s
= ep
->tterm
.Strings
[n
];
208 && strchr(s
, L_BRACE
) != 0) {
211 while ((ch
= *t
++) != 0) {
215 } else if ((ch
== '%')
216 && (*t
== L_BRACE
)) {
218 long value
= strtol(t
+ 1, &v
, 0);
222 && value
!= '\\' /* FIXME */
224 && isprint((int) value
)) {
233 if (strlen(result
) < strlen(s
))
234 _nc_STRCPY(s
, result
, strlen(s
) + 1);
238 _nc_set_type(_nc_first_name(ep
->tterm
.term_names
));
239 _nc_curr_line
= (int) ep
->startline
;
240 _nc_write_entry(&ep
->tterm
);
244 immedhook(ENTRY
* ep GCC_UNUSED
)
245 /* write out entries with no use capabilities immediately to save storage */
249 * This is strictly a core-economy kluge. The really clean way to handle
250 * compilation is to slurp the whole file into core and then do all the
251 * name-collision checks and entry writes in one swell foop. But the
252 * terminfo master file is large enough that some core-poor systems swap
253 * like crazy when you compile it this way...there have been reports of
254 * this process taking *three hours*, rather than the twenty seconds or
255 * less typical on my development box.
257 * So. This hook *immediately* writes out the referenced entry if it
258 * has no use capabilities. The compiler main loop refrains from
259 * adding the entry to the in-core list when this hook fires. If some
260 * other entry later needs to reference an entry that got written
261 * immediately, that's OK; the resolution code will fetch it off disk
262 * when it can't find it in core.
264 * Name collisions will still be detected, just not as cleanly. The
265 * write_entry() code complains before overwriting an entry that
266 * postdates the time of tic's first call to write_entry(). Thus
267 * it will complain about overwriting entries newly made during the
268 * tic run, but not about overwriting ones that predate it.
270 * The reason this is a hook, and not in line with the rest of the
271 * compiler code, is that the support for termcap fallback cannot assume
272 * it has anywhere to spool out these entries!
274 * The _nc_set_type() call here requires a compensating one in
277 * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
278 * make tic a bit faster (because the resolution code won't have to do
279 * disk I/O nearly as often).
281 if (ep
->nuses
== 0) {
282 int oldline
= _nc_curr_line
;
285 _nc_curr_line
= oldline
;
286 free(ep
->tterm
.str_table
);
289 #endif /* HAVE_BIG_CORE */
295 /* emit a comment char, translating terminfo names to termcap names */
297 static bool in_name
= FALSE
;
298 static size_t have
, used
;
299 static char *namebuf
, *suffix
;
302 if (used
+ 1 >= have
) {
304 if ((namebuf
= typeRealloc(char, have
, namebuf
)) == 0)
305 failed("put_translate namebuf");
306 if ((suffix
= typeRealloc(char, have
, suffix
)) == 0)
307 failed("put_translate suffix");
309 if (c
== '\n' || c
== '@') {
310 namebuf
[used
++] = '\0';
312 (void) fputs(namebuf
, stdout
);
315 } else if (c
!= '>') {
316 namebuf
[used
++] = (char) c
;
317 } else { /* ah! candidate name! */
319 NCURSES_CONST
char *tp
;
321 namebuf
[used
++] = '\0';
325 if ((up
= strchr(namebuf
, '#')) != 0
326 || (up
= strchr(namebuf
, '=')) != 0
327 || ((up
= strchr(namebuf
, '@')) != 0 && up
[1] == '>')) {
328 _nc_STRCPY(suffix
, up
, have
);
332 if ((tp
= nametrans(namebuf
)) != 0) {
334 (void) fputs(tp
, stdout
);
335 (void) fputs(suffix
, stdout
);
338 /* couldn't find a translation, just dump the name */
340 (void) fputs(namebuf
, stdout
);
341 (void) fputs(suffix
, stdout
);
355 /* Returns a string, stripped of leading/trailing whitespace */
361 while (isspace(UChar(*src
)))
367 if ((dst
= strdup(src
)) == NULL
) {
371 while (--len
!= 0 && isspace(UChar(dst
[len
])))
379 open_tempfile(char *filename
)
383 _nc_STRCPY(filename
, "/tmp/XXXXXX", PATH_MAX
);
386 int oldmask
= (int) umask(077);
387 int fd
= mkstemp(filename
);
389 result
= fdopen(fd
, "w");
390 umask((mode_t
) oldmask
);
393 if (tmpnam(filename
) != 0)
394 result
= fopen(filename
, "w");
400 copy_input(FILE *source
, const char *filename
, char *alt_file
)
402 char my_altfile
[PATH_MAX
];
408 alt_file
= my_altfile
;
411 failed("copy_input (source)");
412 } else if ((target
= open_tempfile(alt_file
)) == 0) {
413 failed("copy_input (target)");
420 } else if (ferror(source
)) {
422 } else if (ch
== 0) {
423 /* don't loop in case someone wants to convert /dev/zero */
424 fprintf(stderr
, "%s: %s is not a text-file\n", _nc_progname
, filename
);
425 ExitProgram(EXIT_FAILURE
);
431 * rewind() does not force the target file's data to disk (not does
432 * fflush()...). So open a second stream on the data and then close
433 * the one that we were writing on before starting to read from the
436 result
= fopen(alt_file
, "r+");
438 to_remove
= strdup(alt_file
);
444 open_input(const char *filename
, char *alt_file
)
450 if (!strcmp(filename
, "-")) {
451 fp
= copy_input(stdin
, STDIN_NAME
, alt_file
);
452 } else if (stat(filename
, &sb
) < 0) {
453 fprintf(stderr
, "%s: %s %s\n", _nc_progname
, filename
, strerror(errno
));
454 ExitProgram(EXIT_FAILURE
);
455 } else if ((mode
= (sb
.st_mode
& S_IFMT
)) == S_IFDIR
456 || (mode
!= S_IFREG
&& mode
!= S_IFCHR
&& mode
!= S_IFIFO
)) {
457 fprintf(stderr
, "%s: %s is not a file\n", _nc_progname
, filename
);
458 ExitProgram(EXIT_FAILURE
);
460 fp
= fopen(filename
, "r");
463 fprintf(stderr
, "%s: Can't open %s\n", _nc_progname
, filename
);
464 ExitProgram(EXIT_FAILURE
);
466 if (mode
!= S_IFREG
) {
468 FILE *fp2
= copy_input(fp
, filename
, alt_file
);
471 fprintf(stderr
, "%s: %s is not a file\n", _nc_progname
, filename
);
472 ExitProgram(EXIT_FAILURE
);
479 /* Parse the "-e" option-value into a list of names */
481 make_namelist(char *src
)
486 unsigned pass
, n
, nn
;
491 } else if (strchr(src
, '/') != 0) { /* a filename */
492 FILE *fp
= open_input(src
, (char *) 0);
494 for (pass
= 1; pass
<= 2; pass
++) {
496 while (fgets(buffer
, sizeof(buffer
), fp
) != 0) {
497 if ((s
= stripped(buffer
)) != 0) {
506 if ((dst
= typeCalloc(char *, nn
+ 1)) == 0)
507 failed("make_namelist");
512 } else { /* literal list of names */
513 for (pass
= 1; pass
<= 2; pass
++) {
514 for (n
= nn
= 0, base
= src
;; n
++) {
516 if (mark
== ',' || mark
== '\0') {
521 if ((s
= stripped(base
)) != 0)
530 if ((dst
= typeCalloc(char *, nn
+ 1)) == 0)
531 failed("make_namelist");
535 if (showsummary
&& (dst
!= 0)) {
536 fprintf(log_fp
, "Entries that will be compiled:\n");
537 for (n
= 0; dst
[n
] != 0; n
++)
538 fprintf(log_fp
, "%u:%s\n", n
+ 1, dst
[n
]);
544 matches(char **needle
, const char *haystack
)
545 /* does entry in needle list match |-separated field in haystack? */
551 for (n
= 0; needle
[n
] != 0; n
++) {
552 if (_nc_name_match(haystack
, needle
[n
], "|")) {
563 valid_db_path(const char *nominal
)
567 char suffix
[] = DBM_SUFFIX
;
568 size_t need
= strlen(nominal
) + sizeof(suffix
);
569 char *result
= malloc(need
);
572 failed("valid_db_path");
573 _nc_STRCPY(result
, nominal
, need
);
574 if (strcmp(result
+ need
- sizeof(suffix
), suffix
)) {
575 _nc_STRCAT(result
, suffix
, need
);
578 char *result
= strdup(nominal
);
581 DEBUG(1, ("** stat(%s)", result
));
582 if (stat(result
, &sb
) >= 0) {
584 if (!S_ISREG(sb
.st_mode
)
585 || access(result
, R_OK
| W_OK
) != 0) {
586 DEBUG(1, ("...not a writable file"));
591 if (!S_ISDIR(sb
.st_mode
)
592 || access(result
, R_OK
| W_OK
| X_OK
) != 0) {
593 DEBUG(1, ("...not a writable directory"));
599 /* check if parent is directory and is writable */
600 unsigned leaf
= _nc_pathlast(result
);
602 DEBUG(1, ("...not found"));
604 char save
= result
[leaf
];
606 if (stat(result
, &sb
) >= 0
607 && S_ISDIR(sb
.st_mode
)
608 && access(result
, R_OK
| W_OK
| X_OK
) == 0) {
611 DEBUG(1, ("...parent directory %s is not writable", result
));
616 DEBUG(1, ("... no parent directory"));
625 * Show the databases to which tic could write. The location to which it
626 * writes is always the first one. If none are writable, print an error
630 show_databases(const char *outdir
)
632 bool specific
= (outdir
!= 0) || getenv("TERMINFO") != 0;
634 const char *tried
= 0;
637 outdir
= _nc_tic_dir(0);
639 if ((result
= valid_db_path(outdir
)) != 0) {
640 printf("%s\n", result
);
646 if ((outdir
= _nc_home_terminfo())) {
647 if ((result
= valid_db_path(outdir
)) != 0) {
648 printf("%s\n", result
);
650 } else if (!specific
) {
656 * If we can write in neither location, give an error message.
660 fprintf(stderr
, "%s: %s (no permission)\n", _nc_progname
, tried
);
661 ExitProgram(EXIT_FAILURE
);
666 add_digit(int *target
, int source
)
668 *target
= (*target
* 10) + (source
- '0');
671 #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
674 main(int argc
, char *argv
[])
676 char my_tmpname
[PATH_MAX
];
677 char my_altfile
[PATH_MAX
];
679 unsigned debug_level
;
680 int smart_defaults
= TRUE
;
684 int this_opt
, last_opt
= '?';
686 int outform
= F_TERMINFO
; /* output format */
687 int sortmode
= S_TERMINFO
; /* sort_mode */
691 bool formatted
= FALSE
; /* reformat complex strings? */
692 bool literal
= FALSE
; /* suppress post-processing? */
693 int numbers
= 0; /* format "%'char'" to/from "%{number}" */
694 bool forceresolve
= FALSE
; /* force resolution */
696 char *tversion
= (char *) NULL
;
697 const char *source_file
= "terminfo";
698 char *outdir
= (char *) NULL
;
699 bool check_only
= FALSE
;
700 bool suppress_untranslatable
= FALSE
;
706 _nc_progname
= _nc_rootname(argv
[0]);
709 if ((infodump
= same_program(_nc_progname
, PROG_CAPTOINFO
)) != FALSE
) {
710 outform
= F_TERMINFO
;
711 sortmode
= S_TERMINFO
;
713 if ((capdump
= same_program(_nc_progname
, PROG_INFOTOCAP
)) != FALSE
) {
715 sortmode
= S_TERMCAP
;
718 use_extended_names(FALSE
);
723 * Processing arguments is a little complicated, since someone made a
724 * design decision to allow the numeric values for -w, -v options to
727 while ((this_opt
= getopt(argc
, argv
,
728 "0123456789CDIKLNQR:TUVace:fGgo:qrstvwx")) != -1) {
729 if (isdigit(this_opt
)) {
732 add_digit(&quickdump
, this_opt
);
735 add_digit(&v_opt
, this_opt
);
738 add_digit(&width
, this_opt
);
760 /* the initial version of -K in 20110730 fell-thru here, but the
761 * same flag is useful when reading sources -TD
767 sortmode
= S_TERMCAP
;
770 debug_level
= VtoTrace(v_opt
);
771 set_trace_level(debug_level
);
772 show_databases(outdir
);
773 ExitProgram(EXIT_SUCCESS
);
777 outform
= F_TERMINFO
;
778 sortmode
= S_TERMINFO
;
782 outform
= F_VARIABLE
;
783 sortmode
= S_VARIABLE
;
786 smart_defaults
= FALSE
;
802 puts(curses_version());
803 ExitProgram(EXIT_SUCCESS
);
808 namelst
= make_namelist(optarg
);
839 _nc_disable_period
= FALSE
;
840 suppress_untranslatable
= TRUE
;
843 _nc_disable_period
= TRUE
;
846 use_extended_names(TRUE
);
855 debug_level
= VtoTrace(v_opt
);
856 set_trace_level(debug_level
);
859 save_check_termtype
= _nc_check_termtype2
;
860 _nc_check_termtype2
= check_termtype
;
864 * Aaargh! immedhook seriously hoses us!
866 * One problem with immedhook is it means we can't do -e. Problem
867 * is that we can't guarantee that for each terminal listed, all the
868 * terminals it depends on will have been kept in core for reference
869 * resolution -- in fact it's certain the primitive types at the end
870 * of reference chains *won't* be in core unless they were explicitly
871 * in the select list themselves.
873 if (namelst
&& (!infodump
&& !capdump
)) {
874 (void) fprintf(stderr
,
875 "%s: Sorry, -e can't be used without -I or -C\n",
877 ExitProgram(EXIT_FAILURE
);
879 #endif /* HAVE_BIG_CORE */
882 source_file
= argv
[optind
++];
885 "%s: Too many file names. Usage:\n\t%s %s",
889 ExitProgram(EXIT_FAILURE
);
892 if (infodump
== TRUE
) {
893 /* captoinfo's no-argument case */
894 source_file
= "/etc/termcap";
895 if ((termcap
= getenv("TERMCAP")) != 0
896 && (namelst
= make_namelist(getenv("TERM"))) != 0) {
897 if (access(termcap
, F_OK
) == 0) {
899 source_file
= termcap
;
901 if ((tmp_fp
= open_tempfile(my_tmpname
)) != 0) {
902 source_file
= my_tmpname
;
903 fprintf(tmp_fp
, "%s\n", termcap
);
905 tmp_fp
= open_input(source_file
, (char *) 0);
906 to_remove
= source_file
;
915 "%s: File name needed. Usage:\n\t%s %s",
919 ExitProgram(EXIT_FAILURE
);
924 tmp_fp
= open_input(source_file
, my_altfile
);
925 if (!strcmp(source_file
, "-")) {
926 source_file
= STDIN_NAME
;
930 if (infodump
|| check_only
) {
935 sortmode
, width
, height
, debug_level
, formatted
||
936 check_only
, check_only
, quickdump
);
937 } else if (capdump
) {
940 sortmode
, width
, height
, debug_level
, FALSE
, FALSE
, FALSE
);
943 /* parse entries out of the source file */
944 _nc_set_source(source_file
);
946 if (!(check_only
|| infodump
|| capdump
))
947 _nc_set_writedir(outdir
);
948 #endif /* HAVE_BIG_CORE */
949 _nc_read_entry_source(tmp_fp
, (char *) NULL
,
950 !smart_defaults
|| literal
, FALSE
,
951 ((check_only
|| infodump
|| capdump
)
955 /* do use resolution */
956 if (check_only
|| (!infodump
&& !capdump
) || forceresolve
) {
957 if (!_nc_resolve_uses2(TRUE
, literal
) && !check_only
) {
958 ExitProgram(EXIT_FAILURE
);
963 if (check_only
&& limited
&& (capdump
|| infodump
)) {
965 if (matches(namelst
, qp
->tterm
.term_names
)) {
966 int len
= fmt_entry(&qp
->tterm
, NULL
, FALSE
, TRUE
, infodump
, numbers
);
968 if (len
> (infodump
? MAX_TERMINFO_LENGTH
: MAX_TERMCAP_LENGTH
))
969 (void) fprintf(stderr
,
970 "warning: resolved %s entry is %d bytes long\n",
971 _nc_first_name(qp
->tterm
.term_names
),
977 /* write or dump all entries */
979 /* this is in case infotocap() generates warnings */
980 _nc_curr_col
= _nc_curr_line
= -1;
983 if (matches(namelst
, qp
->tterm
.term_names
)) {
984 /* this is in case infotocap() generates warnings */
985 _nc_set_type(_nc_first_name(qp
->tterm
.term_names
));
986 _nc_curr_line
= (int) qp
->startline
;
987 repair_acsc(&qp
->tterm
);
988 dump_entry(&qp
->tterm
, suppress_untranslatable
,
989 limited
, numbers
, NULL
);
993 if (!infodump
&& !capdump
) {
994 _nc_set_writedir(outdir
);
996 if (matches(namelst
, qp
->tterm
.term_names
))
1000 /* this is in case infotocap() generates warnings */
1001 _nc_curr_col
= _nc_curr_line
= -1;
1003 for_entry_list(qp
) {
1004 if (matches(namelst
, qp
->tterm
.term_names
)) {
1005 long j
= qp
->cend
- qp
->cstart
;
1008 /* this is in case infotocap() generates warnings */
1009 _nc_set_type(_nc_first_name(qp
->tterm
.term_names
));
1012 (void) fseek(tmp_fp
, qp
->cstart
, SEEK_SET
);
1015 (void) putchar(fgetc(tmp_fp
));
1017 put_translate(fgetc(tmp_fp
));
1021 repair_acsc(&qp
->tterm
);
1022 dump_entry(&qp
->tterm
, suppress_untranslatable
,
1023 limited
, numbers
, NULL
);
1024 for (j
= 0; j
< (long) qp
->nuses
; j
++)
1025 dump_uses(qp
->uses
[j
].name
, !capdump
);
1027 if (debug_level
!= 0 && !limited
)
1028 printf("# length=%d\n", len
);
1031 if (!namelst
&& _nc_tail
&& !quiet
) {
1033 bool in_comment
= FALSE
;
1034 bool trailing_comment
= FALSE
;
1036 (void) fseek(tmp_fp
, _nc_tail
->cend
, SEEK_SET
);
1037 while ((c
= fgetc(tmp_fp
)) != EOF
) {
1040 trailing_comment
= TRUE
;
1046 if (trailing_comment
1047 && (in_comment
|| (oldc
== '\n' && c
== '\n')))
1055 /* Show the directory into which entries were written, and the total
1059 && (!(check_only
|| infodump
|| capdump
))) {
1060 int total
= _nc_tic_written();
1062 fprintf(log_fp
, "%d entries written to %s\n",
1064 _nc_tic_dir((char *) 0));
1066 fprintf(log_fp
, "No entries written\n");
1068 ExitProgram(EXIT_SUCCESS
);
1072 * This bit of legerdemain turns all the terminfo variable names into
1073 * references to locations in the arrays Booleans, Numbers, and Strings ---
1074 * precisely what's needed (see comp_parse.c).
1080 * Check if the alternate character-set capabilities are consistent.
1083 check_acs(TERMTYPE
*tp
)
1085 if (VALID_STRING(acs_chars
)) {
1086 const char *boxes
= "lmkjtuvwqxn";
1092 memset(mapped
, 0, sizeof(mapped
));
1093 for (p
= acs_chars
; *p
!= '\0'; p
+= 2) {
1095 _nc_warning("acsc has odd number of characters");
1098 mapped
[UChar(p
[0])] = p
[1];
1101 if (mapped
[UChar('I')] && !mapped
[UChar('i')]) {
1102 _nc_warning("acsc refers to 'I', which is probably an error");
1105 for (p
= boxes
, q
= missing
; *p
!= '\0'; ++p
) {
1106 if (!mapped
[UChar(p
[0])]) {
1112 assert(strlen(missing
) <= strlen(boxes
));
1113 if (*missing
!= '\0' && strcmp(missing
, boxes
)) {
1114 _nc_warning("acsc is missing some line-drawing mapping: %s", missing
);
1120 * Check if the color capabilities are consistent
1123 check_colors(TERMTYPE
*tp
)
1125 if ((max_colors
> 0) != (max_pairs
> 0)
1126 || ((max_colors
> max_pairs
) && (initialize_pair
== 0)))
1127 _nc_warning("inconsistent values for max_colors (%d) and max_pairs (%d)",
1128 max_colors
, max_pairs
);
1130 PAIRED(set_foreground
, set_background
);
1131 PAIRED(set_a_foreground
, set_a_background
);
1132 PAIRED(set_color_pair
, initialize_pair
);
1134 if (VALID_STRING(set_foreground
)
1135 && VALID_STRING(set_a_foreground
)
1136 && !_nc_capcmp(set_foreground
, set_a_foreground
))
1137 _nc_warning("expected setf/setaf to be different");
1139 if (VALID_STRING(set_background
)
1140 && VALID_STRING(set_a_background
)
1141 && !_nc_capcmp(set_background
, set_a_background
))
1142 _nc_warning("expected setb/setab to be different");
1144 /* see: has_colors() */
1145 if (VALID_NUMERIC(max_colors
) && VALID_NUMERIC(max_pairs
)
1146 && (((set_foreground
!= NULL
)
1147 && (set_background
!= NULL
))
1148 || ((set_a_foreground
!= NULL
)
1149 && (set_a_background
!= NULL
))
1150 || set_color_pair
)) {
1151 if (!VALID_STRING(orig_pair
) && !VALID_STRING(orig_colors
))
1152 _nc_warning("expected either op/oc string for resetting colors");
1155 if (!VALID_STRING(initialize_pair
) &&
1156 !VALID_STRING(initialize_color
)) {
1157 _nc_warning("expected initc or initp because ccc is given");
1160 if (VALID_STRING(initialize_pair
) ||
1161 VALID_STRING(initialize_color
)) {
1162 _nc_warning("expected ccc because initc is given");
1168 keypad_final(const char *string
)
1172 if (VALID_STRING(string
)
1173 && *string
++ == '\033'
1175 && strlen(string
) == 1) {
1183 keypad_index(const char *string
)
1186 const char *list
= "PQRSwxymtuvlqrsPpn"; /* app-keypad except "Enter" */
1190 if ((ch
= keypad_final(string
)) != '\0') {
1191 test
= (strchr
) (list
, ch
);
1193 result
= (long) (test
- list
);
1199 * list[] is down, up, left, right
1200 * "left" may be ^H rather than \E[D
1201 * "down" may be ^J rather than \E[B
1202 * But up/right are generally consistently escape sequences for ANSI terminals.
1205 check_ansi_cursor(char *list
[4])
1212 bool repeated
= FALSE
;
1214 for (j
= 0; j
< 4; ++j
) {
1216 for (k
= 0; k
< j
; ++k
) {
1218 && !strcmp(list
[j
], list
[k
])) {
1219 char *value
= _nc_tic_expand(list
[k
], TRUE
, 0);
1220 _nc_warning("repeated cursor control %s\n", value
);
1228 if (UChar(up
[0]) == '\033') {
1234 } else if (UChar(up
[0]) == UChar('\233')) {
1239 while (up
[suffix
] && isdigit(UChar(up
[suffix
])))
1242 if (prefix
&& up
[suffix
] == 'A') {
1244 if (!strcmp(list
[0], "\n"))
1246 if (!strcmp(list
[2], "\b"))
1249 for (j
= 0; j
< 4; ++j
) {
1250 if (skip
[j
] || strlen(list
[j
]) == 1)
1252 if (memcmp(list
[j
], up
, prefix
)) {
1253 char *value
= _nc_tic_expand(list
[j
], TRUE
, 0);
1254 _nc_warning("inconsistent prefix for %s\n", value
);
1257 if (strlen(list
[j
]) < suffix
) {
1258 char *value
= _nc_tic_expand(list
[j
], TRUE
, 0);
1259 _nc_warning("inconsistent length for %s, expected %d\n",
1260 value
, (int) suffix
+ 1);
1264 if (list
[j
][suffix
] != want
) {
1265 char *value
= _nc_tic_expand(list
[j
], TRUE
, 0);
1266 _nc_warning("inconsistent suffix for %s, expected %c, have %c\n",
1267 value
, want
, list
[j
][suffix
]);
1274 #define EXPECTED(name) if (!PRESENT(name)) _nc_warning("expected " #name)
1275 #define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why)
1278 check_noaddress(TERMTYPE
*tp
, const char *why
)
1280 UNEXPECTED(column_address
);
1281 UNEXPECTED(cursor_address
);
1282 UNEXPECTED(cursor_home
);
1283 UNEXPECTED(cursor_mem_address
);
1284 UNEXPECTED(cursor_to_ll
);
1285 UNEXPECTED(row_address
);
1286 UNEXPECTED(row_address
);
1290 check_cursor(TERMTYPE
*tp
)
1296 check_noaddress(tp
, "hard_copy");
1297 } else if (generic_type
) {
1298 check_noaddress(tp
, "generic_type");
1299 } else if (strchr(tp
->term_names
, '+') == 0) {
1302 if (PRESENT(column_address
))
1304 if (PRESENT(cursor_address
))
1306 if (PRESENT(cursor_home
))
1308 if (PRESENT(cursor_mem_address
))
1310 if (PRESENT(cursor_to_ll
))
1312 if (PRESENT(row_address
))
1314 if (PRESENT(cursor_down
))
1316 if (PRESENT(cursor_up
))
1318 if (PRESENT(cursor_left
))
1320 if (PRESENT(cursor_right
))
1322 if (x
< 2 && y
< 2) {
1323 _nc_warning("terminal lacks cursor addressing");
1326 _nc_warning("terminal lacks cursor column-addressing");
1328 _nc_warning("terminal lacks cursor row-addressing");
1332 /* it is rare to have an insert-line feature without a matching delete */
1333 ANDMISSING(parm_insert_line
, insert_line
);
1334 ANDMISSING(parm_delete_line
, delete_line
);
1335 ANDMISSING(parm_insert_line
, parm_delete_line
);
1337 /* if we have a parameterized form, then the non-parameterized is easy */
1338 ANDMISSING(parm_down_cursor
, cursor_down
);
1339 ANDMISSING(parm_up_cursor
, cursor_up
);
1340 ANDMISSING(parm_left_cursor
, cursor_left
);
1341 ANDMISSING(parm_right_cursor
, cursor_right
);
1343 /* Given any of a set of cursor movement, the whole set should be present.
1344 * Technically this is not true (we could use cursor_address to fill in
1345 * unsupported controls), but it is likely.
1348 if (PRESENT(parm_down_cursor
)) {
1349 list
[count
++] = parm_down_cursor
;
1351 if (PRESENT(parm_up_cursor
)) {
1352 list
[count
++] = parm_up_cursor
;
1354 if (PRESENT(parm_left_cursor
)) {
1355 list
[count
++] = parm_left_cursor
;
1357 if (PRESENT(parm_right_cursor
)) {
1358 list
[count
++] = parm_right_cursor
;
1361 check_ansi_cursor(list
);
1362 } else if (count
!= 0) {
1363 EXPECTED(parm_down_cursor
);
1364 EXPECTED(parm_up_cursor
);
1365 EXPECTED(parm_left_cursor
);
1366 EXPECTED(parm_right_cursor
);
1370 if (PRESENT(cursor_down
)) {
1371 list
[count
++] = cursor_down
;
1373 if (PRESENT(cursor_up
)) {
1374 list
[count
++] = cursor_up
;
1376 if (PRESENT(cursor_left
)) {
1377 list
[count
++] = cursor_left
;
1379 if (PRESENT(cursor_right
)) {
1380 list
[count
++] = cursor_right
;
1383 check_ansi_cursor(list
);
1384 } else if (count
!= 0) {
1386 if (PRESENT(cursor_down
) && strcmp(cursor_down
, "\n"))
1388 if (PRESENT(cursor_left
) && strcmp(cursor_left
, "\b"))
1390 if (PRESENT(cursor_up
) && strlen(cursor_up
) > 1)
1392 if (PRESENT(cursor_right
) && strlen(cursor_right
) > 1)
1395 EXPECTED(cursor_down
);
1396 EXPECTED(cursor_up
);
1397 EXPECTED(cursor_left
);
1398 EXPECTED(cursor_right
);
1405 * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad
1406 * is mapped inconsistently.
1409 check_keypad(TERMTYPE
*tp
)
1413 if (VALID_STRING(key_a1
) &&
1414 VALID_STRING(key_a3
) &&
1415 VALID_STRING(key_b2
) &&
1416 VALID_STRING(key_c1
) &&
1417 VALID_STRING(key_c3
)) {
1418 char final
[MAX_KP
+ 1];
1425 final
[0] = keypad_final(key_a1
);
1426 final
[1] = keypad_final(key_a3
);
1427 final
[2] = keypad_final(key_b2
);
1428 final
[3] = keypad_final(key_c1
);
1429 final
[4] = keypad_final(key_c3
);
1432 /* special case: legacy coding using 1,2,3,0,. on the bottom */
1433 assert(strlen(final
) <= MAX_KP
);
1434 if (!strcmp(final
, "qsrpn"))
1437 list
[0] = keypad_index(key_a1
);
1438 list
[1] = keypad_index(key_a3
);
1439 list
[2] = keypad_index(key_b2
);
1440 list
[3] = keypad_index(key_c1
);
1441 list
[4] = keypad_index(key_c3
);
1443 /* check that they're all vt100 keys */
1444 for (j
= 0; j
< MAX_KP
; ++j
) {
1450 /* check if they're all in increasing order */
1451 for (j
= 1; j
< MAX_KP
; ++j
) {
1452 if (list
[j
] > list
[j
- 1]) {
1456 if (increase
!= (MAX_KP
- 1)) {
1459 for (j
= 0, last
= -1; j
< MAX_KP
; ++j
) {
1460 for (k
= 0, kk
= -1, test
= 100; k
< 5; ++k
) {
1461 if (list
[k
] > last
&&
1468 assert(strlen(show
) < (MAX_KP
* 4));
1471 _nc_STRCAT(show
, " ka1", sizeof(show
));
1474 _nc_STRCAT(show
, " ka3", sizeof(show
));
1477 _nc_STRCAT(show
, " kb2", sizeof(show
));
1480 _nc_STRCAT(show
, " kc1", sizeof(show
));
1483 _nc_STRCAT(show
, " kc3", sizeof(show
));
1488 _nc_warning("vt100 keypad order inconsistent: %s", show
);
1491 } else if (VALID_STRING(key_a1
) ||
1492 VALID_STRING(key_a3
) ||
1493 VALID_STRING(key_b2
) ||
1494 VALID_STRING(key_c1
) ||
1495 VALID_STRING(key_c3
)) {
1497 if (keypad_index(key_a1
) >= 0)
1498 _nc_STRCAT(show
, " ka1", sizeof(show
));
1499 if (keypad_index(key_a3
) >= 0)
1500 _nc_STRCAT(show
, " ka3", sizeof(show
));
1501 if (keypad_index(key_b2
) >= 0)
1502 _nc_STRCAT(show
, " kb2", sizeof(show
));
1503 if (keypad_index(key_c1
) >= 0)
1504 _nc_STRCAT(show
, " kc1", sizeof(show
));
1505 if (keypad_index(key_c3
) >= 0)
1506 _nc_STRCAT(show
, " kc3", sizeof(show
));
1508 _nc_warning("vt100 keypad map incomplete:%s", show
);
1512 * These warnings are useful for consistency checks - it is possible that
1513 * there are real terminals with mismatches in these
1515 ANDMISSING(key_ic
, key_dc
);
1519 check_printer(TERMTYPE
*tp
)
1521 PAIRED(enter_doublewide_mode
, exit_doublewide_mode
);
1522 PAIRED(enter_italics_mode
, exit_italics_mode
);
1523 PAIRED(enter_leftward_mode
, exit_leftward_mode
);
1524 PAIRED(enter_micro_mode
, exit_micro_mode
);
1525 PAIRED(enter_shadow_mode
, exit_shadow_mode
);
1526 PAIRED(enter_subscript_mode
, exit_subscript_mode
);
1527 PAIRED(enter_superscript_mode
, exit_superscript_mode
);
1528 PAIRED(enter_upward_mode
, exit_upward_mode
);
1530 ANDMISSING(start_char_set_def
, stop_char_set_def
);
1532 /* if we have a parameterized form, then the non-parameterized is easy */
1533 ANDMISSING(set_bottom_margin_parm
, set_bottom_margin
);
1534 ANDMISSING(set_left_margin_parm
, set_left_margin
);
1535 ANDMISSING(set_right_margin_parm
, set_right_margin
);
1536 ANDMISSING(set_top_margin_parm
, set_top_margin
);
1538 ANDMISSING(parm_down_micro
, micro_down
);
1539 ANDMISSING(parm_left_micro
, micro_left
);
1540 ANDMISSING(parm_right_micro
, micro_right
);
1541 ANDMISSING(parm_up_micro
, micro_up
);
1545 uses_SGR_39_49(const char *value
)
1547 return (strstr(value
, "39;49") != 0
1548 || strstr(value
, "49;39") != 0);
1552 * Check consistency of termcap extensions related to "screen".
1555 check_screen(TERMTYPE
*tp
)
1558 if (_nc_user_definable
) {
1559 int have_XT
= tigetflag("XT");
1560 int have_XM
= tigetflag("XM");
1561 int have_bce
= back_color_erase
;
1562 bool have_kmouse
= FALSE
;
1563 bool use_sgr_39_49
= FALSE
;
1564 char *name
= _nc_first_name(tp
->term_names
);
1566 if (!VALID_BOOLEAN(have_bce
)) {
1569 if (!VALID_BOOLEAN(have_XM
)) {
1572 if (!VALID_BOOLEAN(have_XT
)) {
1575 if (VALID_STRING(key_mouse
)) {
1576 have_kmouse
= !strcmp("\033[M", key_mouse
);
1578 if (VALID_STRING(orig_colors
)) {
1579 use_sgr_39_49
= uses_SGR_39_49(orig_colors
);
1580 } else if (VALID_STRING(orig_pair
)) {
1581 use_sgr_39_49
= uses_SGR_39_49(orig_pair
);
1584 if (have_XM
&& have_XT
) {
1585 _nc_warning("Screen's XT capability conflicts with XM");
1587 && strstr(name
, "screen") != 0
1588 && strchr(name
, '.') != 0) {
1589 _nc_warning("Screen's \"screen\" entries should not have XT set");
1590 } else if (have_XT
) {
1591 if (!have_kmouse
&& have_bce
) {
1592 if (VALID_STRING(key_mouse
)) {
1593 _nc_warning("Value of kmous inconsistent with screen's usage");
1595 _nc_warning("Expected kmous capability with XT");
1598 if (!have_bce
&& max_colors
> 0)
1599 _nc_warning("Expected bce capability with XT");
1600 if (!use_sgr_39_49
&& have_bce
&& max_colors
> 0)
1601 _nc_warning("Expected orig_colors capability with XT to have 39/49 parameters");
1602 if (VALID_STRING(to_status_line
))
1603 _nc_warning("\"tsl\" capability is redundant, given XT");
1605 if (have_kmouse
&& !have_XM
)
1606 _nc_warning("Expected XT to be set, given kmous");
1613 * Returns the expected number of parameters for the given capability.
1616 expected_params(const char *name
)
1618 #define DATA(name,count) { { name }, count }
1620 static const struct {
1624 DATA( "S0", 1 ), /* 'screen' extension */
1627 DATA( "colornm", 1 ),
1671 DATA( "setcolor", 1 ),
1675 DATA( "slength", 1 ),
1676 DATA( "slines", 1 ),
1677 DATA( "smgbp", 1 ), /* 2 if smgtp is not given */
1694 int result
= 0; /* function-keys, etc., use none */
1696 for (n
= 0; n
< SIZEOF(table
); n
++) {
1697 if (!strcmp(name
, table
[n
].name
)) {
1698 result
= table
[n
].count
;
1707 * Make a quick sanity check for the parameters which are used in the given
1708 * strings. If there are no "%p" tokens, then there should be no other "%"
1712 check_params(TERMTYPE
*tp
, const char *name
, char *value
)
1714 int expected
= expected_params(name
);
1717 bool params
[NUM_PARM
];
1720 #ifdef set_top_margin_parm
1721 if (!strcmp(name
, "smgbp")
1722 && set_top_margin_parm
== 0)
1726 for (n
= 0; n
< NUM_PARM
; n
++)
1732 _nc_warning("expected character after %% in %s", name
);
1734 } else if (*s
== 'p') {
1735 if (*++s
== '\0' || !isdigit((int) *s
)) {
1736 _nc_warning("expected digit after %%p in %s", name
);
1750 _nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name
);
1752 if (value
== set_attributes
|| expected
< 0) {
1754 } else if (expected
!= actual
) {
1755 _nc_warning("%s uses %d parameters, expected %d", name
,
1757 for (n
= 1; n
< actual
; n
++) {
1759 _nc_warning("%s omits parameter %d", name
, n
);
1765 check_1_infotocap(const char *name
, NCURSES_CONST
char *value
, int count
)
1769 long numbers
[1 + NUM_PARM
];
1770 char *strings
[1 + NUM_PARM
];
1771 char *p_is_s
[NUM_PARM
];
1773 char blob
[NUM_PARM
* 10];
1777 for (k
= 1; k
<= NUM_PARM
; k
++) {
1779 sprintf(next
, "XYZ%d", count
);
1781 next
+= strlen(next
) + 1;
1784 switch (tparm_type(name
)) {
1786 result
= TPARM_2(value
, numbers
[1], strings
[2]);
1789 result
= TPARM_3(value
, numbers
[1], strings
[2], strings
[3]);
1793 (void) _nc_tparm_analyze(value
, p_is_s
, &ignored
);
1794 #define myParam(n) (p_is_s[n - 1] != 0 ? ((TPARM_ARG) strings[n]) : numbers[n])
1795 result
= TPARM_9(value
,
1810 #define IsDelay(ch) ((ch) == '.' || isdigit(UChar(ch)))
1813 parse_delay_value(const char *src
, double *delays
, int *always
)
1821 while (isdigit(UChar(*src
))) {
1822 (*delays
) = (*delays
) * 10 + (*src
++ - '0');
1828 while (isdigit(UChar(*src
))) {
1830 (*delays
) += (*src
++ - '0') / gotdot
;
1833 while (*src
== '*' || *src
== '/') {
1834 if (always
== 0 && *src
== '/')
1836 if (*src
++ == '*') {
1843 *delays
= -(*delays
);
1848 parse_ti_delay(const char *ti
, double *delays
)
1851 while (*ti
!= '\0') {
1857 && IsDelay(UChar(ti
[2]))) {
1859 const char *last
= parse_delay_value(ti
+ 2, delays
, &ignored
);
1871 parse_tc_delay(const char *tc
, double *delays
)
1873 return parse_delay_value(tc
, delays
, (int *) 0);
1877 * Compare terminfo- and termcap-strings, factoring out delays.
1880 same_ti_tc(const char *ti
, const char *tc
, bool * embedded
)
1883 double ti_delay
= 0.0;
1884 double tc_delay
= 0.0;
1885 const char *ti_last
;
1888 ti_last
= parse_ti_delay(ti
, &ti_delay
);
1889 tc
= parse_tc_delay(tc
, &tc_delay
);
1891 while ((ti
< ti_last
) && *tc
) {
1892 if (*ti
== '\\' && ispunct(UChar(ti
[1]))) {
1894 if ((*ti
== '^') && !strncmp(tc
, "\\136", 4)) {
1899 } else if (ti
[0] == '$' && ti
[1] == '<') {
1901 const char *ss
= parse_ti_delay(ti
, &no_delay
);
1908 if (*tc
== '\\' && ispunct(UChar(tc
[1]))) {
1911 if (*ti
++ != *tc
++) {
1921 *embedded
= FALSE
; /* report only one problem */
1929 * Check terminfo to termcap translation.
1932 check_infotocap(TERMTYPE
*tp
, int i
, const char *value
)
1934 const char *name
= ExtStrname(tp
, i
, strnames
);
1935 int params
= (((i
< (int) SIZEOF(parametrized
)) &&
1940 : has_params(value
)));
1946 if ((ti_value
= _nc_tic_expand(value
, TRUE
, to_char
)) == ABSENT_STRING
) {
1947 _nc_warning("tic-expansion of %s failed", name
);
1948 } else if ((tc_value
= _nc_infotocap(name
, ti_value
, params
)) == ABSENT_STRING
) {
1949 _nc_warning("tic-conversion of %s failed", name
);
1950 } else if (params
> 0) {
1955 if (!strcmp(name
, "setf")
1956 || !strcmp(name
, "setb")
1957 || !strcmp(name
, "setaf")
1958 || !strcmp(name
, "setab")) {
1961 for (count
= 0; count
< limit
; ++count
) {
1962 char *ti_check
= check_1_infotocap(name
, ti_value
, count
);
1963 char *tc_check
= check_1_infotocap(name
, tc_value
, count
);
1965 if (strcmp(ti_check
, tc_check
)) {
1967 fprintf(stderr
, "check_infotocap(%s)\n", name
);
1968 fprintf(stderr
, "...ti '%s'\n", ti_value
);
1969 fprintf(stderr
, "...tc '%s'\n", tc_value
);
1972 _nc_warning("tparm-conversion of %s(%d) differs between\n\tterminfo %s\n\ttermcap %s",
1973 name
, count
, ti_check
, tc_check
);
1976 } else if (params
== 0 && !same_ti_tc(ti_value
, tc_value
, &embedded
)) {
1978 _nc_warning("termcap equivalent of %s cannot use embedded delay", name
);
1980 _nc_warning("tic-conversion of %s changed value\n\tfrom %s\n\tto %s",
1981 name
, ti_value
, tc_value
);
1989 while (*s
== '/' || isdigit(UChar(*s
)))
1995 * Skip a delay altogether, e.g., when comparing a simple string to sgr,
1996 * the latter may have a worst-case delay on the end.
1999 ignore_delays(char *s
)
2031 #define DATA(name) { #name }
2032 static const char sgr_names
[][11] =
2049 * An sgr string may contain several settings other than the one we're
2050 * interested in, essentially sgr0 + rmacs + whatever. As long as the
2051 * "whatever" is contained in the sgr string, that is close enough for our
2055 similar_sgr(int num
, char *a
, char *b
)
2066 } else if (b
[0] == '$'
2068 _nc_warning("Did not find delay %s", _nc_visbuf(b
));
2070 _nc_warning("checking sgr(%s) %s\n\tcompare to %s\n\tunmatched %s",
2071 sgr_names
[num
], _nc_visbuf2(1, base_a
),
2072 _nc_visbuf2(2, base_b
),
2076 } else if (delaying
) {
2079 } else if ((*b
== '0' || (*b
== ';')) && *a
== 'm') {
2101 /* ignore delays on the end of the string */
2102 a
= ignore_delays(a
);
2103 return ((num
!= 0) || (*a
== 0));
2107 check_sgr(TERMTYPE
*tp
, char *zero
, int num
, char *cap
, const char *name
)
2112 test
= TPARM_9(set_attributes
,
2124 if (!similar_sgr(num
, test
, cap
)) {
2125 _nc_warning("%s differs from sgr(%d)\n\t%s=%s\n\tsgr(%d)=%s",
2127 name
, _nc_visbuf2(1, cap
),
2128 num
, _nc_visbuf2(2, test
));
2130 } else if (_nc_capcmp(test
, zero
)) {
2131 _nc_warning("sgr(%d) present, but not %s", num
, name
);
2133 } else if (PRESENT(cap
)) {
2134 _nc_warning("sgr(%d) missing, but %s present", num
, name
);
2137 _nc_warning("stack error in sgr(%d) string", num
);
2141 #define CHECK_SGR(num,name) check_sgr(tp, zero, num, name, #name)
2145 * If tic is compiled with TRACE, we'll be able to see the output from the
2146 * DEBUG() macro. But since it doesn't use traceon(), it always goes to
2147 * the standard error. Use this function to make it simpler to follow the
2148 * resulting debug traces.
2151 show_where(unsigned level
)
2153 if (_nc_tracing
>= DEBUG_LEVEL(level
)) {
2154 char my_name
[MAX_NAME_SIZE
];
2155 _nc_get_type(my_name
);
2156 _tracef("\"%s\", line %d, '%s'",
2158 _nc_curr_line
, my_name
);
2163 #define show_where(level) /* nothing */
2173 get_fkey_list(TERMTYPE
*tp
)
2175 NAME_VALUE
*result
= typeMalloc(NAME_VALUE
, NUM_STRINGS(tp
) + 1);
2176 const struct tinfo_fkeys
*all_fkeys
= _nc_tinfo_fkeys
;
2181 failed("get_fkey_list");
2183 for (j
= 0; all_fkeys
[j
].code
; j
++) {
2184 char *a
= tp
->Strings
[all_fkeys
[j
].offset
];
2185 if (VALID_STRING(a
)) {
2186 result
[used
].keycode
= (int) all_fkeys
[j
].code
;
2187 result
[used
].name
= strnames
[all_fkeys
[j
].offset
];
2188 result
[used
].value
= a
;
2193 for (j
= STRCOUNT
; j
< NUM_STRINGS(tp
); ++j
) {
2194 const char *name
= ExtStrname(tp
, (int) j
, strnames
);
2196 result
[used
].keycode
= -1;
2197 result
[used
].name
= name
;
2198 result
[used
].value
= tp
->Strings
[j
];
2203 result
[used
].keycode
= 0;
2208 show_fkey_name(NAME_VALUE
* data
)
2210 if (data
->keycode
> 0) {
2211 fprintf(stderr
, " %s", keyname(data
->keycode
));
2212 fprintf(stderr
, " (capability \"%s\")", data
->name
);
2214 fprintf(stderr
, " capability \"%s\"", data
->name
);
2219 * A terminal entry may contain more than one keycode assigned to a given
2220 * string (e.g., KEY_END and KEY_LL). But curses will only return one (the
2221 * last one assigned).
2224 check_conflict(TERMTYPE
*tp
)
2226 bool conflict
= FALSE
;
2229 if (!(_nc_syntax
== SYN_TERMCAP
&& capdump
)) {
2230 char *check
= calloc((size_t) (NUM_STRINGS(tp
) + 1), sizeof(char));
2231 NAME_VALUE
*given
= get_fkey_list(tp
);
2234 failed("check_termtype");
2236 for (j
= 0; given
[j
].keycode
; ++j
) {
2237 const char *a
= given
[j
].value
;
2240 for (k
= j
+ 1; given
[k
].keycode
; k
++) {
2241 const char *b
= given
[k
].value
;
2244 if (!_nc_capcmp(a
, b
)) {
2249 _nc_warning("Conflicting key definitions (using the last)");
2252 fprintf(stderr
, "...");
2253 show_fkey_name(given
+ j
);
2254 fprintf(stderr
, " is the same as");
2255 show_fkey_name(given
+ k
);
2258 fprintf(stderr
, ", ");
2259 show_fkey_name(given
+ k
);
2264 fprintf(stderr
, "\n");
2272 * Exiting a video mode should not duplicate sgr0
2275 check_exit_attribute(const char *name
, char *test
, char *trimmed
, char *untrimmed
)
2277 if (VALID_STRING(test
)) {
2278 if (similar_sgr(-1, trimmed
, test
) ||
2279 similar_sgr(-1, untrimmed
, test
)) {
2280 _nc_warning("%s matches exit_attribute_mode", name
);
2286 * Returns true if the string looks like a standard SGR string.
2289 is_sgr_string(char *value
)
2291 bool result
= FALSE
;
2293 if (VALID_STRING(value
)) {
2294 if (value
[0] == '\033' && value
[1] == '[') {
2297 } else if (UChar(value
[0]) == 0x9a) {
2303 while ((ch
= UChar(*value
++)) != '\0') {
2304 if (isdigit(ch
) || ch
== ';') {
2306 } else if (ch
== 'm' && *value
== '\0') {
2319 * Check if the given capability contains a given SGR attribute.
2322 check_sgr_param(TERMTYPE
*tp
, int code
, const char *name
, char *value
)
2324 if (VALID_STRING(value
)) {
2325 int ncv
= ((code
!= 0) ? (1 << (code
- 1)) : 0);
2326 char *test
= tgoto(value
, 0, 0);
2327 if (is_sgr_string(test
)) {
2331 int color
= (value
== set_a_foreground
||
2332 value
== set_a_background
||
2333 value
== set_foreground
||
2334 value
== set_background
);
2335 while (*test
!= 0) {
2336 if (isdigit(UChar(*test
))) {
2337 param
= 10 * param
+ (*test
- '0');
2342 * Avoid unnecessary warning for xterm 256color codes.
2344 if (color
&& (param
== 38 || param
== 48))
2346 if ((skips
-- <= 0) && (param
== code
))
2354 if (count
!= 0 && param
== code
) {
2356 no_color_video
< 0 ||
2357 !(no_color_video
& ncv
)) {
2358 _nc_warning("\"%s\" SGR-attribute used in %s",
2367 /* other sanity-checks (things that we don't want in the normal
2368 * logic that reads a terminfo entry)
2371 check_termtype(TERMTYPE
*tp
, bool literal
)
2377 for_each_string(j
, tp
) {
2378 char *a
= tp
->Strings
[j
];
2379 if (VALID_STRING(a
)) {
2380 check_params(tp
, ExtStrname(tp
, (int) j
, strnames
), a
);
2382 check_infotocap(tp
, (int) j
, a
);
2395 * These may be mismatched because the terminal description relies on
2396 * restoring the cursor visibility by resetting it.
2398 ANDMISSING(cursor_invisible
, cursor_normal
);
2399 ANDMISSING(cursor_visible
, cursor_normal
);
2401 if (PRESENT(cursor_visible
) && PRESENT(cursor_normal
)
2402 && !_nc_capcmp(cursor_visible
, cursor_normal
))
2403 _nc_warning("cursor_visible is same as cursor_normal");
2406 * From XSI & O'Reilly, we gather that sc/rc are required if csr is
2407 * given, because the cursor position after the scrolling operation is
2408 * performed is undefined.
2410 ANDMISSING(change_scroll_region
, save_cursor
);
2411 ANDMISSING(change_scroll_region
, restore_cursor
);
2414 * If we can clear tabs, we should be able to initialize them.
2416 ANDMISSING(clear_all_tabs
, set_tab
);
2418 if (PRESENT(set_attributes
)) {
2422 if (PRESENT(exit_attribute_mode
)) {
2423 zero
= strdup(CHECK_SGR(0, exit_attribute_mode
));
2425 zero
= strdup(TPARM_9(set_attributes
, 0, 0, 0, 0, 0, 0, 0, 0, 0));
2428 _nc_warning("stack error in sgr(0) string");
2431 CHECK_SGR(1, enter_standout_mode
);
2432 CHECK_SGR(2, enter_underline_mode
);
2433 CHECK_SGR(3, enter_reverse_mode
);
2434 CHECK_SGR(4, enter_blink_mode
);
2435 CHECK_SGR(5, enter_dim_mode
);
2436 CHECK_SGR(6, enter_bold_mode
);
2437 CHECK_SGR(7, enter_secure_mode
);
2438 CHECK_SGR(8, enter_protected_mode
);
2439 CHECK_SGR(9, enter_alt_charset_mode
);
2442 _nc_warning("sgr(0) did not return a value");
2444 } else if (PRESENT(exit_attribute_mode
) &&
2445 set_attributes
!= CANCELLED_STRING
) {
2446 if (_nc_syntax
== SYN_TERMINFO
)
2447 _nc_warning("missing sgr string");
2449 #define CHECK_SGR0(name) check_exit_attribute(#name, name, check_sgr0, exit_attribute_mode)
2450 if (PRESENT(exit_attribute_mode
)) {
2451 char *check_sgr0
= _nc_trim_sgr0(tp
);
2453 if (check_sgr0
== 0 || *check_sgr0
== '\0') {
2454 _nc_warning("trimmed sgr0 is empty");
2457 if (check_sgr0
!= exit_attribute_mode
) {
2459 ("will trim sgr0\n\toriginal sgr0=%s\n\ttrimmed sgr0=%s",
2460 _nc_visbuf2(1, exit_attribute_mode
),
2461 _nc_visbuf2(2, check_sgr0
)));
2464 ("will not trim sgr0\n\toriginal sgr0=%s",
2465 _nc_visbuf(exit_attribute_mode
)));
2468 CHECK_SGR0(exit_italics_mode
);
2469 CHECK_SGR0(exit_standout_mode
);
2470 CHECK_SGR0(exit_underline_mode
);
2471 if (check_sgr0
!= exit_attribute_mode
) {
2475 #define CHECK_SGR_PARAM(code, name) check_sgr_param(tp, (int)code, #name, name)
2476 for (j
= 0; *sgr_names
[j
] != '\0'; ++j
) {
2477 CHECK_SGR_PARAM(j
, set_a_foreground
);
2478 CHECK_SGR_PARAM(j
, set_a_background
);
2479 CHECK_SGR_PARAM(j
, set_foreground
);
2480 CHECK_SGR_PARAM(j
, set_background
);
2484 if (!auto_right_margin
) {
2486 ("can write to lower-right directly"));
2487 } else if (PRESENT(enter_am_mode
) && PRESENT(exit_am_mode
)) {
2489 ("can write to lower-right by suppressing automargin"));
2490 } else if ((PRESENT(enter_insert_mode
) && PRESENT(exit_insert_mode
))
2491 || PRESENT(insert_character
) || PRESENT(parm_ich
)) {
2493 ("can write to lower-right by using inserts"));
2496 ("cannot write to lower-right"));
2501 * Some standard applications (e.g., vi) and some non-curses
2502 * applications (e.g., jove) get confused if we have both ich1 and
2503 * smir/rmir. Let's be nice and warn about that, too, even though
2504 * ncurses handles it.
2506 if ((PRESENT(enter_insert_mode
) || PRESENT(exit_insert_mode
))
2507 && PRESENT(parm_ich
)) {
2508 _nc_warning("non-curses applications may be confused by ich1 with smir/rmir");
2512 * Finally, do the non-verbose checks
2514 if (save_check_termtype
!= 0)
2515 save_check_termtype(tp
, literal
);