1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.82 2008/04/19 22:27:04 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 #define is_termcap(type) (idx < (int) sizeof(type##_from_termcap) && \
356 type##_from_termcap[idx])
358 case V_BSD: /* BSD */
361 return is_termcap(bool);
363 return is_termcap(num);
365 return is_termcap(str);
370 return (FALSE); /* pacify the compiler */
376 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
377 outbuf.text[--outbuf.used] = '\0';
385 strcpy_DYN(&outbuf, trailer);
390 wrap_concat(const char *src)
392 int need = strlen(src);
393 int want = strlen(separator) + need;
396 && column + want > width) {
399 strcpy_DYN(&outbuf, src);
400 strcpy_DYN(&outbuf, separator);
404 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
405 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
406 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
407 first += sizeof(sep_trail)-2
409 /* Returns the nominal length of the buffer assuming it is termcap format,
410 * i.e., the continuation sequence is treated as a single character ":".
412 * There are several implementations of termcap which read the text into a
413 * fixed-size buffer. Generally they strip the newlines from the text, but may
414 * not do it until after the buffer is read. Also, "tc=" resolution may be
415 * expanded in the same buffer. This function is useful for measuring the size
416 * of the best fixed-buffer implementation; the worst case may be much worse.
418 #ifdef TEST_TERMCAP_LENGTH
420 termcap_length(const char *src)
422 static const char pattern[] = ":\\\n\t:";
425 const char *const t = src + strlen(src);
427 while (*src != '\0') {
428 IGNORE_SEP_TRAIL(src, t, pattern);
435 #define termcap_length(src) strlen(src)
439 indent_DYN(DYNBUF * buffer, int level)
443 for (n = 0; n < level; n++)
444 strncpy_DYN(buffer, "\t", 1);
448 has_params(const char *src)
451 int len = strlen(src);
456 for (n = 0; n < len - 1; ++n) {
457 if (!strncmp(src + n, "%p", 2)) {
459 } else if (!strncmp(src + n, "%;", 2)) {
466 result = ((len > 50) && params);
472 fmt_complex(char *src, int level)
474 bool percent = FALSE;
475 bool params = has_params(src);
477 while (*src != '\0') {
481 strncpy_DYN(&tmpbuf, src++, 1);
487 case 't': /* "then" */
488 case 'e': /* "else" */
491 tmpbuf.text[tmpbuf.used - 1] = '\n';
492 /* treat a "%e" as else-if, on the same level */
494 indent_DYN(&tmpbuf, level);
495 strncpy_DYN(&tmpbuf, "%", 1);
496 strncpy_DYN(&tmpbuf, src, 1);
498 params = has_params(src);
499 if (!params && *src != '\0' && *src != '%') {
500 strncpy_DYN(&tmpbuf, "\n", 1);
501 indent_DYN(&tmpbuf, level + 1);
504 indent_DYN(&tmpbuf, level + 1);
505 strncpy_DYN(&tmpbuf, "%", 1);
506 strncpy_DYN(&tmpbuf, src, 1);
508 src = fmt_complex(src, level + 1);
509 if (*src != '\0' && *src != '%') {
510 strncpy_DYN(&tmpbuf, "\n", 1);
511 indent_DYN(&tmpbuf, level + 1);
513 } else if (level == 1) {
514 _nc_warning("%%%c without %%?", *src);
520 case ';': /* "endif" */
524 tmpbuf.text[tmpbuf.used - 1] = '\n';
525 indent_DYN(&tmpbuf, level);
526 strncpy_DYN(&tmpbuf, "%", 1);
527 strncpy_DYN(&tmpbuf, src++, 1);
530 _nc_warning("%%; without %%?");
534 if (percent && params) {
535 tmpbuf.text[tmpbuf.used - 1] = '\n';
536 indent_DYN(&tmpbuf, level + 1);
537 strncpy_DYN(&tmpbuf, "%", 1);
543 strncpy_DYN(&tmpbuf, "\\s", 2);
550 strncpy_DYN(&tmpbuf, src++, 1);
555 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
558 fmt_entry(TERMTYPE *tterm,
561 bool suppress_untranslatable,
566 char buffer[MAX_TERMINFO_LENGTH];
568 NCURSES_CONST char *name;
570 PredIdx num_bools = 0;
571 PredIdx num_values = 0;
572 PredIdx num_strings = 0;
575 #define WRAP_CONCAT \
576 wrap_concat(buffer); \
579 len = 12; /* terminfo file-header */
583 pred = dump_predicate;
586 strcpy_DYN(&outbuf, 0);
588 column = INDENT; /* FIXME: workaround to prevent empty lines */
590 strcpy_DYN(&outbuf, tterm->term_names);
591 strcpy_DYN(&outbuf, separator);
592 column = outbuf.used;
596 for_each_boolean(j, tterm) {
598 name = ExtBoolname(tterm, i, bool_names);
600 if (!version_filter(BOOLEAN, i))
602 else if (isObsolete(outform, name))
605 predval = pred(BOOLEAN, i);
606 if (predval != FAIL) {
607 (void) strcpy(buffer, name);
609 (void) strcat(buffer, "@");
610 else if (i + 1 > num_bools)
616 if (column != INDENT)
619 for_each_number(j, tterm) {
621 name = ExtNumname(tterm, i, num_names);
623 if (!version_filter(NUMBER, i))
625 else if (isObsolete(outform, name))
628 predval = pred(NUMBER, i);
629 if (predval != FAIL) {
630 if (tterm->Numbers[i] < 0) {
631 sprintf(buffer, "%s@", name);
633 sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
634 if (i + 1 > num_values)
641 if (column != INDENT)
646 + strlen(tterm->term_names) + 1;
652 if (outform == F_TERMCAP) {
653 if (termcap_reset != ABSENT_STRING) {
654 if (init_3string != ABSENT_STRING
655 && !strcmp(init_3string, termcap_reset))
656 DISCARD(init_3string);
658 if (reset_2string != ABSENT_STRING
659 && !strcmp(reset_2string, termcap_reset))
660 DISCARD(reset_2string);
664 for_each_string(j, tterm) {
666 name = ExtStrname(tterm, i, str_names);
667 capability = tterm->Strings[i];
669 if (!version_filter(STRING, i))
671 else if (isObsolete(outform, name))
676 * Extended names can be longer than 2 characters, but termcap programs
677 * cannot read those (filter them out).
679 if (outform == F_TERMCAP && (strlen(name) > 2))
683 if (outform == F_TERMCAP) {
685 * Some older versions of vi want rmir/smir to be defined
686 * for ich/ich1 to work. If they're not defined, force
687 * them to be output as defined and empty.
689 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
690 if (SAME_CAP(i, enter_insert_mode)
691 && enter_insert_mode == ABSENT_STRING) {
692 (void) strcpy(buffer, "im=");
697 if (SAME_CAP(i, exit_insert_mode)
698 && exit_insert_mode == ABSENT_STRING) {
699 (void) strcpy(buffer, "ei=");
705 * termcap applications such as screen will be confused if sgr0
706 * is translated to a string containing rmacs. Filter that out.
708 if (PRESENT(exit_attribute_mode)) {
709 if (SAME_CAP(i, exit_attribute_mode)) {
711 char *my_sgr = set_attributes;
713 set_attributes = save_sgr;
715 trimmed_sgr0 = _nc_trim_sgr0(tterm);
716 if (strcmp(capability, trimmed_sgr0))
717 capability = trimmed_sgr0;
719 set_attributes = my_sgr;
724 predval = pred(STRING, i);
727 if (predval != FAIL) {
728 if (capability != ABSENT_STRING
729 && i + 1 > num_strings)
732 if (!VALID_STRING(capability)) {
733 sprintf(buffer, "%s@", name);
735 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
736 int params = ((i < (int) SIZEOF(parametrized))
739 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
740 char *cv = _nc_infotocap(name, srccap, params);
743 if (outform == F_TCONVERR) {
744 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
746 } else if (suppress_untranslatable) {
749 char *s = srccap, *d = buffer;
750 sprintf(d, "..%s=", name);
752 while ((*d = *s++) != 0) {
756 } else if (*d == '\\') {
763 sprintf(buffer, "%s=%s", name, cv);
765 len += strlen(capability) + 1;
768 char *src = _nc_tic_expand(capability,
769 outform == F_TERMINFO, numbers);
771 strcpy_DYN(&tmpbuf, 0);
772 strcpy_DYN(&tmpbuf, name);
773 strcpy_DYN(&tmpbuf, "=");
775 && (outform == F_TERMINFO
776 || outform == F_VARIABLE)) {
779 strcpy_DYN(&tmpbuf, src);
781 len += strlen(capability) + 1;
782 wrap_concat(tmpbuf.text);
786 /* e.g., trimmed_sgr0 */
787 if (capability != tterm->Strings[i])
790 len += num_strings * 2;
793 * This piece of code should be an effective inverse of the functions
794 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
795 * Much more work should be done on this to support dumping termcaps.
797 if (tversion == V_HPUX) {
798 if (VALID_STRING(memory_lock)) {
799 (void) sprintf(buffer, "meml=%s", memory_lock);
802 if (VALID_STRING(memory_unlock)) {
803 (void) sprintf(buffer, "memu=%s", memory_unlock);
806 } else if (tversion == V_AIX) {
807 if (VALID_STRING(acs_chars)) {
809 const char *acstrans = "lqkxjmwuvtn";
811 char *tp, *sp, boxchars[11];
814 for (cp = acstrans; *cp; cp++) {
815 sp = strchr(acs_chars, *cp);
826 (void) strcpy(buffer, "box1=");
827 (void) strcat(buffer, _nc_tic_expand(boxchars,
828 outform == F_TERMINFO, numbers));
835 * kludge: trim off trailer to avoid an extra blank line
836 * in infocmp -u output when there are no string differences
839 bool trimmed = FALSE;
842 && outbuf.text[j - 1] == '\t'
843 && outbuf.text[j - 2] == '\n') {
847 && outbuf.text[j - 1] == ':'
848 && outbuf.text[j - 2] == '\t'
849 && outbuf.text[j - 3] == '\n'
850 && outbuf.text[j - 4] == '\\') {
855 outbuf.text[outbuf.used] = '\0';
857 strcpy_DYN(&outbuf, " ");
861 fprintf(stderr, "num_bools = %d\n", num_bools);
862 fprintf(stderr, "num_values = %d\n", num_values);
863 fprintf(stderr, "num_strings = %d\n", num_strings);
864 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
865 tterm->term_names, len, outbuf.used, outbuf.text);
868 * Here's where we use infodump to trigger a more stringent length check
869 * for termcap-translation purposes.
870 * Return the length of the raw entry, without tc= expansions,
871 * It gives an idea of which entries are deadly to even *scan past*,
872 * as opposed to *use*.
874 return (infodump ? len : (int) termcap_length(outbuf.text));
878 kill_string(TERMTYPE *tterm, char *cap)
881 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
882 if (cap == tterm->Strings[n]) {
883 tterm->Strings[n] = ABSENT_STRING;
891 find_string(TERMTYPE *tterm, char *name)
894 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
895 if (version_filter(STRING, n)
896 && !strcmp(name, strnames[n])) {
897 char *cap = tterm->Strings[n];
898 if (VALID_STRING(cap)) {
904 return ABSENT_STRING;
908 * This is used to remove function-key labels from a termcap entry to
912 kill_labels(TERMTYPE *tterm, int target)
919 for (n = 0; n <= 10; ++n) {
920 sprintf(name, "lf%d", n);
921 if ((cap = find_string(tterm, name)) != ABSENT_STRING
922 && kill_string(tterm, cap)) {
923 target -= (strlen(cap) + 5);
933 * This is used to remove function-key definitions from a termcap entry to
937 kill_fkeys(TERMTYPE *tterm, int target)
944 for (n = 60; n >= 0; --n) {
945 sprintf(name, "kf%d", n);
946 if ((cap = find_string(tterm, name)) != ABSENT_STRING
947 && kill_string(tterm, cap)) {
948 target -= (strlen(cap) + 5);
958 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
959 * Also, since this is for termcap, we only care about the line-drawing map.
961 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
964 one_one_mapping(const char *mapping)
968 if (mapping != ABSENT_STRING) {
970 while (mapping[n] != '\0') {
971 if (isLine(mapping[n]) &&
972 mapping[n] != mapping[n + 1]) {
982 #define FMT_ENTRY() \
983 fmt_entry(tterm, pred, \
985 suppress_untranslatable, \
988 #define SHOW_WHY PRINTF
991 purged_acs(TERMTYPE *tterm)
995 if (VALID_STRING(acs_chars)) {
996 if (!one_one_mapping(acs_chars)) {
997 enter_alt_charset_mode = ABSENT_STRING;
998 exit_alt_charset_mode = ABSENT_STRING;
999 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1007 * Dump a single entry.
1010 dump_entry(TERMTYPE *tterm,
1011 bool suppress_untranslatable,
1016 TERMTYPE save_tterm;
1021 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1022 critlen = MAX_TERMCAP_LENGTH;
1023 legend = "older termcap";
1025 set_obsolete_termcaps(tterm);
1027 critlen = MAX_TERMINFO_LENGTH;
1028 legend = "terminfo";
1032 save_sgr = set_attributes;
1034 if (((len = FMT_ENTRY()) > critlen)
1037 save_tterm = *tterm;
1038 if (!suppress_untranslatable) {
1039 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1041 suppress_untranslatable = TRUE;
1043 if ((len = FMT_ENTRY()) > critlen) {
1045 * We pick on sgr because it's a nice long string capability that
1046 * is really just an optimization hack. Another good candidate is
1047 * acsc since it is both long and unused by BSD termcap.
1049 bool changed = FALSE;
1053 * Extended names are most likely function-key definitions. Drop
1057 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1058 const char *name = ExtStrname(tterm, n, strnames);
1060 if (VALID_STRING(tterm->Strings[n])) {
1061 set_attributes = ABSENT_STRING;
1062 /* we remove long names anyway - only report the short */
1063 if (strlen(name) <= 2) {
1064 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1069 if ((len = FMT_ENTRY()) <= critlen)
1074 if (VALID_STRING(set_attributes)) {
1075 set_attributes = ABSENT_STRING;
1076 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1080 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1081 if (purged_acs(tterm)) {
1082 acs_chars = ABSENT_STRING;
1083 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1088 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1089 int oldversion = tversion;
1092 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1097 && kill_labels(tterm, len - critlen)) {
1098 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1103 && kill_fkeys(tterm, len - critlen)) {
1104 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1108 if (len > critlen) {
1109 (void) fprintf(stderr,
1110 "warning: %s entry is %d bytes long\n",
1111 _nc_first_name(tterm->term_names),
1113 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1116 tversion = oldversion;
1118 set_attributes = save_sgr;
1119 *tterm = save_tterm;
1121 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1122 save_tterm = *tterm;
1123 if (purged_acs(tterm)) {
1126 *tterm = save_tterm;
1131 dump_uses(const char *name, bool infodump)
1132 /* dump "use=" clauses in the appropriate format */
1134 char buffer[MAX_TERMINFO_LENGTH];
1136 if (outform == F_TERMCAP || outform == F_TCONVERR)
1138 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
1139 wrap_concat(buffer);
1146 (void) fputs(outbuf.text, stdout);
1152 compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
1153 TERMTYPE *tp GCC_UNUSED,
1155 /* compare two entries */
1158 NCURSES_CONST char *name;
1161 fputs(" comparing booleans.\n", stdout);
1162 for_each_boolean(j, tp) {
1163 i = BoolIndirect(j);
1164 name = ExtBoolname(tp, i, bool_names);
1166 if (isObsolete(outform, name))
1169 (*hook) (CMP_BOOLEAN, i, name);
1173 fputs(" comparing numbers.\n", stdout);
1174 for_each_number(j, tp) {
1176 name = ExtNumname(tp, i, num_names);
1178 if (isObsolete(outform, name))
1181 (*hook) (CMP_NUMBER, i, name);
1185 fputs(" comparing strings.\n", stdout);
1186 for_each_string(j, tp) {
1188 name = ExtStrname(tp, i, str_names);
1190 if (isObsolete(outform, name))
1193 (*hook) (CMP_STRING, i, name);
1196 /* (void) fputs(" comparing use entries.\n", stdout); */
1197 (*hook) (CMP_USE, 0, "use");
1201 #define NOTSET(s) ((s) == 0)
1204 * This bit of legerdemain turns all the terminfo variable names into
1205 * references to locations in the arrays Booleans, Numbers, and Strings ---
1206 * precisely what's needed.
1212 set_obsolete_termcaps(TERMTYPE *tp)
1214 #include "capdefaults.c"
1218 * Convert an alternate-character-set string to canonical form: sorted and
1222 repair_acsc(TERMTYPE *tp)
1224 if (VALID_STRING(acs_chars)) {
1230 bool fix_needed = FALSE;
1232 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1233 target = UChar(acs_chars[n]);
1234 if (source >= target) {
1239 if (acs_chars[n + 1])
1243 memset(mapped, 0, sizeof(mapped));
1244 for (n = 0; acs_chars[n] != 0; n++) {
1245 source = UChar(acs_chars[n]);
1246 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1247 mapped[source] = target;
1253 for (n = m = 0; n < sizeof(mapped); n++) {
1256 acs_chars[m++] = mapped[n];
1260 acs_chars[m++] = extra; /* garbage in, garbage out */