action: convert a few missed unsigned -> enum xkb_action_type
[platform/upstream/libxkbcommon.git] / src / xkbcomp / action.c
index 0aad747..d2baa5f 100644 (file)
@@ -103,7 +103,7 @@ enum action_field {
 ActionsInfo *
 NewActionsInfo(void)
 {
-    unsigned type;
+    enum xkb_action_type type;
     ActionsInfo *info;
 
     info = calloc(1, sizeof(*info));
@@ -118,6 +118,8 @@ NewActionsInfo(void)
     /* Increment default button. */
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
     info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
+    info->actions[ACTION_TYPE_PTR_MOVE].ptr.flags = ACTION_ACCEL;
+    info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN;
 
     return info;
 }
@@ -166,7 +168,7 @@ static const LookupEntry fieldStrings[] = {
 };
 
 static bool
-stringToAction(const char *str, unsigned *type_rtrn)
+stringToAction(const char *str, enum xkb_action_type *type_rtrn)
 {
     return LookupString(actionTypeNames, str, type_rtrn);
 }
@@ -228,30 +230,23 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
 }
 
 static bool
-CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
-                    enum action_field field, const ExprDef *array_ndx,
-                    const ExprDef *value, enum xkb_action_flags *flags_inout)
+CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
+                 enum action_field field, enum xkb_action_flags flag,
+                 const ExprDef *array_ndx, const ExprDef *value,
+                 enum xkb_action_flags *flags_inout)
 {
-    enum xkb_action_flags tmp;
-    bool result;
+    bool set;
 
     if (array_ndx)
         return ReportActionNotArray(ctx, action, field);
 
-    if (field == ACTION_FIELD_CLEAR_LOCKS)
-        tmp = ACTION_LOCK_CLEAR;
-    else if (field == ACTION_FIELD_LATCH_TO_LOCK)
-        tmp = ACTION_LATCH_TO_LOCK;
-    else
-        return false;           /* WSGO! */
-
-    if (!ExprResolveBoolean(ctx, value, &result))
+    if (!ExprResolveBoolean(ctx, value, &set))
         return ReportMismatch(ctx, action, field, "boolean");
 
-    if (result)
-        *flags_inout |= tmp;
+    if (set)
+        *flags_inout |= flag;
     else
-        *flags_inout &= ~tmp;
+        *flags_inout &= ~flag;
 
     return true;
 }
@@ -283,24 +278,6 @@ CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
     return true;
 }
 
-static bool
-HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
-                   enum action_field field, const ExprDef *array_ndx,
-                   const ExprDef *value)
-{
-    struct xkb_mod_action *act = &action->mods;
-
-    if (field == ACTION_FIELD_CLEAR_LOCKS ||
-        field == ACTION_FIELD_LATCH_TO_LOCK)
-        return CheckLatchLockFlags(keymap->ctx, 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->ctx, action->type, field);
-}
-
 static const LookupEntry lockWhich[] = {
     { "both", 0 },
     { "lock", ACTION_LOCK_NO_UNLOCK },
@@ -329,16 +306,28 @@ CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
 }
 
 static bool
-HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
-               enum action_field field, const ExprDef *array_ndx,
-               const ExprDef *value)
+HandleSetLatchLockMods(struct xkb_keymap *keymap, union xkb_action *action,
+                       enum action_field field, const ExprDef *array_ndx,
+                       const ExprDef *value)
 {
     struct xkb_mod_action *act = &action->mods;
+    const enum xkb_action_type type = action->type;
 
     if (field == ACTION_FIELD_MODIFIERS)
         return CheckModifierField(keymap, action->type, array_ndx, value,
                                   &act->flags, &act->mods.mods);
-    else if (field == ACTION_FIELD_AFFECT)
+    if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) &&
+        field == ACTION_FIELD_CLEAR_LOCKS)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LOCK_CLEAR, array_ndx, value,
+                                &act->flags);
+    if (type == ACTION_TYPE_MOD_LATCH &&
+        field == ACTION_FIELD_LATCH_TO_LOCK)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LATCH_TO_LOCK, array_ndx, value,
+                                &act->flags);
+    if (type == ACTION_TYPE_MOD_LOCK &&
+        field == ACTION_FIELD_AFFECT)
         return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
                                 &act->flags);
 
@@ -346,7 +335,7 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
 }
 
 static bool
