From: Andre Noll Date: Tue, 7 Jan 2014 18:52:26 +0000 (+0000) Subject: gui: Improve check_key_map_args(). X-Git-Tag: v0.5.3~12^2~23 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=8ae94747078cfd5c50ff3397788f95598d2299bb gui: Improve check_key_map_args(). Simplify the code a bit, make it call die() on errors and print the invalid key map in the error case. --- diff --git a/gui.c b/gui.c index 8ec009cc..ead75209 100644 --- a/gui.c +++ b/gui.c @@ -824,36 +824,31 @@ err_out: return 0; } -static int check_key_map_args(void) +static void check_key_map_args_or_die(void) { - char *s; - int i, ret = -1; - char *tmp = NULL, *handler, *arg; + int i; + char *tmp = NULL; for (i = 0; i < conf.key_map_given; ++i) { - s = conf.key_map_arg[i]; - if (!(*s)) - goto out; + char *handler, *arg; + free(tmp); - tmp = para_strdup(s); + tmp = para_strdup(conf.key_map_arg[i]); if (!split_key_map(tmp, &handler, &arg)) - goto out; + break; if (strlen(handler) != 1) - goto out; - if (*handler != 'x' - && *handler != 'd' - && *handler != 'i' - && *handler != 'p') - goto out; + break; + if (*handler != 'x' && *handler != 'd' && *handler != 'i' + && *handler != 'p') + break; if (*handler != 'i') continue; if (find_cmd_byname(arg) < 0) - goto out; + break; } - ret = 0; -out: + if (i != conf.key_map_given) + die(EXIT_FAILURE, "invalid key map: %s\n", conf.key_map_arg[i]); free(tmp); - return ret; } /* @@ -1286,8 +1281,7 @@ static void com_reread_conf(void) gui_cmdline_parser_config_file(cf, &conf, ¶ms); init_curses(); PARA_NOTICE_LOG("config file reloaded\n"); - if (check_key_map_args() < 0) - die(EXIT_FAILURE, "invalid key map\n"); + check_key_map_args_or_die(); } static void com_help(void) @@ -1453,8 +1447,7 @@ int main(int argc, char *argv[]) gui_cmdline_parser_config_file(cf, &conf, ¶ms); loglevel = get_loglevel_by_name(conf.loglevel_arg); } - if (check_key_map_args() < 0) - die(EXIT_FAILURE, "invalid key map\n"); + check_key_map_args_or_die(); theme_init(conf.theme_arg, &theme); setup_signal_handling(); bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);