From 000528dd594881cb411c619d29c5a534889d6b25 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 24 Jul 2012 00:23:34 +0300 Subject: [PATCH] expr: drop ExprResult from ResolveKeyCode Signed-off-by: Ran Benita --- src/xkbcomp/expr.c | 37 +++++++++++++------------ src/xkbcomp/expr.h | 5 ++-- src/xkbcomp/keycodes.c | 61 +++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 2b60a01..7731e4a 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -282,11 +282,10 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn) return false; } -int -ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn) +bool +ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc) { - ExprResult leftRtrn, rightRtrn; + xkb_keycode_t leftRtrn, rightRtrn; ExprDef *left, *right; switch (expr->op) { @@ -297,7 +296,8 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, exprValueTypeText(expr->value_type)); return false; } - val_rtrn->uval = expr->value.uval; + + *kc = expr->value.uval; return true; case EXPR_ADD: @@ -306,27 +306,29 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, case EXPR_DIVIDE: left = expr->value.binary.left; right = expr->value.binary.right; + if (!ExprResolveKeyCode(ctx, left, &leftRtrn) || !ExprResolveKeyCode(ctx, right, &rightRtrn)) return false; switch (expr->op) { case EXPR_ADD: - val_rtrn->uval = leftRtrn.uval + rightRtrn.uval; + *kc = leftRtrn + rightRtrn; break; case EXPR_SUBTRACT: - val_rtrn->uval = leftRtrn.uval - rightRtrn.uval; + *kc = leftRtrn - rightRtrn; break; case EXPR_MULTIPLY: - val_rtrn->uval = leftRtrn.uval * rightRtrn.uval; + *kc = leftRtrn * rightRtrn; break; case EXPR_DIVIDE: - if (rightRtrn.uval == 0) { + if (rightRtrn == 0) { log_err(ctx, "Cannot divide by zero: %d / %d\n", - leftRtrn.uval, rightRtrn.uval); + leftRtrn, rightRtrn); return false; } - val_rtrn->uval = leftRtrn.uval / rightRtrn.uval; + + *kc = leftRtrn / rightRtrn; break; default: break; @@ -336,20 +338,21 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, case EXPR_NEGATE: left = expr->value.child; - if (ExprResolveKeyCode(ctx, left, &leftRtrn)) { - val_rtrn->uval = ~leftRtrn.uval; - return true; - } - return false; + if (!ExprResolveKeyCode(ctx, left, &leftRtrn)) + return false; + + *kc = ~leftRtrn; + return true; case EXPR_UNARY_PLUS: left = expr->value.child; - return ExprResolveKeyCode(ctx, left, val_rtrn); + return ExprResolveKeyCode(ctx, left, kc); default: log_wsgo(ctx, "Unknown operator %d in ResolveKeyCode\n", expr->op); break; } + return false; } diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 280cb6e..4712ca1 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -69,9 +69,8 @@ ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr, bool ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn); -extern int -ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn); +bool +ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc); extern int ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr, diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 558d7cf..cfd09a6 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -609,19 +609,19 @@ static int HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt) { const char *elem, *field; - ExprResult tmp; + xkb_keycode_t kc; ExprDef *arrayNdx; int which; - if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, - &arrayNdx) == 0) - return 0; /* internal error, already reported */ + if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, + &arrayNdx)) + return false; /* internal error, already reported */ if (elem) { log_err(info->keymap->ctx, "Unknown element %s encountered; " "Default for field %s ignored\n", elem, field); - goto err_out; + return false; } if (istreq(field, "minimum")) @@ -632,71 +632,72 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt) log_err(info->keymap->ctx, "Unknown field encountered; " "Assigment to field %s ignored\n", field); - goto err_out; + return false; } if (arrayNdx != NULL) { log_err(info->keymap->ctx, "The %s setting is not an array; " "Illegal array reference ignored\n", field); - goto err_out; + return false; } - if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &tmp) == 0) { + if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &kc) == 0) { log_err(info->keymap->ctx, "Illegal keycode encountered; " "Assignment to field %s ignored\n", field); - goto err_out; + return false; } - if (tmp.uval > XKB_KEYCODE_MAX) { + if (kc > XKB_KEYCODE_MAX) { log_err(info->keymap->ctx, "Illegal keycode %d (must be in the range %d-%d inclusive); " "Value of \"%s\" not changed\n", - tmp.uval, 0, XKB_KEYCODE_MAX, field); - goto err_out; + kc, 0, XKB_KEYCODE_MAX, field); + return false; } if (which == MIN_KEYCODE_DEF) { - if ((info->explicitMax > 0) && (info->explicitMax < tmp.uval)) { + if (info->explicitMax > 0 && info->explicitMax < kc) { log_err(info->keymap->ctx, "Minimum key code (%d) must be <= maximum key code (%d); " "Minimum key code value not changed\n", - tmp.uval, info->explicitMax); - goto err_out; + kc, info->explicitMax); + return false; } - if ((info->computedMax > 0) && (info->computedMin < tmp.uval)) { + + if (info->computedMax > 0 && info->computedMin < kc) { log_err(info->keymap->ctx, "Minimum key code (%d) must be <= lowest defined key (%d); " "Minimum key code value not changed\n", - tmp.uval, info->computedMin); - goto err_out; + kc, info->computedMin); + return false; } - info->explicitMin = tmp.uval; + + info->explicitMin = kc; } if (which == MAX_KEYCODE_DEF) { - if ((info->explicitMin > 0) && (info->explicitMin > tmp.uval)) { + if (info->explicitMin > 0 && info->explicitMin > kc) { log_err(info->keymap->ctx, "Maximum code (%d) must be >= minimum key code (%d); " "Maximum code value not changed\n", - tmp.uval, info->explicitMin); - goto err_out; + kc, info->explicitMin); + return false; } - if ((info->computedMax > 0) && (info->computedMax > tmp.uval)) { + + if (info->computedMax > 0 && info->computedMax > kc) { log_err(info->keymap->ctx, "Maximum code (%d) must be >= highest defined key (%d); " "Maximum code value not changed\n", - tmp.uval, info->computedMax); - goto err_out; + kc, info->computedMax); + return false; } - info->explicitMax = tmp.uval; - } - return 1; + info->explicitMax = kc; + } -err_out: - return 0; + return true; } static int -- 2.34.1