Introduction
Introduction Statistics Contact Development Disclaimer Help
tsv2agenda: add line wrapping - ics2txt - convert icalendar .ics file to plain …
git clone git://bitreich.org/ics2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws…
Log
Files
Refs
Tags
README
---
commit d1604d44d1926ce38a94073ad8d55b2c8a99d172
parent 3b9f2bbdc0b786d3732555f8e7a001f40eaa59c6
Author: Josuah Demangeon <[email protected]>
Date: Fri, 25 Jun 2021 20:18:33 +0200
tsv2agenda: add line wrapping
Diffstat:
M tsv2agenda.c | 50 ++++++++++++++++++++++++-----…
1 file changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/tsv2agenda.c b/tsv2agenda.c
@@ -106,20 +106,48 @@ print_header(AgendaCtx *ctx, struct tm *beg, struct tm *e…
}
static void
-print_row(AgendaCtx *ctx, char *line, struct tm *beg, struct tm *end, size_t *…
+unescape(char const *s, char *d)
{
+ for (; *s != '\0'; s++) {
+ if (*s == '\\') {
+ s++;
+ *d++ = (*s == 'n') ? '\n' : (*s == 't') ? ' ' : *s;
+ } else {
+ if (*s == '\\')
+ debug("s='%c'", *s);
+ *d++ = *s;
+ }
+ }
+ *d = '\0';
+}
+
+static void
+print_row(AgendaCtx *ctx, char *s, struct tm *beg, struct tm *end, size_t *num)
+{
+ unescape(s, s);
+
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;
- }
+ for (size_t i, n = 0; *s != '\0'; s++) {
+ switch (*s) {
+ case '\n':
+newline:
+ fputc('\n', stdout);
+ print_header(ctx, beg, end, num);
+ fputs(": ", stdout);
+ n = 0;
+ break;
+ case ' ':
+ case '\t':
+ i = strcspn(s + 1, " \t\n");
+ if (n + i > 70)
+ goto newline;
+ fputc(' ', stdout);
+ n++;
+ break;
+ default:
+ fputc(*s, stdout);
+ n++;
}
- fputc(*cp, stdout);
}
fputc('\n', stdout);
}
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.