diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2018-12-06 09:56:45 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2019-01-07 16:58:06 +0100 |
commit | 42abbf53463cbbdcd319063fcbfb91cf6ed5bdc5 (patch) | |
tree | a787439c222045a47484e30d6752c71635c41efc /src/event.c | |
parent | 9300e9154c5f70aa6fb858452f0c3563d100850d (diff) | |
download | calcurse-42abbf53463cbbdcd319063fcbfb91cf6ed5bdc5.tar.gz calcurse-42abbf53463cbbdcd319063fcbfb91cf6ed5bdc5.zip |
Filter option: invert
New filter option: --filter-invert. When present it inverts (negates)
the other filter options combined. This is mostly useful with the -G
option (with -Q the output is limited by the query range (day range)).
The ouput from "calcurse -G <filter options>" is the (set) complement of
"calcurse -G <filter options> --filter-invert". Here <filter options>
may be any combination of filter options.
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/event.c b/src/event.c index fe8f883..65af662 100644 --- a/src/event.c +++ b/src/event.c @@ -152,7 +152,8 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note, { char buf[BUFSIZ], *nl; time_t tstart, tend; - struct event *ev; + struct event *ev = NULL; + int cond; EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) || !check_time(start.tm_hour, start.tm_min), @@ -179,31 +180,29 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note, /* Filter item. */ if (filter) { - if (!(filter->type_mask & TYPE_MASK_EVNT)) - return NULL; - if (filter->regex && regexec(filter->regex, buf, 0, 0, 0)) - return NULL; - if (filter->start_from != -1 && tstart < filter->start_from) - return NULL; - if (filter->start_to != -1 && tstart > filter->start_to) - return NULL; - if (filter->end_from != -1 && tend < filter->end_from) - return NULL; - if (filter->end_to != -1 && tend > filter->end_to) - return NULL; - } - - ev = event_new(buf, note, tstart, id); + cond = ( + !(filter->type_mask & TYPE_MASK_EVNT) || + (filter->regex && regexec(filter->regex, buf, 0, 0, 0)) || + (filter->start_from != -1 && tstart < filter->start_from) || + (filter->start_to != -1 && tstart > filter->start_to) || + (filter->end_from != -1 && tend < filter->end_from) || + (filter->end_to != -1 && tend > filter->end_to) + ); + if (filter->hash) { + ev = event_new(buf, note, tstart, id); + char *hash = event_hash(ev); + cond = cond || !hash_matches(filter->hash, hash); + mem_free(hash); + } - /* Filter by hash. */ - if (filter && filter->hash) { - char *hash = event_hash(ev); - if (!hash_matches(filter->hash, hash)) { - event_delete(ev); - ev = NULL; + if ((!filter->invert && cond) || (filter->invert && !cond)) { + if (filter->hash) + event_delete(ev); + return NULL; } - mem_free(hash); } + if (!ev) + ev = event_new(buf, note, tstart, id); return ev; } |