expr: drop ExprResult from ResolveString

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-23 15:46:50 +03:00
parent 025ca57905
commit 27f9492969
6 changed files with 54 additions and 36 deletions

View File

@ -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 {

View File

@ -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:

View File

@ -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,

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
}