1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 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.81 2007/08/25 20:05:35 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);
546 strncpy_DYN(&tmpbuf, src++, 1);
551 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
554 fmt_entry(TERMTYPE *tterm,
557 bool suppress_untranslatable,
562 char buffer[MAX_TERMINFO_LENGTH];
564 NCURSES_CONST char *name;
566 PredIdx num_bools = 0;
567 PredIdx num_values = 0;
568 PredIdx num_strings = 0;
571 #define WRAP_CONCAT \
572 wrap_concat(buffer); \
575 len = 12; /* terminfo file-header */
579 pred = dump_predicate;
582 strcpy_DYN(&outbuf, 0);
584 column = INDENT; /* FIXME: workaround to prevent empty lines */
586 strcpy_DYN(&outbuf, tterm->term_names);
587 strcpy_DYN(&outbuf, separator);
588 column = outbuf.used;
592 for_each_boolean(j, tterm) {
594 name = ExtBoolname(tterm, i, bool_names);
596 if (!version_filter(BOOLEAN, i))
598 else if (isObsolete(outform, name))
601 predval = pred(BOOLEAN, i);
602 if (predval != FAIL) {
603 (void) strcpy(buffer, name);
605 (void) strcat(buffer, "@");
606 else if (i + 1 > num_bools)
612 if (column != INDENT)
615 for_each_number(j, tterm) {
617 name = ExtNumname(tterm, i, num_names);
619 if (!version_filter(NUMBER, i))
621 else if (isObsolete(outform, name))
624 predval = pred(NUMBER, i);
625 if (predval != FAIL) {
626 if (tterm->Numbers[i] < 0) {
627 sprintf(buffer, "%s@", name);
629 sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
630 if (i + 1 > num_values)
637 if (column != INDENT)
642 + strlen(tterm->term_names) + 1;
648 if (outform == F_TERMCAP) {
649 if (termcap_reset != ABSENT_STRING) {
650 if (init_3string != ABSENT_STRING
651 && !strcmp(init_3string, termcap_reset))
652 DISCARD(init_3string);
654 if (reset_2string != ABSENT_STRING
655 && !strcmp(reset_2string, termcap_reset))
656 DISCARD(reset_2string);
660 for_each_string(j, tterm) {
662 name = ExtStrname(tterm, i, str_names);
663 capability = tterm->Strings[i];
665 if (!version_filter(STRING, i))
667 else if (isObsolete(outform, name))
672 * Extended names can be longer than 2 characters, but termcap programs
673 * cannot read those (filter them out).
675 if (outform == F_TERMCAP && (strlen(name) > 2))
679 if (outform == F_TERMCAP) {
681 * Some older versions of vi want rmir/smir to be defined
682 * for ich/ich1 to work. If they're not defined, force
683 * them to be output as defined and empty.
685 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
686 if (SAME_CAP(i, enter_insert_mode)
687 && enter_insert_mode == ABSENT_STRING) {
688 (void) strcpy(buffer, "im=");
693 if (SAME_CAP(i, exit_insert_mode)
694 && exit_insert_mode == ABSENT_STRING) {
695 (void) strcpy(buffer, "ei=");
701 * termcap applications such as screen will be confused if sgr0
702 * is translated to a string containing rmacs. Filter that out.
704 if (PRESENT(exit_attribute_mode)) {
705 if (SAME_CAP(i, exit_attribute_mode)) {
707 char *my_sgr = set_attributes;
709 set_attributes = save_sgr;
711 trimmed_sgr0 = _nc_trim_sgr0(tterm);
712 if (strcmp(capability, trimmed_sgr0))
713 capability = trimmed_sgr0;
715 set_attributes = my_sgr;
720 predval = pred(STRING, i);
723 if (predval != FAIL) {
724 if (capability != ABSENT_STRING
725 && i + 1 > num_strings)
728 if (!VALID_STRING(capability)) {
729 sprintf(buffer, "%s@", name);
731 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
732 int params = ((i < (int) SIZEOF(parametrized))
735 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
736 char *cv = _nc_infotocap(name, srccap, params);
739 if (outform == F_TCONVERR) {
740 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
742 } else if (suppress_untranslatable) {
745 char *s = srccap, *d = buffer;
746 sprintf(d, "..%s=", name);
748 while ((*d = *s++) != 0) {
752 } else if (*d == '\\') {
759 sprintf(buffer, "%s=%s", name, cv);
761 len += strlen(capability) + 1;
764 char *src = _nc_tic_expand(capability,
765 outform == F_TERMINFO, numbers);
767 strcpy_DYN(&tmpbuf, 0);
768 strcpy_DYN(&tmpbuf, name);
769 strcpy_DYN(&tmpbuf, "=");
771 && (outform == F_TERMINFO
772 || outform == F_VARIABLE)) {
775 strcpy_DYN(&tmpbuf, src);
777 len += strlen(capability) + 1;
778 wrap_concat(tmpbuf.text);
782 /* e.g., trimmed_sgr0 */
783 if (capability != tterm->Strings[i])
786 len += num_strings * 2;
789 * This piece of code should be an effective inverse of the functions
790 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
791 * Much more work should be done on this to support dumping termcaps.
793 if (tversion == V_HPUX) {
794 if (VALID_STRING(memory_lock)) {
795 (void) sprintf(buffer, "meml=%s", memory_lock);
798 if (VALID_STRING(memory_unlock)) {
799 (void) sprintf(buffer, "memu=%s", memory_unlock);
802 } else if (tversion == V_AIX) {
803 if (VALID_STRING(acs_chars)) {
805 const char *acstrans = "lqkxjmwuvtn";
807 char *tp, *sp, boxchars[11];
810 for (cp = acstrans; *cp; cp++) {
811 sp = strchr(acs_chars, *cp);
822 (void) strcpy(buffer, "box1=");
823 (void) strcat(buffer, _nc_tic_expand(boxchars,
824 outform == F_TERMINFO, numbers));
831 * kludge: trim off trailer to avoid an extra blank line
832 * in infocmp -u output when there are no string differences
835 bool trimmed = FALSE;
838 && outbuf.text[j - 1] == '\t'
839 && outbuf.text[j - 2] == '\n') {
843 && outbuf.text[j - 1] == ':'
844 && outbuf.text[j - 2] == '\t'
845 && outbuf.text[j - 3] == '\n'
846 && outbuf.text[j - 4] == '\\') {
851 outbuf.text[outbuf.used] = '\0';
853 strcpy_DYN(&outbuf, " ");
857 fprintf(stderr, "num_bools = %d\n", num_bools);
858 fprintf(stderr, "num_values = %d\n", num_values);
859 fprintf(stderr, "num_strings = %d\n", num_strings);
860 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
861 tterm->term_names, len, outbuf.used, outbuf.text);
864 * Here's where we use infodump to trigger a more stringent length check
865 * for termcap-translation purposes.
866 * Return the length of the raw entry, without tc= expansions,
867 * It gives an idea of which entries are deadly to even *scan past*,
868 * as opposed to *use*.
870 return (infodump ? len : (int) termcap_length(outbuf.text));
874 kill_string(TERMTYPE *tterm, char *cap)
877 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
878 if (cap == tterm->Strings[n]) {
879 tterm->Strings[n] = ABSENT_STRING;
887 find_string(TERMTYPE *tterm, char *name)
890 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
891 if (version_filter(STRING, n)
892 && !strcmp(name, strnames[n])) {
893 char *cap = tterm->Strings[n];
894 if (VALID_STRING(cap)) {
900 return ABSENT_STRING;
904 * This is used to remove function-key labels from a termcap entry to
908 kill_labels(TERMTYPE *tterm, int target)
915 for (n = 0; n <= 10; ++n) {
916 sprintf(name, "lf%d", n);
917 if ((cap = find_string(tterm, name)) != ABSENT_STRING
918 && kill_string(tterm, cap)) {
919 target -= (strlen(cap) + 5);
929 * This is used to remove function-key definitions from a termcap entry to
933 kill_fkeys(TERMTYPE *tterm, int target)
940 for (n = 60; n >= 0; --n) {
941 sprintf(name, "kf%d", n);
942 if ((cap = find_string(tterm, name)) != ABSENT_STRING
943 && kill_string(tterm, cap)) {
944 target -= (strlen(cap) + 5);
954 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
955 * Also, since this is for termcap, we only care about the line-drawing map.
957 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
960 one_one_mapping(const char *mapping)
964 if (mapping != ABSENT_STRING) {
966 while (mapping[n] != '\0') {
967 if (isLine(mapping[n]) &&
968 mapping[n] != mapping[n + 1]) {
978 #define FMT_ENTRY() \
979 fmt_entry(tterm, pred, \
981 suppress_untranslatable, \
984 #define SHOW_WHY PRINTF
987 purged_acs(TERMTYPE *tterm)
991 if (VALID_STRING(acs_chars)) {
992 if (!one_one_mapping(acs_chars)) {
993 enter_alt_charset_mode = ABSENT_STRING;
994 exit_alt_charset_mode = ABSENT_STRING;
995 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1003 * Dump a single entry.
1006 dump_entry(TERMTYPE *tterm,
1007 bool suppress_untranslatable,
1012 TERMTYPE save_tterm;
1017 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1018 critlen = MAX_TERMCAP_LENGTH;
1019 legend = "older termcap";
1021 set_obsolete_termcaps(tterm);
1023 critlen = MAX_TERMINFO_LENGTH;
1024 legend = "terminfo";
1028 save_sgr = set_attributes;
1030 if (((len = FMT_ENTRY()) > critlen)
1033 save_tterm = *tterm;
1034 if (!suppress_untranslatable) {
1035 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1037 suppress_untranslatable = TRUE;
1039 if ((len = FMT_ENTRY()) > critlen) {
1041 * We pick on sgr because it's a nice long string capability that
1042 * is really just an optimization hack. Another good candidate is
1043 * acsc since it is both long and unused by BSD termcap.
1045 bool changed = FALSE;
1049 * Extended names are most likely function-key definitions. Drop
1053 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1054 const char *name = ExtStrname(tterm, n, strnames);
1056 if (VALID_STRING(tterm->Strings[n])) {
1057 set_attributes = ABSENT_STRING;
1058 /* we remove long names anyway - only report the short */
1059 if (strlen(name) <= 2) {
1060 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1065 if ((len = FMT_ENTRY()) <= critlen)
1070 if (VALID_STRING(set_attributes)) {
1071 set_attributes = ABSENT_STRING;
1072 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1076 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1077 if (purged_acs(tterm)) {
1078 acs_chars = ABSENT_STRING;
1079 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1084 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1085 int oldversion = tversion;
1088 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1093 && kill_labels(tterm, len - critlen)) {
1094 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1099 && kill_fkeys(tterm, len - critlen)) {
1100 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1104 if (len > critlen) {
1105 (void) fprintf(stderr,
1106 "warning: %s entry is %d bytes long\n",
1107 _nc_first_name(tterm->term_names),
1109 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1112 tversion = oldversion;
1114 set_attributes = save_sgr;
1115 *tterm = save_tterm;
1117 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1118 save_tterm = *tterm;
1119 if (purged_acs(tterm)) {
1122 *tterm = save_tterm;
1127 dump_uses(const char *name, bool infodump)
1128 /* dump "use=" clauses in the appropriate format */
1130 char buffer[MAX_TERMINFO_LENGTH];
1132 if (outform == F_TERMCAP || outform == F_TCONVERR)
1134 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
1135 wrap_concat(buffer);
1142 (void) fputs(outbuf.text, stdout);
1148 compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
1149 TERMTYPE *tp GCC_UNUSED,
1151 /* compare two entries */
1154 NCURSES_CONST char *name;
1157 fputs(" comparing booleans.\n", stdout);
1158 for_each_boolean(j, tp) {
1159 i = BoolIndirect(j);
1160 name = ExtBoolname(tp, i, bool_names);
1162 if (isObsolete(outform, name))
1165 (*hook) (CMP_BOOLEAN, i, name);
1169 fputs(" comparing numbers.\n", stdout);
1170 for_each_number(j, tp) {
1172 name = ExtNumname(tp, i, num_names);
1174 if (isObsolete(outform, name))
1177 (*hook) (CMP_NUMBER, i, name);
1181 fputs(" comparing strings.\n", stdout);
1182 for_each_string(j, tp) {
1184 name = ExtStrname(tp, i, str_names);
1186 if (isObsolete(outform, name))
1189 (*hook) (CMP_STRING, i, name);
1192 /* (void) fputs(" comparing use entries.\n", stdout); */
1193 (*hook) (CMP_USE, 0, "use");
1197 #define NOTSET(s) ((s) == 0)
1200 * This bit of legerdemain turns all the terminfo variable names into
1201 * references to locations in the arrays Booleans, Numbers, and Strings ---
1202 * precisely what's needed.
1208 set_obsolete_termcaps(TERMTYPE *tp)
1210 #include "capdefaults.c"
1214 * Convert an alternate-character-set string to canonical form: sorted and
1218 repair_acsc(TERMTYPE *tp)
1220 if (VALID_STRING(acs_chars)) {
1226 bool fix_needed = FALSE;
1228 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1229 target = UChar(acs_chars[n]);
1230 if (source >= target) {
1235 if (acs_chars[n + 1])
1239 memset(mapped, 0, sizeof(mapped));
1240 for (n = 0; acs_chars[n] != 0; n++) {
1241 source = UChar(acs_chars[n]);
1242 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1243 mapped[source] = target;
1249 for (n = m = 0; n < sizeof(mapped); n++) {
1252 acs_chars[m++] = mapped[n];
1256 acs_chars[m++] = extra; /* garbage in, garbage out */