diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 5706626..ee09865 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -221,7 +221,7 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action, unsigned field, ExprDef * value, unsigned *flags_inout) { unsigned tmp; - ExprResult result; + bool result; if (field == F_ClearLocks) tmp = XkbSA_ClearLocks; @@ -229,12 +229,15 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action, tmp = XkbSA_LatchToLock; else return false; /* WSGO! */ + if (!ExprResolveBoolean(keymap->ctx, value, &result)) return ReportMismatch(keymap, action, field, "boolean"); - if (result.uval) + + if (result) *flags_inout |= tmp; else *flags_inout &= ~tmp; + return true; } @@ -453,13 +456,17 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; } 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"); - if (rtrn.uval) + + if (set) act->flags &= ~XkbSA_NoAcceleration; else act->flags |= XkbSA_NoAcceleration; } + return ReportIllegal(keymap, action->type, field); } @@ -678,16 +685,22 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; } else if (field == F_Same) { - if (array_ndx != NULL) + bool set; + + if (array_ndx) 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"); - if (rtrn.uval) + + if (set) act->flags &= ~XkbSA_SwitchApplication; else act->flags |= XkbSA_SwitchApplication; + return true; } + return ReportIllegal(keymap, action->type, field); } @@ -750,6 +763,7 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action, { ExprResult rtrn; const char *str; + bool set; struct xkb_message_action *act; act = (struct xkb_message_action *) action; @@ -766,14 +780,17 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action, return true; case F_GenKeyEvent: - if (array_ndx != NULL) + if (array_ndx) 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"); - if (rtrn.uval) + + if (set) act->flags |= XkbSA_MessageGenKeyEvent; else act->flags &= ~XkbSA_MessageGenKeyEvent; + return true; case F_Data: diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index 7fb5063..ea42f21 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -665,32 +665,36 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field, return ReportSIBadType(info, si, field, "virtual modifier"); } else if (istreq(field, "repeat")) { - if (arrayNdx != NULL) + bool set; + + if (arrayNdx) return ReportSINotArray(info, si, field); - ok = ExprResolveBoolean(keymap->ctx, value, &tmp); - if (ok) { - if (tmp.uval) - si->interp.flags |= XkbSI_AutoRepeat; - else - si->interp.flags &= ~XkbSI_AutoRepeat; - si->defined |= _SI_AutoRepeat; - } - else + + if (!ExprResolveBoolean(keymap->ctx, value, &set)) 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")) { - if (arrayNdx != NULL) + bool set; + + if (arrayNdx) return ReportSINotArray(info, si, field); - ok = ExprResolveBoolean(keymap->ctx, value, &tmp); - if (ok) { - if (tmp.uval) - si->interp.flags |= XkbSI_LockingKey; - else - si->interp.flags &= ~XkbSI_LockingKey; - si->defined |= _SI_LockingKey; - } - else + + if (!ExprResolveBoolean(keymap->ctx, value, &set)) 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") || istreq(field, "usemodmapmods")) { @@ -789,16 +793,19 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led, led->defined |= _LED_Ctrls; } else if (istreq(field, "allowexplicit")) { - if (arrayNdx != NULL) + bool set; + + if (arrayNdx) return ReportIndicatorNotArray(info, led, field); - if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) + if (!ExprResolveBoolean(keymap->ctx, value, &set)) return ReportIndicatorBadType(info, led, field, "boolean"); - if (rtrn.uval) + if (set) led->flags &= ~XkbIM_NoExplicit; else led->flags |= XkbIM_NoExplicit; + led->defined |= _LED_Explicit; } else if (istreq(field, "whichmodstate") || @@ -828,16 +835,19 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led, istreq(field, "leddriveskeyboard") || istreq(field, "indicatordriveskbd") || istreq(field, "indicatordriveskeyboard")) { - if (arrayNdx != NULL) + bool set; + + if (arrayNdx) return ReportIndicatorNotArray(info, led, field); - if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) + if (!ExprResolveBoolean(keymap->ctx, value, &set)) return ReportIndicatorBadType(info, led, field, "boolean"); - if (rtrn.uval) + if (set) led->flags |= XkbIM_LEDDrivesKB; else led->flags &= ~XkbIM_LEDDrivesKB; + led->defined |= _LED_DrivesKbd; } else if (istreq(field, "index")) { diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 150dce1..2d71ca7 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -214,11 +214,10 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, return ret; } -int -ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn) +bool +ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn) { - int ok = 0; + bool ok = false; const char *ident; switch (expr->op) { @@ -229,7 +228,7 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, exprValueTypeText(expr->value_type)); return false; } - val_rtrn->ival = expr->value.ival; + *set_rtrn = !!expr->value.ival; return true; case EXPR_IDENT: @@ -238,13 +237,13 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, if (istreq(ident, "true") || istreq(ident, "yes") || istreq(ident, "on")) { - val_rtrn->uval = 1; + *set_rtrn = true; return true; } else if (istreq(ident, "false") || istreq(ident, "no") || istreq(ident, "off")) { - val_rtrn->uval = 0; + *set_rtrn = false; return true; } } @@ -260,9 +259,9 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, case EXPR_INVERT: case EXPR_NOT: - ok = ExprResolveBoolean(ctx, expr, val_rtrn); + ok = ExprResolveBoolean(ctx, expr, set_rtrn); if (ok) - val_rtrn->uval = !val_rtrn->uval; + *set_rtrn = !*set_rtrn; return ok; case EXPR_ADD: 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); break; } + return false; } diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 9465beb..214ea8d 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -66,9 +66,8 @@ extern int ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr, ExprResult *val_rtrn); -extern int -ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn); +bool +ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn); extern int ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index f196f0b..06db89d 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1110,32 +1110,40 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, } else if (istreq(field, "groupswrap") || istreq(field, "wrapgroups")) { - if (!ExprResolveBoolean(ctx, value, &tmp)) { + bool set; + + if (!ExprResolveBoolean(ctx, value, &set)) { log_err(info->keymap->ctx, "Illegal groupsWrap setting for %s; " "Non-boolean value ignored\n", longText(keyi->name)); return false; } - if (tmp.uval) + + if (set) keyi->out_of_range_group_action = XkbWrapIntoRange; else keyi->out_of_range_group_action = XkbClampIntoRange; + keyi->defined |= _Key_GroupInfo; } else if (istreq(field, "groupsclamp") || istreq(field, "clampgroups")) { - if (!ExprResolveBoolean(ctx, value, &tmp)) { + bool set; + + if (!ExprResolveBoolean(ctx, value, &set)) { log_err(info->keymap->ctx, "Illegal groupsClamp setting for %s; " "Non-boolean value ignored\n", longText(keyi->name)); return false; } - if (tmp.uval) + + if (set) keyi->out_of_range_group_action = XkbClampIntoRange; else keyi->out_of_range_group_action = XkbWrapIntoRange; + keyi->defined |= _Key_GroupInfo; } else if (istreq(field, "groupsredirect") ||