summaryrefslogtreecommitdiffstats
path: root/src/args.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.c')
-rw-r--r--src/args.c107
1 files changed, 61 insertions, 46 deletions
diff --git a/src/args.c b/src/args.c
index a3a22fe..c4e4d5c 100644
--- a/src/args.c
+++ b/src/args.c
@@ -51,8 +51,8 @@
static void
usage ()
{
- char *arg_usage =
- _("Usage: calcurse [-h|-v] [-N] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
+ const char *arg_usage =
+ _("Usage: calcurse [-g|-h|-v] [-N] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n"
" [-c<file> | -D<dir>] [-S<regex>] [--status]\n");
fputs (arg_usage, stdout);
@@ -61,7 +61,7 @@ usage ()
static void
usage_try ()
{
- char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
+ const char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
fputs (arg_usage_try, stdout);
}
@@ -71,14 +71,11 @@ usage_try ()
static void
version_arg ()
{
- char vtitle[BUFSIZ];
- char *vtext =
+ const char *vtext =
_("\nCopyright (c) 2004-2011 calcurse Development Team.\n"
"This is free software; see the source for copying conditions.\n");
- (void)snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"),
- VERSION);
- fputs (vtitle, stdout);
+ fprintf (stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
fputs (vtext, stdout);
}
@@ -88,8 +85,7 @@ version_arg ()
static void
help_arg ()
{
- char htitle[BUFSIZ];
- char *htext =
+ const char *htext =
_("\nMiscellaneous:\n"
" -h, --help\n"
" print this help and exit.\n"
@@ -110,6 +106,8 @@ help_arg ()
" print events and appointments for <date> or <num> upcoming days and"
"\n\texit. To specify both a starting date and a range, use the\n"
"\t'--startday' and the '--range' option.\n"
+ "\n -g, --gc\n"
+ " run the garbage collector for note files and exit. \n"
"\n -i <file>, --import <file>\n"
" import the icalendar data contained in <file>. \n"
"\n -n, --next\n"
@@ -146,9 +144,7 @@ help_arg ()
"or read the manpage.\n"
"Mail bug reports and suggestions to <misc@calcurse.org>.\n");
- (void)snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"),
- VERSION);
- fputs (htitle, stdout);
+ fprintf (stdout, _("Calcurse %s - text-based organizer\n"), VERSION);
usage ();
fputs (htext, stdout);
}
@@ -183,7 +179,7 @@ status_arg (void)
else if (dpid)
fprintf (stdout, _("calcurse is running in background (pid %d)\n"), dpid);
else
- fprintf (stdout, _("calcurse is not running\n"));
+ puts (_("calcurse is not running\n"));
}
/*
@@ -213,7 +209,7 @@ print_notefile (FILE *out, char *filename, int nbtab)
else
linestarter[0] = '\0';
- (void)snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
+ snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
notefile = fopen (path_to_notefile, "r");
if (notefile)
{
@@ -323,8 +319,8 @@ next_arg (void)
hours_left = (time_left / HOURINSEC);
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
fputs (_("next appointment:\n"), stdout);
- (void)snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
- next_app.txt);
+ snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
+ next_app.txt);
fputs (mesg, stdout);
mem_free (next_app.txt);
}
@@ -398,7 +394,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
print_notefile (stdout, re->note, 2);
}
- LLIST_FIND_FOREACH (&eventlist, today, event_inday, i)
+ LLIST_FIND_FOREACH_CONT (&eventlist, today, event_inday, i)
{
struct event *ev = LLIST_TS_GET_DATA (i);
if (regex && regexec (regex, ev->mesg, 0, 0, 0) != 0)
@@ -436,6 +432,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
{
struct apoint *apt = LLIST_TS_GET_DATA (i);
struct recur_apoint *ra = LLIST_TS_GET_DATA (j);
+ unsigned occurrence;
while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0)
{
@@ -451,7 +448,8 @@ app_arg (int add_line, struct date *day, long date, int print_note,
if (apt && ra)
{
- if (apt->start <= recur_apoint_inday (ra, today))
+ if (recur_apoint_find_occurrence (ra, today, &occurrence) &&
+ apt->start <= occurrence)
ra = NULL;
else
apt = NULL;
@@ -517,7 +515,7 @@ app_arg (int add_line, struct date *day, long date, int print_note,
LLIST_TS_UNLOCK (&recur_alist_p);
LLIST_TS_UNLOCK (&alist_p);
- return (app_found);
+ return app_found;
}
static void
@@ -550,7 +548,7 @@ display_app (struct tm *t, int numdays, int add_line, int print_note,
if (app_found)
add_line = 1;
t->tm_mday++;
- (void)mktime (t);
+ mktime (t);
}
}
@@ -598,15 +596,15 @@ date_arg (char *ddate, int add_line, int print_note, struct conf *conf,
if (parse_date (ddate, conf->input_datefmt, (int *)&day.yyyy,
(int *)&day.mm, (int *)&day.dd, NULL))
{
- (void)app_arg (add_line, &day, 0, print_note, conf, regex);
+ app_arg (add_line, &day, 0, print_note, conf, regex);
}
else
{
char outstr[BUFSIZ];
fputs (_("Argument to the '-d' flag is not valid\n"), stderr);
- (void)snprintf (outstr, BUFSIZ,
- "Possible argument format are: '%s' or 'n'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ snprintf (outstr, BUFSIZ,
+ "Possible argument format are: '%s' or 'n'\n",
+ DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
more_info ();
}
@@ -652,7 +650,7 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
{
t.tm_year -= 1900;
t.tm_mon--;
- (void)mktime (&t);
+ mktime (&t);
}
else
{
@@ -667,9 +665,9 @@ date_arg_extended (char *startday, char *range, int add_line, int print_note,
{
char outstr[BUFSIZ];
fputs (_("Argument is not valid\n"), stderr);
- (void)snprintf (outstr, BUFSIZ,
- "Argument format for -s and --startday is: '%s'\n",
- DATEFMT_DESC (conf->input_datefmt));
+ snprintf (outstr, BUFSIZ,
+ "Argument format for -s and --startday is: '%s'\n",
+ DATEFMT_DESC (conf->input_datefmt));
fputs (_(outstr), stdout);
fputs (_("Argument format for -r and --range is: 'n'\n"), stdout);
more_info ();
@@ -692,6 +690,7 @@ parse_args (int argc, char **argv, struct conf *conf)
int dflag = 0; /* -d: print appointments for a specified days */
int Dflag = 0; /* -D: specify data directory to use */
int hflag = 0; /* -h: print help text */
+ int gflag = 0; /* -g: run garbage collector */
int iflag = 0; /* -i: import data */
int nflag = 0; /* -n: print next appointment */
int Nflag = 0; /* -N: also print note content with apps and todos */
@@ -714,13 +713,14 @@ parse_args (int argc, char **argv, struct conf *conf)
STATUS_OPT = CHAR_MAX + 1
};
- static char *optstr = "hvnNax::t::d:c:r::s::S:D:i:";
+ static char *optstr = "ghvnNax::t::d:c:r::s::S:D:i:";
struct option longopts[] = {
{"appointment", no_argument, NULL, 'a'},
{"calendar", required_argument, NULL, 'c'},
{"day", required_argument, NULL, 'd'},
{"directory", required_argument, NULL, 'D'},
+ {"gc", no_argument, NULL, 'g'},
{"help", no_argument, NULL, 'h'},
{"import", required_argument, NULL, 'i'},
{"next", no_argument, NULL, 'n'},
@@ -766,6 +766,9 @@ parse_args (int argc, char **argv, struct conf *conf)
case 'h':
hflag = 1;
break;
+ case 'g':
+ gflag = 1;
+ break;
case 'i':
iflag = 1;
multiple_flag++;
@@ -812,7 +815,7 @@ parse_args (int argc, char **argv, struct conf *conf)
{
usage ();
usage_try ();
- return (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
}
else
@@ -900,18 +903,30 @@ parse_args (int argc, char **argv, struct conf *conf)
status_arg ();
non_interactive = 1;
}
+ else if (gflag)
+ {
+ io_init (cfile, datadir);
+ io_check_dir (path_dir, NULL);
+ io_check_dir (path_notes, NULL);
+ io_check_file (path_apts, NULL);
+ io_check_file (path_todo, NULL);
+ io_load_app ();
+ io_load_todo ();
+ note_gc ();
+ non_interactive = 1;
+ }
else if (multiple_flag)
{
if (load_data)
{
io_init (cfile, datadir);
- io_check_dir (path_dir, (int *)0);
- io_check_dir (path_notes, (int *)0);
+ io_check_dir (path_dir, NULL);
+ io_check_dir (path_notes, NULL);
}
if (iflag)
{
- io_check_file (path_apts, (int *)0);
- io_check_file (path_todo, (int *)0);
+ 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);
io_load_app ();
@@ -923,8 +938,8 @@ parse_args (int argc, char **argv, struct conf *conf)
}
if (xflag)
{
- io_check_file (path_apts, (int *)0);
- io_check_file (path_todo, (int *)0);
+ io_check_file (path_apts, NULL);
+ io_check_file (path_todo, NULL);
io_load_app ();
io_load_todo ();
io_export_data (xfmt, conf);
@@ -933,24 +948,24 @@ parse_args (int argc, char **argv, struct conf *conf)
}
if (tflag)
{
- io_check_file (path_todo, (int *)0);
+ io_check_file (path_todo, NULL);
io_load_todo ();
todo_arg (tnum, Nflag, preg);
non_interactive = 1;
}
if (nflag)
{
- io_check_file (path_apts, (int *)0);
+ io_check_file (path_apts, NULL);
io_load_app ();
next_arg ();
non_interactive = 1;
}
if (dflag || rflag || sflag)
{
- io_check_file (path_apts, (int *)0);
- io_check_file (path_conf, (int *)0);
+ io_check_file (path_apts, NULL);
+ io_check_file (path_conf, NULL);
io_load_app ();
- custom_load_conf (conf, 0); /* To get output date format. */
+ custom_load_conf (conf); /* To get output date format. */
if (dflag)
date_arg (ddate, add_line, Nflag, conf, preg);
if (rflag || sflag)
@@ -962,13 +977,13 @@ parse_args (int argc, char **argv, struct conf *conf)
{
struct date day;
- io_check_file (path_apts, (int *)0);
- io_check_file (path_conf, (int *)0);
+ io_check_file (path_apts, NULL);
+ io_check_file (path_conf, NULL);
vars_init (conf);
- custom_load_conf (conf, 0); /* To get output date format. */
+ custom_load_conf (conf); /* To get output date format. */
io_load_app ();
day.dd = day.mm = day.yyyy = 0;
- (void)app_arg (add_line, &day, 0, Nflag, conf, preg);
+ app_arg (add_line, &day, 0, Nflag, conf, preg);
non_interactive = 1;
}
}