From c16c86bcc01dff2a984aeffd58e2402a876cc12d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 24 Jul 2018 02:27:48 +0200 Subject: make: handle empty prefixes properly still needs to add integration tests --- src/blogc-make/rules.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/blogc-make/rules.c') diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index 8851313..2f4b119 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -82,10 +82,9 @@ index_outputlist(bm_ctx_t *ctx) "html_ext"); const char *index_prefix = bc_trie_lookup(ctx->settings->settings, "index_prefix"); - bool is_index = (index_prefix == NULL) && (html_ext[0] == '/'); - char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, - is_index ? "" : "/", is_index ? "" : index_prefix, - html_ext); + const char *slash = index_prefix[0] == '\0' && html_ext[0] == '/' ? "" : "/"; + char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, slash, + index_prefix, html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); return rv; @@ -141,8 +140,9 @@ atom_outputlist(bm_ctx_t *ctx) bc_slist_t *rv = NULL; const char *atom_prefix = bc_trie_lookup(ctx->settings->settings, "atom_prefix"); + const char *slash = atom_prefix[0] == '\0' ? "" : "/"; const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext"); - char *f = bc_strdup_printf("%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir, slash, atom_prefix, atom_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -199,8 +199,9 @@ atom_tags_outputlist(bm_ctx_t *ctx) const char *atom_prefix = bc_trie_lookup(ctx->settings->settings, "atom_prefix"); const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext"); + const char *slash = atom_prefix[0] == '\0' ? "" : "/"; for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, atom_prefix, ctx->settings->tags[i], atom_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -271,10 +272,11 @@ pagination_outputlist(bm_ctx_t *ctx) "pagination_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = pagination_prefix[0] == '\0' ? "" : "/"; bc_slist_t *rv = NULL; for (size_t i = 0; i < pages; i++) { - char *f = bc_strdup_printf("%s/%s/%d%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%d%s", ctx->short_output_dir, slash, pagination_prefix, i + 1, html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -335,10 +337,11 @@ posts_outputlist(bm_ctx_t *ctx) "post_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = post_prefix[0] == '\0' ? "" : "/"; bc_slist_t *rv = NULL; for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, post_prefix, ctx->settings->posts[i], html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); @@ -405,8 +408,9 @@ tags_outputlist(bm_ctx_t *ctx) const char *tag_prefix = bc_trie_lookup(ctx->settings->settings, "tag_prefix"); const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext"); + const char *slash = tag_prefix[0] == '\0' ? "" : "/"; for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) { - char *f = bc_strdup_printf("%s/%s/%s%s", ctx->short_output_dir, + char *f = bc_strdup_printf("%s%s%s/%s%s", ctx->short_output_dir, slash, tag_prefix, ctx->settings->tags[i], html_ext); rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL)); free(f); -- cgit v1.2.3-18-g5258