sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 51480739874ea7070d37a7a09b0df09efedbae83
parent c61b6bf465d94b1618acd5dfc5c3c01d65818061
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  2 Aug 2015 13:04:42 +0200

sfeed_mbox: improvements

- don't xmlencode HTML, show as is.
- mangle "From " mboxrd-style. Content-Length would be cleaner but would
  require extra buffering.

Diffstat:
Msfeed_mbox.c | 48+++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/sfeed_mbox.c b/sfeed_mbox.c @@ -13,6 +13,48 @@ static char *line = NULL; static size_t linesize = 0; +/* Unescape / decode fields printed by string_print_encoded() + * "\\" to "\", "\t", to TAB, "\n" to newline. Unrecognised escape sequences + * are ignored: "\z" etc. Mangle "From " in mboxrd style (always prefix >). */ +static void +printcontent(const char *s, FILE *fp) +{ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + + for (; *s; s++) { +read: + switch (*s) { + case '\\': + switch (*(++s)) { + case '\0': return; /* ignore */ + case '\\': fputc('\\', fp); break; + case 't': fputc('\t', fp); break; + case 'n': + fputc('\n', fp); + for (s++; *s && *s == '>'; s++) + fputc('>', fp); + /* escape "From ", mboxrd-style. */ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + goto read; + } + break; + case '\0': return; /* ignore */ + case '\n': + fputc((int)*s, fp); + for (s++; *s && *s == '>'; s++) + fputc('>', fp); + /* escape "From ", mboxrd-style. */ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + goto read; + default: + fputc((int)*s, fp); + } + } +} + static void printfeed(FILE *fp, const char *feedname) { @@ -61,14 +103,14 @@ printfeed(FILE *fp, const char *feedname) if (!strcmp(fields[FieldContentType], "html")) { fputs("<p>Link: <a href=\"", stdout); - print(fields[FieldLink], stdout, xmlencode); + xmlencode(fields[FieldLink], stdout); fputs("\">", stdout); fputs(fields[FieldLink], stdout); fputs("</a></p>\n\n", stdout); - decodefield(fields[FieldContent], stdout, fputc); + printcontent(fields[FieldContent], stdout); } else { printf("Link: %s\n\n", fields[FieldLink]); - decodefield(fields[FieldContent], stdout, fputc); + printcontent(fields[FieldContent], stdout); } fputs("\n\n", stdout); }