action: s/hndlrType/handler_type
[platform/upstream/libxkbcommon.git] / src / xkbcomp / action.c
index 98484b0..22762c6 100644 (file)
  *
  ********************************************************/
 
+/*
+ * Copyright © 2012 Intel Corporation
+ * Copyright © 2012 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Daniel Stone <daniel@fooishbar.org>
+ *         Ran Benita <ran234@gmail.com>
+ */
+
 #include "xkbcomp-priv.h"
 #include "text.h"
 #include "expr.h"
@@ -80,8 +107,7 @@ NewActionsInfo(void)
     if (!info)
         return NULL;
 
-    /* This includes PrivateAction. */
-    for (type = 0; type < ACTION_TYPE_LAST; type++)
+    for (type = 0; type < _ACTION_TYPE_NUM_ENTRIES; type++)
         info->actions[type].type = type;
 
     /* Apply some "factory defaults". */
@@ -252,7 +278,7 @@ CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
         }
     }
 
-    if (!ExprResolveVModMask(keymap, value, mods_rtrn))
+    if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
         return ReportMismatch(keymap, action,
                               ACTION_FIELD_MODIFIERS, "modifier mask");
 
@@ -338,7 +364,7 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
 static bool
 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
                 const ExprDef *value, enum xkb_action_flags *flags_inout,
-                xkb_group_index_t *grp_rtrn)
+                xkb_layout_index_t *grp_rtrn)
 {
     const ExprDef *spec;
 
@@ -370,7 +396,7 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
 {
     struct xkb_group_action *act = &action->group;
     enum xkb_action_flags rtrn, t1;
-    xkb_group_index_t t2;
+    xkb_layout_index_t t2;
 
     if (array_ndx != NULL) {
         switch (field) {
@@ -417,7 +443,7 @@ HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
 {
     struct xkb_group_action *act = &action->group;
     enum xkb_action_flags t1;
-    xkb_group_index_t t2;
+    xkb_layout_index_t t2;
 
     if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
         return ReportActionNotArray(keymap, action->type, field);
@@ -722,7 +748,26 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
             return false;
         }
 
-        act->type = (uint8_t) type;
+        /*
+         * It's possible for someone to write something like this:
+         *      actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
+         * where the type refers to some existing action type, e.g. LockMods.
+         * This assumes that this action's struct is layed out in memory
+         * exactly as described in the XKB specification and libraries.
+         * We, however, have changed these structs in various ways, so this
+         * assumption is no longer true. Since this is a lousy "feature", we
+         * make actions like these no-ops for now.
+         */
+        if (type < ACTION_TYPE_PRIVATE) {
+            log_info(keymap->ctx,
+                     "Private actions of type %s are not supported; Ignored\n",
+                     ActionTypeText(type));
+            act->type = ACTION_TYPE_NONE;
+        }
+        else {
+            act->type = (enum xkb_action_type) type;
+        }
+
         return true;
     }
     else if (field == ACTION_FIELD_DATA) {
@@ -758,9 +803,9 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
 
             if (ndx < 0 || ndx >= sizeof(act->data)) {
                 log_err(keymap->ctx,
-                        "The data for a private action is %zu bytes long; "
+                        "The data for a private action is %lu bytes long; "
                         "Attempt to use data[%d] ignored\n",
-                        sizeof(act->data), ndx);
+                        (unsigned long) sizeof(act->data), ndx);
                 return false;
             }
 
@@ -788,7 +833,7 @@ typedef bool (*actionHandler)(struct xkb_keymap *keymap,
                               const ExprDef *array_ndx,
                               const ExprDef *value);
 
-static const actionHandler handleAction[ACTION_TYPE_LAST] = {
+static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
     [ACTION_TYPE_NONE] = HandleNoAction,
     [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
     [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
@@ -815,7 +860,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
 {
     ExprDef *arg;
     const char *str;
-    unsigned hndlrType;
+    unsigned handler_type;
 
     if (def->op != EXPR_ACTION_DECL) {
         log_err(keymap->ctx, "Expected an action definition, found %s\n",
@@ -824,7 +869,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
     }
 
     str = xkb_atom_text(keymap->ctx, def->value.action.name);
-    if (!stringToAction(str, &hndlrType)) {
+    if (!stringToAction(str, &handler_type)) {
         log_err(keymap->ctx, "Unknown action %s\n", str);
         return false;
     }
@@ -834,7 +879,7 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
      * statements such as:
      *     latchMods.clearLocks = True;
      */
-    *action = info->actions[hndlrType];
+    *action = info->actions[handler_type];
 
     /*
      * Now change the action properties as specified for this
@@ -878,8 +923,8 @@ HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
             return false;
         }
 
-        if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
-                                     value))
+        if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
+                                        value))
             return false;
     }