diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-15 17:47:28 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-15 17:47:28 +0200 |
commit | 5f24132d18895e6b4670798e63812d6611b25459 (patch) | |
tree | b5511cd27c36f1797586a48f1908c5bba2cec100 /src | |
parent | c21137129adf0e8dcb08ef43aa8174c8f935ca06 (diff) | |
download | calcurse-5f24132d18895e6b4670798e63812d6611b25459.tar.gz calcurse-5f24132d18895e6b4670798e63812d6611b25459.zip |
Refactor custom_load_conf()
Read key and value of each configuration setting in one loop cycle to
facilitate adjustments of the configuration setting format. Also, this
allows us to get rid of all the redundant variable resetting.
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/custom.c | 112 |
1 files changed, 49 insertions, 63 deletions
diff --git a/src/custom.c b/src/custom.c index 1f75978..bb84410 100644 --- a/src/custom.c +++ b/src/custom.c @@ -251,14 +251,61 @@ custom_load_conf (struct conf *conf, int background) wins_doupdate (); (void)keys_getch (win[STA].p); } - var = CUSTOM_CONF_NOVARIABLE; pthread_mutex_lock (&nbar.mutex); for (;;) { if (fgets (buf, sizeof buf, data_file) == NULL) + break; + io_extract_data (e_conf, buf, sizeof buf); + + if (strncmp (e_conf, "auto_save=", 10) == 0) + var = CUSTOM_CONF_AUTOSAVE; + else if (strncmp (e_conf, "periodic_save=", 14) == 0) + var = CUSTOM_CONF_PERIODICSAVE; + else if (strncmp (e_conf, "confirm_quit=", 13) == 0) + var = CUSTOM_CONF_CONFIRMQUIT; + else if (strncmp (e_conf, "confirm_delete=", 15) == 0) + var = CUSTOM_CONF_CONFIRMDELETE; + else if (strncmp (e_conf, "skip_system_dialogs=", 20) == 0) + var = CUSTOM_CONF_SKIPSYSTEMDIALOGS; + else if (strncmp (e_conf, "skip_progress_bar=", 18) == 0) + var = CUSTOM_CONF_SKIPPROGRESSBAR; + else if (strncmp (e_conf, "calendar_default_view=", 22) == 0) + var = CUSTOM_CONF_CALENDAR_DEFAULTVIEW; + else if (strncmp (e_conf, "week_begins_on_monday=", 22) == 0) + var = CUSTOM_CONF_WEEKBEGINSONMONDAY; + else if (strncmp (e_conf, "color-theme=", 12) == 0) + var = CUSTOM_CONF_COLORTHEME; + else if (strncmp (e_conf, "layout=", 7) == 0) + var = CUSTOM_CONF_LAYOUT; + else if (strncmp (e_conf, "side-bar_width=", 15) == 0) + var = CUSTOM_CONF_SBAR_WIDTH; + else if (strncmp (e_conf, "notify-bar_show=", 16) == 0) + var = CUSTOM_CONF_NOTIFYBARSHOW; + else if (strncmp (e_conf, "notify-bar_date=", 16) == 0) + var = CUSTOM_CONF_NOTIFYBARDATE; + else if (strncmp (e_conf, "notify-bar_clock=", 17) == 0) + var = CUSTOM_CONF_NOTIFYBARCLOCK; + else if (strncmp (e_conf, "notify-bar_warning=", 19) == 0) + var = CUSTOM_CONF_NOTIFYBARWARNING; + else if (strncmp (e_conf, "notify-bar_command=", 19) == 0) + var = CUSTOM_CONF_NOTIFYBARCOMMAND; + else if (strncmp (e_conf, "output_datefmt=", 15) == 0) + var = CUSTOM_CONF_OUTPUTDATEFMT; + else if (strncmp (e_conf, "input_datefmt=", 14) == 0) + var = CUSTOM_CONF_INPUTDATEFMT; + else if (strncmp (e_conf, "notify-daemon_enable=", 21) == 0) + var = CUSTOM_CONF_DMON_ENABLE; + else if (strncmp (e_conf, "notify-daemon_log=", 18) == 0) + var = CUSTOM_CONF_DMON_LOG; + else { - break; + var = CUSTOM_CONF_NOVARIABLE; + continue; } + + if (fgets (buf, sizeof buf, data_file) == NULL) + break; io_extract_data (e_conf, buf, sizeof buf); switch (var) @@ -267,138 +314,77 @@ custom_load_conf (struct conf *conf, int background) break; case CUSTOM_CONF_AUTOSAVE: conf->auto_save = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_PERIODICSAVE: if (atoi (e_conf) < 0) conf->periodic_save = 0; else conf->periodic_save = atoi (e_conf); - var = 0; break; case CUSTOM_CONF_CONFIRMQUIT: conf->confirm_quit = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_CONFIRMDELETE: conf->confirm_delete = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_SKIPSYSTEMDIALOGS: conf->skip_system_dialogs = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_SKIPPROGRESSBAR: conf->skip_progress_bar = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_CALENDAR_DEFAULTVIEW: calendar_set_view (atoi (e_conf)); - var = 0; break; case CUSTOM_CONF_WEEKBEGINSONMONDAY: if (fill_config_var (e_conf)) calendar_set_first_day_of_week (MONDAY); else calendar_set_first_day_of_week (SUNDAY); - var = 0; break; case CUSTOM_CONF_COLORTHEME: custom_load_color (e_conf, background); - var = 0; break; case CUSTOM_CONF_LAYOUT: wins_set_layout (atoi (e_conf)); - var = 0; break; case CUSTOM_CONF_SBAR_WIDTH: wins_set_sbar_width (atoi (e_conf)); - var = 0; break; case CUSTOM_CONF_NOTIFYBARSHOW: nbar.show = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_NOTIFYBARDATE: (void)strncpy (nbar.datefmt, e_conf, strlen (e_conf) + 1); - var = 0; break; case CUSTOM_CONF_NOTIFYBARCLOCK: (void)strncpy (nbar.timefmt, e_conf, strlen (e_conf) + 1); - var = 0; break; case CUSTOM_CONF_NOTIFYBARWARNING: nbar.cntdwn = atoi (e_conf); - var = 0; break; case CUSTOM_CONF_NOTIFYBARCOMMAND: (void)strncpy (nbar.cmd, e_conf, strlen (e_conf) + 1); - var = 0; break; case CUSTOM_CONF_OUTPUTDATEFMT: if (e_conf[0] != '\0') (void)strncpy (conf->output_datefmt, e_conf, strlen (e_conf) + 1); - var = 0; break; case CUSTOM_CONF_INPUTDATEFMT: conf->input_datefmt = atoi (e_conf); if (conf->input_datefmt <= 0 || conf->input_datefmt >= DATE_FORMATS) conf->input_datefmt = 1; - var = 0; break; case CUSTOM_CONF_DMON_ENABLE: dmon.enable = fill_config_var (e_conf); - var = 0; break; case CUSTOM_CONF_DMON_LOG: dmon.log = fill_config_var (e_conf); - var = 0; break; default: EXIT (_("configuration variable unknown")); /* NOTREACHED */ } - - if (strncmp (e_conf, "auto_save=", 10) == 0) - var = CUSTOM_CONF_AUTOSAVE; - else if (strncmp (e_conf, "periodic_save=", 14) == 0) - var = CUSTOM_CONF_PERIODICSAVE; - else if (strncmp (e_conf, "confirm_quit=", 13) == 0) - var = CUSTOM_CONF_CONFIRMQUIT; - else if (strncmp (e_conf, "confirm_delete=", 15) == 0) - var = CUSTOM_CONF_CONFIRMDELETE; - else if (strncmp (e_conf, "skip_system_dialogs=", 20) == 0) - var = CUSTOM_CONF_SKIPSYSTEMDIALOGS; - else if (strncmp (e_conf, "skip_progress_bar=", 18) == 0) - var = CUSTOM_CONF_SKIPPROGRESSBAR; - else if (strncmp (e_conf, "calendar_default_view=", 22) == 0) - var = CUSTOM_CONF_CALENDAR_DEFAULTVIEW; - else if (strncmp (e_conf, "week_begins_on_monday=", 22) == 0) - var = CUSTOM_CONF_WEEKBEGINSONMONDAY; - else if (strncmp (e_conf, "color-theme=", 12) == 0) - var = CUSTOM_CONF_COLORTHEME; - else if (strncmp (e_conf, "layout=", 7) == 0) - var = CUSTOM_CONF_LAYOUT; - else if (strncmp (e_conf, "side-bar_width=", 15) == 0) - var = CUSTOM_CONF_SBAR_WIDTH; - else if (strncmp (e_conf, "notify-bar_show=", 16) == 0) - var = CUSTOM_CONF_NOTIFYBARSHOW; - else if (strncmp (e_conf, "notify-bar_date=", 16) == 0) - var = CUSTOM_CONF_NOTIFYBARDATE; - else if (strncmp (e_conf, "notify-bar_clock=", 17) == 0) - var = CUSTOM_CONF_NOTIFYBARCLOCK; - else if (strncmp (e_conf, "notify-bar_warning=", 19) == 0) - var = CUSTOM_CONF_NOTIFYBARWARNING; - else if (strncmp (e_conf, "notify-bar_command=", 19) == 0) - var = CUSTOM_CONF_NOTIFYBARCOMMAND; - else if (strncmp (e_conf, "output_datefmt=", 15) == 0) - var = CUSTOM_CONF_OUTPUTDATEFMT; - else if (strncmp (e_conf, "input_datefmt=", 14) == 0) - var = CUSTOM_CONF_INPUTDATEFMT; - else if (strncmp (e_conf, "notify-daemon_enable=", 21) == 0) - var = CUSTOM_CONF_DMON_ENABLE; - else if (strncmp (e_conf, "notify-daemon_log=", 18) == 0) - var = CUSTOM_CONF_DMON_LOG; } file_close (data_file, __FILE_POS__); pthread_mutex_unlock (&nbar.mutex); |