diff options
Diffstat (limited to 'rcm-server-keymap.c')
-rw-r--r-- | rcm-server-keymap.c | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c index d0f772e..39b4440 100644 --- a/rcm-server-keymap.c +++ b/rcm-server-keymap.c @@ -14,7 +14,7 @@ #include <limits.h> #include "utils.h" -#include "rcm-server.h" +#include "rcm-server-main.h" #include "rcm-server-keymap.h" enum ini_section { @@ -63,6 +63,33 @@ static int strtol_strict(const char *str, int *result) return 0; } +static int strtoull_strict(const char *str, uint64_t *result) +{ + char *end; + unsigned long long val; + + errno = 0; + val = strtoull(str, &end, 16); + + if (errno == ERANGE && (val == ULLONG_MAX || val == 0)) + return -EINVAL; + + if (errno != 0 && val == 0) + return -EINVAL; + + if (end == str) + return -EINVAL; + + if (*end != '\0') + return -EINVAL; + + if (val > UINT64_MAX) + return -EINVAL; + + *result = val; + return 0; +} + static int keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap, uint16_t *rows_return, uint16_t *cols_return, @@ -142,9 +169,37 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap, break; case INI_SECTION_KEYMAP: if (!strcasecmp(p, "Map")) { + char *protocol; + char *scanstr; + char *keycode; + char *end; + uint64_t scancode; + + printf("Map %s\n", tmp); + protocol = strtok(tmp, " :"); + scanstr = strtok(NULL, " :"); + keycode = strtok(NULL, " :"); + end = strtok(NULL, " :"); + + if (!protocol || !scancode || !keycode || end) { + fprintf(stderr, "Invalid map directive\n"); + return -ENOMEM; + } + + r = strtoull_strict(scanstr, &scancode); + if (r < 0) { + fprintf(stderr, "Invalid scancode value\n"); + return r; + } + + printf("Map means protocol %s scancode 0x%08" PRIx64 " keycode %s\n", + protocol, scancode, keycode); + if (keymap) { - keymap->keycodes[keycode_count].name = "apan"; - keymap->keycodes[keycode_count].value = "papan"; + /* FIXME: leaks */ + keymap->keycodes[keycode_count].protocol = strdup(protocol); + keymap->keycodes[keycode_count].scancode = scancode; + keymap->keycodes[keycode_count].keycode = strdup(keycode); } keycode_count++; } else { |