aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-11-04 15:48:36 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2011-11-14 11:08:14 +0100
commit41c33eeb44d1b1a4b476810757f7b91032950439 (patch)
tree2f38da227b9f554d0eab35fdb7c8cfd18e9d88d2
parent14b6ae79a25106501a30693889b1c03abd56c8c1 (diff)
downloadcalcurse-41c33eeb44d1b1a4b476810757f7b91032950439.tar.gz
calcurse-41c33eeb44d1b1a4b476810757f7b91032950439.zip
Use a global configuration variable
This is one of the few valid use cases for a global variable. No need to make it pseudo-local and pass it from one function to another. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/apoint.c4
-rw-r--r--src/args.c58
-rw-r--r--src/calcurse.c31
-rw-r--r--src/calcurse.h29
-rw-r--r--src/custom.c82
-rw-r--r--src/day.c20
-rw-r--r--src/dmon.c4
-rw-r--r--src/io.c54
-rw-r--r--src/recur.c8
-rw-r--r--src/todo.c4
-rw-r--r--src/vars.c27
11 files changed, 159 insertions, 162 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 1ca6639..59c49ec 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -262,7 +262,7 @@ apoint_add (void)
/* Delete an item from the appointment list. */
void
-apoint_delete (struct conf *conf, unsigned *nb_events, unsigned *nb_apoints)
+apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
{
char *choices = "[y/n] ";
char *del_app_str = _("Do you really want to delete this item ?");
@@ -275,7 +275,7 @@ apoint_delete (struct conf *conf, unsigned *nb_events, unsigned *nb_apoints)
date = calendar_get_slctd_day_sec ();
- if (conf->confirm_delete)
+ if (conf.confirm_delete)
{
status_mesg (del_app_str, choices);
answer = wgetch (win[STA].p);
diff --git a/src/args.c b/src/args.c
index c4e4d5c..186dd13 100644
--- a/src/args.c
+++ b/src/args.c
@@ -330,7 +330,7 @@ next_arg (void)
* Print the date on stdout.
*/
static void
-arg_print_date (long date, struct conf *conf)
+arg_print_date (long date)
{
char date_str[BUFSIZ];
time_t t;
@@ -338,7 +338,7 @@ arg_print_date (long date, struct conf *conf)
t = date;
lt = localtime (&t);
- strftime (date_str, BUFSIZ, conf->output_datefmt, lt);
+ strftime (date_str, BUFSIZ, conf.output_datefmt, lt);
fputs (date_str, stdout);
fputs (":\n", stdout);
}
@@ -351,7 +351,7 @@ arg_print_date (long date, struct conf *conf)
*/
static int
app_arg (int add_line, struct date *day, long date, int print_note,
- struct conf *conf, regex_t *regex)
+ regex_t *regex)
{
llist_item_t *i, *j;
long today;
@@ -384,7 +384,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
}
if (print_date)
{
- arg_print_date (today, conf);
+ arg_print_date (today);
print_date = 0;
}
fputs (" * ", stdout);
@@ -408,7 +408,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
}
if (print_date)
{
- arg_print_date (today, conf);
+ arg_print_date (today);
print_date = 0;
}
fputs (" * ", stdout);
@@ -465,7 +465,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
}
if (print_date)
{
- arg_print_date (today, conf);
+ arg_print_date (today);
print_date = 0;
}
apoint_sec2str (apt, APPT, today, apoint_start_time, apoint_end_time);
@@ -490,7 +490,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
}
if (print_date)
{
- arg_print_date (today, conf);
+ arg_print_date (today);
print_date = 0;
}
apt = apoint_recur_s2apoint_s (ra);
@@ -534,7 +534,7 @@ more_info (void)
*/
static void
display_app (struct tm *t, int numdays, int add_line, int print_note,
- struct conf *conf, regex_t *regex)
+ regex_t *regex)
{
int i, app_found;
struct date day;
@@ -544,7 +544,7 @@ display_app (struct tm *t, int numdays, int add_line, int print_note,
day.dd = t->tm_mday;
day.mm = t->tm_mon + 1;
day.yyyy = t->tm_year + 1900;
- app_found = app_arg (add_line, &day, 0, print_note, conf, regex);
+ app_found = app_arg (add_line, &day, 0, print_note, regex);
if (app_found)
add_line = 1;
t->tm_mday++;
@@ -557,8 +557,7 @@ display_app (struct tm *t, int numdays, int add_line, int print_note,
* days.
*/
static void
-date_arg (char *ddate, int add_line, int print_note, struct conf *conf,
- regex_t *regex)
+date_arg (char *ddate, int add_line, int print_note, regex_t *regex)
{
int i;
struct date day;
@@ -589,14 +588,14 @@ date_arg (char *ddate, int add_line, int print_note, struct conf *conf,
*/
timer = time (NULL);
t = *localtime (&timer);
- display_app (&t, numdays, add_line, print_note, conf, regex);
+ display_app (&t, numdays, add_line, print_note, regex);
}
else
{ /* a date was entered */
- if (parse_date (ddate, conf->input_datefmt, (int *)&day.yyyy,
+ if (parse_date (ddate, conf.input_datefmt, (int *)&day.yyyy,
(int *)&day.mm, (int *)&day.dd, NULL))
{
- app_arg (add_line, &day, 0, print_note, conf, regex);
+ app_arg (add_line, &day, 0, print_note, regex);
}
else
{
@@ -604,7 +603,7 @@ date_arg (char *ddate, int add_line, int print_note, struct conf *conf,
fputs (_("Argument to the '-d' flag is not valid\n"), stderr);
snprintf (outstr, BUFSIZ,
"Possible argument format are: '%s' or 'n'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
fputs (_(outstr), stdout);
more_info ();
}
@@ -621,7 +620,7 @@ date_arg (char *ddate, int add_line, int print_note, struct conf *conf,
*/
static void
date_arg_extended (char *startday, char *range, int add_line, int print_note,
- struct conf *conf, regex_t *regex)
+ regex_t *regex)
{
int i, numdays = 1, error = 0, arg_len = 0;
static struct tm t;
@@ -645,7 +644,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
t = *localtime (&timer);
if (startday != NULL)
{
- if (parse_date (startday, conf->input_datefmt, (int *)&t.tm_year,
+ if (parse_date (startday, conf.input_datefmt, (int *)&t.tm_year,
(int *)&t.tm_mon, (int *)&t.tm_mday, NULL))
{
t.tm_year -= 1900;
@@ -659,7 +658,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
}
if (!error)
{
- display_app (&t, numdays, add_line, print_note, conf, regex);
+ display_app (&t, numdays, add_line, print_note, regex);
}
else
{
@@ -667,7 +666,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
fputs (_("Argument is not valid\n"), stderr);
snprintf (outstr, BUFSIZ,
"Argument format for -s and --startday is: '%s'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
fputs (_(outstr), stdout);
fputs (_("Argument format for -r and --range is: 'n'\n"), stdout);
more_info ();
@@ -680,7 +679,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
* routines to handle those arguments. Also initialize the data paths.
*/
int
-parse_args (int argc, char **argv, struct conf *conf)
+parse_args (int argc, char **argv)
{
int ch, add_line = 0;
int unknown_flag = 0;
@@ -928,10 +927,10 @@ parse_args (int argc, char **argv, struct conf *conf)
io_check_file (path_apts, NULL);
io_check_file (path_todo, NULL);
/* Get default pager in case we need to show a log file. */
- vars_init (conf);
+ vars_init ();
io_load_app ();
io_load_todo ();
- io_import_data (IO_IMPORT_ICAL, conf, ifile);
+ io_import_data (IO_IMPORT_ICAL, ifile);
io_save_apts ();
io_save_todo ();
non_interactive = 1;
@@ -942,7 +941,7 @@ parse_args (int argc, char **argv, struct conf *conf)
io_check_file (path_todo, NULL);
io_load_app ();
io_load_todo ();
- io_export_data (xfmt, conf);
+ io_export_data (xfmt);
non_interactive = 1;
return non_interactive;
}
@@ -965,12 +964,11 @@ parse_args (int argc, char **argv, struct conf *conf)
io_check_file (path_apts, NULL);
io_check_file (path_conf, NULL);
io_load_app ();
- custom_load_conf (conf); /* To get output date format. */
+ custom_load_conf (); /* To get output date format. */
if (dflag)
- date_arg (ddate, add_line, Nflag, conf, preg);
+ date_arg (ddate, add_line, Nflag, preg);
if (rflag || sflag)
- date_arg_extended (startday, range, add_line, Nflag, conf,
- preg);
+ date_arg_extended (startday, range, add_line, Nflag, preg);
non_interactive = 1;
}
else if (aflag)
@@ -979,11 +977,11 @@ parse_args (int argc, char **argv, struct conf *conf)
io_check_file (path_apts, NULL);
io_check_file (path_conf, NULL);
- vars_init (conf);
- custom_load_conf (conf); /* To get output date format. */
+ vars_init ();
+ custom_load_conf (); /* To get output date format. */
io_load_app ();
day.dd = day.mm = day.yyyy = 0;
- app_arg (add_line, &day, 0, Nflag, conf, preg);
+ app_arg (add_line, &day, 0, Nflag, preg);
non_interactive = 1;
}
}
diff --git a/src/calcurse.c b/src/calcurse.c
index cde2005..35a1fa5 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -64,7 +64,6 @@ do_storage (int day_changed)
int
main (int argc, char **argv)
{
- struct conf conf;
struct day_items_nb inday;
int non_interactive;
int no_data_file = 1;
@@ -94,7 +93,7 @@ main (int argc, char **argv)
* Begin by parsing and handling command line arguments.
* The data path is also initialized here.
*/
- non_interactive = parse_args (argc, argv, &conf);
+ non_interactive = parse_args (argc, argv);
if (non_interactive)
exit_calcurse (EXIT_SUCCESS);
else
@@ -148,7 +147,7 @@ main (int argc, char **argv)
background = COLOR_BLACK;
}
- vars_init (&conf);
+ vars_init ();
wins_init ();
wins_slctd_init ();
notify_init_bar ();
@@ -159,7 +158,7 @@ main (int argc, char **argv)
* configuration (the display is then updated), and then
* the todo list, appointments and events.
*/
- custom_load_conf (&conf);
+ custom_load_conf ();
wins_erase_status_bar ();
io_load_keys (conf.pager);
io_load_todo ();
@@ -174,7 +173,7 @@ main (int argc, char **argv)
wins_update (FLAG_ALL);
calendar_start_date_thread ();
if (conf.periodic_save > 0)
- io_start_psave_thread (&conf);
+ io_start_psave_thread ();
/* User input */
for (;;)
@@ -266,7 +265,7 @@ main (int argc, char **argv)
break;
case 'G':
case 'g':
- custom_general_config (&conf);
+ custom_general_config ();
break;
case 'N':
case 'n':
@@ -327,7 +326,7 @@ main (int argc, char **argv)
case KEY_EDIT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
- day_edit_item (&conf);
+ day_edit_item ();
inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -341,13 +340,13 @@ main (int argc, char **argv)
case KEY_DEL_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
{
- apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
+ apoint_delete (&inday.nb_events, &inday.nb_apoints);
inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
}
else if (wins_slctd () == TOD && todo_hilt () != 0)
{
- todo_delete (&conf);
+ todo_delete ();
wins_update (FLAG_TOD | FLAG_STA);
}
break;
@@ -373,7 +372,7 @@ main (int argc, char **argv)
case KEY_REPEAT_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
- recur_repeat_item (&conf);
+ recur_repeat_item ();
inday = do_storage (0);
wins_update (FLAG_CAL | FLAG_APP | FLAG_STA);
break;
@@ -394,7 +393,7 @@ main (int argc, char **argv)
case KEY_PIPE_ITEM:
if (wins_slctd () == APP && apoint_hilt () != 0)
- day_pipe_item (&conf);
+ day_pipe_item ();
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_pipe_item ();
wins_update (FLAG_ALL);
@@ -439,13 +438,13 @@ main (int argc, char **argv)
break;
case KEY_GENERIC_SAVE:
- io_save_cal (&conf, IO_SAVE_DISPLAY_BAR);
+ io_save_cal (IO_SAVE_DISPLAY_BAR);
wins_update (FLAG_STA);
break;
case KEY_GENERIC_IMPORT:
wins_erase_status_bar ();
- io_import_data (IO_IMPORT_ICAL, &conf, NULL);
+ io_import_data (IO_IMPORT_ICAL, NULL);
inday = do_storage (0);
wins_update (FLAG_ALL);
break;
@@ -459,11 +458,11 @@ main (int argc, char **argv)
{
case 'I':
case 'i':
- io_export_data (IO_EXPORT_ICAL, &conf);
+ io_export_data (IO_EXPORT_ICAL);
break;
case 'P':
case 'p':
- io_export_data (IO_EXPORT_PCAL, &conf);
+ io_export_data (IO_EXPORT_PCAL);
break;
}
wins_reset ();
@@ -585,7 +584,7 @@ main (int argc, char **argv)
case KEY_GENERIC_QUIT:
if (conf.auto_save)
- io_save_cal (&conf, IO_SAVE_DISPLAY_BAR);
+ io_save_cal (IO_SAVE_DISPLAY_BAR);
if (conf.auto_gc)
note_gc ();
diff --git a/src/calcurse.h b/src/calcurse.h
index adb2c1e..f7ad0dd 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -584,7 +584,7 @@ void apoint_hilt_increase (int);
int apoint_hilt (void);
struct apoint *apoint_new (char *, char *, long, long, char);
void apoint_add (void);
-void apoint_delete (struct conf *, unsigned *, unsigned *);
+void apoint_delete (unsigned *, unsigned *);
int apoint_cut (unsigned *, unsigned *);
void apoint_paste (unsigned *, unsigned *, int);
unsigned apoint_inday (struct apoint *, long);
@@ -602,7 +602,7 @@ void apoint_update_panel (int);
void apoint_paste_item (void);
/* args.c */
-int parse_args (int, char **, struct conf *);
+int parse_args (int, char **);
/* calendar.c */
void calendar_view_next (void);
@@ -631,7 +631,7 @@ char *calendar_get_pom (time_t);
void custom_init_attr (void);
void custom_apply_attr (WINDOW *, int);
void custom_remove_attr (WINDOW *, int);
-void custom_load_conf (struct conf *);
+void custom_load_conf (void);
void custom_config_bar (void);
void custom_layout_config (void);
void custom_sidebar_config (void);
@@ -639,7 +639,7 @@ void custom_color_config (void);
void custom_color_theme_name (char *);
void custom_confwin_init (struct window *, char *);
void custom_set_swsiz (struct scrollwin *);
-void custom_general_config (struct conf *);
+void custom_general_config (void);
void custom_keys_config (void);
/* day.c */
@@ -650,7 +650,7 @@ void day_write_pad (long, int, int, int);
void day_popup_item (void);
int day_check_if_item (struct date);
unsigned day_chk_busy_slices (struct date, int, int *);
-void day_edit_item (struct conf *);
+void day_edit_item (void);
int day_erase_item (long, int, enum eraseflg);
int day_cut_item (long, int);
int day_paste_item (long, int);
@@ -658,7 +658,7 @@ struct day_item *day_get_item (int);
int day_item_nb (long, int, int);
void day_edit_note (char *);
void day_view_note (char *);
-void day_pipe_item (struct conf *);
+void day_pipe_item (void);
/* dmon.c */
void dmon_start (int);
@@ -689,11 +689,11 @@ int updatestring (WINDOW *, char **, int, int);
unsigned io_fprintln (const char *, const char *, ...);
void io_init (char *, char *);
void io_extract_data (char *, const char *, int);
-unsigned io_save_conf (struct conf *);
+unsigned io_save_conf (void);
unsigned io_save_apts (void);
unsigned io_save_todo (void);
unsigned io_save_keys (void);
-void io_save_cal (struct conf *, enum save_display);
+void io_save_cal (enum save_display);
void io_load_app (void);
void io_load_todo (void);
void io_load_keys (char *);
@@ -702,14 +702,14 @@ unsigned io_file_exist (char *);
void io_check_file (char *, int *);
int io_check_data_files (void);
void io_startup_screen (unsigned, int);
-void io_export_data (enum export_type, struct conf *);
+void io_export_data (enum export_type);
void io_export_bar (void);
-void io_import_data (enum import_type, struct conf *, char *);
+void io_import_data (enum import_type, char *);
struct io_file *io_log_init (void);
void io_log_print (struct io_file *, int, char *);
void io_log_display (struct io_file *, char *, char *);
void io_log_free (struct io_file *);
-void io_start_psave_thread (struct conf *);
+void io_start_psave_thread (void);
void io_stop_psave_thread (void);
void io_set_lock (void);
unsigned io_dump_pid (char *);
@@ -838,7 +838,7 @@ void recur_event_erase (long, unsigned, unsigned,
enum eraseflg);
void recur_apoint_erase (long, unsigned, unsigned,
enum eraseflg);
-void recur_repeat_item (struct conf *);
+void recur_repeat_item (void);
void recur_exc_scan (llist_t *, FILE *);
struct notify_app *recur_apoint_check_next (struct notify_app *, long, long);
struct recur_apoint *recur_get_apoint (long, int);
@@ -868,7 +868,7 @@ void todo_new_item (void);
struct todo *todo_add (char *, int, char *);
void todo_write (struct todo *, FILE *);
void todo_flag (void);
-void todo_delete (struct conf *);
+void todo_delete (void);
void todo_chg_priority (int);
void todo_edit_item (void);
void todo_update_panel (int);
@@ -941,10 +941,11 @@ extern char path_notes[BUFSIZ];
extern char path_cpid[BUFSIZ];
extern char path_dpid[BUFSIZ];
extern char path_dmon_log[BUFSIZ];
+extern struct conf conf;
extern struct pad apad;
extern struct nbar nbar;
extern struct dmon_conf dmon;
-void vars_init (struct conf *);
+void vars_init (void);
/* wins.c */
extern struct window win[NBWINS];
diff --git a/src/custom.c b/src/custom.c
index 5700640..38ad8bc 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -284,32 +284,32 @@ custom_remove_attr (WINDOW *win, int attr_num)
/* Set a configuration variable. */
static int
-custom_set_conf (struct conf *conf, enum conf_var var, char *val)
+custom_set_conf (enum conf_var var, char *val)
{
unsigned tmp;
switch (var)
{
case CUSTOM_CONF_AUTOSAVE:
- return conf_parse_bool (&conf->auto_save, val);
+ return conf_parse_bool (&conf.auto_save, val);
break;
case CUSTOM_CONF_AUTOGC:
- return conf_parse_bool (&conf->auto_gc, val);
+ return conf_parse_bool (&conf.auto_gc, val);
break;
case CUSTOM_CONF_PERIODICSAVE:
- return conf_parse_unsigned (&conf->periodic_save, val);
+ return conf_parse_unsigned (&conf.periodic_save, val);
break;
case CUSTOM_CONF_CONFIRMQUIT:
- return conf_parse_bool (&conf->confirm_quit, val);
+ return conf_parse_bool (&conf.confirm_quit, val);
break;
case CUSTOM_CONF_CONFIRMDELETE:
- return conf_parse_bool (&conf->confirm_delete, val);
+ return conf_parse_bool (&conf.confirm_delete, val);
break;
case CUSTOM_CONF_SKIPSYSTEMDIALOGS:
- return conf_parse_bool (&conf->skip_system_dialogs, val);
+ return conf_parse_bool (&conf.skip_system_dialogs, val);
break;
case CUSTOM_CONF_SKIPPROGRESSBAR:
- return conf_parse_bool (&conf->skip_progress_bar, val);
+ return conf_parse_bool (&conf.skip_progress_bar, val);
break;
case CUSTOM_CONF_CALENDAR_DEFAULTVIEW:
calendar_set_view (atoi (val));
@@ -350,12 +350,12 @@ custom_set_conf (struct conf *conf, enum conf_var var, char *val)
break;
case CUSTOM_CONF_OUTPUTDATEFMT:
if (val[0] != '\0')
- strncpy (conf->output_datefmt, val, strlen (val) + 1);
+ strncpy (conf.output_datefmt, val, strlen (val) + 1);
break;
case CUSTOM_CONF_INPUTDATEFMT:
- return conf_parse_int (&conf->input_datefmt, val);
- if (conf->input_datefmt <= 0 || conf->input_datefmt >= DATE_FORMATS)
- conf->input_datefmt = 1;
+ return conf_parse_int (&conf.input_datefmt, val);
+ if (conf.input_datefmt <= 0 || conf.input_datefmt >= DATE_FORMATS)
+ conf.input_datefmt = 1;
break;
case CUSTOM_CONF_DMON_ENABLE:
return conf_parse_bool (&dmon.enable, val);
@@ -373,7 +373,7 @@ custom_set_conf (struct conf *conf, enum conf_var var, char *val)
/* Load the user configuration. */
void
-custom_load_conf (struct conf *conf)
+custom_load_conf (void)
{
FILE *data_file;
char *mesg_line1 = _("Failed to open config file");
@@ -436,7 +436,7 @@ custom_load_conf (struct conf *conf)
val = e_conf;
}
- if (!val || !custom_set_conf (conf, var, val))
+ if (!val || !custom_set_conf (var, val))
{
EXIT (_("wrong configuration variable format for \"%s\""), name);
/* NOTREACHED */
@@ -1017,7 +1017,7 @@ custom_color_theme_name (char *theme_name)
/* Prints the general options. */
static int
-print_general_options (WINDOW *win, struct conf *conf)
+print_general_options (WINDOW *win)
{
enum {
AUTO_SAVE,
@@ -1050,13 +1050,13 @@ print_general_options (WINDOW *win, struct conf *conf)
y = 0;
mvwprintw (win, y, XPOS, "[1] %s ", opt[AUTO_SAVE]);
- print_bool_option_incolor (win, conf->auto_save, y,
+ print_bool_option_incolor (win, conf.auto_save, y,
XPOS + 4 + strlen (opt[AUTO_SAVE]));
mvwprintw (win, y + 1, XPOS,
_("(if set to YES, automatic save is done when quitting)"));
y += YOFF;
mvwprintw (win, y, XPOS, "[2] %s ", opt[AUTO_GC]);
- print_bool_option_incolor (win, conf->auto_gc, y,
+ print_bool_option_incolor (win, conf.auto_gc, y,
XPOS + 4 + strlen (opt[AUTO_GC]));
mvwprintw (win, y + 1, XPOS,
_("(run the garbage collector when quitting)"));
@@ -1064,34 +1064,34 @@ print_general_options (WINDOW *win, struct conf *conf)
mvwprintw (win, y, XPOS, "[3] %s ", opt[PERIODIC_SAVE]);
custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, y, XPOS + 4 + strlen (opt[PERIODIC_SAVE]), "%d",
- conf->periodic_save);
+ conf.periodic_save);
custom_remove_attr (win, ATTR_HIGHEST);
mvwprintw (win, y + 1, XPOS,
_("(if not null, automatically save data every 'periodic_save' "
"minutes)"));
y += YOFF;
mvwprintw (win, y, XPOS, "[4] %s ", opt[CONFIRM_QUIT]);
- print_bool_option_incolor (win, conf->confirm_quit, y,
+ print_bool_option_incolor (win, conf.confirm_quit, y,
XPOS + 4 + strlen (opt[CONFIRM_QUIT]));
mvwprintw (win, y + 1, XPOS,
_("(if set to YES, confirmation is required before quitting)"));
y += YOFF;
mvwprintw (win, y, XPOS, "[5] %s ", opt[CONFIRM_DELETE]);
- print_bool_option_incolor (win, conf->confirm_delete, y,
+ print_bool_option_incolor (win, conf.confirm_delete, y,
XPOS + 4 + strlen (opt[CONFIRM_DELETE]));
mvwprintw (win, y + 1, XPOS,
_("(if set to YES, confirmation is required "
"before deleting an event)"));
y += YOFF;
mvwprintw (win, y, XPOS, "[6] %s ", opt[SKIP_SYSTEM_DIAGS]);
- print_bool_option_incolor (win, conf->skip_system_dialogs, y,
+ print_bool_option_incolor (win, conf.skip_system_dialogs, y,
XPOS + 4 + strlen (opt[SKIP_SYSTEM_DIAGS]));
mvwprintw (win, y + 1, XPOS,
_("(if set to YES, messages about loaded "
"and saved data will not be displayed)"));
y += YOFF;
mvwprintw (win, y, XPOS, "[7] %s ", opt[SKIP_PROGRESS_BAR]);
- print_bool_option_incolor (win, conf->skip_progress_bar, y,
+ print_bool_option_incolor (win, conf.skip_progress_bar, y,
XPOS + 4 + strlen (opt[SKIP_PROGRESS_BAR]));
mvwprintw (win, y + 1, XPOS,
_("(if set to YES, progress bar will not be displayed "
@@ -1107,7 +1107,7 @@ print_general_options (WINDOW *win, struct conf *conf)
mvwprintw (win, y, XPOS, "[9] %s ", opt[OUTPUT_DATE_FMT]);
custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, y, XPOS + 4 + strlen (opt[OUTPUT_DATE_FMT]), "%s",
- conf->output_datefmt);
+ conf.output_datefmt);
custom_remove_attr (win, ATTR_HIGHEST);
mvwprintw (win, y + 1, XPOS,
_("(Format of the date to be displayed in non-interactive mode)"));
@@ -1115,7 +1115,7 @@ print_general_options (WINDOW *win, struct conf *conf)
mvwprintw (win, y, XPOS, "[0] %s ", opt[INPUT_DATE_FMT]);
custom_apply_attr (win, ATTR_HIGHEST);
mvwprintw (win, y, XPOS + 4 + strlen (opt[INPUT_DATE_FMT]), "%d",
- conf->input_datefmt);
+ conf.input_datefmt);
custom_remove_attr (win, ATTR_HIGHEST);
mvwprintw (win, y + 1, XPOS, _("(Format to be used when entering a date: "));
mvwprintw (win, y + 2, XPOS,
@@ -1140,7 +1140,7 @@ custom_set_swsiz (struct scrollwin *sw)
/* General configuration. */
void
-custom_general_config (struct conf *conf)
+custom_general_config (void)
{
struct scrollwin cwin;
char *number_str =
@@ -1163,7 +1163,7 @@ custom_general_config (struct conf *conf)
wins_scrollwin_init (&cwin);
wins_show (cwin.win.p, cwin.label);
status_mesg (number_str, keys);
- cwin.total_lines = print_general_options (cwin.pad.p, conf);
+ cwin.total_lines = print_general_options (cwin.pad.p);
wins_scrollwin_display (&cwin);
buf = mem_malloc (BUFSIZ);
@@ -1180,10 +1180,10 @@ custom_general_config (struct conf *conf)
wins_scrollwin_up (&cwin, 1);
break;
case '1':
- conf->auto_save = !conf->auto_save;
+ conf.auto_save = !conf.auto_save;
break;
case '2':
- conf->auto_gc = !conf->auto_gc;
+ conf.auto_gc = !conf.auto_gc;
break;
case '3':
status_mesg (periodic_save_str, "");
@@ -1191,36 +1191,36 @@ custom_general_config (struct conf *conf)
{
int val = atoi (buf);
if (val >= 0)
- conf->periodic_save = val;
- if (conf->periodic_save > 0)
- io_start_psave_thread (conf);
- else if (conf->periodic_save == 0)
+ conf.periodic_save = val;
+ if (conf.periodic_save > 0)
+ io_start_psave_thread ();
+ else if (conf.periodic_save == 0)
io_stop_psave_thread ();
}
status_mesg (number_str, keys);
break;
case '4':
- conf->confirm_quit = !conf->confirm_quit;
+ conf.confirm_quit = !conf.confirm_quit;
break;
case '5':
- conf->confirm_delete = !conf->confirm_delete;
+ conf.confirm_delete = !conf.confirm_delete;
break;
case '6':
- conf->skip_system_dialogs = !conf->skip_system_dialogs;
+ conf.skip_system_dialogs = !conf.skip_system_dialogs;
break;
case '7':
- conf->skip_progress_bar = !conf->skip_progress_bar;
+ conf.skip_progress_bar = !conf.skip_progress_bar;
break;
case '8':
calendar_change_first_day_of_week ();
break;
case '9':
status_mesg (output_datefmt_str, "");
- strncpy (buf, conf->output_datefmt,
- strlen (conf->output_datefmt) + 1);
+ strncpy (buf, conf.output_datefmt,
+ strlen (conf.output_datefmt) + 1);
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
{
- strncpy (conf->output_datefmt, buf, strlen (buf) + 1);
+ strncpy (conf.output_datefmt, buf, strlen (buf) + 1);
}
status_mesg (number_str, keys);
break;
@@ -1230,7 +1230,7 @@ custom_general_config (struct conf *conf)
{
int val = atoi (buf);
if (val > 0 && val <= DATE_FORMATS)
- conf->input_datefmt = val;
+ conf.input_datefmt = val;
}
status_mesg (number_str, keys);
break;
@@ -1257,7 +1257,7 @@ custom_general_config (struct conf *conf)
}
status_mesg (number_str, keys);
- cwin.total_lines = print_general_options (cwin.pad.p, conf);
+ cwin.total_lines = print_general_options (cwin.pad.p);
wins_scrollwin_display (&cwin);
}
mem_free (buf);
diff --git a/src/day.c b/src/day.c
index 2464653..73c8ada 100644
--- a/src/day.c
+++ b/src/day.c
@@ -688,7 +688,7 @@ update_desc (char **desc)
}
static void
-update_rept (struct rpt **rpt, const long start, struct conf *conf)
+update_rept (struct rpt **rpt, const long start)
{
const int SINGLECHAR = 2;
int ch, newfreq, date_entered;
@@ -749,10 +749,10 @@ update_rept (struct rpt **rpt, const long start, struct conf *conf)
do
{
snprintf (outstr, BUFSIZ, "Enter the new ending date: [%s] or '0'",
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
status_mesg (_(outstr), "");
timstr =
- date_sec2date_str ((*rpt)->until, DATEFMT (conf->input_datefmt));
+ date_sec2date_str ((*rpt)->until, DATEFMT (conf.input_datefmt));
if (updatestring (win[STA].p, &timstr, 0, 1) != GETSTRING_VALID)
{
mem_free (timstr);
@@ -770,8 +770,8 @@ update_rept (struct rpt **rpt, const long start, struct conf *conf)
struct date new_date;
int newmonth, newday, newyear;
- if (parse_date (timstr, conf->input_datefmt,
- &newyear, &newmonth, &newday, calendar_get_slctd_day ()))
+ if (parse_date (timstr, conf.input_datefmt, &newyear, &newmonth,
+ &newday, calendar_get_slctd_day ()))
{
t = start;
lt = localtime (&t);
@@ -791,7 +791,7 @@ update_rept (struct rpt **rpt, const long start, struct conf *conf)
else
{
snprintf (outstr, BUFSIZ, msg_fmts,
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
status_mesg (msg_wrong_date, _(outstr));
wgetch (win[STA].p);
date_entered = 0;
@@ -808,7 +808,7 @@ update_rept (struct rpt **rpt, const long start, struct conf *conf)
/* Edit an already existing item. */
void
-day_edit_item (struct conf *conf)
+day_edit_item (void)
{
#define STRT '1'
#define END '2'
@@ -842,7 +842,7 @@ day_edit_item (struct conf *conf)
update_desc (&re->mesg);
break;
case '2':
- update_rept (&re->rpt, re->day, conf);
+ update_rept (&re->rpt, re->day);
break;
default:
return;
@@ -875,7 +875,7 @@ day_edit_item (struct conf *conf)
break;
case REPT:
need_check_notify = 1;
- update_rept (&ra->rpt, ra->start, conf);
+ update_rept (&ra->rpt, ra->start);
break;
case KEY_GENERIC_CANCEL:
return;
@@ -1134,7 +1134,7 @@ day_view_note (char *pager)
/* Pipe an appointment or event to an external program. */
void
-day_pipe_item (struct conf *conf)
+day_pipe_item (void)
{
char cmd[BUFSIZ] = "";
int pout;
diff --git a/src/dmon.c b/src/dmon.c
index be1fda7..9dc893e 100644
--- a/src/dmon.c
+++ b/src/dmon.c
@@ -154,8 +154,6 @@ daemonize (int status)
void
dmon_start (int parent_exit_status)
{
- struct conf conf;
-
if (!daemonize (parent_exit_status))
DMON_ABRT (_("Cannot daemonize, aborting\n"));
@@ -165,7 +163,7 @@ dmon_start (int parent_exit_status)
if (!io_file_exist (path_conf))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
path_conf, strerror (errno));
- custom_load_conf (&conf);
+ custom_load_conf ();
if (!io_file_exist (path_apts))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
diff --git a/src/io.c b/src/io.c
index 7b54632..2bd0ce4 100644
--- a/src/io.c
+++ b/src/io.c
@@ -834,7 +834,7 @@ static pthread_mutex_t io_save_mutex = PTHREAD_MUTEX_INITIALIZER;
/* Save the user configuration. */
unsigned
-io_save_conf (struct conf *conf)
+io_save_conf (void)
{
char *config_txt =
"#\n"
@@ -860,37 +860,37 @@ io_save_conf (struct conf *conf)
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");
+ 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");
+ 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);
+ 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");
+ 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");
+ 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");
+ 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");
+ 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);
@@ -946,13 +946,13 @@ io_save_conf (struct conf *conf)
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);
+ 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);
+ fprintf (fp, "%d\n", conf.input_datefmt);
if (ui_mode == UI_CURSES)
pthread_mutex_unlock (&nbar.mutex);
@@ -1046,7 +1046,7 @@ io_save_keys (void)
/* Save the calendar data */
void
-io_save_cal (struct conf *conf, enum save_display display)
+io_save_cal (enum save_display display)
{
char *access_pb = _("Problems accessing data file ...");
char *save_success = _("The data files were successfully saved");
@@ -1057,14 +1057,14 @@ io_save_cal (struct conf *conf, enum save_display display)
show_bar = 0;
if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_BAR
- && !conf->skip_progress_bar)
+ && !conf.skip_progress_bar)
show_bar = 1;
else if (ui_mode == UI_CURSES && display == IO_SAVE_DISPLAY_MARK)
display_mark ();
if (show_bar)
progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF);
- if (!io_save_conf (conf))
+ if (!io_save_conf ())
ERROR_MSG ("%s", access_pb);
if (show_bar)
@@ -1083,7 +1083,7 @@ io_save_cal (struct conf *conf, enum save_display display)
ERROR_MSG ("%s", access_pb);
/* Print a message telling data were saved */
- if (ui_mode == UI_CURSES && !conf->skip_system_dialogs
+ if (ui_mode == UI_CURSES && !conf.skip_system_dialogs
&& display != IO_SAVE_DISPLAY_MARK)
{
status_mesg (save_success, enter);
@@ -1620,7 +1620,7 @@ io_startup_screen (unsigned skip_dialogs, int no_data_file)
/* Export calcurse data. */
void
-io_export_data (enum export_type type, struct conf *conf)
+io_export_data (enum export_type type)
{
FILE *stream;
char *success = _("The data were successfully exported");
@@ -1648,17 +1648,17 @@ io_export_data (enum export_type type, struct conf *conf)
cb_export_header[type] (stream);
- if (!conf->skip_progress_bar && ui_mode == UI_CURSES)
+ if (!conf.skip_progress_bar && ui_mode == UI_CURSES)
progress_bar (PROGRESS_BAR_EXPORT, PROGRESS_BAR_EXPORT_EVENTS);
cb_export_recur_events[type] (stream);
cb_export_events[type] (stream);
- if (!conf->skip_progress_bar && ui_mode == UI_CURSES)
+ if (!conf.skip_progress_bar && ui_mode == UI_CURSES)
progress_bar (PROGRESS_BAR_EXPORT, PROGRESS_BAR_EXPORT_APOINTS);
cb_export_recur_apoints[type] (stream);
cb_export_apoints[type] (stream);
- if (!conf->skip_progress_bar && ui_mode == UI_CURSES)
+ if (!conf.skip_progress_bar && ui_mode == UI_CURSES)
progress_bar (PROGRESS_BAR_EXPORT, PROGRESS_BAR_EXPORT_TODO);
cb_export_todo[type] (stream);
@@ -1667,7 +1667,7 @@ io_export_data (enum export_type type, struct conf *conf)
if (stream != stdout)
file_close (stream, __FILE_POS__);
- if (!conf->skip_system_dialogs && ui_mode == UI_CURSES)
+ if (!conf.skip_system_dialogs && ui_mode == UI_CURSES)
{
status_mesg (success, enter);
wgetch (win[STA].p);
@@ -2692,7 +2692,7 @@ get_import_stream (enum export_type type)
* and is cleared at the end.
*/
void
-io_import_data (enum import_type type, struct conf *conf, char *stream_name)
+io_import_data (enum import_type type, char *stream_name)
{
const struct string vevent = STRING_BUILD ("BEGIN:VEVENT");
const struct string vtodo = STRING_BUILD ("BEGIN:VTODO");
@@ -2771,7 +2771,7 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name)
/* Update the number of todo items. */
todo_set_nb (todo_nb () + stats.todos);
- if (ui_mode == UI_CURSES && !conf->skip_system_dialogs)
+ if (ui_mode == UI_CURSES && !conf.skip_system_dialogs)
{
char read[BUFSIZ], stat[BUFSIZ];
@@ -2797,7 +2797,7 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name)
{
char *view_log = _("Some items could not be imported, see log file ?");
- io_log_display (log, view_log, conf->pager);
+ io_log_display (log, view_log, conf.pager);
}
io_log_free (log);
}
@@ -2888,25 +2888,23 @@ static pthread_t io_t_psave;
static void *
io_psave_thread (void *arg)
{
- struct conf *config;
int delay;
- config = (struct conf *)arg;
- delay = config->periodic_save;
+ delay = conf.periodic_save;
EXIT_IF (delay < 0, _("Invalid delay"));
for (;;)
{
sleep (delay * MININSEC);
- io_save_cal (config, IO_SAVE_DISPLAY_MARK);
+ io_save_cal (IO_SAVE_DISPLAY_MARK);
}
}
/* Launch the thread which handles periodic saves. */
void
-io_start_psave_thread (struct conf *conf)
+io_start_psave_thread (void)
{
- pthread_create (&io_t_psave, NULL, io_psave_thread, (void *)conf);
+ pthread_create (&io_t_psave, NULL, io_psave_thread, NULL);
}
/* Stop periodic data saves. */
diff --git a/src/recur.c b/src/recur.c
index f8f04e0..b373b11 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -860,7 +860,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
* and then delete the selected item to recreate it as a recurrent one
*/
void
-recur_repeat_item (struct conf *conf)
+recur_repeat_item (void)
{
struct tm *lt;
time_t t;
@@ -935,7 +935,7 @@ recur_repeat_item (struct conf *conf)
while (!date_entered)
{
snprintf (outstr, BUFSIZ, mesg_until_1,
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
status_mesg (_(outstr), "");
if (getstring (win[STA].p, user_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
{
@@ -946,7 +946,7 @@ recur_repeat_item (struct conf *conf)
}
else
{
- if (parse_date (user_input, conf->input_datefmt,
+ if (parse_date (user_input, conf.input_datefmt,
&year, &month, &day, calendar_get_slctd_day ()))
{
t = p->start;
@@ -969,7 +969,7 @@ recur_repeat_item (struct conf *conf)
else
{
snprintf (outstr, BUFSIZ, mesg_wrong_2,
- DATEFMT_DESC (conf->input_datefmt));
+ DATEFMT_DESC (conf.input_datefmt));
status_mesg (mesg_wrong_1, _(outstr));
wgetch (win[STA].p);
date_entered = 0;
diff --git a/src/todo.c b/src/todo.c
index b89d595..4418710 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -240,7 +240,7 @@ todo_flag (void)
/* Delete an item from the ToDo list. */
void
-todo_delete (struct conf *conf)
+todo_delete (void)
{
char *choices = "[y/n] ";
char *del_todo_str = _("Do you really want to delete this task ?");
@@ -251,7 +251,7 @@ todo_delete (struct conf *conf)
unsigned go_for_todo_del = 0;
int answer, has_note;
- if (conf->confirm_delete)
+ if (conf.confirm_delete)
{
status_mesg (del_todo_str, choices);
answer = wgetch (win[STA].p);
diff --git a/src/vars.c b/src/vars.c
index 5155683..10c87a0 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -102,6 +102,9 @@ char path_cpid[] = "";
char path_dpid[] = "";
char path_dmon_log[] = "";
+/* Variable to store global configuration. */
+struct conf conf;
+
/* Variable to handle pads. */
struct pad apad;
@@ -115,20 +118,20 @@ struct dmon_conf dmon;
* Variables init
*/
void
-vars_init (struct conf *conf)
+vars_init (void)
{
char *ed, *pg;
/* Variables for user configuration */
- conf->confirm_quit = 1;
- conf->confirm_delete = 1;
- conf->auto_save = 1;
- conf->auto_gc = 0;
- conf->periodic_save = 0;
- conf->skip_system_dialogs = 0;
- conf->skip_progress_bar = 0;
- strncpy (conf->output_datefmt, "%D", 3);
- conf->input_datefmt = 1;
+ conf.confirm_quit = 1;
+ conf.confirm_delete = 1;
+ conf.auto_save = 1;
+ conf.auto_gc = 0;
+ conf.periodic_save = 0;
+ conf.skip_system_dialogs = 0;
+ conf.skip_progress_bar = 0;
+ strncpy (conf.output_datefmt, "%D", 3);
+ conf.input_datefmt = 1;
/* Default external editor and pager */
ed = getenv ("VISUAL");
@@ -136,12 +139,12 @@ vars_init (struct conf *conf)
ed = getenv ("EDITOR");
if (ed == NULL || ed[0] == '\0')
ed = DEFAULT_EDITOR;
- conf->editor = ed;
+ conf.editor = ed;
pg = getenv ("PAGER");
if (pg == NULL || pg[0] == '\0')
pg = DEFAULT_PAGER;
- conf->pager = pg;
+ conf.pager = pg;
wins_set_layout (1);