From 025ca5790532adfb187bc2508659b2fabb2c05a3 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 23 Jul 2012 12:20:05 +0300 Subject: [PATCH] expr: drop ExprResult from ResolveLhs Signed-off-by: Ran Benita --- src/xkbcomp/action.c | 17 +++++++++-------- src/xkbcomp/compat.c | 34 +++++++++++++++++----------------- src/xkbcomp/expr.c | 23 ++++++++++------------- src/xkbcomp/expr.h | 10 ++++------ src/xkbcomp/keycodes.c | 21 +++++++++++---------- src/xkbcomp/keytypes.c | 29 +++++++++++++++++------------ src/xkbcomp/symbols.c | 39 +++++++++++++++++++-------------------- 7 files changed, 87 insertions(+), 86 deletions(-) diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index ab836c4..11a9eb9 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -1108,7 +1108,7 @@ HandleActionDef(ExprDef * def, for (arg = def->value.action.args; arg != NULL; arg = (ExprDef *) arg->common.next) { ExprDef *field, *value, *arrayRtrn; - ExprResult elemRtrn, fieldRtrn; + const char *elemRtrn, *fieldRtrn; unsigned fieldNdx; if (arg->op == EXPR_ASSIGN) { @@ -1127,22 +1127,23 @@ HandleActionDef(ExprDef * def, value = &constTrue; } } - if (!ExprResolveLhs(keymap, field, &elemRtrn, &fieldRtrn, &arrayRtrn)) + if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn, + &arrayRtrn)) return false; /* internal error -- already reported */ - if (elemRtrn.str != NULL) { + if (elemRtrn != NULL) { log_err(keymap->ctx, "Cannot change defaults in an action definition; " "Ignoring attempt to change %s.%s\n", - elemRtrn.str, fieldRtrn.str); + elemRtrn, fieldRtrn); return false; } - if (!stringToField(fieldRtrn.str, &fieldNdx)) { - log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn.str); + if (!stringToField(fieldRtrn, &fieldNdx)) { + log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn); return false; } - if (!(*handleAction[hndlrType])(keymap, action, fieldNdx, arrayRtrn, - value)) + if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn, + value)) return false; } return true; diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index adbb446..7fb5063 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -874,20 +874,20 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led, static int HandleInterpVar(CompatInfo *info, VarDef *stmt) { - ExprResult elem, field; + const char *elem, *field; ExprDef *ndx; int ret; - if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &ndx) == 0) + if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx)) ret = 0; /* internal error, already reported */ - else if (elem.str && istreq(elem.str, "interpret")) - ret = SetInterpField(info, &info->dflt, field.str, ndx, stmt->value); - else if (elem.str && istreq(elem.str, "indicator")) - ret = SetIndicatorMapField(info, &info->ledDflt, field.str, ndx, + else if (elem && istreq(elem, "interpret")) + ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value); + else if (elem && istreq(elem, "indicator")) + ret = SetIndicatorMapField(info, &info->ledDflt, field, ndx, stmt->value); else - ret = SetActionField(info->keymap, elem.str, field.str, ndx, - stmt->value, &info->act); + ret = SetActionField(info->keymap, elem, field, ndx, stmt->value, + &info->act); return ret; } @@ -895,7 +895,7 @@ static int HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si) { int ok = 1; - ExprResult tmp, field; + const char *elem, *field; ExprDef *arrayNdx; for (; def != NULL; def = (VarDef *) def->common.next) { @@ -903,9 +903,10 @@ HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si) ok = HandleInterpVar(info, def); continue; } - ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field, &arrayNdx); + ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field, + &arrayNdx); if (ok) { - ok = SetInterpField(info, si, field.str, arrayNdx, def->value); + ok = SetInterpField(info, si, field, arrayNdx, def->value); } } return ok; @@ -997,23 +998,22 @@ HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def, ok = true; for (var = def->body; var != NULL; var = (VarDef *) var->common.next) { - ExprResult elem, field; + const char *elem, *field; ExprDef *arrayNdx; - if (!ExprResolveLhs(info->keymap, var->name, &elem, &field, + if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field, &arrayNdx)) { ok = false; continue; } - if (elem.str != NULL) { + if (elem) { log_err(info->keymap->ctx, "Cannot set defaults for \"%s\" element in indicator map; " - "Assignment to %s.%s ignored\n", - elem.str, elem.str, field.str); + "Assignment to %s.%s ignored\n", elem, elem, field); ok = false; } else { - ok = SetIndicatorMapField(info, &led, field.str, arrayNdx, + ok = SetIndicatorMapField(info, &led, field, arrayNdx, var->value) && ok; } } diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index f5f3657..308124c 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -122,33 +122,30 @@ exprValueTypeText(enum expr_value_type type) return buf; } -int -ExprResolveLhs(struct xkb_keymap *keymap, ExprDef *expr, - ExprResult *elem_rtrn, ExprResult *field_rtrn, - ExprDef **index_rtrn) +bool +ExprResolveLhs(struct xkb_context *ctx, ExprDef *expr, const char **elem_rtrn, + const char **field_rtrn, ExprDef **index_rtrn) { - struct xkb_context *ctx = keymap->ctx; - switch (expr->op) { case EXPR_IDENT: - elem_rtrn->str = NULL; - field_rtrn->str = xkb_atom_text(ctx, expr->value.str); + *elem_rtrn = NULL; + *field_rtrn = xkb_atom_text(ctx, expr->value.str); *index_rtrn = NULL; return true; case EXPR_FIELD_REF: - elem_rtrn->str = xkb_atom_text(ctx, expr->value.field.element); - field_rtrn->str = xkb_atom_text(ctx, expr->value.field.field); + *elem_rtrn = xkb_atom_text(ctx, expr->value.field.element); + *field_rtrn = xkb_atom_text(ctx, expr->value.field.field); *index_rtrn = NULL; return true; case EXPR_ARRAY_REF: - elem_rtrn->str = xkb_atom_text(ctx, expr->value.array.element); - field_rtrn->str = xkb_atom_text(ctx, expr->value.array.field); + *elem_rtrn = xkb_atom_text(ctx, expr->value.array.element); + *field_rtrn = xkb_atom_text(ctx, expr->value.array.field); *index_rtrn = expr->value.array.entry; return true; default: break; } - log_wsgo(keymap->ctx, "Unexpected operator %d in ResolveLhs\n", expr->op); + log_wsgo(ctx, "Unexpected operator %d in ResolveLhs\n", expr->op); return false; } diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 549998b..9befb0b 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -33,14 +33,8 @@ typedef union _ExprResult { const char *str; int ival; unsigned uval; - char name[XkbKeyNameLength]; } ExprResult; -extern int -ExprResolveLhs(struct xkb_keymap *keymap, ExprDef *expr, - ExprResult *elem_rtrn, ExprResult *field_rtrn, - ExprDef **index_rtrn); - typedef struct _LookupEntry { const char *name; unsigned result; @@ -49,6 +43,10 @@ typedef struct _LookupEntry { extern const char * exprOpText(enum expr_op_type op); +bool +ExprResolveLhs(struct xkb_context *ctx, ExprDef *expr, const char **elem_rtrn, + const char **field_rtrn, ExprDef **index_rtrn); + extern bool LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, ExprResult *val_rtrn); diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 5db85dd..708b636 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -608,43 +608,44 @@ HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge, static int HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt) { - ExprResult tmp, field; + const char *elem, *field; + ExprResult tmp; ExprDef *arrayNdx; int which; - if (ExprResolveLhs(info->keymap, stmt->name, &tmp, &field, + if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &arrayNdx) == 0) return 0; /* internal error, already reported */ - if (tmp.str != NULL) { + if (elem) { log_err(info->keymap->ctx, "Unknown element %s encountered; " - "Default for field %s ignored\n", tmp.str, field.str); + "Default for field %s ignored\n", elem, field); goto err_out; } - if (istreq(field.str, "minimum")) + if (istreq(field, "minimum")) which = MIN_KEYCODE_DEF; - else if (istreq(field.str, "maximum")) + else if (istreq(field, "maximum")) which = MAX_KEYCODE_DEF; else { log_err(info->keymap->ctx, "Unknown field encountered; " - "Assigment to field %s ignored\n", field.str); + "Assigment to field %s ignored\n", field); goto err_out; } if (arrayNdx != NULL) { log_err(info->keymap->ctx, "The %s setting is not an array; " - "Illegal array reference ignored\n", field.str); + "Illegal array reference ignored\n", field); goto err_out; } if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &tmp) == 0) { log_err(info->keymap->ctx, "Illegal keycode encountered; " - "Assignment to field %s ignored\n", field.str); + "Assignment to field %s ignored\n", field); goto err_out; } @@ -652,7 +653,7 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt) log_err(info->keymap->ctx, "Illegal keycode %d (must be in the range %d-%d inclusive); " "Value of \"%s\" not changed\n", - tmp.uval, 0, XKB_KEYCODE_MAX, field.str); + tmp.uval, 0, XKB_KEYCODE_MAX, field); goto err_out; } diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 448e925..9aaf32d 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -753,24 +753,27 @@ SetKeyTypeField(KeyTypesInfo *info, KeyTypeInfo *type, static bool HandleKeyTypeVar(KeyTypesInfo *info, VarDef *stmt) { - ExprResult elem, field; + const char *elem, *field; ExprDef *arrayNdx; - if (!ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &arrayNdx)) + if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, + &arrayNdx)) return false; /* internal error, already reported */ - if (elem.str && istreq(elem.str, "type")) - return SetKeyTypeField(info, &info->dflt, field.str, arrayNdx, + + if (elem && istreq(elem, "type")) + return SetKeyTypeField(info, &info->dflt, field, arrayNdx, stmt->value); - if (elem.str != NULL) { + + if (elem) { log_err(info->keymap->ctx, "Default for unknown element %s; " - "Value for field %s ignored\n", - field.str, elem.str); + "Value for field %s ignored\n", field, elem); } - else if (field.str != NULL) { + else if (field) { log_err(info->keymap->ctx, - "Default defined for unknown field %s; Ignored\n", field.str); + "Default defined for unknown field %s; Ignored\n", field); } + return false; } @@ -778,7 +781,7 @@ static int HandleKeyTypeBody(KeyTypesInfo *info, VarDef *def, KeyTypeInfo *type) { int ok = 1; - ExprResult tmp, field; + const char *elem, *field; ExprDef *arrayNdx; for (; def; def = (VarDef *) def->common.next) { @@ -786,12 +789,14 @@ HandleKeyTypeBody(KeyTypesInfo *info, VarDef *def, KeyTypeInfo *type) ok = HandleKeyTypeVar(info, def); continue; } - ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field, &arrayNdx); + ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field, + &arrayNdx); if (ok) { - ok = SetKeyTypeField(info, type, field.str, arrayNdx, + ok = SetKeyTypeField(info, type, field, arrayNdx, def->value); } } + return ok; } diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index c06afc8..4495270 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1193,47 +1193,47 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value) static int HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt) { - ExprResult elem, field; + const char *elem, *field; ExprDef *arrayNdx; bool ret; - if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, + if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &arrayNdx) == 0) return 0; /* internal error, already reported */ - if (elem.str && istreq(elem.str, "key")) { - ret = SetSymbolsField(info, &info->dflt, field.str, arrayNdx, + if (elem && istreq(elem, "key")) { + ret = SetSymbolsField(info, &info->dflt, field, arrayNdx, stmt->value); } - else if (!elem.str && (istreq(field.str, "name") || - istreq(field.str, "groupname"))) { + else if (!elem && (istreq(field, "name") || + istreq(field, "groupname"))) { ret = SetGroupName(info, arrayNdx, stmt->value); } - else if (!elem.str && (istreq(field.str, "groupswrap") || - istreq(field.str, "wrapgroups"))) { + else if (!elem && (istreq(field, "groupswrap") || + istreq(field, "wrapgroups"))) { log_err(info->keymap->ctx, "Global \"groupswrap\" not supported; Ignored\n"); ret = true; } - else if (!elem.str && (istreq(field.str, "groupsclamp") || - istreq(field.str, "clampgroups"))) { + else if (!elem && (istreq(field, "groupsclamp") || + istreq(field, "clampgroups"))) { log_err(info->keymap->ctx, "Global \"groupsclamp\" not supported; Ignored\n"); ret = true; } - else if (!elem.str && (istreq(field.str, "groupsredirect") || - istreq(field.str, "redirectgroups"))) { + else if (!elem && (istreq(field, "groupsredirect") || + istreq(field, "redirectgroups"))) { log_err(info->keymap->ctx, "Global \"groupsredirect\" not supported; Ignored\n"); ret = true; } - else if (!elem.str && istreq(field.str, "allownone")) { + else if (!elem && istreq(field, "allownone")) { log_err(info->keymap->ctx, "Radio groups not supported; " "Ignoring \"allownone\" specification\n"); ret = true; } else { - ret = SetActionField(info->keymap, elem.str, field.str, arrayNdx, + ret = SetActionField(info->keymap, elem, field, arrayNdx, stmt->value, &info->action); } @@ -1244,7 +1244,7 @@ static bool HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi) { bool ok = true; - ExprResult tmp, field; + const char *elem, *field; ExprDef *arrayNdx; for (; def; def = (VarDef *) def->common.next) { @@ -1255,19 +1255,18 @@ HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi) if (!def->name) { if (!def->value || def->value->op == EXPR_KEYSYM_LIST) - field.str = "symbols"; + field = "symbols"; else - field.str = "actions"; + field = "actions"; arrayNdx = NULL; } else { - ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field, + ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field, &arrayNdx); } if (ok) - ok = SetSymbolsField(info, keyi, field.str, arrayNdx, - def->value); + ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value); } return ok; -- 2.7.4