action: move array_ndx errors into the Check functions Makes more sense and flows more nicely this way. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index fa2bf5b..4cb7b67 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -229,12 +229,15 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
static bool
CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action,
- enum action_field field, const ExprDef *value,
- enum xkb_action_flags *flags_inout)
+ enum action_field field, const ExprDef *array_ndx,
+ const ExprDef *value, enum xkb_action_flags *flags_inout)
{
enum xkb_action_flags tmp;
bool result;
+ if (array_ndx)
+ return ReportActionNotArray(keymap, action, field);
+
if (field == ACTION_FIELD_CLEAR_LOCKS)
tmp = ACTION_LOCK_CLEAR;
else if (field == ACTION_FIELD_LATCH_TO_LOCK)
@@ -255,15 +258,17 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action,
static bool
CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
- const ExprDef *value, enum xkb_action_flags *flags_inout,
- xkb_mod_mask_t *mods_rtrn)
+ const ExprDef *array_ndx, const ExprDef *value,
+ enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn)
{
+ if (array_ndx)
+ return ReportActionNotArray(keymap, action, ACTION_FIELD_MODIFIERS);
+
if (value->expr.op == EXPR_IDENT) {
const char *valStr;
valStr = xkb_atom_text(keymap->ctx, value->ident.ident);
if (valStr && (istreq(valStr, "usemodmapmods") ||
istreq(valStr, "modmapmods"))) {
-
*mods_rtrn = 0;
*flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
return true;
@@ -285,28 +290,13 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_mod_action *act = &action->mods;
- if (array_ndx) {
- switch (field) {
- case ACTION_FIELD_CLEAR_LOCKS:
- case ACTION_FIELD_LATCH_TO_LOCK:
- case ACTION_FIELD_MODIFIERS:
- return ReportActionNotArray(keymap, action->type, field);
- default:
- break;
- }
- }
-
- switch (field) {
- case ACTION_FIELD_CLEAR_LOCKS:
- case ACTION_FIELD_LATCH_TO_LOCK:
- return CheckLatchLockFlags(keymap, action->type, field, value,
- &act->flags);
- case ACTION_FIELD_MODIFIERS:
- return CheckModifierField(keymap, action->type, value,
- &act->flags, &act->mods.mods);
- default:
- break;
- }
+ if (field == ACTION_FIELD_CLEAR_LOCKS ||
+ field == ACTION_FIELD_LATCH_TO_LOCK)
+ return CheckLatchLockFlags(keymap, action->type, field, array_ndx,
+ value, &act->flags);
+ else if (field == ACTION_FIELD_MODIFIERS)
+ return CheckModifierField(keymap, action->type, array_ndx, value,
+ &act->flags, &act->mods.mods);
return ReportIllegal(keymap, action->type, field);
}
@@ -321,10 +311,14 @@ static const LookupEntry lockWhich[] = {
static bool
CheckAffectField(struct xkb_keymap *keymap, enum xkb_action_type action,
- const ExprDef *value, enum xkb_action_flags *flags_inout)
+ const ExprDef *array_ndx, const ExprDef *value,
+ enum xkb_action_flags *flags_inout)
{
enum xkb_action_flags flags;
+ if (array_ndx)
+ return ReportActionNotArray(keymap, action, ACTION_FIELD_AFFECT);
+
if (!ExprResolveEnum(keymap->ctx, value, &flags, lockWhich))
return ReportMismatch(keymap, action, ACTION_FIELD_AFFECT,
"lock, unlock, both, neither");
@@ -341,32 +335,28 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_mod_action *act = &action->mods;
- if (array_ndx && (field == ACTION_FIELD_MODIFIERS ||
- field == ACTION_FIELD_AFFECT))
- return ReportActionNotArray(keymap, action->type, field);
-
- switch (field) {
- case ACTION_FIELD_MODIFIERS:
- return CheckModifierField(keymap, action->type, value,
+ if (field == ACTION_FIELD_MODIFIERS)
+ return CheckModifierField(keymap, action->type, array_ndx, value,
&act->flags, &act->mods.mods);
- case ACTION_FIELD_AFFECT:
- return CheckAffectField(keymap, action->type, value, &act->flags);
- default:
- break;
- }
+ else if (field == ACTION_FIELD_AFFECT)
+ return CheckAffectField(keymap, action->type, array_ndx, value,
+ &act->flags);
return ReportIllegal(keymap, action->type, field);
}
static bool
CheckGroupField(struct xkb_keymap *keymap, unsigned action,
- const ExprDef *value, enum xkb_action_flags *flags_inout,
- int32_t *group_rtrn)
+ const ExprDef *array_ndx, const ExprDef *value,
+ enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
{
const ExprDef *spec;
xkb_layout_index_t idx;
enum xkb_action_flags flags = *flags_inout;
+ if (array_ndx)
+ return ReportActionNotArray(keymap, action, ACTION_FIELD_GROUP);
+
if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
flags &= ~ACTION_ABSOLUTE_SWITCH;
spec = value->unary.child;
@@ -400,28 +390,13 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_group_action *act = &action->group;
- if (array_ndx) {
- switch (field) {
- case ACTION_FIELD_CLEAR_LOCKS:
- case ACTION_FIELD_LATCH_TO_LOCK:
- case ACTION_FIELD_GROUP:
- return ReportActionNotArray(keymap, action->type, field);
- default:
- break;
- }
- }
-
- switch (field) {
- case ACTION_FIELD_CLEAR_LOCKS:
- case ACTION_FIELD_LATCH_TO_LOCK:
- return CheckLatchLockFlags(keymap, action->type, field, value,
- &act->flags);
- case ACTION_FIELD_GROUP:
- return CheckGroupField(keymap, action->type, value,
+ if (field == ACTION_FIELD_CLEAR_LOCKS ||
+ field == ACTION_FIELD_LATCH_TO_LOCK)
+ return CheckLatchLockFlags(keymap, action->type, field, array_ndx,
+ value, &act->flags);
+ else if (field == ACTION_FIELD_GROUP)
+ return CheckGroupField(keymap, action->type, array_ndx, value,
&act->flags, &act->group);
- default:
- break;
- }
return ReportIllegal(keymap, action->type, field);
}
@@ -433,11 +408,8 @@ HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
{
struct xkb_group_action *act = &action->group;
- if (array_ndx && field == ACTION_FIELD_GROUP)
- return ReportActionNotArray(keymap, action->type, field);
-
if (field == ACTION_FIELD_GROUP)
- return CheckGroupField(keymap, action->type, value,
+ return CheckGroupField(keymap, action->type, array_ndx, value,
&act->flags, &act->group);
return ReportIllegal(keymap, action->type, field);
@@ -527,10 +499,8 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
}
else if (action->type == ACTION_TYPE_PTR_LOCK &&
field == ACTION_FIELD_AFFECT) {
- if (array_ndx)
- return ReportActionNotArray(keymap, action->type, field);
-
- return CheckAffectField(keymap, action->type, value, &act->flags);
+ return CheckAffectField(keymap, action->type, array_ndx, value,
+ &act->flags);
}
else if (field == ACTION_FIELD_COUNT) {
int val;
@@ -551,6 +521,7 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->count = (uint8_t) val;
return true;
}
+
return ReportIllegal(keymap, action->type, field);
}
@@ -699,10 +670,8 @@ HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
return true;
}
else if (field == ACTION_FIELD_AFFECT) {
- if (array_ndx)
- return ReportActionNotArray(keymap, action->type, field);
-
- return CheckAffectField(keymap, action->type, value, &act->flags);
+ return CheckAffectField(keymap, action->type, array_ndx, value,
+ &act->flags);
}
return ReportIllegal(keymap, action->type, field);