aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-12-06 09:56:45 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-01-07 16:58:06 +0100
commit42abbf53463cbbdcd319063fcbfb91cf6ed5bdc5 (patch)
treea787439c222045a47484e30d6752c71635c41efc /src/io.c
parent9300e9154c5f70aa6fb858452f0c3563d100850d (diff)
downloadcalcurse-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/io.c')
-rw-r--r--src/io.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/io.c b/src/io.c
index 0e7baea..27c6a31 100644
--- a/src/io.c
+++ b/src/io.c
@@ -707,8 +707,7 @@ void io_load_todo(struct item_filter *filter)
{
FILE *data_file;
char *newline;
- int nb_tod = 0;
- int c, id, completed;
+ int c, id, completed, cond;
char buf[BUFSIZ], e_todo[BUFSIZ], note[MAX_NOTESIZ + 1];
unsigned line = 0;
@@ -760,34 +759,31 @@ void io_load_todo(struct item_filter *filter)
io_extract_data(e_todo, buf, sizeof buf);
/* Filter item. */
+ struct todo *todo = NULL;
if (filter) {
- if (!(filter->type_mask & TYPE_MASK_TODO))
- continue;
- if (filter->regex &&
- regexec(filter->regex, e_todo, 0, 0, 0))
- continue;
- if (filter->priority && id != filter->priority)
- continue;
- if (filter->completed && !completed)
- continue;
- if (filter->uncompleted && completed)
- continue;
- }
-
- struct todo *todo = todo_add(e_todo, id, completed, note);
+ cond = (
+ !(filter->type_mask & TYPE_MASK_TODO) ||
+ (filter->regex && regexec(filter->regex, e_todo, 0, 0, 0)) ||
+ (filter->priority && id != filter->priority) ||
+ (filter->completed && !completed) ||
+ (filter->uncompleted && completed)
+ );
+ if (filter->hash) {
+ todo = todo_add(e_todo, id, completed, note);
+ char *hash = todo_hash(todo);
+ cond = cond || !hash_matches(filter->hash, hash);
+ mem_free(hash);
+ }
- /* Filter by hash. */
- if (filter && filter->hash) {
- char *hash = todo_hash(todo);
- if (!hash_matches(filter->hash, hash)) {
- todo_delete(todo);
- todo = NULL;
+ if ((!filter->invert && cond) || (filter->invert && !cond)) {
+ if (filter->hash)
+ todo_delete(todo);
+ continue;
}
- mem_free(hash);
}
- if (todo)
- ++nb_tod;
+ if (!todo)
+ todo = todo_add(e_todo, id, completed, note);
}
file_close(data_file, __FILE_POS__);
}