expr: drop ExprResult from ResolveBoolean

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-23 19:52:17 +03:00
parent 27f9492969
commit 0d262fa105
5 changed files with 86 additions and 52 deletions

View File

@ -221,7 +221,7 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
unsigned field, ExprDef * value, unsigned *flags_inout) unsigned field, ExprDef * value, unsigned *flags_inout)
{ {
unsigned tmp; unsigned tmp;
ExprResult result; bool result;
if (field == F_ClearLocks) if (field == F_ClearLocks)
tmp = XkbSA_ClearLocks; tmp = XkbSA_ClearLocks;
@ -229,12 +229,15 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
tmp = XkbSA_LatchToLock; tmp = XkbSA_LatchToLock;
else else
return false; /* WSGO! */ return false; /* WSGO! */
if (!ExprResolveBoolean(keymap->ctx, value, &result)) if (!ExprResolveBoolean(keymap->ctx, value, &result))
return ReportMismatch(keymap, action, field, "boolean"); return ReportMismatch(keymap, action, field, "boolean");
if (result.uval)
if (result)
*flags_inout |= tmp; *flags_inout |= tmp;
else else
*flags_inout &= ~tmp; *flags_inout &= ~tmp;
return true; return true;
} }
@ -453,13 +456,17 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
return true; return true;
} }
else if (field == F_Accel) { else if (field == F_Accel) {
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) bool set;
if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportMismatch(keymap, action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval)
if (set)
act->flags &= ~XkbSA_NoAcceleration; act->flags &= ~XkbSA_NoAcceleration;
else else
act->flags |= XkbSA_NoAcceleration; act->flags |= XkbSA_NoAcceleration;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
@ -678,16 +685,22 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
return true; return true;
} }
else if (field == F_Same) { else if (field == F_Same) {
if (array_ndx != NULL) bool set;
if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportMismatch(keymap, action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval)
if (set)
act->flags &= ~XkbSA_SwitchApplication; act->flags &= ~XkbSA_SwitchApplication;
else else
act->flags |= XkbSA_SwitchApplication; act->flags |= XkbSA_SwitchApplication;
return true; return true;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
@ -750,6 +763,7 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
{ {
ExprResult rtrn; ExprResult rtrn;
const char *str; const char *str;
bool set;
struct xkb_message_action *act; struct xkb_message_action *act;
act = (struct xkb_message_action *) action; act = (struct xkb_message_action *) action;
@ -766,14 +780,17 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
return true; return true;
case F_GenKeyEvent: case F_GenKeyEvent:
if (array_ndx != NULL) if (array_ndx)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportMismatch(keymap, action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval)
if (set)
act->flags |= XkbSA_MessageGenKeyEvent; act->flags |= XkbSA_MessageGenKeyEvent;
else else
act->flags &= ~XkbSA_MessageGenKeyEvent; act->flags &= ~XkbSA_MessageGenKeyEvent;
return true; return true;
case F_Data: case F_Data:

View File

@ -665,32 +665,36 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
return ReportSIBadType(info, si, field, "virtual modifier"); return ReportSIBadType(info, si, field, "virtual modifier");
} }
else if (istreq(field, "repeat")) { else if (istreq(field, "repeat")) {
if (arrayNdx != NULL) bool set;
if (arrayNdx)
return ReportSINotArray(info, si, field); return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (ok) { if (!ExprResolveBoolean(keymap->ctx, value, &set))
if (tmp.uval)
si->interp.flags |= XkbSI_AutoRepeat;
else
si->interp.flags &= ~XkbSI_AutoRepeat;
si->defined |= _SI_AutoRepeat;
}
else
return ReportSIBadType(info, si, field, "boolean"); return ReportSIBadType(info, si, field, "boolean");
if (set)
si->interp.flags |= XkbSI_AutoRepeat;
else
si->interp.flags &= ~XkbSI_AutoRepeat;
si->defined |= _SI_AutoRepeat;
} }
else if (istreq(field, "locking")) { else if (istreq(field, "locking")) {
if (arrayNdx != NULL) bool set;
if (arrayNdx)
return ReportSINotArray(info, si, field); return ReportSINotArray(info, si, field);
ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
if (ok) { if (!ExprResolveBoolean(keymap->ctx, value, &set))
if (tmp.uval)
si->interp.flags |= XkbSI_LockingKey;
else
si->interp.flags &= ~XkbSI_LockingKey;
si->defined |= _SI_LockingKey;
}
else
return ReportSIBadType(info, si, field, "boolean"); return ReportSIBadType(info, si, field, "boolean");
if (set)
si->interp.flags |= XkbSI_LockingKey;
else
si->interp.flags &= ~XkbSI_LockingKey;
si->defined |= _SI_LockingKey;
} }
else if (istreq(field, "usemodmap") || else if (istreq(field, "usemodmap") ||
istreq(field, "usemodmapmods")) { istreq(field, "usemodmapmods")) {
@ -789,16 +793,19 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
led->defined |= _LED_Ctrls; led->defined |= _LED_Ctrls;
} }
else if (istreq(field, "allowexplicit")) { else if (istreq(field, "allowexplicit")) {
if (arrayNdx != NULL) bool set;
if (arrayNdx)
return ReportIndicatorNotArray(info, led, field); return ReportIndicatorNotArray(info, led, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportIndicatorBadType(info, led, field, "boolean"); return ReportIndicatorBadType(info, led, field, "boolean");
if (rtrn.uval) if (set)
led->flags &= ~XkbIM_NoExplicit; led->flags &= ~XkbIM_NoExplicit;
else else
led->flags |= XkbIM_NoExplicit; led->flags |= XkbIM_NoExplicit;
led->defined |= _LED_Explicit; led->defined |= _LED_Explicit;
} }
else if (istreq(field, "whichmodstate") || else if (istreq(field, "whichmodstate") ||
@ -828,16 +835,19 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
istreq(field, "leddriveskeyboard") || istreq(field, "leddriveskeyboard") ||
istreq(field, "indicatordriveskbd") || istreq(field, "indicatordriveskbd") ||
istreq(field, "indicatordriveskeyboard")) { istreq(field, "indicatordriveskeyboard")) {
if (arrayNdx != NULL) bool set;
if (arrayNdx)
return ReportIndicatorNotArray(info, led, field); return ReportIndicatorNotArray(info, led, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) if (!ExprResolveBoolean(keymap->ctx, value, &set))
return ReportIndicatorBadType(info, led, field, "boolean"); return ReportIndicatorBadType(info, led, field, "boolean");
if (rtrn.uval) if (set)
led->flags |= XkbIM_LEDDrivesKB; led->flags |= XkbIM_LEDDrivesKB;
else else
led->flags &= ~XkbIM_LEDDrivesKB; led->flags &= ~XkbIM_LEDDrivesKB;
led->defined |= _LED_DrivesKbd; led->defined |= _LED_DrivesKbd;
} }
else if (istreq(field, "index")) { else if (istreq(field, "index")) {

View File

@ -214,11 +214,10 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
return ret; return ret;
} }
int bool
ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn)
ExprResult *val_rtrn)
{ {
int ok = 0; bool ok = false;
const char *ident; const char *ident;
switch (expr->op) { switch (expr->op) {
@ -229,7 +228,7 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
exprValueTypeText(expr->value_type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->ival = expr->value.ival; *set_rtrn = !!expr->value.ival;
return true; return true;
case EXPR_IDENT: case EXPR_IDENT:
@ -238,13 +237,13 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
if (istreq(ident, "true") || if (istreq(ident, "true") ||
istreq(ident, "yes") || istreq(ident, "yes") ||
istreq(ident, "on")) { istreq(ident, "on")) {
val_rtrn->uval = 1; *set_rtrn = true;
return true; return true;
} }
else if (istreq(ident, "false") || else if (istreq(ident, "false") ||
istreq(ident, "no") || istreq(ident, "no") ||
istreq(ident, "off")) { istreq(ident, "off")) {
val_rtrn->uval = 0; *set_rtrn = false;
return true; return true;
} }
} }
@ -260,9 +259,9 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
case EXPR_INVERT: case EXPR_INVERT:
case EXPR_NOT: case EXPR_NOT:
ok = ExprResolveBoolean(ctx, expr, val_rtrn); ok = ExprResolveBoolean(ctx, expr, set_rtrn);
if (ok) if (ok)
val_rtrn->uval = !val_rtrn->uval; *set_rtrn = !*set_rtrn;
return ok; return ok;
case EXPR_ADD: case EXPR_ADD:
case EXPR_SUBTRACT: case EXPR_SUBTRACT:
@ -279,6 +278,7 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
log_wsgo(ctx, "Unknown operator %d in ResolveBoolean\n", expr->op); log_wsgo(ctx, "Unknown operator %d in ResolveBoolean\n", expr->op);
break; break;
} }
return false; return false;
} }

