From a4d4e766e38c7c8aa0c842e6de84b912c9fcaed7 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 29 Nov 2020 00:50:33 -0500 Subject: Revert to old quoting style in atom --- archive.h | 8 +++++ atom.c | 110 +++++++++++++++++++++++++++++--------------------------------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/archive.h b/archive.h index 3328340..8576df5 100644 --- a/archive.h +++ b/archive.h @@ -172,6 +172,14 @@ void concatData( void concatThreads(struct List threads, const struct Envelope *envelopes); void concatIndex(struct List threads, const struct Envelope *envelopes); +static inline struct ISO8601 { + char s[sizeof("0000-00-00T00:00:00Z")]; +} iso8601(time_t time) { + struct ISO8601 buf; + strftime(buf.s, sizeof(buf.s), "%FT%TZ", gmtime(&time)); + return buf; +} + struct Variable { const char *name; const char *value; diff --git a/atom.c b/atom.c index ddfb3f6..16215df 100644 --- a/atom.c +++ b/atom.c @@ -41,22 +41,6 @@ static char *atomID(const struct Envelope *envelope) { return templateString("mid:[messageID]", vars, escapeURL); } -static int atomAuthor(FILE *file, struct Address addr) { - const char *template = { - Q() - Q([name]) - Q([mailbox]@[host]) - Q() - }; - struct Variable vars[] = { - { "name", addressName(addr) }, - { "mailbox", addr.mailbox }, - { "host", addr.host }, - {0}, - }; - return templateRender(file, template, vars, escapeXML); -} - static char *atomEntryURL(const struct Envelope *envelope) { struct Variable vars[] = { { "messageID", envelope->messageID }, @@ -66,26 +50,36 @@ static char *atomEntryURL(const struct Envelope *envelope) { return templateString("/" PATH_MESSAGE, vars, escapeURL); } -static const char *atomUpdated(time_t time) { - static char buf[sizeof("0000-00-00T00:00:00Z")]; - strftime(buf, sizeof(buf), "%FT%TZ", gmtime(&time)); - return buf; +static int atomAuthor(FILE *file, struct Address addr) { + const char *template = Q( + + [name] + [mailbox]@[host] + + ); + struct Variable vars[] = { + { "name", addressName(addr) }, + { "mailbox", addr.mailbox }, + { "host", addr.host }, + {0}, + }; + return templateRender(file, template, vars, escapeXML); } int atomEntryOpen(FILE *file, const struct Envelope *envelope) { - const char *template = { - Q() - Q([id]) - Q([title]) - Q([updated]) - Q() - }; char *id = atomID(envelope); char *url = atomEntryURL(envelope); + const char *template = Q( + + [id] + [title] + [updated] + + ); struct Variable vars[] = { { "id", id }, { "title", envelope->subject }, - { "updated", atomUpdated(envelope->time) }, + { "updated", iso8601(envelope->time).s }, { "base", baseURL }, { "url", url }, {0}, @@ -99,13 +93,13 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) { } int atomContent(FILE *file, const char *content) { - const char *template = { - Q() - Q(
) - Q(
[content]
) - Q(
) - Q(
) - }; + const char *template = Q( + +
+
[content]
+
+
+ ); struct Variable vars[] = { { "content", content }, {0}, @@ -126,27 +120,28 @@ static char *atomThreadURL(const struct Envelope *envelope, const char *type) { return templateString("/" PATH_THREAD, vars, escapeURL); } +#define XML_DECL "" + int atomThreadOpen(FILE *file, const struct Envelope *envelope) { - const char *template = { - "" - Q() - Q(bubger) - Q([id]) - Q([title]) - Q([updated]) - Q() - Q() - Q() - }; char *id = atomID(envelope); char *atom = atomThreadURL(envelope, "atom"); char *html = atomThreadURL(envelope, "html"); char *mbox = atomThreadURL(envelope, "mbox"); + const char *template = XML_DECL Q( + + bubger + [id] + [title] + [updated] + + + + ); struct Variable vars[] = { { "generator", GENERATOR_URL }, { "id", id }, { "title", envelope->subject }, - { "updated", atomUpdated(time(NULL)) }, + { "updated", iso8601(time(NULL)).s }, { "base", baseURL }, { "atom", atom }, { "html", html }, @@ -168,21 +163,20 @@ int atomThreadClose(FILE *file) { } int atomIndexOpen(FILE *file) { - const char *template = { - "" - Q() - Q(bubger) - Q(mailto:[mailto]) - Q([title]) - Q([updated]) - Q() - Q() - }; + const char *template = XML_DECL Q( + + bubger + mailto:[mailto] + [title] + [updated] + + + ); struct Variable vars[] = { { "generator", GENERATOR_URL }, { "mailto", baseMailto }, { "title", baseTitle }, - { "updated", atomUpdated(time(NULL)) }, + { "updated", iso8601(time(NULL)).s }, { "base", baseURL }, {0}, }; -- cgit 1.4.1