expr: drop ExprResult from ResolveButton

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-24 01:22:26 +03:00
parent 6ec135700d
commit d568228988
3 changed files with 54 additions and 29 deletions

View File

@ -486,18 +486,23 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_pointer_button_action *) action; act = (struct xkb_pointer_button_action *) action;
if (field == F_Button) { if (field == F_Button) {
if (array_ndx != NULL) int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveButton(keymap->ctx, value, &rtrn))
if (!ExprResolveButton(keymap->ctx, value, &btn))
return ReportMismatch(keymap, action->type, field, return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)"); "integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
if (btn < 0 || btn > 5) {
log_err(keymap->ctx, log_err(keymap->ctx,
"Button must specify default or be in the range 1..5; " "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; return false;
} }
act->button = rtrn.ival;
act->button = btn;
return true; return true;
} }
else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) { 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; return true;
} }
else if (field == F_Count) { else if (field == F_Count) {
if (array_ndx != NULL) int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); 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"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
if (btn < 0 || btn > 255) {
log_err(keymap->ctx, log_err(keymap->ctx,
"The count field must have a value in the range 0..255; " "The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", rtrn.ival); "Illegal count %d ignored\n", rtrn.ival);
return false; return false;
} }
act->count = rtrn.ival;
act->count = btn;
return true; return true;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
@ -552,37 +563,42 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
return true; return true;
} }
else if ((field == F_Button) || (field == F_Value)) { else if ((field == F_Button) || (field == F_Value)) {
ExprDef *btn; ExprDef *button;
if (array_ndx != NULL) int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) { if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
act->flags &= ~XkbSA_DfltBtnAbsolute; act->flags &= ~XkbSA_DfltBtnAbsolute;
btn = value->value.child; button = value->value.child;
} }
else { else {
act->flags |= XkbSA_DfltBtnAbsolute; 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, return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)"); "integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
if (btn < 0 || btn > 5) {
log_err(keymap->ctx, log_err(keymap->ctx,
"New default button value must be in the range 1..5; " "New default button value must be in the range 1..5; "
"Illegal default button value %d ignored\n", rtrn.ival); "Illegal default button value %d ignored\n", rtrn.ival);
return false; return false;
} }
if (rtrn.ival == 0) { if (btn == 0) {
log_err(keymap->ctx, log_err(keymap->ctx,
"Cannot set default pointer button to \"default\"; " "Cannot set default pointer button to \"default\"; "
"Illegal default button setting ignored\n"); "Illegal default button setting ignored\n");
return false; return false;
} }
act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival); act->value = (value->op == EXPR_NEGATE ? -btn: btn);
return true; return true;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
@ -924,17 +940,23 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
return true; return true;
} }
else if (field == F_Count) { else if (field == F_Count) {
if (array_ndx != NULL) int btn;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); 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"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
if (btn < 0 || btn > 255) {
log_err(keymap->ctx, log_err(keymap->ctx,
"The count field must have a value in the range 0..255; " "The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", rtrn.ival); "Illegal count %d ignored\n", rtrn.ival);
return false; return false;
} }
act->count = rtrn.ival;
act->count = btn;
return true; return true;
} }
else if (field == F_Device) { else if (field == F_Device) {

View File

@ -561,10 +561,11 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
return true; return true;
} }
int bool
ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn)
ExprResult *val_rtrn)
{ {
bool ok;
ExprResult result;
static const LookupEntry button_names[] = { static const LookupEntry button_names[] = {
{ "button1", 1 }, { "button1", 1 },
{ "button2", 2 }, { "button2", 2 },
@ -575,8 +576,11 @@ ExprResolveButton(struct xkb_context *ctx, ExprDef *expr,
{ NULL, 0 } { NULL, 0 }
}; };
return ExprResolveIntegerLookup(ctx, expr, val_rtrn, SimpleLookup, ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
button_names); button_names);
if (ok)
*btn_rtrn = result.ival;
return ok;
} }
bool bool

View File

@ -84,9 +84,8 @@ bool
ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr, ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
xkb_group_index_t *group_rtrn); xkb_group_index_t *group_rtrn);
extern int bool
ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn);
ExprResult *val_rtrn);
bool bool
ExprResolveString(struct xkb_context *ctx, ExprDef *expr, ExprResolveString(struct xkb_context *ctx, ExprDef *expr,