From 27f9492969a4f9e2b31ecc1053233dfe0726dfcf Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 23 Jul 2012 15:46:50 +0300 Subject: [PATCH] expr: drop ExprResult from ResolveString Signed-off-by: Ran Benita --- src/xkbcomp/action.c | 44 +++++++++++++++++++++++++------------------- src/xkbcomp/expr.c | 7 ++++--- src/xkbcomp/expr.h | 5 ++--- src/xkbcomp/keycodes.c | 11 +++++++---- src/xkbcomp/keytypes.c | 9 +++++++-- src/xkbcomp/symbols.c | 14 +++++++++----- 6 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 11a9eb9..5706626 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -749,6 +749,7 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action, unsigned field, ExprDef *array_ndx, ExprDef *value) { ExprResult rtrn; + const char *str; struct xkb_message_action *act; act = (struct xkb_message_action *) action; @@ -777,17 +778,19 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action, case F_Data: if (array_ndx == NULL) { - if (!ExprResolveString(keymap->ctx, value, &rtrn)) + int len; + + if (!ExprResolveString(keymap->ctx, value, &str)) return ReportMismatch(keymap, action->type, field, "string"); - else { - int len = strlen(rtrn.str); - if ((len < 1) || (len > 6)) { - log_warn(keymap->ctx, - "An action message can hold only 6 bytes; " - "Extra %d bytes ignored\n", len - 6); - } - strncpy((char *) act->message, rtrn.str, 6); + + len = strlen(str); + if (len < 1 || len > 6) { + log_warn(keymap->ctx, + "An action message can hold only 6 bytes; " + "Extra %d bytes ignored\n", len - 6); } + + strncpy((char *) act->message, str, 6); return true; } else { @@ -971,18 +974,21 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action, case F_Data: if (array_ndx == NULL) { - if (!ExprResolveString(keymap->ctx, value, &rtrn)) + const char *str; + int len; + + if (!ExprResolveString(keymap->ctx, value, &str)) return ReportMismatch(keymap, action->type, field, "string"); - else { - int len = strlen(rtrn.str); - if ((len < 1) || (len > 7)) { - log_warn(keymap->ctx, - "A private action has 7 data bytes; " - "Extra %d bytes ignored\n", len - 6); - return false; - } - strncpy((char *) action->data, rtrn.str, sizeof action->data); + + len = strlen(str); + if (len < 1 || len > 7) { + log_warn(keymap->ctx, + "A private action has 7 data bytes; " + "Extra %d bytes ignored\n", len - 6); + return false; } + + strncpy((char *) action->data, str, sizeof(action->data)); return true; } else { diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 308124c..150dce1 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -572,9 +572,9 @@ ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, button_names); } -int +bool ExprResolveString(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn) + const char **val_rtrn) { switch (expr->op) { case EXPR_VALUE: @@ -583,7 +583,8 @@ ExprResolveString(struct xkb_context *ctx, ExprDef *expr, exprValueTypeText(expr->value_type)); return false; } - val_rtrn->str = xkb_atom_text(ctx, expr->value.str); + + *val_rtrn = xkb_atom_text(ctx, expr->value.str); return true; case EXPR_IDENT: diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 9befb0b..9465beb 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -30,7 +30,6 @@ #include "xkbcomp-priv.h" typedef union _ExprResult { - const char *str; int ival; unsigned uval; } ExprResult; @@ -89,9 +88,9 @@ extern int ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, ExprResult *val_rtrn); -extern int +bool ExprResolveString(struct xkb_context *ctx, ExprDef *expr, - ExprResult *val_rtrn); + const char **val_rtrn); bool ExprResolveKeyName(struct xkb_context *ctx, ExprDef *expr, diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 708b636..558d7cf 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -704,25 +704,28 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def, enum merge_mode merge) { IndicatorNameInfo ii; - ExprResult tmp; + const char *str; - if ((def->ndx < 1) || (def->ndx > XkbNumIndicators)) { + if (def->ndx < 1 || def->ndx > XkbNumIndicators) { info->errorCount++; log_err(info->keymap->ctx, "Name specified for illegal indicator index %d\n; Ignored\n", def->ndx); return false; } + InitIndicatorNameInfo(&ii, info); ii.ndx = def->ndx; - if (!ExprResolveString(info->keymap->ctx, def->name, &tmp)) { + + if (!ExprResolveString(info->keymap->ctx, def->name, &str)) { char buf[20]; snprintf(buf, sizeof(buf), "%d", def->ndx); info->errorCount++; return ReportBadType(info->keymap, "indicator", "name", buf, "string"); } - ii.name = xkb_atom_intern(info->keymap->ctx, tmp.str); + + ii.name = xkb_atom_intern(info->keymap->ctx, str); ii.virtual = def->virtual; return AddIndicatorName(info, merge, &ii); diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 9aaf32d..d5c75c3 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -671,20 +671,25 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx, unsigned level; xkb_atom_t level_name; struct xkb_context *ctx = info->keymap->ctx; + const char *str; if (arrayNdx == NULL) return ReportTypeShouldBeArray(info, type, "level name"); + if (!ExprResolveLevel(ctx, arrayNdx, &rtrn)) return ReportTypeBadType(info, type, "level name", "integer"); level = rtrn.ival - 1; - if (!ExprResolveString(ctx, value, &rtrn)) { + + if (!ExprResolveString(ctx, value, &str)) { log_err(info->keymap->ctx, "Non-string name for level %d in key type %s; " "Ignoring illegal level name definition\n", level + 1, xkb_atom_text(ctx, type->name)); return false; } - level_name = xkb_atom_intern(ctx, rtrn.str); + + level_name = xkb_atom_intern(ctx, str); + return AddLevelName(info, type, level, level_name, true); } diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 4495270..f196f0b 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1028,12 +1028,15 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, if (istreq(field, "type")) { ExprResult ndx; - if (!ExprResolveString(ctx, value, &tmp)) + const char *str; + + if (!ExprResolveString(ctx, value, &str)) log_lvl(info->keymap->ctx, 1, "The type field of a key symbol map must be a string; " "Ignoring illegal type definition\n"); + if (arrayNdx == NULL) { - keyi->dfltType = xkb_atom_intern(ctx, tmp.str); + keyi->dfltType = xkb_atom_intern(ctx, str); keyi->defined |= _Key_Type_Dflt; } else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) { @@ -1044,7 +1047,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, return false; } else { - keyi->types[ndx.uval - 1] = xkb_atom_intern(ctx, tmp.str); + keyi->types[ndx.uval - 1] = xkb_atom_intern(ctx, str); keyi->typesDefined |= (1 << (ndx.uval - 1)); } } @@ -1161,7 +1164,8 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, static int SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value) { - ExprResult tmp, name; + ExprResult tmp; + const char *name; if (!arrayNdx) { log_lvl(info->keymap->ctx, 1, @@ -1185,7 +1189,7 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value) } info->groupNames[tmp.uval - 1 + info->explicit_group] = - xkb_atom_intern(info->keymap->ctx, name.str); + xkb_atom_intern(info->keymap->ctx, name); return true; } -- 2.7.4