expr: drop ExprResult from ResolveEnum
authorRan Benita <ran234@gmail.com>
Tue, 24 Jul 2012 16:39:59 +0000 (19:39 +0300)
committerRan Benita <ran234@gmail.com>
Thu, 26 Jul 2012 22:57:14 +0000 (01:57 +0300)
Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/action.c
src/xkbcomp/compat.c
src/xkbcomp/expr.c
src/xkbcomp/expr.h
src/xkbcomp/symbols.c

index cc86387..bdfbbb1 100644 (file)
@@ -508,13 +508,17 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
         return true;
     }
     else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
-        if (array_ndx != NULL)
+        unsigned int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
-        if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
+
+        if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
             return ReportMismatch(keymap, action->type, field,
                                   "lock or unlock");
+
         act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
-        act->flags |= rtrn.ival;
+        act->flags |= val;
         return true;
     }
     else if (field == F_Count) {
@@ -556,12 +560,15 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
 
     act = (struct xkb_pointer_default_action *) action;
     if (field == F_Affect) {
-        if (array_ndx != NULL)
+        unsigned int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
-        if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
+
+        if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
             return ReportMismatch(keymap, action->type, field,
                                   "pointer component");
-        act->affect = rtrn.uval;
+        act->affect = val;
         return true;
     }
     else if ((field == F_Button) || (field == F_Value)) {
@@ -955,14 +962,18 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
         act->button = val;
         return true;
     }
-    else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
-        if (array_ndx != NULL)
+    else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
+        unsigned int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
-        if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
+
+        if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
             return ReportMismatch(keymap, action->type, field,
                                   "lock or unlock");
+
         act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
-        act->flags |= rtrn.ival;
+        act->flags |= val;
         return true;
     }
     else if (field == F_Count) {
index e898d58..f299f39 100644 (file)
@@ -634,29 +634,28 @@ static int
 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
                ExprDef *arrayNdx, ExprDef *value)
 {
-    int ok = 1;
-    ExprResult tmp;
     struct xkb_keymap *keymap = info->keymap;
+    ExprResult tmp;
 
     if (istreq(field, "action")) {
-        if (arrayNdx != NULL)
+        if (arrayNdx)
             return ReportSINotArray(info, si, field);
-        ok = HandleActionDef(value, keymap, &si->interp.act.any,
-                             info->act);
-        if (ok)
-            si->defined |= _SI_Action;
+
+        if (!HandleActionDef(value, keymap, &si->interp.act.any, info->act))
+            return false;
+
+        si->defined |= _SI_Action;
     }
     else if (istreq(field, "virtualmodifier") ||
              istreq(field, "virtualmod")) {
-        if (arrayNdx != NULL)
+        if (arrayNdx)
             return ReportSINotArray(info, si, field);
-        ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
-        if (ok) {
-            si->interp.virtual_mod = tmp.uval;
-            si->defined |= _SI_VirtualMod;
-        }
-        else
+
+        if (!ResolveVirtualModifier(value, keymap, &tmp, &info->vmods))
             return ReportSIBadType(info, si, field, "virtual modifier");
+
+        si->interp.virtual_mod = tmp.uval;
+        si->defined |= _SI_VirtualMod;
     }
     else if (istreq(field, "repeat")) {
         bool set;
@@ -692,24 +691,27 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
     }
     else if (istreq(field, "usemodmap") ||
              istreq(field, "usemodmapmods")) {
-        if (arrayNdx != NULL)
+        unsigned int val;
+
+        if (arrayNdx)
             return ReportSINotArray(info, si, field);
-        ok = ExprResolveEnum(keymap->ctx, value, &tmp, useModMapValues);
-        if (ok) {
-            if (tmp.uval)
-                si->interp.match |= XkbSI_LevelOneOnly;
-            else
-                si->interp.match &= ~XkbSI_LevelOneOnly;
-            si->defined |= _SI_LevelOneOnly;
-        }
-        else
+
+        if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValues))
             return ReportSIBadType(info, si, field, "level specification");
+
+        if (val)
+            si->interp.match |= XkbSI_LevelOneOnly;
+        else
+            si->interp.match &= ~XkbSI_LevelOneOnly;
+
+        si->defined |= _SI_LevelOneOnly;
     }
     else {
-        ok = ReportBadField(keymap, "symbol interpretation", field,
-                            siText(si, info));
+        return ReportBadField(keymap, "symbol interpretation", field,
+                              siText(si, info));
     }
-    return ok;
+
+    return true;
 }
 
 static const LookupEntry modComponentNames[] = {
index 7e10e45..11f803a 100644 (file)
@@ -677,19 +677,19 @@ ExprResolveKeyName(struct xkb_context *ctx, ExprDef *expr,
     return false;
 }
 
-/***====================================================================***/
-
-int
+bool
 ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr,
-                ExprResult *val_rtrn, const LookupEntry *values)
+                unsigned int *val_rtrn, const LookupEntry *values)
 {
+    ExprResult result;
+
     if (expr->op != EXPR_IDENT) {
         log_err(ctx, "Found a %s where an enumerated value was expected\n",
                 exprOpText(expr->op));
         return false;
     }
-    if (!SimpleLookup(ctx, values, expr->value.str, EXPR_TYPE_INT,
-                      val_rtrn)) {
+
+    if (!SimpleLookup(ctx, values, expr->value.str, EXPR_TYPE_INT, &result)) {
         int nOut = 0;
         log_err(ctx, "Illegal identifier %s (expected one of: ",
                 xkb_atom_text(ctx, expr->value.str));
@@ -705,6 +705,8 @@ ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr,
         log_info(ctx, ")\n");
         return false;
     }
+
+    *val_rtrn = result.uval;
     return true;
 }
 
index 5b0c732..194b668 100644 (file)
@@ -94,9 +94,9 @@ bool
 ExprResolveKeyName(struct xkb_context *ctx, ExprDef *expr,
                    char name[XkbKeyNameLength]);
 
-extern int
-ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr, ExprResult *val_rtrn,
-                const LookupEntry *values);
+bool
+ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr,
+                unsigned int *val_rtrn, const LookupEntry *values);
 
 bool
 ExprResolveMask(struct xkb_context *ctx, ExprDef *expr,
index 6dc9a0d..fcb679f 100644 (file)
@@ -1025,7 +1025,6 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
                 ExprDef *arrayNdx, ExprDef *value)
 {
     bool ok = true;
-    ExprResult tmp;
     struct xkb_context *ctx = info->keymap->ctx;
 
     if (istreq(field, "type")) {
@@ -1078,9 +1077,11 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
     else if (istreq(field, "locking") ||
              istreq(field, "lock") ||
              istreq(field, "locks")) {
-        ok = ExprResolveEnum(ctx, value, &tmp, lockingEntries);
+        unsigned int val;
+
+        ok = ExprResolveEnum(ctx, value, &val, lockingEntries);
         if (ok)
-            keyi->behavior.type = tmp.uval;
+            keyi->behavior.type = val;
         keyi->defined |= _Key_Behavior;
     }
     else if (istreq(field, "radiogroup") ||
@@ -1102,7 +1103,9 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
     else if (istreq(field, "repeating") ||
              istreq(field, "repeats") ||
              istreq(field, "repeat")) {
-        ok = ExprResolveEnum(ctx, value, &tmp, repeatEntries);
+        unsigned int val;
+
+        ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
         if (!ok) {
             log_err(info->keymap->ctx,
                     "Illegal repeat setting for %s; "
@@ -1110,7 +1113,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
                     longText(keyi->name));
             return false;
         }
-        keyi->repeat = tmp.uval;
+        keyi->repeat = val;
         keyi->defined |= _Key_Repeat;
     }
     else if (istreq(field, "groupswrap") ||