From 6f26bf203b485033762b070fc895761923e510f2 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sun, 17 May 2020 22:53:42 +0930 Subject: change how file modification functions work we use to assume we're definitely editing something in output_dir, now we don't assume that, the caller must tell us so --- config.h | 4 +++- pages.c | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/config.h b/config.h index 1404b90..67b497a 100644 --- a/config.h +++ b/config.h @@ -25,6 +25,7 @@ enum flag RSSIMAGES = 1<<2, PINNED = 1<<3, GIRLNUMBERS = 1<<4, + READMORETAG = 1<<5, }; struct page @@ -99,6 +100,7 @@ static const char *direct_output_dir = "posts/direct/"; static const int posts_per_page = 10; static const int ignore[] = {}; /* ignore these posts */ static const int pinned[] = {112, 107, 104}; /* pinned posts */ +static const char *read_more_tag = "[READMORE]"; /* rss */ static const char *rss_output = "posts/posts.rss"; @@ -123,7 +125,7 @@ static const struct page pages[] = { {opinions_animepage, NONE}, {opinions_everythingpage, NONE}, {portfoliopage, NONE}, - {postspage, RSS|RSSIMAGES|PINNED|GIRLNUMBERS}, /* flags: RSS feed, RSS images, pinned posts, girl numbers */ + {postspage, RSS|RSSIMAGES|PINNED|GIRLNUMBERS|READMORETAG}, /* flags: RSS feed, RSS images, pinned posts, girl numbers, read more tag */ }; #endif diff --git a/pages.c b/pages.c index 9e2a9c0..85d6d82 100644 --- a/pages.c +++ b/pages.c @@ -45,7 +45,7 @@ int createfile(const char *file, const char *template) { /* - * create file at location 'output_dir'/file' using the template 'template' + * create file at location 'file' using the template 'template' * overwrite if it exists * assume the caller has put us in the base directory already */ @@ -96,7 +96,7 @@ long findstring(const char *file, const char *str) { /* - * find first occurance of substring 'str' in file 'output_dir'/'file' + * find first occurance of substring 'str' in file 'file' * return offset of string beginning * -1 on error (including not found) * @@ -107,7 +107,7 @@ findstring(const char *file, const char *str) long offset = -1; char filename[512] = {0}; - snprintf(filename, 512, "%s%s", output_dir, file); + snprintf(filename, 512, "%s", file); FILE *in = fopen(filename, "r"); if (!in) @@ -157,12 +157,12 @@ int deletebytes(const char *file, long offset, size_t bytes) { /* - * delete 'bytes' bytes from 'output_dir'/'file' starting at offset 'offset' + * delete 'bytes' bytes from 'file' starting at offset 'offset' * return 1 on success. 0 on failure */ char filename[512] = {0}; - snprintf(filename, 512, "%s%s", output_dir, file); + snprintf(filename, 512, "%s", file); FILE *in = fopen(filename, "r"); if (!in) @@ -225,7 +225,7 @@ writeatbyte(const char *dest, struct fileorstring *source, long offset) * return 1 on success. 0 on failure */ char filename[512] = {0}; - snprintf(filename, 512, "%s%s", output_dir, dest); + snprintf(filename, 512, "%s", dest); FILE *in = fopen(filename, "r"); if (!in) @@ -334,19 +334,22 @@ replaceinpage(const char *outfile, const char *toreplace, struct fileorstring *s long substrpos = -1; - substrpos = findstring(outfile, toreplace); + char out[512] = {0}; + snprintf(out, 512, "%s/%s", output_dir, outfile); + + substrpos = findstring(out, toreplace); if (substrpos < 0) { return 0; } - if (!deletebytes(outfile, substrpos, strlen(toreplace))) + if (!deletebytes(out, substrpos, strlen(toreplace))) { return 0; } - if (!writeatbyte(outfile, source, substrpos)) + if (!writeatbyte(out, source, substrpos)) { return 0; } @@ -657,7 +660,16 @@ writeposts(const int *posts, size_t totalposts, const char *outfile, int current fclose(postfile); } fprintf(tmp, "%s\n", pagebar); + fclose(tmp); + + if (flags & READMORETAG) + { + // TODO + //long readmorepos = findstring("post.tmp", read_more_tag); + //printf("got: %ld\n", readmorepos); + } + struct fileorstring replacement = {"post.tmp", NULL}; if (!replaceinpage(outfile, content_string, &replacement)) { -- cgit v1.2.3