From 7f8c62bf57b85234c248316505a503602792839a Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 11 Jan 2016 22:26:46 +0100 Subject: Add an option to filter by object hash Implement a new --filter-hash option to filter by object identifiers. Each object having an identifier that has the specified pattern as a prefix is matched. Patterns starting with an exclamation mark (!) are interpreted as negative patterns. Signed-off-by: Lukas Fleischer --- src/recur.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/recur.c') diff --git a/src/recur.c b/src/recur.c index ddfddb4..921b5c9 100644 --- a/src/recur.c +++ b/src/recur.c @@ -336,6 +336,7 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start, { char buf[BUFSIZ], *nl; time_t tstart, tend, tuntil; + struct recur_apoint *rapt; EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) || !check_date(end.tm_year, end.tm_mon, end.tm_mday) || @@ -393,8 +394,20 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start, return NULL; } - return recur_apoint_new(buf, note, tstart, tend - tstart, state, + rapt = recur_apoint_new(buf, note, tstart, tend - tstart, state, recur_char2def(type), freq, tuntil, exc); + + /* Filter by hash. */ + if (filter && filter->hash) { + char *hash = recur_apoint_hash(rapt); + if (!hash_matches(filter->hash, hash)) { + recur_apoint_erase(rapt); + rapt = NULL; + } + mem_free(hash); + } + + return rapt; } /* Load the recursive events from file */ @@ -405,6 +418,7 @@ struct recur_event *recur_event_scan(FILE * f, struct tm start, int id, { char buf[BUFSIZ], *nl; time_t tstart, tend, tuntil; + struct recur_event *rev; EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) || !check_time(start.tm_hour, start.tm_min) || @@ -453,8 +467,20 @@ struct recur_event *recur_event_scan(FILE * f, struct tm start, int id, return NULL; } - return recur_event_new(buf, note, tstart, id, recur_char2def(type), - freq, tuntil, exc); + rev = recur_event_new(buf, note, tstart, id, recur_char2def(type), + freq, tuntil, exc); + + /* Filter by hash. */ + if (filter && filter->hash) { + char *hash = recur_event_hash(rev); + if (!hash_matches(filter->hash, hash)) { + recur_event_erase(rev); + rev = NULL; + } + mem_free(hash); + } + + return rev; } char *recur_apoint_tostr(struct recur_apoint *o) -- cgit v1.2.3-54-g00ecf