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
105
src/recur.c
105
src/recur.c
@@ -349,7 +349,8 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
|
||||
{
|
||||
char buf[BUFSIZ], *nl;
|
||||
time_t tstart, tend, tuntil;
|
||||
struct recur_apoint *rapt;
|
||||
struct recur_apoint *rapt = 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) ||
|
||||
@@ -393,32 +394,34 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start,
|
||||
|
||||
/* Filter item. */
|
||||
if (filter) {
|
||||
if (!(filter->type_mask & TYPE_MASK_RECUR_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;
|
||||
}
|
||||
|
||||
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;
|
||||
cond = (
|
||||
!(filter->type_mask & TYPE_MASK_RECUR_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) {
|
||||
rapt = recur_apoint_new(buf, note, tstart,
|
||||
tend - tstart, state,
|
||||
recur_char2def(type),
|
||||
freq, tuntil, exc);
|
||||
char *hash = recur_apoint_hash(rapt);
|
||||
cond = cond || !hash_matches(filter->hash, hash);
|
||||
mem_free(hash);
|
||||
}
|
||||
|
||||
if ((!filter->invert && cond) || (filter->invert && !cond)) {
|
||||
if (filter->hash)
|
||||
recur_apoint_erase(rapt);
|
||||
return NULL;
|
||||
}
|
||||
mem_free(hash);
|
||||
}
|
||||
if (!rapt)
|
||||
rapt = recur_apoint_new(buf, note, tstart, tend - tstart,
|
||||
state, recur_char2def(type), freq,
|
||||
tuntil, exc);
|
||||
|
||||
return rapt;
|
||||
}
|
||||
@@ -431,7 +434,8 @@ 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;
|
||||
struct recur_event *rev = NULL;
|
||||
int cond;
|
||||
|
||||
EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
|
||||
!check_time(start.tm_hour, start.tm_min) ||
|
||||
@@ -466,32 +470,33 @@ struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
|
||||
|
||||
/* Filter item. */
|
||||
if (filter) {
|
||||
if (!(filter->type_mask & TYPE_MASK_RECUR_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;
|
||||
}
|
||||
|
||||
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;
|
||||
cond = (
|
||||
!(filter->type_mask & TYPE_MASK_RECUR_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) {
|
||||
rev = recur_event_new(buf, note, tstart, id,
|
||||
recur_char2def(type),
|
||||
freq, tuntil, exc);
|
||||
char *hash = recur_event_hash(rev);
|
||||
cond = cond || !hash_matches(filter->hash, hash);
|
||||
mem_free(hash);
|
||||
}
|
||||
|
||||
if ((!filter->invert && cond) || (filter->invert && !cond)) {
|
||||
if (filter->hash)
|
||||
recur_event_erase(rev);
|
||||
return NULL;
|
||||
}
|
||||
mem_free(hash);
|
||||
}
|
||||
if (!rev)
|
||||
rev = recur_event_new(buf, note, tstart, id,
|
||||
recur_char2def(type),
|
||||
freq, tuntil, exc);
|
||||
|
||||
return rev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user