aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make/rules.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-make/rules.c')
-rw-r--r--src/blogc-make/rules.c323
1 files changed, 162 insertions, 161 deletions
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 8464bd2..958641c 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -12,7 +12,8 @@
#include <stdlib.h>
#include <time.h>
#include <math.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "exec.h"
#include "exec-native.h"
@@ -22,75 +23,75 @@
static void
-posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
+posts_ordering(bm_ctx_t *ctx, sb_trie_t *variables, const char *variable)
{
if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL)
return; // something is wrong, let's not add any variable
- const char *value = bc_trie_lookup(ctx->settings->settings, variable);
+ const char *value = sb_trie_lookup(ctx->settings->settings, variable);
if (value != NULL && ((0 == strcmp(value, "ASC")) || (0 == strcmp(value, "asc"))))
return; // user explicitly asked for ASC
- bc_trie_insert(variables, "FILTER_REVERSE", bc_strdup("1"));
+ sb_trie_insert(variables, "FILTER_REVERSE", sb_strdup("1"));
}
static void
-posts_pagination(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
+posts_pagination(bm_ctx_t *ctx, sb_trie_t *variables, const char *variable)
{
if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL)
return; // something is wrong, let's not add any variable
long posts_per_page = strtol(
- bc_trie_lookup(ctx->settings->settings, variable),
+ sb_trie_lookup(ctx->settings->settings, variable),
NULL, 10); // FIXME: improve
if (posts_per_page >= 0) {
- bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(variables, "FILTER_PER_PAGE",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, variable)));
+ sb_trie_insert(variables, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(variables, "FILTER_PER_PAGE",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, variable)));
}
}
// INDEX RULE
-static bc_slist_t*
+static sb_slist_t*
index_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- bc_slist_t *rv = NULL;
- const char *html_ext = bc_trie_lookup(ctx->settings->settings,
+ sb_slist_t *rv = NULL;
+ const char *html_ext = sb_trie_lookup(ctx->settings->settings,
"html_ext");
- const char *index_prefix = bc_trie_lookup(ctx->settings->settings,
+ const char *index_prefix = sb_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,
+ char *f = sb_strdup_printf("%s%s%s%s", ctx->short_output_dir,
is_index ? "" : "/", is_index ? "" : index_prefix,
html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
return rv;
}
static int
-index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+index_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("index"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("index"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -104,7 +105,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -112,39 +113,39 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// ATOM RULE
-static bc_slist_t*
+static sb_slist_t*
atom_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- bc_slist_t *rv = NULL;
- const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
+ sb_slist_t *rv = NULL;
+ const char *atom_prefix = sb_trie_lookup(ctx->settings->settings,
"atom_prefix");
- const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext");
- char *f = bc_strdup_printf("%s/%s%s", ctx->short_output_dir,
+ const char *atom_ext = sb_trie_lookup(ctx->settings->settings, "atom_ext");
+ char *f = sb_strdup_printf("%s/%s%s", ctx->short_output_dir,
atom_prefix, atom_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
return rv;
}
static int
-atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+atom_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "atom_posts_per_page");
posts_ordering(ctx, variables, "atom_order");
- bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ"));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
+ sb_trie_insert(variables, "DATE_FORMAT", sb_strdup("%Y-%m-%dT%H:%M:%SZ"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("atom"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("atom"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -158,7 +159,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -166,27 +167,27 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// ATOM TAGS RULE
-static bc_slist_t*
+static sb_slist_t*
atom_tags_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
- bc_slist_t *rv = NULL;
- const char *atom_prefix = bc_trie_lookup(ctx->settings->settings,
+ sb_slist_t *rv = NULL;
+ const char *atom_prefix = sb_trie_lookup(ctx->settings->settings,
"atom_prefix");
- const char *atom_ext = bc_trie_lookup(ctx->settings->settings, "atom_ext");
+ const char *atom_ext = sb_trie_lookup(ctx->settings->settings, "atom_ext");
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 = sb_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
atom_prefix, ctx->settings->tags[i], atom_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+atom_tags_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
@@ -194,20 +195,20 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t i = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "atom_posts_per_page");
posts_ordering(ctx, variables, "atom_order");
- bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ"));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom_tags"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
+ sb_trie_insert(variables, "DATE_FORMAT", sb_strdup("%Y-%m-%dT%H:%M:%SZ"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("atom_tags"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("atom"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, i++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, i++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_TAG",
- bc_strdup(ctx->settings->tags[i]));
+ sb_trie_insert(variables, "FILTER_TAG",
+ sb_strdup(ctx->settings->tags[i]));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL,
fctx, false))
@@ -219,7 +220,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -227,38 +228,38 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// PAGINATION RULE
-static bc_slist_t*
+static sb_slist_t*
pagination_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- long num_posts = bc_slist_length(ctx->posts_fctx);
+ long num_posts = sb_slist_length(ctx->posts_fctx);
long posts_per_page = strtol(
- bc_trie_lookup(ctx->settings->settings, "posts_per_page"),
+ sb_trie_lookup(ctx->settings->settings, "posts_per_page"),
NULL, 10); // FIXME: improve
if (posts_per_page <= 0)
return NULL;
size_t pages = ceilf(((float) num_posts) / posts_per_page);
- const char *pagination_prefix = bc_trie_lookup(ctx->settings->settings,
+ const char *pagination_prefix = sb_trie_lookup(ctx->settings->settings,
"pagination_prefix");
- const char *html_ext = bc_trie_lookup(ctx->settings->settings,
+ const char *html_ext = sb_trie_lookup(ctx->settings->settings,
"html_ext");
- bc_slist_t *rv = NULL;
+ sb_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 = sb_strdup_printf("%s/%s/%d%s", ctx->short_output_dir,
pagination_prefix, i + 1, html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+pagination_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
@@ -266,22 +267,22 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t page = 1;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
// not using posts_pagination because we set FILTER_PAGE anyway, and the
// first value inserted in that function would be useless
- bc_trie_insert(variables, "FILTER_PER_PAGE",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "posts_per_page")));
+ sb_trie_insert(variables, "FILTER_PER_PAGE",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "posts_per_page")));
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pagination"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("pagination"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, page++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, page++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_PAGE", bc_strdup_printf("%zu", page));
+ sb_trie_insert(variables, "FILTER_PAGE", sb_strdup_printf("%zu", page));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->main_template_fctx, fctx, false))
{
@@ -292,7 +293,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -300,44 +301,44 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// POSTS RULE
-static bc_slist_t*
+static sb_slist_t*
posts_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- const char *post_prefix = bc_trie_lookup(ctx->settings->settings,
+ const char *post_prefix = sb_trie_lookup(ctx->settings->settings,
"post_prefix");
- const char *html_ext = bc_trie_lookup(ctx->settings->settings,
+ const char *html_ext = sb_trie_lookup(ctx->settings->settings,
"html_ext");
- bc_slist_t *rv = NULL;
+ sb_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 = sb_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
post_prefix, ctx->settings->posts[i], html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+posts_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "IS_POST", bc_strdup("1"));
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "IS_POST", sb_strdup("1"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "date_format")));
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("posts"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("posts"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->posts_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -349,17 +350,17 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(s, ctx->settings_fctx,
ctx->main_template_fctx, o_fctx, true))
{
- bc_trie_t *local = bc_trie_new(NULL);
- bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
+ sb_trie_t *local = sb_trie_new(NULL);
+ sb_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
rv = bm_exec_blogc(ctx, variables, local, false, ctx->main_template_fctx,
o_fctx, s, true);
- bc_trie_free(local);
+ sb_trie_free(local);
if (rv != 0)
break;
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -367,27 +368,27 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// TAGS RULE
-static bc_slist_t*
+static sb_slist_t*
tags_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
- bc_slist_t *rv = NULL;
- const char *tag_prefix = bc_trie_lookup(ctx->settings->settings,
+ sb_slist_t *rv = NULL;
+ const char *tag_prefix = sb_trie_lookup(ctx->settings->settings,
"tag_prefix");
- const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext");
+ const char *html_ext = sb_trie_lookup(ctx->settings->settings, "html_ext");
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 = sb_strdup_printf("%s/%s/%s%s", ctx->short_output_dir,
tag_prefix, ctx->settings->tags[i], html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+tags_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
@@ -395,21 +396,21 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t i = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "atom_posts_per_page");
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("tags"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("tags"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, i++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, i++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_TAG",
- bc_strdup(ctx->settings->tags[i]));
+ sb_trie_insert(variables, "FILTER_TAG",
+ sb_strdup(ctx->settings->tags[i]));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->main_template_fctx, fctx, false))
@@ -421,7 +422,7 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -429,42 +430,42 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// PAGES RULE
-static bc_slist_t*
+static sb_slist_t*
pages_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->pages == NULL)
return NULL;
- const char *html_ext = bc_trie_lookup(ctx->settings->settings, "html_ext");
+ const char *html_ext = sb_trie_lookup(ctx->settings->settings, "html_ext");
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
for (size_t i = 0; ctx->settings->pages[i] != NULL; i++) {
bool is_index = (0 == strcmp(ctx->settings->pages[i], "index"))
&& (html_ext[0] == '/');
- char *f = bc_strdup_printf("%s%s%s%s", ctx->short_output_dir,
+ char *f = sb_strdup_printf("%s%s%s%s", ctx->short_output_dir,
is_index ? "" : "/", is_index ? "" : ctx->settings->pages[i],
html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+pages_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->pages == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bc_trie_lookup(ctx->settings->settings, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pages"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("page"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(sb_trie_lookup(ctx->settings->settings, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("pages"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("page"));
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->pages_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -476,17 +477,17 @@ pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(s, ctx->settings_fctx,
ctx->main_template_fctx, o_fctx, true))
{
- bc_trie_t *local = bc_trie_new(NULL);
- bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
+ sb_trie_t *local = sb_trie_new(NULL);
+ sb_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
rv = bm_exec_blogc(ctx, variables, local, false, ctx->main_template_fctx,
o_fctx, s, true);
- bc_trie_free(local);
+ sb_trie_free(local);
if (rv != 0)
break;
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -494,33 +495,33 @@ pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// COPY FILES RULE
-static bc_slist_t*
+static sb_slist_t*
copy_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->copy == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
// we iterate over ctx->copy_fctx list instead of ctx->settings->copy,
// because bm_ctx_new() expands directories into its files, recursively.
- for (bc_slist_t *s = ctx->copy_fctx; s != NULL; s = s->next) {
- char *f = bc_strdup_printf("%s/%s", ctx->short_output_dir,
+ for (sb_slist_t *s = ctx->copy_fctx; s != NULL; s = s->next) {
+ char *f = sb_strdup_printf("%s/%s", ctx->short_output_dir,
((bm_filectx_t*) s->data)->short_path);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
return rv;
}
static int
-copy_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+copy_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->copy == NULL)
return 0;
int rv = 0;
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->copy_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -542,18 +543,18 @@ copy_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// CLEAN RULE
-static bc_slist_t*
+static sb_slist_t*
clean_outputlist(bm_ctx_t *ctx)
{
return bm_rule_list_built_files(ctx);
}
static int
-clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+clean_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
int rv = 0;
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -573,21 +574,21 @@ clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
-static int all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args);
+static int all_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args);
// RUNSERVER RULE
static int
-runserver_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+runserver_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
bm_reloader_t *reloader = bm_reloader_new(ctx, all_exec, outputs, args);
if (reloader == NULL) {
return 3;
}
- int rv = bm_exec_blogc_runserver(ctx, bc_trie_lookup(args, "host"),
- bc_trie_lookup(args, "port"), bc_trie_lookup(args, "threads"));
+ int rv = bm_exec_blogc_runserver(ctx, sb_trie_lookup(args, "host"),
+ sb_trie_lookup(args, "port"), sb_trie_lookup(args, "threads"));
bm_reloader_stop(reloader);
return rv;
@@ -680,7 +681,7 @@ const bm_rule_t rules[] = {
// ALL RULE
static int
-all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+all_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
for (size_t i = 0; rules[i].name != NULL; i++) {
if (!rules[i].generate_files) {
@@ -696,30 +697,30 @@ all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
-bc_trie_t*
+sb_trie_t*
bm_rule_parse_args(const char *sep)
{
if (sep == NULL || *sep == '\0' || *sep != ':')
return NULL;
- bc_trie_t *rv = bc_trie_new(free);
+ sb_trie_t *rv = sb_trie_new(free);
char *end = (char*) sep + 1;
char *kv_sep;
while (NULL != (kv_sep = strchr(end, '='))) {
- char *key = bc_strndup(end, kv_sep - end);
+ char *key = sb_strndup(end, kv_sep - end);
end = kv_sep + 1;
kv_sep = strchr(end, ',');
if (kv_sep == NULL)
kv_sep = strchr(end, '\0');
- char *value = bc_strndup(end, kv_sep - end);
- bc_trie_insert(rv, key, value);
+ char *value = sb_strndup(end, kv_sep - end);
+ sb_trie_insert(rv, key, value);
free(key);
if (*kv_sep == '\0')
break;
end = kv_sep + 1;
}
if (kv_sep == NULL) {
- bc_trie_free(rv);
+ sb_trie_free(rv);
return NULL;
}
return rv;
@@ -727,7 +728,7 @@ bm_rule_parse_args(const char *sep)
int
-bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
+bm_rule_executor(bm_ctx_t *ctx, sb_slist_t *rule_list)
{
if (ctx == NULL)
return 3;
@@ -735,12 +736,12 @@ bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
const bm_rule_t *rule = NULL;
int rv = 0;
- for (bc_slist_t *l = rule_list; l != NULL; l = l->next) {
+ for (sb_slist_t *l = rule_list; l != NULL; l = l->next) {
char *rule_str = l->data;
char *sep = strchr(rule_str, ':');
- bc_trie_t *args = NULL;
+ sb_trie_t *args = NULL;
if (sep == NULL) {
sep = strchr(rule_str, '\0');
}
@@ -775,26 +776,26 @@ bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
int
-bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, bc_trie_t *args)
+bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, sb_trie_t *args)
{
if (ctx == NULL || rule == NULL)
return 3;
- bc_slist_t *outputs = NULL;
+ sb_slist_t *outputs = NULL;
if (rule->outputlist_func != NULL) {
outputs = rule->outputlist_func(ctx);
}
int rv = rule->exec_func(ctx, outputs, args);
- bc_slist_free_full(outputs, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(outputs, (sb_free_func_t) bm_filectx_free);
return rv;
}
bool
-bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
+bm_rule_need_rebuild(sb_slist_t *sources, bm_filectx_t *settings,
bm_filectx_t *template, bm_filectx_t *output, bool only_first_source)
{
if (output == NULL || !output->readable)
@@ -802,19 +803,19 @@ bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
bool rv = false;
- bc_slist_t *s = NULL;
+ sb_slist_t *s = NULL;
if (settings != NULL)
- s = bc_slist_append(s, settings);
+ s = sb_slist_append(s, settings);
if (template != NULL)
- s = bc_slist_append(s, template);
+ s = sb_slist_append(s, template);
- for (bc_slist_t *l = sources; l != NULL; l = l->next) {
- s = bc_slist_append(s, l->data);
+ for (sb_slist_t *l = sources; l != NULL; l = l->next) {
+ s = sb_slist_append(s, l->data);
if (only_first_source)
break;
}
- for (bc_slist_t *l = s; l != NULL; l = l->next) {
+ for (sb_slist_t *l = s; l != NULL; l = l->next) {
bm_filectx_t *source = l->data;
if (source == NULL || !source->readable) {
// this is unlikely to happen, but lets just say that we need
@@ -834,29 +835,29 @@ bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
}
}
- bc_slist_free(s);
+ sb_slist_free(s);
return rv;
}
-bc_slist_t*
+sb_slist_t*
bm_rule_list_built_files(bm_ctx_t *ctx)
{
if (ctx == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
for (size_t i = 0; rules[i].name != NULL; i++) {
if (!rules[i].generate_files) {
continue;
}
- bc_slist_t *o = rules[i].outputlist_func(ctx);
- for (bc_slist_t *l = o; l != NULL; l = l->next) {
- rv = bc_slist_append(rv, l->data);
+ sb_slist_t *o = rules[i].outputlist_func(ctx);
+ for (sb_slist_t *l = o; l != NULL; l = l->next) {
+ rv = sb_slist_append(rv, l->data);
}
- bc_slist_free(o);
+ sb_slist_free(o);
}
return rv;
}