⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dump_entry.c

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 C
📖 第 1 页 / 共 2 页
字号:
	    } else {		sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);		if (i + 1 > num_values)		    num_values = i + 1;	    }	    WRAP_CONCAT;	}    }    if (column != INDENT)	force_wrap();    len += num_bools	+ num_values * 2	+ strlen(tterm->term_names) + 1;    if (len & 1)	len++;#undef CUR#define CUR tterm->    if (outform == F_TERMCAP) {	if (termcap_reset != ABSENT_STRING) {	    if (init_3string != ABSENT_STRING		&& !strcmp(init_3string, termcap_reset))		DISCARD(init_3string);	    if (reset_2string != ABSENT_STRING		&& !strcmp(reset_2string, termcap_reset))		DISCARD(reset_2string);	}    }    for_each_string(j, tterm) {	i = StrIndirect(j);	name = ExtStrname(tterm, i, str_names);	capability = tterm->Strings[i];	if (!version_filter(STRING, i))	    continue;	else if (isObsolete(outform, name))	    continue;#if NCURSES_XNAMES	/*	 * Extended names can be longer than 2 characters, but termcap programs	 * cannot read those (filter them out).	 */	if (outform == F_TERMCAP && (strlen(name) > 2))	    continue;#endif	if (outform == F_TERMCAP) {	    /*	     * Some older versions of vi want rmir/smir to be defined	     * for ich/ich1 to work.  If they're not defined, force	     * them to be output as defined and empty.	     */	    if (PRESENT(insert_character) || PRESENT(parm_ich)) {		if (SAME_CAP(i, enter_insert_mode)		    && enter_insert_mode == ABSENT_STRING) {		    (void) strcpy(buffer, "im=");		    WRAP_CONCAT;		    continue;		}		if (SAME_CAP(i, exit_insert_mode)		    && exit_insert_mode == ABSENT_STRING) {		    (void) strcpy(buffer, "ei=");		    WRAP_CONCAT;		    continue;		}	    }	    /*	     * termcap applications such as screen will be confused if sgr0	     * is translated to a string containing rmacs.  Filter that out.	     */	    if (PRESENT(exit_attribute_mode)) {		if (SAME_CAP(i, exit_attribute_mode)) {		    char *trimmed_sgr0;		    char *my_sgr = set_attributes;		    set_attributes = save_sgr;		    trimmed_sgr0 = _nc_trim_sgr0(tterm);		    if (strcmp(capability, trimmed_sgr0))			capability = trimmed_sgr0;		    set_attributes = my_sgr;		}	    }	}	predval = pred(STRING, i);	buffer[0] = '\0';	if (predval != FAIL) {	    if (capability != ABSENT_STRING		&& i + 1 > num_strings)		num_strings = i + 1;	    if (!VALID_STRING(capability)) {		sprintf(buffer, "%s@", name);		WRAP_CONCAT;	    } else if (outform == F_TERMCAP || outform == F_TCONVERR) {		int params = ((i < (int) SIZEOF(parametrized))			      ? parametrized[i]			      : 0);		char *srccap = _nc_tic_expand(capability, TRUE, numbers);		char *cv = _nc_infotocap(name, srccap, params);		if (cv == 0) {		    if (outform == F_TCONVERR) {			sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!",				name, srccap);		    } else if (suppress_untranslatable) {			continue;		    } else {			char *s = srccap, *d = buffer;			sprintf(d, "..%s=", name);			d += strlen(d);			while ((*d = *s++) != 0) {			    if (*d == ':') {				*d++ = '\\';				*d = ':';			    } else if (*d == '\\') {				*++d = *s++;			    }			    d++;			}		    }		} else {		    sprintf(buffer, "%s=%s", name, cv);		}		len += strlen(capability) + 1;		WRAP_CONCAT;	    } else {		char *src = _nc_tic_expand(capability,					   outform == F_TERMINFO, numbers);		strcpy_DYN(&tmpbuf, 0);		strcpy_DYN(&tmpbuf, name);		strcpy_DYN(&tmpbuf, "=");		if (pretty		    && (outform == F_TERMINFO			|| outform == F_VARIABLE)) {		    fmt_complex(src, 1);		} else {		    strcpy_DYN(&tmpbuf, src);		}		len += strlen(capability) + 1;		wrap_concat(tmpbuf.text);		outcount = TRUE;	    }	}	/* e.g., trimmed_sgr0 */	if (capability != tterm->Strings[i])	    free(capability);    }    len += num_strings * 2;    /*     * This piece of code should be an effective inverse of the functions     * postprocess_terminfo and postprocess_terminfo in parse_entry.c.     * Much more work should be done on this to support dumping termcaps.     */    if (tversion == V_HPUX) {	if (memory_lock) {	    (void) sprintf(buffer, "meml=%s", memory_lock);	    WRAP_CONCAT;	}	if (memory_unlock) {	    (void) sprintf(buffer, "memu=%s", memory_unlock);	    WRAP_CONCAT;	}    } else if (tversion == V_AIX) {	if (VALID_STRING(acs_chars)) {	    bool box_ok = TRUE;	    const char *acstrans = "lqkxjmwuvtn";	    const char *cp;	    char *tp, *sp, boxchars[11];	    tp = boxchars;	    for (cp = acstrans; *cp; cp++) {		sp = strchr(acs_chars, *cp);		if (sp)		    *tp++ = sp[1];		else {		    box_ok = FALSE;		    break;		}	    }	    tp[0] = '\0';	    if (box_ok) {		(void) strcpy(buffer, "box1=");		(void) strcat(buffer, _nc_tic_expand(boxchars,						     outform == F_TERMINFO, numbers));		WRAP_CONCAT;	    }	}    }    /*     * kludge: trim off trailer to avoid an extra blank line     * in infocmp -u output when there are no string differences     */    if (outcount) {	bool trimmed = FALSE;	j = outbuf.used;	if (j >= 2	    && outbuf.text[j - 1] == '\t'	    && outbuf.text[j - 2] == '\n') {	    outbuf.used -= 2;	    trimmed = TRUE;	} else if (j >= 4		   && outbuf.text[j - 1] == ':'		   && outbuf.text[j - 2] == '\t'		   && outbuf.text[j - 3] == '\n'		   && outbuf.text[j - 4] == '\\') {	    outbuf.used -= 4;	    trimmed = TRUE;	}	if (trimmed) {	    outbuf.text[outbuf.used] = '\0';	    column = oldcol;	}    }#if 0    fprintf(stderr, "num_bools = %d\n", num_bools);    fprintf(stderr, "num_values = %d\n", num_values);    fprintf(stderr, "num_strings = %d\n", num_strings);    fprintf(stderr, "term_names=%s, len=%d, strlen(outbuf)=%d, outbuf=%s\n",	    tterm->term_names, len, outbuf.used, outbuf.text);#endif    /*     * Here's where we use infodump to trigger a more stringent length check     * for termcap-translation purposes.     * Return the length of the raw entry, without tc= expansions,     * It gives an idea of which entries are deadly to even *scan past*,     * as opposed to *use*.     */    return (infodump ? len : (int) termcap_length(outbuf.text));}static boolkill_string(TERMTYPE *tterm, char *cap){    int n;    for (n = 0; n < NUM_STRINGS(tterm); ++n) {	if (cap == tterm->Strings[n]) {	    tterm->Strings[n] = ABSENT_STRING;	    return TRUE;	}    }    return FALSE;}static char *find_string(TERMTYPE *tterm, char *name){    PredIdx n;    for (n = 0; n < NUM_STRINGS(tterm); ++n) {	if (version_filter(STRING, n)	    && !strcmp(name, strnames[n])) {	    char *cap = tterm->Strings[n];	    if (VALID_STRING(cap)) {		return cap;	    }	    break;	}    }    return ABSENT_STRING;}/* * This is used to remove function-key labels from a termcap entry to * make it smaller. */static intkill_labels(TERMTYPE *tterm, int target){    int n;    int result = 0;    char *cap;    char name[10];    for (n = 0; n <= 10; ++n) {	sprintf(name, "lf%d", n);	if ((cap = find_string(tterm, name)) != ABSENT_STRING	    && kill_string(tterm, cap)) {	    target -= (strlen(cap) + 5);	    ++result;	    if (target < 0)		break;	}    }    return result;}/* * This is used to remove function-key definitions from a termcap entry to * make it smaller. */static intkill_fkeys(TERMTYPE *tterm, int target){    int n;    int result = 0;    char *cap;    char name[10];    for (n = 60; n >= 0; --n) {	sprintf(name, "kf%d", n);	if ((cap = find_string(tterm, name)) != ABSENT_STRING	    && kill_string(tterm, cap)) {	    target -= (strlen(cap) + 5);	    ++result;	    if (target < 0)		break;	}    }    return result;}#define FMT_ENTRY() \		fmt_entry(tterm, pred, \			(already_used > 0), \			suppress_untranslatable, \			infodump, numbers)#define SHOW_WHY if (!already_used) PRINTFintdump_entry(TERMTYPE *tterm,	   bool suppress_untranslatable,	   bool limited,	   int already_used,	   int numbers,	   PredFunc pred)/* dump a single entry */{    int len, critlen;    const char *legend;    bool infodump;    if (outform == F_TERMCAP || outform == F_TCONVERR) {	critlen = MAX_TERMCAP_LENGTH;	legend = "older termcap";	infodump = FALSE;	set_obsolete_termcaps(tterm);    } else {	critlen = MAX_TERMINFO_LENGTH;	legend = "terminfo";	infodump = TRUE;    }    critlen -= already_used;    save_sgr = set_attributes;    save_acsc = acs_chars;    if (((len = FMT_ENTRY()) > critlen)	&& limited) {	if (!suppress_untranslatable) {	    SHOW_WHY("# (untranslatable capabilities removed to fit entry within %d bytes)\n",		     critlen);	    suppress_untranslatable = TRUE;	}	if ((len = FMT_ENTRY()) > critlen) {	    /*	     * We pick on sgr because it's a nice long string capability that	     * is really just an optimization hack.  Another good candidate is	     * acsc since it is both long and unused by BSD termcap.	     */	    bool changed = FALSE;#if NCURSES_XNAMES	    /*	     * Extended names are most likely function-key definitions.  Drop	     * those first.	     */	    int n;	    for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {		char *name = ExtStrname(tterm, n, strnames);		if (VALID_STRING(tterm->Strings[n])) {		    set_attributes = ABSENT_STRING;		    /* we remove long names anyway - only report the short */		    if (strlen(name) <= 2) {			SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",				 name,				 critlen);		    }		    changed = TRUE;		    if ((len = FMT_ENTRY()) <= critlen)			break;		}	    }#endif	    if (VALID_STRING(set_attributes)) {		set_attributes = ABSENT_STRING;		SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",			 critlen);		changed = TRUE;	    }	    if (!changed || ((len = FMT_ENTRY()) > critlen)) {		if (VALID_STRING(acs_chars)) {		    acs_chars = ABSENT_STRING;		    SHOW_WHY("# (acsc removed to fit entry within %d bytes)\n",			     critlen);		    changed = TRUE;		}	    }	    if (!changed || ((len = FMT_ENTRY()) > critlen)) {		int oldversion = tversion;		tversion = V_BSD;		SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",			 critlen);		len = FMT_ENTRY();		if (len > critlen		    && kill_labels(tterm, len - critlen)) {		    SHOW_WHY("# (some labels capabilities suppressed to fit entry within %d bytes)\n",			     critlen);		    len = FMT_ENTRY();		}		if (len > critlen		    && kill_fkeys(tterm, len - critlen)) {		    SHOW_WHY("# (some function-key capabilities suppressed to fit entry within %d bytes)\n",			     critlen);		    len = FMT_ENTRY();		}		if (len > critlen && !already_used) {		    (void) fprintf(stderr,				   "warning: %s entry is %d bytes long\n",				   _nc_first_name(tterm->term_names),				   len);		    SHOW_WHY("# WARNING: this entry, %d bytes long, may core-dump %s libraries!\n",			     already_used + len, legend);		}		tversion = oldversion;	    }	    set_attributes = save_sgr;	    acs_chars = save_acsc;	}    }    (void) fputs(outbuf.text, stdout);    return len;}intdump_uses(const char *name, bool infodump)/* dump "use=" clauses in the appropriate format */{    char buffer[MAX_TERMINFO_LENGTH];    strcpy_DYN(&outbuf, 0);    (void) sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);    wrap_concat(buffer);    (void) fputs(outbuf.text, stdout);    return outbuf.used;}voidcompare_entry(void (*hook) (PredType t, PredIdx i, const char *name),	      TERMTYPE *tp GCC_UNUSED,	      bool quiet)/* compare two entries */{    PredIdx i, j;    NCURSES_CONST char *name;    if (!quiet)	fputs("    comparing booleans.\n", stdout);    for_each_boolean(j, tp) {	i = BoolIndirect(j);	name = ExtBoolname(tp, i, bool_names);	if (isObsolete(outform, name))	    continue;	(*hook) (CMP_BOOLEAN, i, name);    }    if (!quiet)	fputs("    comparing numbers.\n", stdout);    for_each_number(j, tp) {	i = NumIndirect(j);	name = ExtNumname(tp, i, num_names);	if (isObsolete(outform, name))	    continue;	(*hook) (CMP_NUMBER, i, name);    }    if (!quiet)	fputs("    comparing strings.\n", stdout);    for_each_string(j, tp) {	i = StrIndirect(j);	name = ExtStrname(tp, i, str_names);	if (isObsolete(outform, name))	    continue;	(*hook) (CMP_STRING, i, name);    }    /* (void) fputs("    comparing use entries.\n", stdout); */    (*hook) (CMP_USE, 0, "use");}#define NOTSET(s)	((s) == 0)/* * This bit of legerdemain turns all the terminfo variable names into * references to locations in the arrays Booleans, Numbers, and Strings --- * precisely what's needed. */#undef CUR#define CUR tp->static voidset_obsolete_termcaps(TERMTYPE *tp){#include "capdefaults.c"}/* * Convert an alternate-character-set string to canonical form: sorted and * unique. */voidrepair_acsc(TERMTYPE *tp){    if (VALID_STRING(acs_chars)) {	size_t n, m;	char mapped[256];	char extra = 0;	unsigned source;	unsigned target;	bool fix_needed = FALSE;	for (n = 0, source = 0; acs_chars[n] != 0; n++) {	    target = acs_chars[n];	    if (source >= target) {		fix_needed = TRUE;		break;	    }	    source = target;	    if (acs_chars[n + 1])		n++;	}	if (fix_needed) {	    memset(mapped, 0, sizeof(mapped));	    for (n = 0; acs_chars[n] != 0; n++) {		source = acs_chars[n];		if ((target = (unsigned char) acs_chars[n + 1]) != 0) {		    mapped[source] = target;		    n++;		} else {		    extra = source;		}	    }	    for (n = m = 0; n < sizeof(mapped); n++) {		if (mapped[n]) {		    acs_chars[m++] = n;		    acs_chars[m++] = mapped[n];		}	    }	    if (extra)		acs_chars[m++] = extra;		/* garbage in, garbage out */	    acs_chars[m] = 0;	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -