diff --git a/src/compose/parser.c b/src/compose/parser.c index 124456d11..c88539a58 100644 --- a/src/compose/parser.c +++ b/src/compose/parser.c @@ -62,6 +62,7 @@ OR PERFORMANCE OF THIS SOFTWARE. #include "paths.h" #include "utf8.h" #include "parser.h" +#include "keysym.h" #define MAX_LHS_LEN 10 #define MAX_INCLUDE_DEPTH 5 @@ -457,6 +458,22 @@ resolve_modifier(const char *name) return XKB_MOD_INVALID; } +static void +check_deprecated_keysym(struct scanner *s, xkb_keysym_t keysym, + xkb_keysym_format_t keysym_format, const char *name) +{ + const char *ref_name = NULL; + if (xkb_keysym_is_deprecated(keysym, keysym_format, name, &ref_name)) { + if (ref_name == NULL) { + scanner_warn(s, "deprecated keysym \"%s\"", name); + } else { + scanner_warn(s, + "deprecated keysym \"%s\"; please use \"%s\"", + name, ref_name); + } + } +} + static bool parse(struct xkb_compose_table *table, struct scanner *s, unsigned include_depth); @@ -585,12 +602,16 @@ parse(struct xkb_compose_table *table, struct scanner *s, lhs_keysym_tok: switch (tok) { case TOK_LHS_KEYSYM: - keysym = xkb_keysym_from_name(val.string.str, XKB_KEYSYM_NO_FLAGS); + xkb_keysym_format_t keysym_format; + keysym = xkb_keysym_with_format_from_name( + val.string.str, XKB_KEYSYM_NO_FLAGS, &keysym_format + ); if (keysym == XKB_KEY_NoSymbol) { scanner_err(s, "unrecognized keysym \"%s\" on left-hand side", val.string.str); goto error; } + check_deprecated_keysym(s, keysym, keysym_format, val.string.str); if (production.len + 1 > MAX_LHS_LEN) { scanner_warn(s, "too many keysyms (%d) on left-hand side; skipping line", MAX_LHS_LEN + 1); @@ -656,12 +677,16 @@ lhs_mod_list_tok: { production.has_string = true; goto rhs; case TOK_IDENT: - keysym = xkb_keysym_from_name(val.string.str, XKB_KEYSYM_NO_FLAGS); + xkb_keysym_format_t keysym_format; + keysym = xkb_keysym_with_format_from_name( + val.string.str, XKB_KEYSYM_NO_FLAGS, &keysym_format + ); if (keysym == XKB_KEY_NoSymbol) { scanner_err(s, "unrecognized keysym \"%s\" on right-hand side", val.string.str); goto error; } + check_deprecated_keysym(s, keysym, keysym_format, val.string.str); if (production.has_keysym) { scanner_warn(s, "right-hand side can have at most one keysym; skipping line"); goto skip; diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index dbdf73434..8a8f2d673 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -29,6 +29,7 @@ #include "xkbcomp-priv.h" #include "text.h" #include "expr.h" +#include "keysym.h" typedef bool (*IdentLookupFunc)(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, @@ -648,9 +649,21 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr, if (expr->expr.op == EXPR_IDENT) { const char *str = xkb_atom_text(ctx, expr->ident.ident); - *sym_rtrn = xkb_keysym_from_name(str, 0); - if (*sym_rtrn != XKB_KEY_NoSymbol) + xkb_keysym_format_t keysym_format; + *sym_rtrn = xkb_keysym_with_format_from_name(str, 0, &keysym_format); + if (*sym_rtrn != XKB_KEY_NoSymbol) { + const char *ref_name = NULL; + if (xkb_keysym_is_deprecated(*sym_rtrn, keysym_format, str, &ref_name)) { + if (ref_name == NULL) { + log_warn(ctx, "deprecated keysym \"%s\"\n", str); + } else { + log_warn(ctx, + "deprecated keysym \"%s\"; please use \"%s\"\n", + str, ref_name); + } + } return true; + } } if (!ExprResolveInteger(ctx, expr, &val)) @@ -659,6 +672,13 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr, if (val < 0 || val >= 10) return false; + /* FIXME: after #357 is merged, this section will + * need to update the test against deprecated keysyms */ + const char *ref_name = NULL; + if (xkb_keysym_is_deprecated(val, XKB_KEYSYM_FORMAT_HEXADECIMAL, NULL, &ref_name)) { + log_warn(ctx, "deprecated keysym \"0x%x\" (%d)\n", val, val); + } + *sym_rtrn = XKB_KEY_0 + (xkb_keysym_t) val; return true; } diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y index 87dea65b2..3684ca16f 100644 --- a/src/xkbcomp/parser.y +++ b/src/xkbcomp/parser.y @@ -37,6 +37,7 @@ #include "xkbcomp/ast-build.h" #include "xkbcomp/parser-priv.h" #include "scanner-utils.h" +#include "keysym.h" struct parser_param { struct xkb_context *ctx; @@ -58,7 +59,7 @@ _xkbcommon_error(struct parser_param *param, const char *msg) } static bool -resolve_keysym(const char *name, xkb_keysym_t *sym_rtrn) +resolve_keysym(struct parser_param *param, const char *name, xkb_keysym_t *sym_rtrn) { xkb_keysym_t sym; @@ -72,9 +73,20 @@ resolve_keysym(const char *name, xkb_keysym_t *sym_rtrn) return true; } - sym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS); + xkb_keysym_format_t keysym_format; + sym = xkb_keysym_with_format_from_name(name, XKB_KEYSYM_NO_FLAGS, &keysym_format); if (sym != XKB_KEY_NoSymbol) { *sym_rtrn = sym; + const char *ref_name = NULL; + if (xkb_keysym_is_deprecated(sym, keysym_format, name, &ref_name)) { + if (ref_name == NULL) { + parser_warn(param, "deprecated keysym \"%s\"", name); + } else { + parser_warn(param, + "deprecated keysym \"%s\"; please use \"%s\"", + name, ref_name); + } + } return true; } @@ -726,7 +738,7 @@ KeySyms : OBRACE KeySymList CBRACE KeySym : IDENT { - if (!resolve_keysym($1, &$$)) { + if (!resolve_keysym(param, $1, &$$)) { parser_warn(param, "unrecognized keysym \"%s\"", $1); $$ = XKB_KEY_NoSymbol; } @@ -743,9 +755,12 @@ KeySym : IDENT $$ = XKB_KEY_0 + (xkb_keysym_t) $1; } else { + /* FIXME: after #357 is merged, this section might + * need to add again the test against deprecated keysyms + */ char buf[32]; snprintf(buf, sizeof(buf), "0x%"PRIx64, $1); - if (!resolve_keysym(buf, &$$)) { + if (!resolve_keysym(param, buf, &$$)) { parser_warn(param, "unrecognized keysym \"%s\"", buf); $$ = XKB_KEY_NoSymbol; }