From d90814db94038d394731f4b2490a699769b598b0 Mon Sep 17 00:00:00 2001 From: Pierre Le Marre Date: Fri, 22 Sep 2023 10:48:13 +0200 Subject: [PATCH] Improve xkb_keysym_is_deprecated --- src/keysym.c | 29 +++++++++++------------------ src/xkbcomp/parser.y | 2 -- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/keysym.c b/src/keysym.c index 2c8eb06cb..1df6bd5bf 100644 --- a/src/keysym.c +++ b/src/keysym.c @@ -248,10 +248,13 @@ xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags) /* * Check whether a keysym with code "keysym" and name "name" is deprecated. - * If so, and if there is a non-deprecated name for the given keysym, then write - * it in "reference_name", else write NULL. - * If "name" is NULL, then just check if there is some non-deprecated name for - * "keysym". + * • If the keysym is not deprecated itself and has no deprecated names, + * then return false and write NULL in "reference_name". + * • If there is a non-deprecated name for the given keysym, then write this + * name in "reference_name", else write NULL and return true. + * • If "name" is NULL, then returns false: the keysym itself is not deprecated. + * • If "name" is not NULL, then returns whether "name" and "reference_name" + * are different. * * WARNING: this function is unsafe because it does not test if "name" is * actually a correct name for "keysym". It is intended to be used just after @@ -292,20 +295,10 @@ xkb_keysym_is_deprecated(xkb_keysym_t keysym, return true; } else { /* There is a reference name that is not deprecated */ - if (keysym_format != XKB_KEYSYM_FORMAT_NAME || name == NULL) { - /* No name given: just indicate not deprecated */ - *reference_name = NULL; - return false; - } else { - /* Check if the given name is the reference one */ - *reference_name = get_name(&deprecated_keysyms[mid]); - if (strcmp(name, *reference_name) == 0) { - *reference_name = NULL; - return false; - } else { - return true; - } - } + *reference_name = get_name(&deprecated_keysyms[mid]); + /* If there is no name given: just indicate not deprecated; + * else check if the given name is the reference one */ + return (name != NULL && strcmp(name, *reference_name) != 0); } } } diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y index 235ffb8ab..8cd41a769 100644 --- a/src/xkbcomp/parser.y +++ b/src/xkbcomp/parser.y @@ -774,14 +774,12 @@ KeySym : IDENT if (unlikely(param->ctx->log_verbosity >= XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM)) { - // [FIXME] ref_name is never used: change API to allow NULL?? const char *ref_name = NULL; if (xkb_keysym_is_deprecated($$, XKB_KEYSYM_FORMAT_NUMERIC, NULL, &ref_name)) { if (ref_name == NULL) { parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM, "deprecated keysym \"0x%"PRIx64"\"", $1); } else { - // [FIXME] currently dead code parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM, "deprecated keysym \"0x%"PRIx64"\"; please use \"%s\"", $1, ref_name);