Commit 2e4933cda7c141c9efc8c62e7d72f591f2998836

Ran Benita 2012-07-24T10:39:15

expr: drop ExprResult from ResolveInteger 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 9c9c546..35fd6e5 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -427,7 +427,6 @@ static bool
 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
               unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
     struct xkb_pointer_action *act;
     bool absolute;
 
@@ -435,23 +434,28 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
     if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
         return ReportActionNotArray(keymap, action->type, field);
 
-    if ((field == F_X) || (field == F_Y)) {
+    if (field == F_X || field == F_Y) {
+        int val;
+
         if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
             absolute = false;
         else
             absolute = true;
-        if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+
+        if (!ExprResolveInteger(keymap->ctx, value, &val))
             return ReportMismatch(keymap, action->type, field, "integer");
+
         if (field == F_X) {
             if (absolute)
                 act->flags |= XkbSA_MoveAbsoluteX;
-            act->x = rtrn.ival;
+            act->x = val;
         }
         else {
             if (absolute)
                 act->flags |= XkbSA_MoveAbsoluteY;
-            act->y = rtrn.ival;
+            act->y = val;
         }
+
         return true;
     }
     else if (field == F_Accel) {
@@ -673,8 +677,11 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
     act = (struct xkb_switch_screen_action *) action;
     if (field == F_Screen) {
         ExprDef *scrn;
-        if (array_ndx != NULL)
+        int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
+
         if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
             act->flags &= ~XkbSA_SwitchAbsolute;
             scrn = value->value.child;
@@ -684,19 +691,18 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
             scrn = value;
         }
 
-        if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
+        if (!ExprResolveInteger(keymap->ctx, scrn, &val))
             return ReportMismatch(keymap, action->type, field,
                                   "integer (0..255)");
-        if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+        if (val < 0 || val > 255) {
             log_err(keymap->ctx,
                     "Screen index must be in the range 1..255; "
                     "Illegal screen value %d ignored\n", rtrn.ival);
             return false;
         }
-        if (value->op == EXPR_NEGATE)
-            act->screen = -rtrn.ival;
-        else
-            act->screen = rtrn.ival;
+
+        act->screen = (value->op == EXPR_NEGATE ? -val : val);
         return true;
     }
     else if (field == F_Same) {
@@ -826,32 +832,38 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
             return true;
         }
         else {
-            unsigned ndx;
-            if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
+            int ndx, datum;
+
+            if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
                 log_err(keymap->ctx,
                         "Array subscript must be integer; "
                         "Illegal subscript ignored\n");
                 return false;
             }
-            ndx = rtrn.uval;
-            if (ndx > 5) {
+
+            if (ndx < 0 || ndx > 5) {
                 log_err(keymap->ctx,
                         "An action message is at most 6 bytes long; "
                         "Attempt to use data[%d] ignored\n", ndx);
                 return false;
             }
-            if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+
+            if (!ExprResolveInteger(keymap->ctx, value, &datum))
                 return ReportMismatch(keymap, action->type, field, "integer");
-            if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+            if (datum < 0 || datum > 255) {
                 log_err(keymap->ctx,
                         "Message data must be in the range 0..255; "
-                        "Illegal datum %d ignored\n", rtrn.ival);
+                        "Illegal datum %d ignored\n", datum);
                 return false;
             }
-            act->message[ndx] = rtrn.uval;
+
+            act->message[ndx] = (uint8_t) datum;
         }
+
         return true;
     }
+
     return ReportIllegal(keymap, action->type, field);
 }
 
@@ -915,18 +927,23 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
 
     act = (struct xkb_device_button_action *) action;
     if (field == F_Button) {
-        if (array_ndx != NULL)
+        int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
-        if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+
+        if (!ExprResolveInteger(keymap->ctx, value, &val))
             return ReportMismatch(keymap, action->type, field,
                                   "integer (range 1..255)");
-        if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+        if (val < 0 || val > 255) {
             log_err(keymap->ctx,
                     "Button must specify default or be in the range 1..255; "
-                    "Illegal button value %d ignored\n", rtrn.ival);
+                    "Illegal button value %d ignored\n", val);
             return false;
         }
-        act->button = rtrn.ival;
+
+        act->button = val;
         return true;
     }
     else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
@@ -960,20 +977,26 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
         return true;
     }
     else if (field == F_Device) {
-        if (array_ndx != NULL)
+        int val;
+
+        if (array_ndx)
             return ReportActionNotArray(keymap, action->type, field);
-        if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+
+        if (!ExprResolveInteger(keymap->ctx, value, &val))
             return ReportMismatch(keymap, action->type, field,
                                   "integer (range 1..255)");
-        if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+        if (val < 0 || val > 255) {
             log_err(keymap->ctx,
                     "Device must specify default or be in the range 1..255; "
-                    "Illegal device value %d ignored\n", rtrn.ival);
+                    "Illegal device value %d ignored\n", val);
             return false;
         }
-        act->device = rtrn.ival;
+
+        act->device = val;
         return true;
     }
+
     return ReportIllegal(keymap, action->type, field);
 }
 
@@ -995,22 +1018,23 @@ static bool
 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
               unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
