1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 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 ****************************************************************************/
35 #define __INTERNAL_CAPS_VISIBLE
36 #include <progs.priv.h>
38 #include "dump_entry.h"
39 #include "termsort.c" /* this C file is generated */
40 #include <parametrized.h> /* so is this */
42 MODULE_ID("$Id: dump_entry.c,v 1.101 2012/10/27 19:45:17 tom Exp $")
45 #define DISCARD(string) string = ABSENT_STRING
46 #define PRINTF (void) printf
48 #define OkIndex(index,array) ((int)(index) >= 0 && (int)(index) < (int) SIZEOF(array))
56 static int tversion; /* terminfo version */
57 static int outform; /* output format to use */
58 static int sortmode; /* sort mode to use */
59 static int width = 60; /* max line width for listings */
60 static int height = 65535; /* max number of lines for listings */
61 static int column; /* current column, limited by 'width' */
62 static int oldcol; /* last value of column before wrap */
63 static bool pretty; /* true if we format if-then-else strings */
65 static char *save_sgr;
70 /* indirection pointers for implementing sort and display modes */
71 static const PredIdx *bool_indirect, *num_indirect, *str_indirect;
72 static NCURSES_CONST char *const *bool_names;
73 static NCURSES_CONST char *const *num_names;
74 static NCURSES_CONST char *const *str_names;
76 static const char *separator, *trailer;
78 /* cover various ports and variants of terminfo */
79 #define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */
80 #define V_SVR1 1 /* SVR1, Ultrix */
81 #define V_HPUX 2 /* HP/UX */
82 #define V_AIX 3 /* AIX */
83 #define V_BSD 4 /* BSD */
86 #define OBSOLETE(n) (!_nc_user_definable && (n[0] == 'O' && n[1] == 'T'))
88 #define OBSOLETE(n) (n[0] == 'O' && n[1] == 'T')
91 #define isObsolete(f,n) ((f == F_TERMINFO || f == F_VARIABLE) && OBSOLETE(n))
94 #define BoolIndirect(j) ((j >= BOOLCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : bool_indirect[j]))
95 #define NumIndirect(j) ((j >= NUMCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : num_indirect[j]))
96 #define StrIndirect(j) ((j >= STRCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : str_indirect[j]))
98 #define BoolIndirect(j) ((sortmode == S_NOSORT) ? (j) : bool_indirect[j])
99 #define NumIndirect(j) ((sortmode == S_NOSORT) ? (j) : num_indirect[j])
100 #define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
104 failed(const char *s)
107 ExitProgram(EXIT_FAILURE);
111 strncpy_DYN(DYNBUF * dst, const char *src, size_t need)
113 size_t want = need + dst->used + 1;
114 if (want > dst->size) {
115 dst->size += (want + 1024); /* be generous */
116 dst->text = typeRealloc(char, dst->size, dst->text);
118 failed("strncpy_DYN");
120 (void) strncpy(dst->text + dst->used, src, need);
122 dst->text[dst->used] = 0;
126 strcpy_DYN(DYNBUF * dst, const char *src)
132 strncpy_DYN(dst, src, strlen(src));
148 _nc_leaks_dump_entry(void)
155 #define NameTrans(check,result) \
156 if (OkIndex(np->nte_index, check) \
157 && check[np->nte_index]) \
158 return (result[np->nte_index])
161 nametrans(const char *name)
162 /* translate a capability name from termcap to terminfo */
164 const struct name_table_entry *np;
166 if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
167 switch (np->nte_type) {
169 NameTrans(bool_from_termcap, boolcodes);
173 NameTrans(num_from_termcap, numcodes);
177 NameTrans(str_from_termcap, strcodes);
185 dump_init(const char *version,
192 /* set up for entry display */
200 tversion = V_ALLCAPS;
201 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
202 || !strcmp(version, "Ultrix"))
204 else if (!strcmp(version, "HP"))
206 else if (!strcmp(version, "AIX"))
208 else if (!strcmp(version, "BSD"))
211 tversion = V_ALLCAPS;
213 /* implement display modes */
214 switch (outform = mode) {
217 bool_names = boolnames;
218 num_names = numnames;
219 str_names = strnames;
220 separator = (twidth > 0 && theight > 1) ? ", " : ",";
225 bool_names = boolfnames;
226 num_names = numfnames;
227 str_names = strfnames;
228 separator = (twidth > 0 && theight > 1) ? ", " : ",";
234 bool_names = boolcodes;
235 num_names = numcodes;
236 str_names = strcodes;
242 /* implement sort modes */
243 switch (sortmode = sort) {
246 (void) fprintf(stderr,
247 "%s: sorting by term structure order\n", _nc_progname);
252 (void) fprintf(stderr,
253 "%s: sorting by terminfo name order\n", _nc_progname);
254 bool_indirect = bool_terminfo_sort;
255 num_indirect = num_terminfo_sort;
256 str_indirect = str_terminfo_sort;
261 (void) fprintf(stderr,
262 "%s: sorting by C variable order\n", _nc_progname);
263 bool_indirect = bool_variable_sort;
264 num_indirect = num_variable_sort;
265 str_indirect = str_variable_sort;
270 (void) fprintf(stderr,
271 "%s: sorting by termcap name order\n", _nc_progname);
272 bool_indirect = bool_termcap_sort;
273 num_indirect = num_termcap_sort;
274 str_indirect = str_termcap_sort;
279 (void) fprintf(stderr,
280 "%s: width = %d, tversion = %d, outform = %d\n",
281 _nc_progname, width, tversion, outform);
284 static TERMTYPE *cur_type;
287 dump_predicate(PredType type, PredIdx idx)
288 /* predicate function to use for ordinary decompilation */
292 return (cur_type->Booleans[idx] == FALSE)
293 ? FAIL : cur_type->Booleans[idx];
296 return (cur_type->Numbers[idx] == ABSENT_NUMERIC)
297 ? FAIL : cur_type->Numbers[idx];
300 return (cur_type->Strings[idx] != ABSENT_STRING)
304 return (FALSE); /* pacify compiler */
307 static void set_obsolete_termcaps(TERMTYPE *tp);
309 /* is this the index of a function key string? */
310 #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
313 * If we configure with a different Caps file, the offsets into the arrays
314 * will change. So we use an address expression.
316 #define BOOL_IDX(name) (PredType) (&(name) - &(CUR Booleans[0]))
317 #define NUM_IDX(name) (PredType) (&(name) - &(CUR Numbers[0]))
318 #define STR_IDX(name) (PredType) (&(name) - &(CUR Strings[0]))
321 version_filter(PredType type, PredIdx idx)
322 /* filter out capabilities we may want to suppress */
325 case V_ALLCAPS: /* SVr4, XSI Curses */
328 case V_SVR1: /* System V Release 1, Ultrix */
331 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
333 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
335 return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE);
339 case V_HPUX: /* Hewlett-Packard */
342 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
344 return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE);
346 if (idx <= STR_IDX(prtr_non))
348 else if (FNKEY(idx)) /* function keys */
350 else if (idx == STR_IDX(plab_norm)
351 || idx == STR_IDX(label_on)
352 || idx == STR_IDX(label_off))
359 case V_AIX: /* AIX */
362 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
364 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
366 if (idx <= STR_IDX(prtr_non))
368 else if (FNKEY(idx)) /* function keys */
375 #define is_termcap(type) (OkIndex(idx, type##_from_termcap) && \
376 type##_from_termcap[idx])
378 case V_BSD: /* BSD */
381 return is_termcap(bool);
383 return is_termcap(num);
385 return is_termcap(str);
390 return (FALSE); /* pacify the compiler */
396 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
397 outbuf.text[--outbuf.used] = '\0';
405 strcpy_DYN(&outbuf, trailer);
410 wrap_concat(const char *src)
412 size_t need = strlen(src);
413 size_t want = strlen(separator) + need;
416 && column + (int) want > width) {
419 strcpy_DYN(&outbuf, src);
420 strcpy_DYN(&outbuf, separator);
421 column += (int) need;
424 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
425 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
426 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
427 first += sizeof(sep_trail)-2
429 /* Returns the nominal length of the buffer assuming it is termcap format,
430 * i.e., the continuation sequence is treated as a single character ":".
432 * There are several implementations of termcap which read the text into a
433 * fixed-size buffer. Generally they strip the newlines from the text, but may
434 * not do it until after the buffer is read. Also, "tc=" resolution may be
435 * expanded in the same buffer. This function is useful for measuring the size
436 * of the best fixed-buffer implementation; the worst case may be much worse.
438 #ifdef TEST_TERMCAP_LENGTH
440 termcap_length(const char *src)
442 static const char pattern[] = ":\\\n\t:";
445 const char *const t = src + strlen(src);
447 while (*src != '\0') {
448 IGNORE_SEP_TRAIL(src, t, pattern);
455 #define termcap_length(src) strlen(src)
459 indent_DYN(DYNBUF * buffer, int level)
463 for (n = 0; n < level; n++)
464 strncpy_DYN(buffer, "\t", 1);
468 has_params(const char *src)
471 int len = (int) strlen(src);
476 for (n = 0; n < len - 1; ++n) {
477 if (!strncmp(src + n, "%p", 2)) {
479 } else if (!strncmp(src + n, "%;", 2)) {
486 result = ((len > 50) && params);
492 fmt_complex(char *src, int level)
494 bool percent = FALSE;
495 bool params = has_params(src);
497 while (*src != '\0') {
501 strncpy_DYN(&tmpbuf, src++, 1);
507 case 't': /* "then" */
508 case 'e': /* "else" */
511 tmpbuf.text[tmpbuf.used - 1] = '\n';
512 /* treat a "%e" as else-if, on the same level */
514 indent_DYN(&tmpbuf, level);
515 strncpy_DYN(&tmpbuf, "%", 1);
516 strncpy_DYN(&tmpbuf, src, 1);
518 params = has_params(src);
519 if (!params && *src != '\0' && *src != '%') {
520 strncpy_DYN(&tmpbuf, "\n", 1);
521 indent_DYN(&tmpbuf, level + 1);
524 indent_DYN(&tmpbuf, level + 1);
525 strncpy_DYN(&tmpbuf, "%", 1);
526 strncpy_DYN(&tmpbuf, src, 1);
528 src = fmt_complex(src, level + 1);
529 if (*src != '\0' && *src != '%') {
530 strncpy_DYN(&tmpbuf, "\n", 1);
531 indent_DYN(&tmpbuf, level + 1);
533 } else if (level == 1) {
534 _nc_warning("%%%c without %%?", *src);
540 case ';': /* "endif" */
544 tmpbuf.text[tmpbuf.used - 1] = '\n';
545 indent_DYN(&tmpbuf, level);
546 strncpy_DYN(&tmpbuf, "%", 1);
547 strncpy_DYN(&tmpbuf, src++, 1);
550 _nc_warning("%%; without %%?");
554 if (percent && params) {
555 tmpbuf.text[tmpbuf.used - 1] = '\n';
556 indent_DYN(&tmpbuf, level + 1);
557 strncpy_DYN(&tmpbuf, "%", 1);
563 strncpy_DYN(&tmpbuf, "\\s", 2);
570 strncpy_DYN(&tmpbuf, src++, 1);
575 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
579 fmt_entry(TERMTYPE *tterm,
582 bool suppress_untranslatable,
587 char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP];
589 NCURSES_CONST char *name;
591 PredIdx num_bools = 0;
592 PredIdx num_values = 0;
593 PredIdx num_strings = 0;
596 #define WRAP_CONCAT \
597 wrap_concat(buffer); \
600 len = 12; /* terminfo file-header */
604 pred = dump_predicate;
607 strcpy_DYN(&outbuf, 0);
609 column = INDENT; /* FIXME: workaround to prevent empty lines */
611 strcpy_DYN(&outbuf, tterm->term_names);
614 * Colon is legal in terminfo descriptions, but not in termcap.
617 char *p = outbuf.text;
625 strcpy_DYN(&outbuf, separator);
626 column = (int) outbuf.used;
631 for_each_boolean(j, tterm) {
633 name = ExtBoolname(tterm, (int) i, bool_names);
634 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
636 if (!version_filter(BOOLEAN, i))
638 else if (isObsolete(outform, name))
641 predval = pred(BOOLEAN, i);
642 if (predval != FAIL) {
643 _nc_STRCPY(buffer, name, sizeof(buffer));
645 _nc_STRCAT(buffer, "@", sizeof(buffer));
646 else if (i + 1 > num_bools)
652 if (column != INDENT && height > 1)
655 for_each_number(j, tterm) {
657 name = ExtNumname(tterm, (int) i, num_names);
658 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
660 if (!version_filter(NUMBER, i))
662 else if (isObsolete(outform, name))
665 predval = pred(NUMBER, i);
666 if (predval != FAIL) {
667 if (tterm->Numbers[i] < 0) {
668 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
671 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
672 "%s#%d", name, tterm->Numbers[i]);
673 if (i + 1 > num_values)
680 if (column != INDENT && height > 1)
683 len += (int) (num_bools
685 + strlen(tterm->term_names) + 1);
691 if (outform == F_TERMCAP) {
692 if (termcap_reset != ABSENT_STRING) {
693 if (init_3string != ABSENT_STRING
694 && !strcmp(init_3string, termcap_reset))
695 DISCARD(init_3string);
697 if (reset_2string != ABSENT_STRING
698 && !strcmp(reset_2string, termcap_reset))
699 DISCARD(reset_2string);
703 for_each_string(j, tterm) {
705 name = ExtStrname(tterm, (int) i, str_names);
706 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
708 capability = tterm->Strings[i];
710 if (!version_filter(STRING, i))
712 else if (isObsolete(outform, name))
717 * Extended names can be longer than 2 characters, but termcap programs
718 * cannot read those (filter them out).
720 if (outform == F_TERMCAP && (strlen(name) > 2))
724 if (outform == F_TERMCAP) {
726 * Some older versions of vi want rmir/smir to be defined
727 * for ich/ich1 to work. If they're not defined, force
728 * them to be output as defined and empty.
730 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
731 if (SAME_CAP(i, enter_insert_mode)
732 && enter_insert_mode == ABSENT_STRING) {
733 _nc_STRCPY(buffer, "im=", sizeof(buffer));
738 if (SAME_CAP(i, exit_insert_mode)
739 && exit_insert_mode == ABSENT_STRING) {
740 _nc_STRCPY(buffer, "ei=", sizeof(buffer));
746 * termcap applications such as screen will be confused if sgr0
747 * is translated to a string containing rmacs. Filter that out.
749 if (PRESENT(exit_attribute_mode)) {
750 if (SAME_CAP(i, exit_attribute_mode)) {
752 char *my_sgr = set_attributes;
754 set_attributes = save_sgr;
756 trimmed_sgr0 = _nc_trim_sgr0(tterm);
757 if (strcmp(capability, trimmed_sgr0))
758 capability = trimmed_sgr0;
760 set_attributes = my_sgr;
765 predval = pred(STRING, i);
768 if (predval != FAIL) {
769 if (capability != ABSENT_STRING
770 && i + 1 > num_strings)
773 if (!VALID_STRING(capability)) {
774 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
777 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
778 int params = ((i < (int) SIZEOF(parametrized))
781 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
782 char *cv = _nc_infotocap(name, srccap, params);
785 if (outform == F_TCONVERR) {
786 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
787 "%s=!!! %s WILL NOT CONVERT !!!",
789 } else if (suppress_untranslatable) {
792 char *s = srccap, *d = buffer;
793 _nc_SPRINTF(d, _nc_SLIMIT(sizeof(buffer)) "..%s=", name);
795 while ((*d = *s++) != 0) {
799 } else if (*d == '\\') {
806 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
809 len += (int) strlen(capability) + 1;
812 char *src = _nc_tic_expand(capability,
813 outform == F_TERMINFO, numbers);
815 strcpy_DYN(&tmpbuf, 0);
816 strcpy_DYN(&tmpbuf, name);
817 strcpy_DYN(&tmpbuf, "=");
819 && (outform == F_TERMINFO
820 || outform == F_VARIABLE)) {
823 strcpy_DYN(&tmpbuf, src);
825 len += (int) strlen(capability) + 1;
826 wrap_concat(tmpbuf.text);
830 /* e.g., trimmed_sgr0 */
831 if (capability != tterm->Strings[i])
834 len += (int) (num_strings * 2);
837 * This piece of code should be an effective inverse of the functions
838 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
839 * Much more work should be done on this to support dumping termcaps.
841 if (tversion == V_HPUX) {
842 if (VALID_STRING(memory_lock)) {
843 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
844 "meml=%s", memory_lock);
847 if (VALID_STRING(memory_unlock)) {
848 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
849 "memu=%s", memory_unlock);
852 } else if (tversion == V_AIX) {
853 if (VALID_STRING(acs_chars)) {
855 const char *acstrans = "lqkxjmwuvtn";
857 char *tp, *sp, boxchars[11];
860 for (cp = acstrans; *cp; cp++) {
861 sp = strchr(acs_chars, *cp);
872 _nc_STRCPY(buffer, "box1=", sizeof(buffer));
874 _nc_tic_expand(boxchars,
875 outform == F_TERMINFO, numbers),
883 * kludge: trim off trailer to avoid an extra blank line
884 * in infocmp -u output when there are no string differences
887 bool trimmed = FALSE;
888 j = (PredIdx) outbuf.used;
890 && outbuf.text[j - 1] == '\t'
891 && outbuf.text[j - 2] == '\n') {
895 && outbuf.text[j - 1] == ':'
896 && outbuf.text[j - 2] == '\t'
897 && outbuf.text[j - 3] == '\n'
898 && outbuf.text[j - 4] == '\\') {
903 outbuf.text[outbuf.used] = '\0';
905 strcpy_DYN(&outbuf, " ");
909 fprintf(stderr, "num_bools = %d\n", num_bools);
910 fprintf(stderr, "num_values = %d\n", num_values);
911 fprintf(stderr, "num_strings = %d\n", num_strings);
912 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
913 tterm->term_names, len, outbuf.used, outbuf.text);
916 * Here's where we use infodump to trigger a more stringent length check
917 * for termcap-translation purposes.
918 * Return the length of the raw entry, without tc= expansions,
919 * It gives an idea of which entries are deadly to even *scan past*,
920 * as opposed to *use*.
922 return (infodump ? len : (int) termcap_length(outbuf.text));
926 kill_string(TERMTYPE *tterm, char *cap)
929 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
930 if (cap == tterm->Strings[n]) {
931 tterm->Strings[n] = ABSENT_STRING;
939 find_string(TERMTYPE *tterm, char *name)
942 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
943 if (version_filter(STRING, n)
944 && !strcmp(name, strnames[n])) {
945 char *cap = tterm->Strings[n];
946 if (VALID_STRING(cap)) {
952 return ABSENT_STRING;
956 * This is used to remove function-key labels from a termcap entry to
960 kill_labels(TERMTYPE *tterm, int target)
967 for (n = 0; n <= 10; ++n) {
968 _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "lf%d", n);
969 if ((cap = find_string(tterm, name)) != ABSENT_STRING
970 && kill_string(tterm, cap)) {
971 target -= (int) (strlen(cap) + 5);
981 * This is used to remove function-key definitions from a termcap entry to
985 kill_fkeys(TERMTYPE *tterm, int target)
992 for (n = 60; n >= 0; --n) {
993 _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "kf%d", n);
994 if ((cap = find_string(tterm, name)) != ABSENT_STRING
995 && kill_string(tterm, cap)) {
996 target -= (int) (strlen(cap) + 5);
1006 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
1007 * Also, since this is for termcap, we only care about the line-drawing map.
1009 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
1012 one_one_mapping(const char *mapping)
1016 if (mapping != ABSENT_STRING) {
1018 while (mapping[n] != '\0') {
1019 if (isLine(mapping[n]) &&
1020 mapping[n] != mapping[n + 1]) {
1030 #define FMT_ENTRY() \
1031 fmt_entry(tterm, pred, \
1033 suppress_untranslatable, \
1036 #define SHOW_WHY PRINTF
1039 purged_acs(TERMTYPE *tterm)
1041 bool result = FALSE;
1043 if (VALID_STRING(acs_chars)) {
1044 if (!one_one_mapping(acs_chars)) {
1045 enter_alt_charset_mode = ABSENT_STRING;
1046 exit_alt_charset_mode = ABSENT_STRING;
1047 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1055 * Dump a single entry.
1058 dump_entry(TERMTYPE *tterm,
1059 bool suppress_untranslatable,
1064 TERMTYPE save_tterm;
1069 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1070 critlen = MAX_TERMCAP_LENGTH;
1071 legend = "older termcap";
1073 set_obsolete_termcaps(tterm);
1075 critlen = MAX_TERMINFO_LENGTH;
1076 legend = "terminfo";
1080 save_sgr = set_attributes;
1082 if ((FMT_ENTRY() > critlen)
1085 save_tterm = *tterm;
1086 if (!suppress_untranslatable) {
1087 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1089 suppress_untranslatable = TRUE;
1091 if (FMT_ENTRY() > critlen) {
1093 * We pick on sgr because it's a nice long string capability that
1094 * is really just an optimization hack. Another good candidate is
1095 * acsc since it is both long and unused by BSD termcap.
1097 bool changed = FALSE;
1101 * Extended names are most likely function-key definitions. Drop
1105 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1106 const char *name = ExtStrname(tterm, (int) n, strnames);
1108 if (VALID_STRING(tterm->Strings[n])) {
1109 set_attributes = ABSENT_STRING;
1110 /* we remove long names anyway - only report the short */
1111 if (strlen(name) <= 2) {
1112 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1117 if (FMT_ENTRY() <= critlen)
1122 if (VALID_STRING(set_attributes)) {
1123 set_attributes = ABSENT_STRING;
1124 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1128 if (!changed || (FMT_ENTRY() > critlen)) {
1129 if (purged_acs(tterm)) {
1130 acs_chars = ABSENT_STRING;
1131 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1136 if (!changed || (FMT_ENTRY() > critlen)) {
1137 int oldversion = tversion;
1140 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1145 && kill_labels(tterm, len - critlen)) {
1146 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1151 && kill_fkeys(tterm, len - critlen)) {
1152 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1156 if (len > critlen) {
1157 (void) fprintf(stderr,
1158 "warning: %s entry is %d bytes long\n",
1159 _nc_first_name(tterm->term_names),
1161 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1164 tversion = oldversion;
1166 set_attributes = save_sgr;
1167 *tterm = save_tterm;
1169 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1170 save_tterm = *tterm;
1171 if (purged_acs(tterm)) {
1174 *tterm = save_tterm;
1179 dump_uses(const char *name, bool infodump)
1180 /* dump "use=" clauses in the appropriate format */
1182 char buffer[MAX_TERMINFO_LENGTH];
1184 if (outform == F_TERMCAP || outform == F_TCONVERR)
1186 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
1187 "%s%s", infodump ? "use=" : "tc=", name);
1188 wrap_concat(buffer);
1195 * Trim any remaining whitespace.
1197 if (outbuf.used != 0) {
1198 bool infodump = (outform != F_TERMCAP && outform != F_TCONVERR);
1199 char delim = (char) (infodump ? ',' : ':');
1202 for (j = (int) outbuf.used - 1; j > 0; --j) {
1203 char ch = outbuf.text[j];
1206 } else if (isspace(UChar(ch))) {
1207 outbuf.used = (size_t) j;
1208 } else if (!infodump && ch == '\\') {
1209 outbuf.used = (size_t) j;
1210 } else if (ch == delim && (j == 0 || outbuf.text[j - 1] != '\\')) {
1211 outbuf.used = (size_t) (j + 1);
1216 outbuf.text[outbuf.used] = '\0';
1218 (void) fputs(outbuf.text, stdout);
1220 return (int) outbuf.used;
1224 compare_entry(PredHook hook,
1225 TERMTYPE *tp GCC_UNUSED,
1227 /* compare two entries */
1230 NCURSES_CONST char *name;
1233 fputs(" comparing booleans.\n", stdout);
1234 for_each_boolean(j, tp) {
1235 i = BoolIndirect(j);
1236 name = ExtBoolname(tp, (int) i, bool_names);
1238 if (isObsolete(outform, name))
1241 (*hook) (CMP_BOOLEAN, i, name);
1245 fputs(" comparing numbers.\n", stdout);
1246 for_each_number(j, tp) {
1248 name = ExtNumname(tp, (int) i, num_names);
1250 if (isObsolete(outform, name))
1253 (*hook) (CMP_NUMBER, i, name);
1257 fputs(" comparing strings.\n", stdout);
1258 for_each_string(j, tp) {
1260 name = ExtStrname(tp, (int) i, str_names);
1262 if (isObsolete(outform, name))
1265 (*hook) (CMP_STRING, i, name);
1268 /* (void) fputs(" comparing use entries.\n", stdout); */
1269 (*hook) (CMP_USE, 0, "use");
1273 #define NOTSET(s) ((s) == 0)
1276 * This bit of legerdemain turns all the terminfo variable names into
1277 * references to locations in the arrays Booleans, Numbers, and Strings ---
1278 * precisely what's needed.
1284 set_obsolete_termcaps(TERMTYPE *tp)
1286 #include "capdefaults.c"
1290 * Convert an alternate-character-set string to canonical form: sorted and
1294 repair_acsc(TERMTYPE *tp)
1296 if (VALID_STRING(acs_chars)) {
1302 bool fix_needed = FALSE;
1304 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1305 target = UChar(acs_chars[n]);
1306 if (source >= target) {
1311 if (acs_chars[n + 1])
1315 memset(mapped, 0, sizeof(mapped));
1316 for (n = 0; acs_chars[n] != 0; n++) {
1317 source = UChar(acs_chars[n]);
1318 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1319 mapped[source] = (char) target;
1322 extra = (char) source;
1325 for (n = m = 0; n < sizeof(mapped); n++) {
1327 acs_chars[m++] = (char) n;
1328 acs_chars[m++] = mapped[n];
1332 acs_chars[m++] = extra; /* garbage in, garbage out */