1 /****************************************************************************
2 * Copyright (c) 1998-2010,2011 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.91 2011/05/14 22:39:21 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,
181 /* set up for entry display */
188 tversion = V_ALLCAPS;
189 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
190 || !strcmp(version, "Ultrix"))
192 else if (!strcmp(version, "HP"))
194 else if (!strcmp(version, "AIX"))
196 else if (!strcmp(version, "BSD"))
199 tversion = V_ALLCAPS;
201 /* implement display modes */
202 switch (outform = mode) {
205 bool_names = boolnames;
206 num_names = numnames;
207 str_names = strnames;
208 separator = twidth ? ", " : ",";
213 bool_names = boolfnames;
214 num_names = numfnames;
215 str_names = strfnames;
216 separator = twidth ? ", " : ",";
222 bool_names = boolcodes;
223 num_names = numcodes;
224 str_names = strcodes;
230 /* implement sort modes */
231 switch (sortmode = sort) {
234 (void) fprintf(stderr,
235 "%s: sorting by term structure order\n", _nc_progname);
240 (void) fprintf(stderr,
241 "%s: sorting by terminfo name order\n", _nc_progname);
242 bool_indirect = bool_terminfo_sort;
243 num_indirect = num_terminfo_sort;
244 str_indirect = str_terminfo_sort;
249 (void) fprintf(stderr,
250 "%s: sorting by C variable order\n", _nc_progname);
251 bool_indirect = bool_variable_sort;
252 num_indirect = num_variable_sort;
253 str_indirect = str_variable_sort;
258 (void) fprintf(stderr,
259 "%s: sorting by termcap name order\n", _nc_progname);
260 bool_indirect = bool_termcap_sort;
261 num_indirect = num_termcap_sort;
262 str_indirect = str_termcap_sort;
267 (void) fprintf(stderr,
268 "%s: width = %d, tversion = %d, outform = %d\n",
269 _nc_progname, width, tversion, outform);
272 static TERMTYPE *cur_type;
275 dump_predicate(PredType type, PredIdx idx)
276 /* predicate function to use for ordinary decompilation */
280 return (cur_type->Booleans[idx] == FALSE)
281 ? FAIL : cur_type->Booleans[idx];
284 return (cur_type->Numbers[idx] == ABSENT_NUMERIC)
285 ? FAIL : cur_type->Numbers[idx];
288 return (cur_type->Strings[idx] != ABSENT_STRING)
292 return (FALSE); /* pacify compiler */
295 static void set_obsolete_termcaps(TERMTYPE *tp);
297 /* is this the index of a function key string? */
298 #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
301 * If we configure with a different Caps file, the offsets into the arrays
302 * will change. So we use an address expression.
304 #define BOOL_IDX(name) (PredType) (&(name) - &(CUR Booleans[0]))
305 #define NUM_IDX(name) (PredType) (&(name) - &(CUR Numbers[0]))
306 #define STR_IDX(name) (PredType) (&(name) - &(CUR Strings[0]))
309 version_filter(PredType type, PredIdx idx)
310 /* filter out capabilities we may want to suppress */
313 case V_ALLCAPS: /* SVr4, XSI Curses */
316 case V_SVR1: /* System V Release 1, Ultrix */
319 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
321 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
323 return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE);
327 case V_HPUX: /* Hewlett-Packard */
330 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
332 return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE);
334 if (idx <= STR_IDX(prtr_non))
336 else if (FNKEY(idx)) /* function keys */
338 else if (idx == STR_IDX(plab_norm)
339 || idx == STR_IDX(label_on)
340 || idx == STR_IDX(label_off))
347 case V_AIX: /* AIX */
350 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
352 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
354 if (idx <= STR_IDX(prtr_non))
356 else if (FNKEY(idx)) /* function keys */
363 #define is_termcap(type) (OkIndex(idx, type##_from_termcap) && \
364 type##_from_termcap[idx])
366 case V_BSD: /* BSD */
369 return is_termcap(bool);
371 return is_termcap(num);
373 return is_termcap(str);
378 return (FALSE); /* pacify the compiler */
384 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
385 outbuf.text[--outbuf.used] = '\0';
393 strcpy_DYN(&outbuf, trailer);
398 wrap_concat(const char *src)
400 size_t need = strlen(src);
401 size_t want = strlen(separator) + need;
404 && column + (int) want > width) {
407 strcpy_DYN(&outbuf, src);
408 strcpy_DYN(&outbuf, separator);
409 column += (int) need;
412 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
413 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
414 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
415 first += sizeof(sep_trail)-2
417 /* Returns the nominal length of the buffer assuming it is termcap format,
418 * i.e., the continuation sequence is treated as a single character ":".
420 * There are several implementations of termcap which read the text into a
421 * fixed-size buffer. Generally they strip the newlines from the text, but may
422 * not do it until after the buffer is read. Also, "tc=" resolution may be
423 * expanded in the same buffer. This function is useful for measuring the size
424 * of the best fixed-buffer implementation; the worst case may be much worse.
426 #ifdef TEST_TERMCAP_LENGTH
428 termcap_length(const char *src)
430 static const char pattern[] = ":\\\n\t:";
433 const char *const t = src + strlen(src);
435 while (*src != '\0') {
436 IGNORE_SEP_TRAIL(src, t, pattern);
443 #define termcap_length(src) strlen(src)
447 indent_DYN(DYNBUF * buffer, int level)
451 for (n = 0; n < level; n++)
452 strncpy_DYN(buffer, "\t", 1);
456 has_params(const char *src)
459 int len = (int) strlen(src);
464 for (n = 0; n < len - 1; ++n) {
465 if (!strncmp(src + n, "%p", 2)) {
467 } else if (!strncmp(src + n, "%;", 2)) {
474 result = ((len > 50) && params);
480 fmt_complex(char *src, int level)
482 bool percent = FALSE;
483 bool params = has_params(src);
485 while (*src != '\0') {
489 strncpy_DYN(&tmpbuf, src++, 1);
495 case 't': /* "then" */
496 case 'e': /* "else" */
499 tmpbuf.text[tmpbuf.used - 1] = '\n';
500 /* treat a "%e" as else-if, on the same level */
502 indent_DYN(&tmpbuf, level);
503 strncpy_DYN(&tmpbuf, "%", 1);
504 strncpy_DYN(&tmpbuf, src, 1);
506 params = has_params(src);
507 if (!params && *src != '\0' && *src != '%') {
508 strncpy_DYN(&tmpbuf, "\n", 1);
509 indent_DYN(&tmpbuf, level + 1);
512 indent_DYN(&tmpbuf, level + 1);
513 strncpy_DYN(&tmpbuf, "%", 1);
514 strncpy_DYN(&tmpbuf, src, 1);
516 src = fmt_complex(src, level + 1);
517 if (*src != '\0' && *src != '%') {
518 strncpy_DYN(&tmpbuf, "\n", 1);
519 indent_DYN(&tmpbuf, level + 1);
521 } else if (level == 1) {
522 _nc_warning("%%%c without %%?", *src);
528 case ';': /* "endif" */
532 tmpbuf.text[tmpbuf.used - 1] = '\n';
533 indent_DYN(&tmpbuf, level);
534 strncpy_DYN(&tmpbuf, "%", 1);
535 strncpy_DYN(&tmpbuf, src++, 1);
538 _nc_warning("%%; without %%?");
542 if (percent && params) {
543 tmpbuf.text[tmpbuf.used - 1] = '\n';
544 indent_DYN(&tmpbuf, level + 1);
545 strncpy_DYN(&tmpbuf, "%", 1);
551 strncpy_DYN(&tmpbuf, "\\s", 2);
558 strncpy_DYN(&tmpbuf, src++, 1);
563 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
567 fmt_entry(TERMTYPE *tterm,
570 bool suppress_untranslatable,
575 char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP];
577 NCURSES_CONST char *name;
579 PredIdx num_bools = 0;
580 PredIdx num_values = 0;
581 PredIdx num_strings = 0;
584 #define WRAP_CONCAT \
585 wrap_concat(buffer); \
588 len = 12; /* terminfo file-header */
592 pred = dump_predicate;
595 strcpy_DYN(&outbuf, 0);
597 column = INDENT; /* FIXME: workaround to prevent empty lines */
599 strcpy_DYN(&outbuf, tterm->term_names);
600 strcpy_DYN(&outbuf, separator);
601 column = (int) outbuf.used;
605 for_each_boolean(j, tterm) {
607 name = ExtBoolname(tterm, (int) i, bool_names);
608 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
610 if (!version_filter(BOOLEAN, i))
612 else if (isObsolete(outform, name))
615 predval = pred(BOOLEAN, i);
616 if (predval != FAIL) {
617 (void) strcpy(buffer, name);
619 (void) strcat(buffer, "@");
620 else if (i + 1 > num_bools)
626 if (column != INDENT)
629 for_each_number(j, tterm) {
631 name = ExtNumname(tterm, (int) i, num_names);
632 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
634 if (!version_filter(NUMBER, i))
636 else if (isObsolete(outform, name))
639 predval = pred(NUMBER, i);
640 if (predval != FAIL) {
641 if (tterm->Numbers[i] < 0) {
642 sprintf(buffer, "%s@", name);
644 sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
645 if (i + 1 > num_values)
652 if (column != INDENT)
655 len += (int) (num_bools
657 + strlen(tterm->term_names) + 1);
663 if (outform == F_TERMCAP) {
664 if (termcap_reset != ABSENT_STRING) {
665 if (init_3string != ABSENT_STRING
666 && !strcmp(init_3string, termcap_reset))
667 DISCARD(init_3string);
669 if (reset_2string != ABSENT_STRING
670 && !strcmp(reset_2string, termcap_reset))
671 DISCARD(reset_2string);
675 for_each_string(j, tterm) {
677 name = ExtStrname(tterm, (int) i, str_names);
678 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
680 capability = tterm->Strings[i];
682 if (!version_filter(STRING, i))
684 else if (isObsolete(outform, name))
689 * Extended names can be longer than 2 characters, but termcap programs
690 * cannot read those (filter them out).
692 if (outform == F_TERMCAP && (strlen(name) > 2))
696 if (outform == F_TERMCAP) {
698 * Some older versions of vi want rmir/smir to be defined
699 * for ich/ich1 to work. If they're not defined, force
700 * them to be output as defined and empty.
702 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
703 if (SAME_CAP(i, enter_insert_mode)
704 && enter_insert_mode == ABSENT_STRING) {
705 (void) strcpy(buffer, "im=");
710 if (SAME_CAP(i, exit_insert_mode)
711 && exit_insert_mode == ABSENT_STRING) {
712 (void) strcpy(buffer, "ei=");
718 * termcap applications such as screen will be confused if sgr0
719 * is translated to a string containing rmacs. Filter that out.
721 if (PRESENT(exit_attribute_mode)) {
722 if (SAME_CAP(i, exit_attribute_mode)) {
724 char *my_sgr = set_attributes;
726 set_attributes = save_sgr;
728 trimmed_sgr0 = _nc_trim_sgr0(tterm);
729 if (strcmp(capability, trimmed_sgr0))
730 capability = trimmed_sgr0;
732 set_attributes = my_sgr;
737 predval = pred(STRING, i);
740 if (predval != FAIL) {
741 if (capability != ABSENT_STRING
742 && i + 1 > num_strings)
745 if (!VALID_STRING(capability)) {
746 sprintf(buffer, "%s@", name);
748 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
749 int params = ((i < (int) SIZEOF(parametrized))
752 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
753 char *cv = _nc_infotocap(name, srccap, params);
756 if (outform == F_TCONVERR) {
757 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",
759 } else if (suppress_untranslatable) {
762 char *s = srccap, *d = buffer;
763 sprintf(d, "..%s=", name);
765 while ((*d = *s++) != 0) {
769 } else if (*d == '\\') {
776 sprintf(buffer, "%s=%s", name, cv);
778 len += (int) strlen(capability) + 1;
781 char *src = _nc_tic_expand(capability,
782 outform == F_TERMINFO, numbers);
784 strcpy_DYN(&tmpbuf, 0);
785 strcpy_DYN(&tmpbuf, name);
786 strcpy_DYN(&tmpbuf, "=");
788 && (outform == F_TERMINFO
789 || outform == F_VARIABLE)) {
792 strcpy_DYN(&tmpbuf, src);
794 len += (int) strlen(capability) + 1;
795 wrap_concat(tmpbuf.text);
799 /* e.g., trimmed_sgr0 */
800 if (capability != tterm->Strings[i])
803 len += (int) (num_strings * 2);
806 * This piece of code should be an effective inverse of the functions
807 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
808 * Much more work should be done on this to support dumping termcaps.
810 if (tversion == V_HPUX) {
811 if (VALID_STRING(memory_lock)) {
812 (void) sprintf(buffer, "meml=%s", memory_lock);
815 if (VALID_STRING(memory_unlock)) {
816 (void) sprintf(buffer, "memu=%s", memory_unlock);
819 } else if (tversion == V_AIX) {
820 if (VALID_STRING(acs_chars)) {
822 const char *acstrans = "lqkxjmwuvtn";
824 char *tp, *sp, boxchars[11];
827 for (cp = acstrans; *cp; cp++) {
828 sp = strchr(acs_chars, *cp);
839 (void) strcpy(buffer, "box1=");
840 (void) strcat(buffer, _nc_tic_expand(boxchars,
841 outform == F_TERMINFO, numbers));
848 * kludge: trim off trailer to avoid an extra blank line
849 * in infocmp -u output when there are no string differences
852 bool trimmed = FALSE;
853 j = (PredIdx) outbuf.used;
855 && outbuf.text[j - 1] == '\t'
856 && outbuf.text[j - 2] == '\n') {
860 && outbuf.text[j - 1] == ':'
861 && outbuf.text[j - 2] == '\t'
862 && outbuf.text[j - 3] == '\n'
863 && outbuf.text[j - 4] == '\\') {
868 outbuf.text[outbuf.used] = '\0';
870 strcpy_DYN(&outbuf, " ");
874 fprintf(stderr, "num_bools = %d\n", num_bools);
875 fprintf(stderr, "num_values = %d\n", num_values);
876 fprintf(stderr, "num_strings = %d\n", num_strings);
877 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
878 tterm->term_names, len, outbuf.used, outbuf.text);
881 * Here's where we use infodump to trigger a more stringent length check
882 * for termcap-translation purposes.
883 * Return the length of the raw entry, without tc= expansions,
884 * It gives an idea of which entries are deadly to even *scan past*,
885 * as opposed to *use*.
887 return (infodump ? len : (int) termcap_length(outbuf.text));
891 kill_string(TERMTYPE *tterm, char *cap)
894 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
895 if (cap == tterm->Strings[n]) {
896 tterm->Strings[n] = ABSENT_STRING;
904 find_string(TERMTYPE *tterm, char *name)
907 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
908 if (version_filter(STRING, n)
909 && !strcmp(name, strnames[n])) {
910 char *cap = tterm->Strings[n];
911 if (VALID_STRING(cap)) {
917 return ABSENT_STRING;
921 * This is used to remove function-key labels from a termcap entry to
925 kill_labels(TERMTYPE *tterm, int target)
932 for (n = 0; n <= 10; ++n) {
933 sprintf(name, "lf%d", n);
934 if ((cap = find_string(tterm, name)) != ABSENT_STRING
935 && kill_string(tterm, cap)) {
936 target -= (int) (strlen(cap) + 5);
946 * This is used to remove function-key definitions from a termcap entry to
950 kill_fkeys(TERMTYPE *tterm, int target)
957 for (n = 60; n >= 0; --n) {
958 sprintf(name, "kf%d", n);
959 if ((cap = find_string(tterm, name)) != ABSENT_STRING
960 && kill_string(tterm, cap)) {
961 target -= (int) (strlen(cap) + 5);
971 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
972 * Also, since this is for termcap, we only care about the line-drawing map.
974 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
977 one_one_mapping(const char *mapping)
981 if (mapping != ABSENT_STRING) {
983 while (mapping[n] != '\0') {
984 if (isLine(mapping[n]) &&
985 mapping[n] != mapping[n + 1]) {
995 #define FMT_ENTRY() \
996 fmt_entry(tterm, pred, \
998 suppress_untranslatable, \
1001 #define SHOW_WHY PRINTF
1004 purged_acs(TERMTYPE *tterm)
1006 bool result = FALSE;
1008 if (VALID_STRING(acs_chars)) {
1009 if (!one_one_mapping(acs_chars)) {
1010 enter_alt_charset_mode = ABSENT_STRING;
1011 exit_alt_charset_mode = ABSENT_STRING;
1012 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1020 * Dump a single entry.
1023 dump_entry(TERMTYPE *tterm,
1024 bool suppress_untranslatable,
1029 TERMTYPE save_tterm;
1034 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1035 critlen = MAX_TERMCAP_LENGTH;
1036 legend = "older termcap";
1038 set_obsolete_termcaps(tterm);
1040 critlen = MAX_TERMINFO_LENGTH;
1041 legend = "terminfo";
1045 save_sgr = set_attributes;
1047 if ((FMT_ENTRY() > critlen)
1050 save_tterm = *tterm;
1051 if (!suppress_untranslatable) {
1052 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1054 suppress_untranslatable = TRUE;
1056 if (FMT_ENTRY() > critlen) {
1058 * We pick on sgr because it's a nice long string capability that
1059 * is really just an optimization hack. Another good candidate is
1060 * acsc since it is both long and unused by BSD termcap.
1062 bool changed = FALSE;
1066 * Extended names are most likely function-key definitions. Drop
1070 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1071 const char *name = ExtStrname(tterm, (int) n, strnames);
1073 if (VALID_STRING(tterm->Strings[n])) {
1074 set_attributes = ABSENT_STRING;
1075 /* we remove long names anyway - only report the short */
1076 if (strlen(name) <= 2) {
1077 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1082 if (FMT_ENTRY() <= critlen)
1087 if (VALID_STRING(set_attributes)) {
1088 set_attributes = ABSENT_STRING;
1089 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1093 if (!changed || (FMT_ENTRY() > critlen)) {
1094 if (purged_acs(tterm)) {
1095 acs_chars = ABSENT_STRING;
1096 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1101 if (!changed || (FMT_ENTRY() > critlen)) {
1102 int oldversion = tversion;
1105 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1110 && kill_labels(tterm, len - critlen)) {
1111 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1116 && kill_fkeys(tterm, len - critlen)) {
1117 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1121 if (len > critlen) {
1122 (void) fprintf(stderr,
1123 "warning: %s entry is %d bytes long\n",
1124 _nc_first_name(tterm->term_names),
1126 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1129 tversion = oldversion;
1131 set_attributes = save_sgr;
1132 *tterm = save_tterm;
1134 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1135 save_tterm = *tterm;
1136 if (purged_acs(tterm)) {
1139 *tterm = save_tterm;
1144 dump_uses(const char *name, bool infodump)
1145 /* dump "use=" clauses in the appropriate format */
1147 char buffer[MAX_TERMINFO_LENGTH];
1149 if (outform == F_TERMCAP || outform == F_TCONVERR)
1151 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
1152 wrap_concat(buffer);
1159 (void) fputs(outbuf.text, stdout);
1161 return (int) outbuf.used;
1165 compare_entry(PredHook hook,
1166 TERMTYPE *tp GCC_UNUSED,
1168 /* compare two entries */
1171 NCURSES_CONST char *name;
1174 fputs(" comparing booleans.\n", stdout);
1175 for_each_boolean(j, tp) {
1176 i = BoolIndirect(j);
1177 name = ExtBoolname(tp, (int) i, bool_names);
1179 if (isObsolete(outform, name))
1182 (*hook) (CMP_BOOLEAN, i, name);
1186 fputs(" comparing numbers.\n", stdout);
1187 for_each_number(j, tp) {
1189 name = ExtNumname(tp, (int) i, num_names);
1191 if (isObsolete(outform, name))
1194 (*hook) (CMP_NUMBER, i, name);
1198 fputs(" comparing strings.\n", stdout);
1199 for_each_string(j, tp) {
1201 name = ExtStrname(tp, (int) i, str_names);
1203 if (isObsolete(outform, name))
1206 (*hook) (CMP_STRING, i, name);
1209 /* (void) fputs(" comparing use entries.\n", stdout); */
1210 (*hook) (CMP_USE, 0, "use");
1214 #define NOTSET(s) ((s) == 0)
1217 * This bit of legerdemain turns all the terminfo variable names into
1218 * references to locations in the arrays Booleans, Numbers, and Strings ---
1219 * precisely what's needed.
1225 set_obsolete_termcaps(TERMTYPE *tp)
1227 #include "capdefaults.c"
1231 * Convert an alternate-character-set string to canonical form: sorted and
1235 repair_acsc(TERMTYPE *tp)
1237 if (VALID_STRING(acs_chars)) {
1243 bool fix_needed = FALSE;
1245 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1246 target = UChar(acs_chars[n]);
1247 if (source >= target) {
1252 if (acs_chars[n + 1])
1256 memset(mapped, 0, sizeof(mapped));
1257 for (n = 0; acs_chars[n] != 0; n++) {
1258 source = UChar(acs_chars[n]);
1259 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1260 mapped[source] = (char) target;
1263 extra = (char) source;
1266 for (n = m = 0; n < sizeof(mapped); n++) {
1268 acs_chars[m++] = (char) n;
1269 acs_chars[m++] = mapped[n];
1273 acs_chars[m++] = extra; /* garbage in, garbage out */