aboutsummaryrefslogtreecommitdiffstats
path: root/src/recur.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-08-06 08:53:51 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-08-06 12:08:14 +0200
commitbfe73d0e5d66c43006a8a0dd8d58e311432bcb57 (patch)
tree584c1f12effddb2501566a872f7787be65124b89 /src/recur.c
parent4ec7fe123925144506297df5eba4ed41c6f8331d (diff)
downloadcalcurse-bfe73d0e5d66c43006a8a0dd8d58e311432bcb57.tar.gz
calcurse-bfe73d0e5d66c43006a8a0dd8d58e311432bcb57.zip
Add item filters
This adds the following filter options that allow for restricting the set of items that are read from the appointments file: * --filter-type * --filter-start-from * --filter-start-to * --filter-start-after * --filter-start-before * --filter-end-from * --filter-end-to * --filter-end-after * --filter-end-before Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/recur.c')
-rw-r--r--src/recur.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/recur.c b/src/recur.c
index 69706b0..76585d6 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -330,7 +330,8 @@ static void recur_write_exc(llist_t * lexc, FILE * f)
struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
struct tm end, char type, int freq,
struct tm until, char *note,
- llist_t * exc, char state)
+ llist_t * exc, char state,
+ struct item_filter *filter)
{
char buf[BUFSIZ], *nl;
time_t tstart, tend, tuntil;
@@ -375,6 +376,20 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
EXIT_IF(tstart == -1 || tend == -1 || tstart > tend
|| tuntil == -1, _("date error in appointment"));
+ /* Filter item. */
+ if (filter) {
+ if (!(filter->type_mask & TYPE_MASK_RECUR_APPT))
+ return NULL;
+ if (filter->start_from >= 0 && tstart < filter->start_from)
+ return NULL;
+ if (filter->start_to >= 0 && tstart > filter->start_to)
+ return NULL;
+ if (filter->end_from >= 0 && tend < filter->end_from)
+ return NULL;
+ if (filter->end_to >= 0 && tend > filter->end_to)
+ return NULL;
+ }
+
return recur_apoint_new(buf, note, tstart, tend - tstart, state,
recur_char2def(type), freq, tuntil, exc);
}
@@ -382,7 +397,8 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
/* Load the recursive events from file */
struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
char type, int freq, struct tm until,
- char *note, llist_t * exc)
+ char *note, llist_t * exc,
+ struct item_filter *filter)
{
char buf[BUFSIZ], *nl;
time_t tstart, tuntil;
@@ -417,6 +433,16 @@ struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
tstart = mktime(&start);
EXIT_IF(tstart == -1 || tuntil == -1, _("date error in event"));
+ /* Filter item. */
+ if (filter) {
+ if (!(filter->type_mask & TYPE_MASK_RECUR_EVNT))
+ return NULL;
+ if (filter->start_from >= 0 && tstart < filter->start_from)
+ return NULL;
+ if (filter->start_to >= 0 && tstart > filter->start_to)
+ return NULL;
+ }
+
return recur_event_new(buf, note, tstart, id, recur_char2def(type),
freq, tuntil, exc);
}