diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index d73bc13..9c9c546 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -486,18 +486,23 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action, act = (struct xkb_pointer_button_action *) action; if (field == F_Button) { - if (array_ndx != NULL) + int btn; + + if (array_ndx) return ReportActionNotArray(keymap, action->type, field); - if (!ExprResolveButton(keymap->ctx, value, &rtrn)) + + if (!ExprResolveButton(keymap->ctx, value, &btn)) return ReportMismatch(keymap, action->type, field, "integer (range 1..5)"); - if ((rtrn.ival < 0) || (rtrn.ival > 5)) { + + if (btn < 0 || btn > 5) { log_err(keymap->ctx, "Button must specify default or be in the range 1..5; " - "Illegal button value %d ignored\n", rtrn.ival); + "Illegal button value %d ignored\n", btn); return false; } - act->button = rtrn.ival; + + act->button = btn; return true; } else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) { @@ -511,17 +516,23 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; } else if (field == F_Count) { - if (array_ndx != NULL) + int btn; + + if (array_ndx) return ReportActionNotArray(keymap, action->type, field); - if (!ExprResolveButton(keymap->ctx, value, &rtrn)) + + /* XXX: Should this actually be ResolveButton? */ + if (!ExprResolveButton(keymap->ctx, value, &btn)) return ReportMismatch(keymap, action->type, field, "integer"); - if ((rtrn.ival < 0) || (rtrn.ival > 255)) { + + if (btn < 0 || btn > 255) { log_err(keymap->ctx, "The count field must have a value in the range 0..255; " "Illegal count %d ignored\n", rtrn.ival); return false; } - act->count = rtrn.ival; + + act->count = btn; return true; } return ReportIllegal(keymap, action->type, field); @@ -552,37 +563,42 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; } else if ((field == F_Button) || (field == F_Value)) { - ExprDef *btn; - if (array_ndx != NULL) + ExprDef *button; + int btn; + + if (array_ndx) return ReportActionNotArray(keymap, action->type, field); + if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) { act->flags &= ~XkbSA_DfltBtnAbsolute; - btn = value->value.child; + button = value->value.child; } else { act->flags |= XkbSA_DfltBtnAbsolute; - btn = value; + button = value; } - if (!ExprResolveButton(keymap->ctx, btn, &rtrn)) + if (!ExprResolveButton(keymap->ctx, button, &btn)) return ReportMismatch(keymap, action->type, field, "integer (range 1..5)"); - if ((rtrn.ival < 0) || (rtrn.ival > 5)) { + + if (btn < 0 || btn > 5) { log_err(keymap->ctx, "New default button value must be in the range 1..5; " "Illegal default button value %d ignored\n", rtrn.ival); return false; } - if (rtrn.ival == 0) { + if (btn == 0) { log_err(keymap->ctx, "Cannot set default pointer button to \"default\"; " "Illegal default button setting ignored\n"); return false; } - act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival); + act->value = (value->op == EXPR_NEGATE ? -btn: btn); return true; } + return ReportIllegal(keymap, action->type, field); } @@ -924,17 +940,23 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; } else if (field == F_Count) { - if (array_ndx != NULL) + int btn; + + if (array_ndx) return ReportActionNotArray(keymap, action->type, field); - if (!ExprResolveButton(keymap->ctx, value, &rtrn)) + + /* XXX: Should this actually be ResolveButton? */ + if (!ExprResolveButton(keymap->ctx, value, &btn)) return ReportMismatch(keymap, action->type, field, "integer"); - if ((rtrn.ival < 0) || (rtrn.ival > 255)) { + + if (btn < 0 || btn > 255) { log_err(keymap->ctx, "The count field must have a value in the range 0..255; " "Illegal count %d ignored\n", rtrn.ival); return false; } - act->count = rtrn.ival; + + act->count = btn; return true; } else if (field == F_Device) { diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index c1d79ee..0d67c2d 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -561,10 +561,11 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr, return true; } -int -ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn) +bool +ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn) { + bool ok; + ExprResult result; static const LookupEntry button_names[] = { { "button1", 1 }, { "button2", 2 }, @@ -575,8 +576,11 @@ ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, { NULL, 0 } }; - return ExprResolveIntegerLookup(ctx, expr, val_rtrn, SimpleLookup, - button_names); + ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup, + button_names); + if (ok) + *btn_rtrn = result.ival; + return ok; } bool diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index bf7891b..d4a0560 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -84,9 +84,8 @@ bool ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr, xkb_group_index_t *group_rtrn); -extern int -ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn); +bool +ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn); bool ExprResolveString(struct xkb_context *ctx, ExprDef *expr,