static int command_fds[2] = {-1, -1};
static int stat_pipe = -1;
static struct gui_args_info conf;
+static int loglevel;
enum {GETCH_MODE, COMMAND_MODE, EXTERNAL_MODE};
return buf;
}
-static char *configfile_exists(void)
-{
- static char *config_file;
- char *tmp;
-
- if (!conf.config_file_given) {
- if (!config_file) {
- char *home = para_homedir();
- config_file = make_message("%s/.paraslash/gui.conf",
- home);
- free(home);
- }
- tmp = config_file;
- } else
- tmp = conf.config_file_arg;
- return file_exists(tmp)? tmp: NULL;
-}
-
/* Print given number of spaces to curses window. */
static void add_spaces(WINDOW* win, unsigned int num)
{
return 1;
}
-static int loglevel;
-
static __printf_2_3 void curses_log(int ll, const char *fmt,...)
{
va_list ap;
free(tmp);
}
+static void parse_config_file_or_die(bool override)
+{
+ bool err;
+ char *config_file;
+ struct gui_cmdline_parser_params params = {
+ .override = override,
+ .initialize = 0,
+ .check_required = !override,
+ .check_ambiguity = 0,
+ .print_errors = 1,
+ };
+
+ if (conf.config_file_given)
+ config_file = para_strdup(conf.config_file_arg);
+ else {
+ char *home = para_homedir();
+ config_file = make_message("%s/.paraslash/gui.conf", home);
+ free(home);
+ }
+ if (!file_exists(config_file)) {
+ if (!conf.config_file_given)
+ err = false;
+ else {
+ PARA_EMERG_LOG("config file %s does not exist\n",
+ config_file);
+ err = true;
+ }
+ goto out;
+ }
+ gui_cmdline_parser_config_file(config_file, &conf, ¶ms);
+ loglevel = get_loglevel_by_name(conf.loglevel_arg);
+ check_key_map_args_or_die();
+ theme_init(conf.theme_arg, &theme);
+ err = false;
+out:
+ free(config_file);
+ if (err)
+ exit(EXIT_FAILURE);
+}
+
/*
* React to various signal-related events
*/
*/
static void com_reread_conf(void)
{
- char *cf = configfile_exists();
- struct gui_cmdline_parser_params params = {
- .override = 1,
- .initialize = 1,
- .check_required = 0,
- .check_ambiguity = 0,
- .print_errors = 0,
- };
-
- if (!cf) {
- PARA_WARNING_LOG("there is no configuration to read\n");
- return;
- }
- PARA_INFO_LOG("rereading command line options and config file\n");
/*
- * Despite .print_errors is set to 0, gengetopt will print to stderr
- * anyway, and exit on errors. So we have to shutdown curses first.
+ * gengetopt might print to stderr and exit on errors. So we have to
+ * shutdown curses first.
*/
shutdown_curses();
- gui_cmdline_parser_config_file(cf, &conf, ¶ms);
+ parse_config_file_or_die(true /* override */);
init_curses();
- PARA_NOTICE_LOG("config file reloaded\n");
- check_key_map_args_or_die();
+ print_in_bar(COLOR_MSG, "config file reloaded\n");
}
static void com_help(void)
int main(int argc, char *argv[])
{
int ret;
- char *cf;
gui_cmdline_parser(argc, argv, &conf); /* exits on errors */
loglevel = get_loglevel_by_name(conf.loglevel_arg);
version_handle_flag("gui", conf.version_given);
if (conf.help_given || conf.detailed_help_given)
print_help_and_die();
- cf = configfile_exists();
- if (!cf && conf.config_file_given)
- die(EXIT_FAILURE, "can not read config file %s\n",
- conf.config_file_arg);
- if (cf) {
- struct gui_cmdline_parser_params params = {
- .override = 0,
- .initialize = 0,
- .check_required = 0,
- .check_ambiguity = 0,
- .print_errors = 1,
- };
- gui_cmdline_parser_config_file(cf, &conf, ¶ms);
- loglevel = get_loglevel_by_name(conf.loglevel_arg);
- }
- check_key_map_args_or_die();
- theme_init(conf.theme_arg, &theme);
+ parse_config_file_or_die(false /* override */);
setup_signal_handling();
bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);
setlocale(LC_CTYPE, "");