action: use new log functions

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-21 14:53:49 +03:00
parent 87444fb969
commit e037f51862
2 changed files with 164 additions and 132 deletions

View File

@ -37,7 +37,6 @@
#define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr)) #define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
#define uDupString(s) ((s) ? strdup(s) : NULL) #define uDupString(s) ((s) ? strdup(s) : NULL)
#define uStringText(s) ((s) == NULL ? "<NullString>" : (s))
#define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0) #define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
/* Compiler Attributes */ /* Compiler Attributes */

View File

@ -166,46 +166,54 @@ fieldText(unsigned field)
/***====================================================================***/ /***====================================================================***/
static inline bool static inline bool
ReportMismatch(unsigned action, unsigned field, const char *type) ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
const char *type)
{ {
ERROR("Value of %s field must be of type %s\n", fieldText(field), type); log_err(keymap->ctx,
ACTION("Action %s definition ignored\n", XkbcActionTypeText(action)); "Value of %s field must be of type %s; "
"Action %s definition ignored\n",
fieldText(field), type, XkbcActionTypeText(action));
return false; return false;
} }
static inline bool static inline bool
ReportIllegal(unsigned action, unsigned field) ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
{ {
ERROR("Field %s is not defined for an action of type %s\n", log_err(keymap->ctx,
"Field %s is not defined for an action of type %s; "
"Action definition ignored\n",
fieldText(field), XkbcActionTypeText(action)); fieldText(field), XkbcActionTypeText(action));
ACTION("Action definition ignored\n");
return false; return false;
} }
static inline bool static inline bool
ReportActionNotArray(unsigned action, unsigned field) ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
unsigned field)
{ {
ERROR("The %s field in the %s action is not an array\n", log_err(keymap->ctx,
"The %s field in the %s action is not an array; "
"Action definition ignored\n",
fieldText(field), XkbcActionTypeText(action)); fieldText(field), XkbcActionTypeText(action));
ACTION("Action definition ignored\n");
return false; return false;
} }
static inline bool static inline bool
ReportNotFound(unsigned action, unsigned field, const char *what, ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
const char *bad) const char *what, const char *bad)
{ {
ERROR("%s named %s not found\n", what, bad); log_err(keymap->ctx,
ACTION("Ignoring the %s field of an %s action\n", fieldText(field), "%s named %s not found; "
XkbcActionTypeText(action)); "Ignoring the %s field of an %s action\n",
what, bad, fieldText(field), XkbcActionTypeText(action));
return false; return false;
} }
static bool static bool
HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action, HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action,
unsigned field, ExprDef *array_ndx, ExprDef *value) unsigned field, ExprDef *array_ndx, ExprDef *value)
{ {
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -222,7 +230,7 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
else else
return false; /* WSGO! */ return false; /* WSGO! */
if (!ExprResolveBoolean(keymap->ctx, value, &result)) if (!ExprResolveBoolean(keymap->ctx, value, &result))
return ReportMismatch(action, field, "boolean"); return ReportMismatch(keymap, action, field, "boolean");
if (result.uval) if (result.uval)
*flags_inout |= tmp; *flags_inout |= tmp;
else else
@ -248,7 +256,7 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
} }
} }
if (!ExprResolveVModMask(value, &rtrn, keymap)) if (!ExprResolveVModMask(value, &rtrn, keymap))
return ReportMismatch(action, F_Modifiers, "modifier mask"); return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
*mods_rtrn = rtrn.uval; *mods_rtrn = rtrn.uval;
*flags_inout &= ~XkbSA_UseModMapMods; *flags_inout &= ~XkbSA_UseModMapMods;
return true; return true;
@ -268,7 +276,7 @@ HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_ClearLocks: case F_ClearLocks:
case F_LatchToLock: case F_LatchToLock:
case F_Modifiers: case F_Modifiers:
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
} }
} }
switch (field) { switch (field) {
@ -291,7 +299,7 @@ HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
return false; return false;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -303,7 +311,7 @@ HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_mod_action *) action; act = (struct xkb_mod_action *) action;
if ((array_ndx != NULL) && (field == F_Modifiers)) if ((array_ndx != NULL) && (field == F_Modifiers))
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
switch (field) { switch (field) {
case F_Modifiers: case F_Modifiers:
t1 = act->flags; t1 = act->flags;
@ -315,7 +323,7 @@ HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
return false; return false;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -336,7 +344,8 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
} }
if (!ExprResolveGroup(keymap->ctx, spec, &rtrn)) if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
return ReportMismatch(action, F_Group, "integer (range 1..8)"); return ReportMismatch(keymap, action, F_Group,
"integer (range 1..8)");
if (value->op == OpNegate) if (value->op == OpNegate)
*grp_rtrn = -rtrn.ival; *grp_rtrn = -rtrn.ival;
else if (value->op == OpUnaryPlus) else if (value->op == OpUnaryPlus)
@ -361,7 +370,7 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_ClearLocks: case F_ClearLocks:
case F_LatchToLock: case F_LatchToLock:
case F_Group: case F_Group:
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
} }
} }
switch (field) { switch (field) {
@ -383,7 +392,7 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
return false; return false;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -396,7 +405,7 @@ HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_group_action *) action; act = (struct xkb_group_action *) action;
if ((array_ndx != NULL) && (field == F_Group)) if ((array_ndx != NULL) && (field == F_Group))
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (field == F_Group) { if (field == F_Group) {
t1 = act->flags; t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
@ -406,7 +415,7 @@ HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
return false; return false;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -419,7 +428,7 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_pointer_action *) action; act = (struct xkb_pointer_action *) action;
if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y))) if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((field == F_X) || (field == F_Y)) { if ((field == F_X) || (field == F_Y)) {
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
@ -427,7 +436,7 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
else else
absolute = true; absolute = true;
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if (field == F_X) { if (field == F_X) {
if (absolute) if (absolute)
act->flags |= XkbSA_MoveAbsoluteX; act->flags |= XkbSA_MoveAbsoluteX;
@ -442,13 +451,13 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
else if (field == F_Accel) { else if (field == F_Accel) {
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval) if (rtrn.uval)
act->flags &= ~XkbSA_NoAcceleration; act->flags &= ~XkbSA_NoAcceleration;
else else
act->flags |= XkbSA_NoAcceleration; act->flags |= XkbSA_NoAcceleration;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static const LookupEntry lockWhich[] = { static const LookupEntry lockWhich[] = {
@ -469,13 +478,14 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_pointer_button_action *) action; act = (struct xkb_pointer_button_action *) action;
if (field == F_Button) { if (field == F_Button) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveButton(keymap->ctx, value, &rtrn)) if (!ExprResolveButton(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)"); "integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5)) { if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
ERROR("Button must specify default or be in the range 1..5\n"); log_err(keymap->ctx,
ACTION("Illegal button value %d ignored\n", rtrn.ival); "Button must specify default or be in the range 1..5; "
"Illegal button value %d ignored\n", rtrn.ival);
return false; return false;
} }
act->button = rtrn.ival; act->button = rtrn.ival;
@ -483,27 +493,29 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) { else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich)) if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
return ReportMismatch(action->type, field, "lock or unlock"); return ReportMismatch(keymap, action->type, field,
"lock or unlock");
act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock); act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
act->flags |= rtrn.ival; act->flags |= rtrn.ival;
return true; return true;
} }
else if (field == F_Count) { else if (field == F_Count) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveButton(keymap->ctx, value, &rtrn)) if (!ExprResolveButton(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("The count field must have a value in the range 0..255\n"); log_err(keymap->ctx,
ACTION("Illegal count %d ignored\n", rtrn.ival); "The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", rtrn.ival);
return false; return false;
} }
act->count = rtrn.ival; act->count = rtrn.ival;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static const LookupEntry ptrDflts[] = { static const LookupEntry ptrDflts[] = {
@ -523,16 +535,17 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_pointer_default_action *) action; act = (struct xkb_pointer_default_action *) action;
if (field == F_Affect) { if (field == F_Affect) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts)) if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
return ReportMismatch(action->type, field, "pointer component"); return ReportMismatch(keymap, action->type, field,
"pointer component");
act->affect = rtrn.uval; act->affect = rtrn.uval;
return true; return true;
} }
else if ((field == F_Button) || (field == F_Value)) { else if ((field == F_Button) || (field == F_Value)) {
ExprDef *btn; ExprDef *btn;
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) { if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
act->flags &= ~XkbSA_DfltBtnAbsolute; act->flags &= ~XkbSA_DfltBtnAbsolute;
btn = value->value.child; btn = value->value.child;
@ -543,16 +556,18 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
if (!ExprResolveButton(keymap->ctx, btn, &rtrn)) if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
return ReportMismatch(action->type, field, return ReportMismatch(keymap, action->type, field,
"integer (range 1..5)"); "integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5)) { if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
ERROR("New default button value must be in the range 1..5\n"); log_err(keymap->ctx,
ACTION("Illegal default button value %d ignored\n", rtrn.ival); "New default button value must be in the range 1..5; "
"Illegal default button value %d ignored\n", rtrn.ival);
return false; return false;
} }
if (rtrn.ival == 0) { if (rtrn.ival == 0) {
ERROR("Cannot set default pointer button to \"default\"\n"); log_err(keymap->ctx,
ACTION("Illegal default button setting ignored\n"); "Cannot set default pointer button to \"default\"; "
"Illegal default button setting ignored\n");
return false; return false;
} }
if (value->op == OpNegate) if (value->op == OpNegate)
@ -561,7 +576,7 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
act->value = rtrn.ival; act->value = rtrn.ival;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static const LookupEntry isoNames[] = { static const LookupEntry isoNames[] = {
@ -591,7 +606,7 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
switch (field) { switch (field) {
case F_Modifiers: case F_Modifiers:
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
flags = act->flags; flags = act->flags;
if (CheckModifierField(keymap, action->type, value, &flags, &mods)) { if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
act->flags = flags & (~XkbSA_ISODfltIsGroup); act->flags = flags & (~XkbSA_ISODfltIsGroup);
@ -603,7 +618,7 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_Group: case F_Group:
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
flags = act->flags; flags = act->flags;
if (CheckGroupField(keymap, action->type, value, &flags, &group)) { if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
act->flags = flags | XkbSA_ISODfltIsGroup; act->flags = flags | XkbSA_ISODfltIsGroup;
@ -614,13 +629,14 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_Affect: case F_Affect:
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames)) if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
return ReportMismatch(action->type, field, "keyboard component"); return ReportMismatch(keymap, action->type, field,
"keyboard component");
act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask; act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -634,7 +650,7 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
if (field == F_Screen) { if (field == F_Screen) {
ExprDef *scrn; ExprDef *scrn;
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) { if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
act->flags &= ~XkbSA_SwitchAbsolute; act->flags &= ~XkbSA_SwitchAbsolute;
scrn = value->value.child; scrn = value->value.child;
@ -645,10 +661,12 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn)) if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
return ReportMismatch(action->type, field, "integer (0..255)"); return ReportMismatch(keymap, action->type, field,
"integer (0..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("Screen index must be in the range 1..255\n"); log_err(keymap->ctx,
ACTION("Illegal screen value %d ignored\n", rtrn.ival); "Screen index must be in the range 1..255; "
"Illegal screen value %d ignored\n", rtrn.ival);
return false; return false;
} }
if (value->op == OpNegate) if (value->op == OpNegate)
@ -659,16 +677,16 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
else if (field == F_Same) { else if (field == F_Same) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval) if (rtrn.uval)
act->flags &= ~XkbSA_SwitchApplication; act->flags &= ~XkbSA_SwitchApplication;
else else
act->flags |= XkbSA_SwitchApplication; act->flags |= XkbSA_SwitchApplication;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
const LookupEntry ctrlNames[] = { const LookupEntry ctrlNames[] = {
@ -704,13 +722,14 @@ HandleSetLockControls(struct xkb_keymap *keymap,
act = (struct xkb_controls_action *) action; act = (struct xkb_controls_action *) action;
if (field == F_Controls) { if (field == F_Controls) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames)) if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
return ReportMismatch(action->type, field, "controls mask"); return ReportMismatch(keymap, action->type, field,
"controls mask");
act->ctrls = rtrn.uval; act->ctrls = rtrn.uval;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static const LookupEntry evNames[] = { static const LookupEntry evNames[] = {
@ -734,9 +753,10 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
switch (field) { switch (field) {
case F_Report: case F_Report:
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames)) if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
return ReportMismatch(action->type, field, "key event mask"); return ReportMismatch(keymap, action->type, field,
"key event mask");
act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease); act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
act->flags = act->flags =
rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease); rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
@ -744,9 +764,9 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_GenKeyEvent: case F_GenKeyEvent:
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveBoolean(keymap->ctx, value, &rtrn)) if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "boolean"); return ReportMismatch(keymap, action->type, field, "boolean");
if (rtrn.uval) if (rtrn.uval)
act->flags |= XkbSA_MessageGenKeyEvent; act->flags |= XkbSA_MessageGenKeyEvent;
else else
@ -756,12 +776,13 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_Data: case F_Data:
if (array_ndx == NULL) { if (array_ndx == NULL) {
if (!ExprResolveString(keymap->ctx, value, &rtrn)) if (!ExprResolveString(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "string"); return ReportMismatch(keymap, action->type, field, "string");
else { else {
int len = strlen(rtrn.str); int len = strlen(rtrn.str);
if ((len < 1) || (len > 6)) { if ((len < 1) || (len > 6)) {
WARN("An action message can hold only 6 bytes\n"); log_warn(keymap->ctx,
ACTION("Extra %d bytes ignored\n", len - 6); "An action message can hold only 6 bytes; "
"Extra %d bytes ignored\n", len - 6);
} }
strncpy((char *) act->message, rtrn.str, 6); strncpy((char *) act->message, rtrn.str, 6);
} }
@ -770,28 +791,31 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
else { else {
unsigned ndx; unsigned ndx;
if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) { if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
ERROR("Array subscript must be integer\n"); log_err(keymap->ctx,
ACTION("Illegal subscript ignored\n"); "Array subscript must be integer; "
"Illegal subscript ignored\n");
return false; return false;
} }
ndx = rtrn.uval; ndx = rtrn.uval;
if (ndx > 5) { if (ndx > 5) {
ERROR("An action message is at most 6 bytes long\n"); log_err(keymap->ctx,
ACTION("Attempt to use data[%d] ignored\n", ndx); "An action message is at most 6 bytes long; "
"Attempt to use data[%d] ignored\n", ndx);
return false; return false;
} }
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("Message data must be in the range 0..255\n"); log_err(keymap->ctx,
ACTION("Illegal datum %d ignored\n", rtrn.ival); "Message data must be in the range 0..255; "
"Illegal datum %d ignored\n", rtrn.ival);
return false; return false;
} }
act->message[ndx] = rtrn.uval; act->message[ndx] = rtrn.uval;
} }
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -805,18 +829,18 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
unsigned long tmp; unsigned long tmp;
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
act = (struct xkb_redirect_key_action *) action; act = (struct xkb_redirect_key_action *) action;
switch (field) { switch (field) {
case F_Keycode: case F_Keycode:
if (!ExprResolveKeyName(keymap->ctx, value, &rtrn)) if (!ExprResolveKeyName(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "key name"); return ReportMismatch(keymap, action->type, field, "key name");
tmp = KeyNameToLong(rtrn.name); tmp = KeyNameToLong(rtrn.name);
key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0); key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
if (!key) if (!key)
return ReportNotFound(action->type, field, "Key", return ReportNotFound(keymap, action->type, field, "Key",
XkbcKeyNameText(rtrn.name)); XkbcKeyNameText(rtrn.name));
act->new_kc = XkbKeyGetKeycode(keymap, key); act->new_kc = XkbKeyGetKeycode(keymap, key);
return true; return true;
@ -841,7 +865,7 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -854,13 +878,14 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
act = (struct xkb_device_button_action *) action; act = (struct xkb_device_button_action *) action;
if (field == F_Button) { if (field == F_Button) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, return ReportMismatch(keymap, action->type, field,
"integer (range 1..255)"); "integer (range 1..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("Button must specify default or be in the range 1..255\n"); log_err(keymap->ctx,
ACTION("Illegal button value %d ignored\n", rtrn.ival); "Button must specify default or be in the range 1..255; "
"Illegal button value %d ignored\n", rtrn.ival);
return false; return false;
} }
act->button = rtrn.ival; act->button = rtrn.ival;
@ -868,21 +893,23 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) { else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich)) if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
return ReportMismatch(action->type, field, "lock or unlock"); return ReportMismatch(keymap, action->type, field,
"lock or unlock");
act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock); act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
act->flags |= rtrn.ival; act->flags |= rtrn.ival;
return true; return true;
} }
else if (field == F_Count) { else if (field == F_Count) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveButton(keymap->ctx, value, &rtrn)) if (!ExprResolveButton(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("The count field must have a value in the range 0..255\n"); log_err(keymap->ctx,
ACTION("Illegal count %d ignored\n", rtrn.ival); "The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", rtrn.ival);
return false; return false;
} }
act->count = rtrn.ival; act->count = rtrn.ival;
@ -890,19 +917,20 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
} }
else if (field == F_Device) { else if (field == F_Device) {
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(action->type, field); return ReportActionNotArray(keymap, action->type, field);
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, return ReportMismatch(keymap, action->type, field,
"integer (range 1..255)"); "integer (range 1..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("Device must specify default or be in the range 1..255\n"); log_err(keymap->ctx,
ACTION("Illegal device value %d ignored\n", rtrn.ival); "Device must specify default or be in the range 1..255; "
"Illegal device value %d ignored\n", rtrn.ival);
return false; return false;
} }
act->device = rtrn.ival; act->device = rtrn.ival;
return true; return true;
} }
return ReportIllegal(action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
@ -928,10 +956,11 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
switch (field) { switch (field) {
case F_Type: case F_Type:
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(PrivateAction, field, "integer"); return ReportMismatch(keymap, PrivateAction, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("Private action type must be in the range 0..255\n"); log_err(keymap->ctx,
ACTION("Illegal type %d ignored\n", rtrn.ival); "Private action type must be in the range 0..255; "
"Illegal type %d ignored\n", rtrn.ival);
return false; return false;
} }
action->type = rtrn.uval; action->type = rtrn.uval;
@ -940,12 +969,13 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
case F_Data: case F_Data:
if (array_ndx == NULL) { if (array_ndx == NULL) {
if (!ExprResolveString(keymap->ctx, value, &rtrn)) if (!ExprResolveString(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "string"); return ReportMismatch(keymap, action->type, field, "string");
else { else {
int len = strlen(rtrn.str); int len = strlen(rtrn.str);
if ((len < 1) || (len > 7)) { if ((len < 1) || (len > 7)) {
WARN("A private action has 7 data bytes\n"); log_warn(keymap->ctx,
ACTION("Extra %d bytes ignored\n", len - 6); "A private action has 7 data bytes; "
"Extra %d bytes ignored\n", len - 6);
return false; return false;
} }
strncpy((char *) action->data, rtrn.str, sizeof action->data); strncpy((char *) action->data, rtrn.str, sizeof action->data);
@ -956,28 +986,31 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
else { else {
unsigned ndx; unsigned ndx;
if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) { if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
ERROR("Array subscript must be integer\n"); log_err(keymap->ctx,
ACTION("Illegal subscript ignored\n"); "Array subscript must be integer; "
"Illegal subscript ignored\n");
return false; return false;
} }
ndx = rtrn.uval; ndx = rtrn.uval;
if (ndx >= sizeof action->data) { if (ndx >= sizeof action->data) {
ERROR("The data for a private action is 18 bytes long\n"); log_err(keymap->ctx,
ACTION("Attempt to use data[%d] ignored\n", ndx); "The data for a private action is 18 bytes long; "
"Attempt to use data[%d] ignored\n", ndx);
return false; return false;
} }
if (!ExprResolveInteger(keymap->ctx, value, &rtrn)) if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
return ReportMismatch(action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255)) { if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
ERROR("All data for a private action must be 0..255\n"); log_err(keymap->ctx,
ACTION("Illegal datum %d ignored\n", rtrn.ival); "All data for a private action must be 0..255; "
"Illegal datum %d ignored\n", rtrn.ival);
return false; return false;
} }
action->data[ndx] = rtrn.uval; action->data[ndx] = rtrn.uval;
return true; return true;
} }
} }
return ReportIllegal(PrivateAction, field); return ReportIllegal(keymap, PrivateAction, field);
} }
typedef bool (*actionHandler)(struct xkb_keymap *keymap, typedef bool (*actionHandler)(struct xkb_keymap *keymap,
@ -1040,17 +1073,17 @@ HandleActionDef(ExprDef * def,
ActionsInit(keymap->ctx); ActionsInit(keymap->ctx);
if (def->op != ExprActionDecl) { if (def->op != ExprActionDecl) {
ERROR("Expected an action definition, found %s\n", log_err(keymap->ctx, "Expected an action definition, found %s\n",
exprOpText(def->op)); exprOpText(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 (!str) {
WSGO("Missing name in action definition!!\n"); log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
return false; return false;
} }
if (!stringToAction(str, &tmp)) { if (!stringToAction(str, &tmp)) {
ERROR("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 = tmp;
@ -1096,15 +1129,16 @@ HandleActionDef(ExprDef * def,
return false; /* internal error -- already reported */ return false; /* internal error -- already reported */
if (elemRtrn.str != NULL) { if (elemRtrn.str != NULL) {
ERROR("Cannot change defaults in an action definition\n"); log_err(keymap->ctx,
ACTION("Ignoring attempt to change %s.%s\n", elemRtrn.str, "Cannot change defaults in an action definition; "
fieldRtrn.str); "Ignoring attempt to change %s.%s\n",
elemRtrn.str, fieldRtrn.str);
free(elemRtrn.str); free(elemRtrn.str);
free(fieldRtrn.str); free(fieldRtrn.str);
return false; return false;
} }
if (!stringToField(fieldRtrn.str, &fieldNdx)) { if (!stringToField(fieldRtrn.str, &fieldNdx)) {
ERROR("Unknown field name %s\n", uStringText(fieldRtrn.str)); log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn.str);
free(elemRtrn.str); free(elemRtrn.str);
free(fieldRtrn.str); free(fieldRtrn.str);
return false; return false;
@ -1121,10 +1155,8 @@ HandleActionDef(ExprDef * def,
/***====================================================================***/ /***====================================================================***/
int int
SetActionField(struct xkb_keymap *keymap, SetActionField(struct xkb_keymap *keymap, char *elem, char *field,
char *elem, ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
char *field,
ExprDef * array_ndx, ExprDef * value, ActionInfo ** info_rtrn)
{ {
ActionInfo *new, *old; ActionInfo *new, *old;
@ -1133,7 +1165,7 @@ SetActionField(struct xkb_keymap *keymap,
new = malloc(sizeof(*new)); new = malloc(sizeof(*new));
if (!new) { if (!new) {
WSGO("Couldn't allocate space for action default\n"); log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
return false; return false;
} }
@ -1145,14 +1177,15 @@ SetActionField(struct xkb_keymap *keymap,
return false; return false;
} }
if (new->action == XkbSA_NoAction) { if (new->action == XkbSA_NoAction) {
ERROR("\"%s\" is not a valid field in a NoAction action\n", log_err(keymap->ctx,
"\"%s\" is not a valid field in a NoAction action\n",
field); field);
free(new); free(new);
return false; return false;
} }
} }
if (!stringToField(field, &new->field)) { if (!stringToField(field, &new->field)) {
ERROR("\"%s\" is not a legal field name\n", field); log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
free(new); free(new);
return false; return false;
} }