tsv2agenda: add support for multiline fileds - ics2txt - convert icalendar .ics file to plain text HTML git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ics2txt DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit f4e7114a3838d2bcd8b80fd946a5e4ada83e9b05 DIR parent 46202b022c22d7e917ece6bcdb5f8235ac314e09 HTML Author: Josuah Demangeon <me@josuah.net> Date: Sun, 20 Jun 2021 21:44:57 +0200 tsv2agenda: add support for multiline fileds Diffstat: M tsv2agenda.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) --- DIR diff --git a/tsv2agenda.c b/tsv2agenda.c @@ -106,6 +106,25 @@ print_header(AgendaCtx *ctx, struct tm *beg, struct tm *end, size_t *num) } static void +print_row(AgendaCtx *ctx, char *line, struct tm *beg, struct tm *end, size_t *num) +{ + print_header(ctx, beg, end, num); + for (char *cp = line; *cp != '\0'; cp++) { + if (*cp == '\\') { + switch (*++cp) { + case 'n': + fputc('\n', stdout); + print_header(ctx, beg, end, num); + fputs(": ", stdout); + continue; + } + } + fputc(*cp, stdout); + } + fputc('\n', stdout); +} + +static void print(AgendaCtx *ctx, char **fields) { struct tm beg = {0}, end = {0}; @@ -130,8 +149,7 @@ print(AgendaCtx *ctx, char **fields) for (size_t i = FIELD_OTHER, row = 0; i < ctx->fieldnum; i++) { if (*fields[i] == '\0') continue; - print_header(ctx, &beg, &end, &row); - fprintf(stdout, "%s\n", fields[i]); + print_row(ctx, fields[i], &beg, &end, &row); } ctx->beg = beg;