1 /****************************************************************************
2 * Copyright (c) 1998-2005,2006 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.79 2006/09/30 20:18:15 tom Exp $")
45 #define DISCARD(string) string = ABSENT_STRING
46 #define PRINTF (void) printf
54 static int tversion; /* terminfo version */
55 static int outform; /* output format to use */
56 static int sortmode; /* sort mode to use */
57 static int width = 60; /* max line width for listings */
58 static int column; /* current column, limited by 'width' */
59 static int oldcol; /* last value of column before wrap */
60 static bool pretty; /* true if we format if-then-else strings */
62 static char *save_sgr;
67 /* indirection pointers for implementing sort and display modes */
68 static const PredIdx *bool_indirect, *num_indirect, *str_indirect;
69 static NCURSES_CONST char *const *bool_names;
70 static NCURSES_CONST char *const *num_names;
71 static NCURSES_CONST char *const *str_names;
73 static const char *separator, *trailer;
75 /* cover various ports and variants of terminfo */
76 #define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */
77 #define V_SVR1 1 /* SVR1, Ultrix */
78 #define V_HPUX 2 /* HP/UX */
79 #define V_AIX 3 /* AIX */
80 #define V_BSD 4 /* BSD */
83 #define OBSOLETE(n) (!_nc_user_definable && (n[0] == 'O' && n[1] == 'T'))
85 #define OBSOLETE(n) (n[0] == 'O' && n[1] == 'T')
88 #define isObsolete(f,n) ((f == F_TERMINFO || f == F_VARIABLE) && OBSOLETE(n))
91 #define BoolIndirect(j) ((j >= BOOLCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : bool_indirect[j]))
92 #define NumIndirect(j) ((j >= NUMCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : num_indirect[j]))
93 #define StrIndirect(j) ((j >= STRCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : str_indirect[j]))
95 #define BoolIndirect(j) ((sortmode == S_NOSORT) ? (j) : bool_indirect[j])
96 #define NumIndirect(j) ((sortmode == S_NOSORT) ? (j) : num_indirect[j])
97 #define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
101 strncpy_DYN(DYNBUF * dst, const char *src, size_t need)
103 size_t want = need + dst->used + 1;
104 if (want > dst->size) {
105 dst->size += (want + 1024); /* be generous */
106 dst->text = typeRealloc(char, dst->size, dst->text);
108 (void) strncpy(dst->text + dst->used, src, need);
110 dst->text[dst->used] = 0;
114 strcpy_DYN(DYNBUF * dst, const char *src)
120 strncpy_DYN(dst, src, strlen(src));
136 _nc_leaks_dump_entry(void)
144 nametrans(const char *name)
145 /* translate a capability name from termcap to terminfo */
147 const struct name_table_entry *np;
149 if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
150 switch (np->nte_type) {
152 if (bool_from_termcap[np->nte_index])
153 return (boolcodes[np->nte_index]);
157 if (num_from_termcap[np->nte_index])
158 return (numcodes[np->nte_index]);
162 if (str_from_termcap[np->nte_index])
163 return (strcodes[np->nte_index]);
171 dump_init(const char *version, int mode, int sort, int twidth, int traceval,
173 /* set up for entry display */
180 tversion = V_ALLCAPS;
181 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
182 || !strcmp(version, "Ultrix"))
184 else if (!strcmp(version, "HP"))
186 else if (!strcmp(version, "AIX"))
188 else if (!strcmp(version, "BSD"))
191 tversion = V_ALLCAPS;
193 /* implement display modes */
194 switch (outform = mode) {
197 bool_names = boolnames;
198 num_names = numnames;
199 str_names = strnames;
200 separator = twidth ? ", " : ",";
205 bool_names = boolfnames;
206 num_names = numfnames;
207 str_names = strfnames;
208 separator = twidth ? ", " : ",";
214 bool_names = boolcodes;
215 num_names = numcodes;
216 str_names = strcodes;
222 /* implement sort modes */
223 switch (sortmode = sort) {
226 (void) fprintf(stderr,
227 "%s: sorting by term structure order\n", _nc_progname);
232 (void) fprintf(stderr,
233 "%s: sorting by terminfo name order\n", _nc_progname);
234 bool_indirect = bool_terminfo_sort;
235 num_indirect = num_terminfo_sort;
236 str_indirect = str_terminfo_sort;
241 (void) fprintf(stderr,
242 "%s: sorting by C variable order\n", _nc_progname);
243 bool_indirect = bool_variable_sort;
244 num_indirect = num_variable_sort;
245 str_indirect = str_variable_sort;
250 (void) fprintf(stderr,
251 "%s: sorting by termcap name order\n", _nc_progname);
252 bool_indirect = bool_termcap_sort;
253 num_indirect = num_termcap_sort;
254 str_indirect = str_termcap_sort;
259 (void) fprintf(stderr,
260 "%s: width = %d, tversion = %d, outform = %d\n",
261 _nc_progname, width, tversion, outform);
264 static TERMTYPE *cur_type;
267 dump_predicate(PredType type, PredIdx idx)
268 /* predicate function to use for ordinary decompilation */
272 return (cur_type->Booleans[idx] == FALSE)
273 ? FAIL : cur_type->Booleans[idx];
276 return (cur_type->Numbers[idx] == ABSENT_NUMERIC)
277 ? FAIL : cur_type->Numbers[idx];
280 return (cur_type->Strings[idx] != ABSENT_STRING)
284 return (FALSE); /* pacify compiler */
287 static void set_obsolete_termcaps(TERMTYPE *tp);
289 /* is this the index of a function key string? */
290 #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
293 * If we configure with a different Caps file, the offsets into the arrays
294 * will change. So we use an address expression.
296 #define BOOL_IDX(name) (&(name) - &(CUR Booleans[0]))
297 #define NUM_IDX(name) (&(name) - &(CUR Numbers[0]))
298 #define STR_IDX(name) (&(name) - &(CUR Strings[0]))
301 version_filter(PredType type, PredIdx idx)
302 /* filter out capabilities we may want to suppress */
305 case V_ALLCAPS: /* SVr4, XSI Curses */
308 case V_SVR1: /* System V Release 1, Ultrix */
311 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
313 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
315 return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE);
319 case V_HPUX: /* Hewlett-Packard */
322 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
324 return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE);
326 if (idx <= STR_IDX(prtr_non))
328 else if (FNKEY(idx)) /* function keys */
330 else if (idx == STR_IDX(plab_norm)
331 || idx == STR_IDX(label_on)
332 || idx == STR_IDX(label_off))
339 case V_AIX: /* AIX */
342 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
344 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
346 if (idx <= STR_IDX(prtr_non))
348 else if (FNKEY(idx)) /* function keys */
355 case V_BSD: /* BSD */
358 return bool_from_termcap[idx];
360 return num_from_termcap[idx];
362 return str_from_termcap[idx];
367 return (FALSE); /* pacify the compiler */
373 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
374 outbuf.text[--outbuf.used] = '\0';
382 strcpy_DYN(&outbuf, trailer);
387 wrap_concat(const char *src)
389 int need = strlen(src);
390 int want = strlen(separator) + need;
393 && column + want > width) {
396 strcpy_DYN(&outbuf, src);
397 strcpy_DYN(&outbuf, separator);
401 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
402 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
403 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
404 first += sizeof(sep_trail)-2
406 /* Returns the nominal length of the buffer assuming it is termcap format,
407 * i.e., the continuation sequence is treated as a single character ":".
409 * There are several implementations of termcap which read the text into a
410 * fixed-size buffer. Generally they strip the newlines from the text, but may
411 * not do it until after the buffer is read. Also, "tc=" resolution may be
412 * expanded in the same buffer. This function is useful for measuring the size
413 * of the best fixed-buffer implementation; the worst case may be much worse.
415 #ifdef TEST_TERMCAP_LENGTH
417 termcap_length(const char *src)
419 static const char pattern[] = ":\\\n\t:";
422 const char *const t = src + strlen(src);
424 while (*src != '\0') {
425 IGNORE_SEP_TRAIL(src, t, pattern);
432 #define termcap_length(src) strlen(src)
436 indent_DYN(DYNBUF * buffer, int level)
440 for (n = 0; n < level; n++)
441 strncpy_DYN(buffer, "\t", 1);
445 has_params(const char *src)
448 int len = strlen(src);
453 for (n = 0; n < len - 1; ++n) {
454 if (!strncmp(src + n, "%p", 2)) {
456 } else if (!strncmp(src + n, "%;", 2)) {
463 result = ((len > 50) && params);
469 fmt_complex(char *src, int level)
471 bool percent = FALSE;
472 bool params = has_params(src);
474 while (*src != '\0') {
478 strncpy_DYN(&tmpbuf, src++, 1);
484 case 't': /* "then" */
485 case 'e': /* "else" */
488 tmpbuf.text[tmpbuf.used - 1] = '\n';
489 /* treat a "%e" as else-if, on the same level */
491 indent_DYN(&tmpbuf, level);
492 strncpy_DYN(&tmpbuf, "%", 1);
493 strncpy_DYN(&tmpbuf, src, 1);
495 params = has_params(src);
496 if (!params && *src != '\0' && *src != '%') {
497 strncpy_DYN(&tmpbuf, "\n", 1);
498 indent_DYN(&tmpbuf, level + 1);
501 indent_DYN(&tmpbuf, level + 1);
502 strncpy_DYN(&tmpbuf, "%", 1);
503 strncpy_DYN(&tmpbuf, src, 1);
505 src = fmt_complex(src, level + 1);
506 if (*src != '\0' && *src != '%') {
507 strncpy_DYN(&tmpbuf, "\n", 1);
508 indent_DYN(&tmpbuf, level + 1);
510 } else if (level == 1) {
511 _nc_warning("%%%c without %%?", *src);
517 case ';': /* "endif" */
521 tmpbuf.text[tmpbuf.used - 1] = '\n';
522 indent_DYN(&tmpbuf, level);
523 strncpy_DYN(&tmpbuf, "%", 1);
524 strncpy_DYN(&tmpbuf, src++, 1);
527 _nc_warning("%%; without %%?");
531 if (percent && params) {
532 tmpbuf.text[tmpbuf.used - 1] = '\n';
533 indent_DYN(&tmpbuf, level + 1);
534 strncpy_DYN(&tmpbuf, "%", 1);
543 strncpy_DYN(&tmpbuf, src++, 1);
548 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
551 fmt_entry(TERMTYPE *tterm,
554 bool suppress_untranslatable,
559 char buffer[MAX_TERMINFO_LENGTH];
561 NCURSES_CONST char *name;
563 PredIdx num_bools = 0;
564 PredIdx num_values = 0;
565 PredIdx num_strings = 0;
568 #define WRAP_CONCAT \
569 wrap_concat(buffer); \
572 len = 12; /* terminfo file-header */
576 pred = dump_predicate;
579 strcpy_DYN(&outbuf, 0);
581 column = INDENT; /* FIXME: workaround to prevent empty lines */
583 strcpy_DYN(&outbuf, tterm->term_names);
584 strcpy_DYN(&outbuf, separator);
585 column = outbuf.used;
589 for_each_boolean(j, tterm) {
591 name = ExtBoolname(tterm, i, bool_names);
593 if (!version_filter(BOOLEAN, i))
595 else if (isObsolete(outform, name))
598 predval = pred(BOOLEAN, i);
599 if (predval != FAIL) {
600 (void) strcpy(buffer, name);
602 (void) strcat(buffer, "@");
603 else if (i + 1 > num_bools)
609 if (column != INDENT)
612 for_each_number(j, tterm) {
614 name = ExtNumname(tterm, i, num_names);
616 if (!version_filter(NUMBER, i))
618 else if (isObsolete(outform, name))
621 predval = pred(NUMBER, i);
622 if (predval != FAIL) {
623 if (tterm->Numbers[i] < 0) {
624 sprintf(buffer, "%s@", name);
626 sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
627 if (i + 1 > num_values)
634 if (column != INDENT)
639 + strlen(tterm->term_names) + 1;
645 if (outform == F_TERMCAP) {
646 if (termcap_reset != ABSENT_STRING) {
647 if (init_3string != ABSENT_STRING
648 && !strcmp(init_3string, termcap_reset))
649 DISCARD(init_3string);
651 if (reset_2string != ABSENT_STRING
652 && !strcmp(reset_2string, termcap_reset))
653 DISCARD(reset_2string);
657 for_each_string(j, tterm) {
659 name = ExtStrname(tterm, i, str_names);
660 capability = tterm->Strings[i];
662 if (!version_filter(STRING, i))
664 else if (isObsolete(outform, name))
669 * Extended names can be longer than 2 characters, but termcap programs
670 * cannot read those (filter them out).
672 if (outform == F_TERMCAP && (strlen(name) > 2))
676 if (outform == F_TERMCAP) {
678 * Some older versions of vi want rmir/smir to be defined
679 * for ich/ich1 to work. If they're not defined, force
680 * them to be output as defined and empty.
682 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
683 if (SAME_CAP(i, enter_insert_mode)
684 && enter_insert_mode == ABSENT_STRING) {
685 (void) strcpy(buffer, "im=");
690 if (SAME_CAP(i, exit_insert_mode)
691 && exit_insert_mode == ABSENT_STRING) {
692 (void) strcpy(buffer, "ei=");
698 * termcap applications such as screen will be confused if sgr0
699 * is translated to a string containing rmacs. Filter that out.
701 if (PRESENT(exit_attribute_mode)) {
702 if (SAME_CAP(i, exit_attribute_mode)) {
704 char *my_sgr = set_attributes;
706 set_attributes = save_sgr;
708 trimmed_sgr0 = _nc_trim_sgr0(tterm);
709 if (strcmp(capability, trimmed_sgr0))
710 capability = trimmed_sgr0;
712 set_attributes = my_sgr;
717 predval = pred(STRING, i);
720 if (predval != FAIL) {
721 if (capability != ABSENT_STRING
722 && i + 1 > num_strings)
725 if (!VALID_STRING(capability)) {
726 sprintf(buffer, "%s@", name);
728 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
729 int params = ((i < (int) SIZEOF(parametrized))
732 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
733 char *cv = _nc_infotocap(name, srccap, params);
736 if (outform == F_TCONVERR) {
737 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
739 } else if (suppress_untranslatable) {
742 char *s = srccap, *d = buffer;
743 sprintf(d, "..%s=", name);
745 while ((*d = *s++) != 0) {
749 } else if (*d == '\\') {
756 sprintf(buffer, "%s=%s", name, cv);
758 len += strlen(capability) + 1;
761 char *src = _nc_tic_expand(capability,
762 outform == F_TERMINFO, numbers);
764 strcpy_DYN(&tmpbuf, 0);
765 strcpy_DYN(&tmpbuf, name);
766 strcpy_DYN(&tmpbuf, "=");
768 && (outform == F_TERMINFO
769 || outform == F_VARIABLE)) {
772 strcpy_DYN(&tmpbuf, src);
774 len += strlen(capability) + 1;
775 wrap_concat(tmpbuf.text);
779 /* e.g., trimmed_sgr0 */
780 if (capability != tterm->Strings[i])
783 len += num_strings * 2;
786 * This piece of code should be an effective inverse of the functions
787 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
788 * Much more work should be done on this to support dumping termcaps.
790 if (tversion == V_HPUX) {
792 (void) sprintf(buffer, "meml=%s", memory_lock);
796 (void) sprintf(buffer, "memu=%s", memory_unlock);
799 } else if (tversion == V_AIX) {
800 if (VALID_STRING(acs_chars)) {
802 const char *acstrans = "lqkxjmwuvtn";
804 char *tp, *sp, boxchars[11];
807 for (cp = acstrans; *cp; cp++) {
808 sp = strchr(acs_chars, *cp);
819 (void) strcpy(buffer, "box1=");
820 (void) strcat(buffer, _nc_tic_expand(boxchars,
821 outform == F_TERMINFO, numbers));
828 * kludge: trim off trailer to avoid an extra blank line
829 * in infocmp -u output when there are no string differences
832 bool trimmed = FALSE;
835 && outbuf.text[j - 1] == '\t'
836 && outbuf.text[j - 2] == '\n') {
840 && outbuf.text[j - 1] == ':'
841 && outbuf.text[j - 2] == '\t'
842 && outbuf.text[j - 3] == '\n'
843 && outbuf.text[j - 4] == '\\') {
848 outbuf.text[outbuf.used] = '\0';
850 strcpy_DYN(&outbuf, " ");
854 fprintf(stderr, "num_bools = %d\n", num_bools);
855 fprintf(stderr, "num_values = %d\n", num_values);
856 fprintf(stderr, "num_strings = %d\n", num_strings);
857 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
858 tterm->term_names, len, outbuf.used, outbuf.text);
861 * Here's where we use infodump to trigger a more stringent length check
862 * for termcap-translation purposes.
863 * Return the length of the raw entry, without tc= expansions,
864 * It gives an idea of which entries are deadly to even *scan past*,
865 * as opposed to *use*.
867 return (infodump ? len : (int) termcap_length(outbuf.text));
871 kill_string(TERMTYPE *tterm, char *cap)
874 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
875 if (cap == tterm->Strings[n]) {
876 tterm->Strings[n] = ABSENT_STRING;
884 find_string(TERMTYPE *tterm, char *name)
887 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
888 if (version_filter(STRING, n)
889 && !strcmp(name, strnames[n])) {
890 char *cap = tterm->Strings[n];
891 if (VALID_STRING(cap)) {
897 return ABSENT_STRING;
901 * This is used to remove function-key labels from a termcap entry to
905 kill_labels(TERMTYPE *tterm, int target)
912 for (n = 0; n <= 10; ++n) {
913 sprintf(name, "lf%d", n);
914 if ((cap = find_string(tterm, name)) != ABSENT_STRING
915 && kill_string(tterm, cap)) {
916 target -= (strlen(cap) + 5);
926 * This is used to remove function-key definitions from a termcap entry to
930 kill_fkeys(TERMTYPE *tterm, int target)
937 for (n = 60; n >= 0; --n) {
938 sprintf(name, "kf%d", n);
939 if ((cap = find_string(tterm, name)) != ABSENT_STRING
940 && kill_string(tterm, cap)) {
941 target -= (strlen(cap) + 5);
951 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
952 * Also, since this is for termcap, we only care about the line-drawing map.
954 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
957 one_one_mapping(const char *mapping)
961 if (mapping != ABSENT_STRING) {
963 while (mapping[n] != '\0') {
964 if (isLine(mapping[n]) &&
965 mapping[n] != mapping[n + 1]) {
975 #define FMT_ENTRY() \
976 fmt_entry(tterm, pred, \
978 suppress_untranslatable, \
981 #define SHOW_WHY PRINTF
984 purged_acs(TERMTYPE *tterm)
988 if (VALID_STRING(acs_chars)) {
989 if (!one_one_mapping(acs_chars)) {
990 enter_alt_charset_mode = ABSENT_STRING;
991 exit_alt_charset_mode = ABSENT_STRING;
992 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1000 * Dump a single entry.
1003 dump_entry(TERMTYPE *tterm,
1004 bool suppress_untranslatable,
1009 TERMTYPE save_tterm;
1014 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1015 critlen = MAX_TERMCAP_LENGTH;
1016 legend = "older termcap";
1018 set_obsolete_termcaps(tterm);
1020 critlen = MAX_TERMINFO_LENGTH;
1021 legend = "terminfo";
1025 save_sgr = set_attributes;
1027 if (((len = FMT_ENTRY()) > critlen)
1030 save_tterm = *tterm;
1031 if (!suppress_untranslatable) {
1032 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1034 suppress_untranslatable = TRUE;
1036 if ((len = FMT_ENTRY()) > critlen) {
1038 * We pick on sgr because it's a nice long string capability that
1039 * is really just an optimization hack. Another good candidate is
1040 * acsc since it is both long and unused by BSD termcap.
1042 bool changed = FALSE;
1046 * Extended names are most likely function-key definitions. Drop
1050 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1051 const char *name = ExtStrname(tterm, n, strnames);
1053 if (VALID_STRING(tterm->Strings[n])) {
1054 set_attributes = ABSENT_STRING;
1055 /* we remove long names anyway - only report the short */
1056 if (strlen(name) <= 2) {
1057 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1062 if ((len = FMT_ENTRY()) <= critlen)
1067 if (VALID_STRING(set_attributes)) {
1068 set_attributes = ABSENT_STRING;
1069 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1073 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1074 if (purged_acs(tterm)) {
1075 acs_chars = ABSENT_STRING;
1076 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1081 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1082 int oldversion = tversion;
1085 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1090 && kill_labels(tterm, len - critlen)) {
1091 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1096 && kill_fkeys(tterm, len - critlen)) {
1097 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1101 if (len > critlen) {
1102 (void) fprintf(stderr,
1103 "warning: %s entry is %d bytes long\n",
1104 _nc_first_name(tterm->term_names),
1106 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1109 tversion = oldversion;
1111 set_attributes = save_sgr;
1112 *tterm = save_tterm;
1114 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1115 save_tterm = *tterm;
1116 if (purged_acs(tterm)) {
1119 *tterm = save_tterm;
1124 dump_uses(const char *name, bool infodump)
1125 /* dump "use=" clauses in the appropriate format */
1127 char buffer[MAX_TERMINFO_LENGTH];
1129 if (outform == F_TERMCAP || outform == F_TCONVERR)
1131 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
1132 wrap_concat(buffer);
1139 (void) fputs(outbuf.text, stdout);
1145 compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
1146 TERMTYPE *tp GCC_UNUSED,
1148 /* compare two entries */
1151 NCURSES_CONST char *name;
1154 fputs(" comparing booleans.\n", stdout);
1155 for_each_boolean(j, tp) {
1156 i = BoolIndirect(j);
1157 name = ExtBoolname(tp, i, bool_names);
1159 if (isObsolete(outform, name))
1162 (*hook) (CMP_BOOLEAN, i, name);
1166 fputs(" comparing numbers.\n", stdout);
1167 for_each_number(j, tp) {
1169 name = ExtNumname(tp, i, num_names);
1171 if (isObsolete(outform, name))
1174 (*hook) (CMP_NUMBER, i, name);
1178 fputs(" comparing strings.\n", stdout);
1179 for_each_string(j, tp) {
1181 name = ExtStrname(tp, i, str_names);
1183 if (isObsolete(outform, name))
1186 (*hook) (CMP_STRING, i, name);
1189 /* (void) fputs(" comparing use entries.\n", stdout); */
1190 (*hook) (CMP_USE, 0, "use");
1194 #define NOTSET(s) ((s) == 0)
1197 * This bit of legerdemain turns all the terminfo variable names into
1198 * references to locations in the arrays Booleans, Numbers, and Strings ---
1199 * precisely what's needed.
1205 set_obsolete_termcaps(TERMTYPE *tp)
1207 #include "capdefaults.c"
1211 * Convert an alternate-character-set string to canonical form: sorted and
1215 repair_acsc(TERMTYPE *tp)
1217 if (VALID_STRING(acs_chars)) {
1223 bool fix_needed = FALSE;
1225 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1226 target = acs_chars[n];
1227 if (source >= target) {
1232 if (acs_chars[n + 1])
1236 memset(mapped, 0, sizeof(mapped));
1237 for (n = 0; acs_chars[n] != 0; n++) {
1238 source = acs_chars[n];
1239 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1240 mapped[source] = target;
1246 for (n = m = 0; n < sizeof(mapped); n++) {
1249 acs_chars[m++] = mapped[n];
1253 acs_chars[m++] = extra; /* garbage in, garbage out */