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.88 2008/08/04 12:36:12 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 column; /* current column, limited by 'width' */
61 static int oldcol; /* last value of column before wrap */
62 static bool pretty; /* true if we format if-then-else strings */
64 static char *save_sgr;
69 /* indirection pointers for implementing sort and display modes */
70 static const PredIdx *bool_indirect, *num_indirect, *str_indirect;
71 static NCURSES_CONST char *const *bool_names;
72 static NCURSES_CONST char *const *num_names;
73 static NCURSES_CONST char *const *str_names;
75 static const char *separator, *trailer;
77 /* cover various ports and variants of terminfo */
78 #define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */
79 #define V_SVR1 1 /* SVR1, Ultrix */
80 #define V_HPUX 2 /* HP/UX */
81 #define V_AIX 3 /* AIX */
82 #define V_BSD 4 /* BSD */
85 #define OBSOLETE(n) (!_nc_user_definable && (n[0] == 'O' && n[1] == 'T'))
87 #define OBSOLETE(n) (n[0] == 'O' && n[1] == 'T')
90 #define isObsolete(f,n) ((f == F_TERMINFO || f == F_VARIABLE) && OBSOLETE(n))
93 #define BoolIndirect(j) ((j >= BOOLCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : bool_indirect[j]))
94 #define NumIndirect(j) ((j >= NUMCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : num_indirect[j]))
95 #define StrIndirect(j) ((j >= STRCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : str_indirect[j]))
97 #define BoolIndirect(j) ((sortmode == S_NOSORT) ? (j) : bool_indirect[j])
98 #define NumIndirect(j) ((sortmode == S_NOSORT) ? (j) : num_indirect[j])
99 #define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
103 strncpy_DYN(DYNBUF * dst, const char *src, size_t need)
105 size_t want = need + dst->used + 1;
106 if (want > dst->size) {
107 dst->size += (want + 1024); /* be generous */
108 dst->text = typeRealloc(char, dst->size, dst->text);
110 (void) strncpy(dst->text + dst->used, src, need);
112 dst->text[dst->used] = 0;
116 strcpy_DYN(DYNBUF * dst, const char *src)
122 strncpy_DYN(dst, src, strlen(src));
138 _nc_leaks_dump_entry(void)
145 #define NameTrans(check,result) \
146 if (OkIndex(np->nte_index, check) \
147 && check[np->nte_index]) \
148 return (result[np->nte_index])
151 nametrans(const char *name)
152 /* translate a capability name from termcap to terminfo */
154 const struct name_table_entry *np;
156 if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
157 switch (np->nte_type) {
159 NameTrans(bool_from_termcap, boolcodes);
163 NameTrans(num_from_termcap, numcodes);
167 NameTrans(str_from_termcap, strcodes);
175 dump_init(const char *version, int mode, int sort, int twidth, int traceval,
177 /* set up for entry display */
184 tversion = V_ALLCAPS;
185 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
186 || !strcmp(version, "Ultrix"))
188 else if (!strcmp(version, "HP"))
190 else if (!strcmp(version, "AIX"))
192 else if (!strcmp(version, "BSD"))
195 tversion = V_ALLCAPS;
197 /* implement display modes */
198 switch (outform = mode) {
201 bool_names = boolnames;
202 num_names = numnames;
203 str_names = strnames;
204 separator = twidth ? ", " : ",";
209 bool_names = boolfnames;
210 num_names = numfnames;
211 str_names = strfnames;
212 separator = twidth ? ", " : ",";
218 bool_names = boolcodes;
219 num_names = numcodes;
220 str_names = strcodes;
226 /* implement sort modes */
227 switch (sortmode = sort) {
230 (void) fprintf(stderr,
231 "%s: sorting by term structure order\n", _nc_progname);
236 (void) fprintf(stderr,
237 "%s: sorting by terminfo name order\n", _nc_progname);
238 bool_indirect = bool_terminfo_sort;
239 num_indirect = num_terminfo_sort;
240 str_indirect = str_terminfo_sort;
245 (void) fprintf(stderr,
246 "%s: sorting by C variable order\n", _nc_progname);
247 bool_indirect = bool_variable_sort;
248 num_indirect = num_variable_sort;
249 str_indirect = str_variable_sort;
254 (void) fprintf(stderr,
255 "%s: sorting by termcap name order\n", _nc_progname);
256 bool_indirect = bool_termcap_sort;
257 num_indirect = num_termcap_sort;
258 str_indirect = str_termcap_sort;
263 (void) fprintf(stderr,
264 "%s: width = %d, tversion = %d, outform = %d\n",
265 _nc_progname, width, tversion, outform);
268 static TERMTYPE *cur_type;
271 dump_predicate(PredType type, PredIdx idx)
272 /* predicate function to use for ordinary decompilation */
276 return (cur_type->Booleans[idx] == FALSE)
277 ? FAIL : cur_type->Booleans[idx];
280 return (cur_type->Numbers[idx] == ABSENT_NUMERIC)
281 ? FAIL : cur_type->Numbers[idx];
284 return (cur_type->Strings[idx] != ABSENT_STRING)
288 return (FALSE); /* pacify compiler */
291 static void set_obsolete_termcaps(TERMTYPE *tp);
293 /* is this the index of a function key string? */
294 #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
297 * If we configure with a different Caps file, the offsets into the arrays
298 * will change. So we use an address expression.
300 #define BOOL_IDX(name) (PredType) (&(name) - &(CUR Booleans[0]))
301 #define NUM_IDX(name) (PredType) (&(name) - &(CUR Numbers[0]))
302 #define STR_IDX(name) (PredType) (&(name) - &(CUR Strings[0]))
305 version_filter(PredType type, PredIdx idx)
306 /* filter out capabilities we may want to suppress */
309 case V_ALLCAPS: /* SVr4, XSI Curses */
312 case V_SVR1: /* System V Release 1, Ultrix */
315 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
317 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
319 return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE);
323 case V_HPUX: /* Hewlett-Packard */
326 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
328 return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE);
330 if (idx <= STR_IDX(prtr_non))
332 else if (FNKEY(idx)) /* function keys */
334 else if (idx == STR_IDX(plab_norm)
335 || idx == STR_IDX(label_on)
336 || idx == STR_IDX(label_off))
343 case V_AIX: /* AIX */
346 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
348 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
350 if (idx <= STR_IDX(prtr_non))
352 else if (FNKEY(idx)) /* function keys */
359 #define is_termcap(type) (OkIndex(idx, type##_from_termcap) && \
360 type##_from_termcap[idx])
362 case V_BSD: /* BSD */
365 return is_termcap(bool);
367 return is_termcap(num);
369 return is_termcap(str);
374 return (FALSE); /* pacify the compiler */
380 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
381 outbuf.text[--outbuf.used] = '\0';
389 strcpy_DYN(&outbuf, trailer);
394 wrap_concat(const char *src)
396 unsigned need = strlen(src);
397 unsigned want = strlen(separator) + need;
400 && column + (int) want > width) {
403 strcpy_DYN(&outbuf, src);
404 strcpy_DYN(&outbuf, separator);
405 column += (int) need;
408 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
409 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
410 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
411 first += sizeof(sep_trail)-2
413 /* Returns the nominal length of the buffer assuming it is termcap format,
414 * i.e., the continuation sequence is treated as a single character ":".
416 * There are several implementations of termcap which read the text into a
417 * fixed-size buffer. Generally they strip the newlines from the text, but may
418 * not do it until after the buffer is read. Also, "tc=" resolution may be
419 * expanded in the same buffer. This function is useful for measuring the size
420 * of the best fixed-buffer implementation; the worst case may be much worse.
422 #ifdef TEST_TERMCAP_LENGTH
424 termcap_length(const char *src)
426 static const char pattern[] = ":\\\n\t:";
429 const char *const t = src + strlen(src);
431 while (*src != '\0') {
432 IGNORE_SEP_TRAIL(src, t, pattern);
439 #define termcap_length(src) strlen(src)
443 indent_DYN(DYNBUF * buffer, int level)
447 for (n = 0; n < level; n++)
448 strncpy_DYN(buffer, "\t", 1);
452 has_params(const char *src)
455 int len = (int) strlen(src);
460 for (n = 0; n < len - 1; ++n) {
461 if (!strncmp(src + n, "%p", 2)) {
463 } else if (!strncmp(src + n, "%;", 2)) {
470 result = ((len > 50) && params);
476 fmt_complex(char *src, int level)
478 bool percent = FALSE;
479 bool params = has_params(src);
481 while (*src != '\0') {
485 strncpy_DYN(&tmpbuf, src++, 1);
491 case 't': /* "then" */
492 case 'e': /* "else" */
495 tmpbuf.text[tmpbuf.used - 1] = '\n';
496 /* treat a "%e" as else-if, on the same level */
498 indent_DYN(&tmpbuf, level);
499 strncpy_DYN(&tmpbuf, "%", 1);
500 strncpy_DYN(&tmpbuf, src, 1);
502 params = has_params(src);
503 if (!params && *src != '\0' && *src != '%') {
504 strncpy_DYN(&tmpbuf, "\n", 1);
505 indent_DYN(&tmpbuf, level + 1);
508 indent_DYN(&tmpbuf, level + 1);
509 strncpy_DYN(&tmpbuf, "%", 1);
510 strncpy_DYN(&tmpbuf, src, 1);
512 src = fmt_complex(src, level + 1);
513 if (*src != '\0' && *src != '%') {
514 strncpy_DYN(&tmpbuf, "\n", 1);
515 indent_DYN(&tmpbuf, level + 1);
517 } else if (level == 1) {
518 _nc_warning("%%%c without %%?", *src);
524 case ';': /* "endif" */
528 tmpbuf.text[tmpbuf.used - 1] = '\n';
529 indent_DYN(&tmpbuf, level);
530 strncpy_DYN(&tmpbuf, "%", 1);
531 strncpy_DYN(&tmpbuf, src++, 1);
534 _nc_warning("%%; without %%?");
538 if (percent && params) {
539 tmpbuf.text[tmpbuf.used - 1] = '\n';
540 indent_DYN(&tmpbuf, level + 1);
541 strncpy_DYN(&tmpbuf, "%", 1);
547 strncpy_DYN(&tmpbuf, "\\s", 2);
554 strncpy_DYN(&tmpbuf, src++, 1);
559 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
563 fmt_entry(TERMTYPE *tterm,
566 bool suppress_untranslatable,
571 char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP];
573 NCURSES_CONST char *name;
575 PredIdx num_bools = 0;
576 PredIdx num_values = 0;
577 PredIdx num_strings = 0;
580 #define WRAP_CONCAT \
581 wrap_concat(buffer); \
584 len = 12; /* terminfo file-header */
588 pred = dump_predicate;
591 strcpy_DYN(&outbuf, 0);
593 column = INDENT; /* FIXME: workaround to prevent empty lines */
595 strcpy_DYN(&outbuf, tterm->term_names);
596 strcpy_DYN(&outbuf, separator);
597 column = (int) outbuf.used;
601 for_each_boolean(j, tterm) {
603 name = ExtBoolname(tterm, i, bool_names);
604 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
606 if (!version_filter(BOOLEAN, i))
608 else if (isObsolete(outform, name))
611 predval = pred(BOOLEAN, i);
612 if (predval != FAIL) {
613 (void) strcpy(buffer, name);
615 (void) strcat(buffer, "@");
616 else if (i + 1 > num_bools)
622 if (column != INDENT)
625 for_each_number(j, tterm) {
627 name = ExtNumname(tterm, i, num_names);
628 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
630 if (!version_filter(NUMBER, i))
632 else if (isObsolete(outform, name))
635 predval = pred(NUMBER, i);
636 if (predval != FAIL) {
637 if (tterm->Numbers[i] < 0) {
638 sprintf(buffer, "%s@", name);
640 sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
641 if (i + 1 > num_values)
648 if (column != INDENT)
651 len += (int) (num_bools
653 + strlen(tterm->term_names) + 1);
659 if (outform == F_TERMCAP) {
660 if (termcap_reset != ABSENT_STRING) {
661 if (init_3string != ABSENT_STRING
662 && !strcmp(init_3string, termcap_reset))
663 DISCARD(init_3string);
665 if (reset_2string != ABSENT_STRING
666 && !strcmp(reset_2string, termcap_reset))
667 DISCARD(reset_2string);
671 for_each_string(j, tterm) {
673 name = ExtStrname(tterm, i, str_names);
674 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
676 capability = tterm->Strings[i];
678 if (!version_filter(STRING, i))
680 else if (isObsolete(outform, name))
685 * Extended names can be longer than 2 characters, but termcap programs
686 * cannot read those (filter them out).
688 if (outform == F_TERMCAP && (strlen(name) > 2))
692 if (outform == F_TERMCAP) {
694 * Some older versions of vi want rmir/smir to be defined
695 * for ich/ich1 to work. If they're not defined, force
696 * them to be output as defined and empty.
698 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
699 if (SAME_CAP(i, enter_insert_mode)
700 && enter_insert_mode == ABSENT_STRING) {
701 (void) strcpy(buffer, "im=");
706 if (SAME_CAP(i, exit_insert_mode)
707 && exit_insert_mode == ABSENT_STRING) {
708 (void) strcpy(buffer, "ei=");
714 * termcap applications such as screen will be confused if sgr0
715 * is translated to a string containing rmacs. Filter that out.
717 if (PRESENT(exit_attribute_mode)) {
718 if (SAME_CAP(i, exit_attribute_mode)) {
720 char *my_sgr = set_attributes;
722 set_attributes = save_sgr;
724 trimmed_sgr0 = _nc_trim_sgr0(tterm);
725 if (strcmp(capability, trimmed_sgr0))
726 capability = trimmed_sgr0;
728 set_attributes = my_sgr;
733 predval = pred(STRING, i);
736 if (predval != FAIL) {
737 if (capability != ABSENT_STRING
738 && i + 1 > num_strings)
741 if (!VALID_STRING(capability)) {
742 sprintf(buffer, "%s@", name);
744 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
745 int params = ((i < (int) SIZEOF(parametrized))
748 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
749 char *cv = _nc_infotocap(name, srccap, params);
752 if (outform == F_TCONVERR) {
753 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
755 } else if (suppress_untranslatable) {
758 char *s = srccap, *d = buffer;
759 sprintf(d, "..%s=", name);
761 while ((*d = *s++) != 0) {
765 } else if (*d == '\\') {
772 sprintf(buffer, "%s=%s", name, cv);
774 len += (int) strlen(capability) + 1;
777 char *src = _nc_tic_expand(capability,
778 outform == F_TERMINFO, numbers);
780 strcpy_DYN(&tmpbuf, 0);
781 strcpy_DYN(&tmpbuf, name);
782 strcpy_DYN(&tmpbuf, "=");
784 && (outform == F_TERMINFO
785 || outform == F_VARIABLE)) {
788 strcpy_DYN(&tmpbuf, src);
790 len += (int) strlen(capability) + 1;
791 wrap_concat(tmpbuf.text);
795 /* e.g., trimmed_sgr0 */
796 if (capability != tterm->Strings[i])
799 len += (int) (num_strings * 2);
802 * This piece of code should be an effective inverse of the functions
803 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
804 * Much more work should be done on this to support dumping termcaps.
806 if (tversion == V_HPUX) {
807 if (VALID_STRING(memory_lock)) {
808 (void) sprintf(buffer, "meml=%s", memory_lock);
811 if (VALID_STRING(memory_unlock)) {
812 (void) sprintf(buffer, "memu=%s", memory_unlock);
815 } else if (tversion == V_AIX) {
816 if (VALID_STRING(acs_chars)) {
818 const char *acstrans = "lqkxjmwuvtn";
820 char *tp, *sp, boxchars[11];
823 for (cp = acstrans; *cp; cp++) {
824 sp = strchr(acs_chars, *cp);
835 (void) strcpy(buffer, "box1=");
836 (void) strcat(buffer, _nc_tic_expand(boxchars,
837 outform == F_TERMINFO, numbers));
844 * kludge: trim off trailer to avoid an extra blank line
845 * in infocmp -u output when there are no string differences
848 bool trimmed = FALSE;
851 && outbuf.text[j - 1] == '\t'
852 && outbuf.text[j - 2] == '\n') {
856 && outbuf.text[j - 1] == ':'
857 && outbuf.text[j - 2] == '\t'
858 && outbuf.text[j - 3] == '\n'
859 && outbuf.text[j - 4] == '\\') {
864 outbuf.text[outbuf.used] = '\0';
866 strcpy_DYN(&outbuf, " ");
870 fprintf(stderr, "num_bools = %d\n", num_bools);
871 fprintf(stderr, "num_values = %d\n", num_values);
872 fprintf(stderr, "num_strings = %d\n", num_strings);
873 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
874 tterm->term_names, len, outbuf.used, outbuf.text);
877 * Here's where we use infodump to trigger a more stringent length check
878 * for termcap-translation purposes.
879 * Return the length of the raw entry, without tc= expansions,
880 * It gives an idea of which entries are deadly to even *scan past*,
881 * as opposed to *use*.
883 return (infodump ? len : (int) termcap_length(outbuf.text));
887 kill_string(TERMTYPE *tterm, char *cap)
890 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
891 if (cap == tterm->Strings[n]) {
892 tterm->Strings[n] = ABSENT_STRING;
900 find_string(TERMTYPE *tterm, char *name)
903 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
904 if (version_filter(STRING, n)
905 && !strcmp(name, strnames[n])) {
906 char *cap = tterm->Strings[n];
907 if (VALID_STRING(cap)) {
913 return ABSENT_STRING;
917 * This is used to remove function-key labels from a termcap entry to
921 kill_labels(TERMTYPE *tterm, int target)
928 for (n = 0; n <= 10; ++n) {
929 sprintf(name, "lf%d", n);
930 if ((cap = find_string(tterm, name)) != ABSENT_STRING
931 && kill_string(tterm, cap)) {
932 target -= (int) (strlen(cap) + 5);
942 * This is used to remove function-key definitions from a termcap entry to
946 kill_fkeys(TERMTYPE *tterm, int target)
953 for (n = 60; n >= 0; --n) {
954 sprintf(name, "kf%d", n);
955 if ((cap = find_string(tterm, name)) != ABSENT_STRING
956 && kill_string(tterm, cap)) {
957 target -= (int) (strlen(cap) + 5);
967 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
968 * Also, since this is for termcap, we only care about the line-drawing map.
970 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
973 one_one_mapping(const char *mapping)
977 if (mapping != ABSENT_STRING) {
979 while (mapping[n] != '\0') {
980 if (isLine(mapping[n]) &&
981 mapping[n] != mapping[n + 1]) {
991 #define FMT_ENTRY() \
992 fmt_entry(tterm, pred, \
994 suppress_untranslatable, \
997 #define SHOW_WHY PRINTF
1000 purged_acs(TERMTYPE *tterm)
1002 bool result = FALSE;
1004 if (VALID_STRING(acs_chars)) {
1005 if (!one_one_mapping(acs_chars)) {
1006 enter_alt_charset_mode = ABSENT_STRING;
1007 exit_alt_charset_mode = ABSENT_STRING;
1008 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1016 * Dump a single entry.
1019 dump_entry(TERMTYPE *tterm,
1020 bool suppress_untranslatable,
1025 TERMTYPE save_tterm;
1030 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1031 critlen = MAX_TERMCAP_LENGTH;
1032 legend = "older termcap";
1034 set_obsolete_termcaps(tterm);
1036 critlen = MAX_TERMINFO_LENGTH;
1037 legend = "terminfo";
1041 save_sgr = set_attributes;
1043 if (((len = FMT_ENTRY()) > critlen)
1046 save_tterm = *tterm;
1047 if (!suppress_untranslatable) {
1048 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1050 suppress_untranslatable = TRUE;
1052 if ((len = FMT_ENTRY()) > critlen) {
1054 * We pick on sgr because it's a nice long string capability that
1055 * is really just an optimization hack. Another good candidate is
1056 * acsc since it is both long and unused by BSD termcap.
1058 bool changed = FALSE;
1062 * Extended names are most likely function-key definitions. Drop
1066 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1067 const char *name = ExtStrname(tterm, n, strnames);
1069 if (VALID_STRING(tterm->Strings[n])) {
1070 set_attributes = ABSENT_STRING;
1071 /* we remove long names anyway - only report the short */
1072 if (strlen(name) <= 2) {
1073 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1078 if ((len = FMT_ENTRY()) <= critlen)
1083 if (VALID_STRING(set_attributes)) {
1084 set_attributes = ABSENT_STRING;
1085 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1089 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1090 if (purged_acs(tterm)) {
1091 acs_chars = ABSENT_STRING;
1092 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1097 if (!changed || ((len = FMT_ENTRY()) > critlen)) {
1098 int oldversion = tversion;
1101 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1106 && kill_labels(tterm, len - critlen)) {
1107 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1112 && kill_fkeys(tterm, len - critlen)) {
1113 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1117 if (len > critlen) {
1118 (void) fprintf(stderr,
1119 "warning: %s entry is %d bytes long\n",
1120 _nc_first_name(tterm->term_names),
1122 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1125 tversion = oldversion;
1127 set_attributes = save_sgr;
1128 *tterm = save_tterm;
1130 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1131 save_tterm = *tterm;
1132 if (purged_acs(tterm)) {
1135 *tterm = save_tterm;
1140 dump_uses(const char *name, bool infodump)
1141 /* dump "use=" clauses in the appropriate format */
1143 char buffer[MAX_TERMINFO_LENGTH];
1145 if (outform == F_TERMCAP || outform == F_TCONVERR)
1147 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
1148 wrap_concat(buffer);
1155 (void) fputs(outbuf.text, stdout);
1157 return (int) outbuf.used;
1161 compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
1162 TERMTYPE *tp GCC_UNUSED,
1164 /* compare two entries */
1167 NCURSES_CONST char *name;
1170 fputs(" comparing booleans.\n", stdout);
1171 for_each_boolean(j, tp) {
1172 i = BoolIndirect(j);
1173 name = ExtBoolname(tp, i, bool_names);
1175 if (isObsolete(outform, name))
1178 (*hook) (CMP_BOOLEAN, i, name);
1182 fputs(" comparing numbers.\n", stdout);
1183 for_each_number(j, tp) {
1185 name = ExtNumname(tp, i, num_names);
1187 if (isObsolete(outform, name))
1190 (*hook) (CMP_NUMBER, i, name);
1194 fputs(" comparing strings.\n", stdout);
1195 for_each_string(j, tp) {
1197 name = ExtStrname(tp, i, str_names);
1199 if (isObsolete(outform, name))
1202 (*hook) (CMP_STRING, i, name);
1205 /* (void) fputs(" comparing use entries.\n", stdout); */
1206 (*hook) (CMP_USE, 0, "use");
1210 #define NOTSET(s) ((s) == 0)
1213 * This bit of legerdemain turns all the terminfo variable names into
1214 * references to locations in the arrays Booleans, Numbers, and Strings ---
1215 * precisely what's needed.
1221 set_obsolete_termcaps(TERMTYPE *tp)
1223 #include "capdefaults.c"
1227 * Convert an alternate-character-set string to canonical form: sorted and
1231 repair_acsc(TERMTYPE *tp)
1233 if (VALID_STRING(acs_chars)) {
1239 bool fix_needed = FALSE;
1241 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1242 target = UChar(acs_chars[n]);
1243 if (source >= target) {
1248 if (acs_chars[n + 1])
1252 memset(mapped, 0, sizeof(mapped));
1253 for (n = 0; acs_chars[n] != 0; n++) {
1254 source = UChar(acs_chars[n]);
1255 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1256 mapped[source] = (char) target;
1259 extra = (char) source;
1262 for (n = m = 0; n < sizeof(mapped); n++) {
1264 acs_chars[m++] = (char) n;
1265 acs_chars[m++] = mapped[n];
1269 acs_chars[m++] = extra; /* garbage in, garbage out */