Simplify parsing of numeric keysyms in parser.y
In `parser.y`, a numeric keysym is parsed by formatting it in its hexadecimal form then parsed as a keysym name. This is convoluted. Fixed by checking directly the upper bound.master
parent
397e7e013d
commit
0da68bc648
|
@ -37,6 +37,7 @@
|
||||||
#include "xkbcomp/ast-build.h"
|
#include "xkbcomp/ast-build.h"
|
||||||
#include "xkbcomp/parser-priv.h"
|
#include "xkbcomp/parser-priv.h"
|
||||||
#include "scanner-utils.h"
|
#include "scanner-utils.h"
|
||||||
|
#include "keysym.h"
|
||||||
|
|
||||||
struct parser_param {
|
struct parser_param {
|
||||||
struct xkb_context *ctx;
|
struct xkb_context *ctx;
|
||||||
|
@ -735,18 +736,19 @@ KeySym : IDENT
|
||||||
| SECTION { $$ = XKB_KEY_section; }
|
| SECTION { $$ = XKB_KEY_section; }
|
||||||
| Integer
|
| Integer
|
||||||
{
|
{
|
||||||
if ($1 < 0) {
|
if ($1 < XKB_KEYSYM_MIN) {
|
||||||
parser_warn(param, "unrecognized keysym \"%"PRId64"\"", $1);
|
parser_warn(param, "unrecognized keysym \"%"PRId64"\"", $1);
|
||||||
$$ = XKB_KEY_NoSymbol;
|
$$ = XKB_KEY_NoSymbol;
|
||||||
}
|
}
|
||||||
|
/* Special case for digits 0..9 */
|
||||||
else if ($1 < 10) { /* XKB_KEY_0 .. XKB_KEY_9 */
|
else if ($1 < 10) { /* XKB_KEY_0 .. XKB_KEY_9 */
|
||||||
$$ = XKB_KEY_0 + (xkb_keysym_t) $1;
|
$$ = XKB_KEY_0 + (xkb_keysym_t) $1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char buf[32];
|
if ($1 <= XKB_KEYSYM_MAX) {
|
||||||
snprintf(buf, sizeof(buf), "0x%"PRIx64, $1);
|
$$ = (xkb_keysym_t) $1;
|
||||||
if (!resolve_keysym(buf, &$$)) {
|
} else {
|
||||||
parser_warn(param, "unrecognized keysym \"%s\"", buf);
|
parser_warn(param, "unrecognized keysym \"0x%"PRIx64"\"", $1);
|
||||||
$$ = XKB_KEY_NoSymbol;
|
$$ = XKB_KEY_NoSymbol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue