diff options
author | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-05 09:15:01 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2016-02-05 19:06:54 +0100 |
commit | e9c8197e4ed1f516c41f803b9aa79bcfe7c7a7ab (patch) | |
tree | 80660f846491bfa750a4e425d9caf7ab2b571cc3 /src | |
parent | 8bdf0c0b3b8870157f50554ea51d4751d0b7efa9 (diff) | |
download | calcurse-e9c8197e4ed1f516c41f803b9aa79bcfe7c7a7ab.tar.gz calcurse-e9c8197e4ed1f516c41f803b9aa79bcfe7c7a7ab.zip |
Refactor grep mode
Split io_save_{apts,todo}() into functions that write raw data to a file
and functions that write formatted items to stdout such that one can
easily extend the grep mode for format string support in a follow-up
commit.
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/args.c | 9 | ||||
-rw-r--r-- | src/calcurse.h | 2 | ||||
-rw-r--r-- | src/io.c | 42 | ||||
-rw-r--r-- | src/utils.c | 1 |
4 files changed, 52 insertions, 2 deletions
@@ -727,8 +727,13 @@ int parse_args(int argc, char **argv) vars_init(); config_load(); /* To get output date format. */ io_load_data(&filter); - io_save_todo(grep_filter ? path_todo : NULL); - io_save_apts(grep_filter ? path_apts : NULL); + if (grep_filter) { + io_save_todo(path_todo); + io_save_apts(path_apts); + } else { + io_dump_todo("%(raw)"); + io_dump_apts("%(raw)", "%(raw)", "%(raw)", "%(raw)"); + } } else if (query) { io_check_file(path_apts); io_check_file(path_todo); diff --git a/src/calcurse.h b/src/calcurse.h index 5e117dc..aafea6b 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -819,7 +819,9 @@ void io_init(const char *, const char *); void io_extract_data(char *, const char *, int); void io_save_mutex_lock(void); void io_save_mutex_unlock(void); +void io_dump_apts(const char *, const char *, const char *, const char *); unsigned io_save_apts(const char *); +void io_dump_todo(const char *); unsigned io_save_todo(const char *); unsigned io_save_keys(void); void io_save_cal(enum save_display); @@ -295,6 +295,37 @@ void io_save_mutex_unlock(void) pthread_mutex_unlock(&io_save_mutex); } +/* Print all appointments and events to stdout. */ +void io_dump_apts(const char *fmt_apt, const char *fmt_rapt, + const char *fmt_ev, const char *fmt_rev) +{ + llist_item_t *i; + + LLIST_FOREACH(&recur_elist, i) { + struct recur_event *rev = LLIST_GET_DATA(i); + time_t day = update_time_in_date(rev->day, 0, 0); + print_recur_event(fmt_rev, day, rev); + } + + LLIST_TS_FOREACH(&recur_alist_p, i) { + struct recur_apoint *rapt = LLIST_GET_DATA(i); + time_t day = update_time_in_date(rapt->start, 0, 0); + print_recur_apoint(fmt_rapt, day, rapt->start, rapt); + } + + LLIST_TS_FOREACH(&alist_p, i) { + struct apoint *apt = LLIST_TS_GET_DATA(i); + time_t day = update_time_in_date(apt->start, 0, 0); + print_apoint(fmt_apt, day, apt); + } + + LLIST_FOREACH(&eventlist, i) { + struct event *ev = LLIST_TS_GET_DATA(i); + time_t day = update_time_in_date(ev->day, 0, 0); + print_event(fmt_ev, day, ev); + } +} + /* * Save the apts data file, which contains the * appointments first, and then the events. @@ -337,6 +368,17 @@ unsigned io_save_apts(const char *aptsfile) return 1; } +/* Print all todo items to stdout. */ +void io_dump_todo(const char *fmt_todo) +{ + llist_item_t *i; + + LLIST_FOREACH(&todolist, i) { + struct todo *todo = LLIST_TS_GET_DATA(i); + print_todo(fmt_todo, todo); + } +} + /* Save the todo data file. */ unsigned io_save_todo(const char *todofile) { diff --git a/src/utils.c b/src/utils.c index b1ef630..a5e1196 100644 --- a/src/utils.c +++ b/src/utils.c @@ -485,6 +485,7 @@ long update_time_in_date(long date, unsigned hr, unsigned mn) localtime_r(&t, <); lt.tm_hour = hr; lt.tm_min = mn; + lt.tm_sec = 0; new_date = mktime(<); EXIT_IF(new_date == -1, _("error in mktime")); |