From 3b4a21e79cbfe5d05e87322eeb2dbab1f063b236 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 15 Jul 2011 18:21:37 +0200 Subject: Parse single-line configuration variables Include a fallback branch that accepts multi-line comments as well (backward compatibility). Signed-off-by: Lukas Fleischer --- src/custom.c | 58 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/custom.c b/src/custom.c index 3ae181f..3b6c6ba 100644 --- a/src/custom.c +++ b/src/custom.c @@ -239,6 +239,7 @@ custom_load_conf (struct conf *conf, int background) char *mesg_line1 = _("Failed to open config file"); char *mesg_line2 = _("Press [ENTER] to continue"); char buf[BUFSIZ], e_conf[BUFSIZ]; + char *val; enum conf_var var; data_file = fopen (path_conf, "r"); @@ -304,80 +305,87 @@ custom_load_conf (struct conf *conf, int background) /* NOTREACHED */ } - if (fgets (buf, sizeof buf, data_file) == NULL) - break; - io_extract_data (e_conf, buf, sizeof buf); + val = strchr (e_conf, '=') + 1; + + /* Backward compatibility mode. */ + if (*val == '\0' || *val == '\n') + { + if (fgets (buf, sizeof buf, data_file) == NULL) + break; + io_extract_data (e_conf, buf, sizeof buf); + val = e_conf; + } switch (var) { case CUSTOM_CONF_AUTOSAVE: - conf->auto_save = fill_config_var (e_conf); + conf->auto_save = fill_config_var (val); break; case CUSTOM_CONF_PERIODICSAVE: - if (atoi (e_conf) < 0) + if (atoi (val) < 0) conf->periodic_save = 0; else - conf->periodic_save = atoi (e_conf); + conf->periodic_save = atoi (val); break; case CUSTOM_CONF_CONFIRMQUIT: - conf->confirm_quit = fill_config_var (e_conf); + conf->confirm_quit = fill_config_var (val); break; case CUSTOM_CONF_CONFIRMDELETE: - conf->confirm_delete = fill_config_var (e_conf); + conf->confirm_delete = fill_config_var (val); break; case CUSTOM_CONF_SKIPSYSTEMDIALOGS: - conf->skip_system_dialogs = fill_config_var (e_conf); + conf->skip_system_dialogs = fill_config_var (val); break; case CUSTOM_CONF_SKIPPROGRESSBAR: - conf->skip_progress_bar = fill_config_var (e_conf); + conf->skip_progress_bar = fill_config_var (val); break; case CUSTOM_CONF_CALENDAR_DEFAULTVIEW: - calendar_set_view (atoi (e_conf)); + calendar_set_view (atoi (val)); break; case CUSTOM_CONF_WEEKBEGINSONMONDAY: - if (fill_config_var (e_conf)) + if (fill_config_var (val)) calendar_set_first_day_of_week (MONDAY); else calendar_set_first_day_of_week (SUNDAY); break; case CUSTOM_CONF_COLORTHEME: - custom_load_color (e_conf, background); + custom_load_color (val, background); break; case CUSTOM_CONF_LAYOUT: - wins_set_layout (atoi (e_conf)); + wins_set_layout (atoi (val)); break; case CUSTOM_CONF_SBAR_WIDTH: - wins_set_sbar_width (atoi (e_conf)); + wins_set_sbar_width (atoi (val)); break; case CUSTOM_CONF_NOTIFYBARSHOW: - nbar.show = fill_config_var (e_conf); + nbar.show = fill_config_var (val); break; case CUSTOM_CONF_NOTIFYBARDATE: - (void)strncpy (nbar.datefmt, e_conf, strlen (e_conf) + 1); + (void)strncpy (nbar.datefmt, val, strlen (val) + 1); break; case CUSTOM_CONF_NOTIFYBARCLOCK: - (void)strncpy (nbar.timefmt, e_conf, strlen (e_conf) + 1); + (void)strncpy (nbar.timefmt, val, strlen (val) + 1); break; case CUSTOM_CONF_NOTIFYBARWARNING: - nbar.cntdwn = atoi (e_conf); + nbar.cntdwn = atoi (val); break; case CUSTOM_CONF_NOTIFYBARCOMMAND: - (void)strncpy (nbar.cmd, e_conf, strlen (e_conf) + 1); + (void)strncpy (nbar.cmd, val, strlen (val) + 1); break; case CUSTOM_CONF_OUTPUTDATEFMT: - if (e_conf[0] != '\0') - (void)strncpy (conf->output_datefmt, e_conf, strlen (e_conf) + 1); + if (val[0] != '\0') + (void)strncpy (conf->output_datefmt, val, strlen (val) + 1); break; case CUSTOM_CONF_INPUTDATEFMT: - conf->input_datefmt = atoi (e_conf); + conf->input_datefmt = atoi (val); if (conf->input_datefmt <= 0 || conf->input_datefmt >= DATE_FORMATS) conf->input_datefmt = 1; break; case CUSTOM_CONF_DMON_ENABLE: - dmon.enable = fill_config_var (e_conf); + dmon.enable = fill_config_var (val); break; case CUSTOM_CONF_DMON_LOG: - dmon.log = fill_config_var (e_conf); + dmon.log = fill_config_var (val); break; } } -- cgit v1.2.3-70-g09d2