-CheckGroupField(struct xkb_context *ctx, unsigned action,
+CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
                 const ExprDef *array_ndx, const ExprDef *value,
                 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
 {
@@ -384,33 +373,26 @@ CheckGroupField(struct xkb_context *ctx, unsigned action,
 }
 
 static bool
-HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
-                    enum action_field field, const ExprDef *array_ndx,
-                    const ExprDef *value)
-{
-    struct xkb_group_action *act = &action->group;
-
-    if (field == ACTION_FIELD_CLEAR_LOCKS ||
-        field == ACTION_FIELD_LATCH_TO_LOCK)
-        return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
-                                   value, &act->flags);
-    else if (field == ACTION_FIELD_GROUP)
-        return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
-                               &act->flags, &act->group);
-
-    return ReportIllegal(keymap->ctx, action->type, field);
-}
-
-static bool
-HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
-                enum action_field field, const ExprDef *array_ndx,
-                const ExprDef *value)
+HandleSetLatchLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
+                        enum action_field field, const ExprDef *array_ndx,
+                        const ExprDef *value)
 {
     struct xkb_group_action *act = &action->group;
+    const enum xkb_action_type type = action->type;
 
     if (field == ACTION_FIELD_GROUP)
         return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
                                &act->flags, &act->group);
+    if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) &&
+        field == ACTION_FIELD_CLEAR_LOCKS)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LOCK_CLEAR, array_ndx, value,
+                                &act->flags);
+    if (type == ACTION_TYPE_GROUP_LATCH &&
+        field == ACTION_FIELD_LATCH_TO_LOCK)
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_LATCH_TO_LOCK, array_ndx, value,
+                                &act->flags);
 
     return ReportIllegal(keymap->ctx, action->type, field);
 }
@@ -456,18 +438,8 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
         return true;
     }
     else if (field == ACTION_FIELD_ACCEL) {
-        bool set;
-
-        if (array_ndx)
-            return ReportActionNotArray(keymap->ctx, action->type, field);
-
-        if (!ExprResolveBoolean(keymap->ctx, value, &set))
-            return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
-        if (set)
-            act->flags &= ~ACTION_NO_ACCEL;
-        else
-            act->flags |= ACTION_NO_ACCEL;
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_ACCEL, array_ndx, value, &act->flags);
     }
 
     return ReportIllegal(keymap->ctx, action->type, field);
@@ -633,20 +605,9 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
         return true;
     }
     else if (field == ACTION_FIELD_SAME) {
-        bool set;
-
-        if (array_ndx)
-            return ReportActionNotArray(keymap->ctx, action->type, field);
-
-        if (!ExprResolveBoolean(keymap->ctx, value, &set))
-            return ReportMismatch(keymap->ctx, action->type, field, "boolean");
-
-        if (set)
-            act->flags &= ~ACTION_SAME_SCREEN;
-        else
-            act->flags |= ACTION_SAME_SCREEN;
-
-        return true;
+        return CheckBooleanFlag(keymap->ctx, action->type, field,
+                                ACTION_SAME_SCREEN, array_ndx, value,
+                                &act->flags);
     }
 
     return ReportIllegal(keymap->ctx, action->type, field);
@@ -660,7 +621,7 @@ HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
     struct xkb_controls_action *act = &action->ctrls;
 
     if (field == ACTION_FIELD_CONTROLS) {
-        unsigned int mask;
+        enum xkb_action_controls mask;
 
         if (array_ndx)
             return ReportActionNotArray(keymap->ctx, action->type, field);
@@ -790,12 +751,12 @@ typedef bool (*actionHandler)(struct xkb_keymap *keymap,
 
 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
     [ACTION_TYPE_NONE] = HandleNoAction,
-    [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
-    [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
-    [ACTION_TYPE_MOD_LOCK] = HandleLockMods,
-    [ACTION_TYPE_GROUP_SET] = HandleSetLatchGroup,
-    [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchGroup,
-    [ACTION_TYPE_GROUP_LOCK] = HandleLockGroup,
+    [ACTION_TYPE_MOD_SET] = HandleSetLatchLockMods,
+    [ACTION_TYPE_MOD_LATCH] = HandleSetLatchLockMods,
+    [ACTION_TYPE_MOD_LOCK] = HandleSetLatchLockMods,
+    [ACTION_TYPE_GROUP_SET] = HandleSetLatchLockGroup,
+    [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchLockGroup,
+    [ACTION_TYPE_GROUP_LOCK] = HandleSetLatchLockGroup,
     [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
     [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
     [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
@@ -890,7 +851,7 @@ bool
 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
                ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
 {
-    unsigned action;
+    enum xkb_action_type action;
     enum action_field action_field;
 
     if (!stringToAction(elem, &action))