ssnail

crappy and opinionated static site generator
git clone https://git.e1e0.net/ssnail.git
Log | Files | Refs | README | LICENSE

commit 24e872edefd049f3f8485a32926fc66849d5a837
parent d1efcd2e6c7ee45f1370cd3e7d8990934dee3b98
Author: Paco Esteban <paco@e1e0.net>
Date:   Tue, 30 Jun 2020 12:36:38 +0200

consistent return (ssnail_error) for gen_html

Diffstat:
Mssnail.c | 57++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/ssnail.c b/ssnail.c @@ -62,8 +62,7 @@ static struct article *populate_article_entry(char *, char *); static const struct ssnail_error *process_dir(char *, char *, int); static const struct ssnail_error *write_html(struct article *, char *, char *); static const struct ssnail_error *article_sort(struct listhead *); - -static int gen_html(struct article *); +static const struct ssnail_error *gen_html(struct article *); __dead static void usage(void) @@ -122,6 +121,7 @@ main(int argc, char *argv[]) argv += optind; LIST_INIT(&head); /* init the linked list */ + /* src and dst dir are mandatory. */ if (argc < 2) usage(); @@ -151,6 +151,7 @@ done: ssnail_error_fprintf(error); return error->code; } + return EXIT_SUCCESS; } @@ -174,14 +175,14 @@ articleq_free(struct listhead *h) } } -static int +static const struct ssnail_error * gen_html(struct article *a) { - struct lowdown_opts opts; - struct lowdown_metaq mq; - struct lowdown_meta *md; - int r = -1; - size_t orig_size = 0; + struct lowdown_opts opts; + struct lowdown_metaq mq; + struct lowdown_meta *md; + const struct ssnail_error *error = NULL; + size_t orig_size = 0; TAILQ_INIT(&mq); /* create the queue(linked list) of lowdown_meta */ memset(&opts, 0, sizeof(struct lowdown_opts)); /* init opts to 0 */ @@ -209,49 +210,59 @@ gen_html(struct article *a) &a->html_content, &a->htmlz, &mq); /* set default values for metadata */ - a->title = strdup(""); - if (a->title == NULL) + if ((a->title = strdup("")) == NULL) { + error = ssnail_error_from_errno("malloc def title"); goto out; - a->author = strdup(""); - if (a->author == NULL) + } + if ((a->author = strdup("")) == NULL) { + error = ssnail_error_from_errno("malloc def author"); goto out; - a->date = strdup(""); - if (a->date == NULL) + } + if ((a->date = strdup("")) == NULL) { + error = ssnail_error_from_errno("malloc def date"); goto out; - a->type = strdup("page"); - if (a->type == NULL) + } + if ((a->type = strdup("page")) == NULL) { + error = ssnail_error_from_errno("malloc def type"); goto out; + } /* collect metadata from markdown */ TAILQ_FOREACH(md, &mq, entries) { if (strcmp(md->key, "title") == 0 ) { free(a->title); - if (asprintf(&a->title, "%s", md->value) == -1) + if (asprintf(&a->title, "%s", md->value) == -1) { + error = ssnail_error_msg(2, "malloc title"); goto out; + } } if (strcmp(md->key, "author") == 0 ) { free(a->author); - if (asprintf(&a->author, "%s", md->value) == -1) + if (asprintf(&a->author, "%s", md->value) == -1) { + error = ssnail_error_msg(2, "malloc author"); goto out; + } } if (strcmp(md->key, "date") == 0 ) { free(a->date); - if (asprintf(&a->date, "%s", md->value) == -1) + if (asprintf(&a->date, "%s", md->value) == -1) { + error = ssnail_error_msg(2, "malloc date"); goto out; + } } if (strcmp(md->key, "type") == 0 ) { free(a->type); - if (asprintf(&a->type, "%s", md->value) == -1) + if (asprintf(&a->type, "%s", md->value) == -1) { + error = ssnail_error_msg(2, "malloc type"); goto out; + } } } - r = 0; - out: lowdown_metaq_free(&mq); - return r; + return error; } static const struct ssnail_error *