1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 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.100 2012/06/09 21:44:40 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 height = 65535; /* max number of lines for listings */
61 static int column; /* current column, limited by 'width' */
62 static int oldcol; /* last value of column before wrap */
63 static bool pretty; /* true if we format if-then-else strings */
65 static char *save_sgr;
70 /* indirection pointers for implementing sort and display modes */
71 static const PredIdx *bool_indirect, *num_indirect, *str_indirect;
72 static NCURSES_CONST char *const *bool_names;
73 static NCURSES_CONST char *const *num_names;
74 static NCURSES_CONST char *const *str_names;
76 static const char *separator, *trailer;
78 /* cover various ports and variants of terminfo */
79 #define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */
80 #define V_SVR1 1 /* SVR1, Ultrix */
81 #define V_HPUX 2 /* HP/UX */
82 #define V_AIX 3 /* AIX */
83 #define V_BSD 4 /* BSD */
86 #define OBSOLETE(n) (!_nc_user_definable && (n[0] == 'O' && n[1] == 'T'))
88 #define OBSOLETE(n) (n[0] == 'O' && n[1] == 'T')
91 #define isObsolete(f,n) ((f == F_TERMINFO || f == F_VARIABLE) && OBSOLETE(n))
94 #define BoolIndirect(j) ((j >= BOOLCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : bool_indirect[j]))
95 #define NumIndirect(j) ((j >= NUMCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : num_indirect[j]))
96 #define StrIndirect(j) ((j >= STRCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : str_indirect[j]))
98 #define BoolIndirect(j) ((sortmode == S_NOSORT) ? (j) : bool_indirect[j])
99 #define NumIndirect(j) ((sortmode == S_NOSORT) ? (j) : num_indirect[j])
100 #define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
104 strncpy_DYN(DYNBUF * dst, const char *src, size_t need)
106 size_t want = need + dst->used + 1;
107 if (want > dst->size) {
108 dst->size += (want + 1024); /* be generous */
109 dst->text = typeRealloc(char, dst->size, dst->text);
111 (void) strncpy(dst->text + dst->used, src, need);
113 dst->text[dst->used] = 0;
117 strcpy_DYN(DYNBUF * dst, const char *src)
123 strncpy_DYN(dst, src, strlen(src));
139 _nc_leaks_dump_entry(void)
146 #define NameTrans(check,result) \
147 if (OkIndex(np->nte_index, check) \
148 && check[np->nte_index]) \
149 return (result[np->nte_index])
152 nametrans(const char *name)
153 /* translate a capability name from termcap to terminfo */
155 const struct name_table_entry *np;
157 if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
158 switch (np->nte_type) {
160 NameTrans(bool_from_termcap, boolcodes);
164 NameTrans(num_from_termcap, numcodes);
168 NameTrans(str_from_termcap, strcodes);
176 dump_init(const char *version,
183 /* set up for entry display */
191 tversion = V_ALLCAPS;
192 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
193 || !strcmp(version, "Ultrix"))
195 else if (!strcmp(version, "HP"))
197 else if (!strcmp(version, "AIX"))
199 else if (!strcmp(version, "BSD"))
202 tversion = V_ALLCAPS;
204 /* implement display modes */
205 switch (outform = mode) {
208 bool_names = boolnames;
209 num_names = numnames;
210 str_names = strnames;
211 separator = (twidth > 0 && theight > 1) ? ", " : ",";
216 bool_names = boolfnames;
217 num_names = numfnames;
218 str_names = strfnames;
219 separator = (twidth > 0 && theight > 1) ? ", " : ",";
225 bool_names = boolcodes;
226 num_names = numcodes;
227 str_names = strcodes;
233 /* implement sort modes */
234 switch (sortmode = sort) {
237 (void) fprintf(stderr,
238 "%s: sorting by term structure order\n", _nc_progname);
243 (void) fprintf(stderr,
244 "%s: sorting by terminfo name order\n", _nc_progname);
245 bool_indirect = bool_terminfo_sort;
246 num_indirect = num_terminfo_sort;
247 str_indirect = str_terminfo_sort;
252 (void) fprintf(stderr,
253 "%s: sorting by C variable order\n", _nc_progname);
254 bool_indirect = bool_variable_sort;
255 num_indirect = num_variable_sort;
256 str_indirect = str_variable_sort;
261 (void) fprintf(stderr,
262 "%s: sorting by termcap name order\n", _nc_progname);
263 bool_indirect = bool_termcap_sort;
264 num_indirect = num_termcap_sort;
265 str_indirect = str_termcap_sort;
270 (void) fprintf(stderr,
271 "%s: width = %d, tversion = %d, outform = %d\n",
272 _nc_progname, width, tversion, outform);
275 static TERMTYPE *cur_type;
278 dump_predicate(PredType type, PredIdx idx)
279 /* predicate function to use for ordinary decompilation */
283 return (cur_type->Booleans[idx] == FALSE)
284 ? FAIL : cur_type->Booleans[idx];
287 return (cur_type->Numbers[idx] == ABSENT_NUMERIC)
288 ? FAIL : cur_type->Numbers[idx];
291 return (cur_type->Strings[idx] != ABSENT_STRING)
295 return (FALSE); /* pacify compiler */
298 static void set_obsolete_termcaps(TERMTYPE *tp);
300 /* is this the index of a function key string? */
301 #define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
304 * If we configure with a different Caps file, the offsets into the arrays
305 * will change. So we use an address expression.
307 #define BOOL_IDX(name) (PredType) (&(name) - &(CUR Booleans[0]))
308 #define NUM_IDX(name) (PredType) (&(name) - &(CUR Numbers[0]))
309 #define STR_IDX(name) (PredType) (&(name) - &(CUR Strings[0]))
312 version_filter(PredType type, PredIdx idx)
313 /* filter out capabilities we may want to suppress */
316 case V_ALLCAPS: /* SVr4, XSI Curses */
319 case V_SVR1: /* System V Release 1, Ultrix */
322 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
324 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
326 return ((idx <= STR_IDX(prtr_non)) ? TRUE : FALSE);
330 case V_HPUX: /* Hewlett-Packard */
333 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
335 return ((idx <= NUM_IDX(label_width)) ? TRUE : FALSE);
337 if (idx <= STR_IDX(prtr_non))
339 else if (FNKEY(idx)) /* function keys */
341 else if (idx == STR_IDX(plab_norm)
342 || idx == STR_IDX(label_on)
343 || idx == STR_IDX(label_off))
350 case V_AIX: /* AIX */
353 return ((idx <= BOOL_IDX(xon_xoff)) ? TRUE : FALSE);
355 return ((idx <= NUM_IDX(width_status_line)) ? TRUE : FALSE);
357 if (idx <= STR_IDX(prtr_non))
359 else if (FNKEY(idx)) /* function keys */
366 #define is_termcap(type) (OkIndex(idx, type##_from_termcap) && \
367 type##_from_termcap[idx])
369 case V_BSD: /* BSD */
372 return is_termcap(bool);
374 return is_termcap(num);
376 return is_termcap(str);
381 return (FALSE); /* pacify the compiler */
387 while (outbuf.used > 0 && outbuf.text[outbuf.used - 1] == ' ')
388 outbuf.text[--outbuf.used] = '\0';
396 strcpy_DYN(&outbuf, trailer);
401 wrap_concat(const char *src)
403 size_t need = strlen(src);
404 size_t want = strlen(separator) + need;
407 && column + (int) want > width) {
410 strcpy_DYN(&outbuf, src);
411 strcpy_DYN(&outbuf, separator);
412 column += (int) need;
415 #define IGNORE_SEP_TRAIL(first,last,sep_trail) \
416 if ((size_t)(last - first) > sizeof(sep_trail)-1 \
417 && !strncmp(first, sep_trail, sizeof(sep_trail)-1)) \
418 first += sizeof(sep_trail)-2
420 /* Returns the nominal length of the buffer assuming it is termcap format,
421 * i.e., the continuation sequence is treated as a single character ":".
423 * There are several implementations of termcap which read the text into a
424 * fixed-size buffer. Generally they strip the newlines from the text, but may
425 * not do it until after the buffer is read. Also, "tc=" resolution may be
426 * expanded in the same buffer. This function is useful for measuring the size
427 * of the best fixed-buffer implementation; the worst case may be much worse.
429 #ifdef TEST_TERMCAP_LENGTH
431 termcap_length(const char *src)
433 static const char pattern[] = ":\\\n\t:";
436 const char *const t = src + strlen(src);
438 while (*src != '\0') {
439 IGNORE_SEP_TRAIL(src, t, pattern);
446 #define termcap_length(src) strlen(src)
450 indent_DYN(DYNBUF * buffer, int level)
454 for (n = 0; n < level; n++)
455 strncpy_DYN(buffer, "\t", 1);
459 has_params(const char *src)
462 int len = (int) strlen(src);
467 for (n = 0; n < len - 1; ++n) {
468 if (!strncmp(src + n, "%p", 2)) {
470 } else if (!strncmp(src + n, "%;", 2)) {
477 result = ((len > 50) && params);
483 fmt_complex(char *src, int level)
485 bool percent = FALSE;
486 bool params = has_params(src);
488 while (*src != '\0') {
492 strncpy_DYN(&tmpbuf, src++, 1);
498 case 't': /* "then" */
499 case 'e': /* "else" */
502 tmpbuf.text[tmpbuf.used - 1] = '\n';
503 /* treat a "%e" as else-if, on the same level */
505 indent_DYN(&tmpbuf, level);
506 strncpy_DYN(&tmpbuf, "%", 1);
507 strncpy_DYN(&tmpbuf, src, 1);
509 params = has_params(src);
510 if (!params && *src != '\0' && *src != '%') {
511 strncpy_DYN(&tmpbuf, "\n", 1);
512 indent_DYN(&tmpbuf, level + 1);
515 indent_DYN(&tmpbuf, level + 1);
516 strncpy_DYN(&tmpbuf, "%", 1);
517 strncpy_DYN(&tmpbuf, src, 1);
519 src = fmt_complex(src, level + 1);
520 if (*src != '\0' && *src != '%') {
521 strncpy_DYN(&tmpbuf, "\n", 1);
522 indent_DYN(&tmpbuf, level + 1);
524 } else if (level == 1) {
525 _nc_warning("%%%c without %%?", *src);
531 case ';': /* "endif" */
535 tmpbuf.text[tmpbuf.used - 1] = '\n';
536 indent_DYN(&tmpbuf, level);
537 strncpy_DYN(&tmpbuf, "%", 1);
538 strncpy_DYN(&tmpbuf, src++, 1);
541 _nc_warning("%%; without %%?");
545 if (percent && params) {
546 tmpbuf.text[tmpbuf.used - 1] = '\n';
547 indent_DYN(&tmpbuf, level + 1);
548 strncpy_DYN(&tmpbuf, "%", 1);
554 strncpy_DYN(&tmpbuf, "\\s", 2);
561 strncpy_DYN(&tmpbuf, src++, 1);
566 #define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
570 fmt_entry(TERMTYPE *tterm,
573 bool suppress_untranslatable,
578 char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP];
580 NCURSES_CONST char *name;
582 PredIdx num_bools = 0;
583 PredIdx num_values = 0;
584 PredIdx num_strings = 0;
587 #define WRAP_CONCAT \
588 wrap_concat(buffer); \
591 len = 12; /* terminfo file-header */
595 pred = dump_predicate;
598 strcpy_DYN(&outbuf, 0);
600 column = INDENT; /* FIXME: workaround to prevent empty lines */
602 strcpy_DYN(&outbuf, tterm->term_names);
605 * Colon is legal in terminfo descriptions, but not in termcap.
608 char *p = outbuf.text;
616 strcpy_DYN(&outbuf, separator);
617 column = (int) outbuf.used;
622 for_each_boolean(j, tterm) {
624 name = ExtBoolname(tterm, (int) i, bool_names);
625 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
627 if (!version_filter(BOOLEAN, i))
629 else if (isObsolete(outform, name))
632 predval = pred(BOOLEAN, i);
633 if (predval != FAIL) {
634 _nc_STRCPY(buffer, name, sizeof(buffer));
636 _nc_STRCAT(buffer, "@", sizeof(buffer));
637 else if (i + 1 > num_bools)
643 if (column != INDENT && height > 1)
646 for_each_number(j, tterm) {
648 name = ExtNumname(tterm, (int) i, num_names);
649 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
651 if (!version_filter(NUMBER, i))
653 else if (isObsolete(outform, name))
656 predval = pred(NUMBER, i);
657 if (predval != FAIL) {
658 if (tterm->Numbers[i] < 0) {
659 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
662 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
663 "%s#%d", name, tterm->Numbers[i]);
664 if (i + 1 > num_values)
671 if (column != INDENT && height > 1)
674 len += (int) (num_bools
676 + strlen(tterm->term_names) + 1);
682 if (outform == F_TERMCAP) {
683 if (termcap_reset != ABSENT_STRING) {
684 if (init_3string != ABSENT_STRING
685 && !strcmp(init_3string, termcap_reset))
686 DISCARD(init_3string);
688 if (reset_2string != ABSENT_STRING
689 && !strcmp(reset_2string, termcap_reset))
690 DISCARD(reset_2string);
694 for_each_string(j, tterm) {
696 name = ExtStrname(tterm, (int) i, str_names);
697 assert(strlen(name) < sizeof(buffer) - EXTRA_CAP);
699 capability = tterm->Strings[i];
701 if (!version_filter(STRING, i))
703 else if (isObsolete(outform, name))
708 * Extended names can be longer than 2 characters, but termcap programs
709 * cannot read those (filter them out).
711 if (outform == F_TERMCAP && (strlen(name) > 2))
715 if (outform == F_TERMCAP) {
717 * Some older versions of vi want rmir/smir to be defined
718 * for ich/ich1 to work. If they're not defined, force
719 * them to be output as defined and empty.
721 if (PRESENT(insert_character) || PRESENT(parm_ich)) {
722 if (SAME_CAP(i, enter_insert_mode)
723 && enter_insert_mode == ABSENT_STRING) {
724 _nc_STRCPY(buffer, "im=", sizeof(buffer));
729 if (SAME_CAP(i, exit_insert_mode)
730 && exit_insert_mode == ABSENT_STRING) {
731 _nc_STRCPY(buffer, "ei=", sizeof(buffer));
737 * termcap applications such as screen will be confused if sgr0
738 * is translated to a string containing rmacs. Filter that out.
740 if (PRESENT(exit_attribute_mode)) {
741 if (SAME_CAP(i, exit_attribute_mode)) {
743 char *my_sgr = set_attributes;
745 set_attributes = save_sgr;
747 trimmed_sgr0 = _nc_trim_sgr0(tterm);
748 if (strcmp(capability, trimmed_sgr0))
749 capability = trimmed_sgr0;
751 set_attributes = my_sgr;
756 predval = pred(STRING, i);
759 if (predval != FAIL) {
760 if (capability != ABSENT_STRING
761 && i + 1 > num_strings)
764 if (!VALID_STRING(capability)) {
765 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
768 } else if (outform == F_TERMCAP || outform == F_TCONVERR) {
769 int params = ((i < (int) SIZEOF(parametrized))
772 char *srccap = _nc_tic_expand(capability, TRUE, numbers);
773 char *cv = _nc_infotocap(name, srccap, params);
776 if (outform == F_TCONVERR) {
777 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
778 "%s=!!! %s WILL NOT CONVERT !!!",
780 } else if (suppress_untranslatable) {
783 char *s = srccap, *d = buffer;
784 _nc_SPRINTF(d, _nc_SLIMIT(sizeof(buffer)) "..%s=", name);
786 while ((*d = *s++) != 0) {
790 } else if (*d == '\\') {
797 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
800 len += (int) strlen(capability) + 1;
803 char *src = _nc_tic_expand(capability,
804 outform == F_TERMINFO, numbers);
806 strcpy_DYN(&tmpbuf, 0);
807 strcpy_DYN(&tmpbuf, name);
808 strcpy_DYN(&tmpbuf, "=");
810 && (outform == F_TERMINFO
811 || outform == F_VARIABLE)) {
814 strcpy_DYN(&tmpbuf, src);
816 len += (int) strlen(capability) + 1;
817 wrap_concat(tmpbuf.text);
821 /* e.g., trimmed_sgr0 */
822 if (capability != tterm->Strings[i])
825 len += (int) (num_strings * 2);
828 * This piece of code should be an effective inverse of the functions
829 * postprocess_terminfo() and postprocess_terminfo() in parse_entry.c.
830 * Much more work should be done on this to support dumping termcaps.
832 if (tversion == V_HPUX) {
833 if (VALID_STRING(memory_lock)) {
834 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
835 "meml=%s", memory_lock);
838 if (VALID_STRING(memory_unlock)) {
839 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
840 "memu=%s", memory_unlock);
843 } else if (tversion == V_AIX) {
844 if (VALID_STRING(acs_chars)) {
846 const char *acstrans = "lqkxjmwuvtn";
848 char *tp, *sp, boxchars[11];
851 for (cp = acstrans; *cp; cp++) {
852 sp = strchr(acs_chars, *cp);
863 _nc_STRCPY(buffer, "box1=", sizeof(buffer));
865 _nc_tic_expand(boxchars,
866 outform == F_TERMINFO, numbers),
874 * kludge: trim off trailer to avoid an extra blank line
875 * in infocmp -u output when there are no string differences
878 bool trimmed = FALSE;
879 j = (PredIdx) outbuf.used;
881 && outbuf.text[j - 1] == '\t'
882 && outbuf.text[j - 2] == '\n') {
886 && outbuf.text[j - 1] == ':'
887 && outbuf.text[j - 2] == '\t'
888 && outbuf.text[j - 3] == '\n'
889 && outbuf.text[j - 4] == '\\') {
894 outbuf.text[outbuf.used] = '\0';
896 strcpy_DYN(&outbuf, " ");
900 fprintf(stderr, "num_bools = %d\n", num_bools);
901 fprintf(stderr, "num_values = %d\n", num_values);
902 fprintf(stderr, "num_strings = %d\n", num_strings);
903 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",
904 tterm->term_names, len, outbuf.used, outbuf.text);
907 * Here's where we use infodump to trigger a more stringent length check
908 * for termcap-translation purposes.
909 * Return the length of the raw entry, without tc= expansions,
910 * It gives an idea of which entries are deadly to even *scan past*,
911 * as opposed to *use*.
913 return (infodump ? len : (int) termcap_length(outbuf.text));
917 kill_string(TERMTYPE *tterm, char *cap)
920 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
921 if (cap == tterm->Strings[n]) {
922 tterm->Strings[n] = ABSENT_STRING;
930 find_string(TERMTYPE *tterm, char *name)
933 for (n = 0; n < NUM_STRINGS(tterm); ++n) {
934 if (version_filter(STRING, n)
935 && !strcmp(name, strnames[n])) {
936 char *cap = tterm->Strings[n];
937 if (VALID_STRING(cap)) {
943 return ABSENT_STRING;
947 * This is used to remove function-key labels from a termcap entry to
951 kill_labels(TERMTYPE *tterm, int target)
958 for (n = 0; n <= 10; ++n) {
959 _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "lf%d", n);
960 if ((cap = find_string(tterm, name)) != ABSENT_STRING
961 && kill_string(tterm, cap)) {
962 target -= (int) (strlen(cap) + 5);
972 * This is used to remove function-key definitions from a termcap entry to
976 kill_fkeys(TERMTYPE *tterm, int target)
983 for (n = 60; n >= 0; --n) {
984 _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "kf%d", n);
985 if ((cap = find_string(tterm, name)) != ABSENT_STRING
986 && kill_string(tterm, cap)) {
987 target -= (int) (strlen(cap) + 5);
997 * Check if the given acsc string is a 1-1 mapping, i.e., just-like-vt100.
998 * Also, since this is for termcap, we only care about the line-drawing map.
1000 #define isLine(c) (strchr("lmkjtuvwqxn", c) != 0)
1003 one_one_mapping(const char *mapping)
1007 if (mapping != ABSENT_STRING) {
1009 while (mapping[n] != '\0') {
1010 if (isLine(mapping[n]) &&
1011 mapping[n] != mapping[n + 1]) {
1021 #define FMT_ENTRY() \
1022 fmt_entry(tterm, pred, \
1024 suppress_untranslatable, \
1027 #define SHOW_WHY PRINTF
1030 purged_acs(TERMTYPE *tterm)
1032 bool result = FALSE;
1034 if (VALID_STRING(acs_chars)) {
1035 if (!one_one_mapping(acs_chars)) {
1036 enter_alt_charset_mode = ABSENT_STRING;
1037 exit_alt_charset_mode = ABSENT_STRING;
1038 SHOW_WHY("# (rmacs/smacs removed for consistency)\n");
1046 * Dump a single entry.
1049 dump_entry(TERMTYPE *tterm,
1050 bool suppress_untranslatable,
1055 TERMTYPE save_tterm;
1060 if (outform == F_TERMCAP || outform == F_TCONVERR) {
1061 critlen = MAX_TERMCAP_LENGTH;
1062 legend = "older termcap";
1064 set_obsolete_termcaps(tterm);
1066 critlen = MAX_TERMINFO_LENGTH;
1067 legend = "terminfo";
1071 save_sgr = set_attributes;
1073 if ((FMT_ENTRY() > critlen)
1076 save_tterm = *tterm;
1077 if (!suppress_untranslatable) {
1078 SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
1080 suppress_untranslatable = TRUE;
1082 if (FMT_ENTRY() > critlen) {
1084 * We pick on sgr because it's a nice long string capability that
1085 * is really just an optimization hack. Another good candidate is
1086 * acsc since it is both long and unused by BSD termcap.
1088 bool changed = FALSE;
1092 * Extended names are most likely function-key definitions. Drop
1096 for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
1097 const char *name = ExtStrname(tterm, (int) n, strnames);
1099 if (VALID_STRING(tterm->Strings[n])) {
1100 set_attributes = ABSENT_STRING;
1101 /* we remove long names anyway - only report the short */
1102 if (strlen(name) <= 2) {
1103 SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
1108 if (FMT_ENTRY() <= critlen)
1113 if (VALID_STRING(set_attributes)) {
1114 set_attributes = ABSENT_STRING;
1115 SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
1119 if (!changed || (FMT_ENTRY() > critlen)) {
1120 if (purged_acs(tterm)) {
1121 acs_chars = ABSENT_STRING;
1122 SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",
1127 if (!changed || (FMT_ENTRY() > critlen)) {
1128 int oldversion = tversion;
1131 SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
1136 && kill_labels(tterm, len - critlen)) {
1137 SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",
1142 && kill_fkeys(tterm, len - critlen)) {
1143 SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",
1147 if (len > critlen) {
1148 (void) fprintf(stderr,
1149 "warning: %s entry is %d bytes long\n",
1150 _nc_first_name(tterm->term_names),
1152 SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",
1155 tversion = oldversion;
1157 set_attributes = save_sgr;
1158 *tterm = save_tterm;
1160 } else if (!version_filter(STRING, STR_IDX(acs_chars))) {
1161 save_tterm = *tterm;
1162 if (purged_acs(tterm)) {
1165 *tterm = save_tterm;
1170 dump_uses(const char *name, bool infodump)
1171 /* dump "use=" clauses in the appropriate format */
1173 char buffer[MAX_TERMINFO_LENGTH];
1175 if (outform == F_TERMCAP || outform == F_TCONVERR)
1177 _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
1178 "%s%s", infodump ? "use=" : "tc=", name);
1179 wrap_concat(buffer);
1186 * Trim any remaining whitespace.
1188 if (outbuf.used != 0) {
1189 bool infodump = (outform != F_TERMCAP && outform != F_TCONVERR);
1190 char delim = (char) (infodump ? ',' : ':');
1193 for (j = (int) outbuf.used - 1; j > 0; --j) {
1194 char ch = outbuf.text[j];
1197 } else if (isspace(UChar(ch))) {
1198 outbuf.used = (size_t) j;
1199 } else if (!infodump && ch == '\\') {
1200 outbuf.used = (size_t) j;
1201 } else if (ch == delim && (j == 0 || outbuf.text[j - 1] != '\\')) {
1202 outbuf.used = (size_t) (j + 1);
1207 outbuf.text[outbuf.used] = '\0';
1209 (void) fputs(outbuf.text, stdout);
1211 return (int) outbuf.used;
1215 compare_entry(PredHook hook,
1216 TERMTYPE *tp GCC_UNUSED,
1218 /* compare two entries */
1221 NCURSES_CONST char *name;
1224 fputs(" comparing booleans.\n", stdout);
1225 for_each_boolean(j, tp) {
1226 i = BoolIndirect(j);
1227 name = ExtBoolname(tp, (int) i, bool_names);
1229 if (isObsolete(outform, name))
1232 (*hook) (CMP_BOOLEAN, i, name);
1236 fputs(" comparing numbers.\n", stdout);
1237 for_each_number(j, tp) {
1239 name = ExtNumname(tp, (int) i, num_names);
1241 if (isObsolete(outform, name))
1244 (*hook) (CMP_NUMBER, i, name);
1248 fputs(" comparing strings.\n", stdout);
1249 for_each_string(j, tp) {
1251 name = ExtStrname(tp, (int) i, str_names);
1253 if (isObsolete(outform, name))
1256 (*hook) (CMP_STRING, i, name);
1259 /* (void) fputs(" comparing use entries.\n", stdout); */
1260 (*hook) (CMP_USE, 0, "use");
1264 #define NOTSET(s) ((s) == 0)
1267 * This bit of legerdemain turns all the terminfo variable names into
1268 * references to locations in the arrays Booleans, Numbers, and Strings ---
1269 * precisely what's needed.
1275 set_obsolete_termcaps(TERMTYPE *tp)
1277 #include "capdefaults.c"
1281 * Convert an alternate-character-set string to canonical form: sorted and
1285 repair_acsc(TERMTYPE *tp)
1287 if (VALID_STRING(acs_chars)) {
1293 bool fix_needed = FALSE;
1295 for (n = 0, source = 0; acs_chars[n] != 0; n++) {
1296 target = UChar(acs_chars[n]);
1297 if (source >= target) {
1302 if (acs_chars[n + 1])
1306 memset(mapped, 0, sizeof(mapped));
1307 for (n = 0; acs_chars[n] != 0; n++) {
1308 source = UChar(acs_chars[n]);
1309 if ((target = (unsigned char) acs_chars[n + 1]) != 0) {
1310 mapped[source] = (char) target;
1313 extra = (char) source;
1316 for (n = m = 0; n < sizeof(mapped); n++) {
1318 acs_chars[m++] = (char) n;
1319 acs_chars[m++] = mapped[n];
1323 acs_chars[m++] = extra; /* garbage in, garbage out */