From 42abbf53463cbbdcd319063fcbfb91cf6ed5bdc5 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Thu, 6 Dec 2018 09:56:45 +0100 Subject: 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 " is the (set) complement of "calcurse -G --filter-invert". Here may be any combination of filter options. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/io.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'src/io.c') 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__); } -- cgit v1.2.3-54-g00ecf