Skip to content

Commit

Permalink
Add new warning for deprecated keysyms
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Jul 3, 2023
1 parent 9fcfe99 commit b704736
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
29 changes: 27 additions & 2 deletions src/compose/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions src/xkbcomp/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
Expand Down
23 changes: 19 additions & 4 deletions src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b704736

Please sign in to comment.