diff options
Diffstat (limited to '')
-rw-r--r-- | concat.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/concat.c b/concat.c index a0f451e..04d2e27 100644 --- a/concat.c +++ b/concat.c @@ -80,22 +80,21 @@ static int concatHTML(FILE *file, struct List thread) { int error; for (size_t i = 0; i < thread.len; ++i) { if (thread.ptr[i].type == List) { - error = concatHTML(file, thread.ptr[i].list); + error = 0 + || htmlSubthreadOpen(file) + || concatHTML(file, thread.ptr[i].list) + || htmlSubthreadClose(file); } else { uint32_t uid = dataCheck(thread.ptr[i], Number).number; - error = htmlThreadOpen(file) - || concatFile(file, pathUID(uid, "html")); + error = concatFile(file, pathUID(uid, "html")); } if (error) return error; } - for (size_t i = 0; i < thread.len; ++i) { - if (thread.ptr[i].type == List) continue; - error = htmlThreadClose(file); - if (error) return error; - } return 0; } +const char *concatHead; + void concatData(struct List threads, struct List items) { uint32_t uid = 0; struct Envelope envelope = {0}; @@ -157,5 +156,27 @@ void concatData(struct List threads, struct List items) { if (error) err(EX_IOERR, "%s", path); } + path = pathThread(envelope.messageID, "html"); + error = stat(path, &status); + if (error || status.st_mtime < uidNewest(flat, "html")) { + FILE *file = fopen(path, "w"); + if (!file) err(EX_CANTCREAT, "%s", path); + + error = htmlThreadHead(file, &envelope); + if (error) err(EX_IOERR, "%s", path); + + if (concatHead) { + error = concatFile(file, concatHead); + if (error) err(EX_IOERR, "%s", path); + } + + error = 0 + || htmlThreadOpen(file, &envelope) + || concatHTML(file, thread) + || htmlThreadClose(file) + || fclose(file); + if (error) err(EX_IOERR, "%s", path); + } + listFree(flat); } |