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>
master
Ran Benita 2012-09-02 10:35:08 +03:00
parent 1736e7daad
commit ba9f66bda3
1 changed files with 63 additions and 49 deletions

View File

@ -1225,9 +1225,10 @@ static const actionHandler handleAction[XkbSA_NumActions + 1] = {
/***====================================================================***/ /***====================================================================***/
static void 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.affect = XkbSA_AffectDfltBtn;
action->dflt.flags = 0; action->dflt.flags = 0;
action->dflt.value = 1; action->dflt.value = 1;
@ -1238,45 +1239,52 @@ ApplyActionFactoryDefaults(union xkb_action * action)
} }
bool bool
HandleActionDef(ExprDef * def, HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
struct xkb_keymap *keymap,
union xkb_action *action, ActionInfo *info) union xkb_action *action, ActionInfo *info)
{ {
ExprDef *arg; ExprDef *arg;
const char *str; const char *str;
unsigned tmp, hndlrType; unsigned hndlrType;
if (def->op != EXPR_ACTION_DECL) { if (def->op != EXPR_ACTION_DECL) {
log_err(keymap->ctx, "Expected an action definition, found %s\n", log_err(keymap->ctx, "Expected an action definition, found %s\n",
expr_op_type_to_string(def->op)); expr_op_type_to_string(def->op));
return false; return false;
} }
str = xkb_atom_text(keymap->ctx, def->value.action.name); str = xkb_atom_text(keymap->ctx, def->value.action.name);
if (!str) { if (!stringToAction(str, &hndlrType)) {
log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
return false;
}
if (!stringToAction(str, &tmp)) {
log_err(keymap->ctx, "Unknown action %s\n", str); log_err(keymap->ctx, "Unknown action %s\n", str);
return false; 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) { if (action->type != XkbSA_NoAction) {
ApplyActionFactoryDefaults((union xkb_action *) action); ApplyActionFactoryDefaults(action);
while (info)
{ for (; info; info = info->next) {
if ((info->action == XkbSA_NoAction) if (info->action != XkbSA_NoAction && info->action != hndlrType)
|| (info->action == hndlrType)) { continue;
if (!(*handleAction[hndlrType])(keymap, action,
info->field, if (!handleAction[hndlrType](keymap, action, info->field,
info->array_ndx, info->array_ndx, info->value))
info->value)) { return false;
return false;
}
}
info = info->next;
} }
} }
/*
* 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; for (arg = def->value.action.args; arg != NULL;
arg = (ExprDef *) arg->common.next) { arg = (ExprDef *) arg->common.next) {
const ExprDef *value; const ExprDef *value;
@ -1288,40 +1296,40 @@ HandleActionDef(ExprDef * def,
field = arg->value.binary.left; field = arg->value.binary.left;
value = arg->value.binary.right; value = arg->value.binary.right;
} }
else { else if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) { field = arg->value.child;
field = arg->value.child; value = &constFalse;
value = &constFalse;
}
else {
field = arg;
value = &constTrue;
}
} }
else {
field = arg;
value = &constTrue;
}
if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn, if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
&arrayRtrn)) &arrayRtrn))
return false; /* internal error -- already reported */ return false;
if (elemRtrn != NULL) { if (elemRtrn) {
log_err(keymap->ctx, log_err(keymap->ctx,
"Cannot change defaults in an action definition; " "Cannot change defaults in an action definition; "
"Ignoring attempt to change %s.%s\n", "Ignoring attempt to change %s.%s\n",
elemRtrn, fieldRtrn); elemRtrn, fieldRtrn);
return false; return false;
} }
if (!stringToField(fieldRtrn, &fieldNdx)) { if (!stringToField(fieldRtrn, &fieldNdx)) {
log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn); log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
return false; return false;
} }
if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn, if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
value)) value))
return false; return false;
} }
return true; return true;
} }
/***====================================================================***/
bool bool
SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field, SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn) 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)); new = malloc(sizeof(*new));
if (!new) { if (!new) {
log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n"); 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; new->action = XkbSA_NoAction;
}
else { else {
if (!stringToAction(elem, &new->action)) { if (!stringToAction(elem, &new->action))
free(new); goto err;
return false;
}
if (new->action == XkbSA_NoAction) { if (new->action == XkbSA_NoAction) {
log_err(keymap->ctx, log_err(keymap->ctx,
"\"%s\" is not a valid field in a NoAction action\n", "\"%s\" is not a valid field in a NoAction action\n",
field); field);
free(new); goto err;
return false;
} }
} }
if (!stringToField(field, &new->field)) { if (!stringToField(field, &new->field)) {
log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field); log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
free(new); goto err;
return false;
} }
new->array_ndx = array_ndx; new->array_ndx = array_ndx;
new->value = value; new->value = value;
new->next = NULL; new->next = NULL;
old = *info_rtrn; old = *info_rtrn;
while ((old) && (old->next)) while (old && old->next)
old = old->next; old = old->next;
if (old == NULL) if (!old)
*info_rtrn = new; *info_rtrn = new;
else else
old->next = new; old->next = new;
return true; return true;
err:
free(new);
return false;
} }