expr: drop ExprResult from ResolveGroup Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index ee09865..d73bc13 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -338,7 +338,6 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
xkb_group_index_t *grp_rtrn)
{
ExprDef *spec;
- ExprResult rtrn;
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
*flags_inout &= ~XkbSA_GroupAbsolute;
@@ -349,15 +348,15 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
spec = value;
}
- if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
+ if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
return ReportMismatch(keymap, action, F_Group,
"integer (range 1..8)");
+
if (value->op == EXPR_NEGATE)
- *grp_rtrn = -rtrn.ival;
- else if (value->op == EXPR_UNARY_PLUS)
- *grp_rtrn = rtrn.ival;
- else
- *grp_rtrn = rtrn.ival - 1;
+ *grp_rtrn = -*grp_rtrn;
+ else if (value->op != EXPR_UNARY_PLUS)
+ (*grp_rtrn)--;
+
return true;
}
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 025010e..2b60a01 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -492,11 +492,12 @@ ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
return ExprResolveIntegerLookup(ctx, expr, val_rtrn, NULL, NULL);
}
-int
+bool
ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
- ExprResult *val_rtrn)
+ xkb_group_index_t *group_rtrn)
{
- int ret;
+ bool ok;
+ ExprResult result;
static const LookupEntry group_names[] = {
{ "group1", 1 },
{ "group2", 2 },
@@ -509,17 +510,18 @@ ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
{ NULL, 0 }
};
- ret = ExprResolveIntegerLookup(ctx, expr, val_rtrn, SimpleLookup,
- group_names);
- if (ret == false)
- return ret;
+ ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
+ group_names);
+ if (!ok)
+ return false;
- if (val_rtrn->uval == 0 || val_rtrn->uval > XkbNumKbdGroups) {
+ if (result.uval == 0 || result.uval > XkbNumKbdGroups) {
log_err(ctx, "Group index %u is out of range (1..%d)\n",
- val_rtrn->uval, XkbNumKbdGroups);
+ result.uval, XkbNumKbdGroups);
return false;
}
+ *group_rtrn = result.uval;
return true;
}
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index c5222a1..280cb6e 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -80,8 +80,9 @@ ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
extern int
ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr, ExprResult *val_rtrn);
-extern int
-ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr, ExprResult *val_rtrn);
+bool
+ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
+ xkb_group_index_t *group_rtrn);
extern int
ExprResolveButton(struct xkb_context *ctx, ExprDef *expr,
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 97a6543..ccc7568 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -803,7 +803,6 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
unsigned what, xkb_group_index_t *ndx_rtrn)
{
const char *name;
- ExprResult tmp;
if (what == SYMBOLS)
name = "symbols";
@@ -824,20 +823,23 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
return true;
}
}
+
log_err(info->keymap->ctx,
"Too many groups of %s for key %s (max %u); "
"Ignoring %s defined for extra groups\n",
name, longText(keyi->name), XkbNumKbdGroups + 1, name);
return false;
}
- if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
+
+ if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, ndx_rtrn)) {
log_err(info->keymap->ctx,
"Illegal group index for %s of key %s\n"
"Definition with non-integer array index ignored\n",
name, longText(keyi->name));
return false;
}
- *ndx_rtrn = tmp.uval - 1;
+
+ (*ndx_rtrn)--;
return true;
}
@@ -1027,7 +1029,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
struct xkb_context *ctx = info->keymap->ctx;
if (istreq(field, "type")) {
- ExprResult ndx;
+ xkb_group_index_t ndx;
const char *str;
if (!ExprResolveString(ctx, value, &str))
@@ -1047,8 +1049,9 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
return false;
}
else {
- keyi->types[ndx.uval - 1] = xkb_atom_intern(ctx, str);
- keyi->typesDefined |= (1 << (ndx.uval - 1));
+ ndx--;
+ keyi->types[ndx] = xkb_atom_intern(ctx, str);
+ keyi->typesDefined |= (1 << ndx);
}
}
else if (istreq(field, "symbols"))
@@ -1148,15 +1151,18 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
}
else if (istreq(field, "groupsredirect") ||
istreq(field, "redirectgroups")) {
- if (!ExprResolveGroup(ctx, value, &tmp)) {
+ xkb_group_index_t grp;
+
+ if (!ExprResolveGroup(ctx, value, &grp)) {
log_err(info->keymap->ctx,
"Illegal group index for redirect of key %s; "
"Definition with non-integer group ignored\n",
longText(keyi->name));
return false;
}
+
keyi->out_of_range_group_action = XkbRedirectIntoRange;
- keyi->out_of_range_group_number = tmp.uval - 1;
+ keyi->out_of_range_group_number = grp - 1;
keyi->defined |= _Key_GroupInfo;
}
else {
@@ -1172,7 +1178,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
static int
SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
{
- ExprResult tmp;
+ xkb_group_index_t grp;
const char *name;
if (!arrayNdx) {
@@ -1182,7 +1188,7 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
return false;
}
- if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
+ if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
log_err(info->keymap->ctx,
"Illegal index in group name definition; "
"Definition with non-integer array index ignored\n");
@@ -1192,11 +1198,11 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
if (!ExprResolveString(info->keymap->ctx, value, &name)) {
log_err(info->keymap->ctx,
"Group name must be a string; "
- "Illegal name for group %d ignored\n", tmp.uval);
+ "Illegal name for group %d ignored\n", grp);
return false;
}
- info->groupNames[tmp.uval - 1 + info->explicit_group] =
+ info->groupNames[grp - 1 + info->explicit_group] =
xkb_atom_intern(info->keymap->ctx, name);
return true;