From 6d9129764bebb775951c2c8629a291407c25a693 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 12 Jan 2016 08:52:39 +0100 Subject: Implement filter mode Add a new -F mode that is identical to -G but writes the result back to the calcurse data files instead of stdout. Signed-off-by: Lukas Fleischer --- src/args.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/args.c b/src/args.c index c843d69..751a41a 100644 --- a/src/args.c +++ b/src/args.c @@ -436,7 +436,7 @@ cleanup: int parse_args(int argc, char **argv) { /* Command-line flags */ - int grep = 0, query = 0, next = 0; + int grep = 0, grep_filter = 0, query = 0, next = 0; int status = 0, gc = 0, import = 0, export = 0; /* Query ranges */ time_t from = -1, to = -1; @@ -459,13 +459,14 @@ int parse_args(int argc, char **argv) int ch; regex_t reg; - static const char *optstr = "gGhvnNax::t::d:c:r::s::S:D:i:l:Q"; + static const char *optstr = "FgGhvnNax::t::d:c:r::s::S:D:i:l:Q"; struct option longopts[] = { {"appointment", no_argument, NULL, 'a'}, {"calendar", required_argument, NULL, 'c'}, {"day", required_argument, NULL, 'd'}, {"directory", required_argument, NULL, 'D'}, + {"filter", no_argument, NULL, 'F'}, {"gc", no_argument, NULL, 'g'}, {"grep", no_argument, NULL, 'G'}, {"help", no_argument, NULL, 'h'}, @@ -534,6 +535,9 @@ int parse_args(int argc, char **argv) case 'D': datadir = optarg; break; + case 'F': + grep_filter = grep = 1; + break; case 'h': help_arg(); goto cleanup; @@ -754,8 +758,8 @@ int parse_args(int argc, char **argv) vars_init(); config_load(); /* To get output date format. */ io_load_data(&filter); - io_save_todo(NULL); - io_save_apts(NULL); + io_save_todo(grep_filter ? path_todo : NULL); + io_save_apts(grep_filter ? path_apts : NULL); } else if (query) { io_check_file(path_apts); io_check_file(path_todo); -- cgit v1.2.3-70-g09d2