/****************************************************************************
- * Copyright 2020-2021,2022 Thomas E. Dickey *
+ * Copyright 2020-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 *
#include <dump_entry.h>
-MODULE_ID("$Id: infocmp.c,v 1.155 2022/09/03 23:28:48 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 */
}
static bool
-no_string(char *value)
+no_string(const char *const value)
{
bool result = (value == ABSENT_STRING);
if (!strcmp(s_absent, s_cancel))
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) {
* 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:
{
* 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
sizeof(buf2));
_nc_STRNCPY(buf3, sp + csi, len);
buf3[len] = '\0';
- len += (size_t) csi + 1;
expansion = lookup_params(std_modes, buf2, buf3);
}
sizeof(buf2));
_nc_STRNCPY(buf3, sp + csi + 1, len);
buf3[len] = '\0';
- len += (size_t) csi + 2;
expansion = lookup_params(private_modes, buf2, buf3);
}
}
#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 */