This is an automatic generated email to let you know that the following patch were queued at the http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:
Subject: ir-ctl: warn if keycode has multiple definitions Author: Sean Young <s...@mess.org> Date: Thu Aug 29 16:09:21 2019 +0100 Signed-off-by: Sean Young <s...@mess.org> utils/common/keymap.c | 6 ++++-- utils/ir-ctl/ir-ctl.c | 52 ++++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 25 deletions(-) --- http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=b393a5408383b7341883857dfda78537f2f85ef6 diff --git a/utils/common/keymap.c b/utils/common/keymap.c index 45d86c8c8105..d9980676c9d1 100644 --- a/utils/common/keymap.c +++ b/utils/common/keymap.c @@ -391,6 +391,8 @@ static error_t parse_toml_protocol(const char *fname, struct toml_table_t *proot } } + struct scancode_entry **next = &map->scancode; + for (;;) { struct scancode_entry *se; const char *scancode; @@ -420,8 +422,8 @@ static error_t parse_toml_protocol(const char *fname, struct toml_table_t *proot se->scancode = strtoul(scancode, NULL, 0); se->keycode = keycode; - se->next = map->scancode; - map->scancode = se; + *next = se; + next = &se->next; } return 0; diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c index 28d8d97acf60..e884b4f8f4e6 100644 --- a/utils/ir-ctl/ir-ctl.c +++ b/utils/ir-ctl/ir-ctl.c @@ -727,17 +727,22 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state) return 0; } -// FIXME: keymaps can have multiple definitions of the same keycode static struct send* convert_keycode(struct keymap *map, const char *keycode) { - struct send *s; + struct send *s = NULL; + int count = 0; + + for (;map; map = map->next) { + struct scancode_entry *se; + struct raw_entry *re; - while (map) { - struct raw_entry *re = map->raw; - struct scancode_entry *se = map->scancode; + for (re = map->raw; re; re = re->next) { + if (strcmp(re->keycode, keycode)) + continue; - while (re) { - if (!strcmp(re->keycode, keycode)) { + count++; + + if (!s) { s = malloc(sizeof(*s) + re->raw_length * sizeof(int)); s->len = re->raw_length; memcpy(s->buf, re->raw, s->len * sizeof(int)); @@ -745,17 +750,18 @@ static struct send* convert_keycode(struct keymap *map, const char *keycode) s->is_keycode = false; s->carrier = keymap_param(map, "carrier", 0); s->next = NULL; - - return s; } - - re = re->next; } - while (se) { - if (!strcmp(se->keycode, keycode)) { - enum rc_proto proto; + for (se = map->scancode; se; se = se->next) { + if (strcmp(se->keycode, keycode)) + continue; + + count++; + + if (!s) { const char *proto_str; + enum rc_proto proto; proto_str = map->variant ?: map->protocol; @@ -770,17 +776,19 @@ static struct send* convert_keycode(struct keymap *map, const char *keycode) s->is_scancode = true; s->is_keycode = false; s->next = NULL; - - return s; } - - se = se->next; } + } - map = map->next; + if (!s) { + fprintf(stderr, _("error: keycode `%s' not found in keymap\n"), keycode); + return NULL; } - return NULL; + if (count > 1) + fprintf(stderr, _("warning: keycode `%s' has %d definitions in keymaps, using first\n"), keycode, count); + + return s; } static const struct argp argp = { @@ -1022,10 +1030,8 @@ static int lirc_send(struct arguments *args, int fd, unsigned features, struct s } f = convert_keycode(map, keycode); - if (!f) { - fprintf(stderr, _("error: keycode `%s' not found in keymap\n"), keycode); + if (!f) return EX_DATAERR; - } } if (f->is_scancode) { _______________________________________________ linuxtv-commits mailing list linuxtv-commits@linuxtv.org https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits