aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-09-02 23:38:48 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-09-02 23:51:15 +0200
commit4763814c683c50f8a3697b74e764f19c3dacccd5 (patch)
tree386ff43f024705a32310b882f2161b5f86d8820a
parentc12bdb94ecdc44f200a8030dfde4a5ec46053ea6 (diff)
downloadblogc-feature/squareball.tar.gz
blogc-feature/squareball.tar.bz2
blogc-feature/squareball.zip
migrate codebase to use squareball. again :)feature/squareball
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
-rw-r--r--Makefile.am229
-rwxr-xr-xbuild-aux/build-static.sh2
-rwxr-xr-xbuild-aux/build-windows.sh2
-rw-r--r--configure.ac2
-rw-r--r--m4/squareball.m446
m---------squareball0
-rw-r--r--src/blogc-git-receiver/post-receive.c18
-rw-r--r--src/blogc-git-receiver/pre-receive-parser.c5
-rw-r--r--src/blogc-git-receiver/pre-receive.c53
-rw-r--r--src/blogc-git-receiver/settings.c40
-rw-r--r--src/blogc-git-receiver/settings.h6
-rw-r--r--src/blogc-git-receiver/shell-command-parser.c13
-rw-r--r--src/blogc-git-receiver/shell.c13
-rw-r--r--src/blogc-make/atom.c48
-rw-r--r--src/blogc-make/atom.h5
-rw-r--r--src/blogc-make/ctx.c76
-rw-r--r--src/blogc-make/ctx.h14
-rw-r--r--src/blogc-make/exec-native.c33
-rw-r--r--src/blogc-make/exec-native.h5
-rw-r--r--src/blogc-make/exec.c208
-rw-r--r--src/blogc-make/exec.h20
-rw-r--r--src/blogc-make/httpd.c15
-rw-r--r--src/blogc-make/httpd.h7
-rw-r--r--src/blogc-make/main.c22
-rw-r--r--src/blogc-make/reloader.c5
-rw-r--r--src/blogc-make/reloader.h5
-rw-r--r--src/blogc-make/rules.c333
-rw-r--r--src/blogc-make/rules.h19
-rw-r--r--src/blogc-make/settings.c68
-rw-r--r--src/blogc-make/settings.h9
-rw-r--r--src/blogc-make/utils.c55
-rw-r--r--src/blogc-make/utils.h4
-rw-r--r--src/blogc-runserver/httpd-utils.c21
-rw-r--r--src/blogc-runserver/httpd.c32
-rw-r--r--src/blogc-runserver/main.c17
-rw-r--r--src/blogc-runserver/mime.c6
-rw-r--r--src/blogc/content-parser.c336
-rw-r--r--src/blogc/datetime-parser.c131
-rw-r--r--src/blogc/datetime-parser.h4
-rw-r--r--src/blogc/debug.c6
-rw-r--r--src/blogc/debug.h4
-rw-r--r--src/blogc/funcvars.c8
-rw-r--r--src/blogc/funcvars.h6
-rw-r--r--src/blogc/loader.c170
-rw-r--r--src/blogc/loader.h11
-rw-r--r--src/blogc/main.c80
-rw-r--r--src/blogc/renderer.c81
-rw-r--r--src/blogc/renderer.h18
-rw-r--r--src/blogc/rusage.c23
-rw-r--r--src/blogc/rusage.h4
-rw-r--r--src/blogc/source-parser.c78
-rw-r--r--src/blogc/source-parser.h7
-rw-r--r--src/blogc/sysinfo.c33
-rw-r--r--src/blogc/sysinfo.h10
-rw-r--r--src/blogc/template-parser.c253
-rw-r--r--src/blogc/template-parser.h11
-rw-r--r--src/common/compat.c39
-rw-r--r--src/common/compat.h14
-rw-r--r--src/common/config-parser.c442
-rw-r--r--src/common/config-parser.h31
-rw-r--r--src/common/error.c158
-rw-r--r--src/common/error.h47
-rw-r--r--src/common/file.c66
-rw-r--r--src/common/file.h20
-rw-r--r--src/common/sort.c44
-rw-r--r--src/common/sort.h18
-rw-r--r--src/common/stdin.c24
-rw-r--r--src/common/stdin.h14
-rw-r--r--src/common/utf8.c102
-rw-r--r--src/common/utf8.h21
-rw-r--r--src/common/utils.c701
-rw-r--r--src/common/utils.h109
-rw-r--r--tests/blogc-git-receiver/check_settings.c20
-rw-r--r--tests/blogc-make/check_atom.c195
-rw-r--r--tests/blogc-make/check_exec.c115
-rw-r--r--tests/blogc-make/check_rules.c81
-rw-r--r--tests/blogc-make/check_settings.c187
-rw-r--r--tests/blogc-make/check_utils.c3
-rw-r--r--tests/blogc-runserver/check_httpd_utils.c5
-rw-r--r--tests/blogc/check_datetime_parser.c336
-rw-r--r--tests/blogc/check_funcvars.c33
-rw-r--r--tests/blogc/check_loader.c919
-rw-r--r--tests/blogc/check_renderer.c398
-rw-r--r--tests/blogc/check_rusage.c15
-rw-r--r--tests/blogc/check_source_parser.c376
-rw-r--r--tests/blogc/check_sysinfo.c41
-rw-r--r--tests/blogc/check_sysinfo2.c9
-rw-r--r--tests/blogc/check_template_parser.c495
-rw-r--r--tests/common/check_config_parser.c1037
-rw-r--r--tests/common/check_error.c109
-rw-r--r--tests/common/check_sort.c148
-rw-r--r--tests/common/check_stdin.c54
-rw-r--r--tests/common/check_utf8.c101
-rw-r--r--tests/common/check_utils.c1095
96 files changed, 2891 insertions, 7465 deletions
diff --git a/.gitignore b/.gitignore
index e97005c..9932cce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ Makefile.in
/m4/*.m4
!/m4/ax_pthread.m4
!/m4/pkg.m4
+!/m4/squareball.m4
# man pages
/blogc*.[157]
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..061fb99
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "squareball"]
+ path = squareball
+ url = https://github.com/rafaelmartins/squareball.git
diff --git a/Makefile.am b/Makefile.am
index 040f291..1c5837b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,6 +13,9 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \
--disable-valgrind \
$(NULL)
+if INTERNAL_SQUAREBALL
+SUBDIRS = squareball
+endif
## File listings
@@ -65,19 +68,10 @@ noinst_HEADERS = \
src/blogc-runserver/httpd.h \
src/blogc-runserver/httpd-utils.h \
src/blogc-runserver/mime.h \
- src/common/compat.h \
- src/common/config-parser.h \
- src/common/error.h \
- src/common/file.h \
- src/common/sort.h \
- src/common/stdin.h \
- src/common/utf8.h \
- src/common/utils.h \
$(NULL)
noinst_LTLIBRARIES = \
libblogc.la \
- libblogc_common.la \
$(NULL)
noinst_PROGRAMS = \
@@ -139,27 +133,12 @@ libblogc_la_SOURCES = \
libblogc_la_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
libblogc_la_LIBADD = \
$(LIBM) \
- libblogc_common.la \
- $(NULL)
-
-
-libblogc_common_la_SOURCES = \
- src/common/compat.c \
- src/common/config-parser.c \
- src/common/error.c \
- src/common/file.c \
- src/common/sort.c \
- src/common/stdin.c \
- src/common/utf8.c \
- src/common/utils.c \
- $(NULL)
-
-libblogc_common_la_CFLAGS = \
- $(AM_CFLAGS) \
+ $(SQUAREBALL_LIBS) \
$(NULL)
@@ -169,11 +148,12 @@ blogc_SOURCES = \
blogc_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
blogc_LDADD = \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
if BUILD_MAKE_EMBEDDED
@@ -194,11 +174,12 @@ blogc_git_receiver_SOURCES = \
blogc_git_receiver_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
blogc_git_receiver_LDADD = \
+ $(SQUAREBALL_LIBS) \
libblogc_git_receiver.la \
- libblogc_common.la \
$(NULL)
libblogc_git_receiver_la_SOURCES = \
@@ -212,10 +193,11 @@ libblogc_git_receiver_la_SOURCES = \
libblogc_git_receiver_la_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
libblogc_git_receiver_la_LIBADD = \
- libblogc_common.la \
+ $(SQUAREBALL_LIBS) \
$(NULL)
endif
@@ -227,13 +209,14 @@ blogc_make_SOURCES = \
blogc_make_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(NULL)
blogc_make_LDADD = \
+ $(SQUAREBALL_LIBS) \
$(PTHREAD_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
endif
@@ -252,12 +235,13 @@ libblogc_make_la_SOURCES = \
libblogc_make_la_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(NULL)
libblogc_make_la_LIBADD = \
+ $(SQUAREBALL_LIBS) \
$(PTHREAD_LIBS) \
- libblogc_common.la \
$(NULL)
endif
@@ -269,13 +253,14 @@ blogc_runserver_SOURCES = \
blogc_runserver_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(NULL)
blogc_runserver_LDADD = \
+ $(SQUAREBALL_LIBS) \
$(PTHREAD_LIBS) \
libblogc_runserver.la \
- libblogc_common.la \
$(NULL)
libblogc_runserver_la_SOURCES = \
@@ -286,12 +271,13 @@ libblogc_runserver_la_SOURCES = \
libblogc_runserver_la_CFLAGS = \
$(AM_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(NULL)
libblogc_runserver_la_LIBADD = \
+ $(SQUAREBALL_LIBS) \
$(PTHREAD_LIBS) \
- libblogc_common.la \
$(NULL)
endif
@@ -471,11 +457,6 @@ check_PROGRAMS += \
tests/blogc/check_renderer \
tests/blogc/check_source_parser \
tests/blogc/check_template_parser \
- tests/common/check_config_parser \
- tests/common/check_error \
- tests/common/check_sort \
- tests/common/check_utf8 \
- tests/common/check_utils \
$(NULL)
if USE_LD_WRAP
@@ -484,7 +465,6 @@ check_PROGRAMS += \
tests/blogc/check_loader \
tests/blogc/check_sysinfo \
tests/blogc/check_sysinfo2 \
- tests/common/check_stdin \
$(NULL)
tests_blogc_check_funcvars_SOURCES = \
@@ -493,17 +473,18 @@ tests_blogc_check_funcvars_SOURCES = \
tests_blogc_check_funcvars_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_funcvars_LDFLAGS = \
-no-install \
- -Wl,--wrap=bc_file_get_contents \
+ -Wl,--wrap=sb_file_get_contents \
$(NULL)
tests_blogc_check_funcvars_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_loader_SOURCES = \
@@ -512,17 +493,18 @@ tests_blogc_check_loader_SOURCES = \
tests_blogc_check_loader_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_loader_LDFLAGS = \
-no-install \
- -Wl,--wrap=bc_file_get_contents \
+ -Wl,--wrap=sb_file_get_contents_utf8 \
$(NULL)
tests_blogc_check_loader_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_sysinfo_SOURCES = \
@@ -531,11 +513,12 @@ tests_blogc_check_sysinfo_SOURCES = \
tests_blogc_check_sysinfo_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_sysinfo_LDFLAGS = \
-no-install \
- -Wl,--wrap=bc_file_get_contents \
+ -Wl,--wrap=sb_file_get_contents \
-Wl,--wrap=getenv \
$(NULL)
@@ -554,8 +537,8 @@ endif
tests_blogc_check_sysinfo_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_sysinfo2_SOURCES = \
@@ -564,35 +547,18 @@ tests_blogc_check_sysinfo2_SOURCES = \
tests_blogc_check_sysinfo2_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_sysinfo2_LDFLAGS = \
-no-install \
- -Wl,--wrap=bc_file_get_contents \
+ -Wl,--wrap=sb_file_get_contents \
$(NULL)
tests_blogc_check_sysinfo2_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_stdin_SOURCES = \
- tests/common/check_stdin.c \
- $(NULL)
-
-tests_common_check_stdin_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_stdin_LDFLAGS = \
- -no-install \
- -Wl,--wrap=fgetc \
- $(NULL)
-
-tests_common_check_stdin_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
$(NULL)
if HAVE_SYS_RESOURCE_H
@@ -607,6 +573,7 @@ tests_blogc_check_rusage_SOURCES = \
tests_blogc_check_rusage_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_rusage_LDFLAGS = \
@@ -616,8 +583,8 @@ tests_blogc_check_rusage_LDFLAGS = \
tests_blogc_check_rusage_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
endif
endif
@@ -630,6 +597,7 @@ tests_blogc_check_content_parser_SOURCES = \
tests_blogc_check_content_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_content_parser_LDFLAGS = \
@@ -638,8 +606,8 @@ tests_blogc_check_content_parser_LDFLAGS = \
tests_blogc_check_content_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_datetime_parser_SOURCES = \
@@ -648,6 +616,7 @@ tests_blogc_check_datetime_parser_SOURCES = \
tests_blogc_check_datetime_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_datetime_parser_LDFLAGS = \
@@ -656,8 +625,8 @@ tests_blogc_check_datetime_parser_LDFLAGS = \
tests_blogc_check_datetime_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_renderer_SOURCES = \
@@ -666,6 +635,7 @@ tests_blogc_check_renderer_SOURCES = \
tests_blogc_check_renderer_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_renderer_LDFLAGS = \
@@ -674,8 +644,8 @@ tests_blogc_check_renderer_LDFLAGS = \
tests_blogc_check_renderer_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_source_parser_SOURCES = \
@@ -684,6 +654,7 @@ tests_blogc_check_source_parser_SOURCES = \
tests_blogc_check_source_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_source_parser_LDFLAGS = \
@@ -692,8 +663,8 @@ tests_blogc_check_source_parser_LDFLAGS = \
tests_blogc_check_source_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
$(NULL)
tests_blogc_check_template_parser_SOURCES = \
@@ -702,6 +673,7 @@ tests_blogc_check_template_parser_SOURCES = \
tests_blogc_check_template_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_check_template_parser_LDFLAGS = \
@@ -710,93 +682,8 @@ tests_blogc_check_template_parser_LDFLAGS = \
tests_blogc_check_template_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc.la \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_config_parser_SOURCES = \
- tests/common/check_config_parser.c \
- $(NULL)
-
-tests_common_check_config_parser_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_config_parser_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_common_check_config_parser_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_error_SOURCES = \
- tests/common/check_error.c \
- $(NULL)
-
-tests_common_check_error_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_error_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_common_check_error_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_sort_SOURCES = \
- tests/common/check_sort.c \
- $(NULL)
-
-tests_common_check_sort_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_sort_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_common_check_sort_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_utf8_SOURCES = \
- tests/common/check_utf8.c \
- $(NULL)
-
-tests_common_check_utf8_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_utf8_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_common_check_utf8_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
- $(NULL)
-
-tests_common_check_utils_SOURCES = \
- tests/common/check_utils.c \
- $(NULL)
-
-tests_common_check_utils_CFLAGS = \
- $(CMOCKA_CFLAGS) \
- $(NULL)
-
-tests_common_check_utils_LDFLAGS = \
- -no-install \
- $(NULL)
-
-tests_common_check_utils_LDADD = \
- $(CMOCKA_LIBS) \
- libblogc_common.la \
$(NULL)
if BUILD_RUNSERVER
@@ -812,6 +699,7 @@ tests_blogc_runserver_check_httpd_utils_SOURCES = \
tests_blogc_runserver_check_httpd_utils_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_runserver_check_httpd_utils_LDFLAGS = \
@@ -821,8 +709,8 @@ tests_blogc_runserver_check_httpd_utils_LDFLAGS = \
tests_blogc_runserver_check_httpd_utils_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_runserver.la \
- libblogc_common.la \
$(NULL)
tests_blogc_runserver_check_mime_SOURCES = \
@@ -831,6 +719,7 @@ tests_blogc_runserver_check_mime_SOURCES = \
tests_blogc_runserver_check_mime_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_runserver_check_mime_LDFLAGS = \
@@ -840,8 +729,8 @@ tests_blogc_runserver_check_mime_LDFLAGS = \
tests_blogc_runserver_check_mime_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_runserver.la \
- libblogc_common.la \
$(NULL)
endif
endif
@@ -863,6 +752,7 @@ tests_blogc_git_receiver_check_settings_SOURCES = \
tests_blogc_git_receiver_check_settings_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_git_receiver_check_settings_LDFLAGS = \
@@ -872,8 +762,8 @@ tests_blogc_git_receiver_check_settings_LDFLAGS = \
tests_blogc_git_receiver_check_settings_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_git_receiver.la \
- libblogc_common.la \
$(NULL)
endif
@@ -883,6 +773,7 @@ tests_blogc_git_receiver_check_pre_receive_parser_SOURCES = \
tests_blogc_git_receiver_check_pre_receive_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_git_receiver_check_pre_receive_parser_LDFLAGS = \
@@ -891,8 +782,8 @@ tests_blogc_git_receiver_check_pre_receive_parser_LDFLAGS = \
tests_blogc_git_receiver_check_pre_receive_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_git_receiver.la \
- libblogc_common.la \
$(NULL)
tests_blogc_git_receiver_check_shell_command_parser_SOURCES = \
@@ -901,6 +792,7 @@ tests_blogc_git_receiver_check_shell_command_parser_SOURCES = \
tests_blogc_git_receiver_check_shell_command_parser_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_git_receiver_check_shell_command_parser_LDFLAGS = \
@@ -909,8 +801,8 @@ tests_blogc_git_receiver_check_shell_command_parser_LDFLAGS = \
tests_blogc_git_receiver_check_shell_command_parser_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_git_receiver.la \
- libblogc_common.la \
$(NULL)
endif
@@ -933,6 +825,7 @@ tests_blogc_make_check_exec_SOURCES = \
tests_blogc_make_check_exec_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_make_check_exec_LDFLAGS = \
@@ -942,8 +835,8 @@ tests_blogc_make_check_exec_LDFLAGS = \
tests_blogc_make_check_exec_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
endif
@@ -953,6 +846,7 @@ tests_blogc_make_check_atom_SOURCES = \
tests_blogc_make_check_atom_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_make_check_atom_LDFLAGS = \
@@ -961,8 +855,8 @@ tests_blogc_make_check_atom_LDFLAGS = \
tests_blogc_make_check_atom_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
tests_blogc_make_check_rules_SOURCES = \
@@ -971,6 +865,7 @@ tests_blogc_make_check_rules_SOURCES = \
tests_blogc_make_check_rules_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_make_check_rules_LDFLAGS = \
@@ -979,8 +874,8 @@ tests_blogc_make_check_rules_LDFLAGS = \
tests_blogc_make_check_rules_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
tests_blogc_make_check_settings_SOURCES = \
@@ -989,6 +884,7 @@ tests_blogc_make_check_settings_SOURCES = \
tests_blogc_make_check_settings_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_make_check_settings_LDFLAGS = \
@@ -997,8 +893,8 @@ tests_blogc_make_check_settings_LDFLAGS = \
tests_blogc_make_check_settings_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
tests_blogc_make_check_utils_SOURCES = \
@@ -1007,6 +903,7 @@ tests_blogc_make_check_utils_SOURCES = \
tests_blogc_make_check_utils_CFLAGS = \
$(CMOCKA_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
$(NULL)
tests_blogc_make_check_utils_LDFLAGS = \
@@ -1015,8 +912,8 @@ tests_blogc_make_check_utils_LDFLAGS = \
tests_blogc_make_check_utils_LDADD = \
$(CMOCKA_LIBS) \
+ $(SQUAREBALL_LIBS) \
libblogc_make.la \
- libblogc_common.la \
$(NULL)
endif
diff --git a/build-aux/build-static.sh b/build-aux/build-static.sh
index cacca1b..10bb4da 100755
--- a/build-aux/build-static.sh
+++ b/build-aux/build-static.sh
@@ -2,6 +2,6 @@
set -ex
-${MAKE_CMD:-make} LDFLAGS="-all-static" blogc
+${MAKE_CMD:-make} LDFLAGS="-all-static"
xz -zc blogc > "blogc-static-amd64-${PV}.xz"
diff --git a/build-aux/build-windows.sh b/build-aux/build-windows.sh
index b00fbe6..56117f4 100755
--- a/build-aux/build-windows.sh
+++ b/build-aux/build-windows.sh
@@ -4,7 +4,7 @@ set -ex
DESTDIR="${PN}-${TARGET}-${PV}"
-${MAKE_CMD:-make} blogc.exe
+${MAKE_CMD:-make}
rm -rf "${DESTDIR}"
mkdir -p "${DESTDIR}"
diff --git a/configure.ac b/configure.ac
index 880acf4..8cdd4f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,8 @@ AS_IF([test "x$ac_cv_prog_cc_c99" = "xno"], [
PKG_PROG_PKG_CONFIG
+SQUAREBALL_INIT
+
AC_PROG_SED
RPM_VERSION=`echo ${PACKAGE_VERSION} | sed "s/-/./g"`
diff --git a/m4/squareball.m4 b/m4/squareball.m4
new file mode 100644
index 0000000..297701d
--- /dev/null
+++ b/m4/squareball.m4
@@ -0,0 +1,46 @@
+# squareball: A general-purpose library for C99.
+# Copyright (C) 2014-2018 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+#
+# This program can be distributed under the terms of the BSD License.
+# See the file LICENSE.
+
+# SQUAREBALL_INIT([VERSION_ATOM])
+#
+# This should be added to Makefile.am
+#
+# if INTERNAL_SQUAREBALL
+# SUBDIRS = squareball
+# endif
+#
+# The following variables will be exported to be used in the Makefile.am:
+#
+# - SQUAREBALL_CFLAGS
+# - SQUAREBALL_LIBS
+#
+# This macro requires squareball to be installed as a git submodule in the
+# top source dir.
+# ----------------------------------
+AC_DEFUN([SQUAREBALL_INIT], [
+ AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@],
+ [whether to use library squareball from system [default=internal]])])
+ AS_IF([test "x$with_squareball" = "xsystem"], [
+ SQUAREBALL="system"
+ PKG_CHECK_MODULES([SQUAREBALL], [squareball$1], , [
+ AC_MSG_ERROR([library squareball requested from system but not found])
+ ])
+ ], [
+ SQUAREBALL="internal"
+ SQUAREBALL_CFLAGS='-I$(top_srcdir)/squareball/src'
+ SQUAREBALL_LIBS='$(top_builddir)/squareball/libsquareball.la'
+ AC_SUBST(SQUAREBALL_LIBS)
+ AC_SUBST(SQUAREBALL_CFLAGS)
+ ac_configure_args_pre="$ac_configure_args"
+ ac_configure_args_post="$ac_configure_args --enable-bundleme"
+ ac_configure_args="$ac_configure_args_post"
+ AC_CONFIG_COMMANDS_PRE([ac_configure_args="$ac_configure_args_pre"])
+ AC_CONFIG_COMMANDS_POST([ac_configure_args="$ac_configure_args_post"])
+ AC_CONFIG_SUBDIRS([squareball])
+ ac_configure_args="$ac_configure_args_pre"
+ ])
+ AM_CONDITIONAL(INTERNAL_SQUAREBALL, [test "x$with_squareball" != "xsystem"])
+])
diff --git a/squareball b/squareball
new file mode 160000
+Subproject dd5b2fc6fd395b5ad1efb4eba7fece9ba76b0a5
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index 17a8aa7..5cdd0ce 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -12,8 +12,8 @@
#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
-#include "../common/utils.h"
-#include "../common/config-parser.h"
+#include <squareball.h>
+
#include "settings.h"
#include "post-receive.h"
@@ -32,7 +32,7 @@ bgr_post_receive_hook(int argc, char *argv[])
return 1;
}
- char *repo_path = bc_strdup(dirname(real_hooks_dir));
+ char *repo_path = sb_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_path)) {
fprintf(stderr, "error: failed to change to repository root\n");
@@ -47,11 +47,11 @@ bgr_post_receive_hook(int argc, char *argv[])
if ((0 == system("git config --local remote.mirror.pushurl > /dev/null")) ||
(0 == system("git config --local remote.mirror.url > /dev/null")))
{
- mirror = bc_strdup("mirror");
+ mirror = sb_strdup("mirror");
goto push;
}
- bc_config_t *config = bgr_settings_parse();
+ sb_config_t *config = bgr_settings_parse();
if (config == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
goto cleanup;
@@ -60,13 +60,13 @@ bgr_post_receive_hook(int argc, char *argv[])
char *section = bgr_settings_get_section(config, repo_path);
if (section == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
- bc_config_free(config);
+ sb_config_free(config);
goto cleanup;
}
- mirror = bc_strdup(bc_config_get(config, section, "mirror"));
+ mirror = sb_strdup(sb_config_get(config, section, "mirror"));
free(section);
- bc_config_free(config);
+ sb_config_free(config);
if (mirror == NULL) {
fprintf(stderr, "warning: repository mirroring disabled\n");
@@ -76,7 +76,7 @@ bgr_post_receive_hook(int argc, char *argv[])
push:
{
- char *git_cmd = bc_strdup_printf("git push --mirror %s", mirror);
+ char *git_cmd = sb_strdup_printf("git push --mirror %s", mirror);
if (0 != system(git_cmd))
fprintf(stderr, "warning: failed push to git mirror\n");
free(git_cmd);
diff --git a/src/blogc-git-receiver/pre-receive-parser.c b/src/blogc-git-receiver/pre-receive-parser.c
index fb4c4d5..0e18ae7 100644
--- a/src/blogc-git-receiver/pre-receive-parser.c
+++ b/src/blogc-git-receiver/pre-receive-parser.c
@@ -8,7 +8,8 @@
#include <stdlib.h>
#include <string.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "pre-receive-parser.h"
typedef enum {
@@ -67,7 +68,7 @@ bgr_pre_receive_parse(const char *input)
if ((current - start == 17) &&
(0 == strncmp("refs/heads/master", input + start, 17)))
{
- return bc_strndup(input + start_new, start - 1 - start_new);
+ return sb_strndup(input + start_new, start - 1 - start_new);
}
break;
}
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 03b5b21..69fec27 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -15,9 +15,8 @@
#include <dirent.h>
#include <time.h>
#include <libgen.h>
-#include "../common/compat.h"
-#include "../common/utils.h"
-#include "../common/stdin.h"
+#include <squareball.h>
+
#include "settings.h"
#include "pre-receive-parser.h"
#include "pre-receive.h"
@@ -58,7 +57,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 = bc_strdup_printf("%s/%s", dir, e->d_name);
+ char *f = sb_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));
@@ -106,7 +105,7 @@ bgr_pre_receive_hook(int argc, char *argv[])
return 1;
}
- char *repo_dir = bc_strdup(dirname(real_hooks_dir));
+ char *repo_dir = sb_strdup(dirname(real_hooks_dir));
free(real_hooks_dir);
if (0 != chdir(repo_dir)) {
fprintf(stderr, "error: failed to change to repository root\n");
@@ -114,33 +113,33 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
- bc_config_t *config = bgr_settings_parse();
+ sb_config_t *config = bgr_settings_parse();
if (config == NULL) {
goto default_sym;
}
char *section = bgr_settings_get_section(config, repo_dir);
if (section == NULL) {
- bc_config_free(config);
+ sb_config_free(config);
goto default_sym;
}
- const char *sym_tmp = bc_config_get(config, section, "symlink");
+ const char *sym_tmp = sb_config_get(config, section, "symlink");
if (sym_tmp == NULL) {
free(section);
- bc_config_free(config);
+ sb_config_free(config);
goto default_sym;
}
- sym = bc_str_starts_with(sym_tmp, "/") ? bc_strdup(sym_tmp) :
- bc_strdup_printf("%s/%s", repo_dir, sym_tmp);
+ sym = sb_str_starts_with(sym_tmp, "/") ? sb_strdup(sym_tmp) :
+ sb_strdup_printf("%s/%s", repo_dir, sym_tmp);
free(section);
- bc_config_free(config);
+ sb_config_free(config);
default_sym:
if (sym == NULL) {
- sym = bc_strdup_printf("%s/htdocs", repo_dir);
+ sym = sb_strdup_printf("%s/htdocs", repo_dir);
}
if (NULL == getenv("GIT_DIR")) {
@@ -157,20 +156,20 @@ default_sym:
rv = 1;
goto cleanup;
}
- char **pieces = bc_str_split(basename(build_dir), '-', 2);
+ char **pieces = sb_str_split(basename(build_dir), '-', 2);
free(build_dir);
- if (bc_strv_length(pieces) != 2) {
+ if (sb_strv_length(pieces) != 2) {
fprintf(stderr, "error: failed to parse the hash of last built "
"commit.\n");
- bc_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 1;
goto cleanup;
}
- master = bc_strdup(pieces[0]);
- bc_strv_free(pieces);
+ master = sb_strdup(pieces[0]);
+ sb_strv_free(pieces);
}
else {
- char *input = bc_stdin_read();
+ char *input = sb_stdin_get_contents();
master = bgr_pre_receive_parse(input);
free(input);
}
@@ -188,7 +187,7 @@ default_sym:
}
tmpdir = dir;
- char *git_archive_cmd = bc_strdup_printf(
+ char *git_archive_cmd = sb_strdup_printf(
"git archive \"%s\" | tar -x -C \"%s\" -f -", master, tmpdir);
if (0 != system(git_archive_cmd)) {
fprintf(stderr, "error: failed to extract git content to temporary "
@@ -214,12 +213,12 @@ default_sym:
}
unsigned long epoch = time(NULL);
- output_dir = bc_strdup_printf("%s/%s-%lu", buildsd, master, epoch);
+ output_dir = sb_strdup_printf("%s/%s-%lu", buildsd, master, epoch);
free(buildsd);
if (0 == access(output_dir, F_OK)) {
char *tmp = output_dir;
- output_dir = bc_strdup_printf("%s-", tmp);
+ output_dir = sb_strdup_printf("%s-", tmp);
free(tmp);
}
@@ -228,24 +227,24 @@ default_sym:
char *build_cmd = NULL;
if (0 == access("blogcfile", F_OK)) {
int status_bmake = system("blogc-make -v 2> /dev/null > /dev/null");
- if (127 == bc_compat_status_code(status_bmake)) {
+ if (127 == sb_compat_status_code(status_bmake)) {
fprintf(stderr, "error: failed to find blogc-make binary\n");
rv = 1;
goto cleanup;
}
- build_cmd = bc_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
+ build_cmd = sb_strdup_printf("OUTPUT_DIR=\"%s\" blogc-make -V all",
output_dir);
}
else if ((0 == access("Makefile", F_OK)) || (0 == access("GNUMakefile", F_OK))) {
const char *make_impl = NULL;
int status_gmake = system("gmake -f /dev/null 2> /dev/null > /dev/null");
- if (127 != bc_compat_status_code(status_gmake)) {
+ if (127 != sb_compat_status_code(status_gmake)) {
make_impl = "gmake";
}
else {
int status_make = system("make -f /dev/null 2> /dev/null > /dev/null");
- if (127 != bc_compat_status_code(status_make)) {
+ if (127 != sb_compat_status_code(status_make)) {
make_impl = "make";
}
}
@@ -255,7 +254,7 @@ default_sym:
rv = 1;
goto cleanup;
}
- build_cmd = bc_strdup_printf(
+ build_cmd = sb_strdup_printf(
"%s -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1", make_impl,
cpu_count(), output_dir);
}
diff --git a/src/blogc-git-receiver/settings.c b/src/blogc-git-receiver/settings.c
index db29b18..6de1042 100644
--- a/src/blogc-git-receiver/settings.c
+++ b/src/blogc-git-receiver/settings.c
@@ -12,10 +12,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
-#include "../common/utils.h"
-#include "../common/config-parser.h"
-#include "../common/error.h"
-#include "../common/file.h"
+#include <squareball.h>
+
#include "settings.h"
@@ -35,72 +33,72 @@ bgr_settings_get_builds_dir(void)
{
char *rv = getenv("BLOGC_GIT_RECEIVER_BUILDS_DIR");
if (rv != NULL) {
- return bc_strdup(rv);
+ return sb_strdup(rv);
}
- return bc_strdup_printf("%s/builds", bgr_settings_get_base_dir());
+ return sb_strdup_printf("%s/builds", bgr_settings_get_base_dir());
}
char*
-bgr_settings_get_section(bc_config_t *config, const char *repo_path)
+bgr_settings_get_section(sb_config_t *config, const char *repo_path)
{
const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
return NULL;
}
char *rv = NULL;
- char** sections = bc_config_list_sections(config);
+ char** sections = sb_config_list_sections(config);
for (size_t i = 0; sections[i] != NULL; i++) {
- if (bc_str_starts_with(sections[i], "repo:")) {
- char *tmp_repo = bc_strdup_printf("%s/repos/%s", bd, sections[i] + 5);
+ if (sb_str_starts_with(sections[i], "repo:")) {
+ char *tmp_repo = sb_strdup_printf("%s/repos/%s", bd, sections[i] + 5);
char *real_tmp_repo = realpath(tmp_repo, NULL); // maybe not needed
free(tmp_repo);
if (real_tmp_repo == NULL)
continue;
if (0 == strcmp(real_tmp_repo, repo_path)) {
- rv = bc_strdup(sections[i]);
+ rv = sb_strdup(sections[i]);
free(real_tmp_repo);
break;
}
free(real_tmp_repo);
}
}
- bc_strv_free(sections);
+ sb_strv_free(sections);
return rv;
}
-bc_config_t*
+sb_config_t*
bgr_settings_parse(void)
{
const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
return NULL;
}
- char *config_file = bc_strdup_printf("%s/blogc-git-receiver.ini", bd);
+ char *config_file = sb_strdup_printf("%s/blogc-git-receiver.ini", bd);
if ((0 != access(config_file, F_OK))) {
free(config_file);
return NULL;
}
size_t len;
- bc_error_t *err = NULL;
- char* config_content = bc_file_get_contents(config_file, true, &len, &err);
+ sb_error_t *err = NULL;
+ char* config_content = sb_file_get_contents(config_file, &len, &err);
if (err != NULL) {
fprintf(stderr, "warning: failed to read configuration file (%s): %s\n",
- config_file, err->msg);
- bc_error_free(err);
+ config_file, sb_error_to_string(err));
+ sb_error_free(err);
free(config_file);
free(config_content);
return NULL;
}
- bc_config_t *config = bc_config_parse(config_content, len, NULL, &err);
+ sb_config_t *config = sb_config_parse(config_content, len, NULL, &err);
free(config_content);
if (err != NULL) {
fprintf(stderr, "warning: failed to parse configuration file (%s): %s\n",
- config_file, err->msg);
- bc_error_free(err);
+ config_file, sb_error_to_string(err));
+ sb_error_free(err);
free(config_file);
return NULL;
}
diff --git a/src/blogc-git-receiver/settings.h b/src/blogc-git-receiver/settings.h
index 04c1a2b..012dfaf 100644
--- a/src/blogc-git-receiver/settings.h
+++ b/src/blogc-git-receiver/settings.h
@@ -9,11 +9,11 @@
#ifndef _SETTINGS_H
#define _SETTINGS_H
-#include "../common/config-parser.h"
+#include <squareball.h>
const char* bgr_settings_get_base_dir(void);
char* bgr_settings_get_builds_dir(void);
-char* bgr_settings_get_section(bc_config_t *config, const char *repo_path);
-bc_config_t* bgr_settings_parse(void);
+char* bgr_settings_get_section(sb_config_t *config, const char *repo_path);
+sb_config_t* bgr_settings_parse(void);
#endif /* _SETTINGS_H */
diff --git a/src/blogc-git-receiver/shell-command-parser.c b/src/blogc-git-receiver/shell-command-parser.c
index 0091e0b..2b99e33 100644
--- a/src/blogc-git-receiver/shell-command-parser.c
+++ b/src/blogc-git-receiver/shell-command-parser.c
@@ -9,7 +9,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "shell-command-parser.h"
typedef enum {
@@ -28,7 +29,7 @@ bgr_shell_command_parse(const char *command)
size_t start = 0;
size_t command_len = strlen(command);
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
for (size_t current = 0; current < command_len; current++) {
@@ -76,7 +77,7 @@ bgr_shell_command_parse(const char *command)
case START_ESCAPED:
if (c == '!' || c == '\'') {
- bc_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
state = START_REPO;
break;
}
@@ -84,7 +85,7 @@ bgr_shell_command_parse(const char *command)
case REPO:
if (c == '\'') {
- bc_string_append_len(rv, command + start, current - start);
+ sb_string_append_len(rv, command + start, current - start);
state = START_REPO;
break;
}
@@ -93,9 +94,9 @@ bgr_shell_command_parse(const char *command)
}
if (rv->len > 0)
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
error:
- bc_string_free(rv, true);
+ sb_string_free(rv, true);
return NULL;
}
diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c
index a460ac2..a9e5c45 100644
--- a/src/blogc-git-receiver/shell.c
+++ b/src/blogc-git-receiver/shell.c
@@ -13,7 +13,8 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "settings.h"
#include "shell-command-parser.h"
#include "shell.h"
@@ -62,15 +63,15 @@ bgr_shell(int argc, char *argv[])
goto cleanup;
}
- repo = bc_strdup_printf("%s/repos/%s", bd, tmp_repo);
- quoted_repo = bc_shell_quote(repo);
+ repo = sb_strdup_printf("%s/repos/%s", bd, tmp_repo);
+ quoted_repo = sb_shell_quote(repo);
free(tmp_repo);
if (0 == strncmp(argv[2], "git-upload-", 11)) // no need to check len here
goto git_exec;
if (0 != access(repo, F_OK)) {
- char *git_init_cmd = bc_strdup_printf(
+ char *git_init_cmd = sb_strdup_printf(
"git init --bare %s > /dev/null", quoted_repo);
if (0 != system(git_init_cmd)) {
fprintf(stderr, "error: failed to create git repository: %s\n",
@@ -147,9 +148,9 @@ git_exec:
goto cleanup;
}
- // static allocation instead of bc_strdup_printf to avoid leaks
+ // static allocation instead of sb_strdup_printf to avoid leaks
char buffer[4096];
- char *command = bc_strdup(argv[2]);
+ char *command = sb_strdup(argv[2]);
char *p;
for (p = command; *p != ' ' && *p != '\0'; p++);
if (*p == ' ')
diff --git a/src/blogc-make/atom.c b/src/blogc-make/atom.c
index 6749658..47b9ee3 100644
--- a/src/blogc-make/atom.c
+++ b/src/blogc-make/atom.c
@@ -10,8 +10,8 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "settings.h"
#include "utils.h"
#include "atom.h"
@@ -53,32 +53,32 @@ bm_atom_generate(bm_settings_t *settings)
if (settings == NULL)
return NULL;
- const char *atom_prefix = bc_trie_lookup(settings->settings, "atom_prefix");
- const char *atom_ext = bc_trie_lookup(settings->settings, "atom_ext");
- const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix");
- const char *post_ext = bc_trie_lookup(settings->settings, "html_ext");
+ const char *atom_prefix = sb_trie_lookup(settings->settings, "atom_prefix");
+ const char *atom_ext = sb_trie_lookup(settings->settings, "atom_ext");
+ const char *post_prefix = sb_trie_lookup(settings->settings, "post_prefix");
+ const char *post_ext = sb_trie_lookup(settings->settings, "html_ext");
- bc_string_t *atom_url = bc_string_new();
+ sb_string_t *atom_url = sb_string_new();
if (atom_prefix[0] != '\0')
- bc_string_append_c(atom_url, '/');
+ sb_string_append_c(atom_url, '/');
- bc_string_append(atom_url, atom_prefix);
- bc_string_append(atom_url, "{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}");
+ sb_string_append(atom_url, atom_prefix);
+ sb_string_append(atom_url, "{% ifdef FILTER_TAG %}/{{ FILTER_TAG }}");
if (atom_prefix[0] == '\0' && atom_ext[0] != '/')
- bc_string_append(atom_url, "{% else %}/index");
+ sb_string_append(atom_url, "{% else %}/index");
- bc_string_append(atom_url, "{% endif %}");
- bc_string_append(atom_url, atom_ext);
+ sb_string_append(atom_url, "{% endif %}");
+ sb_string_append(atom_url, atom_ext);
char *post_url = bm_generate_filename(NULL, post_prefix, "{{ FILENAME }}",
post_ext);
- char *rv = bc_strdup_printf(atom_template, atom_url->str, atom_url->str,
+ char *rv = sb_strdup_printf(atom_template, atom_url->str, atom_url->str,
post_url, post_url);
- bc_string_free(atom_url, true);
+ sb_string_free(atom_url, true);
free(post_url);
return rv;
@@ -86,14 +86,14 @@ bm_atom_generate(bm_settings_t *settings)
char*
-bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
+bm_atom_deploy(bm_settings_t *settings, sb_error_t **err)
{
if (settings == NULL || err == NULL || *err != NULL)
return NULL;
- if (NULL != bc_trie_lookup(settings->settings, "atom_legacy_entry_id")) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
- "'atom_legacy_entry_id' setting is not supported anymore. see "
+ if (NULL != sb_trie_lookup(settings->settings, "atom_legacy_entry_id")) {
+ *err = sb_strerror_new(
+ "atom: 'atom_legacy_entry_id' setting is not supported anymore. see "
"https://blogc.rgm.io/news/blogc-0.16.1/ for details");
return NULL;
}
@@ -102,8 +102,8 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
char fname[] = "/tmp/blogc-make_XXXXXX";
int fd;
if (-1 == (fd = mkstemp(fname))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
- "Failed to create temporary atom template: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "atom: Failed to create temporary atom template: %s", strerror(errno));
return NULL;
}
@@ -115,8 +115,8 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
}
if (-1 == write(fd, content, strlen(content))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_ATOM,
- "Failed to write to temporary atom template: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "atom: Failed to write to temporary atom template: %s", strerror(errno));
free(content);
close(fd);
unlink(fname);
@@ -126,7 +126,7 @@ bm_atom_deploy(bm_settings_t *settings, bc_error_t **err)
free(content);
close(fd);
- return bc_strdup(fname);
+ return sb_strdup(fname);
}
diff --git a/src/blogc-make/atom.h b/src/blogc-make/atom.h
index 29a6dcb..d22b8ab 100644
--- a/src/blogc-make/atom.h
+++ b/src/blogc-make/atom.h
@@ -9,11 +9,12 @@
#ifndef _MAKE_ATOM_H
#define _MAKE_ATOM_H
-#include "../common/error.h"
+#include <squareball.h>
+
#include "settings.h"
char* bm_atom_generate(bm_settings_t *settings);
-char* bm_atom_deploy(bm_settings_t *settings, bc_error_t **err);
+char* bm_atom_deploy(bm_settings_t *settings, sb_error_t **err);
void bm_atom_destroy(const char *fname);
#endif /* _MAKE_ATOM_H */
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index 423b334..f856b6e 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -14,11 +14,11 @@
#include <limits.h>
#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
#include <stdbool.h>
#include <string.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "atom.h"
#include "settings.h"
#include "exec.h"
@@ -33,13 +33,13 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
if (ctx == NULL || filename == NULL)
return NULL;
- char *f = filename[0] == '/' ? bc_strdup(filename) :
- bc_strdup_printf("%s/%s", ctx->root_dir, filename);
+ char *f = filename[0] == '/' ? sb_strdup(filename) :
+ sb_strdup_printf("%s/%s", ctx->root_dir, filename);
- bm_filectx_t *rv = bc_malloc(sizeof(bm_filectx_t));
+ bm_filectx_t *rv = sb_malloc(sizeof(bm_filectx_t));
rv->path = f;
- rv->short_path = bc_strdup(filename);
- rv->slug = bc_strdup(slug);
+ rv->short_path = sb_strdup(filename);
+ rv->slug = sb_strdup(slug);
if (st == NULL) {
struct stat buf;
@@ -62,14 +62,14 @@ bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
}
-bc_slist_t*
-bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
+sb_slist_t*
+bm_filectx_new_r(sb_slist_t *l, bm_ctx_t *ctx, const char *filename)
{
if (ctx == NULL || filename == NULL)
return NULL;
- char *f = filename[0] == '/' ? bc_strdup(filename) :
- bc_strdup_printf("%s/%s", ctx->root_dir, filename);
+ char *f = filename[0] == '/' ? sb_strdup(filename) :
+ sb_strdup_printf("%s/%s", ctx->root_dir, filename);
struct stat buf;
if (0 != stat(f, &buf)) {
@@ -88,7 +88,7 @@ bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
while (NULL != (e = readdir(dir))) {
if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, "..")))
continue;
- char *tmp = bc_strdup_printf("%s/%s", filename, e->d_name);
+ char *tmp = sb_strdup_printf("%s/%s", filename, e->d_name);
l = bm_filectx_new_r(l, ctx, tmp);
free(tmp);
}
@@ -98,7 +98,7 @@ bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename)
return l;
}
- l = bc_slist_append(l, bm_filectx_new(ctx, filename, NULL, &buf));
+ l = sb_slist_append(l, bm_filectx_new(ctx, filename, NULL, &buf));
free(f);
return l;
}
@@ -167,7 +167,7 @@ bm_filectx_free(bm_filectx_t *fctx)
bm_ctx_t*
bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
- bc_error_t **err)
+ sb_error_t **err)
{
if (settings_file == NULL || err == NULL || *err != NULL)
return NULL;
@@ -177,7 +177,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
return NULL;
size_t content_len;
- char *content = bc_file_get_contents(abs_filename, true, &content_len,
+ char *content = sb_file_get_contents_utf8(abs_filename, &content_len,
err);
if (*err != NULL) {
free(abs_filename);
@@ -192,16 +192,16 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
}
free(content);
- const char *template_dir = bc_trie_lookup(settings->settings, "template_dir");
+ const char *template_dir = sb_trie_lookup(settings->settings, "template_dir");
if (template_dir == NULL)
template_dir = "";
char *atom_template = NULL;
bool atom_template_tmp = false;
- const char *atom_template_conf = bc_trie_lookup(settings->settings,
+ const char *atom_template_conf = sb_trie_lookup(settings->settings,
"atom_template");
if (atom_template_conf != NULL) {
- atom_template = bc_strdup_printf("%s/%s", template_dir, atom_template_conf);
+ atom_template = sb_strdup_printf("%s/%s", template_dir, atom_template_conf);
}
else {
atom_template = bm_atom_deploy(settings, err);
@@ -215,7 +215,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
bm_ctx_t *rv = NULL;
if (base == NULL) {
- rv = bc_malloc(sizeof(bm_ctx_t));
+ rv = sb_malloc(sizeof(bm_ctx_t));
rv->blogc = bm_exec_find_binary(argv0, "blogc", "BLOGC");
rv->blogc_runserver = bm_exec_find_binary(argv0, "blogc-runserver",
"BLOGC_RUNSERVER");
@@ -229,23 +229,23 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
rv->settings = settings;
rv->settings_fctx = bm_filectx_new(rv, abs_filename, NULL, NULL);
- rv->root_dir = bc_strdup(dirname(abs_filename));
+ rv->root_dir = sb_strdup(dirname(abs_filename));
free(abs_filename);
const char *output_dir = getenv("OUTPUT_DIR");
- rv->short_output_dir = bc_strdup(output_dir != NULL ? output_dir : "_build");
+ rv->short_output_dir = sb_strdup(output_dir != NULL ? output_dir : "_build");
if (rv->short_output_dir[0] == '/') {
- rv->output_dir = bc_strdup(rv->short_output_dir);
+ rv->output_dir = sb_strdup(rv->short_output_dir);
}
else {
- rv->output_dir = bc_strdup_printf("%s/%s", rv->root_dir,
+ rv->output_dir = sb_strdup_printf("%s/%s", rv->root_dir,
rv->short_output_dir);
}
// can't return null and set error after this!
- char *main_template = bc_strdup_printf("%s/%s", template_dir,
+ char *main_template = sb_strdup_printf("%s/%s", template_dir,
bm_ctx_settings_lookup(rv, "main_template"));
rv->main_template_fctx = bm_filectx_new(rv, main_template, NULL, NULL);
free(main_template);
@@ -271,7 +271,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
for (size_t i = 0; settings->posts[i] != NULL; i++) {
char *f = bm_generate_filename(content_dir, post_prefix,
settings->posts[i], source_ext);
- rv->posts_fctx = bc_slist_append(rv->posts_fctx,
+ rv->posts_fctx = sb_slist_append(rv->posts_fctx,
bm_filectx_new(rv, f, settings->posts[i], NULL));
free(f);
}
@@ -282,7 +282,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
for (size_t i = 0; settings->pages[i] != NULL; i++) {
char *f = bm_generate_filename(content_dir, NULL, settings->pages[i],
source_ext);
- rv->pages_fctx = bc_slist_append(rv->pages_fctx,
+ rv->pages_fctx = sb_slist_append(rv->pages_fctx,
bm_filectx_new(rv, f, settings->pages[i], NULL));
free(f);
}
@@ -312,13 +312,13 @@ bm_ctx_reload(bm_ctx_t **ctx)
// files
// needs to dup path, because it may be freed when reloading.
- char *tmp = bc_strdup((*ctx)->settings_fctx->path);
- bc_error_t *err = NULL;
+ char *tmp = sb_strdup((*ctx)->settings_fctx->path);
+ sb_error_t *err = NULL;
*ctx = bm_ctx_new(*ctx, tmp, NULL, &err);
free(tmp);
if (err != NULL) {
- bc_error_print(err, "blogc-make");
- bc_error_free(err);
+ fprintf(stderr, "blogc-make: error: %s\n", sb_error_to_string(err));
+ sb_error_free(err);
return false;
}
return true;
@@ -328,13 +328,13 @@ bm_ctx_reload(bm_ctx_t **ctx)
bm_filectx_reload((*ctx)->atom_template_fctx);
bm_filectx_reload((*ctx)->listing_entry_fctx);
- for (bc_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
- for (bc_slist_t *tmp = (*ctx)->pages_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->pages_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
- for (bc_slist_t *tmp = (*ctx)->copy_fctx; tmp != NULL; tmp = tmp->next)
+ for (sb_slist_t *tmp = (*ctx)->copy_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
return true;
@@ -370,11 +370,11 @@ bm_ctx_free_internal(bm_ctx_t *ctx)
bm_filectx_free(ctx->listing_entry_fctx);
ctx->listing_entry_fctx = NULL;
- bc_slist_free_full(ctx->posts_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->posts_fctx, (sb_free_func_t) bm_filectx_free);
ctx->posts_fctx = NULL;
- bc_slist_free_full(ctx->pages_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->pages_fctx, (sb_free_func_t) bm_filectx_free);
ctx->pages_fctx = NULL;
- bc_slist_free_full(ctx->copy_fctx, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(ctx->copy_fctx, (sb_free_func_t) bm_filectx_free);
ctx->copy_fctx = NULL;
}
@@ -396,7 +396,7 @@ bm_ctx_settings_lookup(bm_ctx_t *ctx, const char *key)
{
if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL)
return NULL;
- return bc_trie_lookup(ctx->settings->settings, key);
+ return sb_trie_lookup(ctx->settings->settings, key);
}
diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h
index a66d51c..c819b9e 100644
--- a/src/blogc-make/ctx.h
+++ b/src/blogc-make/ctx.h
@@ -12,9 +12,9 @@
#include <sys/stat.h>
#include <stdbool.h>
#include <time.h>
+#include <squareball.h>
+
#include "settings.h"
-#include "../common/error.h"
-#include "../common/utils.h"
#ifdef __APPLE__
#define st_mtim_tv_sec st_mtimespec.tv_sec
@@ -62,19 +62,19 @@ typedef struct {
bm_filectx_t *settings_fctx;
bm_filectx_t *listing_entry_fctx;
- bc_slist_t *posts_fctx;
- bc_slist_t *pages_fctx;
- bc_slist_t *copy_fctx;
+ sb_slist_t *posts_fctx;
+ sb_slist_t *pages_fctx;
+ sb_slist_t *copy_fctx;
} bm_ctx_t;
bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
struct stat *st);
-bc_slist_t* bm_filectx_new_r(bc_slist_t *l, bm_ctx_t *ctx, const char *filename);
+sb_slist_t* bm_filectx_new_r(sb_slist_t *l, bm_ctx_t *ctx, const char *filename);
bool bm_filectx_changed(bm_filectx_t *ctx, time_t *tv_sec, long *tv_nsec);
void bm_filectx_reload(bm_filectx_t *ctx);
void bm_filectx_free(bm_filectx_t *fctx);
bm_ctx_t* bm_ctx_new(bm_ctx_t *base, const char *settings_file,
- const char *argv0, bc_error_t **err);
+ const char *argv0, sb_error_t **err);
bool bm_ctx_reload(bm_ctx_t **ctx);
void bm_ctx_free_internal(bm_ctx_t *ctx);
void bm_ctx_free(bm_ctx_t *ctx);
diff --git a/src/blogc-make/exec-native.c b/src/blogc-make/exec-native.c
index 179216a..0278c00 100644
--- a/src/blogc-make/exec-native.c
+++ b/src/blogc-make/exec-native.c
@@ -16,11 +16,10 @@
#include <unistd.h>
#include <libgen.h>
#include <errno.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
-#include "exec-native.h"
+#include <squareball.h>
+
#include "ctx.h"
+#include "exec-native.h"
int
@@ -32,7 +31,7 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
printf(" COPY %s\n", dest->short_path);
fflush(stdout);
- char *fname = bc_strdup(dest->path);
+ char *fname = sb_strdup(dest->path);
for (char *tmp = fname; *tmp != '\0'; tmp++) {
if (*tmp != '/' && *tmp != '\\')
continue;
@@ -67,8 +66,8 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
}
ssize_t nread;
- char buffer[BC_FILE_CHUNK_SIZE];
- while (0 < (nread = read(fd_from, buffer, BC_FILE_CHUNK_SIZE))) {
+ char buffer[128];
+ while (0 < (nread = read(fd_from, buffer, 128))) {
char *out_ptr = buffer;
do {
ssize_t nwritten = write(fd_to, out_ptr, nread);
@@ -89,7 +88,7 @@ bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose)
bool
-bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
+bm_exec_native_is_empty_dir(const char *dir, sb_error_t **err)
{
DIR *d = opendir(dir);
if (d == NULL) {
@@ -97,7 +96,7 @@ bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
return true;
}
if (err != NULL) {
- *err = bc_error_new_printf(0, "failed to open directory (%s): %s\n",
+ *err = sb_strerror_new_printf("failed to open directory (%s): %s\n",
dir, strerror(errno));
}
return true;
@@ -114,7 +113,7 @@ bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err)
if (0 != closedir(d)) {
if (err != NULL) {
- *err = bc_error_new_printf(0, "failed to close directory (%s): %s\n",
+ *err = sb_strerror_new_printf("failed to close directory (%s): %s\n",
dir, strerror(errno));
}
return true;
@@ -143,16 +142,16 @@ bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose)
// blame freebsd's libc for all of those memory allocations around dirname
// calls!
- char *short_dir = bc_strdup(dirname(dest->short_path));
- char *dir = bc_strdup(dirname(dest->path));
+ char *short_dir = sb_strdup(dirname(dest->short_path));
+ char *dir = sb_strdup(dirname(dest->path));
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
while ((0 != strcmp(short_dir, ".")) && (0 != strcmp(short_dir, "/"))) {
bool empty = bm_exec_native_is_empty_dir(dir, &err);
if (err != NULL) {
- fprintf(stderr, "blogc-make: error: %s\n", err->msg);
- bc_error_free(err);
+ fprintf(stderr, "blogc-make: error: %s\n", sb_error_to_string(err));
+ sb_error_free(err);
rv = 1;
break;
}
@@ -175,10 +174,10 @@ bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose)
}
char *tmp = short_dir;
- short_dir = bc_strdup(dirname(short_dir));
+ short_dir = sb_strdup(dirname(short_dir));
free(tmp);
tmp = dir;
- dir = bc_strdup(dirname(dir));
+ dir = sb_strdup(dirname(dir));
free(tmp);
}
diff --git a/src/blogc-make/exec-native.h b/src/blogc-make/exec-native.h
index 56a1da1..7fe7575 100644
--- a/src/blogc-make/exec-native.h
+++ b/src/blogc-make/exec-native.h
@@ -10,11 +10,12 @@
#define _MAKE_EXEC_NATIVE_H
#include <stdbool.h>
-#include "../common/error.h"
+#include <squareball.h>
+
#include "ctx.h"
int bm_exec_native_cp(bm_filectx_t *source, bm_filectx_t *dest, bool verbose);
-bool bm_exec_native_is_empty_dir(const char *dir, bc_error_t **err);
+bool bm_exec_native_is_empty_dir(const char *dir, sb_error_t **err);
int bm_exec_native_rm(const char *output_dir, bm_filectx_t *dest, bool verbose);
#endif /* _MAKE_EXEC_NATIVE_H */
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index 74af2ed..89d4b0a 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -19,13 +19,11 @@
#include <sysexits.h>
#include <errno.h>
#include <libgen.h>
-#include "../common/compat.h"
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
-#include "exec.h"
#include "settings.h"
+#include "exec.h"
char*
@@ -36,14 +34,14 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
// argv0, because the static binary may not be named `blogc`, and we
// prefer to use our own `blogc` instead of some other version around.
if (argv0 != NULL && bin != NULL && (0 == strcmp(bin, "blogc"))) {
- return bc_shell_quote(argv0);
+ return sb_shell_quote(argv0);
}
#endif
// first try: env var
const char *env_bin = getenv(env);
if (env_bin != NULL) {
- return bc_shell_quote(env_bin);
+ return sb_shell_quote(env_bin);
}
// second try: same dir as current exec
@@ -55,13 +53,13 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
// that relative paths will work as expected.
// - windows path sep is not supported
if (argv0 != NULL && (NULL != strchr(argv0, '/'))) {
- char *path = bc_strdup(argv0);
- char *dir = bc_strdup(dirname(path));
+ char *path = sb_strdup(argv0);
+ char *dir = sb_strdup(dirname(path));
free(path);
- char *tmp = bc_strdup_printf("%s/%s", dir, bin);
+ char *tmp = sb_strdup_printf("%s/%s", dir, bin);
free(dir);
if (0 == access(tmp, X_OK)) {
- char *rv = bc_shell_quote(tmp);
+ char *rv = sb_shell_quote(tmp);
free(tmp);
return rv;
}
@@ -69,28 +67,28 @@ bm_exec_find_binary(const char *argv0, const char *bin, const char *env)
}
// last try: $PATH
- return bc_strdup(bin);
+ return sb_strdup(bin);
}
int
bm_exec_command(const char *cmd, const char *input, char **output,
- char **error, bc_error_t **err)
+ char **error, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return 1;
int fd_in[2];
if (-1 == pipe(fd_in)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to create stdin pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to create stdin pipe: %s", strerror(errno));
return 1;
}
int fd_out[2];
if (-1 == pipe(fd_out)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to create stdout pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to create stdout pipe: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
return 1;
@@ -98,8 +96,8 @@ bm_exec_command(const char *cmd, const char *input, char **output,
int fd_err[2];
if (-1 == pipe(fd_err)) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to create stderr pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to create stderr pipe: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
close(fd_out[0]);
@@ -109,8 +107,8 @@ bm_exec_command(const char *cmd, const char *input, char **output,
pid_t pid = fork();
if (pid == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to fork: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to fork: %s", strerror(errno));
close(fd_in[0]);
close(fd_in[1]);
close(fd_out[0]);
@@ -149,8 +147,8 @@ bm_exec_command(const char *cmd, const char *input, char **output,
if (input != NULL) {
if (-1 == write(fd_in[1], input, strlen(input))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to write to stdin pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to write to stdin pipe: %s", strerror(errno));
close(fd_in[1]);
close(fd_out[0]);
close(fd_err[0]);
@@ -160,145 +158,145 @@ bm_exec_command(const char *cmd, const char *input, char **output,
close(fd_in[1]);
- char buffer[BC_FILE_CHUNK_SIZE];
+ char buffer[128];
ssize_t s;
- bc_string_t *out = NULL;
- while(0 != (s = read(fd_out[0], buffer, BC_FILE_CHUNK_SIZE))) {
+ sb_string_t *out = NULL;
+ while(0 != (s = read(fd_out[0], buffer, 128))) {
if (s == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to read from stdout pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to read from stdout pipe: %s", strerror(errno));
close(fd_out[0]);
close(fd_err[0]);
- bc_string_free(out, true);
+ sb_string_free(out, true);
return 1;
}
if (out == NULL) {
- out = bc_string_new();
+ out = sb_string_new();
}
- bc_string_append_len(out, buffer, s);
+ sb_string_append_len(out, buffer, s);
}
if (out != NULL) {
- *output = bc_string_free(out, false);
+ *output = sb_string_free(out, false);
}
close(fd_out[0]);
out = NULL;
- while(0 != (s = read(fd_err[0], buffer, BC_FILE_CHUNK_SIZE))) {
+ while(0 != (s = read(fd_err[0], buffer, 128))) {
if (s == -1) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_EXEC,
- "Failed to read from stderr pipe: %s", strerror(errno));
+ *err = sb_strerror_new_printf(
+ "exec: Failed to read from stderr pipe: %s", strerror(errno));
close(fd_err[0]);
- bc_string_free(out, true);
+ sb_string_free(out, true);
return 1;
}
if (out == NULL)
- out = bc_string_new();
- bc_string_append_len(out, buffer, s);
+ out = sb_string_new();
+ sb_string_append_len(out, buffer, s);
}
if (out != NULL) {
- *error = bc_string_free(out, false);
+ *error = sb_string_free(out, false);
}
close(fd_err[0]);
int status;
waitpid(pid, &status, 0);
- return bc_compat_status_code(status);
+ return sb_compat_status_code(status);
}
static void
-list_variables(const char *key, const char *value, bc_string_t *str)
+list_variables(const char *key, const char *value, sb_string_t *str)
{
- char *tmp = bc_shell_quote(value);
- bc_string_append_printf(str, " -D %s=%s", key, tmp);
+ char *tmp = sb_shell_quote(value);
+ sb_string_append_printf(str, " -D %s=%s", key, tmp);
free(tmp);
}
char*
bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
- bc_trie_t *global_variables, bc_trie_t *local_variables, const char *print,
+ sb_trie_t *global_variables, sb_trie_t *local_variables, const char *print,
bool listing, const char *listing_entry, const char *template,
const char *output, bool dev, bool sources_stdin)
{
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
const char *locale = NULL;
if (settings != NULL) {
- locale = bc_trie_lookup(settings->settings, "locale");
+ locale = sb_trie_lookup(settings->settings, "locale");
}
if (locale != NULL) {
- char *tmp = bc_shell_quote(locale);
- bc_string_append_printf(rv, "LC_ALL=%s ", tmp);
+ char *tmp = sb_shell_quote(locale);
+ sb_string_append_printf(rv, "LC_ALL=%s ", tmp);
free(tmp);
}
- bc_string_append(rv, blogc_bin);
+ sb_string_append(rv, blogc_bin);
if (settings != NULL) {
if (settings->tags != NULL) {
- char *tags = bc_strv_join(settings->tags, " ");
- bc_string_append_printf(rv, " -D MAKE_TAGS='%s'", tags);
+ char *tags = sb_strv_join(settings->tags, " ");
+ sb_string_append_printf(rv, " -D MAKE_TAGS='%s'", tags);
free(tags);
}
- bc_trie_foreach(settings->global,
- (bc_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(settings->global,
+ (sb_trie_foreach_func_t) list_variables, rv);
}
- bc_trie_foreach(global_variables, (bc_trie_foreach_func_t) list_variables, rv);
- bc_trie_foreach(local_variables, (bc_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(global_variables, (sb_trie_foreach_func_t) list_variables, rv);
+ sb_trie_foreach(local_variables, (sb_trie_foreach_func_t) list_variables, rv);
if (dev) {
- bc_string_append(rv, " -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
+ sb_string_append(rv, " -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
}
if (print != NULL) {
- bc_string_append_printf(rv, " -p %s", print);
+ sb_string_append_printf(rv, " -p %s", print);
}
if (listing) {
- bc_string_append(rv, " -l");
+ sb_string_append(rv, " -l");
if (listing_entry != NULL) {
- char *tmp = bc_shell_quote(listing_entry);
- bc_string_append_printf(rv, " -e %s", tmp);
+ char *tmp = sb_shell_quote(listing_entry);
+ sb_string_append_printf(rv, " -e %s", tmp);
free(tmp);
}
}
if (template != NULL) {
- char *tmp = bc_shell_quote(template);
- bc_string_append_printf(rv, " -t %s", tmp);
+ char *tmp = sb_shell_quote(template);
+ sb_string_append_printf(rv, " -t %s", tmp);
free(tmp);
}
if (output != NULL) {
- char *tmp = bc_shell_quote(output);
- bc_string_append_printf(rv, " -o %s", tmp);
+ char *tmp = sb_shell_quote(output);
+ sb_string_append_printf(rv, " -o %s", tmp);
free(tmp);
}
if (sources_stdin) {
- bc_string_append(rv, " -i");
+ sb_string_append(rv, " -i");
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
int
-bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_variables,
+bm_exec_blogc(bm_ctx_t *ctx, sb_trie_t *global_variables, sb_trie_t *local_variables,
bool listing, bm_filectx_t *listing_entry, bm_filectx_t *template,
- bm_filectx_t *output, bc_slist_t *sources, bool only_first_source)
+ bm_filectx_t *output, sb_slist_t *sources, bool only_first_source)
{
if (ctx == NULL)
return 1;
- bc_string_t *input = bc_string_new();
- for (bc_slist_t *l = sources; l != NULL; l = l->next) {
- bc_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
+ sb_string_t *input = sb_string_new();
+ for (sb_slist_t *l = sources; l != NULL; l = l->next) {
+ sb_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
if (only_first_source)
break;
}
@@ -315,17 +313,17 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
char *out = NULL;
char *err = NULL;
- bc_error_t *error = NULL;
+ sb_error_t *error = NULL;
int rv = bm_exec_command(cmd, input->str, &out, &err, &error);
if (error != NULL) {
- bc_error_print(error, "blogc-make");
+ fprintf(stderr, "blogc-make: error: %s\n", sb_error_to_string(error));
free(cmd);
free(out);
free(err);
- bc_string_free(input, true);
- bc_error_free(error);
+ sb_string_free(input, true);
+ sb_error_free(error);
return 1;
}
@@ -339,21 +337,21 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
"----------------------------->8-----------------------------\n"
"%s\n"
"----------------------------->8-----------------------------\n",
- bc_str_strip(input->str));
+ sb_str_strip(input->str));
}
if (out != NULL) {
fprintf(stderr, "\nSTDOUT:\n"
"----------------------------->8-----------------------------\n"
"%s\n"
"----------------------------->8-----------------------------\n",
- bc_str_strip(out));
+ sb_str_strip(out));
}
if (err != NULL) {
fprintf(stderr, "\nSTDERR:\n"
"----------------------------->8-----------------------------\n"
"%s\n"
"----------------------------->8-----------------------------\n",
- bc_str_strip(err));
+ sb_str_strip(err));
}
fprintf(stderr, "\n");
}
@@ -361,7 +359,7 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
fprintf(stderr, "%s\n", err);
}
- bc_string_free(input, true);
+ sb_string_free(input, true);
free(cmd);
free(out);
free(err);
@@ -371,16 +369,16 @@ bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables, bc_trie_t *local_varia
char*
-bm_exec_blogc_get_variable(bm_ctx_t *ctx, bc_trie_t *global_variables,
- bc_trie_t *local_variables, const char *variable, bool listing,
- bc_slist_t *sources, bool only_first_source)
+bm_exec_blogc_get_variable(bm_ctx_t *ctx, sb_trie_t *global_variables,
+ sb_trie_t *local_variables, const char *variable, bool listing,
+ sb_slist_t *sources, bool only_first_source)
{
if (ctx == NULL)
return NULL;
- bc_string_t *input = bc_string_new();
- for (bc_slist_t *l = sources; l != NULL; l = l->next) {
- bc_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
+ sb_string_t *input = sb_string_new();
+ for (sb_slist_t *l = sources; l != NULL; l = l->next) {
+ sb_string_append_printf(input, "%s\n", ((bm_filectx_t*) l->data)->path);
if (only_first_source)
break;
}
@@ -394,14 +392,14 @@ bm_exec_blogc_get_variable(bm_ctx_t *ctx, bc_trie_t *global_variables,
char *out = NULL;
char *err = NULL;
- bc_error_t *error = NULL;
+ sb_error_t *error = NULL;
int rv = bm_exec_command(cmd, input->str, &out, &err, &error);
if (error != NULL) {
- bc_error_print(error, "blogc-make");
- bc_error_free(error);
- bc_string_free(input, true);
+ fprintf(stderr, "blogc-make: error: %s\n", sb_error_to_string(error));
+ sb_error_free(error);
+ sb_string_free(input, true);
free(cmd);
free(out);
free(err);
@@ -410,8 +408,8 @@ bm_exec_blogc_get_variable(bm_ctx_t *ctx, bc_trie_t *global_variables,
if (rv != 0) {
if (rv != EX_CONFIG)
- fprintf(stderr, "blogc-make: error: %s\n", bc_str_strip(err));
- bc_string_free(input, true);
+ fprintf(stderr, "blogc-make: error: %s\n", sb_str_strip(err));
+ sb_string_free(input, true);
free(cmd);
free(out);
free(err);
@@ -420,9 +418,9 @@ bm_exec_blogc_get_variable(bm_ctx_t *ctx, bc_trie_t *global_variables,
char *val = NULL;
if (out != NULL)
- val = bc_strndup(out, strlen(out) - 1);
+ val = sb_strndup(out, strlen(out) - 1);
- bc_string_free(input, true);
+ sb_string_free(input, true);
free(cmd);
free(out);
free(err);
@@ -438,30 +436,30 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
if (ctx == NULL)
return 1;
- bc_string_t *cmd = bc_string_new();
+ sb_string_t *cmd = sb_string_new();
- bc_string_append(cmd, ctx->blogc_runserver);
+ sb_string_append(cmd, ctx->blogc_runserver);
if (host != NULL) {
- char *tmp = bc_shell_quote(host);
- bc_string_append_printf(cmd, " -t %s", tmp);
+ char *tmp = sb_shell_quote(host);
+ sb_string_append_printf(cmd, " -t %s", tmp);
free(tmp);
}
if (port != NULL) {
- char *tmp = bc_shell_quote(port);
- bc_string_append_printf(cmd, " -p %s", tmp);
+ char *tmp = sb_shell_quote(port);
+ sb_string_append_printf(cmd, " -p %s", tmp);
free(tmp);
}
if (threads != NULL) {
- char *tmp = bc_shell_quote(threads);
- bc_string_append_printf(cmd, " -m %s", tmp);
+ char *tmp = sb_shell_quote(threads);
+ sb_string_append_printf(cmd, " -m %s", tmp);
free(tmp);
}
- char *tmp = bc_shell_quote(ctx->output_dir);
- bc_string_append_printf(cmd, " %s", tmp);
+ char *tmp = sb_shell_quote(ctx->output_dir);
+ sb_string_append_printf(cmd, " %s", tmp);
free(tmp);
if (ctx->verbose)
@@ -472,8 +470,8 @@ bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
// we don't need pipes to run blogc-runserver, because it is "interactive"
int status = system(cmd->str);
- int rv = bc_compat_status_code(status);
- bc_string_free(cmd, true);
+ int rv = sb_compat_status_code(status);
+ sb_string_free(cmd, true);
if (rv != 0 && rv != 130) {
if (rv == 127) {
diff --git a/src/blogc-make/exec.h b/src/blogc-make/exec.h
index 6bc206f..40d38b9 100644
--- a/src/blogc-make/exec.h
+++ b/src/blogc-make/exec.h
@@ -10,25 +10,25 @@
#define _MAKE_EXEC_H
#include <stdbool.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "settings.h"
char* bm_exec_find_binary(const char *argv0, const char *bin, const char *env);
int bm_exec_command(const char *cmd, const char *input, char **output,
- char **error, bc_error_t **err);
+ char **error, sb_error_t **err);
char* bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
- bc_trie_t *global_variables, bc_trie_t *local_variables, const char *print,
+ sb_trie_t *global_variables, sb_trie_t *local_variables, const char *print,
bool listing, const char *listing_entry, const char *template,
const char *output, bool dev, bool sources_stdin);
-int bm_exec_blogc(bm_ctx_t *ctx, bc_trie_t *global_variables,
- bc_trie_t *local_variables, bool listing, bm_filectx_t *listing_entry,
- bm_filectx_t *template, bm_filectx_t *output, bc_slist_t *sources,
+int bm_exec_blogc(bm_ctx_t *ctx, sb_trie_t *global_variables,
+ sb_trie_t *local_variables, bool listing, bm_filectx_t *listing_entry,
+ bm_filectx_t *template, bm_filectx_t *output, sb_slist_t *sources,
bool only_first_source);
-char* bm_exec_blogc_get_variable(bm_ctx_t *ctx, bc_trie_t *global_variables,
- bc_trie_t *local_variables, const char *variable, bool listing,
- bc_slist_t *sources, bool only_first_source);
+char* bm_exec_blogc_get_variable(bm_ctx_t *ctx, sb_trie_t *global_variables,
+ sb_trie_t *local_variables, const char *variable, bool listing,
+ sb_slist_t *sources, bool only_first_source);
int bm_exec_blogc_runserver(bm_ctx_t *ctx, const char *host, const char *port,
const char *threads);
diff --git a/src/blogc-make/httpd.c b/src/blogc-make/httpd.c
index adf9a9b..4412369 100644
--- a/src/blogc-make/httpd.c
+++ b/src/blogc-make/httpd.c
@@ -11,7 +11,8 @@
#include <string.h>
#include <pthread.h>
#include <unistd.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "exec.h"
#include "reloader.h"
@@ -23,7 +24,7 @@
typedef struct {
bm_ctx_t *ctx;
- bc_trie_t *args;
+ sb_trie_t *args;
} bm_httpd_t;
@@ -32,8 +33,8 @@ httpd_thread(void *arg)
{
bm_httpd_t *httpd = arg;
- int rv = bm_exec_blogc_runserver(httpd->ctx, bc_trie_lookup(httpd->args, "host"),
- bc_trie_lookup(httpd->args, "port"), bc_trie_lookup(httpd->args, "threads"));
+ int rv = bm_exec_blogc_runserver(httpd->ctx, sb_trie_lookup(httpd->args, "host"),
+ sb_trie_lookup(httpd->args, "port"), sb_trie_lookup(httpd->args, "threads"));
free(httpd);
@@ -45,8 +46,8 @@ httpd_thread(void *arg)
int
-bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs,
- bc_trie_t *args)
+bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, sb_slist_t *outputs,
+ sb_trie_t *args)
{
// this is here to avoid that the httpd starts running in the middle of the
// first build, as the reloader and the httpd are started in parallel.
@@ -76,7 +77,7 @@ bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs,
return 1;
}
- bm_httpd_t *rv = bc_malloc(sizeof(bm_httpd_t));
+ bm_httpd_t *rv = sb_malloc(sizeof(bm_httpd_t));
rv->ctx = *ctx;
rv->args = args;
diff --git a/src/blogc-make/httpd.h b/src/blogc-make/httpd.h
index b0fa87d..2aa90b9 100644
--- a/src/blogc-make/httpd.h
+++ b/src/blogc-make/httpd.h
@@ -9,11 +9,12 @@
#ifndef _MAKE_HTTPD_H
#define _MAKE_HTTPD_H
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
-int bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs,
- bc_trie_t *args);
+int bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, sb_slist_t *outputs,
+ sb_trie_t *args);
#endif /* _MAKE_HTTPD_H */
diff --git a/src/blogc-make/main.c b/src/blogc-make/main.c
index 5b4a030..9b4bce0 100644
--- a/src/blogc-make/main.c
+++ b/src/blogc-make/main.c
@@ -14,8 +14,8 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
@@ -60,9 +60,9 @@ main(int argc, char **argv)
setlocale(LC_ALL, "");
int rv = 0;
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
- bc_slist_t *rules = NULL;
+ sb_slist_t *rules = NULL;
bool verbose = false;
bool dev = false;
char *blogcfile = NULL;
@@ -85,9 +85,9 @@ main(int argc, char **argv)
break;
case 'f':
if (argv[i][2] != '\0')
- blogcfile = bc_strdup(argv[i] + 2);
+ blogcfile = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- blogcfile = bc_strdup(argv[++i]);
+ blogcfile = sb_strdup(argv[++i]);
break;
#ifdef MAKE_EMBEDDED
case 'm':
@@ -103,18 +103,18 @@ main(int argc, char **argv)
}
}
else {
- rules = bc_slist_append(rules, bc_strdup(argv[i]));
+ rules = sb_slist_append(rules, sb_strdup(argv[i]));
}
}
if (rules == NULL) {
- rules = bc_slist_append(rules, bc_strdup("all"));
+ rules = sb_slist_append(rules, sb_strdup("all"));
}
ctx = bm_ctx_new(NULL, blogcfile ? blogcfile : "blogcfile",
argc > 0 ? argv[0] : NULL, &err);
if (err != NULL) {
- bc_error_print(err, "blogc-make");
+ fprintf(stderr, "blogc-make: error: %s\n", sb_error_to_string(err));
rv = 1;
goto cleanup;
}
@@ -125,10 +125,10 @@ main(int argc, char **argv)
cleanup:
- bc_slist_free_full(rules, free);
+ sb_slist_free_full(rules, free);
free(blogcfile);
bm_ctx_free(ctx);
- bc_error_free(err);
+ sb_error_free(err);
return rv;
}
diff --git a/src/blogc-make/reloader.c b/src/blogc-make/reloader.c
index fea8bd4..2fcbaf9 100644
--- a/src/blogc-make/reloader.c
+++ b/src/blogc-make/reloader.c
@@ -14,7 +14,8 @@
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
#include "reloader.h"
@@ -36,7 +37,7 @@ sig_handler(int signum)
int
bm_reloader_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec,
- bc_slist_t *outputs, bc_trie_t *args)
+ sb_slist_t *outputs, sb_trie_t *args)
{
// install ^C handler
struct sigaction current_action;
diff --git a/src/blogc-make/reloader.h b/src/blogc-make/reloader.h
index f3fddf4..95332db 100644
--- a/src/blogc-make/reloader.h
+++ b/src/blogc-make/reloader.h
@@ -9,12 +9,13 @@
#ifndef _MAKE_RELOADER_H
#define _MAKE_RELOADER_H
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "ctx.h"
#include "rules.h"
int bm_reloader_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec,
- bc_slist_t *outputs, bc_trie_t *args);
+ sb_slist_t *outputs, sb_trie_t *args);
void bm_reloader_stop(int status_code);
#endif /* _MAKE_RELOADER_H */
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 06223c0..3b10bd2 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -11,7 +11,8 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "atom.h"
#include "ctx.h"
#include "exec.h"
@@ -24,36 +25,36 @@
static void
-posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
+posts_ordering(bm_ctx_t *ctx, sb_trie_t *variables, const char *variable)
{
if (ctx == NULL)
return; // something is wrong, let's not add any variable
const char *value = bm_ctx_settings_lookup_str(ctx, variable);
bool asc = 0 == strcasecmp(value, "asc");
- bool sort = bc_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_sort"));
+ bool sort = sb_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_sort"));
if (sort) {
- bc_trie_insert(variables, "FILTER_SORT", bc_strdup("1"));
+ sb_trie_insert(variables, "FILTER_SORT", sb_strdup("1"));
}
if ((sort && asc) || (!sort && !asc)) {
- bc_trie_insert(variables, "FILTER_REVERSE", bc_strdup("1"));
+ sb_trie_insert(variables, "FILTER_REVERSE", sb_strdup("1"));
}
}
static void
-posts_pagination(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
+posts_pagination(bm_ctx_t *ctx, sb_trie_t *variables, const char *variable)
{
if (ctx == NULL)
return; // something is wrong, let's not add any variable
long posts_per_page = strtol(bm_ctx_settings_lookup_str(ctx, variable), NULL, 10);
if (posts_per_page >= 0) {
- bc_trie_insert(variables, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(variables, "FILTER_PER_PAGE",
- bc_strdup(bm_ctx_settings_lookup(ctx, variable)));
+ sb_trie_insert(variables, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(variables, "FILTER_PER_PAGE",
+ sb_strdup(bm_ctx_settings_lookup(ctx, variable)));
}
}
@@ -71,7 +72,7 @@ posts_pagination_enabled(bm_ctx_t *ctx, const char *variable)
// INDEX RULE
-static bc_slist_t*
+static sb_slist_t*
index_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
@@ -80,36 +81,36 @@ index_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "posts_per_page"))
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *index_prefix = bm_ctx_settings_lookup(ctx, "index_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
char *f = bm_generate_filename(ctx->short_output_dir, index_prefix, NULL,
html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
return rv;
}
static int
-index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+index_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("index"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("index"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -123,7 +124,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -131,7 +132,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// ATOM RULE
-static bc_slist_t*
+static sb_slist_t*
atom_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
@@ -140,35 +141,35 @@ atom_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *atom_prefix = bm_ctx_settings_lookup(ctx, "atom_prefix");
const char *atom_ext = bm_ctx_settings_lookup(ctx, "atom_ext");
char *f = bm_generate_filename(ctx->short_output_dir, atom_prefix, NULL,
atom_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
return rv;
}
static int
-atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+atom_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "atom_posts_per_page");
posts_ordering(ctx, variables, "atom_order");
- bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ"));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
+ sb_trie_insert(variables, "DATE_FORMAT", sb_strdup("%Y-%m-%dT%H:%M:%SZ"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("atom"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("atom"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -182,7 +183,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -190,7 +191,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// ATOM TAGS RULE
-static bc_slist_t*
+static sb_slist_t*
atom_tags_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
@@ -199,7 +200,7 @@ atom_tags_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *atom_prefix = bm_ctx_settings_lookup(ctx, "atom_prefix");
const char *atom_ext = bm_ctx_settings_lookup(ctx, "atom_ext");
@@ -207,7 +208,7 @@ atom_tags_outputlist(bm_ctx_t *ctx)
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, atom_prefix,
ctx->settings->tags[i], atom_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -215,7 +216,7 @@ atom_tags_outputlist(bm_ctx_t *ctx)
}
static int
-atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+atom_tags_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
@@ -223,20 +224,20 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t i = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "atom_posts_per_page");
posts_ordering(ctx, variables, "atom_order");
- bc_trie_insert(variables, "DATE_FORMAT", bc_strdup("%Y-%m-%dT%H:%M:%SZ"));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("atom_tags"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("atom"));
+ sb_trie_insert(variables, "DATE_FORMAT", sb_strdup("%Y-%m-%dT%H:%M:%SZ"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("atom_tags"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("atom"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, i++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, i++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_TAG",
- bc_strdup(ctx->settings->tags[i]));
+ sb_trie_insert(variables, "FILTER_TAG",
+ sb_strdup(ctx->settings->tags[i]));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
fctx, false))
@@ -248,7 +249,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -256,7 +257,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// PAGINATION RULE
-static bc_slist_t*
+static sb_slist_t*
pagination_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
@@ -265,13 +266,13 @@ pagination_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "posts_per_page"))
return NULL;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
char *last_page = bm_exec_blogc_get_variable(ctx, variables, NULL, "LAST_PAGE",
true, ctx->posts_fctx, false);
- bc_trie_free(variables);
+ sb_trie_free(variables);
if (last_page == NULL)
return NULL;
@@ -279,16 +280,16 @@ pagination_outputlist(bm_ctx_t *ctx)
long pages = strtol(last_page, NULL, 10);
free(last_page);
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
for (size_t i = 0; i < pages; i++) {
- char *j = bc_strdup_printf("%d", i + 1);
+ char *j = sb_strdup_printf("%d", i + 1);
char *f = bm_generate_filename(ctx->short_output_dir, pagination_prefix,
j, html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(j);
free(f);
}
@@ -297,7 +298,7 @@ pagination_outputlist(bm_ctx_t *ctx)
}
static int
-pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+pagination_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
@@ -305,22 +306,22 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t page = 1;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
// not using posts_pagination because we set FILTER_PAGE anyway, and the
// first value inserted in that function would be useless
- bc_trie_insert(variables, "FILTER_PER_PAGE",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "posts_per_page")));
+ sb_trie_insert(variables, "FILTER_PER_PAGE",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "posts_per_page")));
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pagination"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("pagination"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, page++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, page++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_PAGE", bc_strdup_printf("%zu", page));
+ sb_trie_insert(variables, "FILTER_PAGE", sb_strdup_printf("%zu", page));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
@@ -331,7 +332,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -339,7 +340,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// PAGINATION TAGS RULE
-static bc_slist_t*
+static sb_slist_t*
pagination_tags_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
@@ -348,23 +349,23 @@ pagination_tags_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "posts_per_page"))
return NULL;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
for (size_t k = 0; ctx->settings->tags[k] != NULL; k++) {
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "FILTER_TAG", bc_strdup(ctx->settings->tags[k]));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "FILTER_TAG", sb_strdup(ctx->settings->tags[k]));
char *last_page = bm_exec_blogc_get_variable(ctx, variables, local,
"LAST_PAGE", true, ctx->posts_fctx, false);
- bc_trie_free(local);
+ sb_trie_free(local);
if (last_page == NULL)
continue;
@@ -373,22 +374,22 @@ pagination_tags_outputlist(bm_ctx_t *ctx)
free(last_page);
for (size_t i = 0; i < pages; i++) {
- char *j = bc_strdup_printf("%d", i + 1);
+ char *j = sb_strdup_printf("%d", i + 1);
char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
ctx->settings->tags[k], pagination_prefix, j, html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(j);
free(f);
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
static int
-pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+pagination_tags_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
@@ -396,22 +397,22 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t page = 1;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
// not using posts_pagination because we set FILTER_PAGE anyway, and the
// first value inserted in that function would be useless
- bc_trie_insert(variables, "FILTER_PER_PAGE",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "posts_per_page")));
+ sb_trie_insert(variables, "FILTER_PER_PAGE",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "posts_per_page")));
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pagination_tags"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("pagination_tags"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *pagination_prefix = bm_ctx_settings_lookup(ctx, "pagination_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -424,8 +425,8 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// it is impossible to have more output files per tag than the whole
// amount of output pages
- for (size_t k = 1; k <= bc_slist_length(outputs); k++) {
- char *j = bc_strdup_printf("%d", k);
+ for (size_t k = 1; k <= sb_slist_length(outputs); k++) {
+ char *j = sb_strdup_printf("%d", k);
char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
ctx->settings->tags[i], pagination_prefix, j, html_ext);
free(j);
@@ -444,8 +445,8 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (tag == NULL)
continue;
- bc_trie_insert(variables, "FILTER_TAG", bc_strdup(tag));
- bc_trie_insert(variables, "FILTER_PAGE", bc_strdup_printf("%zu", page));
+ sb_trie_insert(variables, "FILTER_TAG", sb_strdup(tag));
+ sb_trie_insert(variables, "FILTER_PAGE", sb_strdup_printf("%zu", page));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
@@ -457,7 +458,7 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -465,13 +466,13 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// POSTS RULE
-static bc_slist_t*
+static sb_slist_t*
posts_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *post_prefix = bm_ctx_settings_lookup(ctx, "post_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
@@ -479,7 +480,7 @@ posts_outputlist(bm_ctx_t *ctx)
for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, post_prefix,
ctx->settings->posts[i], html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -487,22 +488,22 @@ posts_outputlist(bm_ctx_t *ctx)
}
static int
-posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+posts_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "IS_POST", bc_strdup("1"));
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup(ctx, "date_format")));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "IS_POST", sb_strdup("1"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup(ctx, "date_format")));
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("posts"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("posts"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->posts_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -514,17 +515,17 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(s, ctx->settings_fctx, NULL,
ctx->main_template_fctx, o_fctx, true))
{
- bc_trie_t *local = bc_trie_new(NULL);
- bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
+ sb_trie_t *local = sb_trie_new(NULL);
+ sb_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
rv = bm_exec_blogc(ctx, variables, local, false, NULL, ctx->main_template_fctx,
o_fctx, s, true);
- bc_trie_free(local);
+ sb_trie_free(local);
if (rv != 0)
break;
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -532,7 +533,7 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// TAGS RULE
-static bc_slist_t*
+static sb_slist_t*
tags_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
@@ -541,7 +542,7 @@ tags_outputlist(bm_ctx_t *ctx)
if (!posts_pagination_enabled(ctx, "posts_per_page"))
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *tag_prefix = bm_ctx_settings_lookup(ctx, "tag_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
@@ -549,7 +550,7 @@ tags_outputlist(bm_ctx_t *ctx)
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, tag_prefix,
ctx->settings->tags[i], html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -557,7 +558,7 @@ tags_outputlist(bm_ctx_t *ctx)
}
static int
-tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+tags_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
@@ -565,21 +566,21 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
int rv = 0;
size_t i = 0;
- bc_trie_t *variables = bc_trie_new(free);
+ sb_trie_t *variables = sb_trie_new(free);
posts_pagination(ctx, variables, "posts_per_page");
posts_ordering(ctx, variables, "html_order");
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("tags"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("post"));
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup_str(ctx, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("tags"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("post"));
- for (bc_slist_t *l = outputs; l != NULL; l = l->next, i++) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next, i++) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- bc_trie_insert(variables, "FILTER_TAG",
- bc_strdup(ctx->settings->tags[i]));
+ sb_trie_insert(variables, "FILTER_TAG",
+ sb_strdup(ctx->settings->tags[i]));
if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
@@ -591,7 +592,7 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -599,20 +600,20 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// PAGES RULE
-static bc_slist_t*
+static sb_slist_t*
pages_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->pages == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
for (size_t i = 0; ctx->settings->pages[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, NULL,
ctx->settings->pages[i], html_ext);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -620,20 +621,20 @@ pages_outputlist(bm_ctx_t *ctx)
}
static int
-pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+pages_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->pages == NULL)
return 0;
int rv = 0;
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "DATE_FORMAT",
- bc_strdup(bm_ctx_settings_lookup(ctx, "date_format")));
- bc_trie_insert(variables, "MAKE_RULE", bc_strdup("pages"));
- bc_trie_insert(variables, "MAKE_TYPE", bc_strdup("page"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "DATE_FORMAT",
+ sb_strdup(bm_ctx_settings_lookup(ctx, "date_format")));
+ sb_trie_insert(variables, "MAKE_RULE", sb_strdup("pages"));
+ sb_trie_insert(variables, "MAKE_TYPE", sb_strdup("page"));
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->pages_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -645,17 +646,17 @@ pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (bm_rule_need_rebuild(s, ctx->settings_fctx, NULL,
ctx->main_template_fctx, o_fctx, true))
{
- bc_trie_t *local = bc_trie_new(NULL);
- bc_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
+ sb_trie_t *local = sb_trie_new(NULL);
+ sb_trie_insert(local, "MAKE_SLUG", s_fctx->slug); // no need to copy
rv = bm_exec_blogc(ctx, variables, local, false, NULL, ctx->main_template_fctx,
o_fctx, s, true);
- bc_trie_free(local);
+ sb_trie_free(local);
if (rv != 0)
break;
}
}
- bc_trie_free(variables);
+ sb_trie_free(variables);
return rv;
}
@@ -663,20 +664,20 @@ pages_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// COPY FILES RULE
-static bc_slist_t*
+static sb_slist_t*
copy_outputlist(bm_ctx_t *ctx)
{
if (ctx == NULL || ctx->settings->copy == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
// we iterate over ctx->copy_fctx list instead of ctx->settings->copy,
// because bm_ctx_new() expands directories into its files, recursively.
- for (bc_slist_t *s = ctx->copy_fctx; s != NULL; s = s->next) {
- char *f = bc_strdup_printf("%s/%s", ctx->short_output_dir,
+ for (sb_slist_t *s = ctx->copy_fctx; s != NULL; s = s->next) {
+ char *f = sb_strdup_printf("%s/%s", ctx->short_output_dir,
((bm_filectx_t*) s->data)->short_path);
- rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
+ rv = sb_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -684,14 +685,14 @@ copy_outputlist(bm_ctx_t *ctx)
}
static int
-copy_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+copy_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
if (ctx == NULL || ctx->settings->copy == NULL)
return 0;
int rv = 0;
- bc_slist_t *s, *o;
+ sb_slist_t *s, *o;
for (s = ctx->copy_fctx, o = outputs; s != NULL && o != NULL;
s = s->next, o = o->next)
@@ -713,18 +714,18 @@ copy_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// CLEAN RULE
-static bc_slist_t*
+static sb_slist_t*
clean_outputlist(bm_ctx_t *ctx)
{
return bm_rule_list_built_files(ctx);
}
static int
-clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+clean_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
int rv = 0;
- for (bc_slist_t *l = outputs; l != NULL; l = l->next) {
+ for (sb_slist_t *l = outputs; l != NULL; l = l->next) {
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
@@ -744,13 +745,13 @@ clean_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
-static int all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args);
+static int all_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args);
// RUNSERVER RULE
static int
-runserver_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+runserver_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
return bm_httpd_run(&ctx, all_exec, outputs, args);
}
@@ -759,7 +760,7 @@ runserver_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// WATCH RULE
static int
-watch_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+watch_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
return bm_reloader_run(&ctx, all_exec, outputs, args);
}
@@ -768,7 +769,7 @@ watch_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// ATOM DUMP RULE
static int
-atom_dump_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+atom_dump_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
char *content = bm_atom_generate(ctx->settings);
if (content == NULL)
@@ -887,7 +888,7 @@ const bm_rule_t rules[] = {
// ALL RULE
static int
-all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
+all_exec(bm_ctx_t *ctx, sb_slist_t *outputs, sb_trie_t *args)
{
for (size_t i = 0; rules[i].name != NULL; i++) {
if (!rules[i].generate_files) {
@@ -904,30 +905,30 @@ all_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
-bc_trie_t*
+sb_trie_t*
bm_rule_parse_args(const char *sep)
{
if (sep == NULL || *sep == '\0' || *sep != ':')
return NULL;
- bc_trie_t *rv = bc_trie_new(free);
+ sb_trie_t *rv = sb_trie_new(free);
char *end = (char*) sep + 1;
char *kv_sep;
while (NULL != (kv_sep = strchr(end, '='))) {
- char *key = bc_strndup(end, kv_sep - end);
+ char *key = sb_strndup(end, kv_sep - end);
end = kv_sep + 1;
kv_sep = strchr(end, ',');
if (kv_sep == NULL)
kv_sep = strchr(end, '\0');
- char *value = bc_strndup(end, kv_sep - end);
- bc_trie_insert(rv, key, value);
+ char *value = sb_strndup(end, kv_sep - end);
+ sb_trie_insert(rv, key, value);
free(key);
if (*kv_sep == '\0')
break;
end = kv_sep + 1;
}
if (kv_sep == NULL) {
- bc_trie_free(rv);
+ sb_trie_free(rv);
return NULL;
}
@@ -936,7 +937,7 @@ bm_rule_parse_args(const char *sep)
int
-bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
+bm_rule_executor(bm_ctx_t *ctx, sb_slist_t *rule_list)
{
if (ctx == NULL)
return 1;
@@ -944,12 +945,12 @@ bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
const bm_rule_t *rule = NULL;
int rv = 0;
- for (bc_slist_t *l = rule_list; l != NULL; l = l->next) {
+ for (sb_slist_t *l = rule_list; l != NULL; l = l->next) {
char *rule_str = l->data;
char *sep = strchr(rule_str, ':');
- bc_trie_t *args = NULL;
+ sb_trie_t *args = NULL;
if (sep == NULL) {
sep = strchr(rule_str, '\0');
}
@@ -985,26 +986,26 @@ bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list)
int
-bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, bc_trie_t *args)
+bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, sb_trie_t *args)
{
if (ctx == NULL || rule == NULL)
return 1;
- bc_slist_t *outputs = NULL;
+ sb_slist_t *outputs = NULL;
if (rule->outputlist_func != NULL) {
outputs = rule->outputlist_func(ctx);
}
int rv = rule->exec_func(ctx, outputs, args);
- bc_slist_free_full(outputs, (bc_free_func_t) bm_filectx_free);
+ sb_slist_free_full(outputs, (sb_free_func_t) bm_filectx_free);
return rv;
}
bool
-bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
+bm_rule_need_rebuild(sb_slist_t *sources, bm_filectx_t *settings,
bm_filectx_t *listing_entry, bm_filectx_t *template, bm_filectx_t *output,
bool only_first_source)
{
@@ -1013,21 +1014,21 @@ bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
bool rv = false;
- bc_slist_t *s = NULL;
+ sb_slist_t *s = NULL;
if (settings != NULL)
- s = bc_slist_append(s, settings);
+ s = sb_slist_append(s, settings);
if (template != NULL)
- s = bc_slist_append(s, template);
+ s = sb_slist_append(s, template);
if (listing_entry != NULL)
- s = bc_slist_append(s, listing_entry);
+ s = sb_slist_append(s, listing_entry);
- for (bc_slist_t *l = sources; l != NULL; l = l->next) {
- s = bc_slist_append(s, l->data);
+ for (sb_slist_t *l = sources; l != NULL; l = l->next) {
+ s = sb_slist_append(s, l->data);
if (only_first_source)
break;
}
- for (bc_slist_t *l = s; l != NULL; l = l->next) {
+ for (sb_slist_t *l = s; l != NULL; l = l->next) {
bm_filectx_t *source = l->data;
if (source == NULL || !source->readable) {
// this is unlikely to happen, but lets just say that we need
@@ -1047,29 +1048,29 @@ bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
}
}
- bc_slist_free(s);
+ sb_slist_free(s);
return rv;
}
-bc_slist_t*
+sb_slist_t*
bm_rule_list_built_files(bm_ctx_t *ctx)
{
if (ctx == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
for (size_t i = 0; rules[i].name != NULL; i++) {
if (!rules[i].generate_files) {
continue;
}
- bc_slist_t *o = rules[i].outputlist_func(ctx);
- for (bc_slist_t *l = o; l != NULL; l = l->next) {
- rv = bc_slist_append(rv, l->data);
+ sb_slist_t *o = rules[i].outputlist_func(ctx);
+ for (sb_slist_t *l = o; l != NULL; l = l->next) {
+ rv = sb_slist_append(rv, l->data);
}
- bc_slist_free(o);
+ sb_slist_free(o);
}
return rv;
diff --git a/src/blogc-make/rules.h b/src/blogc-make/rules.h
index 29ba27e..d532084 100644
--- a/src/blogc-make/rules.h
+++ b/src/blogc-make/rules.h
@@ -10,12 +10,13 @@
#define _MAKE_RULES_H
#include <stdbool.h>
+#include <squareball.h>
+
#include "ctx.h"
-#include "../common/utils.h"
-typedef bc_slist_t* (*bm_rule_outputlist_func_t) (bm_ctx_t *ctx);
-typedef int (*bm_rule_exec_func_t) (bm_ctx_t *ctx, bc_slist_t *outputs,
- bc_trie_t *args);
+typedef sb_slist_t* (*bm_rule_outputlist_func_t) (bm_ctx_t *ctx);
+typedef int (*bm_rule_exec_func_t) (bm_ctx_t *ctx, sb_slist_t *outputs,
+ sb_trie_t *args);
typedef struct {
const char *name;
@@ -25,13 +26,13 @@ typedef struct {
bool generate_files;
} bm_rule_t;
-bc_trie_t* bm_rule_parse_args(const char *sep);
-int bm_rule_executor(bm_ctx_t *ctx, bc_slist_t *rule_list);
-int bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, bc_trie_t *args);
-bool bm_rule_need_rebuild(bc_slist_t *sources, bm_filectx_t *settings,
+sb_trie_t* bm_rule_parse_args(const char *sep);
+int bm_rule_executor(bm_ctx_t *ctx, sb_slist_t *rule_list);
+int bm_rule_execute(bm_ctx_t *ctx, const bm_rule_t *rule, sb_trie_t *args);
+bool bm_rule_need_rebuild(sb_slist_t *sources, bm_filectx_t *settings,
bm_filectx_t *listing_entry, bm_filectx_t *template, bm_filectx_t *output,
bool only_first_source);
-bc_slist_t* bm_rule_list_built_files(bm_ctx_t *ctx);
+sb_slist_t* bm_rule_list_built_files(bm_ctx_t *ctx);
void bm_rule_print_help(void);
#endif /* _MAKE_RULES_H */
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index be976e3..796f1b4 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -9,10 +9,8 @@
#include <libgen.h>
#include <stdbool.h>
#include <stdlib.h>
-#include "../common/config-parser.h"
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "settings.h"
@@ -77,7 +75,7 @@ static const char* list_sections[] = {
bm_settings_t*
-bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
+bm_settings_parse(const char *content, size_t content_len, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
@@ -85,14 +83,14 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
if (content == NULL)
return NULL;
- bc_config_t *config = bc_config_parse(content, content_len, list_sections,
+ sb_config_t *config = sb_config_parse(content, content_len, list_sections,
err);
if (config == NULL || (err != NULL && *err != NULL))
return NULL;
- bm_settings_t *rv = bc_malloc(sizeof(bm_settings_t));
- rv->global = bc_trie_new(free);
- rv->settings = bc_trie_new(free);
+ bm_settings_t *rv = sb_malloc(sizeof(bm_settings_t));
+ rv->global = sb_trie_new(free);
+ rv->settings = sb_trie_new(free);
rv->posts = NULL;
rv->pages = NULL;
rv->copy = NULL;
@@ -102,12 +100,12 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
// even if I never released a version with it, but some people is using
// it already.
const char *section = NULL;
- char **global = bc_config_list_keys(config, "global");
+ char **global = sb_config_list_keys(config, "global");
if (global != NULL) {
section = "global";
}
else {
- global = bc_config_list_keys(config, "environment");
+ global = sb_config_list_keys(config, "environment");
if (global != NULL) {
section = "environment";
}
@@ -120,25 +118,25 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
for (size_t i = 0; global[i] != NULL; i++) {
for (size_t j = 0; global[i][j] != '\0'; j++) {
if (!((global[i][j] >= 'A' && global[i][j] <= 'Z') || global[i][j] == '_')) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
- "Invalid [%s] key: %s", section, global[i]);
- bc_strv_free(global);
+ *err = sb_strerror_new_printf(
+ "settings: Invalid [%s] key: %s", section, global[i]);
+ sb_strv_free(global);
bm_settings_free(rv);
rv = NULL;
goto cleanup;
}
}
- bc_trie_insert(rv->global, global[i],
- bc_strdup(bc_config_get(config, section, global[i])));
+ sb_trie_insert(rv->global, global[i],
+ sb_strdup(sb_config_get(config, section, global[i])));
}
}
- bc_strv_free(global);
+ sb_strv_free(global);
for (size_t i = 0; required_global[i] != NULL; i++) {
- const char *value = bc_trie_lookup(rv->global, required_global[i]);
+ const char *value = sb_trie_lookup(rv->global, required_global[i]);
if (value == NULL || value[0] == '\0') {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
- "[%s] key required but not found or empty: %s", section,
+ *err = sb_strerror_new_printf(
+ "settings: [%s] key required but not found or empty: %s", section,
required_global[i]);
bm_settings_free(rv);
rv = NULL;
@@ -147,27 +145,27 @@ bm_settings_parse(const char *content, size_t content_len, bc_error_t **err)
}
for (size_t i = 0; default_settings[i].key != NULL; i++) {
- const char *value = bc_config_get_with_default(
+ const char *value = sb_config_get_with_default(
config, "settings", default_settings[i].key,
default_settings[i].default_value);
if (value != NULL) {
- bc_trie_insert(rv->settings, default_settings[i].key,
- bc_strdup(value));
+ sb_trie_insert(rv->settings, default_settings[i].key,
+ sb_strdup(value));
}
}
- rv->posts = bc_config_get_list(config, "posts");
- rv->pages = bc_config_get_list(config, "pages");
- rv->tags = bc_config_get_list(config, "tags");
+ rv->posts = sb_config_get_list(config, "posts");
+ rv->pages = sb_config_get_list(config, "pages");
+ rv->tags = sb_config_get_list(config, "tags");
// this is for backward compatibility too.
- rv->copy = bc_config_get_list(config, "copy");
+ rv->copy = sb_config_get_list(config, "copy");
if (rv->copy == NULL)
- rv->copy = bc_config_get_list(config, "copy_files");
+ rv->copy = sb_config_get_list(config, "copy_files");
cleanup:
- bc_config_free(config);
+ sb_config_free(config);
return rv;
}
@@ -178,11 +176,11 @@ bm_settings_free(bm_settings_t *settings)
{
if (settings == NULL)
return;
- bc_trie_free(settings->global);
- bc_trie_free(settings->settings);
- bc_strv_free(settings->posts);
- bc_strv_free(settings->pages);
- bc_strv_free(settings->copy);
- bc_strv_free(settings->tags);
+ sb_trie_free(settings->global);
+ sb_trie_free(settings->settings);
+ sb_strv_free(settings->posts);
+ sb_strv_free(settings->pages);
+ sb_strv_free(settings->copy);
+ sb_strv_free(settings->tags);
free(settings);
}
diff --git a/src/blogc-make/settings.h b/src/blogc-make/settings.h
index 69fdbb6..a147df6 100644
--- a/src/blogc-make/settings.h
+++ b/src/blogc-make/settings.h
@@ -10,12 +10,11 @@
#define _MAKE_SETTINGS_H
#include <stddef.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
typedef struct {
- bc_trie_t *global;
- bc_trie_t *settings;
+ sb_trie_t *global;
+ sb_trie_t *settings;
char **posts;
char **pages;
char **copy;
@@ -23,7 +22,7 @@ typedef struct {
} bm_settings_t;
bm_settings_t* bm_settings_parse(const char *content, size_t content_len,
- bc_error_t **err);
+ sb_error_t **err);
void bm_settings_free(bm_settings_t *settings);
#endif /* _MAKE_SETTINGS_H */
diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c
index 8f69e44..f2bd777 100644
--- a/src/blogc-make/utils.c
+++ b/src/blogc-make/utils.c
@@ -11,8 +11,9 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
+#include "utils.h"
#ifndef PATH_MAX
#define PATH_MAX 4096
@@ -30,42 +31,42 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
bool is_index = have_fname && have_ext && (
(0 == strcmp(fname, "index")) && ext[0] == '/') && !have_prefix;
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
if (dir != NULL && (have_prefix || have_fname || have_ext))
- bc_string_append(rv, dir);
+ sb_string_append(rv, dir);
if ((have_prefix || have_fname || have_ext_noslash) && !is_index)
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (have_prefix)
- bc_string_append(rv, prefix);
+ sb_string_append(rv, prefix);
// with fname we have posts, pages and tags
if (have_fname) {
if (have_prefix && have_fname && fname[0] != '/')
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (!is_index)
- bc_string_append(rv, fname);
+ sb_string_append(rv, fname);
}
// no fname means index
else if (have_ext_noslash) {
if (have_fname)
- bc_string_append_c(rv, '/');
+ sb_string_append_c(rv, '/');
if (!have_prefix)
- bc_string_append(rv, "index");
+ sb_string_append(rv, "index");
}
if (have_ext)
- bc_string_append(rv, ext);
+ sb_string_append(rv, ext);
if (rv->len == 0) {
- bc_string_free(rv, true);
+ sb_string_free(rv, true);
return NULL;
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -77,52 +78,52 @@ bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
bool have_fname = fname != NULL && fname[0] != '\0';
bool have_prefix2 = prefix2 != NULL && prefix2[0] != '\0';
- bc_string_t *p = bc_string_new();
+ sb_string_t *p = sb_string_new();
if (have_prefix)
- bc_string_append(p, prefix);
+ sb_string_append(p, prefix);
if (have_prefix && (have_fname || have_prefix2))
- bc_string_append_c(p, '/');
+ sb_string_append_c(p, '/');
if (have_fname)
- bc_string_append(p, fname);
+ sb_string_append(p, fname);
if (have_fname && have_prefix2)
- bc_string_append_c(p, '/');
+ sb_string_append_c(p, '/');
if (have_prefix2)
- bc_string_append(p, prefix2);
+ sb_string_append(p, prefix2);
char *rv = bm_generate_filename(dir, p->str, fname2, ext);
- bc_string_free(p, true);
+ sb_string_free(p, true);
return rv;
}
char*
-bm_abspath(const char *path, bc_error_t **err)
+bm_abspath(const char *path, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
if (path[0] == '/') {
- return bc_strdup(path);
+ return sb_strdup(path);
}
char cwd[PATH_MAX];
if (NULL == getcwd(cwd, sizeof(cwd))) {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
- "Failed to detect absolute path (%s): %s", path, strerror(errno));
+ *err = sb_strerror_new_printf(
+ "utils: Failed to detect absolute path (%s): %s", path, strerror(errno));
return NULL;
}
if (cwd[0] != '/') {
- *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS,
- "Failed to get current working directory: %s", cwd);
+ *err = sb_strerror_new_printf(
+ "utils: Failed to get current working directory: %s", cwd);
return NULL;
}
- return bc_strdup_printf("%s/%s", cwd, path);
+ return sb_strdup_printf("%s/%s", cwd, path);
}
diff --git a/src/blogc-make/utils.h b/src/blogc-make/utils.h
index cbcfc0e..f17d6fe 100644
--- a/src/blogc-make/utils.h
+++ b/src/blogc-make/utils.h
@@ -9,12 +9,12 @@
#ifndef _MAKE_UTILS_H
#define _MAKE_UTILS_H
-#include "../common/error.h"
+#include <squareball.h>
char* bm_generate_filename(const char *dir, const char *prefix, const char *fname,
const char *ext);
char* bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
const char *prefix2, const char *fname2, const char *ext);
-char* bm_abspath(const char *path, bc_error_t **err);
+char* bm_abspath(const char *path, sb_error_t **err);
#endif /* _MAKE_UTILS_H */
diff --git a/src/blogc-runserver/httpd-utils.c b/src/blogc-runserver/httpd-utils.c
index 9d374ae..a920556 100644
--- a/src/blogc-runserver/httpd-utils.c
+++ b/src/blogc-runserver/httpd-utils.c
@@ -9,14 +9,15 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "httpd-utils.h"
char*
br_readline(int socket)
{
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
char buffer[READLINE_BUFFER_SIZE];
ssize_t len;
bool end = false;
@@ -30,7 +31,7 @@ br_readline(int socket)
end = true;
break;
}
- bc_string_append_c(rv, buffer[i]);
+ sb_string_append_c(rv, buffer[i]);
}
}
if (len < READLINE_BUFFER_SIZE) {
@@ -38,7 +39,7 @@ br_readline(int socket)
}
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -58,7 +59,7 @@ br_hextoi(const char c)
char*
br_urldecode(const char *str)
{
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
for (size_t i = 0; i < strlen(str); i++) {
switch (str[i]) {
@@ -67,22 +68,22 @@ br_urldecode(const char *str)
int p1 = br_hextoi(str[i + 1]) * 16;
int p2 = br_hextoi(str[i + 2]);
if (p1 >= 0 && p2 >= 0) {
- bc_string_append_c(rv, p1 + p2);
+ sb_string_append_c(rv, p1 + p2);
i += 2;
continue;
}
}
- bc_string_append_c(rv, '%');
+ sb_string_append_c(rv, '%');
break;
case '+':
- bc_string_append_c(rv, ' ');
+ sb_string_append_c(rv, ' ');
break;
default:
- bc_string_append_c(rv, str[i]);
+ sb_string_append_c(rv, str[i]);
}
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c
index 513c4b0..a78b888 100644
--- a/src/blogc-runserver/httpd.c
+++ b/src/blogc-runserver/httpd.c
@@ -19,11 +19,11 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "mime.h"
#include "httpd-utils.h"
+#include "httpd.h"
#define LISTEN_BACKLOG 100
@@ -43,7 +43,7 @@ typedef struct {
static void
error(int socket, int status_code, const char *error)
{
- char *str = bc_strdup_printf(
+ char *str = sb_strdup_printf(
"HTTP/1.0 %d %s\r\n"
"Content-Type: text/html\r\n"
"Content-Length: %zu\r\n"
@@ -74,8 +74,8 @@ handle_request(void *arg)
unsigned short status_code = 200;
- char **pieces = bc_str_split(conn_line, ' ', 3);
- if (bc_strv_length(pieces) != 3) {
+ char **pieces = sb_str_split(conn_line, ' ', 3);
+ if (sb_strv_length(pieces) != 3) {
status_code = 400;
error(client_socket, 400, "Bad Request");
goto point1;
@@ -87,9 +87,9 @@ handle_request(void *arg)
goto point1;
}
- char **pieces2 = bc_str_split(pieces[1], '?', 2);
+ char **pieces2 = sb_str_split(pieces[1], '?', 2);
char *path = br_urldecode(pieces2[0]);
- bc_strv_free(pieces2);
+ sb_strv_free(pieces2);
if (path == NULL) {
status_code = 400;
@@ -97,7 +97,7 @@ handle_request(void *arg)
goto point2;
}
- char *abs_path = bc_strdup_printf("%s/%s", docroot, path);
+ char *abs_path = sb_strdup_printf("%s/%s", docroot, path);
char *real_path = realpath(abs_path, NULL);
free(abs_path);
@@ -161,7 +161,7 @@ handle_request(void *arg)
if (add_slash) {
// production webservers usually returns 301 in such cases, but 302 is
// better for development/testing.
- char *tmp = bc_strdup_printf(
+ char *tmp = sb_strdup_printf(
"HTTP/1.0 302 Found\r\n"
"Location: %s/\r\n"
"Content-Length: 0\r\n"
@@ -177,16 +177,16 @@ handle_request(void *arg)
}
size_t len;
- bc_error_t *err = NULL;
- char* contents = bc_file_get_contents(real_path, false, &len, &err);
+ sb_error_t *err = NULL;
+ char* contents = sb_file_get_contents(real_path, &len, &err);
if (err != NULL) {
status_code = 500;
error(client_socket, 500, "Internal Server Error");
- bc_error_free(err);
+ sb_error_free(err);
goto point4;
}
- char *out = bc_strdup_printf(
+ char *out = sb_strdup_printf(
"HTTP/1.0 200 OK\r\n"
"Content-Type: %s\r\n"
"Content-Length: %zu\r\n"
@@ -213,7 +213,7 @@ point1:
fprintf(stderr, "[Thread-%zu] %s - - \"%s\" %d\n", thread_id + 1,
ip, conn_line, status_code);
free(conn_line);
- bc_strv_free(pieces);
+ sb_strv_free(pieces);
point0:
free(ip);
close(client_socket);
@@ -233,7 +233,7 @@ br_httpd_get_ip(int af, const struct sockaddr *addr)
struct sockaddr_in *a = (struct sockaddr_in*) addr;
inet_ntop(af, &(a->sin_addr), host, INET6_ADDRSTRLEN);
}
- return bc_strdup(host);
+ return sb_strdup(host);
}
diff --git a/src/blogc-runserver/main.c b/src/blogc-runserver/main.c
index 1c5be29..b108137 100644
--- a/src/blogc-runserver/main.c
+++ b/src/blogc-runserver/main.c
@@ -13,7 +13,8 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "httpd.h"
@@ -63,9 +64,9 @@ main(int argc, char **argv)
char *endptr;
char *tmp_host = getenv("BLOGC_RUNSERVER_DEFAULT_HOST");
- char *default_host = bc_strdup(tmp_host != NULL ? tmp_host : "127.0.0.1");
+ char *default_host = sb_strdup(tmp_host != NULL ? tmp_host : "127.0.0.1");
char *tmp_port = getenv("BLOGC_RUNSERVER_DEFAULT_PORT");
- char *default_port = bc_strdup(tmp_port != NULL ? tmp_port : "8080");
+ char *default_port = sb_strdup(tmp_port != NULL ? tmp_port : "8080");
size_t args = 0;
@@ -80,15 +81,15 @@ main(int argc, char **argv)
goto cleanup;
case 't':
if (argv[i][2] != '\0')
- host = bc_strdup(argv[i] + 2);
+ host = sb_strdup(argv[i] + 2);
else
- host = bc_strdup(argv[++i]);
+ host = sb_strdup(argv[++i]);
break;
case 'p':
if (argv[i][2] != '\0')
- port = bc_strdup(argv[i] + 2);
+ port = sb_strdup(argv[i] + 2);
else
- port = bc_strdup(argv[++i]);
+ port = sb_strdup(argv[++i]);
break;
case 'm':
if (argv[i][2] != '\0')
@@ -117,7 +118,7 @@ main(int argc, char **argv)
goto cleanup;
}
args++;
- docroot = bc_strdup(argv[i]);
+ docroot = sb_strdup(argv[i]);
}
}
diff --git a/src/blogc-runserver/mime.c b/src/blogc-runserver/mime.c
index 636c496..a6228cf 100644
--- a/src/blogc-runserver/mime.c
+++ b/src/blogc-runserver/mime.c
@@ -9,8 +9,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "httpd-utils.h"
+#include "mime.h"
// mime types with index should be in the begin of the list. first NULL
@@ -153,7 +155,7 @@ br_mime_guess_index(const char *path)
{
char *found = NULL;
for (size_t i = 0; content_types[i].index != NULL; i++) {
- char *f = bc_strdup_printf("%s/%s", path, content_types[i].index);
+ char *f = sb_strdup_printf("%s/%s", path, content_types[i].index);
if (0 == access(f, F_OK)) {
found = f;
break;
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c
index 047af4b..829638e 100644
--- a/src/blogc/content-parser.c
+++ b/src/blogc/content-parser.c
@@ -9,9 +9,9 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "content-parser.h"
-#include "../common/utils.h"
// this is a half ass implementation of a markdown-like syntax. bugs are
// expected. feel free to improve the parser and add new features.
@@ -22,7 +22,7 @@ blogc_slugify(const char *str)
{
if (str == NULL)
return NULL;
- char *new_str = bc_strdup(str);
+ char *new_str = sb_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(bc_string_t *str, char c)
+htmlentities_append(sb_string_t *str, char c)
{
const char *e = htmlentities(c);
if (e == NULL)
- bc_string_append_c(str, c);
+ sb_string_append_c(str, c);
else
- bc_string_append(str, e);
+ sb_string_append(str, e);
}
@@ -75,10 +75,10 @@ blogc_htmlentities(const char *str)
{
if (str == NULL)
return NULL;
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
for (size_t i = 0; str[i] != '\0'; i++)
htmlentities_append(rv, str[i]);
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -87,7 +87,7 @@ blogc_fix_description(const char *paragraph)
{
if (paragraph == NULL)
return NULL;
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_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 = bc_strndup(paragraph + start, current - start);
- bc_string_append(rv, bc_str_strip(tmp));
+ tmp = sb_strndup(paragraph + start, current - start);
+ sb_string_append(rv, sb_str_strip(tmp));
free(tmp);
tmp = NULL;
if (!last)
- bc_string_append_c(rv, ' ');
+ sb_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(bc_str_strip(rv->str));
- bc_string_free(rv, true);
+ tmp = blogc_htmlentities(sb_str_strip(rv->str));
+ sb_string_free(rv, true);
return tmp;
}
@@ -190,7 +190,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
size_t start_link = 0;
char *link1 = NULL;
- bc_string_t *rv = bc_string_new();
+ sb_string_t *rv = sb_string_new();
blogc_content_parser_inline_state_t state = CONTENT_INLINE_START;
@@ -244,15 +244,15 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
state = CONTENT_INLINE_ASTERISK_DOUBLE;
break;
}
- tmp = bc_str_find(src + current, '*');
+ tmp = sb_str_find(src + current, '*');
if (tmp == NULL || ((tmp - src) >= src_len)) {
- bc_string_append_c(rv, '*');
+ sb_string_append_c(rv, '*');
state = CONTENT_INLINE_START;
continue;
}
tmp2 = blogc_content_parse_inline_internal(
src + current, (tmp - src) - current);
- bc_string_append_printf(rv, "<em>%s</em>", tmp2);
+ sb_string_append_printf(rv, "<em>%s</em>", tmp2);
current = tmp - src;
tmp = NULL;
free(tmp2);
@@ -263,21 +263,21 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
case CONTENT_INLINE_ASTERISK_DOUBLE:
tmp = src + current;
do {
- tmp = bc_str_find(tmp, '*');
+ tmp = sb_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)) {
- bc_string_append_c(rv, '*');
- bc_string_append_c(rv, '*');
+ sb_string_append_c(rv, '*');
+ sb_string_append_c(rv, '*');
state = CONTENT_INLINE_START;
continue;
}
tmp2 = blogc_content_parse_inline_internal(
src + current, (tmp - src) - current);
- bc_string_append_printf(rv, "<strong>%s</strong>", tmp2);
+ sb_string_append_printf(rv, "<strong>%s</strong>", tmp2);
current = tmp - src + 1;
tmp = NULL;
free(tmp2);
@@ -290,15 +290,15 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
state = CONTENT_INLINE_UNDERSCORE_DOUBLE;
break;
}
- tmp = bc_str_find(src + current, '_');
+ tmp = sb_str_find(src + current, '_');
if (tmp == NULL || ((tmp - src) >= src_len)) {
- bc_string_append_c(rv, '_');
+ sb_string_append_c(rv, '_');
state = CONTENT_INLINE_START;
continue;
}
tmp2 = blogc_content_parse_inline_internal(
src + current, (tmp - src) - current);
- bc_string_append_printf(rv, "<em>%s</em>", tmp2);
+ sb_string_append_printf(rv, "<em>%s</em>", tmp2);
current = tmp - src;
tmp = NULL;
free(tmp2);
@@ -309,21 +309,21 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
case CONTENT_INLINE_UNDERSCORE_DOUBLE:
tmp = src + current;
do {
- tmp = bc_str_find(tmp, '_');
+ tmp = sb_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)) {
- bc_string_append_c(rv, '_');
- bc_string_append_c(rv, '_');
+ sb_string_append_c(rv, '_');
+ sb_string_append_c(rv, '_');
state = CONTENT_INLINE_START;
continue;
}
tmp2 = blogc_content_parse_inline_internal(
src + current, (tmp - src) - current);
- bc_string_append_printf(rv, "<strong>%s</strong>", tmp2);
+ sb_string_append_printf(rv, "<strong>%s</strong>", tmp2);
current = tmp - src + 1;
tmp = NULL;
free(tmp2);
@@ -336,19 +336,19 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
state = CONTENT_INLINE_BACKTICKS_DOUBLE;
break;
}
- tmp = bc_str_find(src + current, '`');
+ tmp = sb_str_find(src + current, '`');
if (tmp == NULL || ((tmp - src) >= src_len)) {
- bc_string_append_c(rv, '`');
+ sb_string_append_c(rv, '`');
state = CONTENT_INLINE_START;
continue;
}
- tmp3 = bc_strndup(src + current, (tmp - src) - current);
+ tmp3 = sb_strndup(src + current, (tmp - src) - current);
tmp2 = blogc_htmlentities(tmp3);
free(tmp3);
tmp3 = NULL;
- bc_string_append(rv, "<code>");
- bc_string_append(rv, tmp2);
- bc_string_append(rv, "</code>");
+ sb_string_append(rv, "<code>");
+ sb_string_append(rv, tmp2);
+ sb_string_append(rv, "</code>");
current = tmp - src;
tmp = NULL;
free(tmp2);
@@ -359,25 +359,25 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
case CONTENT_INLINE_BACKTICKS_DOUBLE:
tmp = src + current;
do {
- tmp = bc_str_find(tmp, '`');
+ tmp = sb_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)) {
- bc_string_append_c(rv, '`');
- bc_string_append_c(rv, '`');
+ sb_string_append_c(rv, '`');
+ sb_string_append_c(rv, '`');
state = CONTENT_INLINE_START;
continue;
}
- tmp3 = bc_strndup(src + current, (tmp - src) - current);
+ tmp3 = sb_strndup(src + current, (tmp - src) - current);
tmp2 = blogc_htmlentities(tmp3);
free(tmp3);
tmp3 = NULL;
- bc_string_append(rv, "<code>");
- bc_string_append(rv, tmp2);
- bc_string_append(rv, "</code>");
+ sb_string_append(rv, "<code>");
+ sb_string_append(rv, tmp2);
+ sb_string_append(rv, "</code>");
current = tmp - src + 1;
tmp = NULL;
free(tmp2);
@@ -398,24 +398,24 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
case CONTENT_INLINE_LINK_AUTO:
tmp = src + current;
do {
- tmp = bc_str_find(tmp, ']');
+ tmp = sb_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)) {
- bc_string_append_c(rv, '[');
- bc_string_append_c(rv, '[');
+ sb_string_append_c(rv, '[');
+ sb_string_append_c(rv, '[');
state = CONTENT_INLINE_START;
continue;
}
- 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>");
+ 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>");
current = tmp - src + 1;
tmp = NULL;
free(tmp2);
@@ -434,7 +434,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
}
if (c == ']') {
if (--count == 0) {
- link1 = bc_strndup(src + start_link, current - start_link);
+ link1 = sb_strndup(src + start_link, current - start_link);
state = CONTENT_INLINE_LINK_URL_START;
}
}
@@ -448,7 +448,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
start = current + 1;
break;
}
- bc_string_append_c(rv, '[');
+ sb_string_append_c(rv, '[');
state = CONTENT_INLINE_START;
current = start_link;
start_link = 0;
@@ -460,13 +460,13 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
break;
}
if (c == ')') {
- tmp2 = bc_strndup(src + start, current - start);
+ tmp2 = sb_strndup(src + start, current - start);
tmp3 = blogc_content_parse_inline(link1);
free(link1);
link1 = NULL;
- bc_string_append(rv, "<a href=\"");
- bc_string_append_escaped(rv, tmp2);
- bc_string_append_printf(rv, "\">%s</a>", tmp3);
+ sb_string_append(rv, "<a href=\"");
+ sb_string_append_escaped(rv, tmp2);
+ sb_string_append_printf(rv, "\">%s</a>", tmp3);
free(tmp2);
tmp2 = NULL;
free(tmp3);
@@ -483,7 +483,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
start_link = current + 1;
break;
}
- bc_string_append_c(rv, '!');
+ sb_string_append_c(rv, '!');
state = CONTENT_INLINE_START;
continue;
@@ -493,7 +493,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
break;
}
if (c == ']') {
- link1 = bc_strndup(src + start_link, current - start_link);
+ link1 = sb_strndup(src + start_link, current - start_link);
state = CONTENT_INLINE_IMAGE_URL_START;
}
break;
@@ -506,8 +506,8 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
start = current + 1;
break;
}
- bc_string_append_c(rv, '!');
- bc_string_append_c(rv, '[');
+ sb_string_append_c(rv, '!');
+ sb_string_append_c(rv, '[');
state = CONTENT_INLINE_START;
current = start_link;
start_link = 0;
@@ -519,12 +519,12 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
break;
}
if (c == ')') {
- 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, "\">");
+ 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, "\">");
free(tmp2);
tmp2 = NULL;
free(link1);
@@ -537,31 +537,31 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
case CONTENT_INLINE_ENDASH:
if (c == '-') {
if (is_last) {
- bc_string_append(rv, "&ndash;");
+ sb_string_append(rv, "&ndash;");
state = CONTENT_INLINE_START; // wat
break;
}
state = CONTENT_INLINE_EMDASH;
break;
}
- bc_string_append_c(rv, '-');
+ sb_string_append_c(rv, '-');
state = CONTENT_INLINE_START;
continue;
case CONTENT_INLINE_EMDASH:
if (c == '-') {
- bc_string_append(rv, "&mdash;");
+ sb_string_append(rv, "&mdash;");
state = CONTENT_INLINE_START;
break;
}
- bc_string_append(rv, "&ndash;");
+ sb_string_append(rv, "&ndash;");
state = CONTENT_INLINE_START;
continue;
case CONTENT_INLINE_LINE_BREAK_START:
if (c == ' ') {
if (is_last) {
- bc_string_append(rv, "<br />");
+ sb_string_append(rv, "<br />");
state = CONTENT_INLINE_START; // wat
break;
}
@@ -569,14 +569,14 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
state = CONTENT_INLINE_LINE_BREAK;
break;
}
- bc_string_append_c(rv, ' ');
+ sb_string_append_c(rv, ' ');
state = CONTENT_INLINE_START;
continue;
case CONTENT_INLINE_LINE_BREAK:
if (c == ' ') {
if (is_last) {
- bc_string_append(rv, "<br />");
+ sb_string_append(rv, "<br />");
state = CONTENT_INLINE_START; // wat
break;
}
@@ -584,12 +584,12 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
break;
}
if (c == '\n' || c == '\r') {
- bc_string_append_printf(rv, "<br />%c", c);
+ sb_string_append_printf(rv, "<br />%c", c);
state = CONTENT_INLINE_START;
break;
}
for (size_t i = 0; i < count; i++)
- bc_string_append_c(rv, ' ');
+ sb_string_append_c(rv, ' ');
state = CONTENT_INLINE_START;
continue;
}
@@ -604,14 +604,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:
- bc_string_append_c(rv, '!');
+ sb_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);
- bc_string_append_c(rv, '[');
- bc_string_append_escaped(rv, tmp2); // no need to free, as it wil be done below.
+ sb_string_append_c(rv, '[');
+ sb_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
@@ -636,7 +636,7 @@ blogc_content_parse_inline_internal(const char *src, size_t src_len)
free(tmp3);
free(link1);
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -704,11 +704,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
char d = '\0';
- bc_slist_t *lines = NULL;
- bc_slist_t *lines2 = NULL;
+ sb_slist_t *lines = NULL;
+ sb_slist_t *lines2 = NULL;
- bc_string_t *rv = bc_string_new();
- bc_string_t *tmp_str = NULL;
+ sb_string_t *rv = sb_string_new();
+ sb_string_t *tmp_str = NULL;
blogc_content_parser_state_t state = CONTENT_START_LINE;
@@ -835,16 +835,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = bc_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
if (first_header != NULL && *first_header == NULL)
*first_header = blogc_htmlentities(tmp);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
- bc_string_append_printf(rv, "<h%d>%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d>%s</h%d>%s",
header_level, parsed, header_level, line_ending);
else
- bc_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
header_level, slug, parsed, header_level,
line_ending);
free(slug);
@@ -868,8 +868,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_HTML_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp = bc_strndup(src + start, end - start);
- bc_string_append_printf(rv, "%s%s", tmp, line_ending);
+ tmp = sb_strndup(src + start, end - start);
+ sb_string_append_printf(rv, "%s%s", tmp, line_ending);
free(tmp);
tmp = NULL;
state = CONTENT_START_LINE;
@@ -882,7 +882,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_BLOCKQUOTE:
if (c == ' ' || c == '\t')
break;
- prefix = bc_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_BLOCKQUOTE_START;
break;
@@ -890,16 +890,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = bc_strndup(src + start2, end - start2);
- if (bc_str_starts_with(tmp, prefix)) {
- lines = bc_slist_append(lines, bc_strdup(tmp + strlen(prefix)));
+ tmp = sb_strndup(src + start2, end - start2);
+ if (sb_str_starts_with(tmp, prefix)) {
+ lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix)));
state = CONTENT_BLOCKQUOTE_END;
}
else {
state = CONTENT_PARAGRAPH;
free(prefix);
prefix = NULL;
- bc_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
if (is_last) {
free(tmp);
@@ -915,21 +915,21 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_BLOCKQUOTE_END:
if (c == '\n' || c == '\r' || is_last) {
- 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,
+ 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,
line_ending);
// do not propagate title and description to blockquote parsing,
// because we just want paragraphs from first level of
// content.
tmp = blogc_content_parse(tmp_str->str, NULL, NULL, NULL);
- bc_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
+ sb_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
tmp, line_ending);
free(tmp);
tmp = NULL;
- bc_string_free(tmp_str, true);
+ sb_string_free(tmp_str, true);
tmp_str = NULL;
- bc_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -945,7 +945,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_CODE:
if (c == ' ' || c == '\t')
break;
- prefix = bc_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_CODE_START;
break;
@@ -953,16 +953,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = bc_strndup(src + start2, end - start2);
- if (bc_str_starts_with(tmp, prefix)) {
- lines = bc_slist_append(lines, bc_strdup(tmp + strlen(prefix)));
+ tmp = sb_strndup(src + start2, end - start2);
+ if (sb_str_starts_with(tmp, prefix)) {
+ lines = sb_slist_append(lines, sb_strdup(tmp + strlen(prefix)));
state = CONTENT_CODE_END;
}
else {
state = CONTENT_PARAGRAPH;
free(prefix);
prefix = NULL;
- bc_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(tmp);
tmp = NULL;
@@ -978,18 +978,18 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_CODE_END:
if (c == '\n' || c == '\r' || is_last) {
- bc_string_append(rv, "<pre><code>");
- for (bc_slist_t *l = lines; l != NULL; l = l->next) {
+ sb_string_append(rv, "<pre><code>");
+ for (sb_slist_t *l = lines; l != NULL; l = l->next) {
char *tmp_line = blogc_htmlentities(l->data);
if (l->next == NULL)
- bc_string_append_printf(rv, "%s", tmp_line);
+ sb_string_append_printf(rv, "%s", tmp_line);
else
- bc_string_append_printf(rv, "%s%s", tmp_line,
+ sb_string_append_printf(rv, "%s%s", tmp_line,
line_ending);
free(tmp_line);
}
- bc_string_append_printf(rv, "</code></pre>%s", line_ending);
- bc_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</code></pre>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -1015,7 +1015,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
}
if (c == ' ' || c == '\t')
break;
- prefix = bc_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_UNORDERED_LIST_START;
break;
@@ -1036,7 +1036,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
break;
}
if (c == '\n' || c == '\r' || is_last) {
- bc_string_append_printf(rv, "<hr />%s", line_ending);
+ sb_string_append_printf(rv, "<hr />%s", line_ending);
state = CONTENT_START_LINE;
start = current;
d = '\0';
@@ -1049,30 +1049,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = bc_strndup(src + start2, end - start2);
- tmp2 = bc_strdup_printf("%-*s", strlen(prefix), "");
- if (bc_str_starts_with(tmp, prefix)) {
+ tmp = sb_strndup(src + start2, end - start2);
+ tmp2 = sb_strdup_printf("%-*s", strlen(prefix), "");
+ if (sb_str_starts_with(tmp, prefix)) {
if (lines2 != NULL) {
- tmp_str = bc_string_new();
- for (bc_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- bc_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- bc_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- bc_string_free(tmp_str, true);
- lines = bc_slist_append(lines, bc_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = bc_slist_append(lines2, bc_strdup(tmp + strlen(prefix)));
+ 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 if (sb_str_starts_with(tmp, tmp2)) {
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix)));
}
else {
state = CONTENT_PARAGRAPH_END;
@@ -1082,8 +1082,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
tmp2 = NULL;
free(prefix);
prefix = NULL;
- bc_slist_free_full(lines, free);
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
continue;
@@ -1102,28 +1102,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = bc_string_new();
- for (bc_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- bc_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- bc_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- bc_string_free(tmp_str, true);
- lines = bc_slist_append(lines, bc_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- 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,
+ 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,
line_ending);
- bc_string_append_printf(rv, "</ul>%s", line_ending);
- bc_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ul>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -1160,30 +1160,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = bc_strndup(src + start2, end - start2);
- tmp2 = bc_strdup_printf("%-*s", prefix_len, "");
+ tmp = sb_strndup(src + start2, end - start2);
+ tmp2 = sb_strdup_printf("%-*s", prefix_len, "");
if (blogc_is_ordered_list_item(tmp, prefix_len)) {
if (lines2 != NULL) {
- tmp_str = bc_string_new();
- for (bc_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- bc_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- bc_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- bc_string_free(tmp_str, true);
- lines = bc_slist_append(lines, bc_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = bc_slist_append(lines2, bc_strdup(tmp + prefix_len));
+ 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 if (sb_str_starts_with(tmp, tmp2)) {
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len));
}
else {
state = CONTENT_PARAGRAPH_END;
@@ -1193,8 +1193,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
tmp2 = NULL;
free(parsed);
parsed = NULL;
- bc_slist_free_full(lines, free);
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
continue;
@@ -1213,28 +1213,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = bc_string_new();
- for (bc_slist_t *l = lines2; l != NULL; l = l->next) {
+ tmp_str = sb_string_new();
+ for (sb_slist_t *l = lines2; l != NULL; l = l->next) {
if (l->next == NULL)
- bc_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- bc_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- bc_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- bc_string_free(tmp_str, true);
- lines = bc_slist_append(lines, bc_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- 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,
+ 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,
line_ending);
- bc_string_append_printf(rv, "</ol>%s", line_ending);
- bc_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ol>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -1258,11 +1258,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
case CONTENT_PARAGRAPH_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp = bc_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
if (description != NULL && *description == NULL)
*description = blogc_fix_description(tmp);
parsed = blogc_content_parse_inline(tmp);
- bc_string_append_printf(rv, "<p>%s</p>%s", parsed,
+ sb_string_append_printf(rv, "<p>%s</p>%s", parsed,
line_ending);
free(parsed);
parsed = NULL;
@@ -1280,5 +1280,5 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
current++;
}
- return bc_string_free(rv, false);
+ return sb_string_free(rv, false);
}
diff --git a/src/blogc/datetime-parser.c b/src/blogc/datetime-parser.c
index ddaf6ef..5cb6520 100644
--- a/src/blogc/datetime-parser.c
+++ b/src/blogc/datetime-parser.c
@@ -15,10 +15,9 @@
#endif /* HAVE_TIME_H */
#include <string.h>
+#include <squareball.h>
#include "datetime-parser.h"
-#include "../common/error.h"
-#include "../common/utils.h"
typedef enum {
@@ -47,16 +46,16 @@ typedef enum {
char*
blogc_convert_datetime(const char *orig, const char *format,
- bc_error_t **err)
+ sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
#ifndef HAVE_TIME_H
- *err = bc_error_new(BLOGC_WARNING_DATETIME_PARSER,
- "Your operating system does not supports the datetime functionalities "
- "used by blogc. Sorry.");
+ *err = sb_strerror_new(
+ "datetime: Your operating system does not supports the datetime "
+ "functionalities used by blogc. Sorry.");
return NULL;
#else
@@ -80,8 +79,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_YEAR;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of year. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of year. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -91,8 +90,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_THIRD_YEAR;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of year. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of year. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -102,8 +101,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FOURTH_YEAR;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid third digit of year. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid third digit of year. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -111,8 +110,8 @@ blogc_convert_datetime(const char *orig, const char *format,
if (c >= '0' && c <= '9') {
tmp += c - diff - 1900;
if (tmp < 0) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid year. Found %d, must be >= 1900.",
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid year. Found %d, must be >= 1900.",
tmp + 1900);
break;
}
@@ -120,8 +119,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_HYPHEN;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid fourth digit of year. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid fourth digit of year. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -131,8 +130,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_MONTH;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid separator between year and month. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid separator between year and month. "
"Found '%c', must be '-'.", c);
break;
@@ -142,8 +141,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_MONTH;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of month. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of month. "
"Found '%c', must be integer >= 0 and <= 1.", c);
break;
@@ -151,17 +150,17 @@ blogc_convert_datetime(const char *orig, const char *format,
if (c >= '0' && c <= '9') {
tmp += c - diff - 1;
if (tmp < 0 || tmp > 11) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid month. Found %d, must be >= 1 and <= 12.",
- tmp + 1);
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid month. "
+ "Found %d, must be >= 1 and <= 12.", tmp + 1);
break;
}
t.tm_mon = tmp;
state = DATETIME_SECOND_HYPHEN;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of month. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of month. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -171,8 +170,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_DAY;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid separator between month and day. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid separator between month and day. "
"Found '%c', must be '-'.", c);
break;
@@ -182,8 +181,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_DAY;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of day. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of day. "
"Found '%c', must be integer >= 0 and <= 3.", c);
break;
@@ -191,17 +190,17 @@ blogc_convert_datetime(const char *orig, const char *format,
if (c >= '0' && c <= '9') {
tmp += c - diff;
if (tmp < 1 || tmp > 31) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid day. Found %d, must be >= 1 and <= 31.",
- tmp);
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid day. "
+ "Found %d, must be >= 1 and <= 31.", tmp);
break;
}
t.tm_mday = tmp;
state = DATETIME_SPACE;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of day. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of day. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -211,8 +210,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_HOUR;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid separator between date and time. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid separator between date and time. "
"Found '%c', must be ' ' (empty space).", c);
break;
@@ -222,8 +221,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_HOUR;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of hours. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of hours. "
"Found '%c', must be integer >= 0 and <= 2.", c);
break;
@@ -231,17 +230,17 @@ blogc_convert_datetime(const char *orig, const char *format,
if (c >= '0' && c <= '9') {
tmp += c - diff;
if (tmp < 0 || tmp > 23) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid hours. Found %d, must be >= 0 and <= 23.",
- tmp);
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid hours. "
+ "Found %d, must be >= 0 and <= 23.", tmp);
break;
}
t.tm_hour = tmp;
state = DATETIME_FIRST_COLON;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of hours. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of hours. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -251,8 +250,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_MINUTE;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid separator between hours and minutes. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid separator between hours and minutes. "
"Found '%c', must be ':'.", c);
break;
@@ -262,8 +261,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_MINUTE;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of minutes. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of minutes. "
"Found '%c', must be integer >= 0 and <= 5.", c);
break;
@@ -274,17 +273,17 @@ blogc_convert_datetime(const char *orig, const char *format,
// this won't happen because we are restricting the digits
// to 00-59 already, but lets keep the code here for
// reference.
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid minutes. Found %d, must be >= 0 and <= 59.",
- tmp);
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid minutes. "
+ "Found %d, must be >= 0 and <= 59.", tmp);
break;
}
t.tm_min = tmp;
state = DATETIME_SECOND_COLON;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of minutes. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of minutes. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -294,8 +293,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_FIRST_SECOND;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid separator between minutes and seconds. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid separator between minutes and seconds. "
"Found '%c', must be ':'.", c);
break;
@@ -305,8 +304,8 @@ blogc_convert_datetime(const char *orig, const char *format,
state = DATETIME_SECOND_SECOND;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid first digit of seconds. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid first digit of seconds. "
"Found '%c', must be integer >= 0 and <= 6.", c);
break;
@@ -314,17 +313,17 @@ blogc_convert_datetime(const char *orig, const char *format,
if (c >= '0' && c <= '9') {
tmp += c - diff;
if (tmp < 0 || tmp > 60) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid seconds. Found %d, must be >= 0 and <= 60.",
- tmp);
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid seconds. "
+ "Found %d, must be >= 0 and <= 60.", tmp);
break;
}
t.tm_sec = tmp;
state = DATETIME_DONE;
break;
}
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid second digit of seconds. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid second digit of seconds. "
"Found '%c', must be integer >= 0 and <= 9.", c);
break;
@@ -355,8 +354,8 @@ blogc_convert_datetime(const char *orig, const char *format,
case DATETIME_SECOND_MINUTE:
case DATETIME_FIRST_SECOND:
case DATETIME_SECOND_SECOND:
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Invalid datetime string. "
+ *err = sb_strerror_new_printf(
+ "datetime: Invalid datetime string. "
"Found '%s', formats allowed are: 'yyyy-mm-dd hh:mm:ss', "
"'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and 'yyyy-mm-dd'.",
orig);
@@ -374,13 +373,13 @@ blogc_convert_datetime(const char *orig, const char *format,
char buf[1024];
if (0 == strftime(buf, sizeof(buf), format, &t)) {
- *err = bc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER,
- "Failed to format DATE variable, FORMAT is too long: %s",
+ *err = sb_strerror_new_printf(
+ "datetime: Failed to format DATE variable, FORMAT is too long: %s",
format);
return NULL;
}
- return bc_strdup(buf);
+ return sb_strdup(buf);
#endif
}
diff --git a/src/blogc/datetime-parser.h b/src/blogc/datetime-parser.h
index 8617ad0..25d03f2 100644
--- a/src/blogc/datetime-parser.h
+++ b/src/blogc/datetime-parser.h
@@ -9,9 +9,9 @@
#ifndef _DATETIME_H
#define _DATETIME_H
-#include "../common/error.h"
+#include <squareball.h>
char* blogc_convert_datetime(const char *orig, const char *format,
- bc_error_t **err);
+ sb_error_t **err);
#endif /* _DATETIME_H */
diff --git a/src/blogc/debug.c b/src/blogc/debug.c
index 11e7973..851d4cb 100644
--- a/src/blogc/debug.c
+++ b/src/blogc/debug.c
@@ -7,9 +7,9 @@
*/
#include <stdio.h>
+#include <squareball.h>
#include "template-parser.h"
-#include "../common/utils.h"
#include "debug.h"
@@ -34,9 +34,9 @@ get_operator(blogc_template_operator_t op)
void
-blogc_debug_template(bc_slist_t *ast)
+blogc_debug_template(sb_slist_t *ast)
{
- for (bc_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) {
blogc_template_node_t *data = tmp->data;
fprintf(stderr, "DEBUG: <TEMPLATE ");
switch (data->type) {
diff --git a/src/blogc/debug.h b/src/blogc/debug.h
index 6138a91..8bff4cf 100644
--- a/src/blogc/debug.h
+++ b/src/blogc/debug.h
@@ -9,8 +9,8 @@
#ifndef ___DEBUG_H
#define ___DEBUG_H
-#include "../common/utils.h"
+#include <squareball.h>
-void blogc_debug_template(bc_slist_t *ast);
+void blogc_debug_template(sb_slist_t *ast);
#endif /* ___DEBUG_H */
diff --git a/src/blogc/funcvars.c b/src/blogc/funcvars.c
index 6f0700b..358e3b4 100644
--- a/src/blogc/funcvars.c
+++ b/src/blogc/funcvars.c
@@ -9,11 +9,11 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
-#include "funcvars.h"
#include "rusage.h"
#include "sysinfo.h"
-#include "../common/utils.h"
+#include "funcvars.h"
static const struct func_map {
@@ -41,14 +41,14 @@ static const struct func_map {
void
-blogc_funcvars_eval(bc_trie_t *global, const char *name)
+blogc_funcvars_eval(sb_trie_t *global, const char *name)
{
if (global == NULL || name == NULL)
return;
// protect against evaluating the same function twice in the same global
// context
- if (NULL != bc_trie_lookup(global, name))
+ if (NULL != sb_trie_lookup(global, name))
return;
for (size_t i = 0; funcs[i].variable != NULL; i++) {
diff --git a/src/blogc/funcvars.h b/src/blogc/funcvars.h
index aae1bc3..3768f81 100644
--- a/src/blogc/funcvars.h
+++ b/src/blogc/funcvars.h
@@ -10,10 +10,10 @@
#define ___FUNCVARS_H
#include <stdbool.h>
-#include "../common/utils.h"
+#include <squareball.h>
-typedef void (*blogc_funcvars_func_t) (bc_trie_t*);
+typedef void (*blogc_funcvars_func_t) (sb_trie_t*);
-void blogc_funcvars_eval(bc_trie_t *global, const char *name);
+void blogc_funcvars_eval(sb_trie_t *global, const char *name);
#endif /* ___FUNCVARS_H */
diff --git a/src/blogc/loader.c b/src/blogc/loader.c
index d620988..3a1b8fc 100644
--- a/src/blogc/loader.c
+++ b/src/blogc/loader.c
@@ -12,14 +12,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
+
#include "datetime-parser.h"
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
-#include "../common/sort.h"
char*
@@ -31,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;
@@ -52,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);
@@ -102,8 +100,8 @@ blogc_source_parse_from_file(const char *f, bc_error_t **err)
static int
sort_source(const void *a, const void *b)
{
- const char *ca = bc_trie_lookup((bc_trie_t*) a, "c");
- const char *cb = bc_trie_lookup((bc_trie_t*) b, "c");
+ const char *ca = sb_trie_lookup((sb_trie_t*) a, "c");
+ const char *cb = sb_trie_lookup((sb_trie_t*) b, "c");
if (ca == NULL || cb == NULL) {
return 0; // wat
@@ -120,88 +118,88 @@ sort_source_reverse(const void *a, const void *b)
}
-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 sort = bc_str_to_bool(bc_trie_lookup(conf, "FILTER_SORT"));
+ bool sort = sb_str_to_bool(sb_trie_lookup(conf, "FILTER_SORT"));
- bc_slist_t* sources = NULL;
- bc_error_t *tmp_err = NULL;
+ sb_slist_t* sources = NULL;
+ sb_error_t *tmp_err = NULL;
size_t with_date = 0;
- for (bc_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = l; 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,
- "An error occurred while parsing source file: %s\n\n%s",
- f, tmp_err->msg);
- bc_error_free(tmp_err);
- bc_slist_free_full(sources, (bc_free_func_t) bc_trie_free);
+ *err = sb_strerror_new_printf(
+ "loader: An error occurred while parsing source file: %s\n> %s",
+ f, sb_error_to_string(tmp_err));
+ sb_error_free(tmp_err);
+ sb_slist_free_full(sources, (sb_free_func_t) sb_trie_free);
return NULL;
}
- const char *date = bc_trie_lookup(s, "DATE");
+ const char *date = sb_trie_lookup(s, "DATE");
if (date != NULL) {
with_date++;
}
if (sort) {
if (date == NULL) {
- *err = bc_error_new_printf(BLOGC_ERROR_LOADER,
- "'FILTER_SORT' requires that 'DATE' variable is set for "
- "every source file: %s", f);
- bc_trie_free(s);
- bc_slist_free_full(sources, (bc_free_func_t) bc_trie_free);
+ *err = sb_strerror_new_printf(
+ "loader: 'FILTER_SORT' requires that 'DATE' variable is "
+ "set for every source file: %s", f);
+ sb_trie_free(s);
+ sb_slist_free_full(sources, (sb_free_func_t) sb_trie_free);
return NULL;
}
char *timestamp = blogc_convert_datetime(date, "%s", &tmp_err);
if (timestamp == NULL) {
- *err = bc_error_new_printf(BLOGC_ERROR_LOADER,
- "An error occurred while parsing 'DATE' variable: %s"
- "\n\n%s", f, tmp_err->msg);
- bc_error_free(tmp_err);
- bc_trie_free(s);
- bc_slist_free_full(sources, (bc_free_func_t) bc_trie_free);
+ *err = sb_strerror_new_printf(
+ "loader: An error occurred while parsing 'DATE' variable: "
+ "%s\n> %s", f, sb_error_to_string(tmp_err));
+ sb_error_free(tmp_err);
+ sb_trie_free(s);
+ sb_slist_free_full(sources, (sb_free_func_t) sb_trie_free);
return NULL;
}
- bc_trie_insert(s, "c", timestamp);
+ sb_trie_insert(s, "c", timestamp);
}
- sources = bc_slist_append(sources, s);
+ sources = sb_slist_append(sources, s);
}
- if (with_date > 0 && with_date < bc_slist_length(l)) {
- *err = bc_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.");
- bc_slist_free_full(sources, (bc_free_func_t) bc_trie_free);
+ if (with_date > 0 && with_date < sb_slist_length(l)) {
+ *err = sb_strerror_new(
+ "loader: 'DATE' variable provided for at least one source file, "
+ "but not for all source files. It must be provided for all files.");
+ sb_slist_free_full(sources, (sb_free_func_t) sb_trie_free);
return NULL;
}
- bool reverse = bc_str_to_bool(bc_trie_lookup(conf, "FILTER_REVERSE"));
+ bool reverse = sb_str_to_bool(sb_trie_lookup(conf, "FILTER_REVERSE"));
if (sort) {
- sources = bc_slist_sort(sources,
- (bc_sort_func_t) (reverse ? sort_source_reverse : sort_source));
+ sources = sb_slist_sort(sources,
+ (sb_sort_func_t) (reverse ? sort_source_reverse : sort_source));
}
else if (reverse) {
- bc_slist_t *tmp_sources = NULL;
- for (bc_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
- tmp_sources = bc_slist_prepend(tmp_sources, tmp->data);
+ sb_slist_t *tmp_sources = NULL;
+ for (sb_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
+ tmp_sources = sb_slist_prepend(tmp_sources, tmp->data);
}
- bc_slist_t *tmp = sources;
+ sb_slist_t *tmp = sources;
sources = tmp_sources;
- bc_slist_free(tmp);
+ sb_slist_free(tmp);
}
- 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;
@@ -227,17 +225,17 @@ 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;
- bc_slist_t *rv = NULL;
- for (bc_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
- bc_trie_t *s = tmp->data;
+ sb_slist_t *rv = NULL;
+ for (sb_slist_t *tmp = sources; tmp != NULL; tmp = tmp->next) {
+ sb_trie_t *s = tmp->data;
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')
@@ -245,58 +243,58 @@ 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++;
}
- rv = bc_slist_append(rv, s);
+ rv = sb_slist_append(rv, s);
}
- bc_slist_free(sources);
+ sb_slist_free(sources);
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;
diff --git a/src/blogc/loader.h b/src/blogc/loader.h
index 66da7d0..89de4db 100644
--- a/src/blogc/loader.h
+++ b/src/blogc/loader.h
@@ -9,13 +9,12 @@
#ifndef _LOADER_H
#define _LOADER_H
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
char* blogc_get_filename(const char *f);
-bc_slist_t* blogc_template_parse_from_file(const char *f, bc_error_t **err);
-bc_trie_t* 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_template_parse_from_file(const char *f, sb_error_t **err);
+sb_trie_t* blogc_source_parse_from_file(const char *f, sb_error_t **err);
+sb_slist_t* blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l,
+ sb_error_t **err);
#endif /* _LOADER_H */
diff --git a/src/blogc/main.c b/src/blogc/main.c
index 2f93d18..a12fa90 100644
--- a/src/blogc/main.c
+++ b/src/blogc/main.c
@@ -27,14 +27,12 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "debug.h"
#include "template-parser.h"
#include "loader.h"
#include "renderer.h"
-#include "../common/error.h"
-#include "../common/utf8.h"
-#include "../common/utils.h"
#ifdef MAKE_EMBEDDED
extern int bm_main(int argc, char **argv);
@@ -94,7 +92,7 @@ blogc_print_usage(void)
static void
blogc_mkdir_recursive(const char *filename)
{
- char *fname = bc_strdup(filename);
+ char *fname = sb_strdup(filename);
for (char *tmp = fname; *tmp != '\0'; tmp++) {
if (*tmp != '/' && *tmp != '\\')
continue;
@@ -126,8 +124,8 @@ blogc_mkdir_recursive(const char *filename)
}
-static bc_slist_t*
-blogc_read_stdin_to_list(bc_slist_t *l)
+static sb_slist_t*
+blogc_read_stdin_to_list(sb_slist_t *l)
{
char buffer[4096];
while (NULL != fgets(buffer, 4096, stdin)) {
@@ -142,7 +140,7 @@ blogc_read_stdin_to_list(bc_slist_t *l)
buffer[len - 1] = '\0';
if (strlen(buffer) == 0)
continue;
- l = bc_slist_append(l, bc_strdup(buffer));
+ l = sb_slist_append(l, sb_strdup(buffer));
}
return l;
}
@@ -168,10 +166,10 @@ main(int argc, char **argv)
char *tmp = NULL;
char **pieces = NULL;
- bc_slist_t *sources = NULL;
- bc_trie_t *listing_entry_source = NULL;
- bc_trie_t *config = bc_trie_new(free);
- bc_trie_insert(config, "BLOGC_VERSION", bc_strdup(PACKAGE_VERSION));
+ sb_slist_t *sources = NULL;
+ sb_trie_t *listing_entry_source = NULL;
+ sb_trie_t *config = sb_trie_new(free);
+ sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION));
for (size_t i = 1; i < argc; i++) {
tmp = NULL;
@@ -194,27 +192,27 @@ main(int argc, char **argv)
break;
case 'e':
if (argv[i][2] != '\0')
- listing_entry = bc_strdup(argv[i] + 2);
+ listing_entry = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- listing_entry = bc_strdup(argv[++i]);
+ listing_entry = sb_strdup(argv[++i]);
break;
case 't':
if (argv[i][2] != '\0')
- template = bc_strdup(argv[i] + 2);
+ template = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- template = bc_strdup(argv[++i]);
+ template = sb_strdup(argv[++i]);
break;
case 'o':
if (argv[i][2] != '\0')
- output = bc_strdup(argv[i] + 2);
+ output = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- output = bc_strdup(argv[++i]);
+ output = sb_strdup(argv[++i]);
break;
case 'p':
if (argv[i][2] != '\0')
- print = bc_strdup(argv[i] + 2);
+ print = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- print = bc_strdup(argv[++i]);
+ print = sb_strdup(argv[++i]);
break;
case 'D':
if (argv[i][2] != '\0')
@@ -222,16 +220,16 @@ main(int argc, char **argv)
else if (i + 1 < argc)
tmp = argv[++i];
if (tmp != NULL) {
- if (!bc_utf8_validate((uint8_t*) tmp, strlen(tmp))) {
+ if (!sb_utf8_validate((uint8_t*) tmp, strlen(tmp))) {
fprintf(stderr, "blogc: error: invalid value for "
"-D (must be valid UTF-8 string): %s\n", tmp);
goto cleanup;
}
- pieces = bc_str_split(tmp, '=', 2);
- if (bc_strv_length(pieces) != 2) {
+ pieces = sb_str_split(tmp, '=', 2);
+ if (sb_strv_length(pieces) != 2) {
fprintf(stderr, "blogc: error: invalid value for "
"-D (must have an '='): %s\n", tmp);
- bc_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 1;
goto cleanup;
}
@@ -242,13 +240,13 @@ main(int argc, char **argv)
fprintf(stderr, "blogc: error: invalid value "
"for -D (configuration key must be uppercase "
"with '_'): %s\n", pieces[0]);
- bc_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 1;
goto cleanup;
}
}
- bc_trie_insert(config, pieces[0], bc_strdup(pieces[1]));
- bc_strv_free(pieces);
+ sb_trie_insert(config, pieces[0], sb_strdup(pieces[1]));
+ sb_strv_free(pieces);
pieces = NULL;
}
break;
@@ -266,7 +264,7 @@ main(int argc, char **argv)
}
}
else {
- sources = bc_slist_append(sources, bc_strdup(argv[i]));
+ sources = sb_slist_append(sources, sb_strdup(argv[i]));
}
#ifdef MAKE_EMBEDDED
@@ -281,14 +279,14 @@ main(int argc, char **argv)
if (input_stdin)
sources = blogc_read_stdin_to_list(sources);
- if (!listing && bc_slist_length(sources) == 0) {
+ if (!listing && sb_slist_length(sources) == 0) {
blogc_print_usage();
fprintf(stderr, "blogc: error: one source file is required\n");
rv = 1;
goto cleanup;
}
- if (!listing && bc_slist_length(sources) > 1) {
+ if (!listing && sb_slist_length(sources) > 1) {
blogc_print_usage();
fprintf(stderr, "blogc: error: only one source file should be provided, "
"if running without '-l'\n");
@@ -296,11 +294,11 @@ main(int argc, char **argv)
goto cleanup;
}
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
- bc_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
+ sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
if (err != NULL) {
- bc_error_print(err, "blogc");
+ fprintf(stderr, "blogc: error: %s\n", sb_error_to_string(err));
rv = 1;
goto cleanup2;
}
@@ -308,14 +306,14 @@ main(int argc, char **argv)
if (listing && listing_entry != NULL) {
listing_entry_source = blogc_source_parse_from_file(listing_entry, &err);
if (err != NULL) {
- bc_error_print(err, "blogc");
+ fprintf(stderr, "blogc: error: %s\n", sb_error_to_string(err));
rv = 1;
goto cleanup2;
}
}
if (print != NULL) {
- bc_trie_t *local = NULL;
+ sb_trie_t *local = NULL;
if (!listing && s != NULL) {
local = s->data;
}
@@ -339,9 +337,9 @@ main(int argc, char **argv)
goto cleanup2;
}
- bc_slist_t* l = blogc_template_parse_from_file(template, &err);
+ sb_slist_t* l = blogc_template_parse_from_file(template, &err);
if (err != NULL) {
- bc_error_print(err, "blogc");
+ fprintf(stderr, "blogc: error: %s\n", sb_error_to_string(err));
rv = 1;
goto cleanup3;
}
@@ -376,15 +374,15 @@ cleanup4:
cleanup3:
blogc_template_free_ast(l);
cleanup2:
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
- bc_error_free(err);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
+ sb_error_free(err);
cleanup:
- bc_trie_free(config);
+ sb_trie_free(config);
free(template);
free(output);
free(print);
free(listing_entry);
- bc_trie_free(listing_entry_source);
- bc_slist_free_full(sources, free);
+ sb_trie_free(listing_entry_source);
+ sb_slist_free_full(sources, free);
return rv;
}
diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c
index 87b3f5a..42e4d29 100644
--- a/src/blogc/renderer.c
+++ b/src/blogc/renderer.c
@@ -11,67 +11,68 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
+
#include "datetime-parser.h"
#include "funcvars.h"
#include "template-parser.h"
#include "renderer.h"
-#include "../common/error.h"
-#include "../common/utils.h"
const char*
-blogc_get_variable(const char *name, bc_trie_t *global, bc_trie_t *local)
+blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
const char *rv = NULL;
if (local != NULL) {
- rv = bc_trie_lookup(local, name);
+ rv = sb_trie_lookup(local, name);
if (rv != NULL)
return rv;
}
if (global != NULL)
- rv = bc_trie_lookup(global, name);
+ rv = sb_trie_lookup(global, name);
return rv;
}
char*
-blogc_format_date(const char *date, bc_trie_t *global, bc_trie_t *local)
+blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local)
{
const char *date_format = blogc_get_variable("DATE_FORMAT", global, local);
if (date == NULL)
return NULL;
if (date_format == NULL)
- return bc_strdup(date);
+ return sb_strdup(date);
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *rv = blogc_convert_datetime(date, date_format, &err);
if (err != NULL) {
- bc_error_print(err, "blogc");
- bc_error_free(err);
- return bc_strdup(date);
+ fprintf(stderr, "blogc: warning: An error occurred while formatting "
+ "date:\n> %s\n", sb_error_to_string(err));
+ sb_error_free(err);
+ return sb_strdup(date);
}
return rv;
}
char*
-blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local,
- bc_slist_t *foreach_var)
+blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local,
+ sb_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 bc_strdup(value);
+ return sb_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 bc_strdup(foreach_var->data);
+ return sb_strdup(foreach_var->data);
}
return NULL;
}
- char *var = bc_strdup(name);
+ char *var = sb_strdup(name);
size_t i;
size_t last = strlen(var);
@@ -96,7 +97,7 @@ blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local,
bool must_format = false;
- if (bc_str_ends_with(var, "_FORMATTED")) {
+ if (sb_str_ends_with(var, "_FORMATTED")) {
var[strlen(var) - 10] = '\0';
must_format = true;
}
@@ -118,23 +119,23 @@ blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local,
char *rv = NULL;
if (must_format) {
- if (bc_str_starts_with(name, "DATE_")) {
+ if (sb_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 = bc_strdup(value);
+ rv = sb_strdup(value);
}
}
else {
- rv = bc_strdup(value);
+ rv = sb_strdup(value);
}
free(var);
if (len > 0) {
- char *tmp = bc_strndup(rv, len);
+ char *tmp = sb_strndup(rv, len);
free(rv);
rv = tmp;
}
@@ -143,19 +144,19 @@ blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *local,
}
-bc_slist_t*
-blogc_split_list_variable(const char *name, bc_trie_t *global, bc_trie_t *local)
+sb_slist_t*
+blogc_split_list_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
const char *value = blogc_get_variable(name, global, local);
if (value == NULL)
return NULL;
- bc_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
- char **tmp = bc_str_split(value, ' ', 0);
+ char **tmp = sb_str_split(value, ' ', 0);
for (size_t i = 0; tmp[i] != NULL; i++) {
if (tmp[i][0] != '\0') // ignore empty strings
- rv = bc_slist_append(rv, tmp[i]);
+ rv = sb_slist_append(rv, tmp[i]);
else
free(tmp[i]);
}
@@ -166,25 +167,25 @@ 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 *listing_entry, bc_trie_t *config, bool listing)
+blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *listing_entry, sb_trie_t *config, bool listing)
{
if (tmpl == NULL)
return NULL;
- bc_slist_t *current_source = NULL;
- bc_slist_t *listing_start = NULL;
+ sb_slist_t *current_source = NULL;
+ sb_slist_t *listing_start = NULL;
- bc_string_t *str = bc_string_new();
+ sb_string_t *str = sb_string_new();
- bc_trie_t *tmp_source = NULL;
+ sb_trie_t *tmp_source = NULL;
char *config_value = NULL;
char *defined = NULL;
size_t if_count = 0;
- bc_slist_t *foreach_var = NULL;
- bc_slist_t *foreach_var_start = NULL;
- bc_slist_t *foreach_start = NULL;
+ sb_slist_t *foreach_var = NULL;
+ sb_slist_t *foreach_var_start = NULL;
+ sb_slist_t *foreach_start = NULL;
bool if_not = false;
bool inside_block = false;
@@ -193,7 +194,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
int cmp = 0;
- bc_slist_t *tmp = tmpl;
+ sb_slist_t *tmp = tmpl;
while (tmp != NULL) {
blogc_template_node_t *node = tmp->data;
@@ -201,7 +202,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
case BLOGC_TEMPLATE_NODE_CONTENT:
if (node->data[0] != NULL)
- bc_string_append(str, node->data[0]);
+ sb_string_append(str, node->data[0]);
break;
case BLOGC_TEMPLATE_NODE_BLOCK:
@@ -272,7 +273,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
config_value = blogc_format_variable(node->data[0],
config, inside_block ? tmp_source : NULL, foreach_var);
if (config_value != NULL) {
- bc_string_append(str, config_value);
+ sb_string_append(str, config_value);
free(config_value);
config_value = NULL;
break;
@@ -314,7 +315,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
(node->data[1][0] == '"') &&
(node->data[1][strlen(node->data[1]) - 1] == '"'))
{
- defined2 = bc_strndup(node->data[1] + 1,
+ defined2 = sb_strndup(node->data[1] + 1,
strlen(node->data[1]) - 2);
}
else {
@@ -463,7 +464,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
}
}
foreach_start = NULL;
- bc_slist_free_full(foreach_var_start, free);
+ sb_slist_free_full(foreach_var_start, free);
foreach_var_start = NULL;
break;
}
@@ -473,5 +474,5 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc
// no need to free temporary variables here. the template parser makes sure
// that templates are sane and statements are closed.
- return bc_string_free(str, false);
+ return sb_string_free(str, false);
}
diff --git a/src/blogc/renderer.h b/src/blogc/renderer.h
index 8f2516a..c0bf289 100644
--- a/src/blogc/renderer.h
+++ b/src/blogc/renderer.h
@@ -10,15 +10,15 @@
#define _RENDERER_H
#include <stdbool.h>
-#include "../common/utils.h"
+#include <squareball.h>
-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 *listing_entr,
- bc_trie_t *config, bool listing);
+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 *listing_entr,
+ sb_trie_t *config, bool listing);
#endif /* _RENDERER_H */
diff --git a/src/blogc/rusage.c b/src/blogc/rusage.c
index a38848d..8753506 100644
--- a/src/blogc/rusage.c
+++ b/src/blogc/rusage.c
@@ -19,7 +19,8 @@
#endif /* HAVE_SYS_RESOURCE_H */
#include <stdlib.h>
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "rusage.h"
@@ -33,7 +34,7 @@ blogc_rusage_get(void)
if (0 != getrusage(RUSAGE_SELF, &usage))
return NULL;
- blogc_rusage_t *rv = bc_malloc(sizeof(blogc_rusage_t));
+ blogc_rusage_t *rv = sb_malloc(sizeof(blogc_rusage_t));
rv->cpu_time = (
(usage.ru_utime.tv_sec * 1000000) + usage.ru_utime.tv_usec +
(usage.ru_stime.tv_sec * 1000000) + usage.ru_stime.tv_usec);
@@ -48,14 +49,14 @@ char*
blogc_rusage_format_cpu_time(long long time)
{
if (time >= 1000000)
- return bc_strdup_printf("%.3fs", ((float) time) / 1000000.0);
+ return sb_strdup_printf("%.3fs", ((float) time) / 1000000.0);
// this is a special case: some systems may report the cpu time rounded up to the
// milisecond. it is useless to show ".000" in this case.
if (time >= 1000)
- return bc_strdup_printf("%.*fms", time % 1000 ? 3 : 0, ((float) time) / 1000.0);
+ return sb_strdup_printf("%.*fms", time % 1000 ? 3 : 0, ((float) time) / 1000.0);
- return bc_strdup_printf("%dus", time);
+ return sb_strdup_printf("%dus", time);
}
@@ -63,23 +64,23 @@ char*
blogc_rusage_format_memory(long mem)
{
if (mem >= 1048576)
- return bc_strdup_printf("%.3fGB", ((float) mem) / 1048576.0);
+ return sb_strdup_printf("%.3fGB", ((float) mem) / 1048576.0);
if (mem >= 1024)
- return bc_strdup_printf("%.3fMB", ((float) mem) / 1024.0);
- return bc_strdup_printf("%dKB", mem);
+ return sb_strdup_printf("%.3fMB", ((float) mem) / 1024.0);
+ return sb_strdup_printf("%dKB", mem);
}
void
-blogc_rusage_inject(bc_trie_t *global)
+blogc_rusage_inject(sb_trie_t *global)
{
blogc_rusage_t *usage = blogc_rusage_get();
if (usage == NULL)
return;
- bc_trie_insert(global, "BLOGC_RUSAGE_CPU_TIME",
+ sb_trie_insert(global, "BLOGC_RUSAGE_CPU_TIME",
blogc_rusage_format_cpu_time(usage->cpu_time));
- bc_trie_insert(global, "BLOGC_RUSAGE_MEMORY",
+ sb_trie_insert(global, "BLOGC_RUSAGE_MEMORY",
blogc_rusage_format_memory(usage->memory));
free(usage);
diff --git a/src/blogc/rusage.h b/src/blogc/rusage.h
index 6344066..725a3b6 100644
--- a/src/blogc/rusage.h
+++ b/src/blogc/rusage.h
@@ -19,7 +19,7 @@
#endif
#endif
-#include "../common/utils.h"
+#include <squareball.h>
typedef struct {
long long cpu_time; // in microseconds
@@ -31,6 +31,6 @@ blogc_rusage_t* blogc_rusage_get(void);
char* blogc_rusage_format_cpu_time(long long time);
char* blogc_rusage_format_memory(long mem);
-void blogc_rusage_inject(bc_trie_t *global);
+void blogc_rusage_inject(sb_trie_t *global);
#endif /* ___RUSAGE_H */
diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c
index 18cf95a..fb181de 100644
--- a/src/blogc/source-parser.c
+++ b/src/blogc/source-parser.c
@@ -8,11 +8,10 @@
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "content-parser.h"
#include "source-parser.h"
-#include "../common/error.h"
-#include "../common/utils.h"
typedef enum {
@@ -26,8 +25,8 @@ typedef enum {
} blogc_source_parser_state_t;
-bc_trie_t*
-blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
+sb_trie_t*
+blogc_source_parse(const char *src, size_t src_len, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
@@ -39,7 +38,7 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
char *key = NULL;
char *tmp = NULL;
char *content = NULL;
- bc_trie_t *rv = bc_trie_new(free);
+ sb_trie_t *rv = sb_trie_new(free);
blogc_source_parser_state_t state = SOURCE_START;
@@ -60,16 +59,16 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
state = SOURCE_SEPARATOR;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current,
- "Can't find a configuration key or the content separator.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "source: Can't find a configuration key or the content "
+ "separator.");
break;
case SOURCE_CONFIG_KEY:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
if (c == ':') {
- key = bc_strndup(src + start, current - start);
+ key = sb_strndup(src + start, current - start);
if (((current - start == 8) &&
(0 == strncmp("FILENAME", src + start, 8))) ||
((current - start == 7) &&
@@ -93,16 +92,16 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
((current - start == 13) &&
(0 == strncmp("BLOGC_VERSION", src + start, 13))))
{
- *err = bc_error_new_printf(BLOGC_ERROR_SOURCE_PARSER,
- "'%s' variable is forbidden in source files. It will "
- "be set for you by the compiler.", key);
+ *err = sb_strerror_new_printf(
+ "source: '%s' variable is forbidden in source files. "
+ "It will be set for you by the compiler.", key);
break;
}
state = SOURCE_CONFIG_VALUE_START;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current, "Invalid configuration key.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "source: Invalid configuration key.");
break;
case SOURCE_CONFIG_VALUE_START:
@@ -111,7 +110,7 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
start = current;
break;
}
- bc_trie_insert(rv, key, bc_strdup(""));
+ sb_trie_insert(rv, key, sb_strdup(""));
free(key);
key = NULL;
state = SOURCE_START;
@@ -119,8 +118,8 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
case SOURCE_CONFIG_VALUE:
if (c == '\n' || c == '\r') {
- tmp = bc_strndup(src + start, current - start);
- bc_trie_insert(rv, key, bc_strdup(bc_str_strip(tmp)));
+ tmp = sb_strndup(src + start, current - start);
+ sb_trie_insert(rv, key, sb_strdup(sb_str_strip(tmp)));
free(tmp);
free(key);
key = NULL;
@@ -135,9 +134,9 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
state = SOURCE_CONTENT_START;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current,
- "Invalid content separator. Must be more than one '-' characters.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "source: Invalid content separator. Must be more than one "
+ "'-' characters.");
break;
case SOURCE_CONTENT_START:
@@ -149,18 +148,18 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
case SOURCE_CONTENT:
if (current == (src_len - 1)) {
- tmp = bc_strndup(src + start, src_len - start);
- bc_trie_insert(rv, "RAW_CONTENT", tmp);
+ tmp = sb_strndup(src + start, src_len - start);
+ sb_trie_insert(rv, "RAW_CONTENT", tmp);
char *first_header = NULL;
char *description = NULL;
content = blogc_content_parse(tmp, &end_excerpt,
&first_header, &description);
if (first_header != NULL) {
// do not override source-provided first_header.
- if (NULL == bc_trie_lookup(rv, "FIRST_HEADER")) {
+ if (NULL == sb_trie_lookup(rv, "FIRST_HEADER")) {
// no need to free, because we are transfering memory
// ownership to the trie.
- bc_trie_insert(rv, "FIRST_HEADER", first_header);
+ sb_trie_insert(rv, "FIRST_HEADER", first_header);
}
else {
free(first_header);
@@ -168,18 +167,18 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
}
if (description != NULL) {
// do not override source-provided description.
- if (NULL == bc_trie_lookup(rv, "DESCRIPTION")) {
+ if (NULL == sb_trie_lookup(rv, "DESCRIPTION")) {
// no need to free, because we are transfering memory
// ownership to the trie.
- bc_trie_insert(rv, "DESCRIPTION", description);
+ sb_trie_insert(rv, "DESCRIPTION", description);
}
else {
free(description);
}
}
- bc_trie_insert(rv, "CONTENT", content);
- bc_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
- bc_strdup(content) : bc_strndup(content, end_excerpt));
+ sb_trie_insert(rv, "CONTENT", content);
+ sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
+ sb_strdup(content) : sb_strndup(content, end_excerpt));
}
break;
}
@@ -190,29 +189,28 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
current++;
}
- if (*err == NULL && bc_trie_size(rv) == 0) {
+ if (*err == NULL && sb_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
// output. :)
switch (state) {
case SOURCE_START:
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current, "Your source file is empty.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "source: Your source file is empty.");
break;
case SOURCE_CONFIG_KEY:
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current, "Your last configuration key is missing ':' and "
+ *err = sb_parser_error_new(src, src_len, current,
+ "source: Your last configuration key is missing ':' and "
"the value");
break;
case SOURCE_CONFIG_VALUE_START:
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current, "Configuration value not provided for '%s'.",
- key);
+ *err = sb_parser_error_new_printf(src, src_len, current,
+ "source: Configuration value not provided for '%s'.", key);
break;
case SOURCE_CONFIG_VALUE:
- *err = bc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
- current, "No line ending after the configuration value for "
+ *err = sb_parser_error_new_printf(src, src_len, current,
+ "source: No line ending after the configuration value for "
"'%s'.", key);
break;
case SOURCE_SEPARATOR:
@@ -224,7 +222,7 @@ blogc_source_parse(const char *src, size_t src_len, bc_error_t **err)
if (*err != NULL) {
free(key);
- bc_trie_free(rv);
+ sb_trie_free(rv);
return NULL;
}
diff --git a/src/blogc/source-parser.h b/src/blogc/source-parser.h
index 8672fb0..b90f30b 100644
--- a/src/blogc/source-parser.h
+++ b/src/blogc/source-parser.h
@@ -10,10 +10,9 @@
#define _SOURCE_PARSER_H
#include <stddef.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
-bc_trie_t* blogc_source_parse(const char *src, size_t src_len,
- bc_error_t **err);
+sb_trie_t* blogc_source_parse(const char *src, size_t src_len,
+ sb_error_t **err);
#endif /* _SOURCE_PARSER_H */
diff --git a/src/blogc/sysinfo.c b/src/blogc/sysinfo.c
index cdb860e..9e0ab1b 100644
--- a/src/blogc/sysinfo.c
+++ b/src/blogc/sysinfo.c
@@ -21,9 +21,8 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "../common/error.h"
-#include "../common/file.h"
-#include "../common/utils.h"
+#include <squareball.h>
+
#include "sysinfo.h"
@@ -39,37 +38,37 @@ blogc_sysinfo_get_hostname(void)
return NULL;
// FIXME: return FQDN instead of local host name
- return bc_strdup(buf);
+ return sb_strdup(buf);
#endif
}
void
-blogc_sysinfo_inject_hostname(bc_trie_t *global)
+blogc_sysinfo_inject_hostname(sb_trie_t *global)
{
char *hostname = blogc_sysinfo_get_hostname();
if (hostname == NULL)
return;
- bc_trie_insert(global, "BLOGC_SYSINFO_HOSTNAME", hostname);
+ sb_trie_insert(global, "BLOGC_SYSINFO_HOSTNAME", hostname);
}
char*
blogc_sysinfo_get_username(void)
{
- return bc_strdup(getenv("LOGNAME"));
+ return sb_strdup(getenv("LOGNAME"));
}
void
-blogc_sysinfo_inject_username(bc_trie_t *global)
+blogc_sysinfo_inject_username(sb_trie_t *global)
{
char *username = blogc_sysinfo_get_username();
if (username == NULL)
return;
- bc_trie_insert(global, "BLOGC_SYSINFO_USERNAME", username);
+ sb_trie_insert(global, "BLOGC_SYSINFO_USERNAME", username);
}
@@ -91,19 +90,19 @@ blogc_sysinfo_get_datetime(void)
if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", t))
return NULL;
- return bc_strdup(buf);
+ return sb_strdup(buf);
#endif
}
void
-blogc_sysinfo_inject_datetime(bc_trie_t *global)
+blogc_sysinfo_inject_datetime(sb_trie_t *global)
{
char *t = blogc_sysinfo_get_datetime();
if (t == NULL)
return;
- bc_trie_insert(global, "BLOGC_SYSINFO_DATETIME", t);
+ sb_trie_insert(global, "BLOGC_SYSINFO_DATETIME", t);
}
@@ -121,10 +120,10 @@ blogc_sysinfo_get_inside_docker(void)
inside_docker_evaluated = true;
size_t len;
- bc_error_t *err = NULL;
- char *contents = bc_file_get_contents("/proc/1/cgroup", false, &len, &err);
+ sb_error_t *err = NULL;
+ char *contents = sb_file_get_contents("/proc/1/cgroup", &len, &err);
if (err != NULL) {
- bc_error_free(err);
+ sb_error_free(err);
inside_docker = false;
return inside_docker;
}
@@ -136,8 +135,8 @@ blogc_sysinfo_get_inside_docker(void)
void
-blogc_sysinfo_inject_inside_docker(bc_trie_t *global)
+blogc_sysinfo_inject_inside_docker(sb_trie_t *global)
{
if (blogc_sysinfo_get_inside_docker())
- bc_trie_insert(global, "BLOGC_SYSINFO_INSIDE_DOCKER", bc_strdup("1"));
+ sb_trie_insert(global, "BLOGC_SYSINFO_INSIDE_DOCKER", sb_strdup("1"));
}
diff --git a/src/blogc/sysinfo.h b/src/blogc/sysinfo.h
index b249661..23b7ba6 100644
--- a/src/blogc/sysinfo.h
+++ b/src/blogc/sysinfo.h
@@ -24,15 +24,15 @@
#endif /* HAVE_TIME_H */
#include <stdbool.h>
-#include "../common/utils.h"
+#include <squareball.h>
char* blogc_sysinfo_get_hostname(void);
-void blogc_sysinfo_inject_hostname(bc_trie_t *global);
+void blogc_sysinfo_inject_hostname(sb_trie_t *global);
char* blogc_sysinfo_get_username(void);
-void blogc_sysinfo_inject_username(bc_trie_t *global);
+void blogc_sysinfo_inject_username(sb_trie_t *global);
char* blogc_sysinfo_get_datetime(void);
-void blogc_sysinfo_inject_datetime(bc_trie_t *global);
+void blogc_sysinfo_inject_datetime(sb_trie_t *global);
bool blogc_sysinfo_get_inside_docker(void);
-void blogc_sysinfo_inject_inside_docker(bc_trie_t *global);
+void blogc_sysinfo_inject_inside_docker(sb_trie_t *global);
#endif /* ___SYSINFO_H */
diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c
index 0b4eb55..1ce0c51 100644
--- a/src/blogc/template-parser.c
+++ b/src/blogc/template-parser.c
@@ -9,10 +9,12 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "template-parser.h"
-#include "../common/error.h"
-#include "../common/utils.h"
+
+#define is_space(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || \
+ c == '\t' || c == '\v')
typedef enum {
@@ -41,8 +43,8 @@ typedef enum {
} blogc_template_parser_state_t;
-bc_slist_t*
-blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
+sb_slist_t*
+blogc_template_parse(const char *src, size_t src_len, sb_error_t **err)
{
if (err == NULL || *err != NULL)
return NULL;
@@ -63,7 +65,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
bool foreach_open = false;
bool block_foreach_open = false;
- bc_slist_t *ast = NULL;
+ sb_slist_t *ast = NULL;
blogc_template_node_t *node = NULL;
/*
@@ -94,21 +96,21 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
case TEMPLATE_START:
if (last) {
- node = bc_malloc(sizeof(blogc_template_node_t));
+ node = sb_malloc(sizeof(blogc_template_node_t));
node->type = type;
if (lstrip_next) {
- tmp = bc_strndup(src + start, src_len - start);
- node->data[0] = bc_strdup(bc_str_lstrip(tmp));
+ tmp = sb_strndup(src + start, src_len - start);
+ node->data[0] = sb_strdup(sb_str_lstrip(tmp));
free(tmp);
tmp = NULL;
lstrip_next = false;
}
else {
- node->data[0] = bc_strndup(src + start, src_len - start);
+ node->data[0] = sb_strndup(src + start, src_len - start);
}
node->op = 0;
node->data[1] = NULL;
- ast = bc_slist_append(ast, node);
+ ast = sb_slist_append(ast, node);
previous = node;
node = NULL;
}
@@ -125,21 +127,21 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
else
state = TEMPLATE_VARIABLE_START;
if (end > start) {
- node = bc_malloc(sizeof(blogc_template_node_t));
+ node = sb_malloc(sizeof(blogc_template_node_t));
node->type = type;
if (lstrip_next) {
- tmp = bc_strndup(src + start, end - start);
- node->data[0] = bc_strdup(bc_str_lstrip(tmp));
+ tmp = sb_strndup(src + start, end - start);
+ node->data[0] = sb_strdup(sb_str_lstrip(tmp));
free(tmp);
tmp = NULL;
lstrip_next = false;
}
else {
- node->data[0] = bc_strndup(src + start, end - start);
+ node->data[0] = sb_strndup(src + start, end - start);
}
node->op = 0;
node->data[1] = NULL;
- ast = bc_slist_append(ast, node);
+ ast = sb_slist_append(ast, node);
previous = node;
node = NULL;
}
@@ -153,7 +155,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
if ((previous != NULL) &&
(previous->type == BLOGC_TEMPLATE_NODE_CONTENT))
{
- previous->data[0] = bc_str_rstrip(previous->data[0]); // does not need copy
+ previous->data[0] = sb_str_rstrip(previous->data[0]); // does not need copy
}
state = TEMPLATE_BLOCK_START;
break;
@@ -161,7 +163,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
state = TEMPLATE_BLOCK_START;
case TEMPLATE_BLOCK_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'a' && c <= 'z') {
state = TEMPLATE_BLOCK_TYPE;
@@ -169,21 +171,20 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
}
if (c == '-') {
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Duplicated whitespace "
- "cleaner before statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Duplicated "
+ "whitespace cleaner before statement.");
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Must begin with lowercase letter.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Must begin with "
+ "lowercase letter.");
break;
case TEMPLATE_BLOCK_TYPE:
if (c >= 'a' && c <= 'z')
break;
- if (bc_isspace(c)) {
+ if (is_space(c)) {
if ((current - start == 5) &&
(0 == strncmp("block", src + start, 5)))
{
@@ -195,8 +196,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
block_foreach_open = foreach_open;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current, "Blocks can't be nested.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Blocks can't be nested.");
break;
}
else if ((current - start == 8) &&
@@ -204,16 +205,18 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
{
if (block_open) {
if (if_count != block_if_count) {
- *err = bc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER,
- "%d open 'if', 'ifdef' and/or 'ifndef' statements "
- "were not closed inside a '%s' block!",
+ *err = sb_strerror_new_printf(
+ "template: %d open 'if', 'ifdef' and/or "
+ "'ifndef' statements were not closed "
+ "inside a '%s' block!",
if_count - block_if_count, block_type);
break;
}
if (!block_foreach_open && foreach_open) {
- *err = bc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER,
- "An open 'foreach' statement was not closed "
- "inside a '%s' block!", block_type);
+ *err = sb_strerror_new_printf(
+ "template: An open 'foreach' statement was "
+ "not closed inside a '%s' block!",
+ block_type);
break;
}
state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER;
@@ -221,9 +224,9 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
block_open = false;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'endblock' statement without an open 'block' statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: 'endblock' statement without an open "
+ "'block' statement.");
break;
}
else if ((current - start == 5) &&
@@ -268,16 +271,14 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
else_open = true;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "More than one 'else' statement for an open 'if', "
- "'ifdef' or 'ifndef' statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: More than one 'else' statement for "
+ "an open 'if', 'ifdef' or 'ifndef' statement.");
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'else' statement without an open 'if', 'ifdef' or "
- "'ifndef' statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: 'else' statement without an open 'if', "
+ "'ifdef' or 'ifndef' statement.");
break;
}
else if ((current - start == 5) &&
@@ -292,10 +293,9 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
else_open = false;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'endif' statement without an open 'if', 'ifdef' or "
- "'ifndef' statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: 'endif' statement without an open 'if', "
+ "'ifdef' or 'ifndef' statement.");
break;
}
else if ((current - start == 7) &&
@@ -308,9 +308,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
foreach_open = true;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current, "'foreach' statements can't "
- "be nested.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: 'foreach' statements can't be nested.");
break;
}
else if ((current - start == 10) &&
@@ -324,37 +323,35 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
foreach_open = false;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, current,
- "'endforeach' statement without an open 'foreach' "
- "statement.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: 'endforeach' statement without an open "
+ "'foreach' statement.");
break;
}
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement type: Allowed types are: 'block', "
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement type: Allowed types are: 'block', "
"'endblock', 'if', 'ifdef', 'ifndef', 'else', 'endif', "
"'foreach' and 'endforeach'.");
break;
case TEMPLATE_BLOCK_BLOCK_TYPE_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'a' && c <= 'z') {
state = TEMPLATE_BLOCK_BLOCK_TYPE;
start = current;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid block syntax. Must begin with lowercase letter.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid block syntax. Must begin with lowercase "
+ "letter.");
break;
case TEMPLATE_BLOCK_BLOCK_TYPE:
if ((c >= 'a' && c <= 'z') || c == '_')
break;
- if (bc_isspace(c)) {
+ if (is_space(c)) {
if ((current - start == 5) &&
(0 == strncmp("entry", src + start, 5)))
{
@@ -388,29 +385,28 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
}
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid block type. Allowed types are: 'entry', 'listing', "
- "'listing_once' and 'listing_entry'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid block type. Allowed types are: 'entry', "
+ "'listing', 'listing_once' and 'listing_entry'.");
break;
case TEMPLATE_BLOCK_IF_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_IF_VARIABLE;
start = current;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid variable name. Must begin with uppercase letter.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid variable name. Must begin with uppercase "
+ "letter.");
break;
case TEMPLATE_BLOCK_IF_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (bc_isspace(c)) {
+ if (is_space(c)) {
end = current;
if (type == BLOGC_TEMPLATE_NODE_IF)
state = TEMPLATE_BLOCK_IF_OPERATOR_START;
@@ -418,28 +414,27 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid variable name. Must be uppercase letter, number "
- "or '_'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid variable name. Must be uppercase letter, "
+ "number or '_'.");
break;
case TEMPLATE_BLOCK_IF_OPERATOR_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
state = TEMPLATE_BLOCK_IF_OPERATOR;
op_start = current;
break;
case TEMPLATE_BLOCK_IF_OPERATOR:
- if (!bc_isspace(c))
+ if (!is_space(c))
break;
state = TEMPLATE_BLOCK_IF_OPERAND_START;
op_end = current;
break;
case TEMPLATE_BLOCK_IF_OPERAND_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_IF_VARIABLE_OPERAND;
@@ -453,9 +448,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
}
op_start = 0;
op_end = 0;
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid 'if' operand. Must be double-quoted static "
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid 'if' operand. Must be double-quoted static "
"string or variable.");
break;
@@ -476,35 +470,33 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
case TEMPLATE_BLOCK_FOREACH_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_BLOCK_FOREACH_VARIABLE;
start = current;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid foreach variable name. Must begin with uppercase "
- "letter.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid foreach variable name. Must begin with "
+ "uppercase letter.");
break;
case TEMPLATE_BLOCK_FOREACH_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (bc_isspace(c)) {
+ if (is_space(c)) {
end = current;
state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid foreach variable name. Must be uppercase letter, "
- "number or '_'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid foreach variable name. Must be uppercase "
+ "letter, number or '_'.");
break;
case TEMPLATE_BLOCK_END_WHITESPACE_CLEANER:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c == '-') {
lstrip_next = true;
@@ -519,19 +511,17 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
break;
}
if (c == '-') {
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Duplicated whitespace "
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Duplicated whitespace "
"cleaner after statement.");
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Must end with '%%}'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Must end with '%}'.");
break;
case TEMPLATE_VARIABLE_START:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c >= 'A' && c <= 'Z') {
state = TEMPLATE_VARIABLE;
@@ -539,15 +529,15 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
start = current;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid variable name. Must begin with uppercase letter.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid variable name. Must begin with uppercase "
+ "letter.");
break;
case TEMPLATE_VARIABLE:
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
- if (bc_isspace(c)) {
+ if (is_space(c)) {
end = current;
state = TEMPLATE_VARIABLE_END;
break;
@@ -557,22 +547,20 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
state = TEMPLATE_CLOSE_BRACKET;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid variable name. Must be uppercase letter, number "
- "or '_'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid variable name. Must be uppercase letter, "
+ "number or '_'.");
break;
case TEMPLATE_VARIABLE_END:
- if (bc_isspace(c))
+ if (is_space(c))
break;
if (c == '}') {
state = TEMPLATE_CLOSE_BRACKET;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Must end with '}}'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Must end with '}}'.");
break;
case TEMPLATE_CLOSE_BRACKET:
@@ -596,9 +584,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
tmp_op = BLOGC_TEMPLATE_OP_NEQ;
}
if (tmp_op == 0) {
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER,
- src, src_len, op_start,
- "Invalid 'if' operator. Must be '<', '>', "
+ *err = sb_parser_error_new(src, src_len, op_start,
+ "template: Invalid 'if' operator. Must be '<', '>', "
"'<=', '>=', '==' or '!='.");
op_start = 0;
op_end = 0;
@@ -607,21 +594,21 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
op_start = 0;
op_end = 0;
}
- node = bc_malloc(sizeof(blogc_template_node_t));
+ node = sb_malloc(sizeof(blogc_template_node_t));
node->type = type;
node->op = tmp_op;
node->data[0] = NULL;
node->data[1] = NULL;
if (end > start)
- node->data[0] = bc_strndup(src + start, end - start);
+ node->data[0] = sb_strndup(src + start, end - start);
if (end2 > start2) {
- node->data[1] = bc_strndup(src + start2, end2 - start2);
+ node->data[1] = sb_strndup(src + start2, end2 - start2);
start2 = 0;
end2 = 0;
}
if (type == BLOGC_TEMPLATE_NODE_BLOCK)
block_type = node->data[0];
- ast = bc_slist_append(ast, node);
+ ast = sb_slist_append(ast, node);
previous = node;
node = NULL;
state = TEMPLATE_START;
@@ -629,9 +616,8 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
start = current + 1;
break;
}
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src,
- src_len, current,
- "Invalid statement syntax. Must end with '}'.");
+ *err = sb_parser_error_new(src, src_len, current,
+ "template: Invalid statement syntax. Must end with '}'.");
break;
}
@@ -644,18 +630,17 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
if (*err == NULL) {
if (state == TEMPLATE_BLOCK_IF_STRING_OPERAND)
- *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len,
- start2, "Found an open double-quoted string.");
+ *err = sb_parser_error_new(src, src_len, start2,
+ "template: Found an open double-quoted string.");
else if (if_count != 0)
- *err = bc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER,
- "%d open 'if', 'ifdef' and/or 'ifndef' statements were not closed!",
- if_count);
+ *err = sb_strerror_new_printf(
+ "template: %d open 'if', 'ifdef' and/or 'ifndef' statements "
+ "were not closed!", if_count);
else if (block_open)
- *err = bc_error_new(BLOGC_ERROR_TEMPLATE_PARSER,
- "An open block was not closed!");
+ *err = sb_strerror_new("template: An open block was not closed!");
else if (foreach_open)
- *err = bc_error_new(BLOGC_ERROR_TEMPLATE_PARSER,
- "An open 'foreach' statement was not closed!");
+ *err = sb_strerror_new(
+ "template: An open 'foreach' statement was not closed!");
}
if (*err != NULL) {
@@ -672,9 +657,9 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err)
void
-blogc_template_free_ast(bc_slist_t *ast)
+blogc_template_free_ast(sb_slist_t *ast)
{
- for (bc_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = ast; tmp != NULL; tmp = tmp->next) {
blogc_template_node_t *data = tmp->data;
if (data == NULL)
continue;
@@ -682,5 +667,5 @@ blogc_template_free_ast(bc_slist_t *ast)
free(data->data[1]);
free(data);
}
- bc_slist_free(ast);
+ sb_slist_free(ast);
}
diff --git a/src/blogc/template-parser.h b/src/blogc/template-parser.h
index 6183016..d21d6d8 100644
--- a/src/blogc/template-parser.h
+++ b/src/blogc/template-parser.h
@@ -10,8 +10,7 @@
#define _TEMPLATE_PARSER_H
#include <stddef.h>
-#include "../common/error.h"
-#include "../common/utils.h"
+#include <squareball.h>
/*
* note: whitespace cleaners are NOT added to AST. we fix strings right during
@@ -48,11 +47,11 @@ typedef struct {
// 2 slots to store node data.
char *data[2];
- bc_slist_t *childs;
+ sb_slist_t *childs;
} blogc_template_node_t;
-bc_slist_t* blogc_template_parse(const char *src, size_t src_len,
- bc_error_t **err);
-void blogc_template_free_ast(bc_slist_t *ast);
+sb_slist_t* blogc_template_parse(const char *src, size_t src_len,
+ sb_error_t **err);
+void blogc_template_free_ast(sb_slist_t *ast);
#endif /* _TEMPLATE_PARSER_H */
diff --git a/src/common/compat.c b/src/common/compat.c
deleted file mode 100644
index f7394c8..0000000
--- a/src/common/compat.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#ifdef HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif /* HAVE_SYS_WAIT_H */
-
-#include <signal.h>
-#include "compat.h"
-
-
-int
-bc_compat_status_code(int waitstatus)
-{
- int rv = waitstatus;
-#if defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && defined(WTERMSIG)
- if (WIFEXITED(waitstatus)) {
- rv = WEXITSTATUS(waitstatus);
- }
- else if (WIFSIGNALED(waitstatus)) {
- rv = WTERMSIG(waitstatus);
- rv += 128;
- }
-#elif defined(WIN32) || defined(_WIN32)
- if (waitstatus == 3) {
- rv = SIGTERM + 128; // can't get signal on windows.
- }
-#endif
- return rv;
-}
diff --git a/src/common/compat.h b/src/common/compat.h
deleted file mode 100644
index 1e743db..0000000
--- a/src/common/compat.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _COMPAT_H
-#define _COMPAT_H
-
-int bc_compat_status_code(int waitstatus);
-
-#endif /* _COMPAT_H */
diff --git a/src/common/config-parser.c b/src/common/config-parser.c
deleted file mode 100644
index bc4831b..0000000
--- a/src/common/config-parser.c
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include "error.h"
-#include "utils.h"
-#include "config-parser.h"
-
-
-typedef enum {
- CONFIG_START = 1,
- CONFIG_SECTION_START,
- CONFIG_SECTION,
- CONFIG_SECTION_KEY,
- CONFIG_SECTION_VALUE_START,
- CONFIG_SECTION_VALUE_QUOTE,
- CONFIG_SECTION_VALUE_POST_QUOTED,
- CONFIG_SECTION_VALUE,
- CONFIG_SECTION_LIST_START,
- CONFIG_SECTION_LIST_QUOTE,
- CONFIG_SECTION_LIST_POST_QUOTED,
- CONFIG_SECTION_LIST,
-} bc_configparser_state_t;
-
-typedef enum {
- CONFIG_SECTION_TYPE_MAP = 1,
- CONFIG_SECTION_TYPE_LIST,
-} bc_configparser_section_type_t;
-
-typedef struct {
- bc_configparser_section_type_t type;
- void *data;
-} bc_configparser_section_t;
-
-
-static void
-free_section(bc_configparser_section_t *section)
-{
- if (section == NULL)
- return;
-
- switch (section->type) {
- case CONFIG_SECTION_TYPE_MAP:
- bc_trie_free(section->data);
- break;
- case CONFIG_SECTION_TYPE_LIST:
- bc_slist_free_full(section->data, free);
- break;
- }
- free(section);
-}
-
-
-bc_config_t*
-bc_config_parse(const char *src, size_t src_len, const char *list_sections[],
- bc_error_t **err)
-{
- if (err == NULL || *err != NULL)
- return NULL;
-
- size_t current = 0;
- size_t start = 0;
-
- bc_configparser_section_t *section = NULL;
-
- char *section_name = NULL;
- char *key = NULL;
- bc_string_t *value = NULL;
- bool escaped = false;
-
- bc_config_t *rv = bc_malloc(sizeof(bc_config_t));
- rv->root = bc_trie_new((bc_free_func_t) free_section);
-
- bc_configparser_state_t state = CONFIG_START;
-
- while (current < src_len) {
- char c = src[current];
- bool is_last = current == src_len - 1;
-
- if (escaped) {
- bc_string_append_c(value, c);
- escaped = false;
- current++;
- continue;
- }
-
- if (value != NULL && c == '\\') {
- escaped = true;
- current++;
- continue;
- }
-
- switch (state) {
-
- case CONFIG_START:
- if (c == '#' || c == ';') {
- while (current < src_len) {
- if (src[current] == '\r' || src[current] == '\n')
- break;
- current++;
- }
- break;
- }
- if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
- break;
- if (c == '[') {
- state = CONFIG_SECTION_START;
- break;
- }
- if (section != NULL) {
- start = current;
- switch (section->type) {
- case CONFIG_SECTION_TYPE_MAP:
- state = CONFIG_SECTION_KEY;
- break;
- case CONFIG_SECTION_TYPE_LIST:
- state = CONFIG_SECTION_LIST_START;
- if (value == NULL)
- value = bc_string_new();
- break;
- }
- continue;
- }
- *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len,
- current, "File must start with section.");
- break;
-
- case CONFIG_SECTION_START:
- start = current;
- state = CONFIG_SECTION;
- break;
-
- case CONFIG_SECTION:
- if (c == ']') {
- section_name = bc_strndup(src + start, current - start);
- section = bc_malloc(sizeof(bc_configparser_section_t));
- section->type = CONFIG_SECTION_TYPE_MAP;
- if (list_sections != NULL) {
- for (size_t i = 0; list_sections[i] != NULL; i++) {
- if (0 == strcmp(section_name, list_sections[i])) {
- section->type = CONFIG_SECTION_TYPE_LIST;
- break;
- }
- }
- }
- switch (section->type) {
- case CONFIG_SECTION_TYPE_MAP:
- section->data = bc_trie_new(free);
- break;
- case CONFIG_SECTION_TYPE_LIST:
- section->data = NULL;
- break;
- }
- bc_trie_insert(rv->root, section_name, section);
- free(section_name);
- section_name = NULL;
- state = CONFIG_START;
- break;
- }
- if (c != '\r' && c != '\n')
- break;
- *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len,
- current, "Section names can't have new lines.");
- break;
-
- case CONFIG_SECTION_KEY:
- if (c == '=') {
- key = bc_strndup(src + start, current - start);
- state = CONFIG_SECTION_VALUE_START;
- if (is_last) {
- bc_trie_insert(section->data, bc_str_strip(key),
- bc_strdup(""));
- free(key);
- key = NULL;
- break;
- }
- if (value == NULL)
- value = bc_string_new();
- break;
- }
- if (c != '\r' && c != '\n' && !is_last)
- break;
- // key without value, should we support it?
- size_t end = is_last && c != '\n' && c != '\r' ? src_len :
- current;
- key = bc_strndup(src + start, end - start);
- *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len,
- current, "Key without value: %s.", key);
- free(key);
- key = NULL;
- break;
-
- case CONFIG_SECTION_VALUE_START:
- if (c == ' ' || c == '\t' || c == '\f' || c == '\v')
- break;
- if (c == '"') {
- state = CONFIG_SECTION_VALUE_QUOTE;
- break;
- }
- if (c == '\r' || c == '\n' || is_last) {
- state = CONFIG_SECTION_VALUE;
- continue;
- }
- bc_string_append_c(value, c);
- state = CONFIG_SECTION_VALUE;
- break;
-
- case CONFIG_SECTION_VALUE_QUOTE:
- if (c == '"') {
- bc_trie_insert(section->data, bc_str_strip(key),
- bc_string_free(value, false));
- free(key);
- key = NULL;
- value = NULL;
- state = CONFIG_SECTION_VALUE_POST_QUOTED;
- break;
- }
- bc_string_append_c(value, c);
- break;
-
- case CONFIG_SECTION_VALUE_POST_QUOTED:
- if (c == ' ' || c == '\t' || c == '\f' || c == '\v')
- break;
- if (c == '\r' || c == '\n' || is_last) {
- state = CONFIG_START;
- break;
- }
- *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len,
- current, "Invalid value for key, should not have anything "
- "after quotes.");
- break;
-
- case CONFIG_SECTION_VALUE:
- if (c == '\r' || c == '\n' || is_last) {
- if (is_last && c != '\r' && c != '\n')
- bc_string_append_c(value, c);
- bc_trie_insert(section->data, bc_str_strip(key),
- bc_strdup(bc_str_rstrip(value->str)));
- free(key);
- key = NULL;
- bc_string_free(value, true);
- value = NULL;
- state = CONFIG_START;
- break;
- }
- bc_string_append_c(value, c);
- break;
-
- case CONFIG_SECTION_LIST_START:
- if (c == ' ' || c == '\t' || c == '\f' || c == '\v')
- break;
- if (c == '"') {
- state = CONFIG_SECTION_LIST_QUOTE;
- break;
- }
- bc_string_append_c(value, c);
- state = CONFIG_SECTION_LIST;
- break;
-
- case CONFIG_SECTION_LIST_QUOTE:
- if (c == '"') {
- section->data = bc_slist_append(section->data,
- bc_string_free(value, false));
- value = NULL;
- state = CONFIG_SECTION_LIST_POST_QUOTED;
- break;
-
- }
- bc_string_append_c(value, c);
- break;
-
- case CONFIG_SECTION_LIST_POST_QUOTED:
- if (c == ' ' || c == '\t' || c == '\f' || c == '\v')
- break;
- if (c == '\r' || c == '\n' || is_last) {
- state = CONFIG_START;
- break;
- }
- *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len,
- current, "Invalid value for list item, should not have "
- "anything after quotes.");
- break;
-
- case CONFIG_SECTION_LIST:
- if (c == '\r' || c == '\n' || is_last) {
- if (is_last && c != '\r' && c != '\n')
- bc_string_append_c(value, c);
- section->data = bc_slist_append(section->data,
- bc_strdup(bc_str_strip(value->str)));
- bc_string_free(value, true);
- value = NULL;
- state = CONFIG_START;
- break;
-
- }
- bc_string_append_c(value, c);
- break;
-
- }
-
- if (*err != NULL) {
- bc_config_free(rv);
- rv = NULL;
- break;
- }
-
- current++;
- }
-
- free(section_name);
- free(key);
- bc_string_free(value, true);
-
- return rv;
-}
-
-
-static void
-list_keys(const char *key, const char *value, bc_slist_t **l)
-{
- *l = bc_slist_append(*l, bc_strdup(key));
-}
-
-
-char**
-bc_config_list_sections(bc_config_t *config)
-{
- if (config == NULL)
- return NULL;
-
- bc_slist_t *l = NULL;
- bc_trie_foreach(config->root, (bc_trie_foreach_func_t) list_keys, &l);
-
- char **rv = bc_malloc(sizeof(char*) * (bc_slist_length(l) + 1));
-
- size_t i = 0;
- for (bc_slist_t *tmp = l; tmp != NULL; tmp = tmp->next, i++)
- rv[i] = tmp->data;
- rv[i] = NULL;
-
- bc_slist_free(l);
-
- return rv;
-}
-
-
-char**
-bc_config_list_keys(bc_config_t *config, const char *section)
-{
- if (config == NULL)
- return NULL;
-
- bc_configparser_section_t *s = bc_trie_lookup(config->root, section);
- if (s == NULL)
- return NULL;
-
- if (s->type != CONFIG_SECTION_TYPE_MAP)
- return NULL;
-
- bc_slist_t *l = NULL;
- bc_trie_foreach(s->data, (bc_trie_foreach_func_t) list_keys, &l);
-
- char **rv = bc_malloc(sizeof(char*) * (bc_slist_length(l) + 1));
-
- size_t i = 0;
- for (bc_slist_t *tmp = l; tmp != NULL; tmp = tmp->next, i++)
- rv[i] = tmp->data;
- rv[i] = NULL;
-
- bc_slist_free(l);
-
- return rv;
-}
-
-
-const char*
-bc_config_get(bc_config_t *config, const char *section, const char *key)
-{
- if (config == NULL)
- return NULL;
-
- bc_configparser_section_t *s = bc_trie_lookup(config->root, section);
- if (s == NULL)
- return NULL;
-
- if (s->type != CONFIG_SECTION_TYPE_MAP)
- return NULL;
-
- return bc_trie_lookup(s->data, key);
-}
-
-
-const char*
-bc_config_get_with_default(bc_config_t *config, const char *section, const char *key,
- const char *default_)
-{
- const char *rv = bc_config_get(config, section, key);
- if (rv == NULL)
- return default_;
- return rv;
-}
-
-
-char**
-bc_config_get_list(bc_config_t *config, const char *section)
-{
- if (config == NULL)
- return NULL;
-
- bc_configparser_section_t *s = bc_trie_lookup(config->root, section);
- if (s == NULL)
- return NULL;
-
- if (s->type != CONFIG_SECTION_TYPE_LIST)
- return NULL;
-
- char **rv = bc_malloc(sizeof(char*) * (bc_slist_length(s->data) + 1));
-
- size_t i = 0;
- for (bc_slist_t *tmp = s->data; tmp != NULL; tmp = tmp->next, i++)
- rv[i] = bc_strdup(tmp->data);
- rv[i] = NULL;
-
- return rv;
-}
-
-
-void
-bc_config_free(bc_config_t *config)
-{
- if (config == NULL)
- return;
- bc_trie_free(config->root);
- free(config);
-}
diff --git a/src/common/config-parser.h b/src/common/config-parser.h
deleted file mode 100644
index 0b75ff8..0000000
--- a/src/common/config-parser.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _CONFIG_PARSER_H
-#define _CONFIG_PARSER_H
-
-#include <stddef.h>
-#include "utils.h"
-#include "error.h"
-
-typedef struct {
- bc_trie_t *root;
-} bc_config_t;
-
-bc_config_t* bc_config_parse(const char *src, size_t src_len,
- const char *list_sections[], bc_error_t **err);
-char** bc_config_list_sections(bc_config_t *config);
-char** bc_config_list_keys(bc_config_t *config, const char *section);
-const char* bc_config_get(bc_config_t *config, const char *section,
- const char *key);
-const char* bc_config_get_with_default(bc_config_t *config, const char *section,
- const char *key, const char *default_);
-char** bc_config_get_list(bc_config_t *config, const char *section);
-void bc_config_free(bc_config_t *config);
-
-#endif /* _CONFIG_PARSER_H */
diff --git a/src/common/error.c b/src/common/error.c
deleted file mode 100644
index 03695e7..0000000
--- a/src/common/error.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include "error.h"
-#include "utils.h"
-
-
-bc_error_t*
-bc_error_new(bc_error_type_t type, const char *msg)
-{
- bc_error_t *err = bc_malloc(sizeof(bc_error_t));
- err->type = type;
- err->msg = bc_strdup(msg);
- return err;
-}
-
-
-bc_error_t*
-bc_error_new_printf(bc_error_type_t type, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = bc_strdup_vprintf(format, ap);
- va_end(ap);
- bc_error_t *rv = bc_error_new(type, tmp);
- free(tmp);
- return rv;
-}
-
-
-bc_error_t*
-bc_error_parser(bc_error_type_t type, const char *src, size_t src_len,
- size_t current, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *msg = bc_strdup_vprintf(format, ap);
- va_end(ap);
-
- size_t lineno = 1;
- size_t linestart = 0;
- size_t lineend = 0;
- size_t pos = 1;
-
- for (size_t i = 0; i < src_len; i++) {
- char c = src[i];
- if (i < current) {
- if ((i + 1) < src_len) {
- if ((c == '\n' && src[i + 1] == '\r') ||
- (c == '\r' && src[i + 1] == '\n'))
- {
- lineno++;
- i++;
- pos = 1;
- if ((i + 1) < src_len)
- linestart = i + 1;
- continue;
- }
- }
- if (c == '\n' || c == '\r') {
- lineno++;
- pos = 1;
- if ((i + 1) < src_len)
- linestart = i + 1;
- continue;
- }
- pos++;
- }
- else if (c == '\n' || c == '\r') {
- lineend = i;
- break;
- }
- }
-
- if (lineend <= linestart && src_len >= linestart)
- lineend = src_len;
-
- char *line = bc_strndup(src + linestart, lineend - linestart);
-
- bc_error_t *rv = NULL;
-
- if (line[0] == '\0') // "near" message isn't useful if line is empty
- rv = bc_error_new(type, msg);
- else
- rv = bc_error_new_printf(type,
- "%s\nError occurred near line %d, position %d: %s", msg, lineno,
- pos, line);
-
- free(msg);
- free(line);
-
- return rv;
-}
-
-
-// error handling is centralized here for the sake of simplicity :/
-void
-bc_error_print(bc_error_t *err, const char *prefix)
-{
- if (err == NULL)
- return;
-
- if (prefix != NULL)
- fprintf(stderr, "%s: ", prefix);
-
- switch(err->type) {
- case BC_ERROR_CONFIG_PARSER:
- fprintf(stderr, "error: config-parser: %s\n", err->msg);
- break;
- case BC_ERROR_FILE:
- fprintf(stderr, "error: file: %s\n", err->msg);
- break;
- case BLOGC_ERROR_SOURCE_PARSER:
- fprintf(stderr, "error: source: %s\n", err->msg);
- break;
- case BLOGC_ERROR_TEMPLATE_PARSER:
- fprintf(stderr, "error: template: %s\n", err->msg);
- break;
- case BLOGC_ERROR_LOADER:
- fprintf(stderr, "error: loader: %s\n", err->msg);
- break;
- case BLOGC_WARNING_DATETIME_PARSER:
- fprintf(stderr, "warning: datetime: %s\n", err->msg);
- break;
- case BLOGC_MAKE_ERROR_SETTINGS:
- fprintf(stderr, "error: settings: %s\n", err->msg);
- break;
- case BLOGC_MAKE_ERROR_EXEC:
- fprintf(stderr, "error: exec: %s\n", err->msg);
- break;
- case BLOGC_MAKE_ERROR_ATOM:
- fprintf(stderr, "error: atom: %s\n", err->msg);
- break;
- case BLOGC_MAKE_ERROR_UTILS:
- fprintf(stderr, "error: utils: %s\n", err->msg);
- break;
- default:
- fprintf(stderr, "error: %s\n", err->msg);
- }
-}
-
-
-void
-bc_error_free(bc_error_t *err)
-{
- if (err == NULL)
- return;
- free(err->msg);
- free(err);
-}
diff --git a/src/common/error.h b/src/common/error.h
deleted file mode 100644
index b85f006..0000000
--- a/src/common/error.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _ERROR_H
-#define _ERROR_H
-
-#include <stddef.h>
-
-// error handling is centralized here for the sake of simplicity :/
-typedef enum {
-
- // errors for src/common
- BC_ERROR_CONFIG_PARSER = 1,
- BC_ERROR_FILE,
-
- // errors for src/blogc
- BLOGC_ERROR_SOURCE_PARSER = 100,
- BLOGC_ERROR_TEMPLATE_PARSER,
- BLOGC_ERROR_LOADER,
- BLOGC_WARNING_DATETIME_PARSER,
-
- // errors for src/blogc-make
- BLOGC_MAKE_ERROR_SETTINGS = 300,
- BLOGC_MAKE_ERROR_EXEC,
- BLOGC_MAKE_ERROR_ATOM,
- BLOGC_MAKE_ERROR_UTILS,
-
-} bc_error_type_t;
-
-typedef struct {
- char *msg;
- bc_error_type_t type;
-} bc_error_t;
-
-bc_error_t* bc_error_new(bc_error_type_t type, const char *msg);
-bc_error_t* bc_error_new_printf(bc_error_type_t type, const char *format, ...);
-bc_error_t* bc_error_parser(bc_error_type_t type, const char *src,
- size_t src_len, size_t current, const char *format, ...);
-void bc_error_print(bc_error_t *err, const char *prefix);
-void bc_error_free(bc_error_t *err);
-
-#endif /* _ERROR_H */
diff --git a/src/common/file.c b/src/common/file.c
deleted file mode 100644
index 1e55f64..0000000
--- a/src/common/file.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include "file.h"
-#include "error.h"
-#include "utf8.h"
-#include "utils.h"
-
-
-char*
-bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
-{
- if (path == NULL || len == NULL || err == NULL || *err != NULL)
- return NULL;
-
- *len = 0;
- FILE *fp = fopen(path, "r");
-
- if (fp == NULL) {
- int tmp_errno = errno;
- *err = bc_error_new_printf(BC_ERROR_FILE,
- "Failed to open file (%s): %s", path, strerror(tmp_errno));
- return NULL;
- }
-
- bc_string_t *str = bc_string_new();
- char buffer[BC_FILE_CHUNK_SIZE];
- char *tmp;
-
- while (!feof(fp)) {
- size_t read_len = fread(buffer, sizeof(char), BC_FILE_CHUNK_SIZE, fp);
-
- tmp = buffer;
-
- if (utf8 && str->len == 0 && read_len > 0) {
- // skipping BOM before validation, for performance. should be safe
- // enough
- size_t skip = bc_utf8_skip_bom((uint8_t*) buffer, read_len);
- read_len -= skip;
- tmp += skip;
- }
-
- *len += read_len;
- bc_string_append_len(str, tmp, read_len);
- }
- fclose(fp);
-
- if (utf8 && !bc_utf8_validate_str(str)) {
- *err = bc_error_new_printf(BC_ERROR_FILE,
- "File content is not valid UTF-8: %s", path);
- bc_string_free(str, true);
- return NULL;
- }
-
- return bc_string_free(str, false);
-}
diff --git a/src/common/file.h b/src/common/file.h
deleted file mode 100644
index d002bf7..0000000
--- a/src/common/file.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _FILE_H
-#define _FILE_H
-
-#include <stddef.h>
-#include <stdbool.h>
-#include "error.h"
-
-#define BC_FILE_CHUNK_SIZE 1024
-
-char* bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err);
-
-#endif /* _FILE_H */
diff --git a/src/common/sort.c b/src/common/sort.c
deleted file mode 100644
index 3e24706..0000000
--- a/src/common/sort.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdbool.h>
-#include "utils.h"
-#include "sort.h"
-
-
-bc_slist_t*
-bc_slist_sort(bc_slist_t *l, bc_sort_func_t cmp)
-{
- if (l == NULL) {
- return NULL;
- }
-
- bool swapped = false;
- bc_slist_t *lptr = NULL;
- bc_slist_t *rptr = NULL;
-
- do {
- swapped = false;
- lptr = l;
-
- while (lptr->next != rptr) {
- if (0 < cmp(lptr->data, lptr->next->data)) {
- void *tmp = lptr->data;
- lptr->data = lptr->next->data;
- lptr->next->data = tmp;
- swapped = true;
- }
-
- lptr = lptr->next;
- }
-
- rptr = lptr;
- } while(swapped);
-
- return l;
-}
diff --git a/src/common/sort.h b/src/common/sort.h
deleted file mode 100644
index 9f4dda2..0000000
--- a/src/common/sort.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _SORT_H
-#define _SORT_H
-
-#include "utils.h"
-
-typedef int (*bc_sort_func_t) (const void *a, const void *b);
-
-bc_slist_t* bc_slist_sort(bc_slist_t *l, bc_sort_func_t cmp);
-
-#endif /* _SORT_H */
diff --git a/src/common/stdin.c b/src/common/stdin.c
deleted file mode 100644
index a460247..0000000
--- a/src/common/stdin.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdbool.h>
-#include <stdio.h>
-#include "utils.h"
-#include "stdin.h"
-
-
-// splitted in single file to make it easier to test
-char*
-bc_stdin_read(void)
-{
- int c;
- bc_string_t *rv = bc_string_new();
- while (EOF != (c = fgetc(stdin)))
- bc_string_append_c(rv, c);
- return bc_string_free(rv, false);
-}
diff --git a/src/common/stdin.h b/src/common/stdin.h
deleted file mode 100644
index e6bd7a0..0000000
--- a/src/common/stdin.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _STDIN_H
-#define _STDIN_H
-
-char* bc_stdin_read(void);
-
-#endif /* _STDIN_H */
diff --git a/src/common/utf8.c b/src/common/utf8.c
deleted file mode 100644
index f029e5b..0000000
--- a/src/common/utf8.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
- * Copyright (c) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-// Based on Bjoern Hoehrmann's algorithm.
-// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include "utils.h"
-
-#define UTF8_ACCEPT 0
-#define UTF8_REJECT 12
-
-
-static const uint8_t utf8d[] = {
- // The first part of the table maps bytes to character classes that
- // to reduce the size of the transition table and create bitmasks.
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
- 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
-
- // The second part is a transition table that maps a combination
- // of a state of the automaton and a character class to a state.
- 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
- 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
- 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
- 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
- 12,36,12,12,12,12,12,12,12,12,12,12,
-};
-
-
-static uint32_t inline
-decode(uint32_t* state, uint32_t* codep, uint32_t byte) {
- uint32_t type = utf8d[byte];
-
- *codep = (*state != UTF8_ACCEPT) ?
- (byte & 0x3fu) | (*codep << 6) :
- (0xff >> type) & (byte);
-
- *state = utf8d[256 + *state + type];
- return *state;
-}
-
-
-bool
-bc_utf8_validate(const uint8_t *str, size_t len)
-{
- uint32_t codepoint;
- uint32_t state = 0;
-
- for (size_t i = 0; i < len; i++)
- decode(&state, &codepoint, str[i]);
-
- return state == UTF8_ACCEPT;
-}
-
-
-bool
-bc_utf8_validate_str(bc_string_t *str)
-{
- return bc_utf8_validate((uint8_t*) str->str, str->len);
-}
-
-
-size_t
-bc_utf8_skip_bom(const uint8_t *str, size_t len)
-{
- if (len < 3)
- return 0;
-
- if (str[0] == 0xef && str[1] == 0xbb && str[2] == 0xbf)
- return 3;
-
- return 0;
-}
diff --git a/src/common/utf8.h b/src/common/utf8.h
deleted file mode 100644
index bf0f1ae..0000000
--- a/src/common/utf8.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _UTF_8_H
-#define _UTF_8_H
-
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include "utils.h"
-
-bool bc_utf8_validate(const uint8_t *str, size_t len);
-bool bc_utf8_validate_str(bc_string_t *str);
-size_t bc_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
deleted file mode 100644
index 692d1ce..0000000
--- a/src/common/utils.c
+++ /dev/null
@@ -1,701 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#define BC_STRING_CHUNK_SIZE 128
-
-#include <string.h>
-#include <strings.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "utils.h"
-
-
-void*
-bc_malloc(size_t size)
-{
- // simple things simple!
- void *rv = malloc(size);
- if (rv == NULL) {
- fprintf(stderr, "fatal: Failed to allocate memory!\n");
- abort();
- }
- return rv;
-}
-
-
-void*
-bc_realloc(void *ptr, size_t size)
-{
- // simple things even simpler :P
- void *rv = realloc(ptr, size);
- if (rv == NULL && size != 0) {
- fprintf(stderr, "fatal: Failed to reallocate memory!\n");
- free(ptr);
- abort();
- }
- return rv;
-}
-
-
-bc_slist_t*
-bc_slist_append(bc_slist_t *l, void *data)
-{
- bc_slist_t *node = bc_malloc(sizeof(bc_slist_t));
- node->data = data;
- node->next = NULL;
- if (l == NULL) {
- l = node;
- }
- else {
- bc_slist_t *tmp;
- for (tmp = l; tmp->next != NULL; tmp = tmp->next);
- tmp->next = node;
- }
- return l;
-}
-
-
-bc_slist_t*
-bc_slist_prepend(bc_slist_t *l, void *data)
-{
- bc_slist_t *node = bc_malloc(sizeof(bc_slist_t));
- node->data = data;
- node->next = l;
- l = node;
- return l;
-}
-
-
-void
-bc_slist_free_full(bc_slist_t *l, bc_free_func_t free_func)
-{
- while (l != NULL) {
- bc_slist_t *tmp = l->next;
- if ((free_func != NULL) && (l->data != NULL))
- free_func(l->data);
- free(l);
- l = tmp;
- }
-}
-
-
-void
-bc_slist_free(bc_slist_t *l)
-{
- bc_slist_free_full(l, NULL);
-}
-
-
-size_t
-bc_slist_length(bc_slist_t *l)
-{
- if (l == NULL)
- return 0;
- size_t i;
- bc_slist_t *tmp;
- for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++);
- return i;
-}
-
-
-char*
-bc_strdup(const char *s)
-{
- if (s == NULL)
- return NULL;
- size_t l = strlen(s);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l + 1);
- return tmp;
-}
-
-
-char*
-bc_strndup(const char *s, size_t n)
-{
- if (s == NULL)
- return NULL;
- size_t l = strnlen(s, n);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l);
- tmp[l] = '\0';
- return tmp;
-}
-
-
-char*
-bc_strdup_vprintf(const char *format, va_list ap)
-{
- va_list ap2;
- va_copy(ap2, ap);
- int l = vsnprintf(NULL, 0, format, ap2);
- va_end(ap2);
- if (l < 0)
- return NULL;
- char *tmp = malloc(l + 1);
- if (!tmp)
- return NULL;
- int l2 = vsnprintf(tmp, l + 1, format, ap);
- if (l2 < 0) {
- free(tmp);
- return NULL;
- }
- return tmp;
-}
-
-
-char*
-bc_strdup_printf(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = bc_strdup_vprintf(format, ap);
- va_end(ap);
- return tmp;
-}
-
-
-// locale-independent implementation of isspace
-bool
-bc_isspace(int c)
-{
- return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
-}
-
-
-bool
-bc_str_starts_with(const char *str, const char *prefix)
-{
- int str_l = strlen(str);
- int str_lp = strlen(prefix);
- if (str_lp > str_l)
- return false;
- return strncmp(str, prefix, str_lp) == 0;
-}
-
-
-bool
-bc_str_ends_with(const char *str, const char *suffix)
-{
- int str_l = strlen(str);
- int str_ls = strlen(suffix);
- if (str_ls > str_l)
- return false;
- return strcmp(str + str_l - str_ls, suffix) == 0;
-}
-
-
-char*
-bc_str_lstrip(char *str)
-{
- if (str == NULL)
- return NULL;
- int i;
- size_t str_len = strlen(str);
- for (i = 0; i < str_len; i++) {
- if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
- (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
- (str[i] != '\v'))
- {
- str += i;
- break;
- }
- if (i == str_len - 1) {
- str += str_len;
- break;
- }
- }
- return str;
-}
-
-
-char*
-bc_str_rstrip(char *str)
-{
- if (str == NULL)
- return NULL;
- int i;
- size_t str_len = strlen(str);
- for (i = str_len - 1; i >= 0; i--) {
- if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
- (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
- (str[i] != '\v'))
- {
- str[i + 1] = '\0';
- break;
- }
- if (i == 0) {
- str[0] = '\0';
- break;
- }
- }
- return str;
-}
-
-
-char*
-bc_str_strip(char *str)
-{
- return bc_str_lstrip(bc_str_rstrip(str));
-}
-
-
-char**
-bc_str_split(const char *str, char c, size_t max_pieces)
-{
- if (str == NULL)
- return NULL;
- char **rv = bc_malloc(sizeof(char*));
- size_t 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 = 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 = bc_realloc(rv, (count + 1) * sizeof(char*));
- rv[count] = NULL;
- return rv;
-}
-
-
-char*
-bc_str_replace(const char *str, const char search, const char *replace)
-{
- char **pieces = bc_str_split(str, search, 0);
- if (pieces == NULL)
- return NULL;
- char* rv = bc_strv_join(pieces, replace);
- bc_strv_free(pieces);
- if (rv == NULL)
- return bc_strdup(str);
- return rv;
-}
-
-
-char*
-bc_str_find(const char *str, char c)
-{
- // this is somewhat similar to strchr, but respects '\' escaping.
- if (str == NULL)
- return NULL;
- if (c == '\0')
- return (char*) str + strlen(str);
- for (size_t i = 0; str[i] != '\0'; i++) {
- if (str[i] == '\\') {
- i++;
- continue;
- }
- if (str[i] == c) {
- return (char*) str + i;
- }
- }
- return NULL;
-}
-
-
-bool
-bc_str_to_bool(const char *str)
-{
- if (str == NULL)
- return false;
-
- if (0 == strcmp(str, "1"))
- return true;
-
- if (0 == strcasecmp(str, "y"))
- return true;
-
- if (0 == strcasecmp(str, "yes"))
- return true;
-
- if (0 == strcasecmp(str, "true"))
- return true;
-
- if (0 == strcasecmp(str, "on"))
- return true;
-
- return false;
-}
-
-
-void
-bc_strv_free(char **strv)
-{
- if (strv == NULL)
- return;
- for (size_t i = 0; strv[i] != NULL; i++)
- free(strv[i]);
- free(strv);
-}
-
-
-char*
-bc_strv_join(char **strv, const char *separator)
-{
- if (strv == NULL || separator == NULL)
- return NULL;
- bc_string_t *str = bc_string_new();
- for (size_t i = 0; strv[i] != NULL; i++) {
- str = bc_string_append(str, strv[i]);
- if (strv[i + 1] != NULL)
- str = bc_string_append(str, separator);
- }
- return bc_string_free(str, false);
-}
-
-
-size_t
-bc_strv_length(char **strv)
-{
- if (strv == NULL)
- return 0;
- size_t i;
- for (i = 0; strv[i] != NULL; i++);
- return i;
-}
-
-
-bc_string_t*
-bc_string_new(void)
-{
- 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 = bc_string_append(rv, "");
-
- return rv;
-}
-
-
-char*
-bc_string_free(bc_string_t *str, bool free_str)
-{
- if (str == NULL)
- return NULL;
- char *rv = NULL;
- if (free_str)
- free(str->str);
- else
- rv = str->str;
- free(str);
- return rv;
-}
-
-
-bc_string_t*
-bc_string_dup(bc_string_t *str)
-{
- if (str == NULL)
- return NULL;
- bc_string_t* new = bc_string_new();
- return bc_string_append_len(new, str->str, str->len);
-}
-
-
-bc_string_t*
-bc_string_append_len(bc_string_t *str, const char *suffix, size_t len)
-{
- if (str == NULL)
- return NULL;
- if (suffix == NULL)
- return str;
- size_t old_len = str->len;
- str->len += len;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / BC_STRING_CHUNK_SIZE) + 1) * BC_STRING_CHUNK_SIZE;
- str->str = bc_realloc(str->str, str->allocated_len);
- }
- memcpy(str->str + old_len, suffix, len);
- str->str[str->len] = '\0';
- return str;
-}
-
-
-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 bc_string_append_len(str, my_suffix, strlen(my_suffix));
-}
-
-
-bc_string_t*
-bc_string_append_c(bc_string_t *str, char c)
-{
- if (str == NULL)
- return NULL;
- size_t old_len = str->len;
- str->len += 1;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / BC_STRING_CHUNK_SIZE) + 1) * BC_STRING_CHUNK_SIZE;
- str->str = bc_realloc(str->str, str->allocated_len);
- }
- str->str[old_len] = c;
- str->str[str->len] = '\0';
- return str;
-}
-
-
-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 = bc_strdup_vprintf(format, ap);
- va_end(ap);
- str = bc_string_append(str, tmp);
- free(tmp);
- return str;
-}
-
-
-bc_string_t*
-bc_string_append_escaped(bc_string_t *str, const char *suffix)
-{
- if (str == NULL)
- return NULL;
- if (suffix == NULL)
- return str;
- bool escaped = false;
- for (size_t i = 0; suffix[i] != '\0'; i++) {
- if (suffix[i] == '\\' && !escaped) {
- escaped = true;
- continue;
- }
- escaped = false;
- str = bc_string_append_c(str, suffix[i]);
- }
- return str;
-}
-
-
-bc_trie_t*
-bc_trie_new(bc_free_func_t free_func)
-{
- bc_trie_t *trie = bc_malloc(sizeof(bc_trie_t));
- trie->root = NULL;
- trie->free_func = free_func;
- return trie;
-}
-
-
-static void
-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);
- bc_trie_free_node(trie, node->next);
- bc_trie_free_node(trie, node->child);
- free(node);
-}
-
-
-void
-bc_trie_free(bc_trie_t *trie)
-{
- if (trie == NULL)
- return;
- bc_trie_free_node(trie, trie->root);
- free(trie);
-}
-
-
-void
-bc_trie_insert(bc_trie_t *trie, const char *key, void *data)
-{
- if (trie == NULL || key == NULL || data == NULL)
- return;
-
- 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 = bc_malloc(sizeof(bc_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- if (trie->root == NULL)
- trie->root = current;
- else
- parent->child = current;
- parent = current;
- goto clean;
- }
-
- tmp = parent == NULL ? trie->root : parent->child;
- previous = NULL;
-
- while (tmp != NULL && tmp->key != *key) {
- previous = tmp;
- tmp = tmp->next;
- }
-
- parent = tmp;
-
- if (previous == NULL || parent != NULL)
- goto clean;
-
- current = bc_malloc(sizeof(bc_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- previous->next = current;
- parent = current;
-
-clean:
- if (*key == '\0') {
- if (parent->data != NULL && trie->free_func != NULL)
- trie->free_func(parent->data);
- parent->data = data;
- break;
- }
- key++;
- }
-}
-
-
-void*
-bc_trie_lookup(bc_trie_t *trie, const char *key)
-{
- if (trie == NULL || trie->root == NULL || key == NULL)
- return NULL;
-
- bc_trie_node_t *parent = trie->root;
- bc_trie_node_t *tmp;
- while (1) {
- for (tmp = parent; tmp != NULL; tmp = tmp->next) {
-
- if (tmp->key == *key) {
- if (tmp->key == '\0')
- return tmp->data;
- parent = tmp->child;
- break;
- }
- }
- if (tmp == NULL)
- return NULL;
-
- if (*key == '\0')
- break;
- key++;
- }
- return NULL;
-}
-
-
-static void
-bc_trie_size_node(bc_trie_node_t *node, size_t *count)
-{
- if (node == NULL || count == NULL)
- return;
-
- if (node->key == '\0')
- (*count)++;
-
- bc_trie_size_node(node->next, count);
- bc_trie_size_node(node->child, count);
-}
-
-
-size_t
-bc_trie_size(bc_trie_t *trie)
-{
- if (trie == NULL)
- return 0;
-
- size_t count = 0;
- bc_trie_size_node(trie->root, &count);
- return count;
-}
-
-
-static void
-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;
-
- if (node->key == '\0')
- func(str->str, node->data, user_data);
-
- if (node->child != NULL) {
- 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)
- bc_trie_foreach_node(node->next, str, func, user_data);
-}
-
-
-void
-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;
-
- bc_string_t *str = bc_string_new();
- bc_trie_foreach_node(trie->root, str, func, user_data);
- bc_string_free(str, true);
-}
-
-
-char*
-bc_shell_quote(const char *command)
-{
- bc_string_t *rv = bc_string_new();
- bc_string_append_c(rv, '\'');
- if (command != NULL) {
- for (size_t i = 0; i < strlen(command); i++) {
- switch (command[i]) {
- case '!':
- bc_string_append(rv, "'\\!'");
- break;
- case '\'':
- bc_string_append(rv, "'\\''");
- break;
- default:
- bc_string_append_c(rv, command[i]);
- }
- }
- }
- bc_string_append_c(rv, '\'');
- return bc_string_free(rv, false);
-}
diff --git a/src/common/utils.h b/src/common/utils.h
deleted file mode 100644
index 94c3356..0000000
--- a/src/common/utils.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _UTILS_H
-#define _UTILS_H
-
-#include <stddef.h>
-#include <stdarg.h>
-#include <stdbool.h>
-
-
-// memory
-
-typedef void (*bc_free_func_t) (void *ptr);
-
-void* bc_malloc(size_t size);
-void* bc_realloc(void *ptr, size_t size);
-
-
-// slist
-
-typedef struct _bc_slist_t {
- struct _bc_slist_t *next;
- void *data;
-} bc_slist_t;
-
-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* 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_isspace(int c);
-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, size_t max_pieces);
-char* bc_str_replace(const char *str, const char search, const char *replace);
-char* bc_str_find(const char *str, char c);
-bool bc_str_to_bool(const char *str);
-void bc_strv_free(char **strv);
-char* bc_strv_join(char **strv, const char *separator);
-size_t bc_strv_length(char **strv);
-
-
-// string
-
-typedef struct {
- char *str;
- size_t len;
- size_t allocated_len;
-} bc_string_t;
-
-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 _bc_trie_node_t {
- char key;
- void *data;
- struct _bc_trie_node_t *next, *child;
-} bc_trie_node_t;
-
-struct _bc_trie_t {
- bc_trie_node_t *root;
- bc_free_func_t free_func;
-};
-
-typedef struct _bc_trie_t bc_trie_t;
-
-typedef void (*bc_trie_foreach_func_t)(const char *key, void *data,
- void *user_data);
-
-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);
-
-
-// shell
-
-char* bc_shell_quote(const char *command);
-
-#endif /* _UTILS_H */
diff --git a/tests/blogc-git-receiver/check_settings.c b/tests/blogc-git-receiver/check_settings.c
index cb12037..6de5b32 100644
--- a/tests/blogc-git-receiver/check_settings.c
+++ b/tests/blogc-git-receiver/check_settings.c
@@ -12,8 +12,8 @@
#include <cmocka.h>
#include <string.h>
#include <stdlib.h>
-#include "../../src/common/config-parser.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc-git-receiver/settings.h"
@@ -24,21 +24,21 @@ __wrap_realpath(const char *path, char *resolved_path)
if (real_path == NULL)
return NULL;
assert_string_equal(path, real_path);
- return bc_strdup(real_path);
+ return sb_strdup(real_path);
}
static void
test_settings_get_section(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
setenv("HOME", "/home/blogc", 1);
- bc_config_t *config = bc_config_parse("", 0, NULL, &err);
+ sb_config_t *config = sb_config_parse("", 0, NULL, &err);
assert_null(err);
assert_null(bgr_settings_get_section(config, "/home/blogc/repos/foo.git"));
- bc_config_free(config);
+ sb_config_free(config);
will_return(__wrap_realpath, NULL);
will_return(__wrap_realpath, "/home/blogc/repos/bar.git");
@@ -52,12 +52,12 @@ test_settings_get_section(void **state)
"[repo:baz.git]\n"
"mirror = baz\n"
"\n";
- config = bc_config_parse(conf, strlen(conf), NULL, &err);
+ config = sb_config_parse(conf, strlen(conf), NULL, &err);
assert_null(err);
char *s = bgr_settings_get_section(config, "/home/blogc/repos/bar.git");
assert_string_equal(s, "repo:bar.git");
free(s);
- bc_config_free(config);
+ sb_config_free(config);
setenv("BLOGC_GIT_RECEIVER_BASE_DIR", "/home/bola", 1);
will_return(__wrap_realpath, NULL);
@@ -72,12 +72,12 @@ test_settings_get_section(void **state)
"[repo:asd/baz.git]\n"
"mirror = baz\n"
"\n";
- config = bc_config_parse(conf, strlen(conf), NULL, &err);
+ config = sb_config_parse(conf, strlen(conf), NULL, &err);
assert_null(err);
s = bgr_settings_get_section(config, "/home/bola/repos/asd/bar.git");
assert_string_equal(s, "repo:asd/bar.git");
free(s);
- bc_config_free(config);
+ sb_config_free(config);
}
diff --git a/tests/blogc-make/check_atom.c b/tests/blogc-make/check_atom.c
index 94c9a37..e9e24d3 100644
--- a/tests/blogc-make/check_atom.c
+++ b/tests/blogc-make/check_atom.c
@@ -10,26 +10,23 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/atom.h"
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/file.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
static void
test_atom_generate_empty_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
char *cmp = bm_atom_generate(settings);
@@ -68,7 +65,7 @@ test_atom_generate_empty_file(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -76,12 +73,12 @@ test_atom_generate_empty_file(void **state)
static void
test_atom_generate_empty_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
char *cmp = bm_atom_generate(settings);
@@ -120,7 +117,7 @@ test_atom_generate_empty_dir(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -128,12 +125,12 @@ test_atom_generate_empty_dir(void **state)
static void
test_atom_generate_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
char *cmp = bm_atom_generate(settings);
@@ -172,7 +169,7 @@ test_atom_generate_file(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -180,12 +177,12 @@ test_atom_generate_file(void **state)
static void
test_atom_generate_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
char *cmp = bm_atom_generate(settings);
@@ -224,7 +221,7 @@ test_atom_generate_dir(void **state)
"</feed>\n");
free(cmp);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -232,21 +229,21 @@ test_atom_generate_dir(void **state)
static void
test_atom_empty_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -286,7 +283,7 @@ test_atom_empty_file(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -294,21 +291,21 @@ test_atom_empty_file(void **state)
static void
test_atom_empty_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -348,7 +345,7 @@ test_atom_empty_dir(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -356,21 +353,21 @@ test_atom_empty_dir(void **state)
static void
test_atom_file(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -410,7 +407,7 @@ test_atom_file(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -418,21 +415,21 @@ test_atom_file(void **state)
static void
test_atom_dir(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup("/index.xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup("/index.html"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup("/index.xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup("/index.html"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_non_null(rv);
assert_null(err);
size_t cmp_len;
- char *cmp = bc_file_get_contents(rv, true, &cmp_len, &err);
+ char *cmp = sb_file_get_contents_utf8(rv, &cmp_len, &err);
assert_non_null(cmp);
assert_null(err);
@@ -472,7 +469,7 @@ test_atom_dir(void **state)
free(cmp);
bm_atom_destroy(rv);
free(rv);
- bc_trie_free(settings->settings);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -480,27 +477,26 @@ test_atom_dir(void **state)
static void
test_atom_legacy_entry_id_empty(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup(""));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
- bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup(""));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+ sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_null(rv);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM);
- assert_string_equal(err->msg,
- "'atom_legacy_entry_id' setting is not supported anymore. see "
+ assert_string_equal(sb_error_to_string(err),
+ "atom: 'atom_legacy_entry_id' setting is not supported anymore. see "
"https://blogc.rgm.io/news/blogc-0.16.1/ for details");
- bc_error_free(err);
- bc_trie_free(settings->settings);
+ sb_error_free(err);
+ sb_trie_free(settings->settings);
free(settings);
}
@@ -508,27 +504,26 @@ test_atom_legacy_entry_id_empty(void **state)
static void
test_atom_legacy_entry_id(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "atom_prefix", bc_strdup("atom"));
- bc_trie_insert(settings->settings, "atom_ext", bc_strdup(".xml"));
- bc_trie_insert(settings->settings, "post_prefix", bc_strdup("post"));
- bc_trie_insert(settings->settings, "html_ext", bc_strdup(".html"));
- bc_trie_insert(settings->settings, "atom_legacy_entry_id", bc_strdup("1"));
-
- bc_error_t *err = NULL;
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "atom_prefix", sb_strdup("atom"));
+ sb_trie_insert(settings->settings, "atom_ext", sb_strdup(".xml"));
+ sb_trie_insert(settings->settings, "post_prefix", sb_strdup("post"));
+ sb_trie_insert(settings->settings, "html_ext", sb_strdup(".html"));
+ sb_trie_insert(settings->settings, "atom_legacy_entry_id", sb_strdup("1"));
+
+ sb_error_t *err = NULL;
char *rv = bm_atom_deploy(settings, &err);
assert_null(rv);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_ATOM);
- assert_string_equal(err->msg,
- "'atom_legacy_entry_id' setting is not supported anymore. see "
+ assert_string_equal(sb_error_to_string(err),
+ "atom: 'atom_legacy_entry_id' setting is not supported anymore. see "
"https://blogc.rgm.io/news/blogc-0.16.1/ for details");
- bc_error_free(err);
- bc_trie_free(settings->settings);
+ sb_error_free(err);
+ sb_trie_free(settings->settings);
free(settings);
}
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index 6812496..c5d1d4e 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -14,14 +14,13 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <squareball.h>
#include "../../src/blogc-make/exec.h"
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/utils.h"
int
@@ -75,16 +74,16 @@ test_find_binary(void **state)
static void
test_build_blogc_cmd_with_settings(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
@@ -113,10 +112,10 @@ test_build_blogc_cmd_with_settings(void **state)
"LC_ALL='en_US.utf8' blogc -D FOO='BAR' -D BAR='BAZ'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
free(settings);
}
@@ -124,16 +123,16 @@ test_build_blogc_cmd_with_settings(void **state)
static void
test_build_blogc_cmd_with_settings_and_dev(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
@@ -166,10 +165,10 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
"-D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
free(settings);
}
@@ -177,17 +176,17 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
static void
test_build_blogc_cmd_with_settings_and_tags(void **state)
{
- bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
- settings->settings = bc_trie_new(free);
- bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
- settings->global = bc_trie_new(free);
- bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
- bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
- settings->tags = bc_str_split("asd foo bar", ' ', 0);
+ bm_settings_t *settings = sb_malloc(sizeof(bm_settings_t));
+ settings->settings = sb_trie_new(free);
+ sb_trie_insert(settings->settings, "locale", sb_strdup("en_US.utf8"));
+ settings->global = sb_trie_new(free);
+ sb_trie_insert(settings->global, "FOO", sb_strdup("BAR"));
+ sb_trie_insert(settings->global, "BAR", sb_strdup("BAZ"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
+ settings->tags = sb_str_split("asd foo bar", ' ', 0);
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, local, NULL,
true, NULL, "main.tmpl", "foo.html", true, true);
@@ -219,11 +218,11 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
"-D BAR='BAZ' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
- bc_trie_free(settings->settings);
- bc_trie_free(settings->global);
- bc_strv_free(settings->tags);
+ sb_trie_free(local);
+ sb_trie_free(variables);
+ sb_trie_free(settings->settings);
+ sb_trie_free(settings->global);
+ sb_strv_free(settings->tags);
free(settings);
}
@@ -231,10 +230,10 @@ test_build_blogc_cmd_with_settings_and_tags(void **state)
static void
test_build_blogc_cmd_without_settings(void **state)
{
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, NULL,
true, NULL, "main.tmpl", "foo.html", false, true);
@@ -261,18 +260,18 @@ test_build_blogc_cmd_without_settings(void **state)
"blogc");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
+ sb_trie_free(local);
+ sb_trie_free(variables);
}
static void
test_build_blogc_cmd_print(void **state)
{
- bc_trie_t *variables = bc_trie_new(free);
- bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
- bc_trie_t *local = bc_trie_new(free);
- bc_trie_insert(local, "ASD", bc_strdup("QWE"));
+ sb_trie_t *variables = sb_trie_new(free);
+ sb_trie_insert(variables, "LOL", sb_strdup("HEHE"));
+ sb_trie_t *local = sb_trie_new(free);
+ sb_trie_insert(local, "ASD", sb_strdup("QWE"));
char *rv = bm_exec_build_blogc_cmd("blogc", NULL, variables, local, "LOL",
false, NULL, NULL, NULL, false, true);
@@ -296,8 +295,8 @@ test_build_blogc_cmd_print(void **state)
"blogc -p LOL");
free(rv);
- bc_trie_free(local);
- bc_trie_free(variables);
+ sb_trie_free(local);
+ sb_trie_free(variables);
}
diff --git a/tests/blogc-make/check_rules.c b/tests/blogc-make/check_rules.c
index ed2e46a..25ba0e1 100644
--- a/tests/blogc-make/check_rules.c
+++ b/tests/blogc-make/check_rules.c
@@ -10,73 +10,72 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/rules.h"
-#include "../../src/common/utils.h"
static void
test_rule_parse_args(void **state)
{
- bc_trie_t *t = bm_rule_parse_args("bola:foo=" + 4);
+ sb_trie_t *t = bm_rule_parse_args("bola:foo=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=,baz=lol,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "");
+ sb_trie_free(t);
t = bm_rule_parse_args("bola:foo=bar,baz=lol,asd=qwe" + 4);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 3);
- assert_string_equal(bc_trie_lookup(t, "foo"), "bar");
- assert_string_equal(bc_trie_lookup(t, "baz"), "lol");
- assert_string_equal(bc_trie_lookup(t, "asd"), "qwe");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 3);
+ assert_string_equal(sb_trie_lookup(t, "foo"), "bar");
+ assert_string_equal(sb_trie_lookup(t, "baz"), "lol");
+ assert_string_equal(sb_trie_lookup(t, "asd"), "qwe");
+ sb_trie_free(t);
}
diff --git a/tests/blogc-make/check_settings.c b/tests/blogc-make/check_settings.c
index 7cebedc..3f091dd 100644
--- a/tests/blogc-make/check_settings.c
+++ b/tests/blogc-make/check_settings.c
@@ -10,27 +10,24 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
#include <string.h>
+#include <squareball.h>
#include "../../src/blogc-make/settings.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
static void
test_settings_empty(void **state)
{
const char *a = "";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [global] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -45,14 +42,13 @@ test_settings(void **state)
"[global]\n"
"BOLA = asd\n"
"GUDA = qwe\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[global] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [global] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -67,14 +63,13 @@ test_settings_env(void **state)
"[environment]\n"
"BOLA = asd\n"
"GUDA = qwe\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(s);
- assert_int_equal(err->type, BLOGC_MAKE_ERROR_SETTINGS);
- assert_string_equal(err->msg,
- "[environment] key required but not found or empty: AUTHOR_NAME");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "settings: [environment] key required but not found or empty: AUTHOR_NAME");
+ sb_error_free(err);
}
@@ -113,36 +108,36 @@ test_settings2(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -202,36 +197,36 @@ test_settings_env2(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
@@ -291,36 +286,36 @@ test_settings_copy_files(void **state)
"jjjj\n"
"kkkk\n"
"llll\n";
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
bm_settings_t *s = bm_settings_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(s);
- assert_int_equal(bc_trie_size(s->global), 7);
- assert_string_equal(bc_trie_lookup(s->global, "BOLA"), "asd");
- assert_string_equal(bc_trie_lookup(s->global, "GUDA"), "qwe");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
- assert_string_equal(bc_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
- assert_string_equal(bc_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
- assert_string_equal(bc_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
- assert_int_equal(bc_trie_size(s->settings), 16);
- assert_string_equal(bc_trie_lookup(s->settings, "source_ext"), ".txt");
- assert_string_equal(bc_trie_lookup(s->settings, "html_ext"), "/index.html");
- assert_string_equal(bc_trie_lookup(s->settings, "content_dir"), "guda");
- assert_string_equal(bc_trie_lookup(s->settings, "template_dir"), "templates");
- assert_string_equal(bc_trie_lookup(s->settings, "main_template"), "foo.tmpl");
- assert_string_equal(bc_trie_lookup(s->settings, "date_format"),
+ assert_int_equal(sb_trie_size(s->global), 7);
+ assert_string_equal(sb_trie_lookup(s->global, "BOLA"), "asd");
+ assert_string_equal(sb_trie_lookup(s->global, "GUDA"), "qwe");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_NAME"), "chunda");
+ assert_string_equal(sb_trie_lookup(s->global, "AUTHOR_EMAIL"), "chunda@example.com");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TITLE"), "Fuuuuuuuuu");
+ assert_string_equal(sb_trie_lookup(s->global, "SITE_TAGLINE"), "My cool tagline");
+ assert_string_equal(sb_trie_lookup(s->global, "BASE_DOMAIN"), "http://example.com");
+ assert_int_equal(sb_trie_size(s->settings), 16);
+ assert_string_equal(sb_trie_lookup(s->settings, "source_ext"), ".txt");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_ext"), "/index.html");
+ assert_string_equal(sb_trie_lookup(s->settings, "content_dir"), "guda");
+ assert_string_equal(sb_trie_lookup(s->settings, "template_dir"), "templates");
+ assert_string_equal(sb_trie_lookup(s->settings, "main_template"), "foo.tmpl");
+ assert_string_equal(sb_trie_lookup(s->settings, "date_format"),
"%b %d, %Y, %I:%M %p GMT");
- assert_string_equal(bc_trie_lookup(s->settings, "posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_prefix"), "atom");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_ext"), ".xml");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_posts_per_page"), "10");
- assert_string_equal(bc_trie_lookup(s->settings, "pagination_prefix"), "page");
- assert_string_equal(bc_trie_lookup(s->settings, "post_prefix"), "post");
- assert_string_equal(bc_trie_lookup(s->settings, "tag_prefix"), "tag");
- assert_string_equal(bc_trie_lookup(s->settings, "html_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "atom_order"), "DESC");
- assert_string_equal(bc_trie_lookup(s->settings, "index_prefix"), "");
+ assert_string_equal(sb_trie_lookup(s->settings, "posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_prefix"), "atom");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_ext"), ".xml");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_posts_per_page"), "10");
+ assert_string_equal(sb_trie_lookup(s->settings, "pagination_prefix"), "page");
+ assert_string_equal(sb_trie_lookup(s->settings, "post_prefix"), "post");
+ assert_string_equal(sb_trie_lookup(s->settings, "tag_prefix"), "tag");
+ assert_string_equal(sb_trie_lookup(s->settings, "html_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "atom_order"), "DESC");
+ assert_string_equal(sb_trie_lookup(s->settings, "index_prefix"), "");
assert_non_null(s->posts);
assert_string_equal(s->posts[0], "aaaa");
assert_string_equal(s->posts[1], "bbbb");
diff --git a/tests/blogc-make/check_utils.c b/tests/blogc-make/check_utils.c
index 5b3614d..852c0f7 100644
--- a/tests/blogc-make/check_utils.c
+++ b/tests/blogc-make/check_utils.c
@@ -10,11 +10,10 @@
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-
#include <stdlib.h>
+#include <squareball.h>
#include "../../src/blogc-make/utils.h"
-#include "../../src/common/utils.h"
static void
diff --git a/tests/blogc-runserver/check_httpd_utils.c b/tests/blogc-runserver/check_httpd_utils.c
index 3e21e63..69c2a5b 100644
--- a/tests/blogc-runserver/check_httpd_utils.c
+++ b/tests/blogc-runserver/check_httpd_utils.c
@@ -12,7 +12,8 @@
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc-runserver/httpd-utils.h"
@@ -89,7 +90,7 @@ static void
test_urldecode(void **state)
{
for (size_t i = 0; i < 128; i++) {
- char *t = bc_strdup_printf("%%%02x", i);
+ char *t = sb_strdup_printf("%%%02x", i);
char *r = br_urldecode(t);
assert_int_equal(r[0], i);
assert_int_equal(r[1], 0);
diff --git a/tests/blogc/check_datetime_parser.c b/tests/blogc/check_datetime_parser.c
index 44c1af8..2a79bd4 100644
--- a/tests/blogc/check_datetime_parser.c
+++ b/tests/blogc/check_datetime_parser.c
@@ -12,14 +12,15 @@
#include <cmocka.h>
#include <stdlib.h>
#include <locale.h>
-#include "../../src/common/error.h"
+#include <squareball.h>
+
#include "../../src/blogc/datetime-parser.h"
static void
test_convert_datetime(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -31,7 +32,7 @@ test_convert_datetime(void **state)
static void
test_convert_datetime_implicit_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -43,7 +44,7 @@ test_convert_datetime_implicit_seconds(void **state)
static void
test_convert_datetime_implicit_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -55,7 +56,7 @@ test_convert_datetime_implicit_minutes(void **state)
static void
test_convert_datetime_implicit_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(err);
@@ -67,529 +68,491 @@ test_convert_datetime_implicit_hours(void **state)
static void
test_convert_datetime_invalid_formats(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '20', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '20', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '201', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '201', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-3', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-3', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 ', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 ', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT",
&err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 12:1', formats ""allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
err = NULL;
dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT",
&err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: "
"'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and "
"'yyyy-mm-dd'.");
- bc_error_free(err);
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("a010-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2a10-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_3rd_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("20a0-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_4th_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("201a-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_year(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("1899-11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid year. Found 1899, must be >= 1900.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid year. Found 1899, must be >= 1900.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_hyphen(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010 11-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between year and month. Found ' ', must be '-'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between year and month. Found ' ', must be '-'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-a1-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-1a-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_month(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-13-30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid month. Found 13, must be >= 1 and <= 12.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid month. Found 13, must be >= 1 and <= 12.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_hyphen(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11 30 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between month and day. Found ' ', must be '-'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between month and day. Found ' ', must be '-'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-a0 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-3a 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_day(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-32 12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid day. Found 32, must be >= 1 and <= 31.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid day. Found 32, must be >= 1 and <= 31.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_space(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30-12:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between date and time. Found '-', must be ' ' "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between date and time. Found '-', must be ' ' "
"(empty space).");
- bc_error_free(err);
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 a2:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 1a:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_hours(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 24:13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid hours. Found 24, must be >= 0 and <= 23.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid hours. Found 24, must be >= 0 and <= 23.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_colon(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12 13:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between hours and minutes. Found ' ', must be ':'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between hours and minutes. Found ' ', must be ':'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:a3:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_minutes(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:1a:14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_colon(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13 14",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid separator between minutes and seconds. Found ' ', must be ':'.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid separator between minutes and seconds. Found ' ', must be ':'.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_1st_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:a4",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_2nd_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-11-30 12:13:1a",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_seconds(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 12:13:69",
"%b %d, %Y, %I:%M:%S %p GMT", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Invalid seconds. Found 69, must be >= 0 and <= 60.");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Invalid seconds. Found 69, must be >= 0 and <= 60.");
+ sb_error_free(err);
}
static void
test_convert_datetime_invalid_format_long(void **state)
{
- bc_error_t *err = NULL;
+ sb_error_t *err = NULL;
char *dt = blogc_convert_datetime("2010-12-30 12:13:14",
"bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
"yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
@@ -608,9 +571,8 @@ test_convert_datetime_invalid_format_long(void **state)
"jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err);
assert_null(dt);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER);
- assert_string_equal(err->msg,
- "Failed to format DATE variable, FORMAT is too long: "
+ assert_string_equal(sb_error_to_string(err),
+ "datetime: Failed to format DATE variable, FORMAT is too long: "
"bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb"
"yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk"
"tywccrvnraagtnedwdjtfobinobbymanppwqxubxeepotdyxuvircyshpmtrqyvbivtycs"
@@ -626,7 +588,7 @@ test_convert_datetime_invalid_format_long(void **state)
"uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq"
"gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj"
"jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg");
- bc_error_free(err);
+ sb_error_free(err);
}
diff --git a/tests/blogc/check_funcvars.c b/tests/blogc/check_funcvars.c
index 9d094d5..2c4acb0 100644
--- a/tests/blogc/check_funcvars.c
+++ b/tests/blogc/check_funcvars.c
@@ -13,16 +13,15 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/funcvars.h"
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
char *rv = mock_type(char*);
*len = strlen(rv);
return rv;
@@ -32,40 +31,40 @@ __wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t
static void
test_funcvars_eval(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
blogc_funcvars_eval(t, NULL);
blogc_funcvars_eval(t, "");
blogc_funcvars_eval(t, "BOLA");
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
- bc_trie_insert(t, "BOLA", bc_strdup("GUDA"));
+ sb_trie_insert(t, "BOLA", sb_strdup("GUDA"));
blogc_funcvars_eval(t, "BOLA");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_int_equal(sb_trie_size(t), 1);
- bc_trie_free(t);
+ sb_trie_free(t);
}
static void
test_funcvars_eval_mocked(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
// this is the only function that isn't hidden behind conditional macros
// as of when this test was written. the other functions should be tested
// separately
- will_return(__wrap_bc_file_get_contents, bc_strdup("asd/docker/asd"));
+ will_return(__wrap_sb_file_get_contents, sb_strdup("asd/docker/asd"));
blogc_funcvars_eval(t, "BLOGC_SYSINFO_INSIDE_DOCKER");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
+ assert_int_equal(sb_trie_size(t), 1);
// this specific function call is cached, so calling it again should not
- // call bc_file_get_contents_again
+ // call sb_file_get_contents_again
blogc_funcvars_eval(t, "BLOGC_SYSINFO_INSIDE_DOCKER");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
- assert_int_equal(bc_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_INSIDE_DOCKER"), "1");
+ assert_int_equal(sb_trie_size(t), 1);
- bc_trie_free(t);
+ sb_trie_free(t);
}
diff --git a/tests/blogc/check_loader.c b/tests/blogc/check_loader.c
index d65f418..9510a3d 100644
--- a/tests/blogc/check_loader.c
+++ b/tests/blogc/check_loader.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/template-parser.h"
#include "../../src/blogc/loader.h"
@@ -50,9 +50,8 @@ test_get_filename(void **state)
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents_utf8(const char *path, size_t *len, sb_error_t **err)
{
- assert_true(utf8);
assert_null(*err);
const char *_path = mock_type(const char*);
if (_path != NULL)
@@ -68,13 +67,13 @@ __wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t
static void
test_template_parse_from_file(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola");
- will_return(__wrap_bc_file_get_contents, bc_strdup("{{ BOLA }}\n"));
- bc_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup("{{ BOLA }}\n"));
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_non_null(l);
- assert_int_equal(bc_slist_length(l), 2);
+ assert_int_equal(sb_slist_length(l), 2);
blogc_template_free_ast(l);
}
@@ -82,10 +81,10 @@ test_template_parse_from_file(void **state)
static void
test_template_parse_from_file_null(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola");
- will_return(__wrap_bc_file_get_contents, NULL);
- bc_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola");
+ will_return(__wrap_sb_file_get_contents_utf8, NULL);
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_null(l);
}
@@ -94,33 +93,33 @@ test_template_parse_from_file_null(void **state)
static void
test_source_parse_from_file(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- bc_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_trie_size(t), 6);
- assert_string_equal(bc_trie_lookup(t, "ASD"), "123");
- assert_string_equal(bc_trie_lookup(t, "FILENAME"), "bola");
- assert_string_equal(bc_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(t, "RAW_CONTENT"), "bola");
- assert_string_equal(bc_trie_lookup(t, "DESCRIPTION"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 6);
+ assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
+ assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola");
+ sb_trie_free(t);
}
static void
test_source_parse_from_file_null(void **state)
{
- bc_error_t *err = NULL;
- will_return(__wrap_bc_file_get_contents, "bola.txt");
- will_return(__wrap_bc_file_get_contents, NULL);
- bc_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_error_t *err = NULL;
+ will_return(__wrap_sb_file_get_contents_utf8, "bola.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, NULL);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_null(t);
}
@@ -129,813 +128,811 @@ test_source_parse_from_file_null(void **state)
static void
test_source_parse_from_files(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 4);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 4);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-02 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2001-02-01 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-01 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2001-02-01 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_reverse(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_REVERSE", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_REVERSE", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_REVERSE"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_REVERSE"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort_reverse(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-02 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2001-02-01 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_REVERSE", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_REVERSE", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 6);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_REVERSE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-01 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 6);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_REVERSE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-01 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_tag(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_TAG", bc_strdup("chunda"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 5);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_TAG"), "chunda");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page2(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("3"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("3"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 11);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola6");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "3");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "3");
- assert_string_equal(bc_trie_lookup(c, "PREVIOUS_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "4");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola6");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "4");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page3(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_sort_and_by_page_and_tag(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"TAGS: chunda bola\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"TAGS: bola\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"TAGS: yay chunda\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_trie_insert(c, "FILTER_TAG", bc_strdup("chunda"));
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("2"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("2"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 12);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_TAG"), "chunda");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "PREVIOUS_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "2");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 12);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2003-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "2");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page_invalid(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("-1"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("-1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(bc_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(bc_trie_size(c), 10);
- assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PAGE"), "-1");
- assert_string_equal(bc_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(bc_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(bc_trie_lookup(c, "LAST_PAGE"), "4");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "-1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
static void
test_source_parse_from_files_filter_by_page_invalid2(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola4.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola4.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola5.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola5.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola6.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola6.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola7.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola7.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- s = bc_slist_append(s, bc_strdup("bola4.txt"));
- s = bc_slist_append(s, bc_strdup("bola5.txt"));
- s = bc_slist_append(s, bc_strdup("bola6.txt"));
- s = bc_slist_append(s, bc_strdup("bola7.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_PAGE", bc_strdup("5"));
- bc_trie_insert(c, "FILTER_PER_PAGE", bc_strdup("2"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("5"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_without_all_dates(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola3.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola3.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "'DATE' variable provided for at least one source file, but not for "
+ assert_string_equal(sb_error_to_string(err),
+ "loader: 'DATE' variable provided for at least one source file, but not for "
"all source files. It must be provided for all files.");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 0);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_filter_sort_without_all_dates(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
- will_return(__wrap_bc_file_get_contents, "bola2.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola2.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 456\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "'FILTER_SORT' requires that 'DATE' variable is set for every source "
+ assert_string_equal(sb_error_to_string(err),
+ "loader: 'FILTER_SORT' requires that 'DATE' variable is set for every source "
"file: bola2.txt");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 1);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 1);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_filter_sort_with_wrong_date(void **state)
{
- will_return(__wrap_bc_file_get_contents, "bola1.txt");
- will_return(__wrap_bc_file_get_contents, bc_strdup(
+ will_return(__wrap_sb_file_get_contents_utf8, "bola1.txt");
+ will_return(__wrap_sb_file_get_contents_utf8, sb_strdup(
"ASD: 123\n"
"DATE: 2002-02-03 04:05:ab\n"
"--------\n"
"bola"));
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_strdup("bola1.txt"));
- s = bc_slist_append(s, bc_strdup("bola2.txt"));
- s = bc_slist_append(s, bc_strdup("bola3.txt"));
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "FILTER_SORT", bc_strdup("1"));
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_SORT", sb_strdup("1"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(t);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_LOADER);
- assert_string_equal(err->msg,
- "An error occurred while parsing 'DATE' variable: bola1.txt\n\nInvalid "
- "first digit of seconds. Found 'a', must be integer >= 0 and <= 6.");
- bc_error_free(err);
- assert_int_equal(bc_trie_size(c), 1);
- assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1");
- bc_trie_free(c);
- bc_slist_free_full(s, free);
+ assert_string_equal(sb_error_to_string(err),
+ "loader: An error occurred while parsing 'DATE' variable: bola1.txt\n> "
+ "datetime: Invalid first digit of seconds. Found 'a', must be integer "
+ ">= 0 and <= 6.");
+ sb_error_free(err);
+ assert_int_equal(sb_trie_size(c), 1);
+ assert_string_equal(sb_trie_lookup(c, "FILTER_SORT"), "1");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
static void
test_source_parse_from_files_null(void **state)
{
- bc_error_t *err = NULL;
- bc_slist_t *s = NULL;
- bc_trie_t *c = bc_trie_new(free);
- bc_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *s = NULL;
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- assert_int_equal(bc_slist_length(t), 0);
- assert_int_equal(bc_trie_size(c), 0);
- bc_trie_free(c);
- bc_slist_free_full(s, free);
- bc_slist_free_full(t, (bc_free_func_t) bc_trie_free);
+ assert_int_equal(sb_slist_length(t), 0);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
diff --git a/tests/blogc/check_renderer.c b/tests/blogc/check_renderer.c
index 479c239..63678b8 100644
--- a/tests/blogc/check_renderer.c
+++ b/tests/blogc/check_renderer.c
@@ -13,14 +13,14 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/renderer.h"
#include "../../src/blogc/source-parser.h"
#include "../../src/blogc/template-parser.h"
-static bc_slist_t*
+static sb_slist_t*
create_sources(size_t count)
{
const char *s[] = {
@@ -44,13 +44,13 @@ create_sources(size_t count)
"ahahahahahahahaha3",
};
assert_false(count > 3);
- bc_error_t *err = NULL;
- bc_slist_t *l = NULL;
+ sb_error_t *err = NULL;
+ sb_slist_t *l = NULL;
for (size_t i = 0; i < count; i++) {
- l = bc_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
+ l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
assert_null(err);
}
- assert_int_equal(bc_slist_length(l), count);
+ assert_int_equal(sb_slist_length(l), count);
return l;
}
@@ -76,11 +76,11 @@ test_render_entry(void **state)
"{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n"
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -102,7 +102,7 @@ test_render_entry(void **state)
"lol foo haha lol bar haha lol baz haha \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -123,11 +123,11 @@ test_render_listing(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, true);
assert_string_equal(out,
@@ -151,7 +151,7 @@ test_render_listing(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -173,11 +173,11 @@ test_render_listing_entry(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, true);
assert_string_equal(out,
@@ -202,7 +202,7 @@ test_render_listing_entry(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -225,17 +225,17 @@ test_render_listing_entry2(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
- bc_trie_t *entry = bc_trie_new(free);
- bc_trie_insert(entry, "FUUUUU", bc_strdup("XD"));
- bc_trie_insert(entry, "BAAAAA", bc_strdup(":p"));
+ sb_trie_t *entry = sb_trie_new(free);
+ sb_trie_insert(entry, "FUUUUU", sb_strdup("XD"));
+ sb_trie_insert(entry, "BAAAAA", sb_strdup(":p"));
char *out = blogc_render(l, s, entry, NULL, true);
- bc_trie_free(entry);
+ sb_trie_free(entry);
assert_string_equal(out,
"foo\n"
"fuuu\n"
@@ -259,7 +259,7 @@ test_render_listing_entry2(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -279,8 +279,8 @@ test_render_listing_empty(void **state)
"bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
char *out = blogc_render(l, NULL, NULL, NULL, true);
@@ -306,11 +306,11 @@ test_render_ifdef(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -318,7 +318,7 @@ test_render_ifdef(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -335,11 +335,11 @@ test_render_ifdef2(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -349,7 +349,7 @@ test_render_ifdef2(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -366,11 +366,11 @@ test_render_ifdef3(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -382,7 +382,7 @@ test_render_ifdef3(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -401,11 +401,11 @@ test_render_ifdef4(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -418,7 +418,7 @@ test_render_ifdef4(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -437,11 +437,11 @@ test_render_ifdef5(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -452,7 +452,7 @@ test_render_ifdef5(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -471,11 +471,11 @@ test_render_ifdef6(void **state)
"{% else %}lol\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -484,7 +484,7 @@ test_render_ifdef6(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -504,11 +504,11 @@ test_render_ifdef7(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -522,7 +522,7 @@ test_render_ifdef7(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -540,11 +540,11 @@ test_render_ifndef(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -557,7 +557,7 @@ test_render_ifndef(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -576,11 +576,11 @@ test_render_if_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -594,7 +594,7 @@ test_render_if_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -613,11 +613,11 @@ test_render_if_neq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -631,7 +631,7 @@ test_render_if_neq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -650,11 +650,11 @@ test_render_if_lt(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -668,7 +668,7 @@ test_render_if_lt(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -687,11 +687,11 @@ test_render_if_gt(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -705,7 +705,7 @@ test_render_if_gt(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -726,11 +726,11 @@ test_render_if_lt_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -746,7 +746,7 @@ test_render_if_lt_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -767,11 +767,11 @@ test_render_if_gt_eq(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -787,7 +787,7 @@ test_render_if_gt_eq(void **state)
"\n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -799,11 +799,11 @@ test_render_foreach(void **state)
"{% block entry %}\n"
"{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -811,7 +811,7 @@ test_render_foreach(void **state)
" foo bar baz \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -824,11 +824,11 @@ test_render_foreach_if(void **state)
"{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}"
"{% endif %} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -836,7 +836,7 @@ test_render_foreach_if(void **state)
" bar \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -850,11 +850,11 @@ test_render_foreach_if_else(void **state)
"{% else %}{{ FOREACH_ITEM }}"
"{% endif %} {% endforeach %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, NULL, false);
assert_string_equal(out,
@@ -862,7 +862,7 @@ test_render_foreach_if_else(void **state)
"foo yay baz \n"
"\n");
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -881,22 +881,22 @@ test_render_outside_block(void **state)
"{% ifdef GUDA %}bola{% endif %}\n"
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}lol{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "GUDA", bc_strdup("asd"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("asd"));
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"bola\n"
"\n"
"lol\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -914,15 +914,15 @@ test_render_prefer_local_variable(void **state)
"{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
- bc_trie_insert(c, "GUDA", bc_strdup("hehe"));
- bc_trie_insert(c, "LOL", bc_strdup("hmm"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("hehe"));
+ sb_trie_insert(c, "LOL", sb_strdup("hmm"));
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
@@ -933,9 +933,9 @@ test_render_prefer_local_variable(void **state)
"\n"
"\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -950,13 +950,13 @@ test_render_respect_variable_scope(void **state)
"{% ifdef LOL %}{{ LOL }}{% endif %}\n"
"{% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- bc_trie_t *c = bc_trie_new(free);
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
@@ -965,9 +965,9 @@ test_render_respect_variable_scope(void **state)
"\n"
"asd\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -982,23 +982,23 @@ test_render_ifcount_bug(void **state)
"{% ifdef ASD %}ASD{% endif %}\n"
"{% endif %}\n"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- bc_slist_t *s = NULL;
- s = bc_slist_append(s, bc_trie_new(free));
- bc_trie_insert(s->data, "TITLE", bc_strdup("bola"));
- bc_trie_t *c = bc_trie_new(free);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_trie_new(free));
+ sb_trie_insert(s->data, "TITLE", sb_strdup("bola"));
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, NULL, c, false);
assert_string_equal(out,
"\n"
"<h3>bola</h3>\n"
"\n"
"\n");
- bc_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_ast(l);
- bc_slist_free_full(s, (bc_free_func_t) bc_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -1006,100 +1006,100 @@ test_render_ifcount_bug(void **state)
static void
test_get_variable(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_get_variable_only_local(void **state)
{
- bc_trie_t *g = NULL;
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
+ sb_trie_t *g = NULL;
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(l);
+ sb_trie_free(l);
}
static void
test_get_variable_only_global(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = NULL;
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = NULL;
assert_string_equal(blogc_get_variable("NAME", g, l), "bola");
assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2");
assert_null(blogc_get_variable("BOLA", g, l));
- bc_trie_free(g);
+ sb_trie_free(g);
}
static void
test_format_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%H -- %M"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "DATE_FORMAT", bc_strdup("%R"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE_FORMAT", sb_strdup("%R"));
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03:04");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_with_global_format(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%H -- %M"));
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03 -- 04");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_format(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "2015-01-02 03:04:05");
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_t *l = bc_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date(NULL, g, l);
assert_null(date);
free(date);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
@@ -1107,13 +1107,13 @@ static void
test_format_variable(void **state)
{
// FIXME: test warnings
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "NAME", bc_strdup("bola"));
- bc_trie_insert(g, "TITLE", bc_strdup("bola2"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "NAME", bc_strdup("chunda"));
- bc_trie_insert(l, "TITLE", bc_strdup("chunda2"));
- bc_trie_insert(l, "SIZE", bc_strdup("1234567890987654321"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
+ sb_trie_insert(l, "SIZE", sb_strdup("1234567890987654321"));
char *tmp = blogc_format_variable("NAME", g, l, NULL);
assert_string_equal(tmp, "chunda");
free(tmp);
@@ -1131,19 +1131,19 @@ test_format_variable(void **state)
free(tmp);
assert_null(blogc_format_variable("SIZE_", g, l, NULL));
assert_null(blogc_format_variable("BOLA", g, l, NULL));
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_with_date(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "DATE", bc_strdup("2010-11-12 13:14:15"));
- bc_trie_insert(g, "DATE_FORMAT", bc_strdup("%R"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "DATE", bc_strdup("2011-12-13 14:15:16"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE", sb_strdup("2010-11-12 13:14:15"));
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%R"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE", sb_strdup("2011-12-13 14:15:16"));
char *tmp = blogc_format_variable("DATE_FORMATTED", g, l, NULL);
assert_string_equal(tmp, "14:15");
free(tmp);
@@ -1153,18 +1153,18 @@ test_format_variable_with_date(void **state)
tmp = blogc_format_variable("DATE_FORMATTED_10", g, l, NULL);
assert_string_equal(tmp, "14:15");
free(tmp);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_foreach(void **state)
{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("asd"));
- l = bc_slist_append(l, bc_strdup("qwe"));
- l = bc_slist_append(l, bc_strdup("zxcvbn"));
+ sb_slist_t *l = NULL;
+ l = sb_slist_append(l, sb_strdup("asd"));
+ l = sb_slist_append(l, sb_strdup("qwe"));
+ l = sb_slist_append(l, sb_strdup("zxcvbn"));
char *tmp = blogc_format_variable("FOREACH_ITEM", NULL, NULL, l->next);
assert_string_equal(tmp, "qwe");
free(tmp);
@@ -1176,7 +1176,7 @@ test_format_variable_foreach(void **state)
l->next->next);
assert_string_equal(tmp, "zxcvbn");
free(tmp);
- bc_slist_free_full(l, free);
+ sb_slist_free_full(l, free);
}
@@ -1191,31 +1191,31 @@ test_format_variable_foreach_empty(void **state)
static void
test_split_list_variable(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "TAGS", bc_strdup("asd lol hehe"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "TAGS", bc_strdup("asd lol XD"));
- bc_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
assert_string_equal(tmp->data, "asd");
assert_string_equal(tmp->next->data, "lol");
assert_string_equal(tmp->next->next->data, "XD");
- bc_slist_free_full(tmp, free);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_slist_free_full(tmp, free);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_split_list_variable_not_found(void **state)
{
- bc_trie_t *g = bc_trie_new(free);
- bc_trie_insert(g, "TAGS", bc_strdup("asd lol hehe"));
- bc_trie_t *l = bc_trie_new(free);
- bc_trie_insert(l, "TAGS", bc_strdup("asd lol XD"));
- bc_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
assert_null(tmp);
- bc_trie_free(g);
- bc_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
diff --git a/tests/blogc/check_rusage.c b/tests/blogc/check_rusage.c
index ff64297..7296c4d 100644
--- a/tests/blogc/check_rusage.c
+++ b/tests/blogc/check_rusage.c
@@ -15,7 +15,8 @@
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/rusage.h"
@@ -99,18 +100,18 @@ test_rusage_format_memory(void **state)
static void
test_rusage_inject(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_getrusage, -1);
blogc_rusage_inject(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_getrusage, 0);
blogc_rusage_inject(t);
- assert_int_equal(bc_trie_size(t), 2);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_CPU_TIME"), "4.000s");
- assert_string_equal(bc_trie_lookup(t, "BLOGC_RUSAGE_MEMORY"), "10.010MB");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 2);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_RUSAGE_CPU_TIME"), "4.000s");
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_RUSAGE_MEMORY"), "10.010MB");
+ sb_trie_free(t);
}
diff --git a/tests/blogc/check_source_parser.c b/tests/blogc/check_source_parser.c
index f758522..5aa7a91 100644
--- a/tests/blogc/check_source_parser.c
+++ b/tests/blogc/check_source_parser.c
@@ -11,8 +11,8 @@
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/source-parser.h"
@@ -26,26 +26,26 @@ test_source_parse(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -59,26 +59,26 @@ test_source_parse_crlf(void **state)
"# This is a test\r\n"
"\r\n"
"bola\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -94,26 +94,26 @@ test_source_parse_with_spaces(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "chunda");
- assert_string_equal(bc_trie_lookup(source, "BOLA"), "guda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda");
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -132,22 +132,22 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n"
"<p>guda\n"
"yay</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n"
@@ -156,9 +156,9 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -173,26 +173,26 @@ test_source_parse_with_first_header(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "THIS IS CHUNDA!");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "bola");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "THIS IS CHUNDA!");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -207,26 +207,26 @@ test_source_parse_with_description(void **state)
"# This is a test\n"
"\n"
"bola\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(bc_trie_size(source), 7);
- assert_string_equal(bc_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(bc_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(bc_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 7);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(bc_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- assert_string_equal(bc_trie_lookup(source, "FIRST_HEADER"), "This is a test");
- assert_string_equal(bc_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "FIRST_HEADER"), "This is a test");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
+ sb_trie_free(source);
}
@@ -234,14 +234,13 @@ static void
test_source_parse_config_empty(void **state)
{
const char *a = "";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg, "Your source file is empty.");
- bc_error_free(err);
- bc_trie_free(source);
+ assert_string_equal(sb_error_to_string(err), "source: Your source file is empty.");
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -249,15 +248,14 @@ static void
test_source_parse_config_invalid_key(void **state)
{
const char *a = "bola: guda";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Can't find a configuration key or the content separator.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Can't find a configuration key or the content separator.\n"
"Error occurred near line 1, position 1: bola: guda");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -265,15 +263,14 @@ static void
test_source_parse_config_no_key(void **state)
{
const char *a = "BOLa";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Invalid configuration key.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Invalid configuration key.\n"
"Error occurred near line 1, position 4: BOLa");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -281,15 +278,14 @@ static void
test_source_parse_config_no_key2(void **state)
{
const char *a = "BOLA";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Your last configuration key is missing ':' and the value\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Your last configuration key is missing ':' and the value\n"
"Error occurred near line 1, position 5: BOLA");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -298,12 +294,12 @@ test_source_parse_config_no_value(void **state)
{
// this is a special case, not an error
const char *a = "BOLA:\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(source);
assert_null(err);
- assert_string_equal(bc_trie_lookup(source, "BOLA"), "");
- bc_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "");
+ sb_trie_free(source);
}
@@ -311,16 +307,15 @@ static void
test_source_parse_config_no_value2(void **state)
{
const char *a = "BOLA:";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Configuration value not provided for 'BOLA'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -328,16 +323,15 @@ static void
test_source_parse_config_reserved_name(void **state)
{
const char *a = "FILENAME: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'FILENAME' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'FILENAME' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -345,16 +339,15 @@ static void
test_source_parse_config_reserved_name2(void **state)
{
const char *a = "CONTENT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'CONTENT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'CONTENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -362,16 +355,15 @@ static void
test_source_parse_config_reserved_name3(void **state)
{
const char *a = "DATE_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -379,16 +371,15 @@ static void
test_source_parse_config_reserved_name4(void **state)
{
const char *a = "DATE_FIRST_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -396,16 +387,15 @@ static void
test_source_parse_config_reserved_name5(void **state)
{
const char *a = "DATE_LAST_FORMATTED: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -413,16 +403,15 @@ static void
test_source_parse_config_reserved_name6(void **state)
{
const char *a = "PAGE_FIRST: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_FIRST' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_FIRST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -430,16 +419,15 @@ static void
test_source_parse_config_reserved_name7(void **state)
{
const char *a = "PAGE_PREVIOUS: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -447,16 +435,15 @@ static void
test_source_parse_config_reserved_name8(void **state)
{
const char *a = "PAGE_CURRENT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_CURRENT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_CURRENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -464,16 +451,15 @@ static void
test_source_parse_config_reserved_name9(void **state)
{
const char *a = "PAGE_NEXT: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_NEXT' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_NEXT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -481,16 +467,15 @@ static void
test_source_parse_config_reserved_name10(void **state)
{
const char *a = "PAGE_LAST: asd\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'PAGE_LAST' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'PAGE_LAST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -498,16 +483,15 @@ static void
test_source_parse_config_reserved_name11(void **state)
{
const char *a = "BLOGC_VERSION: 1.0\r\n";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "'BLOGC_VERSION' variable is forbidden in source files. It will be set "
+ assert_string_equal(sb_error_to_string(err),
+ "source: 'BLOGC_VERSION' variable is forbidden in source files. It will be set "
"for you by the compiler.");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -515,16 +499,15 @@ static void
test_source_parse_config_value_no_line_ending(void **state)
{
const char *a = "BOLA: asd";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "No line ending after the configuration value for 'BOLA'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: No line ending after the configuration value for 'BOLA'.\n"
"Error occurred near line 1, position 10: BOLA: asd");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
@@ -532,16 +515,15 @@ static void
test_source_parse_invalid_separator(void **state)
{
const char *a = "BOLA: asd\n---#";
- bc_error_t *err = NULL;
- bc_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
- assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
- assert_string_equal(err->msg,
- "Invalid content separator. Must be more than one '-' characters.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "source: Invalid content separator. Must be more than one '-' characters.\n"
"Error occurred near line 2, position 4: ---#");
- bc_error_free(err);
- bc_trie_free(source);
+ sb_error_free(err);
+ sb_trie_free(source);
}
diff --git a/tests/blogc/check_sysinfo.c b/tests/blogc/check_sysinfo.c
index 01b81b9..13fcb1e 100644
--- a/tests/blogc/check_sysinfo.c
+++ b/tests/blogc/check_sysinfo.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/sysinfo.h"
#ifdef HAVE_SYSINFO_DATETIME
@@ -73,10 +73,9 @@ __wrap_gmtime(const time_t *timep)
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
char *rv = mock_type(char*);
*len = strlen(rv);
return rv;
@@ -103,19 +102,19 @@ test_sysinfo_get_hostname(void **state)
static void
test_sysinfo_inject_hostname(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_gethostname, NULL);
will_return(__wrap_gethostname, -1);
blogc_sysinfo_inject_hostname(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_gethostname, "bola");
will_return(__wrap_gethostname, 0);
blogc_sysinfo_inject_hostname(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_HOSTNAME"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_HOSTNAME"), "bola");
+ sb_trie_free(t);
}
@@ -137,17 +136,17 @@ test_sysinfo_get_username(void **state)
static void
test_sysinfo_inject_username(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_getenv, NULL);
blogc_sysinfo_inject_username(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_getenv, "bola");
blogc_sysinfo_inject_username(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_USERNAME"), "bola");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_USERNAME"), "bola");
+ sb_trie_free(t);
}
@@ -173,21 +172,21 @@ test_sysinfo_get_datetime(void **state)
static void
test_sysinfo_inject_datetime(void **state)
{
- bc_trie_t *t = bc_trie_new(free);
+ sb_trie_t *t = sb_trie_new(free);
will_return(__wrap_time, -1);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_time, 2);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 0);
+ assert_int_equal(sb_trie_size(t), 0);
will_return(__wrap_time, 1);
blogc_sysinfo_inject_datetime(t);
- assert_int_equal(bc_trie_size(t), 1);
- assert_string_equal(bc_trie_lookup(t, "BLOGC_SYSINFO_DATETIME"), "1906-06-04 03:02:01");
- bc_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 1);
+ assert_string_equal(sb_trie_lookup(t, "BLOGC_SYSINFO_DATETIME"), "1906-06-04 03:02:01");
+ sb_trie_free(t);
}
@@ -196,7 +195,7 @@ test_sysinfo_get_inside_docker(void **state)
{
// the "positive" case was already tested in check_funcvars. this is done
// this way because this function caches the results in a global variable.
- will_return(__wrap_bc_file_get_contents, bc_strdup("bola"));
+ will_return(__wrap_sb_file_get_contents, sb_strdup("bola"));
assert_false(blogc_sysinfo_get_inside_docker());
}
diff --git a/tests/blogc/check_sysinfo2.c b/tests/blogc/check_sysinfo2.c
index 2bb4273..9a70059 100644
--- a/tests/blogc/check_sysinfo2.c
+++ b/tests/blogc/check_sysinfo2.c
@@ -13,8 +13,8 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/sysinfo.h"
// this test exists because we can't test more than one return values for
@@ -23,11 +23,10 @@
char*
-__wrap_bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err)
+__wrap_sb_file_get_contents(const char *path, size_t *len, sb_error_t **err)
{
assert_string_equal(path, "/proc/1/cgroup");
- assert_false(utf8);
- *err = bc_error_new(0, "");
+ *err = sb_strerror_new("");
return NULL;
}
diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c
index 15ef7c4..e3a3bd0 100644
--- a/tests/blogc/check_template_parser.c
+++ b/tests/blogc/check_template_parser.c
@@ -11,13 +11,13 @@
#include <setjmp.h>
#include <cmocka.h>
#include <string.h>
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
+#include <squareball.h>
+
#include "../../src/blogc/template-parser.h"
static void
-blogc_assert_template_node(bc_slist_t *l, const char *data,
+blogc_assert_template_node(sb_slist_t *l, const char *data,
const blogc_template_node_type_t type)
{
blogc_template_node_t *node = l->data;
@@ -30,7 +30,7 @@ blogc_assert_template_node(bc_slist_t *l, const char *data,
static void
-blogc_assert_template_if_node(bc_slist_t *l, const char *variable,
+blogc_assert_template_if_node(sb_slist_t *l, const char *variable,
blogc_template_operator_t operator, const char *operand)
{
blogc_template_node_t *node = l->data;
@@ -60,8 +60,8 @@ test_template_parse(void **state)
"{%- foreach BOLA %}hahaha{% endforeach %}\n"
"{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}\n"
"{% block listing_entry %}lol{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "Test",
@@ -78,7 +78,7 @@ test_template_parse(void **state)
BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(ast->next->next->next->next->next->next, "\n",
BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF);
blogc_assert_template_node(tmp->next, "\nbolao", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
@@ -149,8 +149,8 @@ test_template_parse_crlf(void **state)
"{% block listing_once %}asd{% endblock %}\r\n"
"{%- foreach BOLA %}hahaha{% endforeach %}\r\n"
"{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "Test",
@@ -167,7 +167,7 @@ test_template_parse_crlf(void **state)
BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(ast->next->next->next->next->next->next, "\r\n",
BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "BOLA", BLOGC_TEMPLATE_NODE_IFNDEF);
blogc_assert_template_node(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
@@ -241,8 +241,8 @@ test_template_parse_html(void **state)
" {% block listing_once %}</ul>{% endblock %}\n"
" </body>\n"
"</html>\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "<html>\n <head>\n ",
@@ -261,7 +261,7 @@ test_template_parse_html(void **state)
"\n ", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_NODE_BLOCK);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_NODE_CONTENT);
@@ -370,8 +370,8 @@ test_template_parse_html_whitespace(void **state)
" {%\tblock\tlisting_once\t%}</ul>{%\nendblock\n%}\n"
" </body>\n"
"</html>\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "<html>\n <head>\n ",
@@ -390,7 +390,7 @@ test_template_parse_html_whitespace(void **state)
"\n ", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_NODE_BLOCK);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_NODE_CONTENT);
@@ -480,8 +480,8 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
"{% ifdef GUDA %}bola{% endif %}\n"
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF);
@@ -497,7 +497,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(ast->next->next->next->next->next->next,
"CHUNDA", BLOGC_TEMPLATE_NODE_IFNDEF);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, "CHUNDA", BLOGC_TEMPLATE_NODE_VARIABLE);
blogc_assert_template_node(tmp->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF);
blogc_assert_template_node(tmp->next->next, "\n",
@@ -527,8 +527,8 @@ test_template_parse_nested_else(void **state)
"bnm\n"
"{% endif %}\n"
"{% endif %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(ast);
blogc_assert_template_node(ast, "GUDA", BLOGC_TEMPLATE_NODE_IFDEF);
@@ -544,7 +544,7 @@ test_template_parse_nested_else(void **state)
"CHUNDA", BLOGC_TEMPLATE_NODE_IFDEF);
blogc_assert_template_node(ast->next->next->next->next->next->next->next,
"\nqwe\n", BLOGC_TEMPLATE_NODE_CONTENT);
- bc_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = ast->next->next->next->next->next->next->next->next;
blogc_assert_template_node(tmp, NULL, BLOGC_TEMPLATE_NODE_ELSE);
blogc_assert_template_node(tmp->next, "\nrty\n", BLOGC_TEMPLATE_NODE_CONTENT);
blogc_assert_template_node(tmp->next->next, NULL,
@@ -579,35 +579,32 @@ static void
test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must begin with lowercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 4: {% ASD %}");
- bc_error_free(err);
+ sb_error_free(err);
a = "{%-- block entry %}\n";
err = NULL;
ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Duplicated whitespace cleaner before statement.\n"
"Error occurred near line 1, position 4: {%-- block entry %}");
- bc_error_free(err);
+ sb_error_free(err);
a = "{% block entry --%}\n";
err = NULL;
ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Duplicated whitespace cleaner after statement.\n"
"Error occurred near line 1, position 17: {% block entry --%}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -617,15 +614,14 @@ test_template_parse_invalid_block_nested(void **state)
const char *a =
"{% block entry %}\n"
"{% block listing %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Blocks can't be nested.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Blocks can't be nested.\n"
"Error occurred near line 2, position 9: {% block listing %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -635,15 +631,14 @@ test_template_parse_invalid_foreach_nested(void **state)
const char *a =
"{% foreach A %}\n"
"{% foreach B %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'foreach' statements can't be nested.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'foreach' statements can't be nested.\n"
"Error occurred near line 2, position 11: {% foreach B %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -651,15 +646,14 @@ static void
test_template_parse_invalid_block_not_open(void **state)
{
const char *a = "{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endblock' statement without an open 'block' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endblock' statement without an open 'block' statement.\n"
"Error occurred near line 1, position 12: {% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -667,16 +661,15 @@ static void
test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 28: "
"{% block listing %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -684,16 +677,15 @@ static void
test_template_parse_invalid_endif_not_open_inside_block(void **state)
{
const char *a = "{% ifdef BOLA %}{% block listing %}{% endif %}{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endif' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 44: {% ifdef BOLA %}{% block "
"listing %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -701,16 +693,15 @@ static void
test_template_parse_invalid_else_not_open_inside_block(void **state)
{
const char *a = "{% ifdef BOLA %}{% block listing %}{% else %}{% endif %}{% endblock %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 43: {% ifdef BOLA %}"
"{% block listing %}{% else %}{% endif %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -718,15 +709,14 @@ static void
test_template_parse_invalid_endforeach_not_open(void **state)
{
const char *a = "{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 14: {% endforeach %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -735,16 +725,15 @@ test_template_parse_invalid_endforeach_not_open_inside_block(void **state)
{
const char *a = "{% foreach TAGS %}{% block entry %}{% endforeach %}"
"{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 49: {% foreach TAGS %}"
"{% block entry %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -753,16 +742,15 @@ test_template_parse_invalid_endforeach_not_open_inside_block2(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}"
"{% endforeach %}{% endforeach %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'endforeach' statement without an open 'foreach' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'endforeach' statement without an open 'foreach' statement.\n"
"Error occurred near line 1, position 65: {% block entry %}"
"{% foreach TAGS %}{% endforeach %}{% endforeach %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -771,14 +759,13 @@ test_template_parse_invalid_endforeach_not_closed_inside_block(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}{% endblock %}"
"{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed inside a 'entry' block!");
+ sb_error_free(err);
}
@@ -787,14 +774,13 @@ test_template_parse_invalid_endforeach_not_closed_inside_block2(void **state)
{
const char *a = "{% block entry %}{% foreach TAGS %}{% endforeach %}"
"{% foreach TAGS %}{% endblock %}{% endforeach %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "An open 'foreach' statement was not closed inside a 'entry' block!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed inside a 'entry' block!");
+ sb_error_free(err);
}
@@ -802,16 +788,15 @@ static void
test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement type: Allowed types are: 'block', 'endblock', 'if', "
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement type: Allowed types are: 'block', 'endblock', 'if', "
"'ifdef', 'ifndef', 'else', 'endif', 'foreach' and 'endforeach'.\n"
"Error occurred near line 1, position 10: {% chunda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -819,15 +804,14 @@ static void
test_template_parse_invalid_block_type_start(void **state)
{
const char *a = "{% block ENTRY %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid block syntax. Must begin with lowercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid block syntax. Must begin with lowercase letter.\n"
"Error occurred near line 1, position 10: {% block ENTRY %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -835,16 +819,15 @@ static void
test_template_parse_invalid_block_type(void **state)
{
const char *a = "{% block chunda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' "
"and 'listing_entry'.\n"
"Error occurred near line 1, position 16: {% block chunda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -852,16 +835,15 @@ static void
test_template_parse_invalid_ifdef_start(void **state)
{
const char *a = "{% block entry %}{% ifdef guda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -869,16 +851,15 @@ static void
test_template_parse_invalid_foreach_start(void **state)
{
const char *a = "{% block entry %}{% foreach guda %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% foreach guda %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -886,16 +867,15 @@ static void
test_template_parse_invalid_ifdef_variable(void **state)
{
const char *a = "{% block entry %}{% ifdef BoLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 28: "
"{% block entry %}{% ifdef BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -903,16 +883,15 @@ static void
test_template_parse_invalid_ifdef_variable2(void **state)
{
const char *a = "{% block entry %}{% ifdef 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{% ifdef 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -920,16 +899,15 @@ static void
test_template_parse_invalid_foreach_variable(void **state)
{
const char *a = "{% block entry %}{% foreach BoLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 30: "
"{% block entry %}{% foreach BoLA %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -937,16 +915,15 @@ static void
test_template_parse_invalid_foreach_variable2(void **state)
{
const char *a = "{% block entry %}{% foreach 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid foreach variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid foreach variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 29: {% block entry %}"
"{% foreach 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -954,16 +931,15 @@ static void
test_template_parse_invalid_if_operator(void **state)
{
const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n"
"Error occurred near line 1, position 29: "
"{% block entry %}{% if BOLA = \"asd\" %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -971,16 +947,15 @@ static void
test_template_parse_invalid_if_operand(void **state)
{
const char *a = "{% block entry %}{% if BOLA == asd %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operand. Must be double-quoted static string or variable.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -988,16 +963,15 @@ static void
test_template_parse_invalid_if_operand2(void **state)
{
const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Found an open double-quoted string.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Found an open double-quoted string.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == \"asd %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1005,16 +979,15 @@ static void
test_template_parse_invalid_if_operand3(void **state)
{
const char *a = "{% block entry %}{% if BOLA == 0123 %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid 'if' operand. Must be double-quoted static string or variable.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid 'if' operand. Must be double-quoted static string or variable.\n"
"Error occurred near line 1, position 32: "
"{% block entry %}{% if BOLA == 0123 %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1022,15 +995,14 @@ static void
test_template_parse_invalid_else1(void **state)
{
const char *a = "{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: 'else' statement without an open 'if', 'ifdef' or 'ifndef' statement.\n"
"Error occurred near line 1, position 8: {% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1038,16 +1010,15 @@ static void
test_template_parse_invalid_else2(void **state)
{
const char *a = "{% if BOLA == \"123\" %}{% if GUDA == \"1\" %}{% else %}{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
"statement.\nError occurred near line 1, position 60: {% if BOLA == \"123\" "
"%}{% if GUDA == \"1\" %}{% else %}{% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1062,15 +1033,14 @@ test_template_parse_invalid_else3(void **state)
"{% endif %}\n"
"{% else %}\n"
"{% else %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
+ assert_string_equal(sb_error_to_string(err),
+ "template: More than one 'else' statement for an open 'if', 'ifdef' or 'ifndef' "
"statement.\nError occurred near line 7, position 8: {% else %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1078,15 +1048,14 @@ static void
test_template_parse_invalid_block_end(void **state)
{
const char *a = "{% block entry }}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '%}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '%}'.\n"
"Error occurred near line 1, position 16: {% block entry }}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1094,16 +1063,15 @@ static void
test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: "
"{% block entry %}{{ bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1111,16 +1079,15 @@ static void
test_template_parse_invalid_variable_name2(void **state)
{
const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must be uppercase letter, number or '_'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must be uppercase letter, number or '_'.\n"
"Error occurred near line 1, position 22: "
"{% block entry %}{{ Bola }}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1128,16 +1095,15 @@ static void
test_template_parse_invalid_variable_name3(void **state)
{
const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid variable name. Must begin with uppercase letter.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid variable name. Must begin with uppercase letter.\n"
"Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}"
"{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1145,16 +1111,15 @@ static void
test_template_parse_invalid_variable_end(void **state)
{
const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}}'.\n"
"Error occurred near line 1, position 26: "
"{% block entry %}{{ BOLA %}{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1162,15 +1127,14 @@ static void
test_template_parse_invalid_close(void **state)
{
const char *a = "{% block entry %%\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 17: {% block entry %%");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1178,16 +1142,15 @@ static void
test_template_parse_invalid_close2(void **state)
{
const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "Invalid statement syntax. Must end with '}'.\n"
+ assert_string_equal(sb_error_to_string(err),
+ "template: Invalid statement syntax. Must end with '}'.\n"
"Error occurred near line 1, position 27: "
"{% block entry %}{{ BOLA }%{% endblock %}");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1195,14 +1158,14 @@ static void
test_template_parse_invalid_endif_not_closed(void **state)
{
const char *a = "{% block entry %}{% endblock %}{% ifdef BOLA %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "1 open 'if', 'ifdef' and/or 'ifndef' statements "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements "
"were not closed!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1210,15 +1173,14 @@ static void
test_template_parse_invalid_endif_not_closed_inside_block(void **state)
{
const char *a = "{% block listing %}{% ifdef BOLA %}{% endblock %}{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1226,15 +1188,14 @@ static void
test_template_parse_invalid_else_not_closed_inside_block(void **state)
{
const char *a = "{% block listing %}{% ifdef BOLA %}{% else %}{% endblock %}{% endif %}";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg,
- "1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
+ assert_string_equal(sb_error_to_string(err),
+ "template: 1 open 'if', 'ifdef' and/or 'ifndef' statements were not closed inside "
"a 'listing' block!");
- bc_error_free(err);
+ sb_error_free(err);
}
@@ -1242,13 +1203,13 @@ static void
test_template_parse_invalid_block_not_closed(void **state)
{
const char *a = "{% block entry %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "An open block was not closed!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open block was not closed!");
+ sb_error_free(err);
}
@@ -1256,13 +1217,13 @@ static void
test_template_parse_invalid_foreach_not_closed(void **state)
{
const char *a = "{% foreach ASD %}\n";
- bc_error_t *err = NULL;
- bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
+ sb_error_t *err = NULL;
+ sb_slist_t *ast = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(ast);
- assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
- assert_string_equal(err->msg, "An open 'foreach' statement was not closed!");
- bc_error_free(err);
+ assert_string_equal(sb_error_to_string(err),
+ "template: An open 'foreach' statement was not closed!");
+ sb_error_free(err);
}
diff --git a/tests/common/check_config_parser.c b/tests/common/check_config_parser.c
deleted file mode 100644
index 49e2a5b..0000000
--- a/tests/common/check_config_parser.c
+++ /dev/null
@@ -1,1037 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "../../src/common/config-parser.h"
-#include "../../src/common/error.h"
-#include "../../src/common/utils.h"
-
-
-static void
-test_config_empty(void **state)
-{
- const char *a = "";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 0);
- assert_string_equal(bc_config_get_with_default(c, "bola", "foo", "bar"), "bar");
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_empty(void **state)
-{
- const char *a = "[foo]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 0);
- assert_null(k[0]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_multiple_keys(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty \n"
- "zxc = vbn";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty \n"
- "zxc = vbn\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty \r\n"
- "zxc = vbn\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_multiple_sections(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty\r\n"
- "zxc = vbn\r\n"
- "\r\n"
- "[bar]\r\n"
- "lol = hehe\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- assert_string_equal(bc_config_get(c, "bar", "lol"), "hehe");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "lol");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_section_list(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n"
- " asdasdadssad ";
- bc_error_t *err = NULL;
- const char *sections[] = {"bar", NULL};
- bc_config_t *c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- char **bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = zxc\n"
- "qwe = rty\n"
- "zxc = vbn\n"
- "\n"
- "[bar]\n"
- "lol = hehe\n"
- "asdasdadssad\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = zxc\r\n"
- "qwe = rty\r\n"
- "zxc = vbn\r\n"
- "\r\n"
- "[bar]\r\n"
- "lol = hehe\r\n"
- "asdasdadssad\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "zxc");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "rty");
- assert_string_equal(bc_config_get(c, "foo", "zxc"), "vbn");
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "lol = hehe");
- assert_string_equal(bar[1], "asdasdadssad");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 3);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_string_equal(k[2], "zxc");
- assert_null(k[3]);
- bc_strv_free(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_quoted_values(void **state)
-{
- const char *a =
- "[foo]\n"
- "a = \"lol\"\n"
- "b = \"lo\\\"l\"\n"
- "c = \"lo'l\"\n"
- "d = 'lol'\n"
- "e = 'lo\\'l'\n"
- "f = 'lo\"l'\n"
- "g = \\\\asd\n"
- "h = \"\\\\asd\"\n"
- "i = '\\\\asd'\n";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 9);
- assert_string_equal(k[0], "a");
- assert_string_equal(k[1], "b");
- assert_string_equal(k[2], "c");
- assert_string_equal(k[3], "d");
- assert_string_equal(k[4], "e");
- assert_string_equal(k[5], "f");
- assert_string_equal(k[6], "g");
- assert_string_equal(k[7], "h");
- assert_string_equal(k[8], "i");
- assert_null(k[9]);
- bc_strv_free(k);
- assert_string_equal(bc_config_get(c, "foo", "a"), "lol");
- assert_string_equal(bc_config_get(c, "foo", "b"), "lo\"l");
- assert_string_equal(bc_config_get(c, "foo", "c"), "lo'l");
- assert_string_equal(bc_config_get(c, "foo", "d"), "'lol'");
- assert_string_equal(bc_config_get(c, "foo", "e"), "'lo'l'");
- assert_string_equal(bc_config_get(c, "foo", "f"), "'lo\"l'");
- assert_string_equal(bc_config_get(c, "foo", "g"), "\\asd");
- assert_string_equal(bc_config_get(c, "foo", "h"), "\\asd");
- assert_string_equal(bc_config_get(c, "foo", "i"), "'\\asd'");
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "\"lol\"\n"
- "\"lo\\\"l\"\n"
- "\"lo'l\"\n"
- "'lol'\n"
- "'lo\\'l'\n"
- "'lo\"l'\n"
- "\\\\asd\n"
- "\"\\\\asd\"\n"
- "'\\\\asd'\n"
- "\n"
- "[bar]\n"
- "'lol = hehe'\n"
- "\" asdasdadssad \"";
- err = NULL;
- const char *sections[] = {"foo", "bar", NULL};
- c = bc_config_parse(a, strlen(a), sections, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 2);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 2);
- assert_string_equal(s[0], "foo");
- assert_string_equal(s[1], "bar");
- assert_null(s[2]);
- bc_strv_free(s);
- char **bar = bc_config_get_list(c, "foo");
- assert_string_equal(bar[0], "lol");
- assert_string_equal(bar[1], "lo\"l");
- assert_string_equal(bar[2], "lo'l");
- assert_string_equal(bar[3], "'lol'");
- assert_string_equal(bar[4], "'lo'l'");
- assert_string_equal(bar[5], "'lo\"l'");
- assert_string_equal(bar[6], "\\asd");
- assert_string_equal(bar[7], "\\asd");
- assert_string_equal(bar[8], "'\\asd'");
- assert_null(bar[9]);
- bc_strv_free(bar);
- bar = bc_config_get_list(c, "bar");
- assert_non_null(bar);
- assert_string_equal(bar[0], "'lol = hehe'");
- assert_string_equal(bar[1], " asdasdadssad ");
- assert_null(bar[2]);
- bc_strv_free(bar);
- k = bc_config_list_keys(c, "foo");
- assert_null(k);
- k = bc_config_list_keys(c, "bar");
- assert_null(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_empty_values(void **state)
-{
- const char *a =
- "[foo]\n"
- "asd =";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = \n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = foo\n"
- "qwe =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = foo\n"
- "qwe = \n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd =\n"
- "qwe = foo";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\n"
- "asd = \n"
- "qwe = foo\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = \r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 1);
- assert_string_equal(k[0], "asd");
- assert_null(k[1]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = foo\r\n"
- "qwe =";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = foo\r\n"
- "qwe = \r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd =\r\n"
- "qwe = foo";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-
- a =
- "[foo]\r\n"
- "asd = \r\n"
- "qwe = foo\r\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- assert_string_equal(bc_config_get(c, "foo", "asd"), "");
- assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
- k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "asd");
- assert_string_equal(k[1], "qwe");
- assert_null(k[2]);
- bc_strv_free(k);
- bc_config_free(c);
-}
-
-
-static void
-test_config_key_prefix(void **state)
-{
- const char *a =
- "[foo]\n"
- "LAST_FLIGHT = lol\n"
- "LAST_FLIGHT_SLUG = hehe\n";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_null(err);
- assert_non_null(c);
- assert_non_null(c->root);
- assert_int_equal(bc_trie_size(c->root), 1);
- char **s = bc_config_list_sections(c);
- assert_non_null(s);
- assert_int_equal(bc_strv_length(s), 1);
- assert_string_equal(s[0], "foo");
- assert_null(s[1]);
- bc_strv_free(s);
- char **k = bc_config_list_keys(c, "foo");
- assert_non_null(k);
- assert_int_equal(bc_strv_length(k), 2);
- assert_string_equal(k[0], "LAST_FLIGHT");
- assert_string_equal(k[1], "LAST_FLIGHT_SLUG");
- assert_null(k[2]);
- bc_strv_free(k);
- assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT"), "lol");
- assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT_SLUG"), "hehe");
- bc_config_free(c);
-}
-
-
-static void
-test_config_error_start(void **state)
-{
- const char *a =
- "asd\n"
- "[foo]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "File must start with section.\n"
- "Error occurred near line 1, position 1: asd");
- bc_error_free(err);
-}
-
-
-static void
-test_config_error_section_with_newline(void **state)
-{
- const char *a =
- "[foo\nbar]";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Section names can't have new lines.\n"
- "Error occurred near line 1, position 5: [foo");
- bc_error_free(err);
-}
-
-
-static void
-test_config_error_key_without_value(void **state)
-{
- const char *a =
- "[foobar]\n"
- "asd = 12\n"
- "foo";
- bc_error_t *err = NULL;
- bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Key without value: foo.\n"
- "Error occurred near line 3, position 3: foo");
- bc_error_free(err);
- a =
- "[foobar]\n"
- "asd = 12\n"
- "foo\n";
- err = NULL;
- c = bc_config_parse(a, strlen(a), NULL, &err);
- assert_non_null(err);
- assert_null(c);
- assert_int_equal(err->type, BC_ERROR_CONFIG_PARSER);
- assert_string_equal(err->msg,
- "Key without value: foo.\n"
- "Error occurred near line 3, position 4: foo");
- bc_error_free(err);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_config_empty),
- unit_test(test_config_section_empty),
- unit_test(test_config_section),
- unit_test(test_config_section_multiple_keys),
- unit_test(test_config_section_multiple_sections),
- unit_test(test_config_section_list),
- unit_test(test_config_quoted_values),
- unit_test(test_config_empty_values),
- unit_test(test_config_key_prefix),
- unit_test(test_config_error_start),
- unit_test(test_config_error_section_with_newline),
- unit_test(test_config_error_key_without_value),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_error.c b/tests/common/check_error.c
deleted file mode 100644
index d9806f9..0000000
--- a/tests/common/check_error.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include <string.h>
-#include "../../src/common/error.h"
-
-
-static void
-test_error_new(void **state)
-{
- bc_error_t *error = bc_error_new(1, "bola %s");
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "bola %s");
- bc_error_free(error);
-}
-
-
-static void
-test_error_new_printf(void **state)
-{
- bc_error_t *error = bc_error_new_printf(2, "bola %s", "guda");
- assert_non_null(error);
- assert_int_equal(error->type, 2);
- assert_string_equal(error->msg, "bola guda");
- bc_error_free(error);
-}
-
-
-static void
-test_error_parser(void **state)
-{
- const char *a = "bola\nguda\nchunda\n";
- bc_error_t *error = bc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\nguda\nchunda";
- error = bc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\nguda\nchunda";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 1, position 1: bola");
- bc_error_free(error);
- a = "";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg, "asd 10");
- bc_error_free(error);
-}
-
-
-static void
-test_error_parser_crlf(void **state)
-{
- const char *a = "bola\r\nguda\r\nchunda\r\n";
- bc_error_t *error = bc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\r\nguda\r\nchunda";
- error = bc_error_parser(1, a, strlen(a), 13, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 3, position 2: chunda");
- bc_error_free(error);
- a = "bola\r\nguda\r\nchunda";
- error = bc_error_parser(1, a, strlen(a), 0, "asd %d", 10);
- assert_non_null(error);
- assert_int_equal(error->type, 1);
- assert_string_equal(error->msg,
- "asd 10\nError occurred near line 1, position 1: bola");
- bc_error_free(error);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_error_new),
- unit_test(test_error_new_printf),
- unit_test(test_error_parser),
- unit_test(test_error_parser_crlf),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_sort.c b/tests/common/check_sort.c
deleted file mode 100644
index f49710c..0000000
--- a/tests/common/check_sort.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include <stdlib.h>
-#include <string.h>
-#include "../../src/common/utils.h"
-#include "../../src/common/sort.h"
-
-
-static int
-sort_func(void *a, void *b)
-{
- return strcmp((char*) a, (char*) b);
-}
-
-
-static void
-test_slist_sort_empty(void **state)
-{
- bc_slist_t *l = NULL;
- assert_null(bc_slist_sort(l, (bc_sort_func_t) sort_func));
-}
-
-
-static void
-test_slist_sort_single(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_null(l->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_sorted(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("c"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_null(l->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_reverse(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("d"));
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("a"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_mixed1(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("d"));
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_sort_mixed2(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, bc_strdup("c"));
- l = bc_slist_append(l, bc_strdup("b"));
- l = bc_slist_append(l, bc_strdup("a"));
- l = bc_slist_append(l, bc_strdup("d"));
-
- l = bc_slist_sort(l, (bc_sort_func_t) sort_func);
-
- assert_non_null(l);
- assert_string_equal(l->data, "a");
- assert_string_equal(l->next->data, "b");
- assert_string_equal(l->next->next->data, "c");
- assert_string_equal(l->next->next->next->data, "d");
- assert_null(l->next->next->next->next);
-
- bc_slist_free_full(l, free);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_slist_sort_empty),
- unit_test(test_slist_sort_single),
- unit_test(test_slist_sort_sorted),
- unit_test(test_slist_sort_reverse),
- unit_test(test_slist_sort_mixed1),
- unit_test(test_slist_sort_mixed2),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_stdin.c b/tests/common/check_stdin.c
deleted file mode 100644
index 716916d..0000000
--- a/tests/common/check_stdin.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include "../../src/common/stdin.h"
-
-
-int
-__wrap_fgetc(FILE *stream)
-{
- assert_int_equal(fileno(stream), fileno(stdin));
- return mock_type(int);
-}
-
-
-static void
-test_read(void **state)
-{
- will_return(__wrap_fgetc, EOF);
- char *t = bc_stdin_read();
- assert_non_null(t);
- assert_string_equal(t, "");
- free(t);
- will_return(__wrap_fgetc, 'b');
- will_return(__wrap_fgetc, 'o');
- will_return(__wrap_fgetc, 'l');
- will_return(__wrap_fgetc, 'a');
- will_return(__wrap_fgetc, EOF);
- t = bc_stdin_read();
- assert_non_null(t);
- assert_string_equal(t, "bola");
- free(t);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_read),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_utf8.c b/tests/common/check_utf8.c
deleted file mode 100644
index 05bf566..0000000
--- a/tests/common/check_utf8.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include "../../src/common/utf8.h"
-#include "../../src/common/utils.h"
-
-// this file MUST be ASCII
-
-
-static void
-test_utf8_valid(void **state)
-{
- const char *c = "<a href=\"{{ BASE_URL }}/page/{{ PREVIOUS_PAGE }}/\">"
- "\xc2\xab Newer posts</a>";
- assert_true(bc_utf8_validate((uint8_t*) c, strlen(c)));
- const uint8_t d[3] = {0xe2, 0x82, 0xac}; // euro sign
- assert_true(bc_utf8_validate(d, 3));
- const uint8_t e[3] = {0xef, 0xbb, 0xbf}; // utf-8 bom
- assert_true(bc_utf8_validate(e, 3));
-}
-
-
-static void
-test_utf8_invalid(void **state)
-{
- const uint8_t c[4] = {0xff, 0xfe, 0xac, 0x20}; // utf-16
- assert_false(bc_utf8_validate(c, 4));
- const uint8_t d[8] = {0xff, 0xfe, 0x00, 0x00, 0xac, 0x20, 0x00, 0x00}; // utf-32
- assert_false(bc_utf8_validate(d, 8));
-}
-
-
-static void
-test_utf8_valid_str(void **state)
-{
- bc_string_t *s = bc_string_new();
- bc_string_append(s,
- "<a href=\"{{ BASE_URL }}/page/{{ PREVIOUS_PAGE }}/\">\xc2\xab Newer "
- "posts</a>");
- assert_true(bc_utf8_validate_str(s));
- bc_string_free(s, true);
- s = bc_string_new();
- bc_string_append(s, "\xe2\x82\xac");
- assert_true(bc_utf8_validate_str(s));
- bc_string_free(s, true);
-}
-
-
-static void
-test_utf8_invalid_str(void **state)
-{
- bc_string_t *s = bc_string_new();
- bc_string_append(s, "\xff\xfe\xac\x20"); // utf-16
- assert_false(bc_utf8_validate_str(s));
- bc_string_free(s, true);
- s = bc_string_new();
- bc_string_append(s, "\xff\xfe\x00\x00\xac\x20\x00\x00"); // utf-32
- assert_false(bc_utf8_validate_str(s));
- bc_string_free(s, true);
-}
-
-
-static void
-test_utf8_skip_bom(void **state)
-{
- const uint8_t c[4] = {0xef, 0xbb, 0xbf, 0};
- assert_int_equal(bc_utf8_skip_bom(c, 2), 0);
- assert_int_equal(bc_utf8_skip_bom(c, 3), 3);
- assert_string_equal(c + 3, "");
- const uint8_t d[8] = {0xef, 0xbb, 0xbf, 'b', 'o', 'l', 'a', 0};
- assert_int_equal(bc_utf8_skip_bom(d, 7), 3);
- assert_string_equal(d + 3, "bola");
- const uint8_t e[5] = "bola";
- assert_int_equal(bc_utf8_skip_bom(e, 4), 0);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
- unit_test(test_utf8_valid),
- unit_test(test_utf8_invalid),
- unit_test(test_utf8_valid_str),
- unit_test(test_utf8_invalid_str),
- unit_test(test_utf8_skip_bom),
- };
- return run_tests(tests);
-}
diff --git a/tests/common/check_utils.c b/tests/common/check_utils.c
deleted file mode 100644
index cc14f4e..0000000
--- a/tests/common/check_utils.c
+++ /dev/null
@@ -1,1095 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include "../../src/common/utils.h"
-
-#define BC_STRING_CHUNK_SIZE 128
-
-
-static void
-test_slist_append(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, (void*) bc_strdup("bola"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_null(l->next);
- l = bc_slist_append(l, (void*) bc_strdup("guda"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_non_null(l->next);
- assert_string_equal(l->next->data, "guda");
- assert_null(l->next->next);
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_prepend(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_prepend(l, (void*) bc_strdup("bola"));
- assert_non_null(l);
- assert_string_equal(l->data, "bola");
- assert_null(l->next);
- l = bc_slist_prepend(l, (void*) bc_strdup("guda"));
- assert_non_null(l);
- assert_string_equal(l->data, "guda");
- assert_non_null(l->next);
- assert_string_equal(l->next->data, "bola");
- assert_null(l->next->next);
- bc_slist_free_full(l, free);
-}
-
-
-static void
-test_slist_free(void **state)
-{
- bc_slist_t *l = NULL;
- char *t1 = bc_strdup("bola");
- char *t2 = bc_strdup("guda");
- char *t3 = bc_strdup("chunda");
- l = bc_slist_append(l, (void*) t1);
- l = bc_slist_append(l, (void*) t2);
- l = bc_slist_append(l, (void*) t3);
- bc_slist_free(l);
- assert_string_equal(t1, "bola");
- assert_string_equal(t2, "guda");
- assert_string_equal(t3, "chunda");
- free(t1);
- free(t2);
- free(t3);
-}
-
-
-static void
-test_slist_length(void **state)
-{
- bc_slist_t *l = NULL;
- l = bc_slist_append(l, (void*) bc_strdup("bola"));
- l = bc_slist_append(l, (void*) bc_strdup("guda"));
- l = bc_slist_append(l, (void*) bc_strdup("chunda"));
- assert_int_equal(bc_slist_length(l), 3);
- bc_slist_free_full(l, free);
- assert_int_equal(bc_slist_length(NULL), 0);
-}
-
-
-static void
-test_strdup(void **state)
-{
- char *str = bc_strdup("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strndup(void **state)
-{
- char *str = bc_strndup("bolaguda", 4);
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strndup("bolaguda", 30);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = bc_strndup("bolaguda", 8);
- assert_string_equal(str, "bolaguda");
- free(str);
- str = bc_strdup(NULL);
- assert_null(str);
-}
-
-
-static void
-test_strdup_printf(void **state)
-{
- char *str = bc_strdup_printf("bola");
- assert_string_equal(str, "bola");
- free(str);
- str = bc_strdup_printf("bola, %s", "guda");
- assert_string_equal(str, "bola, guda");
- free(str);
-}
-
-
-static void
-test_str_starts_with(void **state)
-{
- assert_true(bc_str_starts_with("bolaguda", "bola"));
- assert_true(bc_str_starts_with("bola", "bola"));
- assert_false(bc_str_starts_with("gudabola", "bola"));
- assert_false(bc_str_starts_with("guda", "bola"));
- assert_false(bc_str_starts_with("bola", "bolaguda"));
-}
-
-
-static void
-test_str_ends_with(void **state)
-{
- assert_true(bc_str_ends_with("bolaguda", "guda"));
- assert_true(bc_str_ends_with("bola", "bola"));
- assert_false(bc_str_ends_with("gudabola", "guda"));
- assert_false(bc_str_ends_with("guda", "bola"));
- assert_false(bc_str_ends_with("bola", "gudabola"));
-}
-
-
-static void
-test_str_lstrip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_lstrip(str), "bola\n \t");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_lstrip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_lstrip(str), "");
- free(str);
- assert_null(bc_str_lstrip(NULL));
-}
-
-
-static void
-test_str_rstrip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_rstrip(str), " \tbola");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_rstrip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_rstrip(str), "");
- free(str);
- assert_null(bc_str_rstrip(NULL));
-}
-
-
-static void
-test_str_strip(void **state)
-{
- char *str = bc_strdup(" \tbola\n \t");
- assert_string_equal(bc_str_strip(str), "bola");
- free(str);
- str = bc_strdup("guda");
- assert_string_equal(bc_str_strip(str), "guda");
- free(str);
- str = bc_strdup("\n");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- str = bc_strdup("\t \n");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- str = bc_strdup("");
- assert_string_equal(bc_str_strip(str), "");
- free(str);
- assert_null(bc_str_strip(NULL));
-}
-
-
-static void
-test_str_split(void **state)
-{
- char **strv = bc_str_split("bola:guda:chunda", ':', 0);
- assert_string_equal(strv[0], "bola");
- assert_string_equal(strv[1], "guda");
- assert_string_equal(strv[2], "chunda");
- assert_null(strv[3]);
- bc_strv_free(strv);
- strv = bc_str_split("bola:guda:chunda", ':', 2);
- assert_string_equal(strv[0], "bola");
- assert_string_equal(strv[1], "guda:chunda");
- assert_null(strv[2]);
- bc_strv_free(strv);
- strv = bc_str_split("bola:guda:chunda", ':', 1);
- assert_string_equal(strv[0], "bola:guda:chunda");
- assert_null(strv[1]);
- bc_strv_free(strv);
- strv = bc_str_split("", ':', 1);
- assert_null(strv[0]);
- bc_strv_free(strv);
- assert_null(bc_str_split(NULL, ':', 0));
-}
-
-
-static void
-test_str_replace(void **state)
-{
- char *str = bc_str_replace("bolao", 'o', "zaz");
- assert_string_equal(str, "bzazlazaz");
- free(str);
- str = bc_str_replace("bolao", 'b', "zaz");
- assert_string_equal(str, "zazolao");
- free(str);
- str = bc_str_replace("bolao", 'b', NULL);
- assert_string_equal(str, "bolao");
- free(str);
- assert_null(bc_str_replace(NULL, 'b', "zaz"));
-}
-
-
-static void
-test_str_find(void **state)
-{
- assert_null(bc_str_find(NULL, 'c'));
- assert_string_equal(bc_str_find("bola", 'l'), "la");
- assert_string_equal(bc_str_find("bo\\lalala", 'l'), "lala");
- assert_string_equal(bc_str_find("bola", '\0'), "");
- assert_null(bc_str_find("bola", 'g'));
- assert_null(bc_str_find("bo\\la", 'l'));
-}
-
-
-static void
-test_str_to_bool(void **state)
-{
- assert_false(bc_str_to_bool(NULL));
- assert_true(bc_str_to_bool("1"));
- assert_true(bc_str_to_bool("y"));
- assert_true(bc_str_to_bool("Y"));
- assert_true(bc_str_to_bool("yes"));
- assert_true(bc_str_to_bool("YES"));
- assert_true(bc_str_to_bool("true"));
- assert_true(bc_str_to_bool("TRUE"));
- assert_true(bc_str_to_bool("on"));
- assert_true(bc_str_to_bool("ON"));
- assert_false(bc_str_to_bool("0"));
- assert_false(bc_str_to_bool("n"));
- assert_false(bc_str_to_bool("N"));
- assert_false(bc_str_to_bool("no"));
- assert_false(bc_str_to_bool("NO"));
- assert_false(bc_str_to_bool("false"));
- assert_false(bc_str_to_bool("FALSE"));
- assert_false(bc_str_to_bool("off"));
- assert_false(bc_str_to_bool("OFF"));
-}
-
-
-static void
-test_strv_join(void **state)
-{
- char *pieces[] = {"guda","bola", "chunda", NULL};
- char *str = bc_strv_join(pieces, ":");
- assert_string_equal(str, "guda:bola:chunda");
- free(str);
- char *pieces2[] = {NULL};
- str = bc_strv_join(pieces2, ":");
- assert_string_equal(str, "");
- free(str);
- assert_null(bc_strv_join(pieces, NULL));
- assert_null(bc_strv_join(NULL, ":"));
- assert_null(bc_strv_join(NULL, NULL));
-}
-
-
-static void
-test_strv_length(void **state)
-{
- char *pieces[] = {"guda","bola", "chunda", NULL};
- assert_int_equal(bc_strv_length(pieces), 3);
- char *pieces2[] = {NULL};
- assert_int_equal(bc_strv_length(pieces2), 0);
- assert_int_equal(bc_strv_length(NULL), 0);
-}
-
-
-static void
-test_string_new(void **state)
-{
- bc_string_t *str = bc_string_new();
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
-}
-
-
-static void
-test_string_free(void **state)
-{
- bc_string_t *str = bc_string_new();
- free(str->str);
- str->str = bc_strdup("bola");
- str->len = 4;
- str->allocated_len = BC_STRING_CHUNK_SIZE;
- char *tmp = bc_string_free(str, false);
- assert_string_equal(tmp, "bola");
- free(tmp);
- assert_null(bc_string_free(NULL, false));
-}
-
-
-static void
-test_string_dup(void **state)
-{
- bc_string_t *str = bc_string_new();
- free(str->str);
- str->str = bc_strdup("bola");
- str->len = 4;
- str->allocated_len = BC_STRING_CHUNK_SIZE;
- bc_string_t *new = bc_string_dup(str);
- assert_non_null(new);
- assert_string_equal(new->str, "bola");
- assert_int_equal(new->len, 4);
- assert_int_equal(new->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(new, true));
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_dup(NULL));
-}
-
-
-static void
-test_string_append_len(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "guda");
- assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- str = bc_string_append_len(str, "bola", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "gudabola");
- assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 3);
- str = bc_string_append_len(str, "bola", 4);
- assert_non_null(str);
- assert_string_equal(str->str, "gudbola");
- assert_int_equal(str->len, 7);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- str = bc_string_append_len(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- str = bc_string_append_len(str, NULL, 0);
- str = bc_string_append_len(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid"
- "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax"
- "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv"
- "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh"
- "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj"
- "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd"
- "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw"
- "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf"
- "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm"
- "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc"
- "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw"
- "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii"
- "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc"
- "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx"
- "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh"
- "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt"
- "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
- "fkeannglvsxprqzfekdinssqymtfexf");
- assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE * 10);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append_len(str, NULL, 0);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_len(NULL, "foo", 3));
-}
-
-
-static void
-test_string_append(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append(str, "guda");
- assert_non_null(str);
- assert_string_equal(str->str, "guda");
- assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, "guda");
- str = bc_string_append(str, "bola");
- assert_non_null(str);
- assert_string_equal(str->str, "gudabola");
- assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, "guda");
- str = bc_string_append(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- str = bc_string_append(str, NULL);
- str = bc_string_append(str,
- "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
- "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
- "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
- "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec"
- "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc"
- "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd"
- "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
- "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
- "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid"
- "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax"
- "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv"
- "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh"
- "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj"
- "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd"
- "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw"
- "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf"
- "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm"
- "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc"
- "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw"
- "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii"
- "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc"
- "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx"
- "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh"
- "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt"
- "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
- "fkeannglvsxprqzfekdinssqymtfexf");
- assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE * 10);
- assert_null(bc_string_free(str, true));
- str = bc_string_new();
- str = bc_string_append(str, NULL);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append(NULL, "asd"));
- assert_null(bc_string_append(NULL, NULL));
-}
-
-
-static void
-test_string_append_c(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_len(str, "guda", 4);
- for (int i = 0; i < 600; i++)
- str = bc_string_append_c(str, 'c');
- assert_non_null(str);
- assert_string_equal(str->str,
- "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
- "cccccccccccccccccccccccccccccccccccccccccccccccccccc");
- assert_int_equal(str->len, 604);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE * 5);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_c(NULL, 0));
-}
-
-
-static void
-test_string_append_printf(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_printf(str, "guda: %s %d", "bola", 1);
- assert_non_null(str);
- assert_string_equal(str->str, "guda: bola 1");
- assert_int_equal(str->len, 12);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_printf(NULL, "asd"));
-}
-
-
-static void
-test_string_append_escaped(void **state)
-{
- bc_string_t *str = bc_string_new();
- str = bc_string_append_escaped(str, NULL);
- assert_non_null(str);
- assert_string_equal(str->str, "");
- assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- str = bc_string_append_escaped(str, "foo \\a bar \\\\ lol");
- assert_non_null(str);
- assert_string_equal(str->str, "foo a bar \\ lol");
- assert_int_equal(str->len, 15);
- assert_int_equal(str->allocated_len, BC_STRING_CHUNK_SIZE);
- assert_null(bc_string_free(str, true));
- assert_null(bc_string_append_escaped(NULL, "asd"));
-}
-
-
-static void
-test_trie_new(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
- assert_non_null(trie);
- assert_null(trie->root);
- assert_true(trie->free_func == free);
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_insert(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
-
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
- assert_true(trie->root->child->child->next->key == 't');
- assert_null(trie->root->child->child->next->data);
- assert_true(trie->root->child->child->next->child->key == 'e');
- assert_null(trie->root->child->child->next->child->data);
- assert_true(trie->root->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->next->child->child->data, "aba");
-
-
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->key == 'c');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'h');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'u');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->data, "nda");
-
- assert_true(trie->root->child->child->next->key == 't');
- assert_null(trie->root->child->child->next->data);
- assert_true(trie->root->child->child->next->child->key == 'e');
- assert_null(trie->root->child->child->next->child->data);
- assert_true(trie->root->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->next->child->child->data, "aba");
-
- assert_true(trie->root->child->child->next->next->key == '\0');
- assert_string_equal(trie->root->child->child->next->next->data, "haha");
-
- bc_trie_free(trie);
-
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
-
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->child->child->next->key == 't');
- assert_null(trie->root->next->child->child->next->data);
- assert_true(trie->root->next->child->child->next->child->key == 'e');
- assert_null(trie->root->next->child->child->next->child->data);
- assert_true(trie->root->next->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba");
-
-
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- assert_true(trie->root->key == 'c');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'h');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'u');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->data, "nda");
-
- assert_true(trie->root->next->key == 'b');
- assert_null(trie->root->next->data);
- assert_true(trie->root->next->child->key == 'o');
- assert_null(trie->root->next->child->data);
- assert_true(trie->root->next->child->child->key == 'l');
- assert_null(trie->root->next->child->child->data);
- assert_true(trie->root->next->child->child->child->key == 'a');
- assert_null(trie->root->next->child->child->child->data);
- assert_true(trie->root->next->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
-
- assert_true(trie->root->next->child->child->next->key == 't');
- assert_null(trie->root->next->child->child->next->data);
- assert_true(trie->root->next->child->child->next->child->key == 'e');
- assert_null(trie->root->next->child->child->next->child->data);
- assert_true(trie->root->next->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba");
-
- assert_true(trie->root->next->child->child->next->next->key == '\0');
- assert_string_equal(trie->root->next->child->child->next->next->data, "haha");
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_insert_duplicated(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- bc_trie_insert(trie, "bola", bc_strdup("asdf"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "asdf");
-
- bc_trie_free(trie);
-
- trie = NULL;
- bc_trie_insert(trie, "bola", NULL);
- assert_null(trie);
-}
-
-
-static void
-test_trie_keep_data(void **state)
-{
- bc_trie_t *trie = bc_trie_new(NULL);
-
- char *t1 = "guda";
- char *t2 = "nda";
- char *t3 = "aba";
- char *t4 = "haha";
-
- bc_trie_insert(trie, "bola", t1);
- bc_trie_insert(trie, "chu", t2);
- bc_trie_insert(trie, "bote", t3);
- bc_trie_insert(trie, "bo", t4);
-
- bc_trie_free(trie);
-
- assert_string_equal(t1, "guda");
- assert_string_equal(t2, "nda");
- assert_string_equal(t3, "aba");
- assert_string_equal(t4, "haha");
-}
-
-
-static void
-test_trie_lookup(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
-
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(bc_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(bc_trie_lookup(trie, "bo"), "haha");
-
- assert_null(bc_trie_lookup(trie, "arcoiro"));
-
- bc_trie_free(trie);
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
-
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(bc_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(bc_trie_lookup(trie, "bo"), "haha");
-
- assert_null(bc_trie_lookup(trie, "arcoiro"));
-
- bc_trie_free(trie);
-
- assert_null(bc_trie_lookup(NULL, "bola"));
-}
-
-
-static void
-test_trie_size(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
-
- assert_int_equal(bc_trie_size(trie), 4);
- assert_int_equal(bc_trie_size(NULL), 0);
-
- bc_trie_free(trie);
-
- trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
-
- assert_int_equal(bc_trie_size(trie), 7);
- assert_int_equal(bc_trie_size(NULL), 0);
-
- bc_trie_free(trie);
-}
-
-
-static size_t counter;
-static char *expected_keys[] = {"chu", "copa", "bola", "bote", "bo", "b", "test", "testa"};
-static char *expected_datas[] = {"nda", "bu", "guda", "aba", "haha", "c", "asd", "lol"};
-
-static void
-mock_foreach(const char *key, void *data, void *user_data)
-{
- assert_string_equal(user_data, "foo");
- assert_string_equal(key, expected_keys[counter]);
- assert_string_equal((char*) data, expected_datas[counter++]);
-}
-
-
-static void
-test_trie_foreach(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "chu", bc_strdup("nda"));
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- bc_trie_insert(trie, "bote", bc_strdup("aba"));
- bc_trie_insert(trie, "bo", bc_strdup("haha"));
- bc_trie_insert(trie, "copa", bc_strdup("bu"));
- bc_trie_insert(trie, "b", bc_strdup("c"));
- bc_trie_insert(trie, "test", bc_strdup("asd"));
- bc_trie_insert(trie, "testa", bc_strdup("lol"));
-
- counter = 0;
- bc_trie_foreach(trie, mock_foreach, "foo");
- bc_trie_foreach(NULL, mock_foreach, "foo");
- bc_trie_foreach(trie, NULL, "foo");
- bc_trie_foreach(NULL, NULL, "foo");
- assert_int_equal(counter, 8);
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_trie_inserted_after_prefix(void **state)
-{
- bc_trie_t *trie = bc_trie_new(free);
-
- bc_trie_insert(trie, "bola", bc_strdup("guda"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
-
- bc_trie_insert(trie, "bolaoo", bc_strdup("asdf"));
- assert_true(trie->root->key == 'b');
- assert_null(trie->root->data);
- assert_true(trie->root->child->key == 'o');
- assert_null(trie->root->child->data);
- assert_true(trie->root->child->child->key == 'l');
- assert_null(trie->root->child->child->data);
- assert_true(trie->root->child->child->child->key == 'a');
- assert_null(trie->root->child->child->child->data);
- assert_true(trie->root->child->child->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->data, "guda");
- assert_non_null(trie->root->child->child->child->child->next);
- assert_true(trie->root->child->child->child->child->next->key == 'o');
- assert_null(trie->root->child->child->child->child->next->data);
- assert_true(trie->root->child->child->child->child->next->child->key == 'o');
- assert_null(trie->root->child->child->child->child->next->child->data);
- assert_true(trie->root->child->child->child->child->next->child->child->key == '\0');
- assert_string_equal(trie->root->child->child->child->child->next->child->child->data, "asdf");
-
- assert_int_equal(bc_trie_size(trie), 2);
- assert_string_equal(bc_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(bc_trie_lookup(trie, "bolaoo"), "asdf");
-
- bc_trie_free(trie);
-}
-
-
-static void
-test_shell_quote(void **state)
-{
- char *t;
- t = bc_shell_quote(NULL);
- assert_string_equal(t, "''");
- free(t);
- t = bc_shell_quote("!bola");
- assert_string_equal(t, "''\\!'bola'");
- free(t);
- t = bc_shell_quote("'bola");
- assert_string_equal(t, "''\\''bola'");
- free(t);
- t = bc_shell_quote("bo!bola");
- assert_string_equal(t, "'bo'\\!'bola'");
- free(t);
- t = bc_shell_quote("bo'bola");
- assert_string_equal(t, "'bo'\\''bola'");
- free(t);
- t = bc_shell_quote("bola!");
- assert_string_equal(t, "'bola'\\!''");
- free(t);
- t = bc_shell_quote("bola'");
- assert_string_equal(t, "'bola'\\'''");
- free(t);
-}
-
-
-int
-main(void)
-{
- const UnitTest tests[] = {
-
- // slist
- unit_test(test_slist_append),
- unit_test(test_slist_prepend),
- unit_test(test_slist_free),
- unit_test(test_slist_length),
-
- // strfuncs
- unit_test(test_strdup),
- unit_test(test_strndup),
- unit_test(test_strdup_printf),
- unit_test(test_str_starts_with),
- unit_test(test_str_ends_with),
- unit_test(test_str_lstrip),
- unit_test(test_str_rstrip),
- unit_test(test_str_strip),
- unit_test(test_str_split),
- unit_test(test_str_replace),
- unit_test(test_str_find),
- unit_test(test_str_to_bool),
- unit_test(test_strv_join),
- unit_test(test_strv_length),
-
- // string
- unit_test(test_string_new),
- unit_test(test_string_free),
- unit_test(test_string_dup),
- unit_test(test_string_append_len),
- unit_test(test_string_append),
- unit_test(test_string_append_c),
- unit_test(test_string_append_printf),
- unit_test(test_string_append_escaped),
-
- // trie
- unit_test(test_trie_new),
- unit_test(test_trie_insert),
- unit_test(test_trie_insert_duplicated),
- unit_test(test_trie_keep_data),
- unit_test(test_trie_lookup),
- unit_test(test_trie_size),
- unit_test(test_trie_foreach),
- unit_test(test_trie_inserted_after_prefix),
-
- // shell
- unit_test(test_shell_quote),
- };
- return run_tests(tests);
-}