summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-08-07 16:34:48 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-08-07 16:34:48 +0200
commitc2a9292bf457b3119c4e141d28d6c629d08de71d (patch)
tree7fb6d2b50f828ef0468d5505b784b52eff5a98ac /src/io.c
parent9f24adfded95bb185887f96569754bf78b197044 (diff)
downloadcalcurse-c2a9292bf457b3119c4e141d28d6c629d08de71d.zip
Add a grep mode
This allows for printing a subset of the items in the data files by using filters. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/io.c b/src/io.c
index a6f5958..dca23d1 100644
--- a/src/io.c
+++ b/src/io.c
@@ -303,11 +303,15 @@ unsigned io_save_apts(const char *aptsfile)
llist_item_t *i;
FILE *fp;
- if (read_only)
- return 1;
+ if (aptsfile) {
+ if (read_only)
+ return 1;
- if ((fp = fopen(aptsfile, "w")) == NULL)
- return 0;
+ if ((fp = fopen(aptsfile, "w")) == NULL)
+ return 0;
+ } else {
+ fp = stdout;
+ }
recur_save_data(fp);
@@ -324,7 +328,9 @@ unsigned io_save_apts(const char *aptsfile)
struct event *ev = LLIST_TS_GET_DATA(i);
event_write(ev, fp);
}
- file_close(fp, __FILE_POS__);
+
+ if (aptsfile)
+ file_close(fp, __FILE_POS__);
return 1;
}
@@ -335,17 +341,23 @@ unsigned io_save_todo(const char *todofile)
llist_item_t *i;
FILE *fp;
- if (read_only)
- return 1;
+ if (todofile) {
+ if (read_only)
+ return 1;
- if ((fp = fopen(todofile, "w")) == NULL)
- return 0;
+ if ((fp = fopen(todofile, "w")) == NULL)
+ return 0;
+ } else {
+ fp = stdout;
+ }
LLIST_FOREACH(&todolist, i) {
struct todo *todo = LLIST_TS_GET_DATA(i);
todo_write(todo, fp);
}
- file_close(fp, __FILE_POS__);
+
+ if (todofile)
+ file_close(fp, __FILE_POS__);
return 1;
}