diff options
Diffstat (limited to 'src/blogc-make')
-rw-r--r-- | src/blogc-make/atom.c | 41 | ||||
-rw-r--r-- | src/blogc-make/atom.h | 1 | ||||
-rw-r--r-- | src/blogc-make/rules.c | 22 |
3 files changed, 52 insertions, 12 deletions
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c index 9dde35e..207b718 100644 --- a/src/blogc-make/atom.c +++ b/src/blogc-make/atom.c @@ -48,20 +48,11 @@ static const char atom_template[] = char* -bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) +bm_atom_generate(bm_settings_t *settings) { - if (settings == NULL || err == NULL || *err != NULL) + if (settings == NULL) return NULL; - // this is not really portable - char fname[] = "/tmp/blogc-make_XXXXXX"; - int fd; - if (-1 == (fd = mkstemp(fname))) { - *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, - "Failed to create temporary atom template: %s", strerror(errno)); - return NULL; - } - const char *atom_prefix = bc_trie_lookup(settings->settings, "atom_prefix"); const char *atom_ext = bc_trie_lookup(settings->settings, "atom_ext"); const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix"); @@ -93,13 +84,39 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) entry_id = bc_strdup(post_url); } - char *content = bc_strdup_printf(atom_template, atom_url->str, atom_url->str, + char *rv = bc_strdup_printf(atom_template, atom_url->str, atom_url->str, entry_id, post_url); bc_string_free(atom_url, true); free(post_url); free(entry_id); + return rv; +} + + +char* +bm_atom_deploy(bm_settings_t *settings, bc_error_t **err) +{ + if (settings == NULL || err == NULL || *err != NULL) + return NULL; + + // this is not really portable + char fname[] = "/tmp/blogc-make_XXXXXX"; + int fd; + if (-1 == (fd = mkstemp(fname))) { + *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, + "Failed to create temporary atom template: %s", strerror(errno)); + return NULL; + } + + char *content = bm_atom_generate(settings); + if (content == NULL) { + close(fd); + unlink(fname); + return NULL; + } + if (-1 == write(fd, content, strlen(content))) { *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM, "Failed to write to temporary atom template: %s", strerror(errno)); diff --git a/src/blogc-make/atom.h b/src/blogc-make/atom.h index 9f47adc..ed3875d 100644 --- a/src/blogc-make/atom.h +++ b/src/blogc-make/atom.h @@ -12,6 +12,7 @@ #include "../common/error.h" #include "settings.h" +char* bm_atom_generate(bm_settings_t *settings); char* bm_atom_deploy(bm_settings_t *settings, bc_error_t **err); void bm_atom_destroy(const char *fname); diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c index 9d599cc..d95edd8 100644 --- a/src/blogc-make/rules.c +++ b/src/blogc-make/rules.c @@ -13,6 +13,7 @@ #include <time.h> #include <math.h> #include "../common/utils.h" +#include "atom.h" #include "ctx.h" #include "exec.h" #include "exec-native.h" @@ -626,6 +627,20 @@ watch_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) } +// ATOM DUMP RULE + +static int +atom_dump_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args) +{ + char *content = bm_atom_generate(ctx->settings); + if (content == NULL) + return 3; + printf("%s", content); + free(content); + return 0; +} + + const bm_rule_t rules[] = { { .name = "all", @@ -713,6 +728,13 @@ const bm_rule_t rules[] = { .exec_func = watch_exec, .generate_files = false, }, + { + .name = "atom_dump", + .help = "dump default Atom feed template based on current settings", + .outputlist_func = NULL, + .exec_func = atom_dump_exec, + .generate_files = false, + }, {NULL, NULL, NULL, NULL, false}, }; |