View File

@ -66,9 +66,8 @@ extern int
ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr, ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr,
ExprResult *val_rtrn); ExprResult *val_rtrn);
extern int bool
ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn);
ExprResult *val_rtrn);
extern int extern int
ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,

View File

@ -1110,32 +1110,40 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
} }
else if (istreq(field, "groupswrap") || else if (istreq(field, "groupswrap") ||
istreq(field, "wrapgroups")) { istreq(field, "wrapgroups")) {
if (!ExprResolveBoolean(ctx, value, &tmp)) { bool set;
if (!ExprResolveBoolean(ctx, value, &set)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Illegal groupsWrap setting for %s; " "Illegal groupsWrap setting for %s; "
"Non-boolean value ignored\n", "Non-boolean value ignored\n",
longText(keyi->name)); longText(keyi->name));
return false; return false;
} }
if (tmp.uval)
if (set)
keyi->out_of_range_group_action = XkbWrapIntoRange; keyi->out_of_range_group_action = XkbWrapIntoRange;
else else
keyi->out_of_range_group_action = XkbClampIntoRange; keyi->out_of_range_group_action = XkbClampIntoRange;
keyi->defined |= _Key_GroupInfo; keyi->defined |= _Key_GroupInfo;
} }
else if (istreq(field, "groupsclamp") || else if (istreq(field, "groupsclamp") ||
istreq(field, "clampgroups")) { istreq(field, "clampgroups")) {
if (!ExprResolveBoolean(ctx, value, &tmp)) { bool set;
if (!ExprResolveBoolean(ctx, value, &set)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Illegal groupsClamp setting for %s; " "Illegal groupsClamp setting for %s; "
"Non-boolean value ignored\n", "Non-boolean value ignored\n",
longText(keyi->name)); longText(keyi->name));
return false; return false;
} }
if (tmp.uval)
if (set)
keyi->out_of_range_group_action = XkbClampIntoRange; keyi->out_of_range_group_action = XkbClampIntoRange;
else else
keyi->out_of_range_group_action = XkbWrapIntoRange; keyi->out_of_range_group_action = XkbWrapIntoRange;
keyi->defined |= _Key_GroupInfo; keyi->defined |= _Key_GroupInfo;
} }
else if (istreq(field, "groupsredirect") || else if (istreq(field, "groupsredirect") ||