1/**************************************************************************** |
2 * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * |
3 * * 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: * --- 13 unchanged lines hidden (view full) --- 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 * 26 * authorization. * 27 ****************************************************************************/ 28 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 ****************************************************************************/ 34 35#define __INTERNAL_CAPS_VISIBLE 36#include <progs.priv.h> 37 38#include "dump_entry.h" 39#include "termsort.c" /* this C file is generated */ 40#include <parametrized.h> /* so is this */ 41 |
42MODULE_ID("$Id: dump_entry.c,v 1.58 2002/06/01 22:58:11 tom Exp $") |
43 44#define INDENT 8 45#define DISCARD(string) string = ABSENT_STRING 46#define PRINTF (void) printf 47 48typedef struct { 49 char *text; 50 size_t used; --- 111 unchanged lines hidden (view full) --- 162 break; 163 } 164 165 return (0); 166} 167 168void 169dump_init(const char *version, int mode, int sort, int twidth, int traceval, |
170 bool formatted) |
171/* set up for entry display */ 172{ 173 width = twidth; 174 pretty = formatted; 175 176 /* versions */ 177 if (version == 0) 178 tversion = V_ALLCAPS; 179 else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1") |
180 || !strcmp(version, "Ultrix")) |
181 tversion = V_SVR1; 182 else if (!strcmp(version, "HP")) 183 tversion = V_HPUX; 184 else if (!strcmp(version, "AIX")) 185 tversion = V_AIX; 186 else if (!strcmp(version, "BSD")) 187 tversion = V_BSD; 188 else --- 28 unchanged lines hidden (view full) --- 217 break; 218 } 219 220 /* implement sort modes */ 221 switch (sortmode = sort) { 222 case S_NOSORT: 223 if (traceval) 224 (void) fprintf(stderr, |
225 "%s: sorting by term structure order\n", _nc_progname); |
226 break; 227 228 case S_TERMINFO: 229 if (traceval) 230 (void) fprintf(stderr, |
231 "%s: sorting by terminfo name order\n", _nc_progname); |
232 bool_indirect = bool_terminfo_sort; 233 num_indirect = num_terminfo_sort; 234 str_indirect = str_terminfo_sort; 235 break; 236 237 case S_VARIABLE: 238 if (traceval) 239 (void) fprintf(stderr, |
240 "%s: sorting by C variable order\n", _nc_progname); |
241 bool_indirect = bool_variable_sort; 242 num_indirect = num_variable_sort; 243 str_indirect = str_variable_sort; 244 break; 245 246 case S_TERMCAP: 247 if (traceval) 248 (void) fprintf(stderr, |
249 "%s: sorting by termcap name order\n", _nc_progname); |
250 bool_indirect = bool_termcap_sort; 251 num_indirect = num_termcap_sort; 252 str_indirect = str_termcap_sort; 253 break; 254 } 255 256 if (traceval) 257 (void) fprintf(stderr, |
258 "%s: width = %d, tversion = %d, outform = %d\n", 259 _nc_progname, width, tversion, outform); |
260} 261 262static TERMTYPE *cur_type; 263 264static int 265dump_predicate(int type, int idx) 266/* predicate function to use for ordinary decompilation */ 267{ --- 224 unchanged lines hidden (view full) --- 492 } 493 strncpy_DYN(&tmpbuf, src++, 1); 494 } 495 return src; 496} 497 498int 499fmt_entry(TERMTYPE * tterm, |
500 int (*pred) (int type, int idx), 501 bool suppress_untranslatable, 502 bool infodump, 503 int numbers) |
504{ 505 int i, j; 506 char buffer[MAX_TERMINFO_LENGTH]; 507 NCURSES_CONST char *name; 508 int predval, len; 509 int num_bools = 0; 510 int num_values = 0; 511 int num_strings = 0; --- 123 unchanged lines hidden (view full) --- 635 if (tterm->Strings[i] != ABSENT_STRING 636 && i + 1 > num_strings) 637 num_strings = i + 1; 638 639 if (!VALID_STRING(tterm->Strings[i])) { 640 sprintf(buffer, "%s@", name); 641 WRAP_CONCAT; 642 } else if (outform == F_TERMCAP || outform == F_TCONVERR) { |
643 int params = ((i < (int) SIZEOF(parametrized)) 644 ? parametrized[i] 645 : 0); |
646 char *srccap = _nc_tic_expand(tterm->Strings[i], TRUE, numbers); 647 char *cv = _nc_infotocap(name, srccap, params); 648 649 if (cv == 0) { 650 if (outform == F_TCONVERR) { 651 sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!", |
652 name, srccap); |
653 } else if (suppress_untranslatable) { 654 continue; 655 } else { 656 char *s = srccap, *d = buffer; 657 sprintf(d, "..%s=", name); 658 d += strlen(d); 659 while ((*d = *s++) != 0) { 660 if (*d == ':') { --- 7 unchanged lines hidden (view full) --- 668 } 669 } else { 670 sprintf(buffer, "%s=%s", name, cv); 671 } 672 len += strlen(tterm->Strings[i]) + 1; 673 WRAP_CONCAT; 674 } else { 675 char *src = _nc_tic_expand(tterm->Strings[i], |
676 outform == F_TERMINFO, numbers); |
677 678 strcpy_DYN(&tmpbuf, 0); 679 strcpy_DYN(&tmpbuf, name); 680 strcpy_DYN(&tmpbuf, "="); 681 if (pretty 682 && (outform == F_TERMINFO 683 || outform == F_VARIABLE)) { 684 fmt_complex(src, 1); --- 39 unchanged lines hidden (view full) --- 724 break; 725 } 726 } 727 tp[0] = '\0'; 728 729 if (box_ok) { 730 (void) strcpy(buffer, "box1="); 731 (void) strcat(buffer, _nc_tic_expand(boxchars, |
732 outform == F_TERMINFO, numbers)); |
733 WRAP_CONCAT; 734 } 735 } 736 } 737 738 /* 739 * kludge: trim off trailer to avoid an extra blank line 740 * in infocmp -u output when there are no string differences 741 */ 742 if (outcount) { 743 bool trimmed = FALSE; 744 j = outbuf.used; 745 if (j >= 2 746 && outbuf.text[j - 1] == '\t' 747 && outbuf.text[j - 2] == '\n') { 748 outbuf.used -= 2; 749 trimmed = TRUE; 750 } else if (j >= 4 |
751 && outbuf.text[j - 1] == ':' 752 && outbuf.text[j - 2] == '\t' 753 && outbuf.text[j - 3] == '\n' 754 && outbuf.text[j - 4] == '\\') { |
755 outbuf.used -= 4; 756 trimmed = TRUE; 757 } 758 if (trimmed) { 759 outbuf.text[outbuf.used] = '\0'; 760 column = oldcol; 761 } 762 } 763#if 0 764 fprintf(stderr, "num_bools = %d\n", num_bools); 765 fprintf(stderr, "num_values = %d\n", num_values); 766 fprintf(stderr, "num_strings = %d\n", num_strings); 767 fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n", |
768 tterm->term_names, len, outbuf.used, outbuf.text); |
769#endif 770 /* 771 * Here's where we use infodump to trigger a more stringent length check 772 * for termcap-translation purposes. 773 * Return the length of the raw entry, without tc= expansions, 774 * It gives an idea of which entries are deadly to even *scan past*, 775 * as opposed to *use*. 776 */ 777 return (infodump ? len : (int) termcap_length(outbuf.text)); 778} 779 |
780static bool 781kill_string(TERMTYPE * tterm, char *cap) 782{ 783 int n; 784 for (n = 0; n < tterm->num_Strings; ++n) { 785 if (cap == tterm->Strings[n]) { 786 tterm->Strings[n] = ABSENT_STRING; 787 return TRUE; 788 } 789 } 790 return FALSE; 791} 792 793static char * 794find_string(TERMTYPE * tterm, char *name) 795{ 796 int n; 797 for (n = 0; n < tterm->num_Strings; ++n) { 798 if (version_filter(STRING, n) 799 && !strcmp(name, strnames[n])) { 800 char *cap = tterm->Strings[n]; 801 if (VALID_STRING(cap)) { 802 return cap; 803 } 804 break; 805 } 806 } 807 return ABSENT_STRING; 808} 809 810/* 811 * This is used to remove function-key labels from a termcap entry to 812 * make it smaller. 813 */ 814static int 815kill_labels(TERMTYPE * tterm, int target) 816{ 817 int n; 818 int result = 0; 819 char *cap; 820 char name[10]; 821 822 for (n = 0; n <= 10; ++n) { 823 sprintf(name, "lf%d", n); 824 if ((cap = find_string(tterm, name)) != ABSENT_STRING 825 && kill_string(tterm, cap)) { 826 target -= (strlen(cap) + 5); 827 ++result; 828 if (target < 0) 829 break; 830 } 831 } 832 return result; 833} 834 835/* 836 * This is used to remove function-key definitions from a termcap entry to 837 * make it smaller. 838 */ 839static int 840kill_fkeys(TERMTYPE * tterm, int target) 841{ 842 int n; 843 int result = 0; 844 char *cap; 845 char name[10]; 846 847 for (n = 60; n >= 0; --n) { 848 sprintf(name, "kf%d", n); 849 if ((cap = find_string(tterm, name)) != ABSENT_STRING 850 && kill_string(tterm, cap)) { 851 target -= (strlen(cap) + 5); 852 ++result; 853 if (target < 0) 854 break; 855 } 856 } 857 return result; 858} 859 |
860int |
861dump_entry(TERMTYPE * tterm, 862 bool limited, 863 int numbers, 864 int (*pred) (int type, int idx)) |
865/* dump a single entry */ 866{ 867 int len, critlen; 868 const char *legend; 869 bool infodump; 870 871 if (outform == F_TERMCAP || outform == F_TCONVERR) { 872 critlen = MAX_TERMCAP_LENGTH; --- 4 unchanged lines hidden (view full) --- 877 critlen = MAX_TERMINFO_LENGTH; 878 legend = "terminfo"; 879 infodump = TRUE; 880 } 881 882 if (((len = fmt_entry(tterm, pred, FALSE, infodump, numbers)) > critlen) 883 && limited) { 884 PRINTF("# (untranslatable capabilities removed to fit entry within %d bytes)\n", |
885 critlen); |
886 if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { 887 /* 888 * We pick on sgr because it's a nice long string capability that 889 * is really just an optimization hack. Another good candidate is 890 * acsc since it is both long and unused by BSD termcap. 891 */ 892 char *oldsgr = set_attributes; 893 char *oldacsc = acs_chars; 894 set_attributes = ABSENT_STRING; 895 PRINTF("# (sgr removed to fit entry within %d bytes)\n", |
896 critlen); |
897 if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { 898 acs_chars = ABSENT_STRING; 899 PRINTF("# (acsc removed to fit entry within %d bytes)\n", |
900 critlen); |
901 } 902 if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen) { 903 int oldversion = tversion; 904 905 tversion = V_BSD; 906 PRINTF("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n", |
907 critlen); |
908 |
909 len = fmt_entry(tterm, pred, TRUE, infodump, numbers); 910 if (len > critlen 911 && kill_labels(tterm, len - critlen)) { 912 PRINTF("# (some labels capabilities suppressed to fit entry within %d bytes)\n", 913 critlen); 914 len = fmt_entry(tterm, pred, TRUE, infodump, numbers); 915 } 916 if (len > critlen 917 && kill_fkeys(tterm, len - critlen)) { 918 PRINTF("# (some function-key capabilities suppressed to fit entry within %d bytes)\n", 919 critlen); 920 len = fmt_entry(tterm, pred, TRUE, infodump, numbers); 921 } 922 if (len > critlen) { |
923 (void) fprintf(stderr, |
924 "warning: %s entry is %d bytes long\n", 925 _nc_first_name(tterm->term_names), 926 len); |
927 PRINTF( |
928 "# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n", 929 len, legend); |
930 } 931 tversion = oldversion; 932 } 933 set_attributes = oldsgr; 934 acs_chars = oldacsc; 935 } 936 } 937 --- 11 unchanged lines hidden (view full) --- 949 (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name); 950 wrap_concat(buffer); 951 (void) fputs(outbuf.text, stdout); 952 return outbuf.used; 953} 954 955void 956compare_entry(void (*hook) (int t, int i, const char *name), TERMTYPE * tp |
957 GCC_UNUSED, bool quiet) |
958/* compare two entries */ 959{ 960 int i, j; 961 NCURSES_CONST char *name; 962 963 if (!quiet) 964 fputs(" comparing booleans.\n", stdout); 965 for_each_boolean(j, tp) { --- 102 unchanged lines hidden --- |