diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-03 20:42:17 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-03 20:42:17 +0200 |
commit | a319fe44f6d50d25f546e17ad9907eedd9a358a0 (patch) | |
tree | 4fdca76c71af9cc78ae2683fa3d8a1589a78d71c /src | |
parent | 6c5adce7b557c696cb6b5a5ebd4cd1e9380ac419 (diff) | |
download | blogc-a319fe44f6d50d25f546e17ad9907eedd9a358a0.tar.gz blogc-a319fe44f6d50d25f546e17ad9907eedd9a358a0.tar.bz2 blogc-a319fe44f6d50d25f546e17ad9907eedd9a358a0.zip |
*: s/sb_/bc_/g
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc-git-receiver/main.c | 18 | ||||
-rw-r--r-- | src/blogc-runserver/main.c | 26 | ||||
-rw-r--r-- | src/blogc/content-parser.c | 334 | ||||
-rw-r--r-- | src/blogc/datetime-parser.c | 2 | ||||
-rw-r--r-- | src/blogc/debug.c | 4 | ||||
-rw-r--r-- | src/blogc/debug.h | 2 | ||||
-rw-r--r-- | src/blogc/error.c | 10 | ||||
-rw-r--r-- | src/blogc/file.c | 8 | ||||
-rw-r--r-- | src/blogc/loader.c | 82 | ||||
-rw-r--r-- | src/blogc/loader.h | 6 | ||||
-rw-r--r-- | src/blogc/main.c | 50 | ||||
-rw-r--r-- | src/blogc/renderer.c | 70 | ||||
-rw-r--r-- | src/blogc/renderer.h | 14 | ||||
-rw-r--r-- | src/blogc/source-parser.c | 28 | ||||
-rw-r--r-- | src/blogc/source-parser.h | 2 | ||||
-rw-r--r-- | src/blogc/template-parser.c | 40 | ||||
-rw-r--r-- | src/blogc/template-parser.h | 4 | ||||
-rw-r--r-- | src/common/utf8.c | 2 | ||||
-rw-r--r-- | src/common/utf8.h | 2 | ||||
-rw-r--r-- | src/common/utils.c | 206 | ||||
-rw-r--r-- | src/common/utils.h | 98 |
21 files changed, 504 insertions, 504 deletions
diff --git a/src/blogc-git-receiver/main.c b/src/blogc-git-receiver/main.c index 554ec0c..86e1027 100644 --- a/src/blogc-git-receiver/main.c +++ b/src/blogc-git-receiver/main.c @@ -60,7 +60,7 @@ rmdir_recursive(const char *dir) while (NULL != (e = readdir(d))) { if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, ".."))) continue; - char *f = sb_strdup_printf("%s/%s", dir, e->d_name); + char *f = bc_strdup_printf("%s/%s", dir, e->d_name); if (0 != stat(f, &buf)) { fprintf(stderr, "error: failed to stat directory entry (%s): %s\n", e->d_name, strerror(errno)); @@ -131,7 +131,7 @@ git_shell(int argc, char *argv[]) } // get git repository - command_orig = sb_strdup(argv[2]); + command_orig = bc_strdup(argv[2]); char *p, *r; for (p = command_orig; *p != ' ' && *p != '\0'; p++); if (*p == ' ') @@ -146,7 +146,7 @@ git_shell(int argc, char *argv[]) if (*--p == '/') *p = '\0'; - repo = sb_strdup_printf("repos/%s", r); + repo = bc_strdup_printf("repos/%s", r); // check if repository is sane if (0 == strlen(repo)) { @@ -166,7 +166,7 @@ git_shell(int argc, char *argv[]) } if (0 != access(repo, F_OK)) { - char *git_init_cmd = sb_strdup_printf( + char *git_init_cmd = bc_strdup_printf( "git init --bare \"%s\" > /dev/null", repo); if (0 != system(git_init_cmd)) { fprintf(stderr, "error: failed to create git repository: %s\n", @@ -243,7 +243,7 @@ git_shell(int argc, char *argv[]) } git_exec: - command_name = sb_strdup(argv[2]); + command_name = bc_strdup(argv[2]); for (p = command_name; *p != ' ' && *p != '\0'; p++); if (*p == ' ') *p = '\0'; @@ -386,7 +386,7 @@ git_pre_receive_hook(int argc, char *argv[]) goto cleanup; } - repo_dir = sb_strdup(buffer); + repo_dir = bc_strdup(buffer); char dir[] = "/tmp/blogc_XXXXXX"; if (NULL == mkdtemp(dir)) { @@ -394,7 +394,7 @@ git_pre_receive_hook(int argc, char *argv[]) goto cleanup; } - char *git_archive_cmd = sb_strdup_printf( + char *git_archive_cmd = bc_strdup_printf( "git archive \"%s\" | tar -x -C \"%s\" -f -", master, dir); if (0 != system(git_archive_cmd)) { fprintf(stderr, "error: failed to extract git content to temporary " @@ -425,8 +425,8 @@ git_pre_receive_hook(int argc, char *argv[]) } unsigned long epoch = time(NULL); - output_dir = sb_strdup_printf("%s/builds/%s-%lu", home, master, epoch); - char *gmake_cmd = sb_strdup_printf( + output_dir = bc_strdup_printf("%s/builds/%s-%lu", home, master, epoch); + char *gmake_cmd = bc_strdup_printf( "gmake -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1", cpu_count(), output_dir); fprintf(stdout, "running command: %s\n\n", gmake_cmd); diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c index 2a756f1..93f404a 100644 --- a/src/blogc-runserver/main.c +++ b/src/blogc-runserver/main.c @@ -87,9 +87,9 @@ guess_content_type(const char *filename, int fd) const char* charset = magic_descriptor(magic_charset, newfd); close(newfd); if (charset != NULL) - return sb_strdup_printf("%s; charset=%s", supported, charset); + return bc_strdup_printf("%s; charset=%s", supported, charset); } - return sb_strdup(supported); + return bc_strdup(supported); } libmagic: @@ -100,9 +100,9 @@ libmagic: const char* content_type = magic_descriptor(magic_all, newfd); close(newfd); if (content_type != NULL) - return sb_strdup(content_type); + return bc_strdup(content_type); } - return sb_strdup("application/octet-stream"); + return bc_strdup("application/octet-stream"); } @@ -128,7 +128,7 @@ handler(struct evhttp_request *request, void *ptr) goto point1; } - char *abs_path = sb_strdup_printf("%s/%s", root, decoded_path); + char *abs_path = bc_strdup_printf("%s/%s", root, decoded_path); char *real_path = realpath(abs_path, NULL); free(abs_path); @@ -162,10 +162,10 @@ handler(struct evhttp_request *request, void *ptr) for (unsigned int i = 0; content_types[i].mimetype != NULL; i++) { if (content_types[i].index == NULL) continue; - char *f = sb_strdup_printf("%s/%s", real_path, + char *f = bc_strdup_printf("%s/%s", real_path, content_types[i].index); if (0 == access(f, F_OK)) { - found = sb_strdup(f); + found = bc_strdup(f); break; } free(f); @@ -200,7 +200,7 @@ handler(struct evhttp_request *request, void *ptr) struct evkeyvalq *headers = evhttp_request_get_output_headers(request); if (add_slash) { - char *tmp = sb_strdup_printf("%s/", path); + char *tmp = bc_strdup_printf("%s/", path); evhttp_add_header(headers, "Location", tmp); free(tmp); // production webservers usually returns 301 in such cases, but 302 is @@ -210,7 +210,7 @@ handler(struct evhttp_request *request, void *ptr) } evhttp_add_header(headers, "Content-Type", type); - char *content_length = sb_strdup_printf("%zu", st.st_size); + char *content_length = bc_strdup_printf("%zu", st.st_size); evhttp_add_header(headers, "Content-Length", content_length); free(content_length); @@ -313,9 +313,9 @@ main(int argc, char **argv) goto cleanup; case 't': if (argv[i][2] != '\0') - host = sb_strdup(argv[i] + 2); + host = bc_strdup(argv[i] + 2); else - host = sb_strdup(argv[++i]); + host = bc_strdup(argv[++i]); break; case 'p': if (argv[i][2] != '\0') @@ -340,7 +340,7 @@ main(int argc, char **argv) goto cleanup; } args++; - docroot = sb_strdup(argv[i]); + docroot = bc_strdup(argv[i]); } } @@ -353,7 +353,7 @@ main(int argc, char **argv) } if (host == NULL) - host = sb_strdup("127.0.0.1"); + host = bc_strdup("127.0.0.1"); magic_all = magic_open(MAGIC_MIME); magic_charset = magic_open(MAGIC_MIME_ENCODING); diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c index e751548..23586bb 100644 --- a/src/blogc/content-parser.c +++ b/src/blogc/content-parser.c @@ -22,7 +22,7 @@ blogc_slugify(const char *str) { if (str == NULL) return NULL; - char *new_str = sb_strdup(str); + char *new_str = bc_strdup(str); int diff = 'a' - 'A'; // just to avoid magic numbers for (size_t i = 0; new_str[i] != '\0'; i++) { if (new_str[i] >= 'a' && new_str[i] <= 'z') @@ -60,13 +60,13 @@ htmlentities(char c) static void -htmlentities_append(sb_string_t *str, char c) +htmlentities_append(bc_string_t *str, char c) { const char *e = htmlentities(c); if (e == NULL) - sb_string_append_c(str, c); + bc_string_append_c(str, c); else - sb_string_append(str, e); + bc_string_append(str, e); } @@ -75,10 +75,10 @@ blogc_htmlentities(const char *str) { if (str == NULL) return NULL; - sb_string_t *rv = sb_string_new(); + bc_string_t *rv = bc_string_new(); for (size_t i = 0; str[i] != '\0'; i++) htmlentities_append(rv, str[i]); - return sb_string_free(rv, false); + return bc_string_free(rv, false); } @@ -87,7 +87,7 @@ blogc_fix_description(const char *paragraph) { if (paragraph == NULL) return NULL; - sb_string_t *rv = sb_string_new(); + bc_string_t *rv = bc_string_new(); bool last = false; bool newline = false; char *tmp = NULL; @@ -101,12 +101,12 @@ blogc_fix_description(const char *paragraph) case '\n': if (newline) break; - tmp = sb_strndup(paragraph + start, current - start); - sb_string_append(rv, sb_str_strip(tmp)); + tmp = bc_strndup(paragraph + start, current - start); + bc_string_append(rv, bc_str_strip(tmp)); free(tmp); tmp = NULL; if (!last) - sb_string_append_c(rv, ' '); + bc_string_append_c(rv, ' '); start = current + 1; newline = true; break; @@ -117,8 +117,8 @@ blogc_fix_description(const char *paragraph) break; current++; } - tmp = blogc_htmlentities(sb_str_strip(rv->str)); - sb_string_free(rv, true); + tmp = blogc_htmlentities(bc_str_strip(rv->str)); + bc_string_free(rv, true); return tmp; } @@ -189,7 +189,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) size_t start_link = 0; char *link1 = NULL; - sb_string_t *rv = sb_string_new(); + bc_string_t *rv = bc_string_new(); blogc_content_parser_inline_state_t state = CONTENT_INLINE_START; @@ -243,15 +243,15 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) state = CONTENT_INLINE_ASTERISK_DOUBLE; break; } - tmp = sb_str_find(src + current, '*'); + tmp = bc_str_find(src + current, '*'); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '*'); + bc_string_append_c(rv, '*'); state = CONTENT_INLINE_START; continue; } tmp2 = blogc_content_parse_inline_internal( src + current, (tmp - src) - current); - sb_string_append_printf(rv, "<em>%s</em>", tmp2); + bc_string_append_printf(rv, "<em>%s</em>", tmp2); current = tmp - src; tmp = NULL; free(tmp2); @@ -262,21 +262,21 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_ASTERISK_DOUBLE: tmp = src + current; do { - tmp = sb_str_find(tmp, '*'); + tmp = bc_str_find(tmp, '*'); if (((tmp - src) < src_len) && *(tmp + 1) == '*') { break; } tmp++; } while (tmp != NULL && (tmp - src) < src_len); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '*'); - sb_string_append_c(rv, '*'); + bc_string_append_c(rv, '*'); + bc_string_append_c(rv, '*'); state = CONTENT_INLINE_START; continue; } tmp2 = blogc_content_parse_inline_internal( src + current, (tmp - src) - current); - sb_string_append_printf(rv, "<strong>%s</strong>", tmp2); + bc_string_append_printf(rv, "<strong>%s</strong>", tmp2); current = tmp - src + 1; tmp = NULL; free(tmp2); @@ -289,15 +289,15 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) state = CONTENT_INLINE_UNDERSCORE_DOUBLE; break; } - tmp = sb_str_find(src + current, '_'); + tmp = bc_str_find(src + current, '_'); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '_'); + bc_string_append_c(rv, '_'); state = CONTENT_INLINE_START; continue; } tmp2 = blogc_content_parse_inline_internal( src + current, (tmp - src) - current); - sb_string_append_printf(rv, "<em>%s</em>", tmp2); + bc_string_append_printf(rv, "<em>%s</em>", tmp2); current = tmp - src; tmp = NULL; free(tmp2); @@ -308,21 +308,21 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_UNDERSCORE_DOUBLE: tmp = src + current; do { - tmp = sb_str_find(tmp, '_'); + tmp = bc_str_find(tmp, '_'); if (((tmp - src) < src_len) && *(tmp + 1) == '_') { break; } tmp++; } while (tmp != NULL && (tmp - src) < src_len); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '_'); - sb_string_append_c(rv, '_'); + bc_string_append_c(rv, '_'); + bc_string_append_c(rv, '_'); state = CONTENT_INLINE_START; continue; } tmp2 = blogc_content_parse_inline_internal( src + current, (tmp - src) - current); - sb_string_append_printf(rv, "<strong>%s</strong>", tmp2); + bc_string_append_printf(rv, "<strong>%s</strong>", tmp2); current = tmp - src + 1; tmp = NULL; free(tmp2); @@ -335,19 +335,19 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) state = CONTENT_INLINE_BACKTICKS_DOUBLE; break; } - tmp = sb_str_find(src + current, '`'); + tmp = bc_str_find(src + current, '`'); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '`'); + bc_string_append_c(rv, '`'); state = CONTENT_INLINE_START; continue; } - tmp3 = sb_strndup(src + current, (tmp - src) - current); + tmp3 = bc_strndup(src + current, (tmp - src) - current); tmp2 = blogc_htmlentities(tmp3); free(tmp3); tmp3 = NULL; - sb_string_append(rv, "<code>"); - sb_string_append_escaped(rv, tmp2); - sb_string_append(rv, "</code>"); + bc_string_append(rv, "<code>"); + bc_string_append_escaped(rv, tmp2); + bc_string_append(rv, "</code>"); current = tmp - src; tmp = NULL; free(tmp2); @@ -358,25 +358,25 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_BACKTICKS_DOUBLE: tmp = src + current; do { - tmp = sb_str_find(tmp, '`'); + tmp = bc_str_find(tmp, '`'); if (((tmp - src) < src_len) && *(tmp + 1) == '`') { break; } tmp++; } while (tmp != NULL && (tmp - src) < src_len); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '`'); - sb_string_append_c(rv, '`'); + bc_string_append_c(rv, '`'); + bc_string_append_c(rv, '`'); state = CONTENT_INLINE_START; continue; } - tmp3 = sb_strndup(src + current, (tmp - src) - current); + tmp3 = bc_strndup(src + current, (tmp - src) - current); tmp2 = blogc_htmlentities(tmp3); free(tmp3); tmp3 = NULL; - sb_string_append(rv, "<code>"); - sb_string_append_escaped(rv, tmp2); - sb_string_append(rv, "</code>"); + bc_string_append(rv, "<code>"); + bc_string_append_escaped(rv, tmp2); + bc_string_append(rv, "</code>"); current = tmp - src + 1; tmp = NULL; free(tmp2); @@ -397,24 +397,24 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_LINK_AUTO: tmp = src + current; do { - tmp = sb_str_find(tmp, ']'); + tmp = bc_str_find(tmp, ']'); if (((tmp - src) < src_len) && *(tmp + 1) == ']') { break; } tmp++; } while (tmp != NULL && (tmp - src) < src_len); if (tmp == NULL || ((tmp - src) >= src_len)) { - sb_string_append_c(rv, '['); - sb_string_append_c(rv, '['); + bc_string_append_c(rv, '['); + bc_string_append_c(rv, '['); state = CONTENT_INLINE_START; continue; } - tmp2 = sb_strndup(src + current, (tmp - src) - current); - sb_string_append(rv, "<a href=\""); - sb_string_append_escaped(rv, tmp2); - sb_string_append(rv, "\">"); - sb_string_append_escaped(rv, tmp2); - sb_string_append(rv, "</a>"); + tmp2 = bc_strndup(src + current, (tmp - src) - current); + bc_string_append(rv, "<a href=\""); + bc_string_append_escaped(rv, tmp2); + bc_string_append(rv, "\">"); + bc_string_append_escaped(rv, tmp2); + bc_string_append(rv, "</a>"); current = tmp - src + 1; tmp = NULL; free(tmp2); @@ -433,7 +433,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) } if (c == ']') { if (--count == 0) { - link1 = sb_strndup(src + start_link, current - start_link); + link1 = bc_strndup(src + start_link, current - start_link); state = CONTENT_INLINE_LINK_URL_START; } } @@ -447,7 +447,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) start = current + 1; break; } - sb_string_append_c(rv, '['); + bc_string_append_c(rv, '['); state = CONTENT_INLINE_START; current = start_link; start_link = 0; @@ -459,13 +459,13 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) break; } if (c == ')') { - tmp2 = sb_strndup(src + start, current - start); + tmp2 = bc_strndup(src + start, current - start); tmp3 = blogc_content_parse_inline(link1); free(link1); link1 = NULL; - sb_string_append(rv, "<a href=\""); - sb_string_append_escaped(rv, tmp2); - sb_string_append_printf(rv, "\">%s</a>", tmp3); + bc_string_append(rv, "<a href=\""); + bc_string_append_escaped(rv, tmp2); + bc_string_append_printf(rv, "\">%s</a>", tmp3); free(tmp2); tmp2 = NULL; free(tmp3); @@ -482,7 +482,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) start_link = current + 1; break; } - sb_string_append_c(rv, '!'); + bc_string_append_c(rv, '!'); state = CONTENT_INLINE_START; continue; @@ -492,7 +492,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) break; } if (c == ']') { - link1 = sb_strndup(src + start_link, current - start_link); + link1 = bc_strndup(src + start_link, current - start_link); state = CONTENT_INLINE_IMAGE_URL_START; } break; @@ -505,8 +505,8 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) start = current + 1; break; } - sb_string_append_c(rv, '!'); - sb_string_append_c(rv, '['); + bc_string_append_c(rv, '!'); + bc_string_append_c(rv, '['); state = CONTENT_INLINE_START; current = start_link; start_link = 0; @@ -518,12 +518,12 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) break; } if (c == ')') { - tmp2 = sb_strndup(src + start, current - start); - sb_string_append(rv, "<img src=\""); - sb_string_append_escaped(rv, tmp2); - sb_string_append(rv, "\" alt=\""); - sb_string_append_escaped(rv, link1); - sb_string_append(rv, "\">"); + tmp2 = bc_strndup(src + start, current - start); + bc_string_append(rv, "<img src=\""); + bc_string_append_escaped(rv, tmp2); + bc_string_append(rv, "\" alt=\""); + bc_string_append_escaped(rv, link1); + bc_string_append(rv, "\">"); free(tmp2); tmp2 = NULL; free(link1); @@ -536,31 +536,31 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_ENDASH: if (c == '-') { if (is_last) { - sb_string_append(rv, "–"); + bc_string_append(rv, "–"); state = CONTENT_INLINE_START; // wat break; } state = CONTENT_INLINE_EMDASH; break; } - sb_string_append_c(rv, '-'); + bc_string_append_c(rv, '-'); state = CONTENT_INLINE_START; continue; case CONTENT_INLINE_EMDASH: if (c == '-') { - sb_string_append(rv, "—"); + bc_string_append(rv, "—"); state = CONTENT_INLINE_START; break; } - sb_string_append(rv, "–"); + bc_string_append(rv, "–"); state = CONTENT_INLINE_START; continue; case CONTENT_INLINE_LINE_BREAK_START: if (c == ' ') { if (is_last) { - sb_string_append(rv, "<br />"); + bc_string_append(rv, "<br />"); state = CONTENT_INLINE_START; // wat break; } @@ -568,14 +568,14 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) state = CONTENT_INLINE_LINE_BREAK; break; } - sb_string_append_c(rv, ' '); + bc_string_append_c(rv, ' '); state = CONTENT_INLINE_START; continue; case CONTENT_INLINE_LINE_BREAK: if (c == ' ') { if (is_last) { - sb_string_append(rv, "<br />"); + bc_string_append(rv, "<br />"); state = CONTENT_INLINE_START; // wat break; } @@ -583,12 +583,12 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) break; } if (c == '\n' || c == '\r') { - sb_string_append_printf(rv, "<br />%c", c); + bc_string_append_printf(rv, "<br />%c", c); state = CONTENT_INLINE_START; break; } for (size_t i = 0; i < count; i++) - sb_string_append_c(rv, ' '); + bc_string_append_c(rv, ' '); state = CONTENT_INLINE_START; continue; } @@ -603,14 +603,14 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) case CONTENT_INLINE_IMAGE_ALT: case CONTENT_INLINE_IMAGE_URL_START: case CONTENT_INLINE_IMAGE_URL: - sb_string_append_c(rv, '!'); + bc_string_append_c(rv, '!'); case CONTENT_INLINE_LINK_CONTENT: case CONTENT_INLINE_LINK_URL_START: case CONTENT_INLINE_LINK_URL: tmp2 = blogc_content_parse_inline(src + start_link); - sb_string_append_c(rv, '['); - sb_string_append_escaped(rv, tmp2); // no need to free, as it wil be done below. + bc_string_append_c(rv, '['); + bc_string_append_escaped(rv, tmp2); // no need to free, as it wil be done below. break; // add all the other states here explicitly, so the compiler helps us @@ -635,7 +635,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len) free(tmp3); free(link1); - return sb_string_free(rv, false); + return bc_string_free(rv, false); } @@ -702,11 +702,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) char d = '\0'; - sb_slist_t *lines = NULL; - sb_slist_t *lines2 = NULL; + bc_slist_t *lines = NULL; + bc_slist_t *lines2 = NULL; - sb_string_t *rv = sb_string_new(); - sb_string_t *tmp_str = NULL; + bc_string_t *rv = bc_string_new(); + bc_string_t *tmp_str = NULL; blogc_content_parser_state_t state = CONTENT_START_LINE; @@ -833,14 +833,14 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); - tmp = sb_strndup(src + start, end - start); + tmp = bc_strndup(src + start, end - start); parsed = blogc_content_parse_inline(tmp); slug = blogc_slugify(tmp); if (slug == NULL) - sb_string_append_printf(rv, "<h%d>%s</h%d>%s", + bc_string_append_printf(rv, "<h%d>%s</h%d>%s", header_level, parsed, header_level, line_ending); else - sb_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s", + bc_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s", header_level, slug, parsed, header_level, line_ending); free(slug); @@ -864,8 +864,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_HTML_END: if (c == '\n' || c == '\r' || is_last) { - tmp = sb_strndup(src + start, end - start); - sb_string_append_printf(rv, "%s%s", tmp, line_ending); + tmp = bc_strndup(src + start, end - start); + bc_string_append_printf(rv, "%s%s", tmp, line_ending); free(tmp); tmp = NULL; state = CONTENT_START_LINE; @@ -878,7 +878,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_BLOCKQUOTE: if (c == ' ' || c == '\t') break; - prefix = sb_strndup(src + start, current - start); + prefix = bc_strndup(src + start, current - start); state = CONTENT_BLOCKQUOTE_START; break; @@ -886,16 +886,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); - tmp = sb_strndup(src + start2, end - start2); - if (sb_str_starts_with(tmp, prefix)) { - lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix))); + tmp = bc_strndup(src + start2, end - start2); + if (bc_str_starts_with(tmp, prefix)) { + lines = bc_slist_append(lines, bc_strdup(tmp + strlen(prefix))); state = CONTENT_BLOCKQUOTE_END; } else { state = CONTENT_PARAGRAPH; free(prefix); prefix = NULL; - sb_slist_free_full(lines, free); + bc_slist_free_full(lines, free); lines = NULL; if (is_last) { free(tmp); @@ -911,21 +911,21 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_BLOCKQUOTE_END: if (c == '\n' || c == '\r' || is_last) { - tmp_str = sb_string_new(); - for (sb_slist_t *l = lines; l != NULL; l = l->next) - sb_string_append_printf(tmp_str, "%s%s", l->data, + tmp_str = bc_string_new(); + for (bc_slist_t *l = lines; l != NULL; l = l->next) + bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); // do not propagate description to blockquote parsing, // because we just want paragraphs from first level of // content. tmp = blogc_content_parse(tmp_str->str, NULL, NULL); - sb_string_append_printf(rv, "<blockquote>%s</blockquote>%s", + bc_string_append_printf(rv, "<blockquote>%s</blockquote>%s", tmp, line_ending); free(tmp); tmp = NULL; - sb_string_free(tmp_str, true); + bc_string_free(tmp_str, true); tmp_str = NULL; - sb_slist_free_full(lines, free); + bc_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -941,7 +941,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_CODE: if (c == ' ' || c == '\t') break; - prefix = sb_strndup(src + start, current - start); + prefix = bc_strndup(src + start, current - start); state = CONTENT_CODE_START; break; @@ -949,16 +949,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); - tmp = sb_strndup(src + start2, end - start2); - if (sb_str_starts_with(tmp, prefix)) { - lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix))); + tmp = bc_strndup(src + start2, end - start2); + if (bc_str_starts_with(tmp, prefix)) { + lines = bc_slist_append(lines, bc_strdup(tmp + strlen(prefix))); state = CONTENT_CODE_END; } else { state = CONTENT_PARAGRAPH; free(prefix); prefix = NULL; - sb_slist_free_full(lines, free); + bc_slist_free_full(lines, free); lines = NULL; free(tmp); tmp = NULL; @@ -974,18 +974,18 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_CODE_END: if (c == '\n' || c == '\r' || is_last) { - sb_string_append(rv, "<pre><code>"); - for (sb_slist_t *l = lines; l != NULL; l = l->next) { + bc_string_append(rv, "<pre><code>"); + for (bc_slist_t *l = lines; l != NULL; l = l->next) { char *tmp_line = blogc_htmlentities(l->data); if (l->next == NULL) - sb_string_append_printf(rv, "%s", tmp_line); + bc_string_append_printf(rv, "%s", tmp_line); else - sb_string_append_printf(rv, "%s%s", tmp_line, + bc_string_append_printf(rv, "%s%s", tmp_line, line_ending); free(tmp_line); } - sb_string_append_printf(rv, "</code></pre>%s", line_ending); - sb_slist_free_full(lines, free); + bc_string_append_printf(rv, "</code></pre>%s", line_ending); + bc_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -1007,7 +1007,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) } if (c == ' ' || c == '\t') break; - prefix = sb_strndup(src + start, current - start); + prefix = bc_strndup(src + start, current - start); state = CONTENT_UNORDERED_LIST_START; break; @@ -1016,7 +1016,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) break; } if (c == '\n' || c == '\r' || is_last) { - sb_string_append_printf(rv, "<hr />%s", line_ending); + bc_string_append_printf(rv, "<hr />%s", line_ending); state = CONTENT_START_LINE; start = current; d = '\0'; @@ -1029,30 +1029,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); - tmp = sb_strndup(src + start2, end - start2); - tmp2 = sb_strdup_printf("%-*s", strlen(prefix), ""); - if (sb_str_starts_with(tmp, prefix)) { + tmp = bc_strndup(src + start2, end - start2); + tmp2 = bc_strdup_printf("%-*s", strlen(prefix), ""); + if (bc_str_starts_with(tmp, prefix)) { if (lines2 != NULL) { - tmp_str = sb_string_new(); - for (sb_slist_t *l = lines2; l != NULL; l = l->next) { + tmp_str = bc_string_new(); + for (bc_slist_t *l = lines2; l != NULL; l = l->next) { if (l->next == NULL) - sb_string_append_printf(tmp_str, "%s", l->data); + bc_string_append_printf(tmp_str, "%s", l->data); else - sb_string_append_printf(tmp_str, "%s%s", l->data, + bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); } - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines2, free); lines2 = NULL; parsed = blogc_content_parse_inline(tmp_str->str); - sb_string_free(tmp_str, true); - lines = sb_slist_append(lines, sb_strdup(parsed)); + bc_string_free(tmp_str, true); + lines = bc_slist_append(lines, bc_strdup(parsed)); free(parsed); parsed = NULL; } - lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix))); + lines2 = bc_slist_append(lines2, bc_strdup(tmp + strlen(prefix))); } - else if (sb_str_starts_with(tmp, tmp2)) { - lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix))); + else if (bc_str_starts_with(tmp, tmp2)) { + lines2 = bc_slist_append(lines2, bc_strdup(tmp + strlen(prefix))); } else { state = CONTENT_PARAGRAPH_END; @@ -1062,8 +1062,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) tmp2 = NULL; free(prefix); prefix = NULL; - sb_slist_free_full(lines, free); - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines, free); + bc_slist_free_full(lines2, free); lines = NULL; if (is_last) continue; @@ -1082,28 +1082,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { if (lines2 != NULL) { // FIXME: avoid repeting the code below - tmp_str = sb_string_new(); - for (sb_slist_t *l = lines2; l != NULL; l = l->next) { + tmp_str = bc_string_new(); + for (bc_slist_t *l = lines2; l != NULL; l = l->next) { if (l->next == NULL) - sb_string_append_printf(tmp_str, "%s", l->data); + bc_string_append_printf(tmp_str, "%s", l->data); else - sb_string_append_printf(tmp_str, "%s%s", l->data, + bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); } - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines2, free); lines2 = NULL; parsed = blogc_content_parse_inline(tmp_str->str); - sb_string_free(tmp_str, true); - lines = sb_slist_append(lines, sb_strdup(parsed)); + bc_string_free(tmp_str, true); + lines = bc_slist_append(lines, bc_strdup(parsed)); free(parsed); parsed = NULL; } - sb_string_append_printf(rv, "<ul>%s", line_ending); - for (sb_slist_t *l = lines; l != NULL; l = l->next) - sb_string_append_printf(rv, "<li>%s</li>%s", l->data, + bc_string_append_printf(rv, "<ul>%s", line_ending); + for (bc_slist_t *l = lines; l != NULL; l = l->next) + bc_string_append_printf(rv, "<li>%s</li>%s", l->data, line_ending); - sb_string_append_printf(rv, "</ul>%s", line_ending); - sb_slist_free_full(lines, free); + bc_string_append_printf(rv, "</ul>%s", line_ending); + bc_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -1140,30 +1140,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { end = is_last && c != '\n' && c != '\r' ? src_len : (real_end != 0 ? real_end : current); - tmp = sb_strndup(src + start2, end - start2); - tmp2 = sb_strdup_printf("%-*s", prefix_len, ""); + tmp = bc_strndup(src + start2, end - start2); + tmp2 = bc_strdup_printf("%-*s", prefix_len, ""); if (blogc_is_ordered_list_item(tmp, prefix_len)) { if (lines2 != NULL) { - tmp_str = sb_string_new(); - for (sb_slist_t *l = lines2; l != NULL; l = l->next) { + tmp_str = bc_string_new(); + for (bc_slist_t *l = lines2; l != NULL; l = l->next) { if (l->next == NULL) - sb_string_append_printf(tmp_str, "%s", l->data); + bc_string_append_printf(tmp_str, "%s", l->data); else - sb_string_append_printf(tmp_str, "%s%s", l->data, + bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); } - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines2, free); lines2 = NULL; parsed = blogc_content_parse_inline(tmp_str->str); - sb_string_free(tmp_str, true); - lines = sb_slist_append(lines, sb_strdup(parsed)); + bc_string_free(tmp_str, true); + lines = bc_slist_append(lines, bc_strdup(parsed)); free(parsed); parsed = NULL; } - lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len)); + lines2 = bc_slist_append(lines2, bc_strdup(tmp + prefix_len)); } - else if (sb_str_starts_with(tmp, tmp2)) { - lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len)); + else if (bc_str_starts_with(tmp, tmp2)) { + lines2 = bc_slist_append(lines2, bc_strdup(tmp + prefix_len)); } else { state = CONTENT_PARAGRAPH_END; @@ -1173,8 +1173,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) tmp2 = NULL; free(parsed); parsed = NULL; - sb_slist_free_full(lines, free); - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines, free); + bc_slist_free_full(lines2, free); lines = NULL; if (is_last) continue; @@ -1193,28 +1193,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) if (c == '\n' || c == '\r' || is_last) { if (lines2 != NULL) { // FIXME: avoid repeting the code below - tmp_str = sb_string_new(); - for (sb_slist_t *l = lines2; l != NULL; l = l->next) { + tmp_str = bc_string_new(); + for (bc_slist_t *l = lines2; l != NULL; l = l->next) { if (l->next == NULL) - sb_string_append_printf(tmp_str, "%s", l->data); + bc_string_append_printf(tmp_str, "%s", l->data); else - sb_string_append_printf(tmp_str, "%s%s", l->data, + bc_string_append_printf(tmp_str, "%s%s", l->data, line_ending); } - sb_slist_free_full(lines2, free); + bc_slist_free_full(lines2, free); lines2 = NULL; parsed = blogc_content_parse_inline(tmp_str->str); - sb_string_free(tmp_str, true); - lines = sb_slist_append(lines, sb_strdup(parsed)); + bc_string_free(tmp_str, true); + lines = bc_slist_append(lines, bc_strdup(parsed)); free(parsed); parsed = NULL; } - sb_string_append_printf(rv, "<ol>%s", line_ending); - for (sb_slist_t *l = lines; l != NULL; l = l->next) - sb_string_append_printf(rv, "<li>%s</li>%s", l->data, + bc_string_append_printf(rv, "<ol>%s", line_ending); + for (bc_slist_t *l = lines; l != NULL; l = l->next) + bc_string_append_printf(rv, "<li>%s</li>%s", l->data, line_ending); - sb_string_append_printf(rv, "</ol>%s", line_ending); - sb_slist_free_full(lines, free); + bc_string_append_printf(rv, "</ol>%s", line_ending); + bc_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -1238,11 +1238,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) case CONTENT_PARAGRAPH_END: if (c == '\n' || c == '\r' || is_last) { - tmp = sb_strndup(src + start, end - start); + tmp = bc_strndup(src + start, end - start); if (description != NULL && *description == NULL) *description = blogc_fix_description(tmp); parsed = blogc_content_parse_inline(tmp); - sb_string_append_printf(rv, "<p>%s</p>%s", parsed, + bc_string_append_printf(rv, "<p>%s</p>%s", parsed, line_ending); free(parsed); parsed = NULL; @@ -1260,5 +1260,5 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **description) current++; } - return sb_string_free(rv, false); + return bc_string_free(rv, false); } diff --git a/src/blogc/datetime-parser.c b/src/blogc/datetime-parser.c index 28efb74..a685c77 100644 --- a/src/blogc/datetime-parser.c +++ b/src/blogc/datetime-parser.c @@ -380,7 +380,7 @@ blogc_convert_datetime(const char *orig, const char *format, return NULL; } - return sb_strdup(buf); + return bc_strdup(buf); #endif } diff --git a/src/blogc/debug.c b/src/blogc/debug.c index 2840f60..0a50f52 100644 --- a/src/blogc/debug.c +++ b/src/blogc/debug.c @@ -34,9 +34,9 @@ get_operator(blogc_template_stmt_operator_t op) void -blogc_debug_template(sb_slist_t *stmts) +blogc_debug_template(bc_slist_t *stmts) { - for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { + for (bc_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { blogc_template_stmt_t *data = tmp->data; fprintf(stderr, "DEBUG: <TEMPLATE "); switch (data->type) { diff --git a/src/blogc/debug.h b/src/blogc/debug.h index eb4e2c1..1a4a257 100644 --- a/src/blogc/debug.h +++ b/src/blogc/debug.h @@ -11,6 +11,6 @@ #include "../common/utils.h" -void blogc_debug_template(sb_slist_t *stmts); +void blogc_debug_template(bc_slist_t *stmts); #endif /* ___DEBUG_H */ diff --git a/src/blogc/error.c b/src/blogc/error.c index 41f4cd0..cca8c03 100644 --- a/src/blogc/error.c +++ b/src/blogc/error.c @@ -16,9 +16,9 @@ blogc_error_t* blogc_error_new(blogc_error_type_t type, const char *msg) { - blogc_error_t *err = sb_malloc(sizeof(blogc_error_t)); + blogc_error_t *err = bc_malloc(sizeof(blogc_error_t)); err->type = type; - err->msg = sb_strdup(msg); + err->msg = bc_strdup(msg); return err; } @@ -28,7 +28,7 @@ blogc_error_new_printf(blogc_error_type_t type, const char *format, ...) { va_list ap; va_start(ap, format); - char *tmp = sb_strdup_vprintf(format, ap); + char *tmp = bc_strdup_vprintf(format, ap); va_end(ap); blogc_error_t *rv = blogc_error_new(type, tmp); free(tmp); @@ -42,7 +42,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, { va_list ap; va_start(ap, format); - char *msg = sb_strdup_vprintf(format, ap); + char *msg = bc_strdup_vprintf(format, ap); va_end(ap); size_t lineno = 1; @@ -83,7 +83,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, if (lineend <= linestart && src_len >= linestart) lineend = src_len; - char *line = sb_strndup(src + linestart, lineend - linestart); + char *line = bc_strndup(src + linestart, lineend - linestart); blogc_error_t *rv = NULL; diff --git a/src/blogc/file.c b/src/blogc/file.c index b3b0c5b..cdd6df4 100644 --- a/src/blogc/file.c +++ b/src/blogc/file.c @@ -37,7 +37,7 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) return NULL; } - sb_string_t *str = sb_string_new(); + bc_string_t *str = bc_string_new(); char buffer[BLOGC_FILE_CHUNK_SIZE]; char *tmp; @@ -55,18 +55,18 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) } *len += read_len; - sb_string_append_len(str, tmp, read_len); + bc_string_append_len(str, tmp, read_len); } fclose(fp); if (!blogc_utf8_validate_str(str)) { *err = blogc_error_new_printf(BLOGC_ERROR_FILE, "File content is not valid UTF-8: %s", path); - sb_string_free(str, true); + bc_string_free(str, true); return NULL; } - return sb_string_free(str, false); + return bc_string_free(str, false); } diff --git a/src/blogc/loader.c b/src/blogc/loader.c index 90f2401..914f07f 100644 --- a/src/blogc/loader.c +++ b/src/blogc/loader.c @@ -29,7 +29,7 @@ blogc_get_filename(const char *f) if (strlen(f) == 0) return NULL; - char *filename = sb_strdup(f); + char *filename = bc_strdup(f); // keep a pointer to original string char *tmp = filename; @@ -50,14 +50,14 @@ blogc_get_filename(const char *f) } } - char *final_filename = sb_strdup(tmp); + char *final_filename = bc_strdup(tmp); free(filename); return final_filename; } -sb_slist_t* +bc_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -66,13 +66,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; - sb_slist_t *rv = blogc_template_parse(s, len, err); + bc_slist_t *rv = blogc_template_parse(s, len, err); free(s); return rv; } -sb_trie_t* +bc_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -81,13 +81,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; - sb_trie_t *rv = blogc_source_parse(s, len, err); + bc_trie_t *rv = blogc_source_parse(s, len, err); // set FILENAME variable if (rv != NULL) { char *filename = blogc_get_filename(f); if (filename != NULL) - sb_trie_insert(rv, "FILENAME", filename); + bc_trie_insert(rv, "FILENAME", filename); } free(s); @@ -95,16 +95,16 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) } -sb_slist_t* -blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err) +bc_slist_t* +blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, blogc_error_t **err) { blogc_error_t *tmp_err = NULL; - sb_slist_t *rv = NULL; + bc_slist_t *rv = NULL; unsigned int with_date = 0; - 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 *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"); long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10); if (page <= 0) @@ -119,27 +119,27 @@ blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **er unsigned int end = start + per_page; unsigned int counter = 0; - for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { + for (bc_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { char *f = tmp->data; - sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err); + bc_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; - sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free); + bc_slist_free_full(rv, (bc_free_func_t) bc_trie_free); rv = NULL; break; } if (filter_tag != NULL) { - const char *tags_str = sb_trie_lookup(s, "TAGS"); + const char *tags_str = bc_trie_lookup(s, "TAGS"); // if user wants to filter by tag and no tag is provided, skip it if (tags_str == NULL) { - sb_trie_free(s); + bc_trie_free(s); continue; } - char **tags = sb_str_split(tags_str, ' ', 0); + char **tags = bc_str_split(tags_str, ' ', 0); bool found = false; for (unsigned int i = 0; tags[i] != NULL; i++) { if (tags[i][0] == '\0') @@ -147,26 +147,26 @@ blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **er if (0 == strcmp(tags[i], filter_tag)) found = true; } - sb_strv_free(tags); + bc_strv_free(tags); if (!found) { - sb_trie_free(s); + bc_trie_free(s); continue; } } if (filter_page != NULL) { if (counter < start || counter >= end) { counter++; - sb_trie_free(s); + bc_trie_free(s); continue; } counter++; } - if (sb_trie_lookup(s, "DATE") != NULL) + if (bc_trie_lookup(s, "DATE") != NULL) with_date++; - rv = sb_slist_append(rv, s); + rv = bc_slist_append(rv, s); } - if (with_date > 0 && with_date < sb_slist_length(rv)) + if (with_date > 0 && with_date < bc_slist_length(rv)) // fatal error, maybe? blogc_fprintf(stderr, "blogc: warning: 'DATE' variable provided for at least one source " @@ -174,38 +174,38 @@ blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **er "wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n"); bool first = true; - for (sb_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) { - sb_trie_t *s = tmp->data; + for (bc_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) { + bc_trie_t *s = tmp->data; if (first) { - const char *val = sb_trie_lookup(s, "DATE"); + const char *val = bc_trie_lookup(s, "DATE"); if (val != NULL) - sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val)); - val = sb_trie_lookup(s, "FILENAME"); + bc_trie_insert(conf, "DATE_FIRST", bc_strdup(val)); + val = bc_trie_lookup(s, "FILENAME"); if (val != NULL) - sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val)); + bc_trie_insert(conf, "FILENAME_FIRST", bc_strdup(val)); first = false; } if (tmp->next == NULL) { // last - const char *val = sb_trie_lookup(s, "DATE"); + const char *val = bc_trie_lookup(s, "DATE"); if (val != NULL) - sb_trie_insert(conf, "DATE_LAST", sb_strdup(val)); - val = sb_trie_lookup(s, "FILENAME"); + bc_trie_insert(conf, "DATE_LAST", bc_strdup(val)); + val = bc_trie_lookup(s, "FILENAME"); if (val != NULL) - sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val)); + bc_trie_insert(conf, "FILENAME_LAST", bc_strdup(val)); } } if (filter_page != NULL) { unsigned int last_page = ceilf(((float) counter) / per_page); - sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page)); + bc_trie_insert(conf, "CURRENT_PAGE", bc_strdup_printf("%ld", page)); if (page > 1) - sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1)); + bc_trie_insert(conf, "PREVIOUS_PAGE", bc_strdup_printf("%ld", page - 1)); if (page < last_page) - 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")); + 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")); if (last_page > 0) - sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page)); + bc_trie_insert(conf, "LAST_PAGE", bc_strdup_printf("%d", last_page)); } return rv; diff --git a/src/blogc/loader.h b/src/blogc/loader.h index c54d11a..97286a0 100644 --- a/src/blogc/loader.h +++ b/src/blogc/loader.h @@ -13,9 +13,9 @@ #include "../common/utils.h" char* blogc_get_filename(const char *f); -sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err); -sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err); -sb_slist_t* blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, +bc_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err); +bc_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err); +bc_slist_t* blogc_source_parse_from_files(bc_trie_t *conf, bc_slist_t *l, blogc_error_t **err); #endif /* _LOADER_H */ diff --git a/src/blogc/main.c b/src/blogc/main.c index 03f43ae..0f174d4 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -71,7 +71,7 @@ blogc_print_usage(void) static void blogc_mkdir_recursive(const char *filename) { - char *fname = sb_strdup(filename); + char *fname = bc_strdup(filename); for (char *tmp = fname; *tmp != '\0'; tmp++) { if (*tmp != '/' && *tmp != '\\') continue; @@ -118,9 +118,9 @@ main(int argc, char **argv) char *tmp = NULL; char **pieces = NULL; - sb_slist_t *sources = NULL; - sb_trie_t *config = sb_trie_new(free); - sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION)); + bc_slist_t *sources = NULL; + bc_trie_t *config = bc_trie_new(free); + bc_trie_insert(config, "BLOGC_VERSION", bc_strdup(PACKAGE_VERSION)); for (unsigned int i = 1; i < argc; i++) { tmp = NULL; @@ -140,21 +140,21 @@ main(int argc, char **argv) break; case 't': if (argv[i][2] != '\0') - template = sb_strdup(argv[i] + 2); + template = bc_strdup(argv[i] + 2); else if (i + 1 < argc) - template = sb_strdup(argv[++i]); + template = bc_strdup(argv[++i]); break; case 'o': if (argv[i][2] != '\0') - output = sb_strdup(argv[i] + 2); + output = bc_strdup(argv[i] + 2); else if (i + 1 < argc) - output = sb_strdup(argv[++i]); + output = bc_strdup(argv[++i]); break; case 'p': if (argv[i][2] != '\0') - print = sb_strdup(argv[i] + 2); + print = bc_strdup(argv[i] + 2); else if (i + 1 < argc) - print = sb_strdup(argv[++i]); + print = bc_strdup(argv[++i]); break; case 'D': if (argv[i][2] != '\0') @@ -167,11 +167,11 @@ main(int argc, char **argv) "-D (must be valid UTF-8 string): %s\n", tmp); goto cleanup; } - pieces = sb_str_split(tmp, '=', 2); - if (sb_strv_length(pieces) != 2) { + pieces = bc_str_split(tmp, '=', 2); + if (bc_strv_length(pieces) != 2) { fprintf(stderr, "blogc: error: invalid value for " "-D (must have an '='): %s\n", tmp); - sb_strv_free(pieces); + bc_strv_free(pieces); rv = 2; goto cleanup; } @@ -182,13 +182,13 @@ main(int argc, char **argv) fprintf(stderr, "blogc: error: invalid value " "for -D (configuration key must be uppercase " "with '_'): %s\n", pieces[0]); - sb_strv_free(pieces); + bc_strv_free(pieces); rv = 2; goto cleanup; } } - sb_trie_insert(config, pieces[0], sb_strdup(pieces[1])); - sb_strv_free(pieces); + bc_trie_insert(config, pieces[0], bc_strdup(pieces[1])); + bc_strv_free(pieces); pieces = NULL; } break; @@ -201,17 +201,17 @@ main(int argc, char **argv) } } else - sources = sb_slist_append(sources, sb_strdup(argv[i])); + sources = bc_slist_append(sources, bc_strdup(argv[i])); } - if (!listing && sb_slist_length(sources) == 0) { + if (!listing && bc_slist_length(sources) == 0) { blogc_print_usage(); fprintf(stderr, "blogc: error: one source file is required\n"); rv = 2; goto cleanup; } - if (!listing && sb_slist_length(sources) > 1) { + if (!listing && bc_slist_length(sources) > 1) { blogc_print_usage(); fprintf(stderr, "blogc: error: only one source file should be provided, " "if running without '-l'\n"); @@ -221,7 +221,7 @@ main(int argc, char **argv) blogc_error_t *err = NULL; - sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err); + bc_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { blogc_error_print(err); rv = 2; @@ -229,7 +229,7 @@ main(int argc, char **argv) } if (print != NULL) { - const char *val = sb_trie_lookup(config, print); + const char *val = bc_trie_lookup(config, print); if (val == NULL) { fprintf(stderr, "blogc: error: configuration variable not found: %s\n", print); @@ -248,7 +248,7 @@ main(int argc, char **argv) goto cleanup2; } - sb_slist_t* l = blogc_template_parse_from_file(template, &err); + bc_slist_t* l = blogc_template_parse_from_file(template, &err); if (err != NULL) { blogc_error_print(err); rv = 2; @@ -285,13 +285,13 @@ cleanup4: cleanup3: blogc_template_free_stmts(l); cleanup2: - sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); + bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); blogc_error_free(err); cleanup: - sb_trie_free(config); + bc_trie_free(config); free(template); free(output); free(print); - sb_slist_free_full(sources, free); + bc_slist_free_full(sources, free); return rv; } diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c index 97a226e..409c75e 100644 --- a/src/blogc/renderer.c +++ b/src/blogc/renderer.c @@ -20,58 +20,58 @@ const char* -blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local) +blogc_get_variable(const char *name, bc_trie_t *global, bc_trie_t *local) { const char *rv = NULL; if (local != NULL) { - rv = sb_trie_lookup(local, name); + rv = bc_trie_lookup(local, name); if (rv != NULL) return rv; } if (global != NULL) - rv = sb_trie_lookup(global, name); + rv = bc_trie_lookup(global, name); return rv; } char* -blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local) +blogc_format_date(const char *date, bc_trie_t *global, bc_trie_t *local) { const char *date_format = blogc_get_variable("DATE_FORMAT", global, local); if (date == NULL) return NULL; if (date_format == NULL) - return sb_strdup(date); + return bc_strdup(date); blogc_error_t *err = NULL; char *rv = blogc_convert_datetime(date, date_format, &err); if (err != NULL) { blogc_error_print(err); blogc_error_free(err); - return sb_strdup(date); + return bc_strdup(date); } return rv; } char* -blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, - sb_slist_t *foreach_var) +blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local, + bc_slist_t *foreach_var) { // if used asked for a variable that exists, just return it right away const char *value = blogc_get_variable(name, global, local); if (value != NULL) - return sb_strdup(value); + return bc_strdup(value); // do the same for special variable 'FOREACH_ITEM' if (0 == strcmp(name, "FOREACH_ITEM")) { if (foreach_var != NULL && foreach_var->data != NULL) { - return sb_strdup(foreach_var->data); + return bc_strdup(foreach_var->data); } return NULL; } - char *var = sb_strdup(name); + char *var = bc_strdup(name); size_t i; size_t last = strlen(var); @@ -96,7 +96,7 @@ blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, bool must_format = false; - if (sb_str_ends_with(var, "_FORMATTED")) { + if (bc_str_ends_with(var, "_FORMATTED")) { var[strlen(var) - 10] = '\0'; must_format = true; } @@ -115,23 +115,23 @@ blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, char *rv = NULL; if (must_format) { - if (sb_str_starts_with(name, "DATE_")) { + if (bc_str_starts_with(name, "DATE_")) { rv = blogc_format_date(value, global, local); } else { fprintf(stderr, "warning: no formatter found for '%s', " "ignoring.\n", var); - rv = sb_strdup(value); + rv = bc_strdup(value); } } else { - rv = sb_strdup(value); + rv = bc_strdup(value); } free(var); if (len > 0) { - char *tmp = sb_strndup(rv, len); + char *tmp = bc_strndup(rv, len); free(rv); rv = tmp; } @@ -140,19 +140,19 @@ blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, } -sb_slist_t* -blogc_split_list_variable(const char *name, sb_trie_t *global, sb_trie_t *local) +bc_slist_t* +blogc_split_list_variable(const char *name, bc_trie_t *global, bc_trie_t *local) { const char *value = blogc_get_variable(name, global, local); if (value == NULL) return NULL; - sb_slist_t *rv = NULL; + bc_slist_t *rv = NULL; - char **tmp = sb_str_split(value, ' ', 0); + char **tmp = bc_str_split(value, ' ', 0); for (unsigned int i = 0; tmp[i] != NULL; i++) { if (tmp[i][0] != '\0') // ignore empty strings - rv = sb_slist_append(rv, tmp[i]); + rv = bc_slist_append(rv, tmp[i]); else free(tmp[i]); } @@ -163,25 +163,25 @@ blogc_split_list_variable(const char *name, sb_trie_t *global, sb_trie_t *local) char* -blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool listing) +blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool listing) { if (tmpl == NULL) return NULL; - sb_slist_t *current_source = NULL; - sb_slist_t *listing_start = NULL; + bc_slist_t *current_source = NULL; + bc_slist_t *listing_start = NULL; - sb_string_t *str = sb_string_new(); + bc_string_t *str = bc_string_new(); - sb_trie_t *tmp_source = NULL; + bc_trie_t *tmp_source = NULL; char *config_value = NULL; char *defined = NULL; unsigned int if_count = 0; - sb_slist_t *foreach_var = NULL; - sb_slist_t *foreach_var_start = NULL; - sb_slist_t *foreach_start = NULL; + bc_slist_t *foreach_var = NULL; + bc_slist_t *foreach_var_start = NULL; + bc_slist_t *foreach_start = NULL; bool if_not = false; bool inside_block = false; @@ -190,7 +190,7 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list int cmp = 0; - sb_slist_t *tmp = tmpl; + bc_slist_t *tmp = tmpl; while (tmp != NULL) { blogc_template_stmt_t *stmt = tmp->data; @@ -198,7 +198,7 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list case BLOGC_TEMPLATE_CONTENT_STMT: if (stmt->value != NULL) - sb_string_append(str, stmt->value); + bc_string_append(str, stmt->value); break; case BLOGC_TEMPLATE_BLOCK_STMT: @@ -255,7 +255,7 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list config_value = blogc_format_variable(stmt->value, config, inside_block ? tmp_source : NULL, foreach_var); if (config_value != NULL) { - sb_string_append(str, config_value); + bc_string_append(str, config_value); free(config_value); config_value = NULL; break; @@ -297,7 +297,7 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list (stmt->value2[0] == '"') && (stmt->value2[strlen(stmt->value2) - 1] == '"')) { - defined2 = sb_strndup(stmt->value2 + 1, + defined2 = bc_strndup(stmt->value2 + 1, strlen(stmt->value2) - 2); } else { @@ -443,7 +443,7 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list } } foreach_start = NULL; - sb_slist_free_full(foreach_var_start, free); + bc_slist_free_full(foreach_var_start, free); foreach_var_start = NULL; break; } @@ -453,5 +453,5 @@ blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool list // no need to free temporary variables here. the template parser makes sure // that templates are sane and statements are closed. - return sb_string_free(str, false); + return bc_string_free(str, false); } diff --git a/src/blogc/renderer.h b/src/blogc/renderer.h index f7f5328..cf6849b 100644 --- a/src/blogc/renderer.h +++ b/src/blogc/renderer.h @@ -12,13 +12,13 @@ #include <stdbool.h> #include "../common/utils.h" -const char* blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local); -char* blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local); -char* blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, - sb_slist_t *foreach_var); -sb_slist_t* blogc_split_list_variable(const char *name, sb_trie_t *global, - sb_trie_t *local); -char* blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, +const char* blogc_get_variable(const char *name, bc_trie_t *global, bc_trie_t *local); +char* blogc_format_date(const char *date, bc_trie_t *global, bc_trie_t *local); +char* blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local, + bc_slist_t *foreach_var); +bc_slist_t* blogc_split_list_variable(const char *name, bc_trie_t *global, + bc_trie_t *local); +char* blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool listing); #endif /* _RENDERER_H */ diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c index 4472096..dc39760 100644 --- a/src/blogc/source-parser.c +++ b/src/blogc/source-parser.c @@ -26,7 +26,7 @@ typedef enum { } blogc_source_parser_state_t; -sb_trie_t* +bc_trie_t* blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -39,7 +39,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) char *key = NULL; char *tmp = NULL; char *content = NULL; - sb_trie_t *rv = sb_trie_new(free); + bc_trie_t *rv = bc_trie_new(free); blogc_source_parser_state_t state = SOURCE_START; @@ -69,7 +69,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') break; if (c == ':') { - key = sb_strndup(src + start, current - start); + key = bc_strndup(src + start, current - start); if (((current - start == 8) && (0 == strncmp("FILENAME", src + start, 8))) || ((current - start == 7) && @@ -118,8 +118,8 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) case SOURCE_CONFIG_VALUE: if (c == '\n' || c == '\r') { - tmp = sb_strndup(src + start, current - start); - sb_trie_insert(rv, key, sb_strdup(sb_str_strip(tmp))); + tmp = bc_strndup(src + start, current - start); + bc_trie_insert(rv, key, bc_strdup(bc_str_strip(tmp))); free(tmp); free(key); key = NULL; @@ -148,24 +148,24 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) case SOURCE_CONTENT: if (current == (src_len - 1)) { - tmp = sb_strndup(src + start, src_len - start); - sb_trie_insert(rv, "RAW_CONTENT", tmp); + tmp = bc_strndup(src + start, src_len - start); + bc_trie_insert(rv, "RAW_CONTENT", tmp); char *description = NULL; content = blogc_content_parse(tmp, &end_excerpt, &description); if (description != NULL) { // do not override source-provided description. - if (NULL == sb_trie_lookup(rv, "DESCRIPTION")) { + if (NULL == bc_trie_lookup(rv, "DESCRIPTION")) { // no need to free, because we are transfering memory // ownership to the trie. - sb_trie_insert(rv, "DESCRIPTION", description); + bc_trie_insert(rv, "DESCRIPTION", description); } else { free(description); } } - sb_trie_insert(rv, "CONTENT", content); - sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ? - sb_strdup(content) : sb_strndup(content, end_excerpt)); + bc_trie_insert(rv, "CONTENT", content); + bc_trie_insert(rv, "EXCERPT", end_excerpt == 0 ? + bc_strdup(content) : bc_strndup(content, end_excerpt)); } break; } @@ -176,7 +176,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) current++; } - if (*err == NULL && sb_trie_size(rv) == 0) { + if (*err == NULL && bc_trie_size(rv) == 0) { // ok, nothing found in the config trie, but no error set either. // let's try to be nice with the users and provide some reasonable @@ -210,7 +210,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) if (*err != NULL) { free(key); - sb_trie_free(rv); + bc_trie_free(rv); return NULL; } diff --git a/src/blogc/source-parser.h b/src/blogc/source-parser.h index 895cb1b..d135f23 100644 --- a/src/blogc/source-parser.h +++ b/src/blogc/source-parser.h @@ -13,7 +13,7 @@ #include "error.h" #include "../common/utils.h" -sb_trie_t* blogc_source_parse(const char *src, size_t src_len, +bc_trie_t* blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err); #endif /* _SOURCE_PARSER_H */ diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c index 15750f1..1cca885 100644 --- a/src/blogc/template-parser.c +++ b/src/blogc/template-parser.c @@ -41,7 +41,7 @@ typedef enum { } blogc_template_parser_state_t; -sb_slist_t* +bc_slist_t* blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -63,7 +63,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) bool foreach_open = false; bool block_foreach_open = false; - sb_slist_t *stmts = NULL; + bc_slist_t *stmts = NULL; blogc_template_stmt_t *stmt = NULL; /* @@ -94,21 +94,21 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) case TEMPLATE_START: if (last) { - stmt = sb_malloc(sizeof(blogc_template_stmt_t)); + stmt = bc_malloc(sizeof(blogc_template_stmt_t)); stmt->type = type; if (lstrip_next) { - tmp = sb_strndup(src + start, src_len - start); - stmt->value = sb_strdup(sb_str_lstrip(tmp)); + tmp = bc_strndup(src + start, src_len - start); + stmt->value = bc_strdup(bc_str_lstrip(tmp)); free(tmp); tmp = NULL; lstrip_next = false; } else { - stmt->value = sb_strndup(src + start, src_len - start); + stmt->value = bc_strndup(src + start, src_len - start); } stmt->op = 0; stmt->value2 = NULL; - stmts = sb_slist_append(stmts, stmt); + stmts = bc_slist_append(stmts, stmt); previous = stmt; stmt = NULL; } @@ -125,21 +125,21 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) else state = TEMPLATE_VARIABLE_START; if (end > start) { - stmt = sb_malloc(sizeof(blogc_template_stmt_t)); + stmt = bc_malloc(sizeof(blogc_template_stmt_t)); stmt->type = type; if (lstrip_next) { - tmp = sb_strndup(src + start, end - start); - stmt->value = sb_strdup(sb_str_lstrip(tmp)); + tmp = bc_strndup(src + start, end - start); + stmt->value = bc_strdup(bc_str_lstrip(tmp)); free(tmp); tmp = NULL; lstrip_next = false; } else { - stmt->value = sb_strndup(src + start, end - start); + stmt->value = bc_strndup(src + start, end - start); } stmt->op = 0; stmt->value2 = NULL; - stmts = sb_slist_append(stmts, stmt); + stmts = bc_slist_append(stmts, stmt); previous = stmt; stmt = NULL; } @@ -153,7 +153,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) if ((previous != NULL) && (previous->type == BLOGC_TEMPLATE_CONTENT_STMT)) { - previous->value = sb_str_rstrip(previous->value); // does not need copy + previous->value = bc_str_rstrip(previous->value); // does not need copy } state = TEMPLATE_BLOCK_START; break; @@ -600,21 +600,21 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) op_start = 0; op_end = 0; } - stmt = sb_malloc(sizeof(blogc_template_stmt_t)); + stmt = bc_malloc(sizeof(blogc_template_stmt_t)); stmt->type = type; stmt->value = NULL; stmt->op = tmp_op; stmt->value2 = NULL; if (end > start) - stmt->value = sb_strndup(src + start, end - start); + stmt->value = bc_strndup(src + start, end - start); if (end2 > start2) { - stmt->value2 = sb_strndup(src + start2, end2 - start2); + stmt->value2 = bc_strndup(src + start2, end2 - start2); start2 = 0; end2 = 0; } if (type == BLOGC_TEMPLATE_BLOCK_STMT) block_type = stmt->value; - stmts = sb_slist_append(stmts, stmt); + stmts = bc_slist_append(stmts, stmt); previous = stmt; stmt = NULL; state = TEMPLATE_START; @@ -665,9 +665,9 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) void -blogc_template_free_stmts(sb_slist_t *stmts) +blogc_template_free_stmts(bc_slist_t *stmts) { - for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { + for (bc_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) { blogc_template_stmt_t *data = tmp->data; if (data == NULL) continue; @@ -675,5 +675,5 @@ blogc_template_free_stmts(sb_slist_t *stmts) free(data->value2); free(data); } - sb_slist_free(stmts); + bc_slist_free(stmts); } diff --git a/src/blogc/template-parser.h b/src/blogc/template-parser.h index 41a2b3a..b22c2e7 100644 --- a/src/blogc/template-parser.h +++ b/src/blogc/template-parser.h @@ -46,8 +46,8 @@ typedef struct { blogc_template_stmt_operator_t op; } blogc_template_stmt_t; -sb_slist_t* blogc_template_parse(const char *src, size_t src_len, +bc_slist_t* blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err); -void blogc_template_free_stmts(sb_slist_t *stmts); +void blogc_template_free_stmts(bc_slist_t *stmts); #endif /* _TEMPLATE_PARSER_H */ diff --git a/src/common/utf8.c b/src/common/utf8.c index a2f4fdd..ddd51ee 100644 --- a/src/common/utf8.c +++ b/src/common/utf8.c @@ -83,7 +83,7 @@ blogc_utf8_validate(const uint8_t *str, size_t len) bool -blogc_utf8_validate_str(sb_string_t *str) +blogc_utf8_validate_str(bc_string_t *str) { return blogc_utf8_validate((uint8_t*) str->str, str->len); } diff --git a/src/common/utf8.h b/src/common/utf8.h index 06fe07e..b37a97d 100644 --- a/src/common/utf8.h +++ b/src/common/utf8.h @@ -15,7 +15,7 @@ #include "utils.h" bool blogc_utf8_validate(const uint8_t *str, size_t len); -bool blogc_utf8_validate_str(sb_string_t *str); +bool blogc_utf8_validate_str(bc_string_t *str); size_t blogc_utf8_skip_bom(const uint8_t *str, size_t len); #endif /* _UTF_8_H */ diff --git a/src/common/utils.c b/src/common/utils.c index b42ae4e..8397419 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -18,7 +18,7 @@ void* -sb_malloc(size_t size) +bc_malloc(size_t size) { // simple things simple! void *rv = malloc(size); @@ -31,7 +31,7 @@ sb_malloc(size_t size) void* -sb_realloc(void *ptr, size_t size) +bc_realloc(void *ptr, size_t size) { // simple things even simpler :P void *rv = realloc(ptr, size); @@ -44,17 +44,17 @@ sb_realloc(void *ptr, size_t size) } -sb_slist_t* -sb_slist_append(sb_slist_t *l, void *data) +bc_slist_t* +bc_slist_append(bc_slist_t *l, void *data) { - sb_slist_t *node = sb_malloc(sizeof(sb_slist_t)); + bc_slist_t *node = bc_malloc(sizeof(bc_slist_t)); node->data = data; node->next = NULL; if (l == NULL) { l = node; } else { - sb_slist_t *tmp; + bc_slist_t *tmp; for (tmp = l; tmp->next != NULL; tmp = tmp->next); tmp->next = node; } @@ -62,10 +62,10 @@ sb_slist_append(sb_slist_t *l, void *data) } -sb_slist_t* -sb_slist_prepend(sb_slist_t *l, void *data) +bc_slist_t* +bc_slist_prepend(bc_slist_t *l, void *data) { - sb_slist_t *node = sb_malloc(sizeof(sb_slist_t)); + bc_slist_t *node = bc_malloc(sizeof(bc_slist_t)); node->data = data; node->next = l; l = node; @@ -74,10 +74,10 @@ sb_slist_prepend(sb_slist_t *l, void *data) void -sb_slist_free_full(sb_slist_t *l, sb_free_func_t free_func) +bc_slist_free_full(bc_slist_t *l, bc_free_func_t free_func) { while (l != NULL) { - sb_slist_t *tmp = l->next; + bc_slist_t *tmp = l->next; if ((free_func != NULL) && (l->data != NULL)) free_func(l->data); free(l); @@ -87,26 +87,26 @@ sb_slist_free_full(sb_slist_t *l, sb_free_func_t free_func) void -sb_slist_free(sb_slist_t *l) +bc_slist_free(bc_slist_t *l) { - sb_slist_free_full(l, NULL); + bc_slist_free_full(l, NULL); } size_t -sb_slist_length(sb_slist_t *l) +bc_slist_length(bc_slist_t *l) { if (l == NULL) return 0; size_t i; - sb_slist_t *tmp; + bc_slist_t *tmp; for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++); return i; } char* -sb_strdup(const char *s) +bc_strdup(const char *s) { if (s == NULL) return NULL; @@ -120,7 +120,7 @@ sb_strdup(const char *s) char* -sb_strndup(const char *s, size_t n) +bc_strndup(const char *s, size_t n) { if (s == NULL) return NULL; @@ -135,7 +135,7 @@ sb_strndup(const char *s, size_t n) char* -sb_strdup_vprintf(const char *format, va_list ap) +bc_strdup_vprintf(const char *format, va_list ap) { va_list ap2; va_copy(ap2, ap); @@ -156,18 +156,18 @@ sb_strdup_vprintf(const char *format, va_list ap) char* -sb_strdup_printf(const char *format, ...) +bc_strdup_printf(const char *format, ...) { va_list ap; va_start(ap, format); - char *tmp = sb_strdup_vprintf(format, ap); + char *tmp = bc_strdup_vprintf(format, ap); va_end(ap); return tmp; } bool -sb_str_starts_with(const char *str, const char *prefix) +bc_str_starts_with(const char *str, const char *prefix) { int str_l = strlen(str); int str_lp = strlen(prefix); @@ -178,7 +178,7 @@ sb_str_starts_with(const char *str, const char *prefix) bool -sb_str_ends_with(const char *str, const char *suffix) +bc_str_ends_with(const char *str, const char *suffix) { int str_l = strlen(str); int str_ls = strlen(suffix); @@ -189,7 +189,7 @@ sb_str_ends_with(const char *str, const char *suffix) char* -sb_str_lstrip(char *str) +bc_str_lstrip(char *str) { if (str == NULL) return NULL; @@ -213,7 +213,7 @@ sb_str_lstrip(char *str) char* -sb_str_rstrip(char *str) +bc_str_rstrip(char *str) { if (str == NULL) return NULL; @@ -237,52 +237,52 @@ sb_str_rstrip(char *str) char* -sb_str_strip(char *str) +bc_str_strip(char *str) { - return sb_str_lstrip(sb_str_rstrip(str)); + return bc_str_lstrip(bc_str_rstrip(str)); } char** -sb_str_split(const char *str, char c, unsigned int max_pieces) +bc_str_split(const char *str, char c, unsigned int max_pieces) { if (str == NULL) return NULL; - char **rv = sb_malloc(sizeof(char*)); + char **rv = bc_malloc(sizeof(char*)); unsigned int i, start = 0, count = 0; for (i = 0; i < strlen(str) + 1; i++) { if (str[0] == '\0') break; if ((str[i] == c && (!max_pieces || count + 1 < max_pieces)) || str[i] == '\0') { - rv = sb_realloc(rv, (count + 1) * sizeof(char*)); - rv[count] = sb_malloc(i - start + 1); + rv = bc_realloc(rv, (count + 1) * sizeof(char*)); + rv[count] = bc_malloc(i - start + 1); memcpy(rv[count], str + start, i - start); rv[count++][i - start] = '\0'; start = i + 1; } } - rv = sb_realloc(rv, (count + 1) * sizeof(char*)); + rv = bc_realloc(rv, (count + 1) * sizeof(char*)); rv[count] = NULL; return rv; } char* -sb_str_replace(const char *str, const char search, const char *replace) +bc_str_replace(const char *str, const char search, const char *replace) { - char **pieces = sb_str_split(str, search, 0); + char **pieces = bc_str_split(str, search, 0); if (pieces == NULL) return NULL; - char* rv = sb_strv_join(pieces, replace); - sb_strv_free(pieces); + char* rv = bc_strv_join(pieces, replace); + bc_strv_free(pieces); if (rv == NULL) - return sb_strdup(str); + return bc_strdup(str); return rv; } char* -sb_str_find(const char *str, char c) +bc_str_find(const char *str, char c) { // this is somewhat similar to strchr, but respects '\' escaping. if (str == NULL) @@ -303,7 +303,7 @@ sb_str_find(const char *str, char c) void -sb_strv_free(char **strv) +bc_strv_free(char **strv) { if (strv == NULL) return; @@ -314,22 +314,22 @@ sb_strv_free(char **strv) char* -sb_strv_join(char **strv, const char *separator) +bc_strv_join(char **strv, const char *separator) { if (strv == NULL || separator == NULL) return NULL; - sb_string_t *str = sb_string_new(); + bc_string_t *str = bc_string_new(); for (size_t i = 0; strv[i] != NULL; i++) { - str = sb_string_append(str, strv[i]); + str = bc_string_append(str, strv[i]); if (strv[i + 1] != NULL) - str = sb_string_append(str, separator); + str = bc_string_append(str, separator); } - return sb_string_free(str, false); + return bc_string_free(str, false); } size_t -sb_strv_length(char **strv) +bc_strv_length(char **strv) { if (strv == NULL) return 0; @@ -339,23 +339,23 @@ sb_strv_length(char **strv) } -sb_string_t* -sb_string_new(void) +bc_string_t* +bc_string_new(void) { - sb_string_t* rv = sb_malloc(sizeof(sb_string_t)); + bc_string_t* rv = bc_malloc(sizeof(bc_string_t)); rv->str = NULL; rv->len = 0; rv->allocated_len = 0; // initialize with empty string - rv = sb_string_append(rv, ""); + rv = bc_string_append(rv, ""); return rv; } char* -sb_string_free(sb_string_t *str, bool free_str) +bc_string_free(bc_string_t *str, bool free_str) { if (str == NULL) return NULL; @@ -369,18 +369,18 @@ sb_string_free(sb_string_t *str, bool free_str) } -sb_string_t* -sb_string_dup(sb_string_t *str) +bc_string_t* +bc_string_dup(bc_string_t *str) { if (str == NULL) return NULL; - sb_string_t* new = sb_string_new(); - return sb_string_append_len(new, str->str, str->len); + bc_string_t* new = bc_string_new(); + return bc_string_append_len(new, str->str, str->len); } -sb_string_t* -sb_string_append_len(sb_string_t *str, const char *suffix, size_t len) +bc_string_t* +bc_string_append_len(bc_string_t *str, const char *suffix, size_t len) { if (str == NULL) return NULL; @@ -390,7 +390,7 @@ sb_string_append_len(sb_string_t *str, const char *suffix, size_t len) str->len += len; if (str->len + 1 > str->allocated_len) { str->allocated_len = (((str->len + 1) / SB_STRING_CHUNK_SIZE) + 1) * SB_STRING_CHUNK_SIZE; - str->str = sb_realloc(str->str, str->allocated_len); + str->str = bc_realloc(str->str, str->allocated_len); } memcpy(str->str + old_len, suffix, len); str->str[str->len] = '\0'; @@ -398,18 +398,18 @@ sb_string_append_len(sb_string_t *str, const char *suffix, size_t len) } -sb_string_t* -sb_string_append(sb_string_t *str, const char *suffix) +bc_string_t* +bc_string_append(bc_string_t *str, const char *suffix) { if (str == NULL) return NULL; const char *my_suffix = suffix == NULL ? "" : suffix; - return sb_string_append_len(str, my_suffix, strlen(my_suffix)); + return bc_string_append_len(str, my_suffix, strlen(my_suffix)); } -sb_string_t* -sb_string_append_c(sb_string_t *str, char c) +bc_string_t* +bc_string_append_c(bc_string_t *str, char c) { if (str == NULL) return NULL; @@ -417,7 +417,7 @@ sb_string_append_c(sb_string_t *str, char c) str->len += 1; if (str->len + 1 > str->allocated_len) { str->allocated_len = (((str->len + 1) / SB_STRING_CHUNK_SIZE) + 1) * SB_STRING_CHUNK_SIZE; - str->str = sb_realloc(str->str, str->allocated_len); + str->str = bc_realloc(str->str, str->allocated_len); } str->str[old_len] = c; str->str[str->len] = '\0'; @@ -425,23 +425,23 @@ sb_string_append_c(sb_string_t *str, char c) } -sb_string_t* -sb_string_append_printf(sb_string_t *str, const char *format, ...) +bc_string_t* +bc_string_append_printf(bc_string_t *str, const char *format, ...) { if (str == NULL) return NULL; va_list ap; va_start(ap, format); - char *tmp = sb_strdup_vprintf(format, ap); + char *tmp = bc_strdup_vprintf(format, ap); va_end(ap); - str = sb_string_append(str, tmp); + str = bc_string_append(str, tmp); free(tmp); return str; } -sb_string_t* -sb_string_append_escaped(sb_string_t *str, const char *suffix) +bc_string_t* +bc_string_append_escaped(bc_string_t *str, const char *suffix) { if (str == NULL) return NULL; @@ -454,16 +454,16 @@ sb_string_append_escaped(sb_string_t *str, const char *suffix) continue; } escaped = false; - str = sb_string_append_c(str, suffix[i]); + str = bc_string_append_c(str, suffix[i]); } return str; } -sb_trie_t* -sb_trie_new(sb_free_func_t free_func) +bc_trie_t* +bc_trie_new(bc_free_func_t free_func) { - sb_trie_t *trie = sb_malloc(sizeof(sb_trie_t)); + bc_trie_t *trie = bc_malloc(sizeof(bc_trie_t)); trie->root = NULL; trie->free_func = free_func; return trie; @@ -471,43 +471,43 @@ sb_trie_new(sb_free_func_t free_func) static void -sb_trie_free_node(sb_trie_t *trie, sb_trie_node_t *node) +bc_trie_free_node(bc_trie_t *trie, bc_trie_node_t *node) { if (trie == NULL || node == NULL) return; if (node->data != NULL && trie->free_func != NULL) trie->free_func(node->data); - sb_trie_free_node(trie, node->next); - sb_trie_free_node(trie, node->child); + bc_trie_free_node(trie, node->next); + bc_trie_free_node(trie, node->child); free(node); } void -sb_trie_free(sb_trie_t *trie) +bc_trie_free(bc_trie_t *trie) { if (trie == NULL) return; - sb_trie_free_node(trie, trie->root); + bc_trie_free_node(trie, trie->root); free(trie); } void -sb_trie_insert(sb_trie_t *trie, const char *key, void *data) +bc_trie_insert(bc_trie_t *trie, const char *key, void *data) { if (trie == NULL || key == NULL || data == NULL) return; - sb_trie_node_t *parent = NULL; - sb_trie_node_t *previous; - sb_trie_node_t *current; - sb_trie_node_t *tmp; + bc_trie_node_t *parent = NULL; + bc_trie_node_t *previous; + bc_trie_node_t *current; + bc_trie_node_t *tmp; while (1) { if (trie->root == NULL || (parent != NULL && parent->child == NULL)) { - current = sb_malloc(sizeof(sb_trie_node_t)); + current = bc_malloc(sizeof(bc_trie_node_t)); current->key = *key; current->data = NULL; current->next = NULL; @@ -533,7 +533,7 @@ sb_trie_insert(sb_trie_t *trie, const char *key, void *data) if (previous == NULL || parent != NULL) goto clean; - current = sb_malloc(sizeof(sb_trie_node_t)); + current = bc_malloc(sizeof(bc_trie_node_t)); current->key = *key; current->data = NULL; current->next = NULL; @@ -554,13 +554,13 @@ clean: void* -sb_trie_lookup(sb_trie_t *trie, const char *key) +bc_trie_lookup(bc_trie_t *trie, const char *key) { if (trie == NULL || trie->root == NULL || key == NULL) return NULL; - sb_trie_node_t *parent = trie->root; - sb_trie_node_t *tmp; + bc_trie_node_t *parent = trie->root; + bc_trie_node_t *tmp; while (1) { for (tmp = parent; tmp != NULL; tmp = tmp->next) { @@ -583,7 +583,7 @@ sb_trie_lookup(sb_trie_t *trie, const char *key) static void -sb_trie_size_node(sb_trie_node_t *node, size_t *count) +bc_trie_size_node(bc_trie_node_t *node, size_t *count) { if (node == NULL || count == NULL) return; @@ -591,26 +591,26 @@ sb_trie_size_node(sb_trie_node_t *node, size_t *count) if (node->key == '\0') (*count)++; - sb_trie_size_node(node->next, count); - sb_trie_size_node(node->child, count); + bc_trie_size_node(node->next, count); + bc_trie_size_node(node->child, count); } size_t -sb_trie_size(sb_trie_t *trie) +bc_trie_size(bc_trie_t *trie) { if (trie == NULL) return 0; size_t count = 0; - sb_trie_size_node(trie->root, &count); + bc_trie_size_node(trie->root, &count); return count; } static void -sb_trie_foreach_node(sb_trie_node_t *node, sb_string_t *str, - sb_trie_foreach_func_t func, void *user_data) +bc_trie_foreach_node(bc_trie_node_t *node, bc_string_t *str, + bc_trie_foreach_func_t func, void *user_data) { if (node == NULL || str == NULL || func == NULL) return; @@ -621,25 +621,25 @@ sb_trie_foreach_node(sb_trie_node_t *node, sb_string_t *str, } if (node->child != NULL) { - sb_string_t *child = sb_string_dup(str); - child = sb_string_append_c(child, node->key); - sb_trie_foreach_node(node->child, child, func, user_data); - sb_string_free(child, true); + bc_string_t *child = bc_string_dup(str); + child = bc_string_append_c(child, node->key); + bc_trie_foreach_node(node->child, child, func, user_data); + bc_string_free(child, true); } if (node->next != NULL) - sb_trie_foreach_node(node->next, str, func, user_data); + bc_trie_foreach_node(node->next, str, func, user_data); } void -sb_trie_foreach(sb_trie_t *trie, sb_trie_foreach_func_t func, +bc_trie_foreach(bc_trie_t *trie, bc_trie_foreach_func_t func, void *user_data) { if (trie == NULL || trie->root == NULL || func == NULL) return; - sb_string_t *str = sb_string_new(); - sb_trie_foreach_node(trie->root, str, func, user_data); - sb_string_free(str, true); + bc_string_t *str = bc_string_new(); + bc_trie_foreach_node(trie->root, str, func, user_data); + bc_string_free(str, true); } diff --git a/src/common/utils.h b/src/common/utils.h index aca02c0..020f243 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -16,43 +16,43 @@ // memory -typedef void (*sb_free_func_t) (void *ptr); +typedef void (*bc_free_func_t) (void *ptr); -void* sb_malloc(size_t size); -void* sb_realloc(void *ptr, size_t size); +void* bc_malloc(size_t size); +void* bc_realloc(void *ptr, size_t size); // slist -typedef struct _sb_slist_t { - struct _sb_slist_t *next; +typedef struct _bc_slist_t { + struct _bc_slist_t *next; void *data; -} sb_slist_t; +} bc_slist_t; -sb_slist_t* sb_slist_append(sb_slist_t *l, void *data); -sb_slist_t* sb_slist_prepend(sb_slist_t *l, void *data); -void sb_slist_free(sb_slist_t *l); -void sb_slist_free_full(sb_slist_t *l, sb_free_func_t free_func); -size_t sb_slist_length(sb_slist_t *l); +bc_slist_t* bc_slist_append(bc_slist_t *l, void *data); +bc_slist_t* bc_slist_prepend(bc_slist_t *l, void *data); +void bc_slist_free(bc_slist_t *l); +void bc_slist_free_full(bc_slist_t *l, bc_free_func_t free_func); +size_t bc_slist_length(bc_slist_t *l); // strfuncs -char* sb_strdup(const char *s); -char* sb_strndup(const char *s, size_t n); -char* sb_strdup_vprintf(const char *format, va_list ap); -char* sb_strdup_printf(const char *format, ...); -bool sb_str_starts_with(const char *str, const char *prefix); -bool sb_str_ends_with(const char *str, const char *suffix); -char* sb_str_lstrip(char *str); -char* sb_str_rstrip(char *str); -char* sb_str_strip(char *str); -char** sb_str_split(const char *str, char c, unsigned int max_pieces); -char* sb_str_replace(const char *str, const char search, const char *replace); -char* sb_str_find(const char *str, char c); -void sb_strv_free(char **strv); -char* sb_strv_join(char **strv, const char *separator); -size_t sb_strv_length(char **strv); +char* bc_strdup(const char *s); +char* bc_strndup(const char *s, size_t n); +char* bc_strdup_vprintf(const char *format, va_list ap); +char* bc_strdup_printf(const char *format, ...); +bool bc_str_starts_with(const char *str, const char *prefix); +bool bc_str_ends_with(const char *str, const char *suffix); +char* bc_str_lstrip(char *str); +char* bc_str_rstrip(char *str); +char* bc_str_strip(char *str); +char** bc_str_split(const char *str, char c, unsigned int max_pieces); +char* bc_str_replace(const char *str, const char search, const char *replace); +char* bc_str_find(const char *str, char c); +void bc_strv_free(char **strv); +char* bc_strv_join(char **strv, const char *separator); +size_t bc_strv_length(char **strv); // string @@ -61,42 +61,42 @@ typedef struct { char *str; size_t len; size_t allocated_len; -} sb_string_t; +} bc_string_t; -sb_string_t* sb_string_new(void); -char* sb_string_free(sb_string_t *str, bool free_str); -sb_string_t* sb_string_dup(sb_string_t *str); -sb_string_t* sb_string_append_len(sb_string_t *str, const char *suffix, size_t len); -sb_string_t* sb_string_append(sb_string_t *str, const char *suffix); -sb_string_t* sb_string_append_c(sb_string_t *str, char c); -sb_string_t* sb_string_append_printf(sb_string_t *str, const char *format, ...); -sb_string_t* sb_string_append_escaped(sb_string_t *str, const char *suffix); +bc_string_t* bc_string_new(void); +char* bc_string_free(bc_string_t *str, bool free_str); +bc_string_t* bc_string_dup(bc_string_t *str); +bc_string_t* bc_string_append_len(bc_string_t *str, const char *suffix, size_t len); +bc_string_t* bc_string_append(bc_string_t *str, const char *suffix); +bc_string_t* bc_string_append_c(bc_string_t *str, char c); +bc_string_t* bc_string_append_printf(bc_string_t *str, const char *format, ...); +bc_string_t* bc_string_append_escaped(bc_string_t *str, const char *suffix); // trie -typedef struct _sb_trie_node_t { +typedef struct _bc_trie_node_t { char key; void *data; - struct _sb_trie_node_t *next, *child; -} sb_trie_node_t; + struct _bc_trie_node_t *next, *child; +} bc_trie_node_t; -struct _sb_trie_t { - sb_trie_node_t *root; - sb_free_func_t free_func; +struct _bc_trie_t { + bc_trie_node_t *root; + bc_free_func_t free_func; }; -typedef struct _sb_trie_t sb_trie_t; +typedef struct _bc_trie_t bc_trie_t; -typedef void (*sb_trie_foreach_func_t)(const char *key, void *data, +typedef void (*bc_trie_foreach_func_t)(const char *key, void *data, void *user_data); -sb_trie_t* sb_trie_new(sb_free_func_t free_func); -void sb_trie_free(sb_trie_t *trie); -void sb_trie_insert(sb_trie_t *trie, const char *key, void *data); -void* sb_trie_lookup(sb_trie_t *trie, const char *key); -size_t sb_trie_size(sb_trie_t *trie); -void sb_trie_foreach(sb_trie_t *trie, sb_trie_foreach_func_t func, +bc_trie_t* bc_trie_new(bc_free_func_t free_func); +void bc_trie_free(bc_trie_t *trie); +void bc_trie_insert(bc_trie_t *trie, const char *key, void *data); +void* bc_trie_lookup(bc_trie_t *trie, const char *key); +size_t bc_trie_size(bc_trie_t *trie); +void bc_trie_foreach(bc_trie_t *trie, bc_trie_foreach_func_t func, void *user_data); #endif /* _UTILS_H */ |