diff options
Diffstat (limited to '')
-rw-r--r-- | concat.c | 29 |
1 files changed, 24 insertions, 5 deletions
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) { |