summaryrefslogtreecommitdiffstats
path: root/src/args.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.c')
-rw-r--r--src/args.c134
1 files changed, 11 insertions, 123 deletions
diff --git a/src/args.c b/src/args.c
index 01f24e9..57aeac8 100644
--- a/src/args.c
+++ b/src/args.c
@@ -41,7 +41,6 @@
#include <limits.h>
#include <getopt.h>
#include <time.h>
-#include <regex.h>
#include "calcurse.h"
@@ -63,7 +62,7 @@ static void usage(void)
const char *arg_usage =
_("Usage: calcurse [-g|-h|-v] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n"
- " [-c<file> | -D<dir>] [-S<regex>] [--status]\n"
+ " [-c<file>] [-D<dir>] [-S<regex>] [--status]\n"
" [--read-only]\n");
fputs(arg_usage, stdout);
}
@@ -113,9 +112,9 @@ static void help_arg(void)
" Don't save configuration nor appointments/todos. Use with care.\n"
"\nFiles:\n"
" -c <file>, --calendar <file>\n"
- " specify the calendar <file> to use (incompatible with '-D').\n"
+ " specify the calendar <file> to use (has precedence over '-D').\n"
"\n -D <dir>, --directory <dir>\n"
- " specify the data directory to use (incompatible with '-c').\n"
+ " specify the data directory to use.\n"
"\tIf not specified, the default directory is ~/.calcurse\n"
"\nNon-interactive:\n"
" -a, --appointment\n"
@@ -289,123 +288,21 @@ static void arg_print_date(long date)
static int
app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
- regex_t * regex)
+ regex_t *regex)
{
- llist_item_t *i, *j;
- long today;
- unsigned print_date = 1;
- int app_found = 0;
-
if (date == 0)
- today = get_sec_date(*day);
- else
- today = date;
+ date = get_sec_date(*day);
- /*
- * Calculate and print the selected date if there is an event for
- * that date and it is the first one, and then print all the events for
- * that date.
- */
- LLIST_FIND_FOREACH(&recur_elist, today, recur_event_inday, i) {
- struct recur_event *re = LLIST_GET_DATA(i);
- if (regex && regexec(regex, re->mesg, 0, 0, 0) != 0)
- continue;
+ int n = day_store_items(date, NULL, NULL, regex);
- app_found = 1;
- if (add_line) {
+ if (n > 0) {
+ if (add_line)
fputs("\n", stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today);
- print_date = 0;
- }
- print_recur_event(fmt_rev, today, re);
- }
-
- 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)
- continue;
-
- app_found = 1;
- if (add_line) {
- fputs("\n", stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today);
- print_date = 0;
- }
- print_event(fmt_ev, today, ev);
- }
-
- /* Same process is performed but this time on the appointments. */
- LLIST_TS_LOCK(&alist_p);
- LLIST_TS_LOCK(&recur_alist_p);
-
- /*
- * Iterate over regular appointments and recurrent ones simultaneously (fixes
- * http://lists.calcurse.org/bugs/msg00002.html).
- */
- i = LLIST_TS_FIND_FIRST(&alist_p, today, apoint_inday);
- j = LLIST_TS_FIND_FIRST(&recur_alist_p, today, recur_apoint_inday);
- while (i || j) {
- 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) {
- i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
- apt = LLIST_TS_GET_DATA(i);
- }
-
- while (j && regex && regexec(regex, ra->mesg, 0, 0, 0) != 0) {
- j = LLIST_TS_FIND_NEXT(j, today, recur_apoint_inday);
- ra = LLIST_TS_GET_DATA(j);
- }
-
- if (apt && ra) {
- if (recur_apoint_find_occurrence(ra, today, &occurrence) &&
- apt->start <= occurrence)
- ra = NULL;
- else
- apt = NULL;
- }
-
- if (apt) {
- app_found = 1;
- if (add_line) {
- fputs("\n", stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today);
- print_date = 0;
- }
- print_apoint(fmt_apt, today, apt);
- i = LLIST_TS_FIND_NEXT(i, today, apoint_inday);
- } else if (ra) {
- app_found = 1;
- if (add_line) {
- fputs("\n", stdout);
- add_line = 0;
- }
- if (print_date) {
- arg_print_date(today);
- print_date = 0;
- }
- recur_apoint_find_occurrence(ra, today, &occurrence);
- print_recur_apoint(fmt_rapt, today, occurrence, ra);
- apt = NULL;
- j = LLIST_TS_FIND_NEXT(j, today, recur_apoint_inday);
- }
+ arg_print_date(date);
+ day_write_stdout(date, fmt_apt, fmt_rapt, fmt_ev, fmt_rev);
}
- LLIST_TS_UNLOCK(&recur_alist_p);
- LLIST_TS_UNLOCK(&alist_p);
-
- return app_found;
+ return n;
}
/*
@@ -548,9 +445,7 @@ int parse_args(int argc, char **argv)
int unknown_flag = 0;
/* Command-line flags */
int aflag = 0; /* -a: print appointments for current day */
- int cflag = 0; /* -c: specify the calendar file to use */
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 */
@@ -619,7 +514,6 @@ int parse_args(int argc, char **argv)
load_data++;
break;
case 'c':
- cflag = 1;
multiple_flag++;
cfile = optarg;
load_data++;
@@ -631,7 +525,6 @@ int parse_args(int argc, char **argv)
ddate = optarg;
break;
case 'D':
- Dflag = 1;
datadir = optarg;
break;
case 'h':
@@ -741,11 +634,6 @@ int parse_args(int argc, char **argv)
usage_try();
return EXIT_FAILURE;
/* Incorrect arguments */
- } else if (Dflag && cflag) {
- fputs(_("Options '-D' and '-c' cannot be used at the same time\n"), stderr);
- usage();
- usage_try();
- return EXIT_FAILURE;
} else if (Sflag && !(aflag || dflag || rflag || sflag || tflag)) {
fputs(_("Option '-S' must be used with either '-d', '-r', '-s', "
"'-a' or '-t'\n"), stderr);