From 093b28ac398ffdc2733bc6f42fa58d2153576ad9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 9 Dec 2011 20:48:39 +0100 Subject: Extract config file handlers into a separate file We used custom_load_conf() to load the configuration file and io_save_conf() to save configuration. Move these functions, including all helpers, to a central location. Signed-off-by: Lukas Fleischer --- src/io.c | 143 +-------------------------------------------------------------- 1 file changed, 1 insertion(+), 142 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index f35e98f..e42d3cf 100644 --- a/src/io.c +++ b/src/io.c @@ -832,147 +832,6 @@ display_mark (void) static pthread_mutex_t io_save_mutex = PTHREAD_MUTEX_INITIALIZER; -/* Save the user configuration. */ -unsigned -io_save_conf (void) -{ - char *config_txt = - "#\n" - "# Calcurse configuration file\n#\n" - "# This file sets the configuration options used by Calcurse. These\n" - "# options are usually set from within Calcurse. A line beginning with \n" - "# a space or tab is considered to be a continuation of the previous " - "line.\n" - "# For a variable to be unset its value must be blank, followed by an\n" - "# empty line. To set a variable to the empty string its value should be " - "\"\".\n" - "# Lines beginning with \"#\" are comments, and ignored by Calcurse.\n"; - char theme_name[BUFSIZ]; - FILE *fp; - - if ((fp = fopen (path_conf, "w")) == NULL) - return 0; - - custom_color_theme_name (theme_name); - - fprintf (fp, "%s\n", config_txt); - - fputs ("# If this option is set to yes, " - "automatic save is done when quitting\n", fp); - fputs ("auto_save=", fp); - fprintf (fp, "%s\n", (conf.auto_save) ? "yes" : "no"); - - fputs ("\n# If this option is set to yes, " - "the GC is run automatically when quitting\n", fp); - fputs ("auto_gc=", fp); - fprintf (fp, "%s\n", (conf.auto_gc) ? "yes" : "no"); - - fputs ("\n# If not null, perform automatic saves every " - "'periodic_save' minutes\n", fp); - fputs ("periodic_save=", fp); - fprintf (fp, "%d\n", conf.periodic_save); - - fputs ("\n# If this option is set to yes, " - "confirmation is required before quitting\n", fp); - fputs ("confirm_quit=", fp); - fprintf (fp, "%s\n", (conf.confirm_quit) ? "yes" : "no"); - - fputs ("\n# If this option is set to yes, " - "confirmation is required before deleting an event\n", fp); - fputs ("confirm_delete=", fp); - fprintf (fp, "%s\n", (conf.confirm_delete) ? "yes" : "no"); - - fputs ("\n# If this option is set to yes, messages about loaded and " - "saved data will not be displayed\n", fp); - fputs ("skip_system_dialogs=", fp); - fprintf (fp, "%s\n", (conf.skip_system_dialogs) ? "yes" : "no"); - - fputs ("\n# If this option is set to yes, progress bar appearing " - "when saving data will not be displayed\n", fp); - fputs ("skip_progress_bar=", fp); - fprintf (fp, "%s\n", (conf.skip_progress_bar) ? "yes" : "no"); - - fputs ("\n# Default calendar view (0)monthly (1)weekly:\n", fp); - fputs ("calendar_default_view=", fp); - fprintf (fp, "%d\n", calendar_get_view ()); - - fputs ("\n# If this option is set to yes, " - "monday is the first day of the week, else it is sunday\n", fp); - fputs ("week_begins_on_monday=", fp); - fprintf (fp, "%s\n", (calendar_week_begins_on_monday ())? "yes" : "no"); - - fputs ("\n# This is the color theme used for menus :\n", fp); - fputs ("color-theme=", fp); - fprintf (fp, "%s\n", theme_name); - - fputs ("\n# This is the layout of the calendar :\n", fp); - fputs ("layout=", fp); - fprintf (fp, "%d\n", wins_layout ()); - - fputs ("\n# Width ( percentage, 0 being minimun width, fp) " - "of the side bar :\n", fp); - fputs ("side-bar_width=", fp); - fprintf (fp, "%d\n", wins_sbar_wperc ()); - - if (ui_mode == UI_CURSES) - pthread_mutex_lock (&nbar.mutex); - fputs ("\n# If this option is set to yes, " - "notify-bar will be displayed :\n", fp); - fputs ("notify-bar_show=", fp); - fprintf (fp, "%s\n", (nbar.show) ? "yes" : "no"); - - fputs ("\n# Format of the date to be displayed inside notify-bar :\n", fp); - fputs ("notify-bar_date=", fp); - fprintf (fp, "%s\n", nbar.datefmt); - - fputs ("\n# Format of the time to be displayed inside notify-bar :\n", fp); - fputs ("notify-bar_clock=", fp); - fprintf (fp, "%s\n", nbar.timefmt); - - fputs ("\n# Warn user if he has an appointment within next " - "'notify-bar_warning' seconds :\n", fp); - fputs ("notify-bar_warning=", fp); - fprintf (fp, "%d\n", nbar.cntdwn); - - fputs ("\n# Command used to notify user of " - "an upcoming appointment :\n", fp); - fputs ("notify-bar_command=", fp); - fprintf (fp, "%s\n", nbar.cmd); - - fputs ("\n# Notify all appointments instead of flagged ones only\n", fp); - fputs ("notify-all=", fp); - fprintf (fp, "%s\n", (nbar.notify_all) ? "yes" : "no"); - - fputs ("\n# Format of the date to be displayed " - "in non-interactive mode :\n", fp); - fputs ("output_datefmt=", fp); - fprintf (fp, "%s\n", conf.output_datefmt); - - fputs ("\n# Format to be used when entering a date " - "(1)mm/dd/yyyy (2)dd/mm/yyyy (3)yyyy/mm/dd) " - "(4)yyyy-mm-dd:\n", fp); - fputs ("input_datefmt=", fp); - fprintf (fp, "%d\n", conf.input_datefmt); - - if (ui_mode == UI_CURSES) - pthread_mutex_unlock (&nbar.mutex); - - fputs ("\n# If this option is set to yes, " - "calcurse will run in background to get notifications " - "after exiting\n", fp); - fputs ("notify-daemon_enable=", fp); - fprintf (fp, "%s\n", dmon.enable ? "yes" : "no"); - - fputs ("\n# If this option is set to yes, " - "activity will be logged when running in background\n", fp); - fputs ("notify-daemon_log=", fp); - fprintf (fp, "%s\n", dmon.log ? "yes" : "no"); - - file_close (fp, __FILE_POS__); - - return 1; -} - /* * Save the apts data file, which contains the * appointments first, and then the events. @@ -1064,7 +923,7 @@ io_save_cal (enum save_display display) if (show_bar) progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF); - if (!io_save_conf ()) + if (!config_save ()) ERROR_MSG ("%s", access_pb); if (show_bar) -- cgit v1.2.3