+    if (field == F_Type) {
+        int type;
 
-    switch (field) {
-    case F_Type:
-        if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+        if (!ExprResolveInteger(keymap->ctx, value, &type))
             return ReportMismatch(keymap, PrivateAction, field, "integer");
-        if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+        if (type < 0 || type > 255) {
             log_err(keymap->ctx,
                     "Private action type must be in the range 0..255; "
-                    "Illegal type %d ignored\n", rtrn.ival);
+                    "Illegal type %d ignored\n", type);
             return false;
         }
-        action->type = rtrn.uval;
-        return true;
 
-    case F_Data:
+        action->type = (uint8_t) type;
+        return true;
+    }
+    else if (field == F_Data) {
         if (array_ndx == NULL) {
             const char *str;
             int len;
@@ -1030,32 +1054,38 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
             return true;
         }
         else {
-            unsigned ndx;
-            if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
+            int ndx, datum;
+
+            if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
                 log_err(keymap->ctx,
                         "Array subscript must be integer; "
                         "Illegal subscript ignored\n");
                 return false;
             }
-            ndx = rtrn.uval;
-            if (ndx >= sizeof action->data) {
+
+            if (ndx < 0 || ndx >= sizeof(action->data)) {
                 log_err(keymap->ctx,
-                        "The data for a private action is 18 bytes long; "
-                        "Attempt to use data[%d] ignored\n", ndx);
+                        "The data for a private action is %zu bytes long; "
+                        "Attempt to use data[%d] ignored\n",
+                        sizeof(action->data), ndx);
                 return false;
             }
-            if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+
+            if (!ExprResolveInteger(keymap->ctx, value, &datum))
                 return ReportMismatch(keymap, action->type, field, "integer");
-            if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
+
+            if (datum < 0 || datum > 255) {
                 log_err(keymap->ctx,
                         "All data for a private action must be 0..255; "
-                        "Illegal datum %d ignored\n", rtrn.ival);
+                        "Illegal datum %d ignored\n", datum);
                 return false;
             }
-            action->data[ndx] = rtrn.uval;
+
+            action->data[ndx] = (uint8_t) datum;
             return true;
         }
     }
+
     return ReportIllegal(keymap, PrivateAction, field);
 }
 
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index ea42f21..c7b07f9 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -851,14 +851,16 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
         led->defined |= _LED_DrivesKbd;
     }
     else if (istreq(field, "index")) {
-        if (arrayNdx != NULL)
+        int ndx;
+
+        if (arrayNdx)
             return ReportIndicatorNotArray(info, led, field);
 
-        if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
+        if (!ExprResolveInteger(keymap->ctx, value, &ndx))
             return ReportIndicatorBadType(info, led, field,
                                           "indicator index");
 
-        if (rtrn.uval < 1 || rtrn.uval > 32) {
+        if (ndx < 1 || ndx > 32) {
             log_err(info->keymap->ctx,
                     "Illegal indicator index %d (range 1..%d); "
                     "Index definition for %s indicator ignored\n",
@@ -867,7 +869,7 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
             return false;
         }
 
-        led->indicator = rtrn.uval;
+        led->indicator = (unsigned char) ndx;
         led->defined |= _LED_Index;
     }
     else {
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 0d67c2d..c73d5c7 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -488,11 +488,15 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
     return false;
 }
 
-int
-ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
-                   ExprResult *val_rtrn)
+bool
+ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr, int *val_rtrn)
 {
-    return ExprResolveIntegerLookup(ctx, expr, val_rtrn, NULL, NULL);
+    ExprResult result;
+    bool ok;
+    ok = ExprResolveIntegerLookup(ctx, expr, &result, NULL, NULL);
+    if (ok)
+        *val_rtrn = result.ival;
+    return ok;
 }
 
 bool
@@ -835,8 +839,7 @@ bool
 ExprResolveKeySym(struct xkb_context *ctx, ExprDef *expr,
                   xkb_keysym_t *sym_rtrn)
 {
-    bool ok = false;
-    ExprResult result;
+    int val;
 
     if (expr->op == EXPR_IDENT) {
         const char *str;
@@ -846,9 +849,12 @@ ExprResolveKeySym(struct xkb_context *ctx, ExprDef *expr,
             return true;
     }
 
-    ok = ExprResolveInteger(ctx, expr, &result);
-    if (ok && result.uval < 10)
-        *sym_rtrn = result.uval + '0';
+    if (!ExprResolveInteger(ctx, expr, &val))
+        return false;
 
-    return ok;
+    if (val < 0 || val >= 10)
+        return false;
+
+    *sym_rtrn = ((xkb_keysym_t) val) + '0';
+    return true;
 }
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index d4a0560..abdd514 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -72,9 +72,8 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr, bool *set_rtrn);
 bool
 ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc);
 
-extern int
-ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr,
-                   ExprResult *val_rtrn);
+bool
+ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr, int *val_rtrn);
 
 bool
 ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 9a18424..d6cac95 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -222,6 +222,8 @@ bool
 ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
                        ExprResult *val_rtrn, VModInfo *info)
 {
+    int val;
+
     if (def->op == EXPR_IDENT) {
         xkb_mod_index_t i;
         xkb_mod_mask_t bit;
@@ -235,12 +237,17 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
             }
         }
     }
-    if (ExprResolveInteger(keymap->ctx, def, val_rtrn)) {
-        if (val_rtrn->uval < XkbNumVirtualMods)
-            return true;
+
+    if (!ExprResolveInteger(keymap->ctx, def, &val))
+        return false;
+
+    if (val < 0 || val >= XkbNumVirtualMods) {
         log_err(keymap->ctx,
                 "Illegal virtual modifier %d (must be 0..%d inclusive)\n",
-                val_rtrn->uval, XkbNumVirtualMods - 1);
+                val, XkbNumVirtualMods - 1);
+        return false;
     }
-    return false;
+
+    val_rtrn->uval = (unsigned int) val;
+    return true;
 }