aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-make')
-rw-r--r--src/blogc-make/atom.c21
-rw-r--r--src/blogc-make/atom.h5
-rw-r--r--src/blogc-make/ctx.c80
-rw-r--r--src/blogc-make/ctx.h14
-rw-r--r--src/blogc-make/error.c36
-rw-r--r--src/blogc-make/error.h20
-rw-r--r--src/blogc-make/exec-native.c31
-rw-r--r--src/blogc-make/exec-native.h5
-rw-r--r--src/blogc-make/exec.c156
-rw-r--r--src/blogc-make/exec.h12
-rw-r--r--src/blogc-make/main.c23
-rw-r--r--src/blogc-make/reloader.c7
-rw-r--r--src/blogc-make/reloader.h9
-rw-r--r--src/blogc-make/rules.c323
-rw-r--r--src/blogc-make/rules.h19
-rw-r--r--src/blogc-make/settings.c71
-rw-r--r--src/blogc-make/settings.h11
17 files changed, 454 insertions, 389 deletions
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c
index d5f5387..327d39b 100644
--- a/src/blogc-make/atom.c
+++ b/src/blogc-make/atom.c
@@ -10,8 +10,9 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
+#include "error.h"
#include "settings.h"
#include "atom.h"
@@ -49,7 +50,7 @@ static const char atom_template[] =
char*
-bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
+bm_atom_deploy(bm_settings_t *settings, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
@@ -58,20 +59,20 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
char fname[] = "/tmp/blogc-make_XXXXXX";
int fd;
if (-1 == (fd = mkstemp(fname))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
+ *err = sb_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");
+ const char *atom_prefix = sb_trie_lookup(settings->settings, "atom_prefix");
+ const char *atom_ext = sb_trie_lookup(settings->settings, "atom_ext");
+ const char *post_prefix = sb_trie_lookup(settings->settings, "post_prefix");
- char *content = bc_strdup_printf(atom_template, atom_prefix, atom_ext,
+ char *content = sb_strdup_printf(atom_template, atom_prefix, atom_ext,
atom_prefix, atom_ext, post_prefix, post_prefix);
if (-1 == write(fd, content, strlen(content))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
"Failed to write to temporary atom template: %s", strerror(errno));
free(content);
close(fd);
@@ -82,7 +83,7 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
free(content);
close(fd);
- return bc_strdup(fname);
+ return sb_strdup(fname);
}
diff --git a/src/blogc-make/atom.h b/src/blogc-make/atom.h
index 9f47adc..0bf8bdb 100644
--- a/src/blogc-make/atom.h
+++ b/src/blogc-make/atom.h
@@ -9,10 +9,11 @@
#ifndef _MAKE_ATOM_H
#define _MAKE_ATOM_H
-#include "../common/error.h"
+#include <squareball.h>
+
#include "settings.h"
-char* bm_atom_deploy(bm_settings_t *settings, bc_error_t **err);
+char* bm_atom_deploy(bm_settings_t *settings, sb_error_t **err);
void bm_atom_destroy(const char *fname);
#endif /* _MAKE_ATOM_H */
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index 0a3f9a0..2784268 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -14,10 +14,10 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "atom.h"
+#include "error.h"
#include "settings.h"
#include "exec.h"
#include "ctx.h"
@@ -30,13 +30,13 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
if (ctx == NULL || filename == NULL)
return NULL;
- char *f = filename[0] == '/' ? bc_strdup(filename) :
- bc_strdup_printf("%s/%s", ctx->root_dir, filename);
+ char *f = filename[0] == '/' ? sb_strdup(filename) :
+ sb_strdup_printf("%s/%s", ctx->root_dir, filename);
- bm_filectx_t *rv = bc_malloc(sizeof(bm_filectx_t));
+ bm_filectx_t *rv = sb_malloc(sizeof(bm_filectx_t));
rv->path = f;
- rv->short_path = bc_strdup(filename);
- rv->slug = bc_strdup(slug);
+ rv->short_path = sb_strdup(filename);
+ rv->slug = sb_strdup(slug);
if (st == NULL) {
struct stat buf;
@@ -59,14 +59,14 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
}
-bc_slist_t*
-bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
+sb_slist_t*
+bm_filectx_new_r(sb_slist_t *l, bm_ctx_t *ctx, const char *filename)
{
if (ctx == NULL || filename == NULL)
return NULL;
- char *f = filename[0] == '/' ? bc_strdup(filename) :
- bc_strdup_printf("%s/%s", ctx->root_dir, filename);
+ char *f = filename[0] == '/' ? sb_strdup(filename) :
+ sb_strdup_printf("%s/%s", ctx->root_dir, filename);
struct stat buf;
if (0 != stat(f, &buf)) {
@@ -85,7 +85,7 @@ bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
while (NULL != (e = readdir(dir))) {
if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, "..")))
continue;
- char *tmp = bc_strdup_printf("%s/%s", filename, e->d_name);
+ char *tmp = sb_strdup_printf("%s/%s", filename, e->d_name);
l = bm_filectx_new_r(l, ctx, tmp);
free(tmp);
}
@@ -95,7 +95,7 @@ bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
return l;
}
- l = bc_slist_append(l, bm_filectx_new(ctx, filename, NULL, &buf));
+ l = sb_slist_append(l, bm_filectx_new(ctx, filename, NULL, &buf));
free(f);
return l;
}
@@ -164,13 +164,13 @@ bm_filectx_free(bm_filectx_t *fctx)
bm_ctx_t*
bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
- bc_error_t **err)
+ sb_error_t **err)
{
if (settings_file == NULL || err == NULL || *err != NULL)
return NULL;
size_t content_len;
- char *content = bc_file_get_contents(settings_file, true, &content_len,
+ char *content = sb_file_get_contents_utf8(settings_file, &content_len,
err);
if (*err != NULL)
return NULL;
@@ -189,7 +189,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
bm_ctx_t *rv = NULL;
if (base == NULL) {
- rv = bc_malloc(sizeof(bm_ctx_t));
+ rv = sb_malloc(sizeof(bm_ctx_t));
rv->blogc = bm_exec_find_binary(argv0, "blogc", "BLOGC");
rv->blogc_runserver = bm_exec_find_binary(argv0, "blogc-runserver",
"BLOGC_RUNSERVER");
@@ -208,39 +208,39 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
free(real_filename);
const char *output_dir = getenv("OUTPUT_DIR");
- rv->short_output_dir = bc_strdup(output_dir != NULL ? output_dir : "_build");
+ rv->short_output_dir = sb_strdup(output_dir != NULL ? output_dir : "_build");
if (rv->short_output_dir[0] == '/') {
- rv->output_dir = bc_strdup(rv->short_output_dir);
+ rv->output_dir = sb_strdup(rv->short_output_dir);
}
else {
- rv->output_dir = bc_strdup_printf("%s/%s", rv->root_dir,
+ rv->output_dir = sb_strdup_printf("%s/%s", rv->root_dir,
rv->short_output_dir);
}
// can't return null and set error after this!
- const char *template_dir = bc_trie_lookup(settings->settings,
+ const char *template_dir = sb_trie_lookup(settings->settings,
"template_dir");
- char *main_template = bc_strdup_printf("%s/%s", template_dir,
- bc_trie_lookup(settings->settings, "main_template"));
+ char *main_template = sb_strdup_printf("%s/%s", template_dir,
+ sb_trie_lookup(settings->settings, "main_template"));
rv->main_template_fctx = bm_filectx_new(rv, main_template, NULL, NULL);
free(main_template);
rv->atom_template_fctx = bm_filectx_new(rv, atom_template, NULL, NULL);
free(atom_template);
- const char *content_dir = bc_trie_lookup(settings->settings, "content_dir");
- const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix");
- const char *source_ext = bc_trie_lookup(settings->settings, "source_ext");
+ const char *content_dir = sb_trie_lookup(settings->settings, "content_dir");
+ const char *post_prefix = sb_trie_lookup(settings->settings, "post_prefix");
+ const char *source_ext = sb_trie_lookup(settings->settings, "source_ext");
rv->posts_fctx = NULL;
if (settings->posts != NULL) {
for (size_t i = 0; settings->posts[i] != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s/%s%s", content_dir, post_prefix,
+ char *f = sb_strdup_printf("%s/%s/%s%s", content_dir, post_prefix,
settings->posts[i], source_ext);
- rv->posts_fctx = bc_slist_append(rv->posts_fctx,
+ rv->posts_fctx = sb_slist_append(rv->posts_fctx,
bm_filectx_new(rv, f, settings->posts[i], NULL));
free(f);
}
@@ -249,9 +249,9 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
rv->pages_fctx = NULL;
if (settings->pages != NULL) {
for (size_t i = 0; settings->pages[i] != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s%s", content_dir,
+ char *f = sb_strdup_printf("%s/%s%s", content_dir,
settings->pages[i], source_ext);
- rv->pages_fctx = bc_slist_append(rv->pages_fctx,
+ rv->pages_fctx = sb_slist_append(rv->pages_fctx,
bm_filectx_new(rv, f, settings->pages[i], NULL));
free(f);
}
@@ -281,13 +281,13 @@ bm_ctx_reload(bm_ctx_t **ctx)
// files
// needs to dup path, because it may be freed when reloading.
- char *tmp = bc_strdup((*ctx)->settings_fctx->path);
- bc_error_t *err = NULL;
+ char *tmp = sb_strdup((*ctx)->settings_fctx->path);
+ sb_error_t *err = NULL;
*ctx = bm_ctx_new(*ctx, tmp, NULL, &err);
free(tmp);
if (err != NULL) {
- bc_error_print(err, "blogc-make");
- bc_error_free(err);
+ bm_error_print(err);
+ sb_error_free(err);
return false;
}
return true;
@@ -296,13 +296,13 @@ bm_ctx_reload(bm_ctx_t **ctx)
bm_filectx_reload((*ctx)->main_template_fctx);
bm_filectx_reload((*ctx)->atom_template_fctx);
- for (bc_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
- for (bc_slist_t *tmp = (*ctx)->pages_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->pages_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
- for (bc_slist_t *tmp = (*ctx)->copy_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->copy_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
return true;
@@ -334,11 +334,11 @@ bm_ctx_free_internal(bm_ctx_t *ctx)
bm_filectx_free(ctx->settings_fctx);
ctx->settings_fctx = NULL;
- bc_slist_free_full(ctx->posts_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->posts_fctx, (sb_free_func_t) bm_filectx_free);
ctx->posts_fctx = NULL;
- bc_slist_free_full(ctx->pages_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->pages_fctx, (sb_free_func_t) bm_filectx_free);
ctx->pages_fctx = NULL;
- bc_slist_free_full(ctx->copy_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->copy_fctx, (sb_free_func_t) bm_filectx_free);
ctx->copy_fctx = NULL;
}
diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h
index 2adfc94..70691b5 100644
--- a/src/blogc-make/ctx.h
+++ b/src/blogc-make/ctx.h
@@ -12,9 +12,9 @@
#include <sys/stat.h>
#include <stdbool.h>
#include <time.h>
+#include <squareball.h>
+
#include "settings.h"
-#include "../common/error.h"
-#include "../common/utils.h"
#ifdef __APPLE__
#define st_mtim_tv_sec st_mtimespec.tv_sec
@@ -60,19 +60,19 @@ typedef struct {
bm_filectx_t *atom_template_fctx;
bm_filectx_t *settings_fctx;
- bc_slist_t *posts_fctx;
- bc_slist_t *pages_fctx;
- bc_slist_t *copy_fctx;
+ sb_slist_t *posts_fctx;
+ sb_slist_t *pages_fctx;
+ sb_slist_t *copy_fctx;
} bm_ctx_t;
bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
struct stat *st);
-bc_slist_t* bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename);
+sb_slist_t* bm_filectx_new_r(sb_slist_t *l, bm_ctx_t *ctx, const char *filename);
bool bm_filectx_changed(bm_filectx_t *ctx, time_t *tv_sec, long *tv_nsec);
void bm_filectx_reload(bm_filectx_t *ctx);
void bm_filectx_free(bm_filectx_t *fctx);
bm_ctx_t* bm_ctx_new(bm_ctx_t *base, const char *settings_file,
- const char *argv0, bc_error_t **err);
+ const char *argv0, sb_error_t **err);
bool bm_ctx_reload(bm_ctx_t **ctx);
void bm_ctx_free_internal(bm_ctx_t *ctx);
void bm_ctx_free(bm_ctx_t *ctx);
diff --git a/src/blogc-make/error.c b/src/blogc-make/error.c
new file mode 100644
index 0000000..f02f5ea
--- /dev/null
+++ b/src/blogc-make/error.c
@@ -0,0 +1,36 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdio.h>
+#include <squareball.h>
+
+#include "error.h"
+
+
+void
+bm_error_print(sb_error_t *err)
+{
+ if (err == NULL)
+ return;
+
+ fprintf(stderr, "blogc-make: ");
+
+ switch((bm_error_type_t) err->code) {
+ case BLOGC_MAKE_ERROR_SETTINGS:
+ fprintf(stderr, "error: settings: %s\n", err->msg);
+ break;
+ case BLOGC_MAKE_ERROR_EXEC:
+ fprintf(stderr, "error: exec: %s\n", err->msg);
+ break;
+ case BLOGC_MAKE_ERROR_ATOM:
+ fprintf(stderr, "error: atom: %s\n", err->msg);
+ break;
+ default:
+ fprintf(stderr, "error: %s\n", err->msg);
+ }
+}
diff --git a/src/blogc-make/error.h b/src/blogc-make/error.h
new file mode 100644
index 0000000..52f9326
--- /dev/null
+++ b/src/blogc-make/error.h
@@ -0,0 +1,20 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2017 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifndef _MAKE_ERROR_H
+#define _MAKE_ERROR_H
+
+typedef enum {
+ BLOGC_MAKE_ERROR_SETTINGS = 100,
+ BLOGC_MAKE_ERROR_EXEC,
+ BLOGC_MAKE_ERROR_ATOM,
+} bm_error_type_t;
+
+void bm_error_print(sb_error_t *err);
+
+#endif /* _MAKE_ERROR_H */
diff --git a/src/blogc-make/exec-native.c b/src/blogc-make/exec-native.c
index ae5517d..1b517ff 100644
--- a/src/blogc-make/exec-native.c
+++ b/src/blogc-make/exec-native.c
@@ -16,12 +16,13 @@
#include <unistd.h>
#include <libgen.h>
#include <errno.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "exec-native.h"
#include "ctx.h"
+#define BM_FILE_CHUNK_SIZE 1024
+
int
bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
@@ -32,7 +33,7 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
printf(" COPY %s\n", dest->short_path);
fflush(stdout);
- char *fname = bc_strdup(dest->path);
+ char *fname = sb_strdup(dest->path);
for (char *tmp = fname; *tmp != '\0'; tmp++) {
if (*tmp != '/' && *tmp != '\\')
continue;
@@ -67,8 +68,8 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
}
ssize_t nread;
- char buffer[BC_FILE_CHUNK_SIZE];
- while (0 < (nread = read(fd_from, buffer, BC_FILE_CHUNK_SIZE))) {
+ char buffer[BM_FILE_CHUNK_SIZE];
+ while (0 < (nread = read(fd_from, buffer, BM_FILE_CHUNK_SIZE))) {
char *out_ptr = buffer;
do {
ssize_t nwritten = write(fd_to, out_ptr, nread);
@@ -89,7 +90,7 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
bool
-bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
+bm_exec_native_is_empty_dir(const char *dir, sb_error_t **err)
{
DIR *d = opendir(dir);
if (d == NULL) {
@@ -97,7 +98,7 @@ bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
return true;
}
if (err != NULL) {
- *err = bc_error_new_printf(0, "failed to open directory (%s): %s\n",
+ *err = sb_error_new_printf(0, "failed to open directory (%s): %s\n",
dir, strerror(errno));
}
return true;
@@ -114,7 +115,7 @@ bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
if (0 != closedir(d)) {
if (err != NULL) {
- *err = bc_error_new_printf(0, "failed to close directory (%s): %s\n",
+ *err = sb_error_new_printf(0, "failed to close directory (%s): %s\n",
dir, strerror(errno));
}
return true;
@@ -143,16 +144,16 @@ bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose)
// blame freebsd's libc for all of those memory allocations around dirname
// calls!
- char *short_dir = bc_strdup(dirname(dest->short_path));
- char *dir = bc_strdup(dirname(dest->path));
+ char *short_dir = sb_strdup(dirname(dest->short_path));
+ char *dir = sb_strdup(dirname(dest->path));
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
while ((0 != strcmp(short_dir, ".")) && (0 != strcmp(short_dir, "/"))) {
bool empty = bm_exec_native_is_empty_dir(dir, &err);
if (err != NULL) {
fprintf(stderr, "blogc-make: error: %s\n", err->msg);
- bc_error_free(err);
+ sb_error_free(err);
rv = 3;
break;
}
@@ -175,10 +176,10 @@ bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose)
}
char *tmp = short_dir;
- short_dir = bc_strdup(dirname(short_dir));
+ short_dir = sb_strdup(dirname(short_dir));
free(tmp);
tmp = dir;
- dir = bc_strdup(dirname(dir));
+ dir = sb_strdup(dirname(dir));
free(tmp);
}
diff --git a/src/blogc-make/exec-native.h b/src/blogc-make/exec-native.h
index b6db3cc..fc264d2 100644
--- a/src/blogc-make/exec-native.h
+++ b/src/blogc-make/exec-native.h
@@ -10,11 +10,12 @@
#define _MAKE_EXEC_NATIVE_H
#include <stdbool.h>
-#include "../common/error.h"
+#include <squareball.h>
+
#include "ctx.h"
int bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose);
-bool bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err);
+bool bm_exec_native_is_empty_dir(const char *dir, sb_error_t **err);
int bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose);
#endif /* _MAKE_EXEC_NATIVE_H */
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index aaae523..5fa86f4 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -18,13 +18,15 @@
#include <sys/wait.h>
#include <errno.h>
#include <libgen.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
+#include "error.h"
#include "exec.h"
#include "settings.h"
+#define BM_FILE_CHUNK_SIZE 1024
+
char*
bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
@@ -34,14 +36,14 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
// argv0, because the static binary may not be named `blogc`, and we
// prefer to use our own `blogc` instead of some other version around.
if (argv0 != NULL && bin != NULL && (0 == strcmp(bin, "blogc"))) {
- return bc_shell_quote(argv0);
+ return sb_shell_quote(argv0);
}
#endif
// first try: env var
const char *env_bin = getenv(env);
if (env_bin != NULL) {
- return bc_shell_quote(env_bin);
+ return sb_shell_quote(env_bin);
}
// second try: same dir as current exec
@@ -53,13 +55,13 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
// that relative paths will work as expected.
// - windows path sep is not supported
if (argv0 != NULL && (NULL != strchr(argv0, '/'))) {
- char *path = bc_strdup(argv0);
- char *dir = bc_strdup(dirname(path));
+ char *path = sb_strdup(argv0);
+ char *dir = sb_strdup(dirname(path));
free(path);
- char *tmp = bc_strdup_printf("%s/%s", dir, bin);
+ char *tmp = sb_strdup_printf("%s/%s", dir, bin);
free(dir);
if (0 == access(tmp, X_OK)) {
- char *rv = bc_shell_quote(tmp);
+ char *rv = sb_shell_quote(tmp);
free(tmp);
return rv;
}
@@ -67,27 +69,27 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
}
// last try: $PATH
- return bc_strdup(bin);
+ return sb_strdup(bin);
}
int
bm_exec_command(const char *cmd, const char *input, char **output,
- char **error, bc_error_t **err)
+ char **error, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return 3;
int fd_in[2];
if (-1 == pipe(fd_in)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to create stdin pipe: %s", strerror(errno));
return 3;
}
int fd_out[2];
if (-1 == pipe(fd_out)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to create stdout pipe: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
@@ -96,7 +98,7 @@ bm_exec_command(const char *cmd, const char *input, char **output,
int fd_err[2];
if (-1 == pipe(fd_err)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to create stderr pipe: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
@@ -107,7 +109,7 @@ bm_exec_command(const char *cmd, const char *input, char **output,
pid_t pid = fork();
if (pid == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to fork: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
@@ -147,7 +149,7 @@ bm_exec_command(const char *cmd, const char *input, char **output,
if (input != NULL) {
if (-1 == write(fd_in[1], input, strlen(input))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to write to stdin pipe: %s", strerror(errno));
close(fd_in[1]);
close(fd_out[0]);
@@ -158,44 +160,44 @@ bm_exec_command(const char *cmd, const char *input, char **output,
close(fd_in[1]);
- char buffer[BC_FILE_CHUNK_SIZE];
+ char buffer[BM_FILE_CHUNK_SIZE];
ssize_t s;
- bc_string_t *out = NULL;
- while(0 != (s = read(fd_out[0], buffer, BC_FILE_CHUNK_SIZE))) {
+ sb_string_t *out = NULL;
+ while(0 != (s = read(fd_out[0], buffer, BM_FILE_CHUNK_SIZE))) {
if (s == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to read from stdout pipe: %s", strerror(errno));
close(fd_out[0]);
close(fd_err[0]);
- bc_string_free(out, true);
+ sb_string_free(out, true);
return 3;
}
if (out == NULL) {
- out = bc_string_new();
+ out = sb_string_new();
}
- bc_string_append_len(out, buffer, s);
+ sb_string_append_len(out, buffer, s);
}
if (out != NULL) {
- *output = bc_string_free(out, false);
+ *output = sb_string_free(out, false);
}
close(fd_out[0]);
out = NULL;
- while(0 != (s = read(fd_err[0], buffer, BC_FILE_CHUNK_SIZE))) {
+ while(0 != (s = read(fd_err[0], buffer, BM_FILE_CHUNK_SIZE))) {
if (s == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
"Failed to read from stderr pipe: %s", strerror(errno));
close(fd_err[0]);
- bc_string_free(out, true);
+ sb_string_free(out, true);
return 3;
}
if (out == NULL)
- out = bc_string_new();
- bc_string_append_len(out, buffer, s);
+ out = sb_string_new();
+ sb_string_append_len(out, buffer, s);
}
if (out != NULL) {
- *error = bc_string_free(out, false);
+ *error = sb_string_free(out, false);
}
close(fd_err[0]);
@@ -207,86 +209,86 @@ bm_exec_command(const char *cmd, const char *input, char **output,
static void
-list_variables(const char *key, const char *value, bc_string_t *str)
+list_variables(const char *key, const char *value, sb_string_t *str)
{
- char *tmp = bc_shell_quote(value);
- bc_string_append_printf(str, " -D %s=%s", key, tmp);
+ char *tmp = sb_shell_quote(value);
+ sb_string_append_printf(str, " -D %s=%s", key, tmp);
free(tmp);
}
char*
bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
- bc_trie_t *global_variables, bc_trie_t *local_variables, bool listing,
+ sb_trie_t *global_variables, sb_trie_t *local_variables, bool listing,
const char *template, const char *output, bool dev, bool sources_stdin)
{
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
const char *locale = NULL;
if (settings != NULL) {
- locale = bc_trie_lookup(settings->settings, "locale");
+ locale = sb_trie_lookup(settings->settings, "locale");
}
if (locale != NULL) {
- char *tmp = bc_shell_quote(locale);
- bc_string_append_printf(rv, "LC_ALL=%s ", tmp);
+ char *tmp = sb_shell_quote(locale);
+ sb_string_append_printf(rv, "LC_ALL=%s ", tmp);
free(tmp);
}
- bc_string_append(rv, blogc_bin);
+ sb_string_append(rv, blogc_bin);
if (settings != NULL) {
if (settings->tags != NULL) {
- char *tags = bc_strv_join(settings->tags, " ");
- bc_string_append_printf(rv, " -D MAKE_TAGS='%s'", tags);
+ char *tags = sb_strv_join(settings->tags, " ");
+ sb_string_append_printf(rv, " -D MAKE_TAGS='%s'", tags);
free(tags);
}
- bc_trie_foreach(settings->global,
- (bc_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(settings->global,
+ (sb_trie_foreach_func_t) list_variables, rv);
}
- bc_trie_foreach(global_variables, (bc_trie_foreach_func_t) list_variables, rv);
- bc_trie_foreach(local_variables, (bc_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(global_variables, (sb_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(local_variables, (sb_trie_foreach_func_t) list_variables, rv);
if (dev) {
- bc_string_append(rv, " -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
+ sb_string_append(rv, " -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
}
if (listing) {
- bc_string_append(rv, " -l");
+ sb_string_append(rv, " -l");
}
if (template != NULL) {
- char *tmp = bc_shell_quote(template);
- bc_string_append_printf(rv, " -t %s", tmp);
+ char *tmp = sb_shell_quote(template);
+ sb_string_append_printf(rv, " -t %s", tmp);
free(tmp);
}
if (output != NULL) {
- char *tmp = bc_shell_quote(output);
- bc_string_append_printf(rv, " -o %s", tmp);
+ char *tmp = sb_shell_quote(output);
+ sb_string_append_printf(rv, " -o %s", tmp);
free(tmp);
}
if (sources_stdin) {
- bc_string_append(rv, " -i");
+ sb_string_append(rv, " -i");
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
int
-bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_variables,
- bool listing, bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
+bm_exec_blogc(bm_ctx_t *ctx, sb_trie_t *global_variables, sb_trie_t *local_variables,
+ bool listing, bm_filectx_t *template, bm_filectx_t *output, sb_slist_t *sources,
bool only_first_source)
{
if (ctx == NULL)
return 3;
- bc_string_t *input = bc_string_new();
- for (bc_slist_t *l = sources; l != NULL; l = l->next) {
- bc_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
+ sb_string_t *input = sb_string_new();
+ for (sb_slist_t *l = sources; l != NULL; l = l->next) {
+ sb_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
if (only_first_source)
break;
}
@@ -303,7 +305,7 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
char *out = NULL;
char *err = NULL;
- bc_error_t *error = NULL;
+ sb_error_t *error = NULL;
int rv = bm_exec_command(cmd, input->str, &out, &err, &error);
@@ -312,12 +314,12 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
}
if (error != NULL) {
- bc_error_print(error, "blogc-make");
+ bm_error_print(error);
free(cmd);
free(out);
free(err);
- bc_string_free(input, true);
- bc_error_free(error);
+ sb_string_free(input, true);
+ sb_error_free(error);
return 3;
}
@@ -332,27 +334,27 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
"----------------------------->8-----------------------------\n"
"%s\n"
"----------------------------->8-----------------------------\n",
- bc_str_strip(input->str));
+ sb_str_strip(input->str));
}
if (out != NULL) {
fprintf(stderr, "\nSTDOUT:\n"
"----------------------------->8-----------------------------\n"
"%s\n"
"----------------------------->8-----------------------------\n",
- bc_str_strip(out));
+ sb_str_strip(out));
}
}
else {
fprintf(stderr,
"blogc-make: error: Failed to execute command (%d)", rv);
if (err != NULL) {
- fprintf(stderr, ":\n%s", bc_str_strip(err));
+ fprintf(stderr, ":\n%s", sb_str_strip(err));
}
fprintf(stderr, "\n");
}
}
- bc_string_free(input, true);
+ sb_string_free(input, true);
free(cmd);
free(out);
free(err);
@@ -368,30 +370,30 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
if (ctx == NULL)
return 3;
- bc_string_t *cmd = bc_string_new();
+ sb_string_t *cmd = sb_string_new();
- bc_string_append(cmd, ctx->blogc_runserver);
+ sb_string_append(cmd, ctx->blogc_runserver);
if (host != NULL) {
- char *tmp = bc_shell_quote(host);
- bc_string_append_printf(cmd, " -t %s", tmp);
+ char *tmp = sb_shell_quote(host);
+ sb_string_append_printf(cmd, " -t %s", tmp);
free(tmp);
}
if (port != NULL) {
- char *tmp = bc_shell_quote(port);
- bc_string_append_printf(cmd, " -p %s", tmp);
+ char *tmp = sb_shell_quote(port);
+ sb_string_append_printf(cmd, " -p %s", tmp);
free(tmp);
}
if (threads != NULL) {
- char *tmp = bc_shell_quote(threads);
- bc_string_append_printf(cmd, " -m %s", tmp);
+ char *tmp = sb_shell_quote(threads);
+ sb_string_append_printf(cmd, " -m %s", tmp);
free(tmp);
}
- char *tmp = bc_shell_quote(ctx->output_dir);
- bc_string_append_printf(cmd, " %s", tmp);
+ char *tmp = sb_shell_quote(ctx->output_dir);
+ sb_string_append_printf(cmd, " %s", tmp);
free(tmp);
if (ctx->verbose)
@@ -403,7 +405,7 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
// we don't need pipes to run blogc-runserver, because it is "interactive"
int status = system(cmd->str);
int rv = WEXITSTATUS(status);
- bc_string_free(cmd, true);
+ sb_string_free(cmd, true);
if (rv != 0 && rv != 130) {
if (rv == 127) {
diff --git a/src/blogc-make/exec.h b/src/blogc-make/exec.h
index 85f2a44..a2acd1b 100644
--- a/src/blogc-make/exec.h
+++ b/src/blogc-make/exec.h
@@ -10,19 +10,19 @@
#define _MAKE_EXEC_H
#include <stdbool.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "settings.h"
char* bm_exec_find_binary(const char *argv0, const char *bin, const char *env);
int bm_exec_command(const char *cmd, const char *input, char **output,
- char **error, bc_error_t **err);
+ char **error, sb_error_t **err);
char* bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
- bc_trie_t *global_variables, bc_trie_t *local_variables, bool listing,
+ sb_trie_t *global_variables, sb_trie_t *local_variables, bool listing,
const char *template, const char *output, bool dev, bool sources_stdin);
-int bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_variables,
- bool listing, bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
+int bm_exec_blogc(bm_ctx_t *ctx, sb_trie_t *global_variables, sb_trie_t *local_variables,
+ bool listing, bm_filectx_t *template, bm_filectx_t *output, sb_slist_t *sources,
bool only_first_source);
int bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
const char *threads);
diff --git a/src/blogc-make/main.c b/src/blogc-make/main.c
index 3ce1f8a..45a0613 100644
--- a/src/blogc-make/main.c
+++ b/src/blogc-make/main.c
@@ -14,9 +14,10 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
+#include "error.h"
#include "rules.h"
@@ -60,9 +61,9 @@ main(int argc, char **argv)
setlocale(LC_ALL, "");
int rv = 0;
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
- bc_slist_t *rules = NULL;
+ sb_slist_t *rules = NULL;
bool verbose = false;
bool dev = false;
char *blogcfile = NULL;
@@ -85,9 +86,9 @@ main(int argc, char **argv)
break;
case 'f':
if (argv[i][2] != '\0')
- blogcfile = bc_strdup(argv[i] + 2);
+ blogcfile = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- blogcfile = bc_strdup(argv[++i]);
+ blogcfile = sb_strdup(argv[++i]);
break;
#ifdef MAKE_EMBEDDED
case 'm':
@@ -103,18 +104,18 @@ main(int argc, char **argv)
}
}
else {
- rules = bc_slist_append(rules, bc_strdup(argv[i]));
+ rules = sb_slist_append(rules, sb_strdup(argv[i]));
}
}
if (rules == NULL) {
- rules = bc_slist_append(rules, bc_strdup("all"));
+ rules = sb_slist_append(rules, sb_strdup("all"));
}
ctx = bm_ctx_new(NULL, blogcfile ? blogcfile : "blogcfile",
argc > 0 ? argv[0] : NULL, &err);
if (err != NULL) {
- bc_error_print(err, "blogc-make");
+ bm_error_print(err);
rv = 3;
goto cleanup;
}
@@ -125,10 +126,10 @@ main(int argc, char **argv)
cleanup:
- bc_slist_free_full(rules, free);
+ sb_slist_free_full(rules, free);
free(blogcfile);
bm_ctx_free(ctx);
- bc_error_free(err);
+ sb_error_free(err);
return rv;
}
diff --git a/src/blogc-make/reloader.c b/src/blogc-make/reloader.c
index 6b30974..12ca202 100644
--- a/src/blogc-make/reloader.c
+++ b/src/blogc-make/reloader.c
@@ -11,7 +11,8 @@
#include <string.h>
#include <unistd.h>
#include <pthread.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
#include "reloader.h"
@@ -47,7 +48,7 @@ bm_reloader_thread(void *arg)
bm_reloader_t*
bm_reloader_new(bm_ctx_t *ctx, bm_rule_exec_func_t rule_exec,
- bc_slist_t *outputs, bc_trie_t *args)
+ sb_slist_t *outputs, sb_trie_t *args)
{
// first rule_exec call is syncronous, to do a 'sanity check'
if (0 != rule_exec(ctx, outputs, args))
@@ -70,7 +71,7 @@ bm_reloader_new(bm_ctx_t *ctx, bm_rule_exec_func_t rule_exec,
return NULL;
}
- bm_reloader_t *rv = bc_malloc(sizeof(bm_reloader_t));
+ bm_reloader_t *rv = sb_malloc(sizeof(bm_reloader_t));
rv->ctx = ctx;
rv->rule_exec = rule_exec;
rv->outputs = outputs;
diff --git a/src/blogc-make/reloader.h b/src/blogc-make/reloader.h
index 40d2fe9..5067738 100644
--- a/src/blogc-make/reloader.h
+++ b/src/blogc-make/reloader.h
@@ -10,20 +10,21 @@
#define _MAKE_RELOADER_H
#include <stdbool.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
typedef struct {
bm_ctx_t *ctx;
bm_rule_exec_func_t rule_exec;
- bc_slist_t *outputs;
- bc_trie_t *args;
+ sb_slist_t *outputs;
+ sb_trie_t *args;
bool running;
} bm_reloader_t;
bm_reloader_t* bm_reloader_new(bm_ctx_t *ctx, bm_rule_exec_func_t rule_exec,
- bc_slist_t *outputs, bc_trie_t *args);
+ sb_slist_t *outputs, sb_trie_t *args);
void bm_reloader_stop(bm_reloader_t *reloader);
#endif /* _MAKE_RELOADER_H */
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;
}
diff --git a/src/blogc-make/rules.h b/src/blogc-make/rules.h
index 1604e13..9dd910d 100644
--- a/src/blogc-make/rules.h
+++ b/src/blogc-make/rules.h
@@ -10,12 +10,13 @@
#define _MAKE_RULES_H
#include <stdbool.h>
+#include <squareball.h>
+
#include "ctx.h"
-#include "../common/utils.h"
-typedef bc_slist_t* (*bm_rule_outputlist_func_t) (bm_ctx_t *ctx);
-typedef int (*bm_rule_exec_func_t) (bm_ctx_t *ctx, bc_slist_t *outputs,
- bc_trie_t *args);
+typedef sb_slist_t* (*bm_rule_outputlist_func_t) (bm_ctx_t *ctx);
+typedef int (*bm_rule_exec_func_t) (bm_ctx_t *ctx, sb_slist_t *outputs,
+ sb_trie_t *args);
typedef struct {
const char *name;
@@ -25,12 +26,12 @@ typedef struct {
bool generate_files;
} bm_rule_t;
-bc_trie_t* bm_rule_parse_args(const char *sep);
-int 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);
-bool bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
+sb_trie_t* bm_rule_parse_args(const char *sep);
+int bm_rule_executor(bm_ctx_t *ctx, sb_slist_t *rule_list);
+int bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, sb_trie_t *args);
+bool bm_rule_need_rebuild(sb_slist_t *sources, bm_filectx_t *settings,
bm_filectx_t *template, bm_filectx_t *output, bool only_first_source);
-bc_slist_t* bm_rule_list_built_files(bm_ctx_t *ctx);
+sb_slist_t* bm_rule_list_built_files(bm_ctx_t *ctx);
void bm_rule_print_help(void);
#endif /* _MAKE_RULES_H */
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 9e24d41..1f3341d 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -9,10 +9,9 @@
#include <libgen.h>
#include <stdbool.h>
#include <stdlib.h>
-#include "../common/config-parser.h"
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
+#include "error.h"
#include "settings.h"
@@ -73,7 +72,7 @@ static const char* list_sections[] = {
bm_settings_t*
-bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
+bm_settings_parse(const char *content, size_t content_len, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
@@ -81,15 +80,15 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
if (content == NULL)
return NULL;
- bc_config_t *config = bc_config_parse(content, content_len, list_sections,
+ sb_config_t *config = sb_config_parse(content, content_len, list_sections,
err);
if (config == NULL || (err != NULL && *err != NULL))
return NULL;
- bm_settings_t *rv = bc_malloc(sizeof(bm_settings_t));
+ bm_settings_t *rv = sb_malloc(sizeof(bm_settings_t));
rv->root_dir = NULL;
- rv->global = bc_trie_new(free);
- rv->settings = bc_trie_new(free);
+ rv->global = sb_trie_new(free);
+ rv->settings = sb_trie_new(free);
rv->posts = NULL;
rv->pages = NULL;
rv->copy = NULL;
@@ -99,12 +98,12 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
// even if I never released a version with it, but some people is using
// it already.
const char *section = NULL;
- char **global = bc_config_list_keys(config, "global");
+ char **global = sb_config_list_keys(config, "global");
if (global != NULL) {
section = "global";
}
else {
- global = bc_config_list_keys(config, "environment");
+ global = sb_config_list_keys(config, "environment");
if (global != NULL) {
section = "environment";
}
@@ -117,24 +116,24 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
for (size_t i = 0; global[i] != NULL; i++) {
for (size_t j = 0; global[i][j] != '\0'; j++) {
if (!((global[i][j] >= 'A' && global[i][j] <= 'Z') || global[i][j] == '_')) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
"Invalid [%s] key: %s", section, global[i]);
- bc_strv_free(global);
+ sb_strv_free(global);
bm_settings_free(rv);
rv = NULL;
goto cleanup;
}
}
- bc_trie_insert(rv->global, global[i],
- bc_strdup(bc_config_get(config, section, global[i])));
+ sb_trie_insert(rv->global, global[i],
+ sb_strdup(sb_config_get(config, section, global[i])));
}
}
- bc_strv_free(global);
+ sb_strv_free(global);
for (size_t i = 0; required_global[i] != NULL; i++) {
- const char *value = bc_trie_lookup(rv->global, required_global[i]);
+ const char *value = sb_trie_lookup(rv->global, required_global[i]);
if (value == NULL || value[0] == '\0') {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
+ *err = sb_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
"[%s] key required but not found or empty: %s", section,
required_global[i]);
bm_settings_free(rv);
@@ -144,46 +143,46 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
}
for (size_t i = 0; default_settings[i].key != NULL; i++) {
- const char *value = bc_config_get_with_default(
+ const char *value = sb_config_get_with_default(
config, "settings", default_settings[i].key,
default_settings[i].default_value);
if (value != NULL) {
- bc_trie_insert(rv->settings, default_settings[i].key,
- bc_strdup(value));
+ sb_trie_insert(rv->settings, default_settings[i].key,
+ sb_strdup(value));
}
}
- rv->posts = bc_config_get_list(config, "posts");
- rv->pages = bc_config_get_list(config, "pages");
- rv->tags = bc_config_get_list(config, "tags");
+ rv->posts = sb_config_get_list(config, "posts");
+ rv->pages = sb_config_get_list(config, "pages");
+ rv->tags = sb_config_get_list(config, "tags");
// this is for backward compatibility too.
- rv->copy = bc_config_get_list(config, "copy");
+ rv->copy = sb_config_get_list(config, "copy");
if (rv->copy == NULL)
- rv->copy = bc_config_get_list(config, "copy_files");
+ rv->copy = sb_config_get_list(config, "copy_files");
cleanup:
- bc_config_free(config);
+ sb_config_free(config);
return rv;
}
bm_settings_t*
-bm_settings_parse_file(const char *filename, bc_error_t **err)
+bm_settings_parse_file(const char *filename, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
size_t content_len;
- char *content = bc_file_get_contents(filename, true, &content_len, err);
+ char *content = sb_file_get_contents_utf8(filename, &content_len, err);
if (*err != NULL)
return NULL;
bm_settings_t *rv = bm_settings_parse(content, content_len, err);
char *real_filename = realpath(filename, NULL);
- rv->root_dir = bc_strdup(dirname(real_filename));
+ rv->root_dir = sb_strdup(dirname(real_filename));
free(real_filename);
free(content);
return rv;
@@ -196,11 +195,11 @@ bm_settings_free(bm_settings_t *settings)
if (settings == NULL)
return;
free(settings->root_dir);
- bc_trie_free(settings->global);
- bc_trie_free(settings->settings);
- bc_strv_free(settings->posts);
- bc_strv_free(settings->pages);
- bc_strv_free(settings->copy);
- bc_strv_free(settings->tags);
+ sb_trie_free(settings->global);
+ sb_trie_free(settings->settings);
+ sb_strv_free(settings->posts);
+ sb_strv_free(settings->pages);
+ sb_strv_free(settings->copy);
+ sb_strv_free(settings->tags);
free(settings);
}
diff --git a/src/blogc-make/settings.h b/src/blogc-make/settings.h
index b1ea117..d524d23 100644
--- a/src/blogc-make/settings.h
+++ b/src/blogc-make/settings.h
@@ -10,13 +10,12 @@
#define _MAKE_SETTINGS_H
#include <stddef.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
typedef struct {
char *root_dir;
- bc_trie_t *global;
- bc_trie_t *settings;
+ sb_trie_t *global;
+ sb_trie_t *settings;
char **posts;
char **pages;
char **copy;
@@ -24,8 +23,8 @@ typedef struct {
} bm_settings_t;
bm_settings_t* bm_settings_parse(const char *content, size_t content_len,
- bc_error_t **err);
-bm_settings_t* bm_settings_parse_file(const char *filename, bc_error_t **err);
+ sb_error_t **err);
+bm_settings_t* bm_settings_parse_file(const char *filename, sb_error_t **err);
void bm_settings_free(bm_settings_t *settings);
#endif /* _MAKE_SETTINGS_H */