action: clean up formatting of extern functions Make it a bit easier to understand what they do. 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
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 9691f57..4a8d20d 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -1225,9 +1225,10 @@ static const actionHandler handleAction[XkbSA_NumActions + 1] = {
/***====================================================================***/
static void
-ApplyActionFactoryDefaults(union xkb_action * action)
+ApplyActionFactoryDefaults(union xkb_action *action)
{
- if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
+ if (action->type == XkbSA_SetPtrDflt) {
+ /* Increment default button. */
action->dflt.affect = XkbSA_AffectDfltBtn;
action->dflt.flags = 0;
action->dflt.value = 1;
@@ -1238,45 +1239,52 @@ ApplyActionFactoryDefaults(union xkb_action * action)
}
bool
-HandleActionDef(ExprDef * def,
- struct xkb_keymap *keymap,
+HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
union xkb_action *action, ActionInfo *info)
{
ExprDef *arg;
const char *str;
- unsigned tmp, hndlrType;
+ unsigned hndlrType;
if (def->op != EXPR_ACTION_DECL) {
log_err(keymap->ctx, "Expected an action definition, found %s\n",
expr_op_type_to_string(def->op));
return false;
}
+
str = xkb_atom_text(keymap->ctx, def->value.action.name);
- if (!str) {
- log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
- return false;
- }
- if (!stringToAction(str, &tmp)) {
+ if (!stringToAction(str, &hndlrType)) {
log_err(keymap->ctx, "Unknown action %s\n", str);
return false;
}
- action->type = hndlrType = tmp;
+
+ action->type = hndlrType;
+
+ /*
+ * Go through all of the ActionInfo's which change the default values
+ * for this action->type and apply them to this action, e.g. if the
+ * action is latchMods, and a statement such as this:
+ * latchMods.clearLocks = True;
+ * appears in the section before, then we apply it.
+ */
if (action->type != XkbSA_NoAction) {
- ApplyActionFactoryDefaults((union xkb_action *) action);
- while (info)
- {
- if ((info->action == XkbSA_NoAction)
- || (info->action == hndlrType)) {
- if (!(*handleAction[hndlrType])(keymap, action,
- info->field,
- info->array_ndx,
- info->value)) {
- return false;
- }
- }
- info = info->next;
+ ApplyActionFactoryDefaults(action);
+
+ for (; info; info = info->next) {
+ if (info->action != XkbSA_NoAction && info->action != hndlrType)
+ continue;
+
+ if (!handleAction[hndlrType](keymap, action, info->field,
+ info->array_ndx, info->value))
+ return false;
}
}
+
+ /*
+ * Now change the action properties as specified for this
+ * particular instance, e.g. "modifiers" and "clearLocks" in:
+ * SetMods(modifiers=Alt,clearLocks);
+ */
for (arg = def->value.action.args; arg != NULL;
arg = (ExprDef *) arg->common.next) {
const ExprDef *value;
@@ -1288,40 +1296,40 @@ HandleActionDef(ExprDef * def,
field = arg->value.binary.left;
value = arg->value.binary.right;
}
+ else if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
+ field = arg->value.child;
+ value = &constFalse;
+ }
else {
- if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
- field = arg->value.child;
- value = &constFalse;
- }
- else {
- field = arg;
- value = &constTrue;
- }
+ field = arg;
+ value = &constTrue;
}
+
if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
&arrayRtrn))
- return false; /* internal error -- already reported */
+ return false;
- if (elemRtrn != NULL) {
+ if (elemRtrn) {
log_err(keymap->ctx,
"Cannot change defaults in an action definition; "
"Ignoring attempt to change %s.%s\n",
elemRtrn, fieldRtrn);
return false;
}
+
if (!stringToField(fieldRtrn, &fieldNdx)) {
log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
return false;
}
+
if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
value))
return false;
}
+
return true;
}
-/***====================================================================***/
-
bool
SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
@@ -1331,38 +1339,44 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
new = malloc(sizeof(*new));
if (!new) {
log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
- return false;
+ goto err;
}
- if (istreq(elem, "action"))
+ if (istreq(elem, "action")) {
new->action = XkbSA_NoAction;
+ }
else {
- if (!stringToAction(elem, &new->action)) {
- free(new);
- return false;
- }
+ if (!stringToAction(elem, &new->action))
+ goto err;
+
if (new->action == XkbSA_NoAction) {
log_err(keymap->ctx,
"\"%s\" is not a valid field in a NoAction action\n",
field);
- free(new);
- return false;
+ goto err;
}
}
+
if (!stringToField(field, &new->field)) {
log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
- free(new);
- return false;
+ goto err;
}
+
new->array_ndx = array_ndx;
new->value = value;
+
new->next = NULL;
old = *info_rtrn;
- while ((old) && (old->next))
+ while (old && old->next)
old = old->next;
- if (old == NULL)
+ if (!old)
*info_rtrn = new;
else
old->next = new;
+
return true;
+
+err:
+ free(new);
+ return false;
}