#include <parametrized.h>
#include <transform.h>
-MODULE_ID("$Id: tic.c,v 1.233 2017/07/15 17:40:19 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.243 2017/08/26 20:56:55 tom Exp $")
#define STDIN_NAME "<stdin>"
static char **namelst = 0;
static const char *to_remove;
+#if NCURSES_XNAMES
+static bool using_extensions = FALSE;
+#endif
+
static void (*save_check_termtype) (TERMTYPE2 *, bool);
static void check_termtype(TERMTYPE2 *tt, bool);
/* FALLTHRU */
case 'x':
use_extended_names(TRUE);
+ using_extensions = TRUE;
break;
#endif
default:
return result;
}
+static int
+is_user_capability(const char *name)
+{
+ int result = 0;
+ if (name[0] == 'u' &&
+ (name[1] >= '0' && name[1] <= '9') &&
+ name[2] == '\0')
+ result = 1;
+ return result;
+}
+
/*
* Make a quick sanity check for the parameters which are used in the given
* strings. If there are no "%p" tokens, then there should be no other "%"
* markers.
*/
static void
-check_params(TERMTYPE2 *tp, const char *name, char *value)
+check_params(TERMTYPE2 *tp, const char *name, char *value, int extended)
{
int expected = expected_params(name);
int actual = 0;
s++;
}
+ if (extended) {
+ if (actual > 0) {
+ _nc_warning("extended %s capability has %d parameters",
+ name, actual);
+ expected = actual;
+ }
+ }
+
if (params[0]) {
_nc_warning("%s refers to parameter 0 (%%p0), which is not allowed", name);
}
_nc_warning("%s omits parameter %d", name, n);
}
}
+
+ /*
+ * Counting "%p" markers does not account for termcap expressions which
+ * may not have been fully translated. Also, tparm does its own analysis.
+ * Report differences here.
+ */
+ if (actual >= 0) {
+ char *p_is_s[NUM_PARM];
+ int popcount;
+ int analyzed = _nc_tparm_analyze(value, p_is_s, &popcount);
+ if (analyzed < popcount) {
+ analyzed = popcount;
+ }
+ if (actual != analyzed && expected != analyzed) {
+ if (is_user_capability(name)) {
+ _nc_warning("tparm will use %d parameters for %s",
+ analyzed, name);
+ } else {
+ _nc_warning("tparm analyzed %d parameters for %s, expected %d",
+ analyzed, name, actual);
+ }
+ }
+ }
}
static bool
NAME_VALUE *given = get_fkey_list(tp);
if (check == 0)
- failed("check_termtype");
+ failed("check_conflict");
for (j = 0; given[j].keycode; ++j) {
const char *a = given[j].value;
bool first = TRUE;
+ if (!VALID_STRING(a))
+ continue;
+
for (k = j + 1; given[k].keycode; k++) {
const char *b = given[k].value;
+
+ if (!VALID_STRING(b))
+ continue;
if (check[k])
continue;
+
if (!_nc_capcmp(a, b)) {
check[j] = 1;
check[k] = 1;
if (!first)
fprintf(stderr, "\n");
}
+#if NCURSES_XNAMES
+ if (using_extensions) {
+ /* *INDENT-OFF* */
+ static struct {
+ const char *xcurses;
+ const char *shifted;
+ } table[] = {
+ { "kDC", NULL },
+ { "kDN", "kind" },
+ { "kEND", NULL },
+ { "kHOM", NULL },
+ { "kLFT", NULL },
+ { "kNXT", NULL },
+ { "kPRV", NULL },
+ { "kRIT", NULL },
+ { "kUP", "kri" },
+ { NULL, NULL },
+ };
+ /* *INDENT-ON* */
+
+ /*
+ * SVr4 curses defines the "xcurses" names listed above except for
+ * the special cases in the "shifted" column. When using these
+ * names for xterm's extensions, that was confusing, and resulted
+ * in adding extended capabilities with "2" (shift) suffix. This
+ * check warns about unnecessary use of extensions for this quirk.
+ */
+ for (j = 0; given[j].keycode; ++j) {
+ const char *find = given[j].name;
+ int value;
+ char ch;
+
+ if (!VALID_STRING(given[j].value))
+ continue;
+
+ for (k = 0; table[k].xcurses; ++k) {
+ const char *test = table[k].xcurses;
+ size_t size = strlen(test);
+
+ if (!strncmp(find, test, size) && strcmp(find, test)) {
+ switch (sscanf(find + size, "%d%c", &value, &ch)) {
+ case 1:
+ if (value == 2) {
+ _nc_warning("expected '%s' rather than '%s'",
+ (table[k].shifted
+ ? table[k].shifted
+ : test), find);
+ } else if (value < 2 || value > 15) {
+ _nc_warning("expected numeric 2..15 '%s'", find);
+ }
+ break;
+ default:
+ _nc_warning("expected numeric suffix for '%s'", find);
+ break;
+ }
+ break;
+ }
+ }
+ }
+ }
+#endif
free(given);
free(check);
}
for_each_string(j, tp) {
char *a = tp->Strings[j];
if (VALID_STRING(a)) {
- check_params(tp, ExtStrname(tp, (int) j, strnames), a);
+ const char *name = ExtStrname(tp, (int) j, strnames);
+ /*
+ * If we expect parameters, or if there might be parameters,
+ * check for consistent number of parameters.
+ */
+ if (j >= SIZEOF(parametrized) ||
+ is_user_capability(name) ||
+ parametrized[j] > 0) {
+ check_params(tp, name, a, (j >= STRCOUNT));
+ }
check_delays(ExtStrname(tp, (int) j, strnames), a);
if (capdump) {
check_infotocap(tp, (int) j, a);