From: Radek Tříška Date: Thu, 4 Aug 2011 11:24:59 +0000 (+0200) Subject: check_for_duplicate_bindings X-Git-Tag: 4.1~240^2~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9d101d847397c1145e66bd7f5f26076eaf1b63ae;p=i3%2Fi3 check_for_duplicate_bindings --- diff --git a/src/cfgparse.y b/src/cfgparse.y index 59b22c6c..226363cc 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -310,6 +310,35 @@ void kill_configerror_nagbar(bool wait_for_it) { waitpid(configerror_pid, NULL, 0); } +/* + check_for_duplicate_bindings is function looking for duplicated + key bindings loaded from configuration file. It goes trought all bindings + and tests if exists same key mapping in bindings visited before. + If exists, message is printed to "stderr" and error warning is set. +*/ +static bool check_for_duplicate_bindings(struct context *context) { + bool retval = true; + Binding *bind, *current; + TAILQ_FOREACH(current, bindings, bindings) { + bind = TAILQ_FIRST(bindings); + // test only bindings visited up to current binding + while ((bind != TAILQ_END(bindings)) && (bind != current)) { + // testing is not case sensitive + if ((strcasecmp(bind->symbol, current->symbol) == 0) && (bind->keycode == current->keycode) && (bind->mods == current->mods)) { + context->has_errors = true; + fprintf(stderr, "Duplicated keybinding in config file: mod%d with key %s", current->mods, current->symbol); + // if keycode is 0, it´s not necessary to print it. + if(current->keycode != 0) + fprintf(stderr, " and keycode %d", current->keycode); + fprintf(stderr, "\n"); + retval = false; + } + bind = TAILQ_NEXT(bind, bindings); + } + } + return retval; +} + void parse_file(const char *f) { SLIST_HEAD(variables_head, Variable) variables = SLIST_HEAD_INITIALIZER(&variables); int fd, ret, read_bytes = 0; @@ -463,6 +492,8 @@ void parse_file(const char *f) { exit(1); } + check_for_duplicate_bindings(context); + if (context->has_errors) { start_configerror_nagbar(f); }