expr: drop ExprResult from ResolveKeyCode
authorRan Benita <ran234@gmail.com>
Mon, 23 Jul 2012 21:23:34 +0000 (00:23 +0300)
committerRan Benita <ran234@gmail.com>
Thu, 26 Jul 2012 22:57:13 +0000 (01:57 +0300)
Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/expr.c
src/xkbcomp/expr.h
src/xkbcomp/keycodes.c

index 2b60a011db8cbce4431ea6f43035eb349eb7eb65..7731e4afcad78dcd32c62103250de3cc95ed193d 100644 (file)
@@ -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;
 }
 
index 280cb6e098784a4bc52dcb192e7de14938101fcb..4712ca148d6bba49ae225033eb1a03675af0b554 100644 (file)
@@ -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,
index 558d7cffb076c2f710196aeead51a915bf82155e..cfd09a654219c6cb994563ace938e1c7662ca15a 100644 (file)
@@ -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