diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/args.c | 29 | ||||
-rw-r--r-- | src/calcurse.c | 2 | ||||
-rw-r--r-- | src/calcurse.h | 8 | ||||
-rw-r--r-- | src/ical.c | 83 | ||||
-rw-r--r-- | src/io.c | 10 |
5 files changed, 72 insertions, 60 deletions
@@ -70,7 +70,7 @@ enum { OPT_FMT_EV, OPT_FMT_REV, OPT_FMT_TODO, - OPT_LIST_IMPORTED, + OPT_DUMP_IMPORTED, OPT_EXPORT_UID, OPT_READ_ONLY, OPT_STATUS, @@ -402,7 +402,7 @@ int parse_args(int argc, char **argv) const char *fmt_todo = NULL; /* Import and export parameters */ int xfmt = IO_EXPORT_ICAL; - int list_imported = 0, export_uid = 0; + int dump_imported = 0, export_uid = 0; /* Data file locations */ const char *cfile = NULL, *datadir = NULL, *ifile = NULL; @@ -459,7 +459,7 @@ int parse_args(int argc, char **argv) {"format-recur-event", required_argument, NULL, OPT_FMT_REV}, {"format-todo", required_argument, NULL, OPT_FMT_TODO}, {"export-uid", no_argument, NULL, OPT_EXPORT_UID}, - {"list-imported", no_argument, NULL, OPT_LIST_IMPORTED}, + {"dump-imported", no_argument, NULL, OPT_DUMP_IMPORTED}, {"read-only", no_argument, NULL, OPT_READ_ONLY}, {"status", no_argument, NULL, OPT_STATUS}, {"daemon", no_argument, NULL, OPT_DAEMON}, @@ -669,8 +669,8 @@ int parse_args(int argc, char **argv) case OPT_FMT_TODO: fmt_todo = optarg; break; - case OPT_LIST_IMPORTED: - list_imported = 1; + case OPT_DUMP_IMPORTED: + dump_imported = 1; break; case OPT_EXPORT_UID: export_uid = 1; @@ -776,7 +776,24 @@ int parse_args(int argc, char **argv) /* Get default pager in case we need to show a log file. */ vars_init(); io_load_data(NULL); - io_import_data(IO_IMPORT_ICAL, ifile, list_imported); + if (dump_imported) { + /* + * Use default values for non-specified format strings. + */ + fmt_apt = fmt_apt ? fmt_apt : "%(raw)"; + fmt_rapt = fmt_rapt ? fmt_rapt : "%(raw)"; + fmt_ev = fmt_ev ? fmt_ev : "%(raw)"; + fmt_rev = fmt_rev ? fmt_rev : "%(raw)"; + fmt_todo = fmt_todo ? fmt_todo : "%(raw)"; + } else { + /* + * Do not dump items, unset format strings explicitly. + */ + fmt_apt = fmt_rapt = fmt_ev = fmt_rev = NULL; + fmt_todo = NULL; + } + io_import_data(IO_IMPORT_ICAL, ifile, fmt_ev, fmt_rev, fmt_apt, + fmt_rapt, fmt_todo); io_save_apts(path_apts); io_save_todo(path_todo); } else if (export) { diff --git a/src/calcurse.c b/src/calcurse.c index 4218962..e550b76 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -276,7 +276,7 @@ static inline void key_generic_reload(void) static inline void key_generic_import(void) { wins_erase_status_bar(); - io_import_data(IO_IMPORT_ICAL, NULL, 0); + io_import_data(IO_IMPORT_ICAL, NULL, NULL, NULL, NULL, NULL, NULL); ui_calendar_monthly_view_cache_set_invalid(); do_storage(0); wins_update(FLAG_ALL); diff --git a/src/calcurse.h b/src/calcurse.h index aafea6b..9ee8be0 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -809,8 +809,9 @@ int display_help(const char *); int run_hook(const char *); /* ical.c */ -void ical_import_data(FILE *, FILE *, int, unsigned *, unsigned *, unsigned *, - unsigned *, unsigned *); +void ical_import_data(FILE *, FILE *, unsigned *, unsigned *, unsigned *, + unsigned *, unsigned *, const char *, const char *, + const char *, const char *, const char *); void ical_export_data(FILE *, int); /* io.c */ @@ -837,7 +838,8 @@ int io_check_file(const char *); int io_check_data_files(void); void io_startup_screen(int); void io_export_data(enum export_type, int); -void io_import_data(enum import_type, const char *, int); +void io_import_data(enum import_type, const char *, const char *, const char *, + const char *, const char *, const char *); struct io_file *io_log_init(void); void io_log_print(struct io_file *, int, const char *); void io_log_display(struct io_file *, const char *, const char *); @@ -325,21 +325,19 @@ static void ical_log(FILE * log, ical_types_e type, unsigned lineno, } static void ical_store_todo(int priority, int completed, char *mesg, - char *note, int list) + char *note, const char *fmt_todo) { struct todo *todo = todo_add(mesg, priority, completed, note); - if (list) { - char *hash = todo_hash(todo); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_todo) + print_todo(fmt_todo, todo); mem_free(mesg); erase_note(¬e); } static void ical_store_event(char *mesg, char *note, long day, long end, - ical_rpt_t * rpt, llist_t * exc, int list) + ical_rpt_t * rpt, llist_t * exc, const char *fmt_ev, + const char *fmt_rev) { const int EVENTID = 1; struct event *ev; @@ -349,21 +347,15 @@ ical_store_event(char *mesg, char *note, long day, long end, rev = recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq, rpt->until, exc); mem_free(rpt); - if (list) { - char *hash = recur_event_hash(rev); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_rev) + print_recur_event(fmt_rev, day, rev); goto cleanup; } if (end == 0 || end - day <= DAYINSEC) { ev = event_new(mesg, note, day, EVENTID); - if (list) { - char *hash = event_hash(ev); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_ev) + print_event(fmt_ev, day, ev); goto cleanup; } @@ -383,11 +375,8 @@ ical_store_event(char *mesg, char *note, long day, long end, rev = recur_event_new(mesg, note, day, EVENTID, rpt->type, rpt->freq, rpt->until, exc); mem_free(rpt); - if (list) { - char *hash = recur_event_hash(rev); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_rev) + print_recur_event(fmt_rev, day, rev); cleanup: mem_free(mesg); @@ -396,7 +385,8 @@ cleanup: static void ical_store_apoint(char *mesg, char *note, long start, long dur, - ical_rpt_t * rpt, llist_t * exc, int has_alarm, int list) + ical_rpt_t * rpt, llist_t * exc, int has_alarm, + const char *fmt_apt, const char *fmt_rapt) { char state = 0L; struct apoint *apt; @@ -408,18 +398,12 @@ ical_store_apoint(char *mesg, char *note, long start, long dur, rapt = recur_apoint_new(mesg, note, start, dur, state, rpt->type, rpt->freq, rpt->until, exc); mem_free(rpt); - if (list) { - char *hash = recur_apoint_hash(rapt); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_rapt) + print_recur_apoint(fmt_rapt, start, rapt->start, rapt); } else { apt = apoint_new(mesg, note, start, dur, state); - if (list) { - char *hash = apoint_hash(apt); - printf("%s\n", hash); - mem_free(hash); - } + if (fmt_apt) + print_apoint(fmt_apt, start, apt); } mem_free(mesg); erase_note(¬e); @@ -897,9 +881,10 @@ static char *ical_read_summary(char *line) } static void -ical_read_event(FILE * fdi, FILE * log, int list, unsigned *noevents, +ical_read_event(FILE * fdi, FILE * log, unsigned *noevents, unsigned *noapoints, unsigned *noskipped, char *buf, - char *lstore, unsigned *lineno) + char *lstore, unsigned *lineno, const char *fmt_ev, + const char *fmt_rev, const char *fmt_apt, const char *fmt_rapt) { const int ITEMLINE = *lineno; ical_vevent_e vevent_type; @@ -963,13 +948,15 @@ ical_read_event(FILE * fdi, FILE * log, int list, unsigned *noevents, ical_store_apoint(vevent.mesg, vevent.note, vevent.start, vevent.dur, vevent.rpt, &vevent.exc, - vevent.has_alarm, list); + vevent.has_alarm, fmt_apt, + fmt_rapt); (*noapoints)++; break; case EVENT: ical_store_event(vevent.mesg, vevent.note, vevent.start, vevent.end, - vevent.rpt, &vevent.exc, list); + vevent.rpt, &vevent.exc, + fmt_ev, fmt_rev); (*noevents)++; break; case UNDEFINED: @@ -1050,9 +1037,8 @@ cleanup: } static void -ical_read_todo(FILE * fdi, FILE * log, int list, unsigned *notodos, - unsigned *noskipped, char *buf, char *lstore, - unsigned *lineno) +ical_read_todo(FILE * fdi, FILE * log, unsigned *notodos, unsigned *noskipped, + char *buf, char *lstore, unsigned *lineno, const char *fmt_todo) { const int ITEMLINE = *lineno; struct { @@ -1083,7 +1069,7 @@ ical_read_todo(FILE * fdi, FILE * log, int list, unsigned *notodos, } ical_store_todo(vtodo.priority, vtodo.completed, - vtodo.mesg, vtodo.note, list); + vtodo.mesg, vtodo.note, fmt_todo); (*notodos)++; return; } @@ -1121,9 +1107,11 @@ cleanup: /* Import calcurse data. */ void -ical_import_data(FILE * stream, FILE * log, int list, unsigned *events, +ical_import_data(FILE * stream, FILE * log, unsigned *events, unsigned *apoints, unsigned *todos, unsigned *lines, - unsigned *skipped) + unsigned *skipped, const char *fmt_ev, const char *fmt_rev, + const char *fmt_apt, const char *fmt_rapt, + const char *fmt_todo) { char buf[BUFSIZ], lstore[BUFSIZ]; int major, minor; @@ -1139,11 +1127,12 @@ ical_import_data(FILE * stream, FILE * log, int list, unsigned *events, while (ical_readline(stream, buf, lstore, lines)) { (*lines)++; if (starts_with_ci(buf, "BEGIN:VEVENT")) { - ical_read_event(stream, log, list, events, apoints, - skipped, buf, lstore, lines); + ical_read_event(stream, log, events, apoints, + skipped, buf, lstore, lines, fmt_ev, + fmt_rev, fmt_apt, fmt_rapt); } else if (starts_with_ci(buf, "BEGIN:VTODO")) { - ical_read_todo(stream, log, list, todos, skipped, buf, - lstore, lines); + ical_read_todo(stream, log, todos, skipped, buf, + lstore, lines, fmt_todo); } } } @@ -1222,7 +1222,10 @@ static FILE *get_import_stream(enum import_type type) * A temporary log file is created in /tmp to store the import process report, * and is cleared at the end. */ -void io_import_data(enum import_type type, const char *stream_name, int list) +void io_import_data(enum import_type type, const char *stream_name, + const char *fmt_ev, const char *fmt_rev, + const char *fmt_apt, const char *fmt_rapt, + const char *fmt_todo) { const char *proc_report = _("Import process report: %04d lines read"); @@ -1266,9 +1269,10 @@ void io_import_data(enum import_type type, const char *stream_name, int list) } if (type == IO_IMPORT_ICAL) - ical_import_data(stream, log->fd, list, &stats.events, + ical_import_data(stream, log->fd, &stats.events, &stats.apoints, &stats.todos, - &stats.lines, &stats.skipped); + &stats.lines, &stats.skipped, fmt_ev, fmt_rev, + fmt_apt, fmt_rapt, fmt_todo); if (stream != stdin) file_close(stream, __FILE_POS__); |