From 7953ea0aef6d6d7110c95f368c07c1ac8b6223b8 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 26 Apr 2020 15:57:07 -0400 Subject: Generate index.atom --- concat.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'concat.c') diff --git a/concat.c b/concat.c index 8e165d2..7be35e0 100644 --- a/concat.c +++ b/concat.c @@ -169,7 +169,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { FILE *file = fopen(path, "w"); if (!file) err(EX_CANTCREAT, "%s", path); - error = atomFeedOpen(file, envelope); + error = atomThreadOpen(file, envelope); if (error) err(EX_IOERR, "%s", path); for (size_t i = 0; i < flat.len; ++i) { @@ -178,7 +178,7 @@ static void concatThread(struct List thread, const struct Envelope *envelope) { if (error) err(EX_IOERR, "%s", path); } - error = atomFeedClose(file) || fclose(file); + error = atomThreadClose(file) || fclose(file); if (error) err(EX_IOERR, "%s", path); } @@ -230,6 +230,25 @@ static int compar(const void *_a, const void *_b) { } void concatIndex(struct List threads, const struct Envelope *envelopes) { + const char *path = "index.atom"; + FILE *file = fopen(path, "w"); + if (!file) err(EX_CANTCREAT, "%s", path); + + int error = atomIndexOpen(file); + if (error) err(EX_IOERR, "%s", path); + + struct List flat = {0}; + listFlatten(&flat, threads); + for (size_t i = flat.len - 1; i < flat.len; --i) { + uint32_t uid = dataCheck(flat.ptr[i], Number).number; + error = concatFile(file, uidPath(uid, "atom")); + if (error) err(EX_IOERR, "%s", path); + } + listFree(flat); + + error = atomIndexClose(file) || fclose(file); + if (error) err(EX_IOERR, "%s", path); + struct Sort *order = calloc(threads.len, sizeof(*order)); if (!order) err(EX_OSERR, "calloc"); @@ -245,11 +264,11 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) { } qsort(order, threads.len, sizeof(*order), compar); - const char *path = "index.html"; - FILE *file = fopen(path, "w"); + path = "index.html"; + file = fopen(path, "w"); if (!file) err(EX_CANTCREAT, "%s", path); - int error = htmlIndexHead(file); + error = htmlIndexHead(file); if (error) err(EX_IOERR, "%s", path); if (concatHead) { -- cgit 1.4.1