diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-02-26 01:04:32 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-02-26 01:04:32 +0100 |
commit | 3b0f9293a3432023cdca91df01418347d9781ffa (patch) | |
tree | e872df7080979732ddf3efbdaabc8a4bdafd0653 /src/loader.c | |
parent | bdff66b0013165c3ef7eff644fb276235f3dd082 (diff) | |
download | blogc-3b0f9293a3432023cdca91df01418347d9781ffa.tar.gz blogc-3b0f9293a3432023cdca91df01418347d9781ffa.tar.bz2 blogc-3b0f9293a3432023cdca91df01418347d9781ffa.zip |
build: replace src/utils with squareball
Diffstat (limited to 'src/loader.c')
-rw-r--r-- | src/loader.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/loader.c b/src/loader.c index baa81fa..8008c3a 100644 --- a/src/loader.c +++ b/src/loader.c @@ -14,7 +14,7 @@ #include <stdbool.h> #include <stdio.h> #include <string.h> -#include "utils/utils.h" +#include <squareball.h> #include "file.h" #include "source-parser.h" #include "template-parser.h" @@ -31,7 +31,7 @@ blogc_get_filename(const char *f) if (strlen(f) == 0) return NULL; - char *filename = b_strdup(f); + char *filename = sb_strdup(f); // keep a pointer to original string char *tmp = filename; @@ -52,14 +52,14 @@ blogc_get_filename(const char *f) } } - char *final_filename = b_strdup(tmp); + char *final_filename = sb_strdup(tmp); free(filename); return final_filename; } -b_slist_t* +sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -68,13 +68,13 @@ blogc_template_parse_from_file(const char *f, blogc_error_t **err) char *s = blogc_file_get_contents(f, &len, err); if (s == NULL) return NULL; - b_slist_t *rv = blogc_template_parse(s, len, err); + sb_slist_t *rv = blogc_template_parse(s, len, err); free(s); return rv; } -b_trie_t* +sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -83,13 +83,13 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) char *s = blogc_file_get_contents(f, &len, err); if (s == NULL) return NULL; - b_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) - b_trie_insert(rv, "FILENAME", filename); + sb_trie_insert(rv, "FILENAME", filename); } free(s); @@ -97,16 +97,16 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) } -b_slist_t* -blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) +sb_slist_t* +blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err) { blogc_error_t *tmp_err = NULL; - b_slist_t *rv = NULL; + sb_slist_t *rv = NULL; unsigned int with_date = 0; - const char *filter_tag = b_trie_lookup(conf, "FILTER_TAG"); - const char *filter_page = b_trie_lookup(conf, "FILTER_PAGE"); - const char *filter_per_page = b_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"); long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10); if (page <= 0) @@ -121,27 +121,27 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) unsigned int end = start + per_page; unsigned int counter = 0; - for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { + for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { char *f = tmp->data; - b_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 = blogc_error_new_printf(BLOGC_ERROR_LOADER, "An error occurred while parsing source file: %s\n\n%s", f, tmp_err->msg); blogc_error_free(tmp_err); tmp_err = NULL; - b_slist_free_full(rv, (b_free_func_t) b_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 = b_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) { - b_trie_free(s); + sb_trie_free(s); continue; } - char **tags = b_str_split(tags_str, ' ', 0); + char **tags = sb_str_split(tags_str, ' ', 0); bool found = false; for (unsigned int i = 0; tags[i] != NULL; i++) { if (tags[i][0] == '\0') @@ -149,26 +149,26 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) if (0 == strcmp(tags[i], filter_tag)) found = true; } - b_strv_free(tags); + sb_strv_free(tags); if (!found) { - b_trie_free(s); + sb_trie_free(s); continue; } } if (filter_page != NULL) { if (counter < start || counter >= end) { counter++; - b_trie_free(s); + sb_trie_free(s); continue; } counter++; } - if (b_trie_lookup(s, "DATE") != NULL) + if (sb_trie_lookup(s, "DATE") != NULL) with_date++; - rv = b_slist_append(rv, s); + rv = sb_slist_append(rv, s); } - if (with_date > 0 && with_date < b_slist_length(rv)) + if (with_date > 0 && with_date < sb_slist_length(rv)) // fatal error, maybe? blogc_fprintf(stderr, "blogc: warning: 'DATE' variable provided for at least one source " @@ -176,38 +176,38 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) "wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n"); bool first = true; - for (b_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) { - b_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 = b_trie_lookup(s, "DATE"); + const char *val = sb_trie_lookup(s, "DATE"); if (val != NULL) - b_trie_insert(conf, "DATE_FIRST", b_strdup(val)); - val = b_trie_lookup(s, "FILENAME"); + sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val)); + val = sb_trie_lookup(s, "FILENAME"); if (val != NULL) - b_trie_insert(conf, "FILENAME_FIRST", b_strdup(val)); + sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val)); first = false; } if (tmp->next == NULL) { // last - const char *val = b_trie_lookup(s, "DATE"); + const char *val = sb_trie_lookup(s, "DATE"); if (val != NULL) - b_trie_insert(conf, "DATE_LAST", b_strdup(val)); - val = b_trie_lookup(s, "FILENAME"); + sb_trie_insert(conf, "DATE_LAST", sb_strdup(val)); + val = sb_trie_lookup(s, "FILENAME"); if (val != NULL) - b_trie_insert(conf, "FILENAME_LAST", b_strdup(val)); + sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val)); } } if (filter_page != NULL) { unsigned int last_page = ceilf(((float) counter) / per_page); - b_trie_insert(conf, "CURRENT_PAGE", b_strdup_printf("%ld", page)); + sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page)); if (page > 1) - b_trie_insert(conf, "PREVIOUS_PAGE", b_strdup_printf("%ld", page - 1)); + sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1)); if (page < last_page) - b_trie_insert(conf, "NEXT_PAGE", b_strdup_printf("%ld", page + 1)); - if (b_slist_length(rv) > 0) - b_trie_insert(conf, "FIRST_PAGE", b_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) - b_trie_insert(conf, "LAST_PAGE", b_strdup_printf("%d", last_page)); + sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page)); } return rv; |