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;
}
int
bool
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[] = {
{ "level1", 1 },
{ "level2", 2 },
@ -545,17 +546,18 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
{ NULL, 0 }
};
ret = ExprResolveIntegerLookup(ctx, expr, val_rtrn, SimpleLookup,
level_names);
if (ret == false)
return ret;
ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
level_names);
if (!ok)
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",
val_rtrn->ival, XkbMaxShiftLevel);
result.uval, XkbMaxShiftLevel);
return false;
}
*level_rtrn = result.uval;
return true;
}

View File

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

View File

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