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>
This commit is contained in:
committed by
Lukas Fleischer
parent
9300e9154c
commit
42abbf5346
48
src/apoint.c
48
src/apoint.c
@@ -200,7 +200,8 @@ struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end,
|
||||
{
|
||||
char buf[BUFSIZ], *newline;
|
||||
time_t tstart, tend;
|
||||
struct apoint *apt;
|
||||
struct apoint *apt = NULL;
|
||||
int cond;
|
||||
|
||||
EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
|
||||
!check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
|
||||
@@ -230,31 +231,30 @@ struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end,
|
||||
|
||||
/* Filter item. */
|
||||
if (filter) {
|
||||
if (!(filter->type_mask & TYPE_MASK_APPT))
|
||||
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;
|
||||
}
|
||||
|
||||
apt = apoint_new(buf, note, tstart, tend - tstart, state);
|
||||
|
||||
/* Filter by hash. */
|
||||
if (filter && filter->hash) {
|
||||
char *hash = apoint_hash(apt);
|
||||
if (!hash_matches(filter->hash, hash)) {
|
||||
apoint_delete(apt);
|
||||
apt = NULL;
|
||||
cond = (
|
||||
!(filter->type_mask & TYPE_MASK_APPT) ||
|
||||
(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) {
|
||||
apt = apoint_new(
|
||||
buf, note, tstart, tend - tstart, state);
|
||||
char *hash = apoint_hash(apt);
|
||||
cond = cond || !hash_matches(filter->hash, hash);
|
||||
mem_free(hash);
|
||||
}
|
||||
|
||||
if ((!filter->invert && cond) || (filter->invert && !cond)) {
|
||||
if (filter->hash)
|
||||
apoint_delete(apt);
|
||||
return NULL;
|
||||
}
|
||||
mem_free(hash);
|
||||
}
|
||||
if (!apt)
|
||||
apt = apoint_new(buf, note, tstart, tend - tstart, state);
|
||||
|
||||
return apt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user