From 4763814c683c50f8a3697b74e764f19c3dacccd5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 2 Sep 2019 23:38:48 +0200 Subject: migrate codebase to use squareball. again :) --- .gitignore | 1 + .gitmodules | 3 + Makefile.am | 229 ++---- build-aux/build-static.sh | 2 +- build-aux/build-windows.sh | 2 +- configure.ac | 2 + m4/squareball.m4 | 46 ++ squareball | 1 + src/blogc-git-receiver/post-receive.c | 18 +- src/blogc-git-receiver/pre-receive-parser.c | 5 +- src/blogc-git-receiver/pre-receive.c | 53 +- src/blogc-git-receiver/settings.c | 40 +- src/blogc-git-receiver/settings.h | 6 +- src/blogc-git-receiver/shell-command-parser.c | 13 +- src/blogc-git-receiver/shell.c | 13 +- src/blogc-make/atom.c | 48 +- src/blogc-make/atom.h | 5 +- src/blogc-make/ctx.c | 76 +- src/blogc-make/ctx.h | 14 +- src/blogc-make/exec-native.c | 33 +- src/blogc-make/exec-native.h | 5 +- src/blogc-make/exec.c | 208 +++-- src/blogc-make/exec.h | 20 +- src/blogc-make/httpd.c | 15 +- src/blogc-make/httpd.h | 7 +- src/blogc-make/main.c | 22 +- src/blogc-make/reloader.c | 5 +- src/blogc-make/reloader.h | 5 +- src/blogc-make/rules.c | 333 ++++---- src/blogc-make/rules.h | 19 +- src/blogc-make/settings.c | 68 +- src/blogc-make/settings.h | 9 +- src/blogc-make/utils.c | 55 +- src/blogc-make/utils.h | 4 +- src/blogc-runserver/httpd-utils.c | 21 +- src/blogc-runserver/httpd.c | 32 +- src/blogc-runserver/main.c | 17 +- src/blogc-runserver/mime.c | 6 +- src/blogc/content-parser.c | 336 ++++---- src/blogc/datetime-parser.c | 131 ++- src/blogc/datetime-parser.h | 4 +- src/blogc/debug.c | 6 +- src/blogc/debug.h | 4 +- src/blogc/funcvars.c | 8 +- src/blogc/funcvars.h | 6 +- src/blogc/loader.c | 170 ++-- src/blogc/loader.h | 11 +- src/blogc/main.c | 80 +- src/blogc/renderer.c | 81 +- src/blogc/renderer.h | 18 +- src/blogc/rusage.c | 23 +- src/blogc/rusage.h | 4 +- src/blogc/source-parser.c | 78 +- src/blogc/source-parser.h | 7 +- src/blogc/sysinfo.c | 33 +- src/blogc/sysinfo.h | 10 +- src/blogc/template-parser.c | 253 +++--- src/blogc/template-parser.h | 11 +- src/common/compat.c | 39 - src/common/compat.h | 14 - src/common/config-parser.c | 442 ---------- src/common/config-parser.h | 31 - src/common/error.c | 158 ---- src/common/error.h | 47 -- src/common/file.c | 66 -- src/common/file.h | 20 - src/common/sort.c | 44 - src/common/sort.h | 18 - src/common/stdin.c | 24 - src/common/stdin.h | 14 - src/common/utf8.c | 102 --- src/common/utf8.h | 21 - src/common/utils.c | 701 ---------------- src/common/utils.h | 109 --- tests/blogc-git-receiver/check_settings.c | 20 +- tests/blogc-make/check_atom.c | 195 +++-- tests/blogc-make/check_exec.c | 115 ++- tests/blogc-make/check_rules.c | 81 +- tests/blogc-make/check_settings.c | 187 ++--- tests/blogc-make/check_utils.c | 3 +- tests/blogc-runserver/check_httpd_utils.c | 5 +- tests/blogc/check_datetime_parser.c | 336 ++++---- tests/blogc/check_funcvars.c | 33 +- tests/blogc/check_loader.c | 919 +++++++++++---------- tests/blogc/check_renderer.c | 398 ++++----- tests/blogc/check_rusage.c | 15 +- tests/blogc/check_source_parser.c | 376 ++++----- tests/blogc/check_sysinfo.c | 41 +- tests/blogc/check_sysinfo2.c | 9 +- tests/blogc/check_template_parser.c | 495 +++++------ tests/common/check_config_parser.c | 1037 ----------------------- tests/common/check_error.c | 109 --- tests/common/check_sort.c | 148 ---- tests/common/check_stdin.c | 54 -- tests/common/check_utf8.c | 101 --- tests/common/check_utils.c | 1095 ------------------------- 96 files changed, 2892 insertions(+), 7465 deletions(-) create mode 100644 .gitmodules create mode 100644 m4/squareball.m4 create mode 160000 squareball delete mode 100644 src/common/compat.c delete mode 100644 src/common/compat.h delete mode 100644 src/common/config-parser.c delete mode 100644 src/common/config-parser.h delete mode 100644 src/common/error.c delete mode 100644 src/common/error.h delete mode 100644 src/common/file.c delete mode 100644 src/common/file.h delete mode 100644 src/common/sort.c delete mode 100644 src/common/sort.h delete mode 100644 src/common/stdin.c delete mode 100644 src/common/stdin.h delete mode 100644 src/common/utf8.c delete mode 100644 src/common/utf8.h delete mode 100644 src/common/utils.c delete mode 100644 src/common/utils.h delete mode 100644 tests/common/check_config_parser.c delete mode 100644 tests/common/check_error.c delete mode 100644 tests/common/check_sort.c delete mode 100644 tests/common/check_stdin.c delete mode 100644 tests/common/check_utf8.c delete mode 100644 tests/common/check_utils.c 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 +# +# 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 index 0000000..dd5b2fc --- /dev/null +++ b/squareball @@ -0,0 +1 @@ +Subproject commit dd5b2fc6fd395b5ad1efb4eba7fece9ba76b0a59 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 #include #include -#include "../common/utils.h" -#include "../common/config-parser.h" +#include + #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 #include -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/compat.h" -#include "../common/utils.h" -#include "../common/stdin.h" +#include + #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 #include #include -#include "../common/utils.h" -#include "../common/config-parser.h" -#include "../common/error.h" -#include "../common/file.h" +#include + #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 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 #include #include -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/error.h" -#include "../common/utils.h" +#include + #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 + #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 #include #include +#include #include #include -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" +#include + #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 #include #include +#include + #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 #include #include -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" -#include "exec-native.h" +#include + #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 -#include "../common/error.h" +#include + #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 #include #include -#include "../common/compat.h" -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" +#include + #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 -#include "../common/error.h" -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/utils.h" +#include + #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 + #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 #include #include -#include "../common/error.h" -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/utils.h" +#include + #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 + #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 #include #include -#include "../common/utils.h" +#include + #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 +#include + #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 #include #include -#include "../common/config-parser.h" -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" +#include + #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 -#include "../common/error.h" -#include "../common/utils.h" +#include 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 #include #include -#include "../common/error.h" -#include "../common/utils.h" +#include + +#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 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 #include #include -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/utils.h" +#include + #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 #include #include -#include "../common/utils.h" +#include + #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 #include #include +#include #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, "%s", tmp2); + sb_string_append_printf(rv, "%s", 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, "%s", tmp2); + sb_string_append_printf(rv, "%s", 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, "%s", tmp2); + sb_string_append_printf(rv, "%s", 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, "%s", tmp2); + sb_string_append_printf(rv, "%s", 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, ""); - bc_string_append(rv, tmp2); - bc_string_append(rv, ""); + sb_string_append(rv, ""); + sb_string_append(rv, tmp2); + sb_string_append(rv, ""); 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, ""); - bc_string_append(rv, tmp2); - bc_string_append(rv, ""); + sb_string_append(rv, ""); + sb_string_append(rv, tmp2); + sb_string_append(rv, ""); 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, ""); - bc_string_append_escaped(rv, tmp2); - bc_string_append(rv, ""); + tmp2 = sb_strndup(src + current, (tmp - src) - current); + sb_string_append(rv, ""); + sb_string_append_escaped(rv, tmp2); + sb_string_append(rv, ""); 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, "%s", tmp3); + sb_string_append(rv, "%s", 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, "\"");"); + tmp2 = sb_strndup(src + start, current - start); + 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, "–"); + sb_string_append(rv, "–"); 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, "—"); + sb_string_append(rv, "—"); state = CONTENT_INLINE_START; break; } - bc_string_append(rv, "–"); + sb_string_append(rv, "–"); state = CONTENT_INLINE_START; continue; case CONTENT_INLINE_LINE_BREAK_START: if (c == ' ') { if (is_last) { - bc_string_append(rv, "
"); + sb_string_append(rv, "
"); 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, "
"); + sb_string_append(rv, "
"); 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, "
%c", c); + sb_string_append_printf(rv, "
%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, "%s%s", + sb_string_append_printf(rv, "%s%s", header_level, parsed, header_level, line_ending); else - bc_string_append_printf(rv, "%s%s", + sb_string_append_printf(rv, "%s%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, "
%s
%s", + sb_string_append_printf(rv, "
%s
%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, "
");
-                    for (bc_slist_t *l = lines; l != NULL; l = l->next) {
+                    sb_string_append(rv, "
");
+                    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, "
%s", line_ending); - bc_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%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, "
%s", line_ending); + sb_string_append_printf(rv, "
%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, "
    %s", line_ending); - for (bc_slist_t *l = lines; l != NULL; l = l->next) - bc_string_append_printf(rv, "
  • %s
  • %s", l->data, + sb_string_append_printf(rv, "
      %s", line_ending); + for (sb_slist_t *l = lines; l != NULL; l = l->next) + sb_string_append_printf(rv, "
    • %s
    • %s", l->data, line_ending); - bc_string_append_printf(rv, "
    %s", line_ending); - bc_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%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, "
    %s", line_ending); - for (bc_slist_t *l = lines; l != NULL; l = l->next) - bc_string_append_printf(rv, "
  1. %s
  2. %s", l->data, + sb_string_append_printf(rv, "
      %s", line_ending); + for (sb_slist_t *l = lines; l != NULL; l = l->next) + sb_string_append_printf(rv, "
    1. %s
    2. %s", l->data, line_ending); - bc_string_append_printf(rv, "
    %s", line_ending); - bc_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%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, "

%s

%s", parsed, + sb_string_append_printf(rv, "

%s

%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 +#include #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 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 +#include #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: