From bd927abf3df164c29d080d9c5ed51301fd1a940b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 24 Jul 2012 19:39:59 +0300 Subject: [PATCH] expr: drop ExprResult from ResolveEnum Signed-off-by: Ran Benita --- src/xkbcomp/action.c | 31 ++++++++++++++++-------- src/xkbcomp/compat.c | 56 ++++++++++++++++++++++--------------------- src/xkbcomp/expr.c | 14 ++++++----- src/xkbcomp/expr.h | 6 ++--- src/xkbcomp/symbols.c | 13 ++++++---- 5 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index cc86387..bdfbbb1 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -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) { diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index e898d58..f299f39 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -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[] = { diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 7e10e45..11f803a 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -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; } diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 5b0c732..194b668 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -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, diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 6dc9a0d..fcb679f 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -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") ||