expr: drop ExprResult from ResolveKeyCode 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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 2b60a01..7731e4a 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -282,11 +282,10 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn)
return false;
}
-int
-ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
- ExprResult *val_rtrn)
+bool
+ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc)
{
- ExprResult leftRtrn, rightRtrn;
+ xkb_keycode_t leftRtrn, rightRtrn;
ExprDef *left, *right;
switch (expr->op) {
@@ -297,7 +296,8 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
exprValueTypeText(expr->value_type));
return false;
}
- val_rtrn->uval = expr->value.uval;
+
+ *kc = expr->value.uval;
return true;
case EXPR_ADD:
@@ -306,27 +306,29 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
case EXPR_DIVIDE:
left = expr->value.binary.left;
right = expr->value.binary.right;
+
if (!ExprResolveKeyCode(ctx, left, &leftRtrn) ||
!ExprResolveKeyCode(ctx, right, &rightRtrn))
return false;
switch (expr->op) {
case EXPR_ADD:
- val_rtrn->uval = leftRtrn.uval + rightRtrn.uval;
+ *kc = leftRtrn + rightRtrn;
break;
case EXPR_SUBTRACT:
- val_rtrn->uval = leftRtrn.uval - rightRtrn.uval;
+ *kc = leftRtrn - rightRtrn;
break;
case EXPR_MULTIPLY:
- val_rtrn->uval = leftRtrn.uval * rightRtrn.uval;
+ *kc = leftRtrn * rightRtrn;
break;
case EXPR_DIVIDE:
- if (rightRtrn.uval == 0) {
+ if (rightRtrn == 0) {
log_err(ctx, "Cannot divide by zero: %d / %d\n",
- leftRtrn.uval, rightRtrn.uval);
+ leftRtrn, rightRtrn);
return false;
}
- val_rtrn->uval = leftRtrn.uval / rightRtrn.uval;
+
+ *kc = leftRtrn / rightRtrn;
break;
default:
break;
@@ -336,20 +338,21 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
case EXPR_NEGATE:
left = expr->value.child;
- if (ExprResolveKeyCode(ctx, left, &leftRtrn)) {
- val_rtrn->uval = ~leftRtrn.uval;
- return true;
- }
- return false;
+ if (!ExprResolveKeyCode(ctx, left, &leftRtrn))
+ return false;
+
+ *kc = ~leftRtrn;
+ return true;
case EXPR_UNARY_PLUS:
left = expr->value.child;
- return ExprResolveKeyCode(ctx, left, val_rtrn);
+ return ExprResolveKeyCode(ctx, left, kc);
default:
log_wsgo(ctx, "Unknown operator %d in ResolveKeyCode\n", expr->op);
break;
}
+
return false;
}
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index 280cb6e..4712ca1 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -69,9 +69,8 @@ ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr,
bool
ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn);
-extern int
-ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
- ExprResult *val_rtrn);
+bool
+ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc);
extern int
ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 558d7cf..cfd09a6 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -609,19 +609,19 @@ static int
HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
{
const char *elem, *field;
- ExprResult tmp;
+ xkb_keycode_t kc;
ExprDef *arrayNdx;
int which;
- if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
- &arrayNdx) == 0)
- return 0; /* internal error, already reported */
+ if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
+ &arrayNdx))
+ return false; /* internal error, already reported */
if (elem) {
log_err(info->keymap->ctx,
"Unknown element %s encountered; "
"Default for field %s ignored\n", elem, field);
- goto err_out;
+ return false;
}
if (istreq(field, "minimum"))
@@ -632,71 +632,72 @@ HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
log_err(info->keymap->ctx,
"Unknown field encountered; "
"Assigment to field %s ignored\n", field);
- goto err_out;
+ return false;
}
if (arrayNdx != NULL) {
log_err(info->keymap->ctx,
"The %s setting is not an array; "
"Illegal array reference ignored\n", field);
- goto err_out;
+ return false;
}
- if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &tmp) == 0) {
+ if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &kc) == 0) {
log_err(info->keymap->ctx,
"Illegal keycode encountered; "
"Assignment to field %s ignored\n", field);
- goto err_out;
+ return false;
}
- if (tmp.uval > XKB_KEYCODE_MAX) {
+ if (kc > XKB_KEYCODE_MAX) {
log_err(info->keymap->ctx,
"Illegal keycode %d (must be in the range %d-%d inclusive); "
"Value of \"%s\" not changed\n",
- tmp.uval, 0, XKB_KEYCODE_MAX, field);
- goto err_out;
+ kc, 0, XKB_KEYCODE_MAX, field);
+ return false;
}
if (which == MIN_KEYCODE_DEF) {
- if ((info->explicitMax > 0) && (info->explicitMax < tmp.uval)) {
+ if (info->explicitMax > 0 && info->explicitMax < kc) {
log_err(info->keymap->ctx,
"Minimum key code (%d) must be <= maximum key code (%d); "
"Minimum key code value not changed\n",
- tmp.uval, info->explicitMax);
- goto err_out;
+ kc, info->explicitMax);
+ return false;
}
- if ((info->computedMax > 0) && (info->computedMin < tmp.uval)) {
+
+ if (info->computedMax > 0 && info->computedMin < kc) {
log_err(info->keymap->ctx,
"Minimum key code (%d) must be <= lowest defined key (%d); "
"Minimum key code value not changed\n",
- tmp.uval, info->computedMin);
- goto err_out;
+ kc, info->computedMin);
+ return false;
}
- info->explicitMin = tmp.uval;
+
+ info->explicitMin = kc;
}
if (which == MAX_KEYCODE_DEF) {
- if ((info->explicitMin > 0) && (info->explicitMin > tmp.uval)) {
+ if (info->explicitMin > 0 && info->explicitMin > kc) {
log_err(info->keymap->ctx,
"Maximum code (%d) must be >= minimum key code (%d); "
"Maximum code value not changed\n",
- tmp.uval, info->explicitMin);
- goto err_out;
+ kc, info->explicitMin);
+ return false;
}
- if ((info->computedMax > 0) && (info->computedMax > tmp.uval)) {
+
+ if (info->computedMax > 0 && info->computedMax > kc) {
log_err(info->keymap->ctx,
"Maximum code (%d) must be >= highest defined key (%d); "
"Maximum code value not changed\n",
- tmp.uval, info->computedMax);
- goto err_out;
+ kc, info->computedMax);
+ return false;
}
- info->explicitMax = tmp.uval;
- }
- return 1;
+ info->explicitMax = kc;
+ }
-err_out:
- return 0;
+ return true;
}
static int