aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc/loader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc/loader.c')
-rw-r--r--src/blogc/loader.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/blogc/loader.c b/src/blogc/loader.c
index 0525198..fc79641 100644
--- a/src/blogc/loader.c
+++ b/src/blogc/loader.c
@@ -12,12 +12,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
+
+#include "error.h"
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
char*
@@ -29,7 +29,7 @@ blogc_get_filename(const char *f)
if (strlen(f) == 0)
return NULL;
- char *filename = bc_strdup(f);
+ char *filename = sb_strdup(f);
// keep a pointer to original string
char *tmp = filename;
@@ -50,46 +50,46 @@ blogc_get_filename(const char *f)
}
}
- char *final_filename = bc_strdup(tmp);
+ char *final_filename = sb_strdup(tmp);
free(filename);
return final_filename;
}
-bc_slist_t*
-blogc_template_parse_from_file(const char *f, bc_error_t **err)
+sb_slist_t*
+blogc_template_parse_from_file(const char *f, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
size_t len;
- char *s = bc_file_get_contents(f, true, &len, err);
+ char *s = sb_file_get_contents_utf8(f, &len, err);
if (s == NULL)
return NULL;
- bc_slist_t *rv = blogc_template_parse(s, len, err);
+ sb_slist_t *rv = blogc_template_parse(s, len, err);
free(s);
return rv;
}
-bc_trie_t*
-blogc_source_parse_from_file(const char *f, bc_error_t **err)
+sb_trie_t*
+blogc_source_parse_from_file(const char *f, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
size_t len;
- char *s = bc_file_get_contents(f, true, &len, err);
+ char *s = sb_file_get_contents_utf8(f, &len, err);
if (s == NULL)
return NULL;
- bc_trie_t *rv = blogc_source_parse(s, len, err);
+ sb_trie_t *rv = blogc_source_parse(s, len, err);
// set FILENAME variable
if (rv != NULL) {
char *filename = blogc_get_filename(f);
if (filename != NULL)
- bc_trie_insert(rv, "FILENAME", filename);
+ sb_trie_insert(rv, "FILENAME", filename);
}
free(s);
@@ -97,30 +97,30 @@ blogc_source_parse_from_file(const char *f, bc_error_t **err)
}
-bc_slist_t*
-blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, bc_error_t **err)
+sb_slist_t*
+blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
- bool reverse = bc_trie_lookup(conf, "FILTER_REVERSE");
- bc_slist_t* sources = NULL;
- for (bc_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
+ bool reverse = sb_trie_lookup(conf, "FILTER_REVERSE");
+ sb_slist_t* sources = NULL;
+ for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
if (reverse) {
- sources = bc_slist_prepend(sources, tmp->data);
+ sources = sb_slist_prepend(sources, tmp->data);
}
else {
- sources = bc_slist_append(sources, tmp->data);
+ sources = sb_slist_append(sources, tmp->data);
}
}
- bc_error_t *tmp_err = NULL;
- bc_slist_t *rv = NULL;
+ sb_error_t *tmp_err = NULL;
+ sb_slist_t *rv = NULL;
size_t with_date = 0;
- const char *filter_tag = bc_trie_lookup(conf, "FILTER_TAG");
- const char *filter_page = bc_trie_lookup(conf, "FILTER_PAGE");
- const char *filter_per_page = bc_trie_lookup(conf, "FILTER_PER_PAGE");
+ const char *filter_tag = sb_trie_lookup(conf, "FILTER_TAG");
+ const char *filter_page = sb_trie_lookup(conf, "FILTER_PAGE");
+ const char *filter_per_page = sb_trie_lookup(conf, "FILTER_PER_PAGE");
const char *ptr;
char *endptr;
@@ -146,27 +146,27 @@ blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, bc_error_t **err)
size_t end = start + per_page;
size_t counter = 0;
- for (bc_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
char *f = tmp->data;
- bc_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
+ sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
if (s == NULL) {
- *err = bc_error_new_printf(BLOGC_ERROR_LOADER,
+ *err = sb_error_new_printf(BLOGC_ERROR_LOADER,
"An error occurred while parsing source file: %s\n\n%s",
f, tmp_err->msg);
- bc_error_free(tmp_err);
+ sb_error_free(tmp_err);
tmp_err = NULL;
- bc_slist_free_full(rv, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free);
rv = NULL;
break;
}
if (filter_tag != NULL) {
- const char *tags_str = bc_trie_lookup(s, "TAGS");
+ const char *tags_str = sb_trie_lookup(s, "TAGS");
// if user wants to filter by tag and no tag is provided, skip it
if (tags_str == NULL) {
- bc_trie_free(s);
+ sb_trie_free(s);
continue;
}
- char **tags = bc_str_split(tags_str, ' ', 0);
+ char **tags = sb_str_split(tags_str, ' ', 0);
bool found = false;
for (size_t i = 0; tags[i] != NULL; i++) {
if (tags[i][0] == '\0')
@@ -174,68 +174,68 @@ blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, bc_error_t **err)
if (0 == strcmp(tags[i], filter_tag))
found = true;
}
- bc_strv_free(tags);
+ sb_strv_free(tags);
if (!found) {
- bc_trie_free(s);
+ sb_trie_free(s);
continue;
}
}
if (filter_page != NULL) {
if (counter < start || counter >= end) {
counter++;
- bc_trie_free(s);
+ sb_trie_free(s);
continue;
}
counter++;
}
- if (bc_trie_lookup(s, "DATE") != NULL)
+ if (sb_trie_lookup(s, "DATE") != NULL)
with_date++;
- rv = bc_slist_append(rv, s);
+ rv = sb_slist_append(rv, s);
}
- bc_slist_free(sources);
+ sb_slist_free(sources);
- if (with_date > 0 && with_date < bc_slist_length(rv)) {
- *err = bc_error_new_printf(BLOGC_ERROR_LOADER,
+ if (with_date > 0 && with_date < sb_slist_length(rv)) {
+ *err = sb_error_new_printf(BLOGC_ERROR_LOADER,
"'DATE' variable provided for at least one source file, but not "
"for all source files. It must be provided for all files.\n");
- bc_slist_free_full(rv, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free);
rv = NULL;
}
bool first = true;
- for (bc_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
- bc_trie_t *s = tmp->data;
+ for (sb_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
+ sb_trie_t *s = tmp->data;
if (first) {
- const char *val = bc_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- bc_trie_insert(conf, "DATE_FIRST", bc_strdup(val));
- val = bc_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- bc_trie_insert(conf, "FILENAME_FIRST", bc_strdup(val));
+ sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val));
first = false;
}
if (tmp->next == NULL) { // last
- const char *val = bc_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- bc_trie_insert(conf, "DATE_LAST", bc_strdup(val));
- val = bc_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_LAST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- bc_trie_insert(conf, "FILENAME_LAST", bc_strdup(val));
+ sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val));
}
}
if (filter_page != NULL) {
size_t last_page = ceilf(((float) counter) / per_page);
- bc_trie_insert(conf, "CURRENT_PAGE", bc_strdup_printf("%ld", page));
+ sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page));
if (page > 1)
- bc_trie_insert(conf, "PREVIOUS_PAGE", bc_strdup_printf("%ld", page - 1));
+ sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1));
if (page < last_page)
- bc_trie_insert(conf, "NEXT_PAGE", bc_strdup_printf("%ld", page + 1));
- if (bc_slist_length(rv) > 0)
- bc_trie_insert(conf, "FIRST_PAGE", bc_strdup("1"));
+ sb_trie_insert(conf, "NEXT_PAGE", sb_strdup_printf("%ld", page + 1));
+ if (sb_slist_length(rv) > 0)
+ sb_trie_insert(conf, "FIRST_PAGE", sb_strdup("1"));
if (last_page > 0)
- bc_trie_insert(conf, "LAST_PAGE", bc_strdup_printf("%d", last_page));
+ sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page));
}
return rv;