summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2012-05-21 10:13:05 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-05-21 10:13:05 +0200
commitcfd8ede2b3c7248bd3b78e71ef17bdc9eb819aae (patch)
tree1ba7b4f15c9a36cd5d9aab803ed4e9defb8222d2 /src/config.c
parent47c52ae7bbfec87a80fb583fb0753b4d77b0ba1d (diff)
downloadcalcurse-cfd8ede2b3c7248bd3b78e71ef17bdc9eb819aae.zip
Switch to Linux kernel coding style
Convert our code base to adhere to Linux kernel coding style using Lindent, with the following exceptions: * Use spaces, instead of tabs, for indentation. * Use 2-character indentations (instead of 8 characters). Rationale: We currently have too much levels of indentation. Using 8-character tabs would make huge code parts unreadable. These need to be cleaned up before we can switch to 8 characters. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c554
1 files changed, 256 insertions, 298 deletions
diff --git a/src/config.c b/src/config.c
index 98e622a..edf1f3b 100644
--- a/src/config.c
+++ b/src/config.c
@@ -49,28 +49,28 @@ struct confvar {
void *target;
};
-static int config_parse_bool (unsigned *, const char *);
-static int config_serialize_bool (char *, unsigned *);
-static int config_parse_int (int *, const char *);
-static int config_serialize_int (char *, int *);
-static int config_parse_unsigned (unsigned *, const char *);
-static int config_serialize_unsigned (char *, unsigned *);
-static int config_parse_str (char *, const char *);
-static int config_serialize_str (char *, const char *);
-static int config_parse_calendar_view (void *, const char *);
-static int config_serialize_calendar_view (char *, void *);
-static int config_parse_first_day_of_week (void *, const char *);
-static int config_serialize_first_day_of_week (char *, void *);
-static int config_parse_color_theme (void *, const char *);
-static int config_serialize_color_theme (char *, void *);
-static int config_parse_layout (void *, const char *);
-static int config_serialize_layout (char *, void *);
-static int config_parse_sidebar_width (void *, const char *);
-static int config_serialize_sidebar_width (char *, void *);
-static int config_parse_output_datefmt (void *, const char *);
-static int config_serialize_output_datefmt (char *, void *);
-static int config_parse_input_datefmt (void *, const char *);
-static int config_serialize_input_datefmt (char *, void *);
+static int config_parse_bool(unsigned *, const char *);
+static int config_serialize_bool(char *, unsigned *);
+static int config_parse_int(int *, const char *);
+static int config_serialize_int(char *, int *);
+static int config_parse_unsigned(unsigned *, const char *);
+static int config_serialize_unsigned(char *, unsigned *);
+static int config_parse_str(char *, const char *);
+static int config_serialize_str(char *, const char *);
+static int config_parse_calendar_view(void *, const char *);
+static int config_serialize_calendar_view(char *, void *);
+static int config_parse_first_day_of_week(void *, const char *);
+static int config_serialize_first_day_of_week(char *, void *);
+static int config_parse_color_theme(void *, const char *);
+static int config_serialize_color_theme(char *, void *);
+static int config_parse_layout(void *, const char *);
+static int config_serialize_layout(char *, void *);
+static int config_parse_sidebar_width(void *, const char *);
+static int config_serialize_sidebar_width(char *, void *);
+static int config_parse_output_datefmt(void *, const char *);
+static int config_serialize_output_datefmt(char *, void *);
+static int config_parse_input_datefmt(void *, const char *);
+static int config_serialize_input_datefmt(char *, void *);
#define CONFIG_HANDLER_BOOL(var) (config_fn_parse_t) config_parse_bool, \
(config_fn_serialize_t) config_serialize_bool, &(var)
@@ -82,44 +82,49 @@ static int config_serialize_input_datefmt (char *, void *);
(config_fn_serialize_t) config_serialize_str, &(var)
static const struct confvar confmap[] = {
- { "appearance.calendarview", config_parse_calendar_view, config_serialize_calendar_view, NULL },
- { "appearance.layout", config_parse_layout, config_serialize_layout, NULL },
- { "appearance.notifybar", CONFIG_HANDLER_BOOL (nbar.show) },
- { "appearance.sidebarwidth", config_parse_sidebar_width, config_serialize_sidebar_width, NULL },
- { "appearance.theme", config_parse_color_theme, config_serialize_color_theme, NULL },
- { "daemon.enable", CONFIG_HANDLER_BOOL (dmon.enable) },
- { "daemon.log", CONFIG_HANDLER_BOOL (dmon.log) },
- { "format.inputdate", config_parse_input_datefmt, config_serialize_input_datefmt, NULL },
- { "format.notifydate", CONFIG_HANDLER_STR (nbar.datefmt) },
- { "format.notifytime", CONFIG_HANDLER_STR (nbar.timefmt) },
- { "format.outputdate", config_parse_output_datefmt, config_serialize_output_datefmt, NULL },
- { "general.autogc", CONFIG_HANDLER_BOOL (conf.auto_gc) },
- { "general.autosave", CONFIG_HANDLER_BOOL (conf.auto_save) },
- { "general.confirmdelete", CONFIG_HANDLER_BOOL (conf.confirm_delete) },
- { "general.confirmquit", CONFIG_HANDLER_BOOL (conf.confirm_quit) },
- { "general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL },
- { "general.periodicsave", CONFIG_HANDLER_UNSIGNED (conf.periodic_save) },
- { "general.progressbar", CONFIG_HANDLER_BOOL (conf.progress_bar) },
- { "general.systemdialogs", CONFIG_HANDLER_BOOL (conf.system_dialogs) },
- { "notification.command", CONFIG_HANDLER_STR (nbar.cmd) },
- { "notification.notifyall", CONFIG_HANDLER_BOOL (nbar.notify_all) },
- { "notification.warning", CONFIG_HANDLER_INT (nbar.cntdwn) }
+ {"appearance.calendarview", config_parse_calendar_view,
+ config_serialize_calendar_view, NULL},
+ {"appearance.layout", config_parse_layout, config_serialize_layout, NULL},
+ {"appearance.notifybar", CONFIG_HANDLER_BOOL(nbar.show)},
+ {"appearance.sidebarwidth", config_parse_sidebar_width,
+ config_serialize_sidebar_width, NULL},
+ {"appearance.theme", config_parse_color_theme, config_serialize_color_theme,
+ NULL},
+ {"daemon.enable", CONFIG_HANDLER_BOOL(dmon.enable)},
+ {"daemon.log", CONFIG_HANDLER_BOOL(dmon.log)},
+ {"format.inputdate", config_parse_input_datefmt,
+ config_serialize_input_datefmt, NULL},
+ {"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
+ {"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
+ {"format.outputdate", config_parse_output_datefmt,
+ config_serialize_output_datefmt, NULL},
+ {"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
+ {"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
+ {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
+ {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)},
+ {"general.firstdayofweek", config_parse_first_day_of_week,
+ config_serialize_first_day_of_week, NULL},
+ {"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)},
+ {"general.progressbar", CONFIG_HANDLER_BOOL(conf.progress_bar)},
+ {"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)},
+ {"notification.command", CONFIG_HANDLER_STR(nbar.cmd)},
+ {"notification.notifyall", CONFIG_HANDLER_BOOL(nbar.notify_all)},
+ {"notification.warning", CONFIG_HANDLER_INT(nbar.cntdwn)}
};
struct config_save_status {
FILE *fp;
- int done[sizeof (confmap) / sizeof (confmap[0])];
+ int done[sizeof(confmap) / sizeof(confmap[0])];
};
typedef int (*config_fn_walk_cb_t) (const char *, const char *, void *);
typedef int (*config_fn_walk_junk_cb_t) (const char *, void *);
-static int
-config_parse_bool (unsigned *dest, const char *val)
+static int config_parse_bool(unsigned *dest, const char *val)
{
- if (strcmp (val, "yes") == 0)
+ if (strcmp(val, "yes") == 0)
*dest = 1;
- else if (strcmp (val, "no") == 0)
+ else if (strcmp(val, "no") == 0)
*dest = 0;
else
return 0;
@@ -127,55 +132,51 @@ config_parse_bool (unsigned *dest, const char *val)
return 1;
}
-static int
-config_parse_unsigned (unsigned *dest, const char *val)
+static int config_parse_unsigned(unsigned *dest, const char *val)
{
- if (is_all_digit (val))
- *dest = atoi (val);
+ if (is_all_digit(val))
+ *dest = atoi(val);
else
return 0;
return 1;
}
-static int
-config_parse_int (int *dest, const char *val)
+static int config_parse_int(int *dest, const char *val)
{
- if ((*val == '+' || *val == '-' || isdigit (*val)) && is_all_digit (val + 1))
- *dest = atoi (val);
+ if ((*val == '+' || *val == '-' || isdigit(*val)) && is_all_digit(val + 1))
+ *dest = atoi(val);
else
return 0;
return 1;
}
-static int
-config_parse_str (char *dest, const char *val)
+static int config_parse_str(char *dest, const char *val)
{
- strncpy (dest, val, BUFSIZ);
+ strncpy(dest, val, BUFSIZ);
return 1;
}
-static int
-config_parse_color (int *dest, const char *val)
+static int config_parse_color(int *dest, const char *val)
{
- if (!strcmp (val, "black"))
+ if (!strcmp(val, "black"))
*dest = COLOR_BLACK;
- else if (!strcmp (val, "red"))
+ else if (!strcmp(val, "red"))
*dest = COLOR_RED;
- else if (!strcmp (val, "green"))
+ else if (!strcmp(val, "green"))
*dest = COLOR_GREEN;
- else if (!strcmp (val, "yellow"))
+ else if (!strcmp(val, "yellow"))
*dest = COLOR_YELLOW;
- else if (!strcmp (val, "blue"))
+ else if (!strcmp(val, "blue"))
*dest = COLOR_BLUE;
- else if (!strcmp (val, "magenta"))
+ else if (!strcmp(val, "magenta"))
*dest = COLOR_MAGENTA;
- else if (!strcmp (val, "cyan"))
+ else if (!strcmp(val, "cyan"))
*dest = COLOR_CYAN;
- else if (!strcmp (val, "white"))
+ else if (!strcmp(val, "white"))
*dest = COLOR_WHITE;
- else if (!strcmp (val, "default"))
+ else if (!strcmp(val, "default"))
*dest = background;
else
return 0;
@@ -183,137 +184,119 @@ config_parse_color (int *dest, const char *val)
return 1;
}
-static int
-config_parse_color_pair (int *dest1, int *dest2, const char *val)
+static int config_parse_color_pair(int *dest1, int *dest2, const char *val)
{
char s1[BUFSIZ], s2[BUFSIZ];
- if (sscanf (val, "%s on %s", s1, s2) != 2)
+ if (sscanf(val, "%s on %s", s1, s2) != 2)
return 0;
- return (config_parse_color (dest1, s1) && config_parse_color (dest2, s2));
+ return (config_parse_color(dest1, s1) && config_parse_color(dest2, s2));
}
-static int
-config_parse_calendar_view (void *dummy, const char *val)
+static int config_parse_calendar_view(void *dummy, const char *val)
{
- calendar_set_view (atoi (val));
+ calendar_set_view(atoi(val));
return 1;
}
-static int
-config_parse_first_day_of_week (void *dummy, const char *val)
+static int config_parse_first_day_of_week(void *dummy, const char *val)
{
- if (!strcmp (val, "monday"))
- calendar_set_first_day_of_week (MONDAY);
- else if (!strcmp (val, "sunday"))
- calendar_set_first_day_of_week (SUNDAY);
+ if (!strcmp(val, "monday"))
+ calendar_set_first_day_of_week(MONDAY);
+ else if (!strcmp(val, "sunday"))
+ calendar_set_first_day_of_week(SUNDAY);
else
return 0;
return 1;
}
-static int
-config_parse_color_theme (void *dummy, const char *val)
+static int config_parse_color_theme(void *dummy, const char *val)
{
int color1, color2;
- if (!config_parse_color_pair (&color1, &color2, val))
+ if (!config_parse_color_pair(&color1, &color2, val))
return 0;
- init_pair (COLR_CUSTOM, color1, color2);
+ init_pair(COLR_CUSTOM, color1, color2);
return 1;
}
-static int
-config_parse_layout (void *dummy, const char *val)
+static int config_parse_layout(void *dummy, const char *val)
{
- wins_set_layout (atoi (val));
+ wins_set_layout(atoi(val));
return 1;
}
-static int
-config_parse_sidebar_width (void *dummy, const char *val)
+static int config_parse_sidebar_width(void *dummy, const char *val)
{
- wins_set_sbar_width (atoi (val));
+ wins_set_sbar_width(atoi(val));
return 1;
}
-static int
-config_parse_output_datefmt (void *dummy, const char *val)
+static int config_parse_output_datefmt(void *dummy, const char *val)
{
if (val[0] != '\0')
- return config_parse_str (conf.output_datefmt, val);
+ return config_parse_str(conf.output_datefmt, val);
return 1;
}
-static int
-config_parse_input_datefmt (void *dummy, const char *val)
+static int config_parse_input_datefmt(void *dummy, const char *val)
{
- if (config_parse_int (&conf.input_datefmt, val)) {
+ if (config_parse_int(&conf.input_datefmt, val)) {
if (conf.input_datefmt <= 0 || conf.input_datefmt >= DATE_FORMATS)
conf.input_datefmt = 1;
return 1;
- }
- else
+ } else
return 0;
}
/* Set a configuration variable. */
-static int
-config_set_conf (const char *key, const char *value)
+static int config_set_conf(const char *key, const char *value)
{
int i;
if (!key)
return -1;
- for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
- {
- if (!strcmp (confmap[i].key, key))
- return confmap[i].fn_parse (confmap[i].target, value);
- }
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!strcmp(confmap[i].key, key))
+ return confmap[i].fn_parse(confmap[i].target, value);
+ }
return -1;
}
-static int
-config_serialize_bool (char *dest, unsigned *val)
-{
- if (*val)
- {
- dest[0] = 'y';
- dest[1] = 'e';
- dest[2] = 's';
- dest[3] = '\0';
- }
- else
- {
- dest[0] = 'n';
- dest[1] = 'o';
- dest[2] = '\0';
- }
+static int config_serialize_bool(char *dest, unsigned *val)
+{
+ if (*val) {
+ dest[0] = 'y';
+ dest[1] = 'e';
+ dest[2] = 's';
+ dest[3] = '\0';
+ } else {
+ dest[0] = 'n';
+ dest[1] = 'o';
+ dest[2] = '\0';
+ }
return 1;
}
-static int
-config_serialize_unsigned (char *dest, unsigned *val)
+static int config_serialize_unsigned(char *dest, unsigned *val)
{
- snprintf (dest, BUFSIZ, "%u", *val);
+ snprintf(dest, BUFSIZ, "%u", *val);
return 1;
}
-static int
-config_serialize_int (char *dest, int *val)
+static int config_serialize_int(char *dest, int *val)
{
- snprintf (dest, BUFSIZ, "%d", *val);
+ snprintf(dest, BUFSIZ, "%d", *val);
return 1;
}
-static int
-config_serialize_str (char *dest, const char *val)
+static int config_serialize_str(char *dest, const char *val)
{
- strncpy (dest, val, BUFSIZ);
+ strncpy(dest, val, BUFSIZ);
return 1;
}
@@ -325,8 +308,7 @@ config_serialize_str (char *dest, const char *val)
* If ncurses library was compiled with --enable-ext-funcs,
* then default color is -1.
*/
-static void
-config_color_theme_name (char *theme_name)
+static void config_color_theme_name(char *theme_name)
{
#define MAXCOLORS 8
#define NBCOLORS 2
@@ -349,37 +331,32 @@ config_color_theme_name (char *theme_name)
};
if (!colorize)
- strncpy (theme_name, "0", BUFSIZ);
- else
- {
- pair_content (COLR_CUSTOM, &color[0], &color[1]);
- for (i = 0; i < NBCOLORS; i++)
- {
- if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
- color_name[i] = default_color;
- else if (color[i] >= 0 && color[i] <= MAXCOLORS)
- color_name[i] = name[color[i]];
- else
- {
- EXIT (_("unknown color"));
- /* NOTREACHED */
- }
- }
- snprintf (theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
+ strncpy(theme_name, "0", BUFSIZ);
+ else {
+ pair_content(COLR_CUSTOM, &color[0], &color[1]);
+ for (i = 0; i < NBCOLORS; i++) {
+ if ((color[i] == DEFAULTCOLOR) || (color[i] == DEFAULTCOLOR_EXT))
+ color_name[i] = default_color;
+ else if (color[i] >= 0 && color[i] <= MAXCOLORS)
+ color_name[i] = name[color[i]];
+ else {
+ EXIT(_("unknown color"));
+ /* NOTREACHED */
+ }
}
+ snprintf(theme_name, BUFSIZ, "%s on %s", color_name[0], color_name[1]);
+ }
}
-static int
-config_serialize_calendar_view (char *buf, void *dummy)
+static int config_serialize_calendar_view(char *buf, void *dummy)
{
- int tmp = calendar_get_view ();
- return config_serialize_int (buf, &tmp);
+ int tmp = calendar_get_view();
+ return config_serialize_int(buf, &tmp);
}
-static int
-config_serialize_first_day_of_week (char *buf, void *dummy)
+static int config_serialize_first_day_of_week(char *buf, void *dummy)
{
- if (calendar_week_begins_on_monday ())
+ if (calendar_week_begins_on_monday())
strcpy(buf, "monday");
else
strcpy(buf, "sunday");
@@ -387,195 +364,177 @@ config_serialize_first_day_of_week (char *buf, void *dummy)
return 1;
}
-static int
-config_serialize_color_theme (char *buf, void *dummy)
+static int config_serialize_color_theme(char *buf, void *dummy)
{
- config_color_theme_name (buf);
+ config_color_theme_name(buf);
return 1;
}
-static int
-config_serialize_layout (char *buf, void *dummy)
+static int config_serialize_layout(char *buf, void *dummy)
{
- int tmp = wins_layout ();
- return config_serialize_int (buf, &tmp);
+ int tmp = wins_layout();
+ return config_serialize_int(buf, &tmp);
}
-static int
-config_serialize_sidebar_width (char *buf, void *dummy)
+static int config_serialize_sidebar_width(char *buf, void *dummy)
{
- int tmp = wins_sbar_wperc ();
- return config_serialize_int (buf, &tmp);
+ int tmp = wins_sbar_wperc();
+ return config_serialize_int(buf, &tmp);
}
-static int
-config_serialize_output_datefmt (char *buf, void *dummy)
+static int config_serialize_output_datefmt(char *buf, void *dummy)
{
- return config_serialize_str (buf, conf.output_datefmt);
+ return config_serialize_str(buf, conf.output_datefmt);
}
-static int
-config_serialize_input_datefmt (char *buf, void *dummy)
+static int config_serialize_input_datefmt(char *buf, void *dummy)
{
- return config_serialize_int (buf, &conf.input_datefmt);
+ return config_serialize_int(buf, &conf.input_datefmt);
}
/* Serialize the value of a configuration variable. */
static int
-config_serialize_conf (char *buf, const char *key,
- struct config_save_status *status)
+config_serialize_conf(char *buf, const char *key,
+ struct config_save_status *status)
{
int i;
if (!key)
return -1;
- for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
- {
- if (!strcmp (confmap[i].key, key))
- {
- if (confmap[i].fn_serialize (buf, confmap[i].target))
- {
- if (status)
- status->done[i] = 1;
- return 1;
- }
- else
- return 0;
- }
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!strcmp(confmap[i].key, key)) {
+ if (confmap[i].fn_serialize(buf, confmap[i].target)) {
+ if (status)
+ status->done[i] = 1;
+ return 1;
+ } else
+ return 0;
}
+ }
return -1;
}
static void
-config_file_walk (config_fn_walk_cb_t fn_cb,
- config_fn_walk_junk_cb_t fn_junk_cb, void *data)
+config_file_walk(config_fn_walk_cb_t fn_cb,
+ config_fn_walk_junk_cb_t fn_junk_cb, void *data)
{
FILE *data_file;
char buf[BUFSIZ], e_conf[BUFSIZ];
char *key, *value;
- data_file = fopen (path_conf, "r");
- EXIT_IF (data_file == NULL, _("failed to open configuration file"));
+ data_file = fopen(path_conf, "r");
+ EXIT_IF(data_file == NULL, _("failed to open configuration file"));
+
+ pthread_mutex_lock(&nbar.mutex);
+ for (;;) {
+ if (fgets(buf, sizeof buf, data_file) == NULL)
+ break;
+ io_extract_data(e_conf, buf, sizeof buf);
- pthread_mutex_lock (&nbar.mutex);
- for (;;)
- {
- if (fgets (buf, sizeof buf, data_file) == NULL)
+ if (*e_conf == '\0') {
+ if (fn_junk_cb)
+ fn_junk_cb(buf, data);
+ continue;
+ }
+
+ key = e_conf;
+ value = strchr(e_conf, '=');
+ if (value) {
+ *value = '\0';
+ value++;
+ }
+
+ if (strcmp(key, "auto_save") == 0 ||
+ strcmp(key, "auto_gc") == 0 ||
+ strcmp(key, "periodic_save") == 0 ||
+ strcmp(key, "confirm_quit") == 0 ||
+ strcmp(key, "confirm_delete") == 0 ||
+ strcmp(key, "skip_system_dialogs") == 0 ||
+ strcmp(key, "skip_progress_bar") == 0 ||
+ strcmp(key, "calendar_default_view") == 0 ||
+ strcmp(key, "week_begins_on_monday") == 0 ||
+ strcmp(key, "color-theme") == 0 ||
+ strcmp(key, "layout") == 0 ||
+ strcmp(key, "side-bar_width") == 0 ||
+ strcmp(key, "notify-bar_show") == 0 ||
+ strcmp(key, "notify-bar_date") == 0 ||
+ strcmp(key, "notify-bar_clock") == 0 ||
+ strcmp(key, "notify-bar_warning") == 0 ||
+ strcmp(key, "notify-bar_command") == 0 ||
+ strcmp(key, "notify-all") == 0 ||
+ strcmp(key, "output_datefmt") == 0 ||
+ strcmp(key, "input_datefmt") == 0 ||
+ strcmp(key, "notify-daemon_enable") == 0 ||
+ strcmp(key, "notify-daemon_log") == 0) {
+ WARN_MSG(_("Pre-3.0.0 configuration file format detected, "
+ "please upgrade running `calcurse-upgrade`."));
+ }
+
+ if (value && (*value == '\0' || *value == '\n')) {
+ /* Backward compatibility mode. */
+ if (fgets(buf, sizeof buf, data_file) == NULL)
break;
- io_extract_data (e_conf, buf, sizeof buf);
-
- if (*e_conf == '\0')
- {
- if (fn_junk_cb)
- fn_junk_cb (buf, data);
- continue;
- }
-
- key = e_conf;
- value = strchr (e_conf, '=');
- if (value)
- {
- *value = '\0';
- value++;
- }
-
- if (strcmp(key, "auto_save") == 0 ||
- strcmp(key, "auto_gc") == 0 ||
- strcmp(key, "periodic_save") == 0 ||
- strcmp(key, "confirm_quit") == 0 ||
- strcmp(key, "confirm_delete") == 0 ||
- strcmp(key, "skip_system_dialogs") == 0 ||
- strcmp(key, "skip_progress_bar") == 0 ||
- strcmp(key, "calendar_default_view") == 0 ||
- strcmp(key, "week_begins_on_monday") == 0 ||
- strcmp(key, "color-theme") == 0 ||
- strcmp(key, "layout") == 0 ||
- strcmp(key, "side-bar_width") == 0 ||
- strcmp(key, "notify-bar_show") == 0 ||
- strcmp(key, "notify-bar_date") == 0 ||
- strcmp(key, "notify-bar_clock") == 0 ||
- strcmp(key, "notify-bar_warning") == 0 ||
- strcmp(key, "notify-bar_command") == 0 ||
- strcmp(key, "notify-all") == 0 ||
- strcmp(key, "output_datefmt") == 0 ||
- strcmp(key, "input_datefmt") == 0 ||
- strcmp(key, "notify-daemon_enable") == 0 ||
- strcmp(key, "notify-daemon_log") == 0)
- {
- WARN_MSG (_("Pre-3.0.0 configuration file format detected, "
- "please upgrade running `calcurse-upgrade`."));
- }
-
- if (value && (*value == '\0' || *value == '\n'))
- {
- /* Backward compatibility mode. */
- if (fgets (buf, sizeof buf, data_file) == NULL)
- break;
- io_extract_data (e_conf, buf, sizeof buf);
- value = e_conf;
- }
-
- fn_cb (key, value, data);
+ io_extract_data(e_conf, buf, sizeof buf);
+ value = e_conf;
}
- file_close (data_file, __FILE_POS__);
- pthread_mutex_unlock (&nbar.mutex);
+
+ fn_cb(key, value, data);
+ }
+ file_close(data_file, __FILE_POS__);
+ pthread_mutex_unlock(&nbar.mutex);
}
-static int
-config_load_cb (const char *key, const char *value, void *dummy)
+static int config_load_cb(const char *key, const char *value, void *dummy)
{
- int result = config_set_conf (key, value);
+ int result = config_set_conf(key, value);
if (result < 0)
- EXIT (_("configuration variable unknown: \"%s\""), key);
- /* NOTREACHED */
+ EXIT(_("configuration variable unknown: \"%s\""), key);
+ /* NOTREACHED */
else if (result == 0)
- EXIT (_("wrong configuration variable format for \"%s\""), key);
- /* NOTREACHED */
+ EXIT(_("wrong configuration variable format for \"%s\""), key);
+ /* NOTREACHED */
return 1;
}
/* Load the user configuration. */
-void
-config_load (void)
+void config_load(void)
{
- config_file_walk (config_load_cb, NULL, NULL);
+ config_file_walk(config_load_cb, NULL, NULL);
}
-static int
-config_save_cb (const char *key, const char *value, void *status)
+static int config_save_cb(const char *key, const char *value, void *status)
{
char buf[BUFSIZ];
- int result = config_serialize_conf (buf, key, (struct config_save_status *) status);
+ int result =
+ config_serialize_conf(buf, key, (struct config_save_status *)status);
if (result < 0)
- EXIT (_("configuration variable unknown: \"%s\""), key);
- /* NOTREACHED */
+ EXIT(_("configuration variable unknown: \"%s\""), key);
+ /* NOTREACHED */
else if (result == 0)
- EXIT (_("wrong configuration variable format for \"%s\""), key);
- /* NOTREACHED */
+ EXIT(_("wrong configuration variable format for \"%s\""), key);
+ /* NOTREACHED */
- fputs (key, ((struct config_save_status *) status)->fp);
- fputc ('=', ((struct config_save_status *) status)->fp);
- fputs (buf, ((struct config_save_status *) status)->fp);
- fputc ('\n', ((struct config_save_status *) status)->fp);
+ fputs(key, ((struct config_save_status *)status)->fp);
+ fputc('=', ((struct config_save_status *)status)->fp);
+ fputs(buf, ((struct config_save_status *)status)->fp);
+ fputc('\n', ((struct config_save_status *)status)->fp);
return 1;
}
-static int
-config_save_junk_cb (const char *data, void *status)
+static int config_save_junk_cb(const char *data, void *status)
{
- fputs (data, ((struct config_save_status *) status)->fp);
+ fputs(data, ((struct config_save_status *)status)->fp);
return 1;
}
/* Save the user configuration. */
-unsigned
-config_save (void)
+unsigned config_save(void)
{
char tmppath[BUFSIZ];
char *tmpext;
@@ -585,32 +544,31 @@ config_save (void)
if (read_only)
return 1;
- strncpy (tmppath, get_tempdir (), BUFSIZ);
- strncat (tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen (tmppath) - 1);
- if ((tmpext = new_tempfile (tmppath, TMPEXTSIZ)) == NULL)
+ strncpy(tmppath, get_tempdir(), BUFSIZ);
+ strncat(tmppath, "/" CONF_PATH_NAME ".", BUFSIZ - strlen(tmppath) - 1);
+ if ((tmpext = new_tempfile(tmppath, TMPEXTSIZ)) == NULL)
return 0;
- strncat (tmppath, tmpext, BUFSIZ - strlen (tmppath) - 1);
- mem_free (tmpext);
+ strncat(tmppath, tmpext, BUFSIZ - strlen(tmppath) - 1);
+ mem_free(tmpext);
- status.fp = fopen (tmppath, "w");
+ status.fp = fopen(tmppath, "w");
if (!status.fp)
return 0;
- memset (status.done, 0, sizeof (status.done));
+ memset(status.done, 0, sizeof(status.done));
- config_file_walk (config_save_cb, config_save_junk_cb, (void *) &status);
+ config_file_walk(config_save_cb, config_save_junk_cb, (void *)&status);
/* Set variables that were missing from the configuration file. */
- for (i = 0; i < sizeof (confmap) / sizeof (confmap[0]); i++)
- {
- if (!status.done[i])
- config_save_cb (confmap[i].key, NULL, &status);
- }
+ for (i = 0; i < sizeof(confmap) / sizeof(confmap[0]); i++) {
+ if (!status.done[i])
+ config_save_cb(confmap[i].key, NULL, &status);
+ }
- file_close (status.fp, __FILE_POS__);
+ file_close(status.fp, __FILE_POS__);
- if (io_file_cp (tmppath, path_conf))
- unlink (tmppath);
+ if (io_file_cp(tmppath, path_conf))
+ unlink(tmppath);
return 1;
}