aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-make/utils.c')
-rw-r--r--src/blogc-make/utils.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c
index 8f69e44..f2bd777 100644
--- a/src/blogc-make/utils.c
+++ b/src/blogc-make/utils.c
@@ -11,8 +11,9 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
+#include "utils.h"
#ifndef PATH_MAX
#define PATH_MAX 4096
@@ -30,42 +31,42 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
bool is_index = have_fname && have_ext && (
(0 == strcmp(fname, "index")) && ext[0] == '/') && !have_prefix;
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
if (dir != NULL && (have_prefix || have_fname || have_ext))
- bc_string_append(rv, dir);
+ sb_string_append(rv, dir);
if ((have_prefix || have_fname || have_ext_noslash) && !is_index)
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (have_prefix)
- bc_string_append(rv, prefix);
+ sb_string_append(rv, prefix);
// with fname we have posts, pages and tags
if (have_fname) {
if (have_prefix && have_fname && fname[0] != '/')
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (!is_index)
- bc_string_append(rv, fname);
+ sb_string_append(rv, fname);
}
// no fname means index
else if (have_ext_noslash) {
if (have_fname)
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (!have_prefix)
- bc_string_append(rv, "index");
+ sb_string_append(rv, "index");
}
if (have_ext)
- bc_string_append(rv, ext);
+ sb_string_append(rv, ext);
if (rv->len == 0) {
- bc_string_free(rv, true);
+ sb_string_free(rv, true);
return NULL;
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -77,52 +78,52 @@ bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
bool have_fname = fname != NULL && fname[0] != '\0';
bool have_prefix2 = prefix2 != NULL && prefix2[0] != '\0';
- bc_string_t *p = bc_string_new();
+ sb_string_t *p = sb_string_new();
if (have_prefix)
- bc_string_append(p, prefix);
+ sb_string_append(p, prefix);
if (have_prefix && (have_fname || have_prefix2))
- bc_string_append_c(p, '/');
+ sb_string_append_c(p, '/');
if (have_fname)
- bc_string_append(p, fname);
+ sb_string_append(p, fname);
if (have_fname && have_prefix2)
- bc_string_append_c(p, '/');
+ sb_string_append_c(p, '/');
if (have_prefix2)
- bc_string_append(p, prefix2);
+ sb_string_append(p, prefix2);
char *rv = bm_generate_filename(dir, p->str, fname2, ext);
- bc_string_free(p, true);
+ sb_string_free(p, true);
return rv;
}
char*
-bm_abspath(const char *path, bc_error_t **err)
+bm_abspath(const char *path, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
if (path[0] == '/') {
- return bc_strdup(path);
+ return sb_strdup(path);
}
char cwd[PATH_MAX];
if (NULL == getcwd(cwd, sizeof(cwd))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
- "Failed to detect absolute path (%s): %s", path, strerror(errno));
+ *err = sb_strerror_new_printf(
+ "utils: Failed to detect absolute path (%s): %s", path, strerror(errno));
return NULL;
}
if (cwd[0] != '/') {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
- "Failed to get current working directory: %s", cwd);
+ *err = sb_strerror_new_printf(
+ "utils: Failed to get current working directory: %s", cwd);
return NULL;
}
- return bc_strdup_printf("%s/%s", cwd, path);
+ return sb_strdup_printf("%s/%s", cwd, path);
}