X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=progs%2Finfocmp.c;h=dbdbdc2dfe359545e4399279ed6cd0dddb77bf42;hb=HEAD;hp=ec5e07650dd43e1bf766e3e164e8d0a0ba77b1ed;hpb=410952f85a313e9ddb6a1d5939dec1b89c8a40f9;p=ncurses.git diff --git a/progs/infocmp.c b/progs/infocmp.c index ec5e0765..7932203a 100644 --- a/progs/infocmp.c +++ b/progs/infocmp.c @@ -43,7 +43,7 @@ #include -MODULE_ID("$Id: infocmp.c,v 1.157 2023/05/27 20:13:10 tom Exp $") +MODULE_ID("$Id: infocmp.c,v 1.163 2023/12/16 17:27:47 tom Exp $") #define MAX_STRING 1024 /* maximum formatted string */ @@ -187,10 +187,21 @@ capcmp(PredIdx idx, const char *s, const char *t) return (_nc_capcmp(s, t)); } +/* + * Predicate function to use for "use=" decompilation. + * + * Return value is used in fmt_entry: + * FAIL show nothing for this capability. + * FALSE show cancel for booleans (a compromise) + * TRUE show capability + * + * The only difference between FALSE/TRUE returns is in the treatment of + * booleans. + */ static int use_predicate(unsigned type, PredIdx idx) -/* predicate function to use for use decompilation */ { + int result = FAIL; ENTRY *ep; switch (type) { @@ -209,16 +220,18 @@ use_predicate(unsigned type, PredIdx idx) * unlike numbers and strings, whose cancelled/absent state is * recorded in the terminfo database. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (ep->tterm.Booleans[idx] == TRUE) { - is_set = entries[0].tterm.Booleans[idx]; - break; + if (idx < NUM_BOOLEANS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) { + if (idx < NUM_BOOLEANS(&(ep->tterm)) + && (is_set = ep->tterm.Booleans[idx])) { + break; + } } - if (is_set != entries[0].tterm.Booleans[idx]) - return (!is_set); - else - return (FAIL); + if (is_set != entries[0].tterm.Booleans[idx]) + result = (!is_set); + } } + break; case NUMBER: { @@ -229,45 +242,56 @@ use_predicate(unsigned type, PredIdx idx) * capability gets the first non-default value found * in the sequence of use entries'. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (VALID_NUMERIC(ep->tterm.Numbers[idx])) { - value = ep->tterm.Numbers[idx]; - break; - } + if (idx < NUM_NUMBERS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) + if (idx < NUM_NUMBERS(&(ep->tterm)) + && VALID_NUMERIC(ep->tterm.Numbers[idx])) { + value = ep->tterm.Numbers[idx]; + break; + } - if (value != entries[0].tterm.Numbers[idx]) - return (value != ABSENT_NUMERIC); - else - return (FAIL); + if (value != entries[0].tterm.Numbers[idx]) + result = (value != ABSENT_NUMERIC); + } } + break; case STRING: { - char *termstr, *usestr = ABSENT_STRING; - - termstr = entries[0].tterm.Strings[idx]; + char *termstr = entries[0].tterm.Strings[idx]; + char *usestr = ABSENT_STRING; /* * We take the semantics of multiple uses to be 'each * capability gets the first non-default value found * in the sequence of use entries'. */ - for (ep = &entries[1]; ep < entries + termcount; ep++) - if (ep->tterm.Strings[idx]) { - usestr = ep->tterm.Strings[idx]; - break; - } + if (idx < NUM_STRINGS(&(entries[0].tterm))) { + for (ep = &entries[1]; ep < entries + termcount; ep++) + if (idx < NUM_STRINGS(&(ep->tterm)) + && ep->tterm.Strings[idx]) { + usestr = ep->tterm.Strings[idx]; + break; + } - if (usestr == ABSENT_STRING && termstr == ABSENT_STRING) - return (FAIL); - else if (!usestr || !termstr || capcmp(idx, usestr, termstr)) - return (TRUE); - else - return (FAIL); + if (usestr == CANCELLED_STRING && termstr == ABSENT_STRING) + result = (FAIL); + else if (usestr == CANCELLED_STRING && termstr == CANCELLED_STRING) + result = (TRUE); + else if (usestr == ABSENT_STRING && termstr == ABSENT_STRING) + result = (FAIL); + else if (!usestr || !termstr || capcmp(idx, usestr, termstr)) + result = (TRUE); + } } + break; + + default: + result = FALSE; + break; } - return (FALSE); /* pacify compiler */ + return (result); } static bool @@ -1858,8 +1882,16 @@ main(int argc, char *argv[]) } #if NCURSES_XNAMES - if (termcount > 1) - _nc_align_termtype(&entries[0].tterm, &entries[1].tterm); + if (termcount > 1) { + /* + * User-defined capabilities in different terminal descriptions + * may have the same name/type but different indices. Line up + * the names to use comparable indices. We may have more than two + * entries to compare when processing the "-u" option. + */ + for (c = 1; c < termcount; ++c) + _nc_align_termtype(&entries[c].tterm, &entries[0].tterm); + } #endif /* dump as C initializer for the terminal type */