expr: drop ExprResult from ResolveLevel

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-24 00:51:19 +03:00
parent 000528dd59
commit 6ec135700d
3 changed files with 20 additions and 16 deletions

View File

@ -528,11 +528,12 @@ ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
return true; return true;
} }
int bool
ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr, ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
ExprResult *val_rtrn) unsigned int *level_rtrn)
{ {
int ret; bool ok;
ExprResult result;
static const LookupEntry level_names[] = { static const LookupEntry level_names[] = {
{ "level1", 1 }, { "level1", 1 },
{ "level2", 2 }, { "level2", 2 },
@ -545,17 +546,18 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
{ NULL, 0 } { NULL, 0 }
}; };
ret = ExprResolveIntegerLookup(ctx, expr, val_rtrn, SimpleLookup, ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
level_names); level_names);
if (ret == false) if (!ok)
return ret; return false;
if (val_rtrn->ival < 1 || val_rtrn->ival > XkbMaxShiftLevel) { if (result.uval < 1 || result.uval > XkbMaxShiftLevel) {
log_err(ctx, "Shift level %d is out of range (1..%d)\n", log_err(ctx, "Shift level %d is out of range (1..%d)\n",
val_rtrn->ival, XkbMaxShiftLevel); result.uval, XkbMaxShiftLevel);
return false; return false;
} }
*level_rtrn = result.uval;
return true; return true;
} }

View File

@ -76,8 +76,9 @@ extern int
ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr, ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
ExprResult *val_rtrn); ExprResult *val_rtrn);
extern int bool
ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr, ExprResult *val_rtrn); ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
unsigned int *level_rtrn);
bool bool
ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr, ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,

View File

@ -532,6 +532,7 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
ExprDef *value) ExprDef *value)
{ {
ExprResult rtrn; ExprResult rtrn;
unsigned int level;
struct xkb_kt_map_entry entry; struct xkb_kt_map_entry entry;
if (arrayNdx == NULL) if (arrayNdx == NULL)
@ -557,14 +558,15 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
entry.mods.vmods &= type->vmask; entry.mods.vmods &= type->vmask;
} }
if (!ExprResolveLevel(info->keymap->ctx, value, &rtrn)) { if (!ExprResolveLevel(info->keymap->ctx, value, &level)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Level specifications in a key type must be integer; " "Level specifications in a key type must be integer; "
"Ignoring malformed level specification\n"); "Ignoring malformed level specification\n");
return false; return false;
} }
entry.level = rtrn.ival - 1; /* level is always >= 1 */
entry.level = level - 1;
return AddMapEntry(info, type, &entry, true, true); return AddMapEntry(info, type, &entry, true, true);
} }
@ -667,7 +669,6 @@ static bool
SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx, SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
ExprDef *value) ExprDef *value)
{ {
ExprResult rtrn;
unsigned level; unsigned level;
xkb_atom_t level_name; xkb_atom_t level_name;
struct xkb_context *ctx = info->keymap->ctx; struct xkb_context *ctx = info->keymap->ctx;
@ -676,9 +677,9 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
if (arrayNdx == NULL) if (arrayNdx == NULL)
return ReportTypeShouldBeArray(info, type, "level name"); return ReportTypeShouldBeArray(info, type, "level name");
if (!ExprResolveLevel(ctx, arrayNdx, &rtrn)) if (!ExprResolveLevel(ctx, arrayNdx, &level))
return ReportTypeBadType(info, type, "level name", "integer"); return ReportTypeBadType(info, type, "level name", "integer");
level = rtrn.ival - 1; level--;
if (!ExprResolveString(ctx, value, &str)) { if (!ExprResolveString(ctx, value, &str)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,