X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Fdump_entry.c;h=664df32b382e3583b529f4691f3d3ad8609ca212;hp=acafaf76c076499ac05637b1e636d1a3e02d9565;hb=HEAD;hpb=d30f99439fcc8d4bb4c38e5c4afb4f6555fc6ad4 diff --git a/progs/dump_entry.c b/progs/dump_entry.c index acafaf76..be332d2e 100644 --- a/progs/dump_entry.c +++ b/progs/dump_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -36,11 +36,11 @@ #define __INTERNAL_CAPS_VISIBLE #include -#include "dump_entry.h" -#include "termsort.c" /* this C file is generated */ +#include +#include /* this C file is generated */ #include /* so is this */ -MODULE_ID("$Id: dump_entry.c,v 1.184 2021/04/03 23:01:08 tom Exp $") +MODULE_ID("$Id: dump_entry.c,v 1.196 2023/05/27 20:13:10 tom Exp $") #define DISCARD(string) string = ABSENT_STRING #define PRINTF (void) printf @@ -85,7 +85,7 @@ static int indent = 8; /* cover various ports and variants of terminfo */ #define V_ALLCAPS 0 /* all capabilities (SVr4, XSI, ncurses) */ #define V_SVR1 1 /* SVR1, Ultrix */ -#define V_HPUX 2 /* HP/UX */ +#define V_HPUX 2 /* HP-UX */ #define V_AIX 3 /* AIX */ #define V_BSD 4 /* BSD */ @@ -549,7 +549,7 @@ fill_spaces(const char *src) if (pass) { result[d] = '\0'; } else { - result = malloc(need + 1); + result = calloc(need + 1, sizeof(char)); if (result == 0) failed("fill_spaces"); } @@ -859,7 +859,6 @@ fmt_complex(TERMTYPE2 *tterm, const char *capability, char *src, int level) indent_DYN(&tmpbuf, level + 1); strncpy_DYN(&tmpbuf, "%", (size_t) 1); } - params = FALSE; percent = FALSE; break; case ' ': @@ -915,7 +914,6 @@ fmt_entry(TERMTYPE2 *tterm, { PredIdx i, j; char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP]; - char *capability; NCURSES_CONST char *name; int predval, len; PredIdx num_bools = 0; @@ -935,7 +933,7 @@ fmt_entry(TERMTYPE2 *tterm, strcpy_DYN(&outbuf, 0); if (content_only) { - column = indent; /* FIXME: workaround to prevent empty lines */ + column = indent; /* workaround to prevent empty lines */ } else { strcpy_DYN(&outbuf, tterm->term_names); @@ -1035,6 +1033,7 @@ fmt_entry(TERMTYPE2 *tterm, } for_each_string(j, tterm) { + char *capability; i = StrIndirect(j); name = ExtStrname(tterm, (int) i, str_names); assert(strlen(name) < sizeof(buffer) - EXTRA_CAP); @@ -1312,7 +1311,7 @@ fmt_entry(TERMTYPE2 *tterm, } static bool -kill_string(TERMTYPE2 *tterm, char *cap) +kill_string(TERMTYPE2 *tterm, const char *const cap) { unsigned n; for (n = 0; n < NUM_STRINGS(tterm); ++n) { @@ -1483,7 +1482,7 @@ dump_entry(TERMTYPE2 *tterm, PredFunc pred) { TERMTYPE2 save_tterm; - int len, critlen; + int critlen; const char *legend; bool infodump; @@ -1554,6 +1553,7 @@ dump_entry(TERMTYPE2 *tterm, save_sgr = set_attributes; if ((FMT_ENTRY() > critlen) + && TcOutput() && limited) { save_tterm = *tterm; @@ -1564,7 +1564,7 @@ dump_entry(TERMTYPE2 *tterm, } if (FMT_ENTRY() > critlen) { /* - * We pick on sgr because it's a nice long string capability that + * We pick on sgr because it is 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. */ @@ -1609,6 +1609,7 @@ dump_entry(TERMTYPE2 *tterm, } if (!changed || (FMT_ENTRY() > critlen)) { int oldversion = tversion; + int len; tversion = V_BSD; SHOW_WHY("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n", @@ -1651,15 +1652,25 @@ dump_entry(TERMTYPE2 *tterm, } void -dump_uses(const char *name, bool infodump) +dump_uses(const char *value, bool infodump) /* dump "use=" clauses in the appropriate format */ { - char buffer[MAX_TERMINFO_LENGTH]; + char buffer[MAX_TERMINFO_LENGTH + EXTRA_CAP]; + int limit = (VALID_STRING(value) ? (int) strlen(value) : 0); + const char *cap = infodump ? "use" : "tc"; if (TcOutput()) trim_trailing(); + if (limit == 0) { + _nc_warning("empty \"%s\" field", cap); + value = ""; + } else if (limit > MAX_ALIAS) { + _nc_warning("\"%s\" field too long (%d), limit to %d", + cap, limit, MAX_ALIAS); + limit = MAX_ALIAS; + } _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) - "%s%s", infodump ? "use=" : "tc=", name); + "%s=%.*s", cap, limit, value); wrap_concat1(buffer); } @@ -1682,7 +1693,7 @@ show_entry(void) outbuf.used = (size_t) j; } else if (!infodump && ch == '\\') { outbuf.used = (size_t) j; - } else if (ch == delim && (j == 0 || outbuf.text[j - 1] != '\\')) { + } else if (ch == delim && (outbuf.text[j - 1] != '\\')) { outbuf.used = (size_t) (j + 1); } else { break;