aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore9
-rw-r--r--.travis.yml34
-rw-r--r--Makefile.am150
-rw-r--r--README.md8
-rw-r--r--blogc.spec.in78
-rwxr-xr-xbuild-aux/build-windows.sh48
-rwxr-xr-xbuild-aux/travis-build.sh21
-rwxr-xr-xbuild-aux/travis-deploy.sh67
-rw-r--r--configure.ac86
-rw-r--r--man/blogc-git-receiver.1.ronn126
-rw-r--r--man/blogc-pagination.7.ronn122
-rw-r--r--man/blogc-runserver.1.ronn48
-rw-r--r--man/blogc-source.7.ronn31
-rw-r--r--man/blogc.1.ronn4
-rw-r--r--man/index.txt18
-rw-r--r--src/blogc-git-receiver.c502
-rw-r--r--src/blogc-runserver.c389
-rw-r--r--src/blogc.c (renamed from src/main.c)52
-rw-r--r--src/content-parser.c349
-rw-r--r--src/content-parser.h3
-rw-r--r--src/datetime-parser.c4
-rw-r--r--src/directives.c8
-rw-r--r--src/directives.h4
-rw-r--r--src/error.c12
-rw-r--r--src/file.c8
-rw-r--r--src/loader.c84
-rw-r--r--src/loader.h8
-rw-r--r--src/renderer.c68
-rw-r--r--src/renderer.h16
-rw-r--r--src/source-parser.c40
-rw-r--r--src/source-parser.h4
-rw-r--r--src/template-parser.c42
-rw-r--r--src/template-parser.h6
-rw-r--r--src/utils.c612
-rw-r--r--src/utils.h102
-rw-r--r--src/utils/mem.c42
-rw-r--r--src/utils/slist.c68
-rw-r--r--src/utils/strings.c314
-rw-r--r--src/utils/trie.c199
-rw-r--r--src/utils/utils.h79
-rw-r--r--tests/check_content_parser.c659
-rw-r--r--tests/check_error.c2
-rw-r--r--tests/check_loader.c545
-rw-r--r--tests/check_renderer.c288
-rw-r--r--tests/check_source_parser.c180
-rw-r--r--tests/check_template_parser.c80
-rw-r--r--tests/check_utils.c524
47 files changed, 4100 insertions, 2043 deletions
diff --git a/.gitignore b/.gitignore
index 01d2647..e0ac2c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,8 +32,9 @@ Makefile.in
/stamp-h1
.dirstamp
/build-aux/*
-!/build-aux/build-windows.sh
!/build-aux/git-version-gen
+!/build-aux/travis-build.sh
+!/build-aux/travis-deploy.sh
# installed .m4 files
/m4/*.m4
@@ -43,8 +44,10 @@ Makefile.in
/blogc*.[17]
blogc*.html
-# blogc
+# binaries
/blogc
+/blogc-git-receiver
+/blogc-runserver
# tests
/tests/check_content_parser
@@ -66,3 +69,5 @@ blogc-*.rpm
# git-version-gen
/.version
+
+/build/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..15c4906
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,34 @@
+dist: trusty
+sudo: required
+language: c
+
+addons:
+ apt:
+ packages:
+ - libcmocka-dev
+ - libmagic-dev
+ - libevent-dev
+ - rpm
+ - valgrind
+
+compiler:
+ - clang
+ - gcc
+
+env:
+ - TARGET=valgrind
+ - TARGET=distcheck
+ - TARGET=dist-srpm
+
+matrix:
+ exclude:
+ - compiler: clang
+ env: TARGET=dist-srpm
+
+install: gem install ronn
+
+before_script: ./autogen.sh
+
+script:
+ - ./build-aux/travis-build.sh
+ - ./build-aux/travis-deploy.sh
diff --git a/Makefile.am b/Makefile.am
index 2c36543..5ebb3bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,15 +4,16 @@ ACLOCAL_AMFLAGS = -I m4
AM_DISTCHECK_CONFIGURE_FLAGS = \
--enable-tests \
- --enable-ronn \
+ --disable-ronn \
--disable-valgrind \
+ --enable-git-receiver \
+ --enable-runserver \
$(NULL)
## File listings
EXTRA_DIST = \
- build-aux/build-windows.sh \
build-aux/git-version-gen \
$(top_srcdir)/.version \
autogen.sh \
@@ -40,11 +41,12 @@ noinst_HEADERS = \
src/renderer.h \
src/source-parser.h \
src/template-parser.h \
- src/utils/utils.h \
+ src/utils.h \
$(NULL)
noinst_LTLIBRARIES = \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
noinst_PROGRAMS = \
@@ -54,6 +56,18 @@ bin_PROGRAMS = \
blogc \
$(NULL)
+if BUILD_GIT_RECEIVER
+bin_PROGRAMS += \
+ blogc-git-receiver \
+ $(NULL)
+endif
+
+if BUILD_RUNSERVER
+bin_PROGRAMS += \
+ blogc-runserver \
+ $(NULL)
+endif
+
check_PROGRAMS = \
$(NULL)
@@ -68,10 +82,6 @@ libblogc_la_SOURCES = \
src/renderer.c \
src/source-parser.c \
src/template-parser.c \
- src/utils/mem.c \
- src/utils/slist.c \
- src/utils/strings.c \
- src/utils/trie.c \
$(NULL)
libblogc_la_CFLAGS = \
@@ -84,8 +94,18 @@ libblogc_la_LIBADD = \
$(NULL)
+libblogc_utils_la_SOURCES = \
+ src/utils.c \
+ $(NULL)
+
+libblogc_utils_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ -I$(top_srcdir)/src \
+ $(NULL)
+
+
blogc_SOURCES = \
- src/main.c \
+ src/blogc.c \
$(NULL)
blogc_CFLAGS = \
@@ -95,23 +115,78 @@ blogc_CFLAGS = \
blogc_LDADD = \
libblogc.la \
+ libblogc_utils.la \
+ $(NULL)
+
+
+if BUILD_GIT_RECEIVER
+blogc_git_receiver_SOURCES = \
+ src/blogc-git-receiver.c \
+ $(NULL)
+
+blogc_git_receiver_CFLAGS = \
+ $(AM_CFLAGS) \
+ -I$(top_srcdir)/src \
$(NULL)
+blogc_git_receiver_LDADD = \
+ libblogc_utils.la \
+ $(NULL)
+endif
+
+
+if BUILD_RUNSERVER
+blogc_runserver_SOURCES = \
+ src/blogc-runserver.c \
+ $(NULL)
+
+blogc_runserver_CFLAGS = \
+ $(AM_CFLAGS) \
+ -I$(top_srcdir)/src \
+ $(LIBEVENT_CFLAGS) \
+ $(SQUAREBALL_CFLAGS) \
+ $(NULL)
+
+blogc_runserver_LDADD = \
+ $(LIBEVENT_LIBS) \
+ $(MAGIC_LIBS) \
+ libblogc_utils.la \
+ $(NULL)
+endif
+
## Build rules: man pages
EXTRA_DIST += \
man/blogc.1.ronn \
+ man/blogc-git-receiver.1.ronn \
+ man/blogc-runserver.1.ronn \
man/blogc-source.7.ronn \
man/blogc-template.7.ronn \
+ man/blogc-pagination.7.ronn \
man/index.txt \
+ blogc-git-receiver.1 \
+ blogc-runserver.1 \
$(NULL)
dist_man_MANS = \
blogc.1 \
blogc-source.7 \
blogc-template.7 \
+ blogc-pagination.7 \
+ $(NULL)
+
+if BUILD_GIT_RECEIVER
+dist_man_MANS += \
+ blogc-git-receiver.1 \
$(NULL)
+endif
+
+if BUILD_RUNSERVER
+dist_man_MANS += \
+ blogc-runserver.1 \
+ $(NULL)
+endif
MAINTAINERCLEANFILES += \
$(dist_man_MANS) \
@@ -125,7 +200,23 @@ blogc.1: man/blogc.1.ronn
--pipe \
--organization "Rafael G. Martins" \
--manual "$(PACKAGE_NAME) Manual" \
- $< > $@
+ $(top_srcdir)/man/blogc.1.ronn > blogc.1
+
+blogc-git-receiver.1: man/blogc-git-receiver.1.ronn
+ $(AM_V_GEN)$(RONN) \
+ --roff \
+ --pipe \
+ --organization "Rafael G. Martins" \
+ --manual "$(PACKAGE_NAME) Manual" \
+ $(top_srcdir)/man/blogc-git-receiver.1.ronn > blogc-git-receiver.1
+
+blogc-runserver.1: man/blogc-runserver.1.ronn
+ $(AM_V_GEN)$(RONN) \
+ --roff \
+ --pipe \
+ --organization "Rafael G. Martins" \
+ --manual "$(PACKAGE_NAME) Manual" \
+ $(top_srcdir)/man/blogc-runserver.1.ronn > blogc-runserver.1
blogc-source.7: man/blogc-source.7.ronn
$(AM_V_GEN)$(RONN) \
@@ -133,7 +224,7 @@ blogc-source.7: man/blogc-source.7.ronn
--pipe \
--organization "Rafael G. Martins" \
--manual "$(PACKAGE_NAME) Manual" \
- $< > $@
+ $(top_srcdir)/man/blogc-source.7.ronn > blogc-source.7
blogc-template.7: man/blogc-template.7.ronn
$(AM_V_GEN)$(RONN) \
@@ -141,19 +232,36 @@ blogc-template.7: man/blogc-template.7.ronn
--pipe \
--organization "Rafael G. Martins" \
--manual "$(PACKAGE_NAME) Manual" \
- $< > $@
+ $(top_srcdir)/man/blogc-template.7.ronn > blogc-template.7
+
+blogc-pagination.7: man/blogc-pagination.7.ronn
+ $(AM_V_GEN)$(RONN) \
+ --roff \
+ --pipe \
+ --organization "Rafael G. Martins" \
+ --manual "$(PACKAGE_NAME) Manual" \
+ $(top_srcdir)/man/blogc-pagination.7.ronn > blogc-pagination.7
else
blogc.1:
$(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
+blogc-git-receiver.1:
+ $(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
+
+blogc-runserver.1:
+ $(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
+
blogc-source.7:
$(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
blogc-template.7:
$(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
+blogc-pagination.7:
+ $(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1
+
endif
@@ -187,6 +295,7 @@ tests_check_error_LDFLAGS = \
tests_check_error_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_loader_SOURCES = \
@@ -206,6 +315,7 @@ tests_check_loader_LDFLAGS = \
tests_check_loader_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_content_parser_SOURCES = \
@@ -224,6 +334,7 @@ tests_check_content_parser_LDFLAGS = \
tests_check_content_parser_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_datetime_parser_SOURCES = \
@@ -241,6 +352,7 @@ tests_check_datetime_parser_LDFLAGS = \
tests_check_datetime_parser_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_renderer_SOURCES = \
@@ -258,6 +370,7 @@ tests_check_renderer_LDFLAGS = \
tests_check_renderer_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_source_parser_SOURCES = \
@@ -275,6 +388,7 @@ tests_check_source_parser_LDFLAGS = \
tests_check_source_parser_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_template_parser_SOURCES = \
@@ -292,6 +406,7 @@ tests_check_template_parser_LDFLAGS = \
tests_check_template_parser_LDADD = \
$(CMOCKA_LIBS) \
libblogc.la \
+ libblogc_utils.la \
$(NULL)
tests_check_utils_SOURCES = \
@@ -308,7 +423,7 @@ tests_check_utils_LDFLAGS = \
tests_check_utils_LDADD = \
$(CMOCKA_LIBS) \
- libblogc.la \
+ libblogc_utils.la \
$(NULL)
endif
@@ -317,6 +432,17 @@ TESTS = \
$(check_PROGRAMS)
+## Helpers: dist-srpm
+
+if USE_RPMBUILD
+dist-srpm: blogc.spec dist-xz
+ $(RPMBUILD) \
+ --define "_srcrpmdir $(top_builddir)" \
+ --define "_sourcedir $(top_builddir)" \
+ -bs blogc.spec
+endif
+
+
## Helpers: git-version-gen
$(top_srcdir)/.version:
diff --git a/README.md b/README.md
index f675267..d5b968e 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# blogc
-[![Build Status](https://semaphoreci.com/api/v1/projects/bd67545c-8593-4a37-ba94-ef1187a6d58d/402577/badge.svg)](https://semaphoreci.com/blogc/blogc)
+[![Build Status](https://travis-ci.org/blogc/blogc.svg?branch=master)](https://travis-ci.org/blogc/blogc)
A blog compiler.
@@ -12,10 +12,12 @@ Clone the [Git repository](https://github.com/blogc/blogc) or grab the [latest r
Inside the source directory, run the following commands:
$ ./autogen.sh # if installing from git
- $ ./configure
+ $ ./configure [--enable-git-receiver] [--enable-runserver]
$ make
# make install
+The `./configure` options listed above will enable building of helper tools. To learn more about these tools, please read the man pages.
+
To create your first blog, please clone our example repository and adapt it to your needs:
$ git clone https://github.com/blogc/blogc-example my-blog
@@ -24,7 +26,7 @@ To create your first blog, please clone our example repository and adapt it to y
$ git init
$ git commit -am 'initial commit'
-At this point you'll have an empty blog, that can be customized to suit your needs. You'll want to look at the 'post/' directory and edit your first post. Each new post, template or asset must be added to the Makefile. Please read it carefully.
+At this point you'll have an empty blog, that can be customized to suit your needs. You'll want to look at the `content/post/` directory and edit your first post. Each new post, template or asset must be added to the `Makefile`. Please read it carefully.
If some unexpected error happened, please [file an issue](https://github.com/blogc/blogc/issues/new).
diff --git a/blogc.spec.in b/blogc.spec.in
index 3d76ecb..534b5c1 100644
--- a/blogc.spec.in
+++ b/blogc.spec.in
@@ -1,43 +1,85 @@
-Name: @PACKAGE_NAME@
-Version: @PACKAGE_VERSION@
-Release: 1%{?dist}
-License: BSD
-Group: Applications/Text
-Summary: A blog compiler
-URL: @PACKAGE_URL@
-Source0: https://github.com/blogc/blogc/releases/download/v%{version}/blogc-%{version}.tar.xz
-
-#BuildRequires:
-#Requires:
+Name: @PACKAGE_NAME@
+Version: @RPM_VERSION@
+Release: 1%{?dist}
+License: BSD
+Group: Applications/Text
+Summary: A blog compiler
+URL: @PACKAGE_URL@
+Source0: https://github.com/blogc/blogc/releases/download/v@PACKAGE_VERSION@/blogc-@PACKAGE_VERSION@.tar.xz
+BuildRequires: libevent-devel >= 2.0, file-devel
%description
blogc(1) is a blog compiler. It converts source files and templates into
blog/website resources.
+%package git-receiver
+Summary: A simple login shell/git hook to deploy blogc websites
+Group: System Environment/Shells
+Requires: git, tar, make
-%prep
-%setup -q -n blogc-%{version}
+%description git-receiver
+blogc-git-receiver is a simple login shell/git hook to deploy blogc websites.
+
+%package runserver
+Summary: A simple HTTP server to test blogc websites
+Group: Development/Tools
+Requires: libevent >= 2.0, file-libs
+
+%description runserver
+blogc-runserver is a simple HTTP server to test blogc websites.
+%prep
+%setup -q -n @PACKAGE_NAME@-@PACKAGE_VERSION@
%build
-%configure
+%configure --enable-git-receiver --enable-runserver
make %{?_smp_mflags}
-
%install
rm -rf $RPM_BUILD_ROOT
%make_install
-
%files
-%{_mandir}/man*/blogc*
+%{_mandir}/man*/blogc.*
+%{_mandir}/man*/blogc-source.*
+%{_mandir}/man*/blogc-template.*
+%{_mandir}/man*/blogc-pagination.*
%{_bindir}/blogc
-
%doc README.md
%license LICENSE
+%files git-receiver
+%{_mandir}/man*/blogc-git-receiver.*
+%{_bindir}/blogc-git-receiver
+%license LICENSE
+
+%files runserver
+%{_mandir}/man*/blogc-runserver.*
+%{_bindir}/blogc-runserver
+%license LICENSE
%changelog
+* Sat Apr 30 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.9.0-1
+- New release. Merged blogc-git-receiver and blogc-runserver.
+
+* Sun Apr 17 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.8.1-1
+- New release.
+
+* Wed Apr 6 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.8.0-1
+- New release.
+
+* Mon Feb 29 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.7.6-1
+- New release. Added new dependency.
+
+* Sun Feb 21 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.7.5-1
+- New release.
+
+* Sun Feb 21 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.7.4-1
+- New release.
+
+* Sat Feb 20 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.7.3-1
+- New release.
+
* Mon Jan 25 2016 Rafael G. Martins <rafael@rafaelmartins.eng.br> 0.7.2-1
- New release.
diff --git a/build-aux/build-windows.sh b/build-aux/build-windows.sh
deleted file mode 100755
index bdecc8b..0000000
--- a/build-aux/build-windows.sh
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/bash
-
-# This script builds windows binaries, given a source tarball.
-# It was designed to work on Fedora, and requires the following packages:
-#
-# mingw32-gcc mingw64-gcc zip
-#
-# This script must be called with the xz source tarball and the target version
-# as arguments.
-
-
-set -ex
-
-[[ $# -eq 2 ]]
-
-
-build() {
- local version=${2}
- local arch=${3}
- local build_dir="/tmp/blogc_build_${version}_${arch}"
- local dest_dir="/tmp/blogc-${version}-w${arch}"
-
- rm -rf "${build_dir}"
- mkdir -p "${build_dir}"
- tar -xvf "${1}" -C "${build_dir}"
-
- pushd "${build_dir}/blogc-${version}" &> /dev/null
- "mingw${arch}-configure"
- make
- popd &> /dev/null
-
- rm -rf "${dest_dir}"
- mkdir -p "${dest_dir}"
- cp "${build_dir}/blogc-${version}/.libs/blogc.exe" "${dest_dir}/"
- cp "${build_dir}/blogc-${version}/LICENSE" "${dest_dir}/"
- cp "${build_dir}/blogc-${version}/README.md" "${dest_dir}/"
-
- pushd "$(dirname ${dest_dir})" &> /dev/null
- zip "$(basename ${dest_dir}).zip" "$(basename ${dest_dir})"/*
- popd &> /dev/null
-
- mv "${dest_dir}.zip" .
-}
-
-
-for arch in 32 64; do
- build "$1" "$2" "${arch}"
-done
diff --git a/build-aux/travis-build.sh b/build-aux/travis-build.sh
new file mode 100755
index 0000000..53cf589
--- /dev/null
+++ b/build-aux/travis-build.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+set -ex
+
+rm -rf build
+mkdir -p build
+
+pushd build > /dev/null
+
+../configure \
+ CFLAGS="-Wall -g" \
+ --enable-ronn \
+ --disable-silent-rules \
+ --enable-tests \
+ --enable-valgrind \
+ --enable-git-receiver \
+ --enable-runserver
+
+popd > /dev/null
+
+make -C build "${TARGET}"
diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh
new file mode 100755
index 0000000..51aac3e
--- /dev/null
+++ b/build-aux/travis-deploy.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+set -e
+
+if [[ "x${TRAVIS_PULL_REQUEST}" != "xfalse" ]]; then
+ echo "This is a pull request. skipping deploy ..."
+ exit 0
+fi
+
+if [[ "x${TRAVIS_BRANCH}" != "xmaster" ]] && [[ "x${TRAVIS_TAG}" != xv* ]]; then
+ echo "This isn't master branch nor a valid tag. skipping deploy ..."
+ exit 0
+fi
+
+if [[ "x${CC}" != "xgcc" ]] || [[ "x${TARGET}" = "xvalgrind" ]]; then
+ echo "Invalid target for deploy. skipping ..."
+ exit 0
+fi
+
+if [[ ! -d build ]]; then
+ echo "Build directory not found."
+ exit 1
+fi
+
+if [[ "x${TARGET}" = "xdist-srpm" ]]; then
+ FILES=( build/*.src.rpm )
+else
+ FILES=( build/*.{*.tar.{gz,bz2,xz},zip} )
+fi
+
+TARNAME="$(grep PACKAGE_TARNAME build/config.h | cut -d\" -f2)"
+VERSION="$(grep PACKAGE_VERSION build/config.h | cut -d\" -f2)"
+
+do_curl() {
+ curl \
+ --silent \
+ --ftp-create-dirs \
+ --upload-file "${1}" \
+ --user "${FTP_USER}:${FTP_PASSWORD}" \
+ "ftp://${FTP_HOST}/public_html/${TARNAME}/${TARNAME}-${VERSION}/$(basename ${1})"
+}
+
+echo " * Found files:"
+for f in "${FILES[@]}"; do
+ echo " $(basename ${f})"
+done
+echo
+
+for f in "${FILES[@]}"; do
+ echo " * Processing file: $(basename ${f}):"
+
+ echo -n " Generating SHA512 checksum ... "
+ pushd build > /dev/null
+ sha512sum "$(basename ${f})" > "$(basename ${f}).sha512"
+ popd > /dev/null
+ echo "done"
+
+ echo -n " Uploading file ... "
+ do_curl "${f}"
+ echo "done"
+
+ echo -n " Uploading SHA512 checksum ... "
+ do_curl "${f}.sha512"
+ echo "done"
+
+ echo
+done
diff --git a/configure.ac b/configure.ac
index bdb7c1e..0e36070 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,30 @@ AS_IF([test "x$ac_cv_prog_cc_c99" = "xno"], [
PKG_PROG_PKG_CONFIG
+AC_PROG_SED
+
+RPM_VERSION=`echo ${PACKAGE_VERSION} | sed "s/-/./g"`
+AC_SUBST(RPM_VERSION)
+
+AC_ARG_ENABLE([rpmbuild], AS_HELP_STRING([--disable-rpmbuild],
+ [ignore presence of rpmbuild and disable srpm generation]))
+AS_IF([test "x$enable_rpmbuild" != "xno"], [
+ AC_PATH_PROG([rpmbuild], [rpmbuild])
+ AS_IF([test "x$ac_cv_path_rpmbuild" = "x"], [
+ have_rpmbuild=no
+ ], [
+ have_rpmbuild=yes
+ ])
+])
+AS_IF([test "x$have_rpmbuild" = "xyes"], , [
+ AS_IF([test "x$enable_rpmbuild" = "xyes"], [
+ AC_MSG_ERROR([rpmbuild requested but not found])
+ ])
+])
+AM_CONDITIONAL([USE_RPMBUILD], [test "x$ac_cv_path_rpmbuild" != "x"])
+RPMBUILD="$ac_cv_path_rpmbuild"
+AC_SUBST(RPMBUILD)
+
AC_ARG_ENABLE([ronn], AS_HELP_STRING([--disable-ronn],
[ignore presence of ronn and disable man pages generation]))
AS_IF([test "x$enable_ronn" != "xno"], [
@@ -95,29 +119,67 @@ AS_IF([test "x$have_cmocka" = "xyes"], , [
])
AM_CONDITIONAL([USE_CMOCKA], [test "x$have_cmocka" = "xyes"])
+GIT_RECEIVER="disabled"
+AC_ARG_ENABLE([git-receiver], AS_HELP_STRING([--enable-git-receiver],
+ [build blogc-git-receiver tool]))
+AS_IF([test "x$enable_git_receiver" = "xyes"], [
+ AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h libgen.h unistd.h errno.h dirent.h], [
+ GIT_RECEIVER="enabled"
+ have_git_receiver=yes
+ ], [
+ AC_MSG_ERROR([blogc-git-receiver tool requested but required headers not found])
+ ])
+])
+AM_CONDITIONAL([BUILD_GIT_RECEIVER], [test "x$have_git_receiver" = "xyes"])
+
+RUNSERVER="disabled"
+AC_ARG_ENABLE([runserver], AS_HELP_STRING([--enable-runserver],
+ [build blogc-runserver tool]))
+AS_IF([test "x$enable_runserver" = "xyes"], [
+ AC_CHECK_HEADERS([signal.h stdarg.h fcntl.h unistd.h sys/stat.h sys/types.h],, [
+ AC_MSG_ERROR([blogc-runserver tool requested but required headers not found])
+ ])
+ AC_CHECK_HEADERS([magic.h],, [
+ AC_MSG_ERROR([blogc-runserver tool requested but libmagic headers not found])
+ ])
+ AC_CHECK_LIB(magic, [magic_open], [MAGIC_LIBS="-lmagic"], [
+ AC_MSG_ERROR([blogc-runserver tool requested but libmagic library not found])
+ ])
+ AC_SUBST(MAGIC_LIBS)
+ PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0])
+ RUNSERVER="enabled"
+ have_runserver=yes
+])
+AM_CONDITIONAL([BUILD_RUNSERVER], [test "x$have_runserver" = "xyes"])
+
AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h])
LT_LIB_M
AC_CONFIG_FILES([
- Makefile
- blogc.spec
+ Makefile
+ blogc.spec
])
+
AC_OUTPUT
AS_ECHO("
- ==== ${PACKAGE_STRING} ====
+ ====== ${PACKAGE_STRING} ======
+
+ prefix: ${prefix}
+ exec_prefix: ${exec_prefix}
+ bindir: ${bindir}
- prefix: ${prefix}
- exec_prefix: ${exec_prefix}
- bindir: ${bindir}
+ compiler: ${CC}
+ cflags: ${CFLAGS}
+ ldflags: ${LDFLAGS}
- compiler: ${CC}
- cflags: ${CFLAGS}
- ldflags: ${LDFLAGS}
+ blogc-git-receiver: ${GIT_RECEIVER}
+ blogc-runserver: ${RUNSERVER}
- tests: ${TESTS}
+ tests: ${TESTS}
- ronn: ${RONN}
- valgrind: ${VALGRIND}
+ ronn: ${RONN}
+ valgrind: ${VALGRIND}
+ rpmbuild: ${RPMBUILD}
")
diff --git a/man/blogc-git-receiver.1.ronn b/man/blogc-git-receiver.1.ronn
new file mode 100644
index 0000000..e26ed09
--- /dev/null
+++ b/man/blogc-git-receiver.1.ronn
@@ -0,0 +1,126 @@
+blogc-git-receiver(1) -- a simple login shell/git hook to deploy blogc websites
+===============================================================================
+
+## SYNOPSIS
+
+chsh -s $(command -v `blogc-git-receiver`) <user>
+
+## DESCRIPTION
+
+**blogc-git-receiver** provides a PaaS-like way to deploy blogc(1) websites.
+When used as a login shell, it will accept git payloads, creating bare repositories
+as needed, and installing a hook, that will take care of rebuilding the website each
+time someone push something to the `master` branch.
+
+The git repository must provide a `Makefile` (or a `GNUMakefile`), that should
+accept the `OUTPUT_DIR` variable, and install built files in the directory pointed
+by this variable.
+
+`blogc-git-receiver` is part of `blogc` project, but isn't tied to blogc(1). Any
+repository with `Makefile` that builds content and install it to `OUTPUT_DIR`
+should works with `blogc-git-receiver`.
+
+## SETUP
+
+After creating an user (`blogc` for the examples), change its shell to
+blogc-git-receiver(1):
+
+ # chsh -s $(command -v blogc-git-receiver) blogc
+
+Now add ssh keys to `/home/blogc/.ssh/authorized_keys`. Every key in
+`authorized_keys` will be allowed to push to the git repositories, and even
+create new ones.
+
+Also, make sure to install all the dependencies required by the websites,
+including a web server. `blogc-git-receiver` can't handle web server virtual hosts.
+
+To deploy a website (e.g. blogc example repository):
+
+ $ git clone https://github.com/blogc/blogc-example.git
+ $ cd blogc-example
+ $ git remote add blogc blogc@${SERVER_IP}:blogs/blogc-example.git
+ $ git push blogc master
+
+This will deploy the example to the server, creating a symlink to the built content
+in `/home/blogc/repos/blogs/blogc-example.git/htdocs`. This symlink should be used
+as the document root for the web server virtual host.
+
+### Setup with SELinux enabled (Fedora)
+
+Supposing the usage of nginx as webserver, running as the `nginx` user:
+
+ # dnf install -y nginx policycoreutils-python-utils
+ # useradd -m -s $(command -v blogc-git-receiver) blogc
+ # gpasswd -a nginx blogc
+ # chmod -R g+rx /home/blogc
+ # su -c "mkdir /home/blogc/{builds,repos}" -s /bin/sh blogc
+ # semanage fcontext -a -t httpd_sys_content_t "/home/blogc/(builds|repos)(/.*)?"
+ # restorecon -R -v /home/blogc
+ # systemctl restart nginx
+
+After running these commands, the machine is ready to be used.
+
+## REPOSITORY MIRRORING
+
+Users can rely on `blogc-git-receiver` to mirror repositories to a remote Git
+repository (e.g. a free Bitbucket private repository). This feature just requires
+adding a remote called `mirror` to the bare repository in the server. If such remote
+exists, `blogc-git-receiver` will `git push --mirror` to it.
+
+Please note that the `blogc` user must be able to push to the remote repository, and
+that any content manually pushed to the remote repository is overwritten by
+`blogc-git-receiver`.
+
+Some reasonable ways to allow the `blogc` user to push to the remote repository are:
+
+- Create a password-less SSH key. The key *must* be password-less, because the push
+ is automatic, and remote git hooks can't be interactive.
+- Create an oauth token in the hosting service (if it supports oauth authentication
+ in git, e.g. GitHub) and add it to the git URL.
+
+The mirroring feature wont't block a `git push`, it will just raise warnings. That
+means that if an error happens when mirroring the repository, the deploy will still
+succeed. Users should pay attention to the git hook logs, to avoid losing data
+due to repositories not being mirrored.
+
+To add the `mirror` remote:
+
+ # su -s /bin/bash - blogc
+ $ git remote add --mirror=push mirror $YOUR_GIT_MIRROR_URL
+
+### Caveats of repository mirroring with SSH
+
+The authentication must be done with a password-less SSH key created by the `blogc`
+user.
+
+As the `git push --mirror` call is automated, users must disable SSH strict host
+checking in SSH's `~/.ssh/config` file:
+
+ Host bitbucket.org
+ StrictHostKeyChecking no
+
+The example uses `bitbucket.org` as remote host, that should be changed if needed.
+
+To change this file, users must login with `/bin/bash` or any other "real" shell,
+as `root`:
+
+ # su -s /bin/bash - blogc
+
+## ENVIRONMENT VARIABLES
+
+`blogc-git-receiver` will export an environment variable called `BLOGC_GIT_RECEIVER`
+when calling `gmake` to build websites. This variable can be used to enable building
+of content that should only be built when running in production environment, for
+example.
+
+## BUGS
+
+Please report any issues to: <https://github.com/blogc/blogc>
+
+## AUTHOR
+
+Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
+
+## SEE ALSO
+
+blogc(1), git(7), chsh(1), su(1), make(1)
diff --git a/man/blogc-pagination.7.ronn b/man/blogc-pagination.7.ronn
new file mode 100644
index 0000000..db40334
--- /dev/null
+++ b/man/blogc-pagination.7.ronn
@@ -0,0 +1,122 @@
+blogc-pagination(7) -- blogc's pagination support
+=================================================
+
+## DESCRIPTION
+
+blogc(1) supports some basic pagination and post filtering, when running on
+`listing` mode. Files are listed in the order that they are provided to
+blogc(1) in the command line, no sorting is done.
+
+## PAGINATION PARAMETERS
+
+blogc(1) accepts some variables as `-D` options, that are used to filter the
+files passed as arguments to it:
+
+ * `FILTER_PER_PAGE`:
+ Integer, limits the maximum number of files to be listed.
+
+ * `FILTER_PAGE`:
+ Integer, current page. If calling blogc(1) with 10 files,
+ `FILTER_PER_PAGE`=4 and `FILTER_PAGE`=3, it will return just the 2 last
+ files, skipping the first 2 pages with 4 files each one.
+
+ * `FILTER_TAG`:
+ String, if defined, blogc(1) will only list files that declare a `TAGS`
+ variable, as a space-separated list of tags (tags can't have spaces,
+ obviously). See blogc-source(7) for details about how to define source
+ variables. The pagination filters will only act on the files with the
+ provided tag, instead of filtering the whole file set.
+
+## TEMPLATE VARIABLES
+
+blogc(1) will export some global blogc-template(7) variables, that can be used
+to build links for next and previous page.
+
+ * `CURRENT_PAGE`:
+ Integer, usually the same value of `FILTER_PAGE` pagination paramenter, if
+ defined, or 1.
+
+ * `FIRST_PAGE`:
+ Integer, 1 if more than zero files were listed.
+
+ * `LAST_PAGE`:
+ Integer, last page available if more than zero files were listed.
+
+ * `PREVIOUS_PAGE`:
+ Integer, `CURRENT_PAGE` minus 1, if `CURRENT_PAGE` is bigger than 1.
+
+ * `NEXT_PAGE`:
+ Integer, `CURRENT_PAGE` plus 1, if `LAST_PAGE` is bigger than `CURRENT_PAGE`.
+
+blogc(1) can output the value of the variables after evaluation, instead of
+actually rendering the files, using the `-p` option. See blogc(1) for details.
+This is useful to know the last page that needs to be built, using `-p LAST_PAGE`,
+for example.
+
+### Date variables
+
+blogc(1) will also export some global blogc-template(7) variables related to
+the `DATE` variable, as specified in blogc-source(7).
+
+ * `DATE_FIRST`:
+ String, `DATE` variable from the first file in the listing.
+ * `DATE_LAST`:
+ String, `DATE` variable from the last file in the listing.
+
+These variables can be also formatted with `DATE_FORMAT` global blogc(1) parameter,
+if provided, using `DATE_FIRST_FORMATTED` and `DATE_LAST_FORMATTED` global
+template variables.
+
+### File name variables
+
+blogc(1) will also export some global blogc-template(7) variables related to
+the `FILENAME` variable, as automatically exported by the source file parser,
+see blogc-source(7) for details.
+
+ * `FILENAME_FIRST`:
+ String, `FILENAME` variable from the first file in the listing.
+ * `FILENAME_LAST`:
+ String, `FILENAME` variable from the last file in the listing.
+
+## EXAMPLES
+
+### Source file with tags
+
+ TITLE: My post
+ TAGS: foo bar baz
+ -----------------
+ Post content
+
+This source file defines 3 tags: `foo`, `bar` and `baz`.
+
+### Template with pagination
+
+ {% block listing_once %}
+ <ul class="pager">
+ {% ifdef PREVIOUS_PAGE %}
+ <li class="previous">
+ <a href="/page/{{ PREVIOUS_PAGE }}/">&larr; Newer</a>
+ </li>
+ {% endif %}
+ {% ifdef NEXT_PAGE %}
+ <li class="next">
+ <a href="/page/{{ NEXT_PAGE }}/">Older &rarr;</a>
+ </li>
+ {% endif %}
+ </ul>
+ {% endblock %}
+
+This example does not uses all the variables, but the concept is the same for
+all of them.
+
+## BUGS
+
+Please report any issues to: <https://github.com/blogc/blogc>
+
+## AUTHOR
+
+Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
+
+## SEE ALSO
+
+blogc(1), blogc-source(7), blogc-template(7)
diff --git a/man/blogc-runserver.1.ronn b/man/blogc-runserver.1.ronn
new file mode 100644
index 0000000..a306fbe
--- /dev/null
+++ b/man/blogc-runserver.1.ronn
@@ -0,0 +1,48 @@
+blogc-runserver(1) -- a simple HTTP server to test blogc websites
+=================================================================
+
+## SYNOPSIS
+
+`blogc-runserver` [`-t` <HOST>] [`-p` <PORT>] <DOCROOT><br>
+`blogc-runserver` [`-h`|`-v`]
+
+## DESCRIPTION
+
+**blogc-runserver** is a simple HTTP server that makes it easy to test blogc websites.
+Users just need to point it to the directory where the target files where built. It
+comes with a few pre-defined rules, similar to production webservers, that allow users
+to quickly test their websites without configuring a webserver.
+
+`blogc-runserver` is part of `blogc` project, but isn't tied to blogc(1). It may be
+able to serve any website built by static site generators.
+
+## OPTIONS
+
+ * `-t` <HOST>:
+ HTTP server listen address, defaults to `127.0.0.1`.
+
+ * `-p` <PORT>:
+ HTTP server listen port, defaults to `8080`.
+
+ * `-v`:
+ Show program name, version and exit.
+
+ * `-h`:
+ Show help message and exit.
+
+## ARGUMENTS
+
+ * <DOCROOT>:
+ HTTP server document root.
+
+## BUGS
+
+Please report any issues to: <https://github.com/blogc/blogc>
+
+## AUTHOR
+
+Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
+
+## SEE ALSO
+
+blogc(1)
diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn
index 7fa0796..b583d6e 100644
--- a/man/blogc-source.7.ronn
+++ b/man/blogc-source.7.ronn
@@ -45,6 +45,15 @@ You can omit seconds, minutes and hours if you want, they will be filled with
The ``DATE_FORMAT`` variable should be passed to blogc(1) as a global
variable. Its value must be a valid strptime(3) format.
+The source parser will also automatically generate a variable called `FILENAME`,
+that stores the name of the source file, without its extension. This is useful
+for building permalinks in templates. This variable can't be overriden by an
+explicit definition in source file.
+
+Another variable, `DESCRIPTION`, will be automatically created by the source
+parser. Its content is the first line of the first paragraph of the content.
+This variable can be overriden by an explicit definition in source file.
+
## SOURCE CONTENT - BLOCK ELEMENTS
### Paragraphs
@@ -203,18 +212,35 @@ Images are defined using the following syntax:
This is an image: ![This is the image alt text](picture.jpg)
+Whitespace characters and new lines are allowed between alt text and image URL:
+
+ This is an image: ![This is the image alt text]
+ (picture.jpg)
+
### Links
Links are defined using the following syntax:
To learn more about blogc, [click here](https://blogc.rgm.io).
+Whitespace characters and new lines are allowed between link text and link URL:
+
+ To learn more about blogc, [click here]
+ (https://blogc.rgm.io).
+
### Image Links
Links can be combined with images:
[![This is the image alt text](picture.jpg)](https://blogc.rgm.io)
+Whitespace characters and new lines are allowed between link text and link URL,
+and between alt text and image URL:
+
+ [![This is the image alt text]
+ (picture.jpg)]
+ (https://blogc.rgm.io)
+
### Automatic Links
Automatic link is defined with 2 '[' before and 2 ']' after the URL.
@@ -226,6 +252,11 @@ Automatic link is defined with 2 '[' before and 2 ']' after the URL.
Line breaks can be added after a paragraph line adding 2 or more white spaces
to the end of the line.
+### En dashes and Em dashes
+
+Sequences of 2 '-' characters are converted to an En dash HTML entity.
+Sequences of 3 '-' characters are converted to an Em dash HTML entity.
+
## BUGS
diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn
index 7ee617f..baee026 100644
--- a/man/blogc.1.ronn
+++ b/man/blogc.1.ronn
@@ -44,7 +44,7 @@ designed to be used with make(1).
* `-p` <KEY>:
Show the value of a global configuration parameter right after the source
parsing and exits. This is useful to get parameters for your `Makefile`,
- like the last page when using pagination.
+ like the last page when using pagination, see blogc-pagination(7) for details.
* `-t` <TEMPLATE>:
Template file. It is a required option, if `blogc` needs to render something.
@@ -93,4 +93,4 @@ Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
## SEE ALSO
-blogc-source(7), blogc-template(7), make(1), strptime(3)
+blogc-source(7), blogc-template(7), blogc-pagination(7) make(1), strptime(3)
diff --git a/man/index.txt b/man/index.txt
index a85e2a0..4ca6e67 100644
--- a/man/index.txt
+++ b/man/index.txt
@@ -1,9 +1,15 @@
# manuals
-blogc(1) blogc.1.ronn
-blogc-source(7) blogc-source.7.ronn
-blogc-template(7) blogc-template.7.ronn
+blogc(1) blogc.1.ronn
+blogc-git-receiver(1) blogc-git-receiver.1.ronn
+blogc-runserver(1) blogc-runserver.1.ronn
+blogc-source(7) blogc-source.7.ronn
+blogc-template(7) blogc-template.7.ronn
+blogc-pagination(7) blogc-pagination.7.ronn
# external manuals
-make(1) http://man.cx/make(1)
-strcmp(3) http://man.cx/strcmp(3)
-strptime(3) http://man.cx/strptime(3)
+make(1) http://man.cx/make(1)
+chsh(1) http://man.cx/chsh(1)
+su(1) http://man.cx/su(1)
+strcmp(3) http://man.cx/strcmp(3)
+strptime(3) http://man.cx/strptime(3)
+git(7) http://man.cx/git(7)
diff --git a/src/blogc-git-receiver.c b/src/blogc-git-receiver.c
new file mode 100644
index 0000000..ffeac61
--- /dev/null
+++ b/src/blogc-git-receiver.c
@@ -0,0 +1,502 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <time.h>
+
+#include "utils.h"
+
+#ifndef BUFFER_SIZE
+#define BUFFER_SIZE 4096
+#endif
+
+
+static unsigned int
+cpu_count(void)
+{
+#ifdef _SC_NPROCESSORS_ONLN
+ long num = sysconf(_SC_NPROCESSORS_ONLN);
+ if (num >= 1)
+ return (unsigned int) num;
+#endif
+ return 1;
+}
+
+
+static void
+rmdir_recursive(const char *dir)
+{
+ struct stat buf;
+ if (0 != stat(dir, &buf)) {
+ fprintf(stderr, "warning: failed to remove directory (%s): %s\n", dir,
+ strerror(errno));
+ return;
+ }
+ if (!S_ISDIR(buf.st_mode)) {
+ fprintf(stderr, "error: trying to remove invalid directory: %s\n", dir);
+ exit(2);
+ }
+ DIR *d = opendir(dir);
+ if (d == NULL) {
+ fprintf(stderr, "error: failed to open directory: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+ struct dirent *e;
+ while (NULL != (e = readdir(d))) {
+ if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, "..")))
+ continue;
+ char *f = sb_strdup_printf("%s/%s", dir, e->d_name);
+ if (0 != stat(f, &buf)) {
+ fprintf(stderr, "error: failed to stat directory entry (%s): %s\n",
+ e->d_name, strerror(errno));
+ free(f);
+ exit(2);
+ }
+ if (S_ISDIR(buf.st_mode)) {
+ rmdir_recursive(f);
+ }
+ else if (0 != unlink(f)) {
+ fprintf(stderr, "error: failed to remove file (%s): %s\n", f,
+ strerror(errno));
+ free(f);
+ exit(2);
+ }
+ free(f);
+ }
+ if (0 != closedir(d)) {
+ fprintf(stderr, "error: failed to close directory: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+ if (0 != rmdir(dir)) {
+ fprintf(stderr, "error: failed to remove directory: %s\n",
+ strerror(errno));
+ exit(2);
+ }
+}
+
+
+static int
+git_shell(int argc, char *argv[])
+{
+ int rv = 0;
+
+ char *repo = NULL;
+ char *command_orig = NULL;
+ char *command_name = NULL;
+ char command_new[BUFFER_SIZE];
+
+ bool exec_git = false;
+
+ // validate git command
+ size_t len = strlen(argv[2]);
+ if (!((len > 17 && (0 == strncmp(argv[2], "git-receive-pack ", 17))) ||
+ (len > 16 && (0 == strncmp(argv[2], "git-upload-pack ", 16))) ||
+ (len > 19 && (0 == strncmp(argv[2], "git-upload-archive ", 19)))))
+ {
+ fprintf(stderr, "error: unsupported git command: %s\n", argv[2]);
+ rv = 1;
+ goto cleanup;
+ }
+
+ // get shell path
+ char *self = getenv("SHELL");
+ if (self == NULL) {
+ fprintf(stderr, "error: failed to find blogc-git-receiver path\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ // get home path
+ char *home = getenv("HOME");
+ if (home == NULL) {
+ fprintf(stderr, "error: failed to find user home path\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ // get git repository
+ command_orig = sb_strdup(argv[2]);
+ char *p, *r;
+ for (p = command_orig; *p != ' ' && *p != '\0'; p++);
+ if (*p == ' ')
+ p++;
+ if (*p == '\'' || *p == '"')
+ p++;
+ if (*p == '/')
+ p++;
+ for (r = p; *p != '\'' && *p != '"' && *p != '\0'; p++);
+ if (*p == '\'' || *p == '"')
+ *p = '\0';
+ if (*--p == '/')
+ *p = '\0';
+
+ repo = sb_strdup_printf("repos/%s", r);
+
+ // check if repository is sane
+ if (0 == strlen(repo)) {
+ fprintf(stderr, "error: invalid repository\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 == strncmp(argv[2], "git-upload-", 11)) // no need to check len here
+ goto git_exec;
+
+ if (0 != chdir(home)) {
+ fprintf(stderr, "error: failed to chdir (%s): %s\n", home,
+ strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 != access(repo, F_OK)) {
+ char *git_init_cmd = sb_strdup_printf(
+ "git init --bare \"%s\" > /dev/null", repo);
+ if (0 != system(git_init_cmd)) {
+ fprintf(stderr, "error: failed to create git repository: %s\n",
+ repo);
+ rv = 1;
+ free(git_init_cmd);
+ goto cleanup;
+ }
+ free(git_init_cmd);
+ }
+
+ if (0 != chdir(repo)) {
+ fprintf(stderr, "error: failed to chdir (%s/%s): %s\n", home, repo,
+ strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 != access("hooks", F_OK)) {
+ // openwrt git package won't install git templates, then the git
+ // repositories created with it won't have the hooks/ directory.
+ if (0 != mkdir("hooks", 0777)) { // mkdir honors umask for us.
+ fprintf(stderr, "error: failed to create directory (%s/%s/hooks): "
+ "%s\n", home, repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+ }
+
+ if (0 != chdir("hooks")) {
+ fprintf(stderr, "error: failed to chdir (%s/%s/hooks): %s\n", home,
+ repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 == access("pre-receive", F_OK)) {
+ if (0 != unlink("pre-receive")) {
+ fprintf(stderr, "error: failed to remove old symlink "
+ "(%s/%s/hooks/pre-receive): %s\n", home, repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+ }
+
+ if (0 != symlink(self, "pre-receive")) {
+ fprintf(stderr, "error: failed to create symlink "
+ "(%s/%s/hooks/pre-receive): %s\n", home, repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 == access("post-receive", F_OK)) {
+ if (0 != unlink("post-receive")) {
+ fprintf(stderr, "error: failed to remove old symlink "
+ "(%s/%s/hooks/post-receive): %s\n", home, repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+ }
+
+ if (0 != symlink(self, "post-receive")) {
+ fprintf(stderr, "error: failed to create symlink "
+ "(%s/%s/hooks/post-receive): %s\n", home, repo, strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (0 != chdir(home)) {
+ fprintf(stderr, "error: failed to chdir (%s): %s\n", home,
+ strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+git_exec:
+ command_name = sb_strdup(argv[2]);
+ for (p = command_name; *p != ' ' && *p != '\0'; p++);
+ if (*p == ' ')
+ *p = '\0';
+
+ if (BUFFER_SIZE < (strlen(command_name) + strlen(repo) + 4)) {
+ fprintf(stderr, "error: git-shell command is too big\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (snprintf(command_new, BUFFER_SIZE, "%s '%s'", command_name, repo))
+ exec_git = true;
+
+cleanup:
+ free(repo);
+ free(command_orig);
+ free(command_name);
+
+ if (exec_git) {
+ execlp("git-shell", "git-shell", "-c", command_new, NULL);
+
+ // execlp only returns on error, then something bad happened
+ fprintf(stderr, "error: failed to execute git-shell\n");
+ rv = 1;
+ }
+
+ return rv;
+}
+
+
+static int
+git_post_receive_hook(int argc, char *argv[])
+{
+ if (0 != system("git remote get-url --push mirror &> /dev/null"))
+ return 0;
+
+ // at this point we know that we have a remote called mirror, we can just
+ // push to it.
+ if (0 != system("git push --mirror mirror"))
+ fprintf(stderr, "warning: failed push to git mirror\n");
+
+ return 0;
+}
+
+
+typedef enum {
+ START_OLD = 1,
+ OLD,
+ START_NEW,
+ NEW,
+ START_REF,
+ REF
+} input_state_t;
+
+
+static int
+git_pre_receive_hook(int argc, char *argv[])
+{
+ int c;
+ char buffer[BUFFER_SIZE];
+
+ input_state_t state = START_OLD;
+ size_t i = 0;
+ size_t start = 0;
+
+ int rv = 0;
+ char *new = NULL;
+ char *master = NULL;
+
+ while (EOF != (c = getc(stdin))) {
+
+ buffer[i] = (char) c;
+
+ switch (state) {
+ case START_OLD:
+ start = i;
+ state = OLD;
+ break;
+ case OLD:
+ if (c != ' ')
+ break;
+ // no need to store old
+ state = START_NEW;
+ break;
+ case START_NEW:
+ start = i;
+ state = NEW;
+ break;
+ case NEW:
+ if (c != ' ')
+ break;
+ state = START_REF;
+ new = strndup(buffer + start, i - start);
+ break;
+ case START_REF:
+ start = i;
+ state = REF;
+ break;
+ case REF:
+ if (c != '\n')
+ break;
+ state = START_OLD;
+ // we just care about a ref (refs/heads/master), everything
+ // else is disposable :)
+ if (!((i - start == 17) &&
+ (0 == strncmp("refs/heads/master", buffer + start, 17))))
+ {
+ free(new);
+ new = NULL;
+ break;
+ }
+ master = new;
+ break;
+ }
+
+ if (++i >= BUFFER_SIZE) {
+ fprintf(stderr, "error: pre-receive hook payload is too big.\n");
+ rv = 1;
+ goto cleanup2;
+ }
+ }
+
+ if (master == NULL) {
+ fprintf(stderr, "warning: no reference to master branch found. "
+ "nothing to deploy.\n");
+ goto cleanup2;
+ }
+
+ char *repo_dir = NULL;
+ char *output_dir = NULL;
+
+ if (NULL == getcwd(buffer, BUFFER_SIZE)) {
+ fprintf(stderr, "error: failed to get repository remote path: %s\n",
+ strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ repo_dir = sb_strdup(buffer);
+
+ char dir[] = "/tmp/blogc_XXXXXX";
+ if (NULL == mkdtemp(dir)) {
+ rv = 1;
+ goto cleanup;
+ }
+
+ char *git_archive_cmd = sb_strdup_printf(
+ "git archive \"%s\" | tar -x -C \"%s\" -f -", master, dir);
+ if (0 != system(git_archive_cmd)) {
+ fprintf(stderr, "error: failed to extract git content to temporary "
+ "directory: %s\n", dir);
+ rv = 1;
+ free(git_archive_cmd);
+ goto cleanup;
+ }
+ free(git_archive_cmd);
+
+ if (0 != chdir(dir)) {
+ fprintf(stderr, "error: failed to chdir (%s): %s\n", dir,
+ strerror(errno));
+ rv = 1;
+ goto cleanup;
+ }
+
+ if ((0 != access("Makefile", F_OK)) && (0 != access("GNUMakefile", F_OK))) {
+ fprintf(stderr, "warning: no makefile found. skipping ...\n");
+ goto cleanup;
+ }
+
+ char *home = getenv("HOME");
+ if (home == NULL) {
+ fprintf(stderr, "error: failed to find user home path\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ unsigned long epoch = time(NULL);
+ output_dir = sb_strdup_printf("%s/builds/%s-%lu", home, master, epoch);
+ char *gmake_cmd = sb_strdup_printf(
+ "gmake -j%d OUTPUT_DIR=\"%s\" BLOGC_GIT_RECEIVER=1",
+ cpu_count(), output_dir);
+ fprintf(stdout, "running command: %s\n\n", gmake_cmd);
+ fflush(stdout);
+ if (0 != system(gmake_cmd)) {
+ fprintf(stderr, "error: failed to build website ...\n");
+ rmdir_recursive(output_dir);
+ free(gmake_cmd);
+ rv = 1;
+ goto cleanup;
+ }
+ free(gmake_cmd);
+
+ if (0 != chdir(repo_dir)) {
+ fprintf(stderr, "error: failed to chdir (%s): %s\n", repo_dir,
+ strerror(errno));
+ rmdir_recursive(output_dir);
+ rv = 1;
+ goto cleanup;
+ }
+
+ char *htdocs_sym = NULL;
+ ssize_t htdocs_sym_len = readlink("htdocs", buffer, BUFFER_SIZE);
+ if (0 < htdocs_sym_len) {
+ if (0 != unlink("htdocs")) {
+ fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
+ repo_dir, strerror(errno));
+ rmdir_recursive(output_dir);
+ rv = 1;
+ goto cleanup;
+ }
+ buffer[htdocs_sym_len] = '\0';
+ htdocs_sym = buffer;
+ }
+
+ if (0 != symlink(output_dir, "htdocs")) {
+ fprintf(stderr, "error: failed to create symlink (%s/htdocs): %s\n",
+ repo_dir, strerror(errno));
+ rmdir_recursive(output_dir);
+ rv = 1;
+ goto cleanup;
+ }
+
+ if (htdocs_sym != NULL)
+ rmdir_recursive(htdocs_sym);
+
+cleanup:
+ free(output_dir);
+ rmdir_recursive(dir);
+ free(repo_dir);
+cleanup2:
+ free(new);
+ return rv;
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ if (argc > 0) {
+ if (0 == strcmp(basename(argv[0]), "pre-receive"))
+ return git_pre_receive_hook(argc, argv);
+ if (0 == strcmp(basename(argv[0]), "post-receive"))
+ return git_post_receive_hook(argc, argv);
+ }
+
+ if (argc == 3 && (0 == strcmp(argv[1], "-c")))
+ return git_shell(argc, argv);
+
+ fprintf(stderr, "error: this is a special shell, go away!\n");
+ return 1;
+}
diff --git a/src/blogc-runserver.c b/src/blogc-runserver.c
new file mode 100644
index 0000000..81bd5f9
--- /dev/null
+++ b/src/blogc-runserver.c
@@ -0,0 +1,389 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <event2/event.h>
+#include <event2/http.h>
+#include <event2/buffer.h>
+#include <event2/keyvalq_struct.h>
+#include <magic.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+
+/**
+ * this mapping is used to declare "supported" file types, that are forced over
+ * whatever detected by libmagic, but we will still use the charset provided by
+ * libmagic anyway. it also helps detecting index files when the client asks
+ * for a directory.
+ */
+static const struct content_type_map {
+ const char *mimetype;
+ const char *extension;
+ const char *index;
+} content_types[] = {
+ {"text/html", "html", "index.html"},
+ {"text/html", "htm", "index.htm"},
+ {"text/xml", "xml", "index.xml"},
+ {"text/plain", "txt", "index.txt"},
+ {"text/css", "css", NULL},
+ {"application/javascript", "js", NULL},
+ {NULL, NULL, NULL}
+};
+
+
+static magic_t magic_all = NULL;
+static magic_t magic_charset = NULL;
+
+
+static const char*
+get_extension(const char *filename)
+{
+ const char *ext = NULL;
+ unsigned int i;
+ for (i = strlen(filename); i > 0; i--) {
+ if (filename[i] == '.') {
+ ext = filename + i + 1;
+ break;
+ }
+ }
+ if (i == 0)
+ return NULL;
+ return ext;
+}
+
+
+static char*
+guess_content_type(const char *filename, int fd)
+{
+ int newfd;
+
+ // try "supported" types first, and just use libmagic for charset
+ const char *extension = get_extension(filename);
+ if (extension == NULL)
+ goto libmagic;
+ const char *supported = NULL;
+ for (unsigned int i = 0; content_types[i].extension != NULL; i++)
+ if (0 == strcmp(content_types[i].extension, extension))
+ supported = content_types[i].mimetype;
+ if (supported != NULL) {
+ newfd = dup(fd);
+ if (-1 != newfd) {
+ const char* charset = magic_descriptor(magic_charset, newfd);
+ close(newfd);
+ if (charset != NULL)
+ return sb_strdup_printf("%s; charset=%s", supported, charset);
+ }
+ return sb_strdup(supported);
+ }
+
+libmagic:
+
+ // fallback to use libmagic for everything
+ newfd = dup(fd);
+ if (-1 != newfd) {
+ const char* content_type = magic_descriptor(magic_all, newfd);
+ close(newfd);
+ if (content_type != NULL)
+ return sb_strdup(content_type);
+ }
+ return sb_strdup("application/octet-stream");
+}
+
+
+static void
+handler(struct evhttp_request *request, void *ptr)
+{
+ const char *root = ptr;
+ const char *uri = evhttp_request_get_uri(request);
+
+ struct evhttp_uri *decoded_uri = evhttp_uri_parse(uri);
+ if (decoded_uri == NULL) {
+ evhttp_send_error(request, 400, "Bad request");
+ return;
+ }
+
+ const char *path = evhttp_uri_get_path(decoded_uri);
+ if (path == NULL)
+ path = "/";
+
+ char *decoded_path = evhttp_uridecode(path, 0, NULL);
+ if (decoded_path == NULL) {
+ evhttp_send_error(request, 400, "Bad request");
+ goto point1;
+ }
+
+ char *abs_path = sb_strdup_printf("%s/%s", root, decoded_path);
+ char *real_path = realpath(abs_path, NULL);
+ free(abs_path);
+
+ if (real_path == NULL) {
+ evhttp_send_error(request, 404, "Not found");
+ goto point2;
+ }
+
+ char *real_root = realpath(root, NULL);
+ if (real_root == NULL) {
+ evhttp_send_error(request, 500, "Internal server error");
+ goto point3;
+ }
+
+ if (0 != strncmp(real_root, real_path, strlen(real_root))) {
+ evhttp_send_error(request, 404, "Not found");
+ goto point4;
+ }
+
+ struct stat st;
+ if (0 > stat(real_path, &st)) {
+ evhttp_send_error(request, 404, "Not found");
+ goto point4;
+ }
+
+ bool add_slash = false;
+
+ if (S_ISDIR(st.st_mode)) {
+ char *found = NULL;
+
+ for (unsigned int i = 0; content_types[i].mimetype != NULL; i++) {
+ if (content_types[i].index == NULL)
+ continue;
+ char *f = sb_strdup_printf("%s/%s", real_path,
+ content_types[i].index);
+ if (0 == access(f, F_OK)) {
+ found = sb_strdup(f);
+ break;
+ }
+ free(f);
+ }
+
+ if (found == NULL) {
+ evhttp_send_error(request, 403, "Forbidden");
+ goto point4;
+ }
+
+ size_t path_len = strlen(path);
+ if (path_len > 0 && path[path_len - 1] != '/')
+ add_slash = true;
+
+ free(real_path);
+ real_path = found;
+ }
+
+ int fd;
+ if ((fd = open(real_path, O_RDONLY)) < 0) {
+ evhttp_send_error(request, 500, "Internal server error");
+ goto point4;
+ }
+
+ char *type = guess_content_type(real_path, fd);
+
+ if (fstat(fd, &st) < 0) {
+ evhttp_send_error(request, 500, "Internal server error");
+ goto point5;
+ }
+
+ struct evkeyvalq *headers = evhttp_request_get_output_headers(request);
+
+ if (add_slash) {
+ char *tmp = sb_strdup_printf("%s/", path);
+ evhttp_add_header(headers, "Location", tmp);
+ free(tmp);
+ // production webservers usually returns 301 in such cases, but 302 is
+ // better for development/testing.
+ evhttp_send_reply(request, 302, "Found", NULL);
+ goto point5;
+ }
+
+ evhttp_add_header(headers, "Content-Type", type);
+ char *content_length = sb_strdup_printf("%zu", st.st_size);
+ evhttp_add_header(headers, "Content-Length", content_length);
+ free(content_length);
+
+ struct evbuffer *evb = evbuffer_new();
+ evbuffer_add_file(evb, fd, 0, st.st_size);
+ evhttp_send_reply(request, 200, "OK", evb);
+
+point5:
+ free(type);
+point4:
+ free(real_root);
+point3:
+ free(real_path);
+point2:
+ free(decoded_path);
+point1:
+ evhttp_uri_free(decoded_uri);
+}
+
+
+static int
+runserver(const char *address, unsigned short port, const char *root)
+{
+ struct event_base *base = event_base_new();
+ if (base == NULL) {
+ fprintf(stderr, "error: failed to initialize event base\n");
+ return 1;
+ }
+
+ struct evhttp *http = evhttp_new(base);
+ if (http == NULL) {
+ fprintf(stderr, "error: failed to initialize HTTP server\n");
+ return 1;
+ }
+
+ evhttp_set_gencb(http, handler, (char*) root);
+
+ evhttp_set_allowed_methods(http, EVHTTP_REQ_GET | EVHTTP_REQ_HEAD);
+
+ if (0 != evhttp_bind_socket(http, address, port)) {
+ fprintf(stderr, "error: failed to bind socket to %s:%d\n", address,
+ port);
+ return 1;
+ }
+
+ fprintf(stderr, " * Running on http://%s:%d/\n", address, port);
+
+ event_base_dispatch(base);
+
+ return 0;
+}
+
+
+static void
+print_help(void)
+{
+ printf(
+ "usage:\n"
+ " blogc-runserver [-h] [-v] [-t HOST] [-p PORT] DOCROOT\n"
+ " - A simple HTTP server to test blogc websites.\n"
+ "\n"
+ "positional arguments:\n"
+ " DOCROOT document root directory\n"
+ "\n"
+ "optional arguments:\n"
+ " -h show this help message and exit\n"
+ " -v show version and exit\n"
+ " -t HOST set server listen address (default: 127.0.0.1)\n"
+ " -p PORT set server listen port (default: 8080)\n");
+}
+
+
+static void
+print_usage(void)
+{
+ printf("usage: blogc-runserver [-h] [-v] [-t HOST] [-p PORT] DOCROOT\n");
+}
+
+
+int
+main(int argc, char **argv)
+{
+ signal(SIGPIPE, SIG_IGN);
+
+ int rv = 0;
+ char *host = NULL;
+ char *docroot = NULL;
+ unsigned short port = 8080;
+
+ unsigned int args = 0;
+
+ for (unsigned int i = 1; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ switch (argv[i][1]) {
+ case 'h':
+ print_help();
+ goto cleanup;
+ case 'v':
+ printf("%s\n", PACKAGE_STRING);
+ goto cleanup;
+ case 't':
+ if (argv[i][2] != '\0')
+ host = sb_strdup(argv[i] + 2);
+ else
+ host = sb_strdup(argv[++i]);
+ break;
+ case 'p':
+ if (argv[i][2] != '\0')
+ port = strtoul(argv[i] + 2, NULL, 10);
+ else
+ port = strtoul(argv[++i], NULL, 10);
+ break;
+ default:
+ print_usage();
+ fprintf(stderr, "blogc-runserver: error: invalid "
+ "argument: -%c\n", argv[i][1]);
+ rv = 2;
+ goto cleanup;
+ }
+ }
+ else {
+ if (args > 0) {
+ print_usage();
+ fprintf(stderr, "blogc-runserver: error: only one positional "
+ "argument allowed\n");
+ rv = 2;
+ goto cleanup;
+ }
+ args++;
+ docroot = sb_strdup(argv[i]);
+ }
+ }
+
+ if (docroot == NULL) {
+ print_usage();
+ fprintf(stderr, "blogc-runserver: error: document root directory "
+ "required\n");
+ rv = 2;
+ goto cleanup;
+ }
+
+ if (host == NULL)
+ host = sb_strdup("127.0.0.1");
+
+ magic_all = magic_open(MAGIC_MIME);
+ magic_charset = magic_open(MAGIC_MIME_ENCODING);
+ if (magic_all == NULL || magic_charset == NULL) {
+ fprintf(stderr, "error: failed to initialize libmagic\n");
+ rv = 1;
+ goto cleanup;
+ }
+
+ if ((0 != magic_load(magic_all, NULL)) ||
+ (0 != magic_load(magic_charset, NULL)))
+ {
+ fprintf(stderr, "error: failed to load libmagic data\n");
+ magic_close(magic_all);
+ magic_close(magic_charset);
+ rv = 1;
+ goto cleanup;
+ }
+
+ rv = runserver(host, port, docroot);
+
+ magic_close(magic_all);
+ magic_close(magic_charset);
+
+cleanup:
+ free(host);
+ free(docroot);
+
+ return rv;
+}
diff --git a/src/main.c b/src/blogc.c
index f3f990b..2338c9e 100644
--- a/src/main.c
+++ b/src/blogc.c
@@ -24,12 +24,12 @@
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
#include "renderer.h"
#include "error.h"
+#include "utils.h"
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "Unknown"
@@ -71,7 +71,7 @@ blogc_print_usage(void)
static void
blogc_mkdir_recursive(const char *filename)
{
- char *fname = b_strdup(filename);
+ char *fname = sb_strdup(filename);
for (char *tmp = fname; *tmp != '\0'; tmp++) {
if (*tmp != '/' && *tmp != '\\')
continue;
@@ -117,9 +117,9 @@ main(int argc, char **argv)
char *tmp = NULL;
char **pieces = NULL;
- b_slist_t *sources = NULL;
- b_trie_t *config = b_trie_new(free);
- b_trie_insert(config, "BLOGC_VERSION", b_strdup(PACKAGE_VERSION));
+ sb_slist_t *sources = NULL;
+ sb_trie_t *config = sb_trie_new(free);
+ sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION));
for (unsigned int i = 1; i < argc; i++) {
tmp = NULL;
@@ -136,21 +136,21 @@ main(int argc, char **argv)
break;
case 't':
if (argv[i][2] != '\0')
- template = b_strdup(argv[i] + 2);
+ template = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- template = b_strdup(argv[++i]);
+ template = sb_strdup(argv[++i]);
break;
case 'o':
if (argv[i][2] != '\0')
- output = b_strdup(argv[i] + 2);
+ output = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- output = b_strdup(argv[++i]);
+ output = sb_strdup(argv[++i]);
break;
case 'p':
if (argv[i][2] != '\0')
- print = b_strdup(argv[i] + 2);
+ print = sb_strdup(argv[i] + 2);
else if (i + 1 < argc)
- print = b_strdup(argv[++i]);
+ print = sb_strdup(argv[++i]);
break;
case 'D':
if (argv[i][2] != '\0')
@@ -158,11 +158,11 @@ main(int argc, char **argv)
else if (i + 1 < argc)
tmp = argv[++i];
if (tmp != NULL) {
- pieces = b_str_split(tmp, '=', 2);
- if (b_strv_length(pieces) != 2) {
+ pieces = sb_str_split(tmp, '=', 2);
+ if (sb_strv_length(pieces) != 2) {
fprintf(stderr, "blogc: error: invalid value for "
"-D (must have an '='): %s\n", tmp);
- b_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 2;
goto cleanup;
}
@@ -173,13 +173,13 @@ main(int argc, char **argv)
fprintf(stderr, "blogc: error: invalid value "
"for -D (configuration key must be uppercase "
"with '_'): %s\n", pieces[0]);
- b_strv_free(pieces);
+ sb_strv_free(pieces);
rv = 2;
goto cleanup;
}
}
- b_trie_insert(config, pieces[0], b_strdup(pieces[1]));
- b_strv_free(pieces);
+ sb_trie_insert(config, pieces[0], sb_strdup(pieces[1]));
+ sb_strv_free(pieces);
pieces = NULL;
}
break;
@@ -192,17 +192,17 @@ main(int argc, char **argv)
}
}
else
- sources = b_slist_append(sources, b_strdup(argv[i]));
+ sources = sb_slist_append(sources, sb_strdup(argv[i]));
}
- if (!listing && b_slist_length(sources) == 0) {
+ if (!listing && sb_slist_length(sources) == 0) {
blogc_print_usage();
fprintf(stderr, "blogc: error: one source file is required\n");
rv = 2;
goto cleanup;
}
- if (!listing && b_slist_length(sources) > 1) {
+ if (!listing && sb_slist_length(sources) > 1) {
blogc_print_usage();
fprintf(stderr, "blogc: error: only one source file should be provided, "
"if running without '-l'\n");
@@ -212,14 +212,14 @@ main(int argc, char **argv)
blogc_error_t *err = NULL;
- b_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
+ sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
if (err != NULL) {
blogc_error_print(err);
rv = 2;
goto cleanup2;
}
- b_slist_t* l = blogc_template_parse_from_file(template, &err);
+ sb_slist_t* l = blogc_template_parse_from_file(template, &err);
if (err != NULL) {
blogc_error_print(err);
rv = 2;
@@ -227,7 +227,7 @@ main(int argc, char **argv)
}
if (print != NULL) {
- const char *val = b_trie_lookup(config, print);
+ const char *val = sb_trie_lookup(config, print);
if (val == NULL) {
fprintf(stderr, "blogc: error: configuration variable not found: %s\n",
print);
@@ -273,13 +273,13 @@ cleanup4:
cleanup3:
blogc_template_free_stmts(l);
cleanup2:
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
blogc_error_free(err);
cleanup:
- b_trie_free(config);
+ sb_trie_free(config);
free(template);
free(output);
free(print);
- b_slist_free_full(sources, free);
+ sb_slist_free_full(sources, free);
return rv;
}
diff --git a/src/content-parser.c b/src/content-parser.c
index 8dceb8b..0561d20 100644
--- a/src/content-parser.c
+++ b/src/content-parser.c
@@ -13,9 +13,9 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/utils.h"
#include "content-parser.h"
#include "directives.h"
+#include "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.
@@ -26,7 +26,7 @@ blogc_slugify(const char *str)
{
if (str == NULL)
return NULL;
- char *new_str = b_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')
@@ -47,32 +47,32 @@ blogc_htmlentities(const char *str)
{
if (str == NULL)
return NULL;
- b_string_t *rv = b_string_new();
+ sb_string_t *rv = sb_string_new();
for (size_t i = 0; str[i] != '\0'; i++) {
switch (str[i]) {
case '&':
- b_string_append(rv, "&amp;");
+ sb_string_append(rv, "&amp;");
break;
case '<':
- b_string_append(rv, "&lt;");
+ sb_string_append(rv, "&lt;");
break;
case '>':
- b_string_append(rv, "&gt;");
+ sb_string_append(rv, "&gt;");
break;
case '"':
- b_string_append(rv, "&quot;");
+ sb_string_append(rv, "&quot;");
break;
case '\'':
- b_string_append(rv, "&#x27;");
+ sb_string_append(rv, "&#x27;");
break;
case '/':
- b_string_append(rv, "&#x2F;");
+ sb_string_append(rv, "&#x2F;");
break;
default:
- b_string_append_c(rv, str[i]);
+ sb_string_append_c(rv, str[i]);
}
}
- return b_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -139,7 +139,7 @@ blogc_content_parse_inline(const char *src)
size_t start_state = 0;
size_t end = 0;
- b_string_t *rv = b_string_new();
+ sb_string_t *rv = sb_string_new();
bool open_em_ast = false;
bool open_strong_ast = false;
@@ -165,7 +165,7 @@ blogc_content_parse_inline(const char *src)
if (escape) {
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
current++;
escape = false;
continue;
@@ -174,11 +174,21 @@ blogc_content_parse_inline(const char *src)
if (c != ' ' && c != '\n' && c != '\r')
spaces = 0;
+ if (state == LINK_TEXT_CLOSE && c != ' ' && c != '\n' && c != '\r' &&
+ c != '(')
+ {
+ sb_string_append_c(rv, src[start_state]);
+ tmp = blogc_content_parse_inline(src + start_state + 1);
+ sb_string_append(rv, tmp);
+ // no need to free here, we will exit the loop!
+ break;
+ }
+
switch (c) {
case '\\':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (!escape)
@@ -188,7 +198,7 @@ blogc_content_parse_inline(const char *src)
case '*':
case '_':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (!is_last && src[current + 1] == c) {
@@ -197,7 +207,7 @@ blogc_content_parse_inline(const char *src)
(c == '_' && open_strong_und))
{
if (state == LINK_CLOSED)
- b_string_append(rv, "</strong>");
+ sb_string_append(rv, "</strong>");
if (c == '*')
open_strong_ast = false;
else
@@ -205,7 +215,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append(rv, "<strong>");
+ sb_string_append(rv, "<strong>");
if (c == '*')
open_strong_ast = true;
else
@@ -214,7 +224,7 @@ blogc_content_parse_inline(const char *src)
}
if ((c == '*' && open_em_ast) || (c == '_' && open_em_und)) {
if (state == LINK_CLOSED)
- b_string_append(rv, "</em>");
+ sb_string_append(rv, "</em>");
if (c == '*')
open_em_ast = false;
else
@@ -222,7 +232,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append(rv, "<em>");
+ sb_string_append(rv, "<em>");
if (c == '*')
open_em_ast = true;
else
@@ -233,22 +243,26 @@ blogc_content_parse_inline(const char *src)
if (!is_last && src[current + 1] == c) {
current++;
if (state == LINK_CLOSED)
- b_string_append_printf(rv, "<%scode>",
+ sb_string_append_printf(rv, "<%scode>",
open_code_double ? "/" : "");
open_code_double = !open_code_double;
break;
}
if (state == LINK_CLOSED)
- b_string_append_printf(rv, "<%scode>", open_code ? "/" : "");
+ sb_string_append_printf(rv, "<%scode>", open_code ? "/" : "");
open_code = !open_code;
break;
case '!':
- if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
- break;
- }
if (state == LINK_CLOSED) {
+ if (open_code || open_code_double) {
+ sb_string_append_c(rv, c);
+ break;
+ }
+ if (!is_last && src[current + 1] != '[') {
+ sb_string_append_c(rv, c);
+ break;
+ }
state = LINK_IMAGE;
is_image = true;
start_state = current;
@@ -257,7 +271,7 @@ blogc_content_parse_inline(const char *src)
case '[':
if (state == LINK_CLOSED && (open_code || open_code_double)) {
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
}
if (state == LINK_CLOSED || state == LINK_IMAGE) {
@@ -287,8 +301,8 @@ blogc_content_parse_inline(const char *src)
}
if (state == LINK_AUTO_CLOSE) {
state = LINK_CLOSED;
- tmp = b_strndup(src + start, end - start);
- b_string_append_printf(rv, "<a href=\"%s\">%s</a>", tmp, tmp);
+ tmp = sb_strndup(src + start, end - start);
+ sb_string_append_printf(rv, "<a href=\"%s\">%s</a>", tmp, tmp);
end = 0;
free(tmp);
tmp = NULL;
@@ -298,7 +312,7 @@ blogc_content_parse_inline(const char *src)
if (state == LINK_TEXT) {
if (open_bracket-- == 0) {
state = LINK_TEXT_CLOSE;
- tmp = b_strndup(src + start, current - start);
+ tmp = sb_strndup(src + start, current - start);
tmp2 = blogc_content_parse_inline(tmp);
free(tmp);
tmp = NULL;
@@ -306,7 +320,7 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case '(':
@@ -316,18 +330,18 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case ')':
if (state == LINK_URL) {
state = LINK_CLOSED;
- tmp = b_strndup(src + start, current - start);
+ tmp = sb_strndup(src + start, current - start);
if (is_image)
- b_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">",
+ sb_string_append_printf(rv, "<img src=\"%s\" alt=\"%s\">",
tmp, tmp2);
else
- b_string_append_printf(rv, "<a href=\"%s\">%s</a>",
+ sb_string_append_printf(rv, "<a href=\"%s\">%s</a>",
tmp, tmp2);
free(tmp);
tmp = NULL;
@@ -337,13 +351,13 @@ blogc_content_parse_inline(const char *src)
break;
}
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
break;
case ' ':
if (state == LINK_CLOSED) {
spaces++;
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
}
if (!is_last)
break;
@@ -352,55 +366,74 @@ blogc_content_parse_inline(const char *src)
case '\r':
if (state == LINK_CLOSED) {
if (spaces >= 2) {
- b_string_append(rv, "<br />");
+ sb_string_append(rv, "<br />");
spaces = 0;
}
if (c == '\n' || c == '\r')
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
+ }
+ break;
+
+ case '-':
+ if (state != LINK_CLOSED)
+ break;
+ if ((current < (src_len - 1) && src[current + 1] == '-') &&
+ !(open_code || open_code_double))
+ {
+ if (current < (src_len - 2) && src[current + 2] == '-') {
+ sb_string_append(rv, "&mdash;");
+ current += 2;
+ }
+ else {
+ sb_string_append(rv, "&ndash;");
+ current += 1;
+ }
+ }
+ else {
+ sb_string_append_c(rv, c);
}
break;
case '&':
if (state == LINK_CLOSED)
- b_string_append(rv, "&amp;");
+ sb_string_append(rv, "&amp;");
break;
case '<':
if (state == LINK_CLOSED)
- b_string_append(rv, "&lt;");
+ sb_string_append(rv, "&lt;");
break;
case '>':
if (state == LINK_CLOSED)
- b_string_append(rv, "&gt;");
+ sb_string_append(rv, "&gt;");
break;
case '"':
if (state == LINK_CLOSED)
- b_string_append(rv, "&quot;");
+ sb_string_append(rv, "&quot;");
break;
case '\'':
if (state == LINK_CLOSED)
- b_string_append(rv, "&#x27;");
+ sb_string_append(rv, "&#x27;");
break;
case '/':
if (state == LINK_CLOSED)
- b_string_append(rv, "&#x2F;");
+ sb_string_append(rv, "&#x2F;");
break;
default:
if (state == LINK_CLOSED)
- b_string_append_c(rv, c);
+ sb_string_append_c(rv, c);
}
if (is_last && state != LINK_CLOSED) {
- b_string_append_c(rv, src[start_state]);
+ sb_string_append_c(rv, src[start_state]);
tmp = blogc_content_parse_inline(src + start_state + 1);
- b_string_append(rv, tmp);
- free(tmp);
- tmp = NULL;
+ sb_string_append(rv, tmp);
+ // no need to free here, its the last iteration
}
current++;
}
@@ -408,7 +441,7 @@ blogc_content_parse_inline(const char *src)
free(tmp);
free(tmp2);
- return b_string_free(rv, false);
+ return sb_string_free(rv, false);
}
@@ -440,7 +473,7 @@ blogc_is_ordered_list_item(const char *str, size_t prefix_len)
char*
-blogc_content_parse(const char *src, size_t *end_excerpt)
+blogc_content_parse(const char *src, size_t *end_excerpt, char **description)
{
// src is always nul-terminated.
size_t src_len = strlen(src);
@@ -463,7 +496,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
char *directive_name = NULL;
char *directive_argument = NULL;
char *directive_key = NULL;
- b_trie_t *directive_params = NULL;
+ sb_trie_t *directive_params = NULL;
// this isn't empty because we need some reasonable default value in the
// unlikely case that we need to print some line ending before evaluating
@@ -473,11 +506,11 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
char d = '\0';
- b_slist_t *lines = NULL;
- b_slist_t *lines2 = NULL;
+ sb_slist_t *lines = NULL;
+ sb_slist_t *lines2 = NULL;
- b_string_t *rv = b_string_new();
- b_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;
@@ -607,14 +640,14 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
slug = blogc_slugify(tmp);
if (slug == NULL)
- b_string_append_printf(rv, "<h%d>%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d>%s</h%d>%s",
header_level, parsed, header_level, line_ending);
else
- b_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
+ sb_string_append_printf(rv, "<h%d id=\"%s\">%s</h%d>%s",
header_level, slug, parsed, header_level,
line_ending);
free(slug);
@@ -638,8 +671,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_HTML_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp = b_strndup(src + start, end - start);
- b_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;
@@ -652,7 +685,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_BLOCKQUOTE:
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_BLOCKQUOTE_START;
break;
@@ -660,16 +693,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- if (b_str_starts_with(tmp, prefix)) {
- lines = b_slist_append(lines, b_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;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
if (is_last) {
free(tmp);
@@ -685,22 +718,18 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_BLOCKQUOTE_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp_str = b_string_new();
- for (b_slist_t *l = lines; l != NULL; l = l->next) {
- if (l->next == NULL)
- b_string_append_printf(tmp_str, "%s", l->data);
- else
- b_string_append_printf(tmp_str, "%s%s", l->data,
- line_ending);
- }
- tmp = blogc_content_parse(tmp_str->str, NULL);
- b_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
+ 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);
+ tmp = blogc_content_parse(tmp_str->str, NULL, description);
+ sb_string_append_printf(rv, "<blockquote>%s</blockquote>%s",
tmp, line_ending);
free(tmp);
tmp = NULL;
- b_string_free(tmp_str, true);
+ sb_string_free(tmp_str, true);
tmp_str = NULL;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -716,7 +745,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_CODE:
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_CODE_START;
break;
@@ -724,16 +753,16 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- if (b_str_starts_with(tmp, prefix)) {
- lines = b_slist_append(lines, b_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;
- b_slist_free_full(lines, free);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(tmp);
tmp = NULL;
@@ -749,18 +778,18 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_CODE_END:
if (c == '\n' || c == '\r' || is_last) {
- b_string_append(rv, "<pre><code>");
- for (b_slist_t *l = lines; l != NULL; l = l->next) {
+ sb_string_append(rv, "<pre><code>");
+ for (sb_slist_t *l = lines; l != NULL; l = l->next) {
char *tmp_line = blogc_htmlentities(l->data);
if (l->next == NULL)
- b_string_append_printf(rv, "%s", tmp_line);
+ sb_string_append_printf(rv, "%s", tmp_line);
else
- b_string_append_printf(rv, "%s%s", tmp_line,
+ sb_string_append_printf(rv, "%s%s", tmp_line,
line_ending);
free(tmp_line);
}
- b_string_append_printf(rv, "</code></pre>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</code></pre>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -782,7 +811,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
}
if (c == ' ' || c == '\t')
break;
- prefix = b_strndup(src + start, current - start);
+ prefix = sb_strndup(src + start, current - start);
state = CONTENT_UNORDERED_LIST_START;
break;
@@ -791,7 +820,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
break;
}
if (c == '\n' || c == '\r' || is_last) {
- b_string_append_printf(rv, "<hr />%s", line_ending);
+ sb_string_append_printf(rv, "<hr />%s", line_ending);
state = CONTENT_START_LINE;
start = current;
d = '\0';
@@ -804,30 +833,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- tmp2 = b_strdup_printf("%-*s", strlen(prefix), "");
- if (b_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 = b_string_new();
- for (b_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)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = b_slist_append(lines2, b_strdup(tmp + strlen(prefix)));
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + strlen(prefix)));
}
- else if (b_str_starts_with(tmp, tmp2)) {
- lines2 = b_slist_append(lines2, b_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;
@@ -837,8 +866,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
tmp2 = NULL;
free(prefix);
prefix = NULL;
- b_slist_free_full(lines, free);
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
continue;
@@ -857,28 +886,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = b_string_new();
- for (b_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)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- b_string_append_printf(rv, "<ul>%s", line_ending);
- for (b_slist_t *l = lines; l != NULL; l = l->next)
- b_string_append_printf(rv, "<li>%s</li>%s", l->data,
+ sb_string_append_printf(rv, "<ul>%s", line_ending);
+ for (sb_slist_t *l = lines; l != NULL; l = l->next)
+ sb_string_append_printf(rv, "<li>%s</li>%s", l->data,
line_ending);
- b_string_append_printf(rv, "</ul>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ul>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -915,30 +944,30 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
- tmp = b_strndup(src + start2, end - start2);
- tmp2 = b_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 = b_string_new();
- for (b_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)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- lines2 = b_slist_append(lines2, b_strdup(tmp + prefix_len));
+ lines2 = sb_slist_append(lines2, sb_strdup(tmp + prefix_len));
}
- else if (b_str_starts_with(tmp, tmp2)) {
- lines2 = b_slist_append(lines2, b_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;
@@ -948,8 +977,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
tmp2 = NULL;
free(parsed);
parsed = NULL;
- b_slist_free_full(lines, free);
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines, free);
+ sb_slist_free_full(lines2, free);
lines = NULL;
if (is_last)
continue;
@@ -968,28 +997,28 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
if (lines2 != NULL) {
// FIXME: avoid repeting the code below
- tmp_str = b_string_new();
- for (b_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)
- b_string_append_printf(tmp_str, "%s", l->data);
+ sb_string_append_printf(tmp_str, "%s", l->data);
else
- b_string_append_printf(tmp_str, "%s%s", l->data,
+ sb_string_append_printf(tmp_str, "%s%s", l->data,
line_ending);
}
- b_slist_free_full(lines2, free);
+ sb_slist_free_full(lines2, free);
lines2 = NULL;
parsed = blogc_content_parse_inline(tmp_str->str);
- b_string_free(tmp_str, true);
- lines = b_slist_append(lines, b_strdup(parsed));
+ sb_string_free(tmp_str, true);
+ lines = sb_slist_append(lines, sb_strdup(parsed));
free(parsed);
parsed = NULL;
}
- b_string_append_printf(rv, "<ol>%s", line_ending);
- for (b_slist_t *l = lines; l != NULL; l = l->next)
- b_string_append_printf(rv, "<li>%s</li>%s", l->data,
+ sb_string_append_printf(rv, "<ol>%s", line_ending);
+ for (sb_slist_t *l = lines; l != NULL; l = l->next)
+ sb_string_append_printf(rv, "<li>%s</li>%s", l->data,
line_ending);
- b_string_append_printf(rv, "</ol>%s", line_ending);
- b_slist_free_full(lines, free);
+ sb_string_append_printf(rv, "</ol>%s", line_ending);
+ sb_slist_free_full(lines, free);
lines = NULL;
free(prefix);
prefix = NULL;
@@ -1033,7 +1062,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_DIRECTIVE_COLON:
if (c == ':') {
free(directive_name);
- directive_name = b_strndup(src + start2, end - start2);
+ directive_name = sb_strndup(src + start2, end - start2);
state = CONTENT_DIRECTIVE_ARGUMENT_START;
if (is_last) {
state = CONTENT_DIRECTIVE_PARAM_END;
@@ -1077,7 +1106,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
free(directive_argument);
- directive_argument = b_strndup(src + start2, end - start2);
+ directive_argument = sb_strndup(src + start2, end - start2);
if (is_last) {
state = CONTENT_DIRECTIVE_PARAM_END;
continue;
@@ -1098,7 +1127,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
state = CONTENT_DIRECTIVE_PARAM_END;
continue;
}
- prefix = b_strndup(src + start2, current - start2);
+ prefix = sb_strndup(src + start2, current - start2);
state = CONTENT_DIRECTIVE_PARAM_PREFIX;
current--;
break;
@@ -1106,7 +1135,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
case CONTENT_DIRECTIVE_PARAM_PREFIX:
if (c == ' ' || c == '\t')
break;
- if (c == ':' && b_str_starts_with(src + start2, prefix)) {
+ if (c == ':' && sb_str_starts_with(src + start2, prefix)) {
state = CONTENT_DIRECTIVE_PARAM_KEY_START;
break;
}
@@ -1137,7 +1166,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
break;
if (c == ':') {
free(directive_key);
- directive_key = b_strndup(src + start2, current - start2);
+ directive_key = sb_strndup(src + start2, current - start2);
state = CONTENT_DIRECTIVE_PARAM_VALUE_START;
break;
}
@@ -1161,9 +1190,9 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
if (directive_params == NULL)
- directive_params = b_trie_new(free);
- b_trie_insert(directive_params, directive_key,
- b_strndup(src + start2, end - start2));
+ directive_params = sb_trie_new(free);
+ sb_trie_insert(directive_params, directive_key,
+ sb_strndup(src + start2, end - start2));
free(directive_key);
directive_key = NULL;
if (!is_last)
@@ -1176,7 +1205,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
if (c == '\n' || c == '\r' || is_last) {
// FIXME: handle errors in the rest of the parser.
blogc_error_t *err = NULL;
- blogc_directive_ctx_t *ctx = b_malloc(
+ blogc_directive_ctx_t *ctx = sb_malloc(
sizeof(blogc_directive_ctx_t));
ctx->name = directive_name;
ctx->argument = directive_argument;
@@ -1186,7 +1215,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
free(ctx);
blogc_error_print(err);
if (rv_d != NULL)
- b_string_append(rv, rv_d);
+ sb_string_append(rv, rv_d);
free(rv_d);
state = CONTENT_START_LINE;
start = current;
@@ -1194,7 +1223,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
directive_name = NULL;
free(directive_argument);
directive_argument = NULL;
- b_trie_free(directive_params);
+ sb_trie_free(directive_params);
directive_params = NULL;
free(prefix);
prefix = NULL;
@@ -1215,15 +1244,17 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
state = CONTENT_PARAGRAPH_END;
end = is_last && c != '\n' && c != '\r' ? src_len :
(real_end != 0 ? real_end : current);
+ if (description != NULL && *description == NULL)
+ *description = sb_strndup(src + start, end - start);
}
if (!is_last)
break;
case CONTENT_PARAGRAPH_END:
if (c == '\n' || c == '\r' || is_last) {
- tmp = b_strndup(src + start, end - start);
+ tmp = sb_strndup(src + start, end - start);
parsed = blogc_content_parse_inline(tmp);
- b_string_append_printf(rv, "<p>%s</p>%s", parsed,
+ sb_string_append_printf(rv, "<p>%s</p>%s", parsed,
line_ending);
free(parsed);
parsed = NULL;
@@ -1244,8 +1275,8 @@ blogc_content_parse(const char *src, size_t *end_excerpt)
free(directive_name);
free(directive_argument);
free(directive_key);
- b_trie_free(directive_params);
+ sb_trie_free(directive_params);
free(prefix);
- return b_string_free(rv, false);
+ return sb_string_free(rv, false);
}
diff --git a/src/content-parser.h b/src/content-parser.h
index 6617bb4..148d5ed 100644
--- a/src/content-parser.h
+++ b/src/content-parser.h
@@ -16,6 +16,7 @@ char* blogc_slugify(const char *str);
char* blogc_htmlentities(const char *str);
char* blogc_content_parse_inline(const char *src);
bool blogc_is_ordered_list_item(const char *str, size_t prefix_len);
-char* blogc_content_parse(const char *src, size_t *end_excerpt);
+char* blogc_content_parse(const char *src, size_t *end_excerpt,
+ char **description);
#endif /* _CONTENT_PARSER_H */
diff --git a/src/datetime-parser.c b/src/datetime-parser.c
index 8785a89..ad65ff7 100644
--- a/src/datetime-parser.c
+++ b/src/datetime-parser.c
@@ -17,8 +17,8 @@
#include <string.h>
#include "error.h"
-#include "utils/utils.h"
#include "datetime-parser.h"
+#include "utils.h"
typedef enum {
@@ -380,7 +380,7 @@ blogc_convert_datetime(const char *orig, const char *format,
return NULL;
}
- return b_strdup(buf);
+ return sb_strdup(buf);
#endif
}
diff --git a/src/directives.c b/src/directives.c
index b538825..eb6166b 100644
--- a/src/directives.c
+++ b/src/directives.c
@@ -12,9 +12,9 @@
#include <string.h>
-#include "utils/utils.h"
#include "directives.h"
#include "error.h"
+#include "utils.h"
const static blogc_directive_t registry[] = {
@@ -48,11 +48,11 @@ blogc_directive_youtube(blogc_directive_ctx_t *ctx, blogc_error_t **err)
return NULL;
}
- char *width = b_trie_lookup(ctx->params, "width");
- char *height = b_trie_lookup(ctx->params, "height");
+ char *width = sb_trie_lookup(ctx->params, "width");
+ char *height = sb_trie_lookup(ctx->params, "height");
// using default 16:9 sizes provided by youtube as of 2015-11-04
- return b_strdup_printf(
+ return sb_strdup_printf(
"<iframe width=\"%s\" height=\"%s\" "
"src=\"https://www.youtube.com/embed/%s\" frameborder=\"0\" "
"allowfullscreen></iframe>%s",
diff --git a/src/directives.h b/src/directives.h
index dd27f03..0c6e35b 100644
--- a/src/directives.h
+++ b/src/directives.h
@@ -9,13 +9,13 @@
#ifndef _DIRECTIVES_H
#define _DIRECTIVES_H
-#include "utils/utils.h"
+#include "utils.h"
#include "error.h"
typedef struct {
const char *name;
const char *argument;
- b_trie_t *params;
+ sb_trie_t *params;
const char *eol;
} blogc_directive_ctx_t;
diff --git a/src/error.c b/src/error.c
index 59a85a3..3aea641 100644
--- a/src/error.c
+++ b/src/error.c
@@ -14,16 +14,16 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
-#include "utils/utils.h"
#include "error.h"
+#include "utils.h"
blogc_error_t*
blogc_error_new(blogc_error_type_t type, const char *msg)
{
- blogc_error_t *err = b_malloc(sizeof(blogc_error_t));
+ blogc_error_t *err = sb_malloc(sizeof(blogc_error_t));
err->type = type;
- err->msg = b_strdup(msg);
+ err->msg = sb_strdup(msg);
return err;
}
@@ -33,7 +33,7 @@ blogc_error_new_printf(blogc_error_type_t type, const char *format, ...)
{
va_list ap;
va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
+ char *tmp = sb_strdup_vprintf(format, ap);
va_end(ap);
blogc_error_t *rv = blogc_error_new(type, tmp);
free(tmp);
@@ -47,7 +47,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len,
{
va_list ap;
va_start(ap, format);
- char *msg = b_strdup_vprintf(format, ap);
+ char *msg = sb_strdup_vprintf(format, ap);
va_end(ap);
size_t lineno = 1;
@@ -88,7 +88,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len,
if (lineend <= linestart && src_len >= linestart)
lineend = src_len;
- char *line = b_strndup(src + linestart, lineend - linestart);
+ char *line = sb_strndup(src + linestart, lineend - linestart);
blogc_error_t *rv = NULL;
diff --git a/src/file.c b/src/file.c
index a4c763a..f784d93 100644
--- a/src/file.c
+++ b/src/file.c
@@ -14,9 +14,9 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
#include "file.h"
#include "error.h"
+#include "utils.h"
// this would belong to loader.c, but we need it in a separated file to be
// able to mock it when unit testing the loader functions.
@@ -38,16 +38,16 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err)
return NULL;
}
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
char buffer[BLOGC_FILE_CHUNK_SIZE];
while (!feof(fp)) {
size_t read_len = fread(buffer, sizeof(char), BLOGC_FILE_CHUNK_SIZE, fp);
*len += read_len;
- b_string_append_len(str, buffer, read_len);
+ sb_string_append_len(str, buffer, read_len);
}
fclose(fp);
- return b_string_free(str, false);
+ return sb_string_free(str, false);
}
diff --git a/src/loader.c b/src/loader.c
index baa81fa..5ca0aac 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -14,12 +14,12 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
#include "file.h"
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
#include "error.h"
+#include "utils.h"
char*
@@ -31,7 +31,7 @@ blogc_get_filename(const char *f)
if (strlen(f) == 0)
return NULL;
- char *filename = b_strdup(f);
+ char *filename = sb_strdup(f);
// keep a pointer to original string
char *tmp = filename;
@@ -52,14 +52,14 @@ blogc_get_filename(const char *f)
}
}
- char *final_filename = b_strdup(tmp);
+ char *final_filename = sb_strdup(tmp);
free(filename);
return final_filename;
}
-b_slist_t*
+sb_slist_t*
blogc_template_parse_from_file(const char *f, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -68,13 +68,13 @@ blogc_template_parse_from_file(const char *f, blogc_error_t **err)
char *s = blogc_file_get_contents(f, &len, err);
if (s == NULL)
return NULL;
- b_slist_t *rv = blogc_template_parse(s, len, err);
+ sb_slist_t *rv = blogc_template_parse(s, len, err);
free(s);
return rv;
}
-b_trie_t*
+sb_trie_t*
blogc_source_parse_from_file(const char *f, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -83,13 +83,13 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err)
char *s = blogc_file_get_contents(f, &len, err);
if (s == NULL)
return NULL;
- b_trie_t *rv = blogc_source_parse(s, len, err);
+ sb_trie_t *rv = blogc_source_parse(s, len, err);
// set FILENAME variable
if (rv != NULL) {
char *filename = blogc_get_filename(f);
if (filename != NULL)
- b_trie_insert(rv, "FILENAME", filename);
+ sb_trie_insert(rv, "FILENAME", filename);
}
free(s);
@@ -97,16 +97,16 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err)
}
-b_slist_t*
-blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
+sb_slist_t*
+blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err)
{
blogc_error_t *tmp_err = NULL;
- b_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
unsigned int with_date = 0;
- const char *filter_tag = b_trie_lookup(conf, "FILTER_TAG");
- const char *filter_page = b_trie_lookup(conf, "FILTER_PAGE");
- const char *filter_per_page = b_trie_lookup(conf, "FILTER_PER_PAGE");
+ const char *filter_tag = sb_trie_lookup(conf, "FILTER_TAG");
+ const char *filter_page = sb_trie_lookup(conf, "FILTER_PAGE");
+ const char *filter_per_page = sb_trie_lookup(conf, "FILTER_PER_PAGE");
long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10);
if (page <= 0)
@@ -121,27 +121,27 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
unsigned int end = start + per_page;
unsigned int counter = 0;
- for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) {
char *f = tmp->data;
- b_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
+ sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err);
if (s == NULL) {
*err = blogc_error_new_printf(BLOGC_ERROR_LOADER,
"An error occurred while parsing source file: %s\n\n%s",
f, tmp_err->msg);
blogc_error_free(tmp_err);
tmp_err = NULL;
- b_slist_free_full(rv, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free);
rv = NULL;
break;
}
if (filter_tag != NULL) {
- const char *tags_str = b_trie_lookup(s, "TAGS");
+ const char *tags_str = sb_trie_lookup(s, "TAGS");
// if user wants to filter by tag and no tag is provided, skip it
if (tags_str == NULL) {
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
- char **tags = b_str_split(tags_str, ' ', 0);
+ char **tags = sb_str_split(tags_str, ' ', 0);
bool found = false;
for (unsigned int i = 0; tags[i] != NULL; i++) {
if (tags[i][0] == '\0')
@@ -149,26 +149,26 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
if (0 == strcmp(tags[i], filter_tag))
found = true;
}
- b_strv_free(tags);
+ sb_strv_free(tags);
if (!found) {
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
}
if (filter_page != NULL) {
if (counter < start || counter >= end) {
counter++;
- b_trie_free(s);
+ sb_trie_free(s);
continue;
}
counter++;
}
- if (b_trie_lookup(s, "DATE") != NULL)
+ if (sb_trie_lookup(s, "DATE") != NULL)
with_date++;
- rv = b_slist_append(rv, s);
+ rv = sb_slist_append(rv, s);
}
- if (with_date > 0 && with_date < b_slist_length(rv))
+ if (with_date > 0 && with_date < sb_slist_length(rv))
// fatal error, maybe?
blogc_fprintf(stderr,
"blogc: warning: 'DATE' variable provided for at least one source "
@@ -176,38 +176,38 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err)
"wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
bool first = true;
- for (b_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
- b_trie_t *s = tmp->data;
+ for (sb_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) {
+ sb_trie_t *s = tmp->data;
if (first) {
- const char *val = b_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- b_trie_insert(conf, "DATE_FIRST", b_strdup(val));
- val = b_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- b_trie_insert(conf, "FILENAME_FIRST", b_strdup(val));
+ sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val));
first = false;
}
if (tmp->next == NULL) { // last
- const char *val = b_trie_lookup(s, "DATE");
+ const char *val = sb_trie_lookup(s, "DATE");
if (val != NULL)
- b_trie_insert(conf, "DATE_LAST", b_strdup(val));
- val = b_trie_lookup(s, "FILENAME");
+ sb_trie_insert(conf, "DATE_LAST", sb_strdup(val));
+ val = sb_trie_lookup(s, "FILENAME");
if (val != NULL)
- b_trie_insert(conf, "FILENAME_LAST", b_strdup(val));
+ sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val));
}
}
if (filter_page != NULL) {
unsigned int last_page = ceilf(((float) counter) / per_page);
- b_trie_insert(conf, "CURRENT_PAGE", b_strdup_printf("%ld", page));
+ sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page));
if (page > 1)
- b_trie_insert(conf, "PREVIOUS_PAGE", b_strdup_printf("%ld", page - 1));
+ sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1));
if (page < last_page)
- b_trie_insert(conf, "NEXT_PAGE", b_strdup_printf("%ld", page + 1));
- if (b_slist_length(rv) > 0)
- b_trie_insert(conf, "FIRST_PAGE", b_strdup("1"));
+ sb_trie_insert(conf, "NEXT_PAGE", sb_strdup_printf("%ld", page + 1));
+ if (sb_slist_length(rv) > 0)
+ sb_trie_insert(conf, "FIRST_PAGE", sb_strdup("1"));
if (last_page > 0)
- b_trie_insert(conf, "LAST_PAGE", b_strdup_printf("%d", last_page));
+ sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page));
}
return rv;
diff --git a/src/loader.h b/src/loader.h
index c432e20..32b58be 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -9,13 +9,13 @@
#ifndef _LOADER_H
#define _LOADER_H
-#include "utils/utils.h"
#include "error.h"
+#include "utils.h"
char* blogc_get_filename(const char *f);
-b_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err);
-b_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err);
-b_slist_t* blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l,
+sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err);
+sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err);
+sb_slist_t* blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l,
blogc_error_t **err);
#endif /* _LOADER_H */
diff --git a/src/renderer.c b/src/renderer.c
index 5e07b0c..5af3b8a 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -13,69 +13,69 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include "utils/utils.h"
#include "datetime-parser.h"
#include "error.h"
#include "loader.h"
#include "source-parser.h"
#include "template-parser.h"
#include "renderer.h"
+#include "utils.h"
const char*
-blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local)
+blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
const char *rv = NULL;
if (local != NULL) {
- rv = b_trie_lookup(local, name);
+ rv = sb_trie_lookup(local, name);
if (rv != NULL)
return rv;
}
if (global != NULL)
- rv = b_trie_lookup(global, name);
+ rv = sb_trie_lookup(global, name);
return rv;
}
char*
-blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local)
+blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local)
{
const char *date_format = blogc_get_variable("DATE_FORMAT", global, local);
if (date == NULL)
return NULL;
if (date_format == NULL)
- return b_strdup(date);
+ return sb_strdup(date);
blogc_error_t *err = NULL;
char *rv = blogc_convert_datetime(date, date_format, &err);
if (err != NULL) {
blogc_error_print(err);
blogc_error_free(err);
- return b_strdup(date);
+ return sb_strdup(date);
}
return rv;
}
char*
-blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local,
- b_slist_t *foreach_var)
+blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local,
+ sb_slist_t *foreach_var)
{
if (0 == strcmp(name, "FOREACH_ITEM")) {
if (foreach_var != NULL && foreach_var->data != NULL) {
- return b_strdup(foreach_var->data);
+ return sb_strdup(foreach_var->data);
}
return NULL;
}
char *var = NULL;
bool must_format = false;
- if (b_str_ends_with(name, "_FORMATTED")) {
- var = b_strndup(name, strlen(name) - 10);
+ if (sb_str_ends_with(name, "_FORMATTED")) {
+ var = sb_strndup(name, strlen(name) - 10);
must_format = true;
}
if (var == NULL)
- var = b_strdup(name);
+ var = sb_strdup(name);
const char *value = blogc_get_variable(var, global, local);
free(var);
@@ -85,30 +85,30 @@ blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local,
char *rv = NULL;
if (must_format) {
- if (b_str_starts_with(name, "DATE_")) {
+ if (sb_str_starts_with(name, "DATE_")) {
rv = blogc_format_date(value, global, local);
}
}
if (rv == NULL)
- return b_strdup(value);
+ return sb_strdup(value);
return rv;
}
-b_slist_t*
-blogc_split_list_variable(const char *name, b_trie_t *global, b_trie_t *local)
+sb_slist_t*
+blogc_split_list_variable(const char *name, sb_trie_t *global, sb_trie_t *local)
{
const char *value = blogc_get_variable(name, global, local);
if (value == NULL)
return NULL;
- b_slist_t *rv = NULL;
+ sb_slist_t *rv = NULL;
- char **tmp = b_str_split(value, ' ', 0);
+ char **tmp = sb_str_split(value, ' ', 0);
for (unsigned int i = 0; tmp[i] != NULL; i++) {
if (tmp[i][0] != '\0') // ignore empty strings
- rv = b_slist_append(rv, tmp[i]);
+ rv = sb_slist_append(rv, tmp[i]);
else
free(tmp[i]);
}
@@ -119,25 +119,25 @@ blogc_split_list_variable(const char *name, b_trie_t *global, b_trie_t *local)
char*
-blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing)
+blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config, bool listing)
{
if (tmpl == NULL)
return NULL;
- b_slist_t *current_source = NULL;
- b_slist_t *listing_start = NULL;
+ sb_slist_t *current_source = NULL;
+ sb_slist_t *listing_start = NULL;
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
- b_trie_t *tmp_source = NULL;
+ sb_trie_t *tmp_source = NULL;
char *config_value = NULL;
char *defined = NULL;
unsigned int if_count = 0;
- b_slist_t *foreach_var = NULL;
- b_slist_t *foreach_var_start = NULL;
- b_slist_t *foreach_start = NULL;
+ sb_slist_t *foreach_var = NULL;
+ sb_slist_t *foreach_var_start = NULL;
+ sb_slist_t *foreach_start = NULL;
bool if_not = false;
bool inside_block = false;
@@ -145,7 +145,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
int cmp = 0;
- b_slist_t *tmp = tmpl;
+ sb_slist_t *tmp = tmpl;
while (tmp != NULL) {
blogc_template_stmt_t *stmt = tmp->data;
@@ -153,7 +153,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
case BLOGC_TEMPLATE_CONTENT_STMT:
if (stmt->value != NULL)
- b_string_append(str, stmt->value);
+ sb_string_append(str, stmt->value);
break;
case BLOGC_TEMPLATE_BLOCK_STMT:
@@ -210,7 +210,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
config_value = blogc_format_variable(stmt->value,
config, inside_block ? tmp_source : NULL, foreach_var);
if (config_value != NULL) {
- b_string_append(str, config_value);
+ sb_string_append(str, config_value);
free(config_value);
config_value = NULL;
break;
@@ -252,7 +252,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
(stmt->value2[0] == '"') &&
(stmt->value2[strlen(stmt->value2) - 1] == '"'))
{
- defined2 = b_strndup(stmt->value2 + 1,
+ defined2 = sb_strndup(stmt->value2 + 1,
strlen(stmt->value2) - 2);
}
else {
@@ -354,7 +354,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
}
}
foreach_start = NULL;
- b_slist_free_full(foreach_var_start, free);
+ sb_slist_free_full(foreach_var_start, free);
foreach_var_start = NULL;
break;
}
@@ -364,5 +364,5 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
// no need to free temporary variables here. the template parser makes sure
// that templates are sane and statements are closed.
- return b_string_free(str, false);
+ return sb_string_free(str, false);
}
diff --git a/src/renderer.h b/src/renderer.h
index 15204e6..2982ee8 100644
--- a/src/renderer.h
+++ b/src/renderer.h
@@ -10,15 +10,15 @@
#define _RENDERER_H
#include <stdbool.h>
-#include "utils/utils.h"
+#include "utils.h"
-const char* blogc_get_variable(const char *name, b_trie_t *global, b_trie_t *local);
-char* blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local);
-char* blogc_format_variable(const char *name, b_trie_t *global, b_trie_t *local,
- b_slist_t *foreach_var);
-b_slist_t* blogc_split_list_variable(const char *name, b_trie_t *global,
- b_trie_t *local);
-char* blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config,
+const char* blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local);
+char* blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local);
+char* blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local,
+ sb_slist_t *foreach_var);
+sb_slist_t* blogc_split_list_variable(const char *name, sb_trie_t *global,
+ sb_trie_t *local);
+char* blogc_render(sb_slist_t *tmpl, sb_slist_t *sources, sb_trie_t *config,
bool listing);
#endif /* _RENDERER_H */
diff --git a/src/source-parser.c b/src/source-parser.c
index 65fdd4e..f250bd3 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -13,10 +13,10 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/utils.h"
#include "content-parser.h"
#include "source-parser.h"
#include "error.h"
+#include "utils.h"
typedef enum {
@@ -30,7 +30,7 @@ typedef enum {
} blogc_source_parser_state_t;
-b_trie_t*
+sb_trie_t*
blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -43,7 +43,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
char *key = NULL;
char *tmp = NULL;
char *content = NULL;
- b_trie_t *rv = b_trie_new(free);
+ sb_trie_t *rv = sb_trie_new(free);
blogc_source_parser_state_t state = SOURCE_START;
@@ -73,7 +73,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
if ((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')
break;
if (c == ':') {
- key = b_strndup(src + start, current - start);
+ key = sb_strndup(src + start, current - start);
if (((current - start == 8) &&
(0 == strncmp("FILENAME", src + start, 8))) ||
((current - start == 7) &&
@@ -122,8 +122,8 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
case SOURCE_CONFIG_VALUE:
if (c == '\n' || c == '\r') {
- tmp = b_strndup(src + start, current - start);
- b_trie_insert(rv, key, b_strdup(b_str_strip(tmp)));
+ tmp = sb_strndup(src + start, current - start);
+ sb_trie_insert(rv, key, sb_strdup(sb_str_strip(tmp)));
free(tmp);
free(key);
key = NULL;
@@ -152,12 +152,24 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
case SOURCE_CONTENT:
if (current == (src_len - 1)) {
- tmp = b_strndup(src + start, src_len - start);
- b_trie_insert(rv, "RAW_CONTENT", tmp);
- content = blogc_content_parse(tmp, &end_excerpt);
- b_trie_insert(rv, "CONTENT", content);
- b_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
- b_strdup(content) : b_strndup(content, end_excerpt));
+ tmp = sb_strndup(src + start, src_len - start);
+ sb_trie_insert(rv, "RAW_CONTENT", tmp);
+ char *description = NULL;
+ content = blogc_content_parse(tmp, &end_excerpt, &description);
+ if (description != NULL) {
+ // do not override source-provided description.
+ if (NULL == sb_trie_lookup(rv, "DESCRIPTION")) {
+ // no need to free, because we are transfering memory
+ // ownership to the trie.
+ sb_trie_insert(rv, "DESCRIPTION", description);
+ }
+ else {
+ free(description);
+ }
+ }
+ sb_trie_insert(rv, "CONTENT", content);
+ sb_trie_insert(rv, "EXCERPT", end_excerpt == 0 ?
+ sb_strdup(content) : sb_strndup(content, end_excerpt));
}
break;
}
@@ -168,7 +180,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
current++;
}
- if (*err == NULL && b_trie_size(rv) == 0) {
+ if (*err == NULL && sb_trie_size(rv) == 0) {
// ok, nothing found in the config trie, but no error set either.
// let's try to be nice with the users and provide some reasonable
@@ -202,7 +214,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
if (*err != NULL) {
free(key);
- b_trie_free(rv);
+ sb_trie_free(rv);
return NULL;
}
diff --git a/src/source-parser.h b/src/source-parser.h
index f359f9e..5cadf95 100644
--- a/src/source-parser.h
+++ b/src/source-parser.h
@@ -10,10 +10,10 @@
#define _SOURCE_PARSER_H
#include <stdlib.h>
-#include "utils/utils.h"
#include "error.h"
+#include "utils.h"
-b_trie_t* blogc_source_parse(const char *src, size_t src_len,
+sb_trie_t* blogc_source_parse(const char *src, size_t src_len,
blogc_error_t **err);
#endif /* _SOURCE_PARSER_H */
diff --git a/src/template-parser.c b/src/template-parser.c
index 1d9046e..525f5f5 100644
--- a/src/template-parser.c
+++ b/src/template-parser.c
@@ -13,9 +13,9 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/utils.h"
#include "template-parser.h"
#include "error.h"
+#include "utils.h"
typedef enum {
@@ -52,7 +52,7 @@ typedef enum {
} blogc_template_parser_block_state_t;
-b_slist_t*
+sb_slist_t*
blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
{
if (err == NULL || *err != NULL)
@@ -71,7 +71,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
unsigned int if_count = 0;
bool foreach_open = false;
- b_slist_t *stmts = NULL;
+ sb_slist_t *stmts = NULL;
blogc_template_stmt_t *stmt = NULL;
/*
@@ -100,21 +100,21 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
case TEMPLATE_START:
if (last) {
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
if (lstrip_next) {
- tmp = b_strndup(src + start, src_len - start);
- stmt->value = b_strdup(b_str_lstrip(tmp));
+ tmp = sb_strndup(src + start, src_len - start);
+ stmt->value = sb_strdup(sb_str_lstrip(tmp));
free(tmp);
tmp = NULL;
lstrip_next = false;
}
else {
- stmt->value = b_strndup(src + start, src_len - start);
+ stmt->value = sb_strndup(src + start, src_len - start);
}
stmt->op = 0;
stmt->value2 = NULL;
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
previous = stmt;
stmt = NULL;
}
@@ -131,21 +131,21 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
else
state = TEMPLATE_VARIABLE_START;
if (end > start) {
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
if (lstrip_next) {
- tmp = b_strndup(src + start, end - start);
- stmt->value = b_strdup(b_str_lstrip(tmp));
+ tmp = sb_strndup(src + start, end - start);
+ stmt->value = sb_strdup(sb_str_lstrip(tmp));
free(tmp);
tmp = NULL;
lstrip_next = false;
}
else {
- stmt->value = b_strndup(src + start, end - start);
+ stmt->value = sb_strndup(src + start, end - start);
}
stmt->op = 0;
stmt->value2 = NULL;
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
previous = stmt;
stmt = NULL;
}
@@ -159,7 +159,7 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
if ((previous != NULL) &&
(previous->type == BLOGC_TEMPLATE_CONTENT_STMT))
{
- previous->value = b_str_rstrip(previous->value); // does not need copy
+ previous->value = sb_str_rstrip(previous->value); // does not need copy
}
state = TEMPLATE_BLOCK_START;
break;
@@ -559,19 +559,19 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
op_start = 0;
op_end = 0;
}
- stmt = b_malloc(sizeof(blogc_template_stmt_t));
+ stmt = sb_malloc(sizeof(blogc_template_stmt_t));
stmt->type = type;
stmt->value = NULL;
stmt->op = tmp_op;
stmt->value2 = NULL;
if (end > start)
- stmt->value = b_strndup(src + start, end - start);
+ stmt->value = sb_strndup(src + start, end - start);
if (end2 > start2) {
- stmt->value2 = b_strndup(src + start2, end2 - start2);
+ stmt->value2 = sb_strndup(src + start2, end2 - start2);
start2 = 0;
end2 = 0;
}
- stmts = b_slist_append(stmts, stmt);
+ stmts = sb_slist_append(stmts, stmt);
previous = stmt;
stmt = NULL;
state = TEMPLATE_START;
@@ -622,9 +622,9 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err)
void
-blogc_template_free_stmts(b_slist_t *stmts)
+blogc_template_free_stmts(sb_slist_t *stmts)
{
- for (b_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) {
+ for (sb_slist_t *tmp = stmts; tmp != NULL; tmp = tmp->next) {
blogc_template_stmt_t *data = tmp->data;
if (data == NULL)
continue;
@@ -632,5 +632,5 @@ blogc_template_free_stmts(b_slist_t *stmts)
free(data->value2);
free(data);
}
- b_slist_free(stmts);
+ sb_slist_free(stmts);
}
diff --git a/src/template-parser.h b/src/template-parser.h
index 6cd2c80..a8b4e8b 100644
--- a/src/template-parser.h
+++ b/src/template-parser.h
@@ -9,8 +9,8 @@
#ifndef _TEMPLATE_PARSER_H
#define _TEMPLATE_PARSER_H
-#include "utils/utils.h"
#include "error.h"
+#include "utils.h"
/*
* note: whitespace cleaners are NOT added to ast. we fix strings right during
@@ -44,8 +44,8 @@ typedef struct {
blogc_template_stmt_operator_t op;
} blogc_template_stmt_t;
-b_slist_t* blogc_template_parse(const char *src, size_t src_len,
+sb_slist_t* blogc_template_parse(const char *src, size_t src_len,
blogc_error_t **err);
-void blogc_template_free_stmts(b_slist_t *stmts);
+void blogc_template_free_stmts(sb_slist_t *stmts);
#endif /* _TEMPLATE_GRAMMAR_H */
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..855b503
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,612 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#define SB_STRING_CHUNK_SIZE 128
+
+#include <ctype.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "utils.h"
+
+
+void*
+sb_malloc(size_t size)
+{
+ // simple things simple!
+ void *rv = malloc(size);
+ if (rv == NULL) {
+ fprintf(stderr, "fatal: Failed to allocate memory!\n");
+ abort();
+ }
+ return rv;
+}
+
+
+void*
+sb_realloc(void *ptr, size_t size)
+{
+ // simple things even simpler :P
+ void *rv = realloc(ptr, size);
+ if (rv == NULL && size != 0) {
+ fprintf(stderr, "fatal: Failed to reallocate memory!\n");
+ free(ptr);
+ abort();
+ }
+ return rv;
+}
+
+
+sb_slist_t*
+sb_slist_append(sb_slist_t *l, void *data)
+{
+ sb_slist_t *node = sb_malloc(sizeof(sb_slist_t));
+ node->data = data;
+ node->next = NULL;
+ if (l == NULL) {
+ l = node;
+ }
+ else {
+ sb_slist_t *tmp;
+ for (tmp = l; tmp->next != NULL; tmp = tmp->next);
+ tmp->next = node;
+ }
+ return l;
+}
+
+
+sb_slist_t*
+sb_slist_prepend(sb_slist_t *l, void *data)
+{
+ sb_slist_t *node = sb_malloc(sizeof(sb_slist_t));
+ node->data = data;
+ node->next = l;
+ l = node;
+ return l;
+}
+
+
+void
+sb_slist_free_full(sb_slist_t *l, sb_free_func_t free_func)
+{
+ while (l != NULL) {
+ sb_slist_t *tmp = l->next;
+ if ((free_func != NULL) && (l->data != NULL))
+ free_func(l->data);
+ free(l);
+ l = tmp;
+ }
+}
+
+
+void
+sb_slist_free(sb_slist_t *l)
+{
+ sb_slist_free_full(l, NULL);
+}
+
+
+size_t
+sb_slist_length(sb_slist_t *l)
+{
+ if (l == NULL)
+ return 0;
+ size_t i;
+ sb_slist_t *tmp;
+ for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++);
+ return i;
+}
+
+
+char*
+sb_strdup(const char *s)
+{
+ if (s == NULL)
+ return NULL;
+ size_t l = strlen(s);
+ char *tmp = malloc(l + 1);
+ if (tmp == NULL)
+ return NULL;
+ memcpy(tmp, s, l + 1);
+ return tmp;
+}
+
+
+char*
+sb_strndup(const char *s, size_t n)
+{
+ if (s == NULL)
+ return NULL;
+ size_t l = strnlen(s, n);
+ char *tmp = malloc(l + 1);
+ if (tmp == NULL)
+ return NULL;
+ memcpy(tmp, s, l);
+ tmp[l] = '\0';
+ return tmp;
+}
+
+
+char*
+sb_strdup_vprintf(const char *format, va_list ap)
+{
+ va_list ap2;
+ va_copy(ap2, ap);
+ int l = vsnprintf(NULL, 0, format, ap2);
+ va_end(ap2);
+ if (l < 0)
+ return NULL;
+ char *tmp = malloc(l + 1);
+ if (!tmp)
+ return NULL;
+ int l2 = vsnprintf(tmp, l + 1, format, ap);
+ if (l2 < 0) {
+ free(tmp);
+ return NULL;
+ }
+ return tmp;
+}
+
+
+char*
+sb_strdup_printf(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ char *tmp = sb_strdup_vprintf(format, ap);
+ va_end(ap);
+ return tmp;
+}
+
+
+bool
+sb_str_starts_with(const char *str, const char *prefix)
+{
+ int str_l = strlen(str);
+ int str_lp = strlen(prefix);
+ if (str_lp > str_l)
+ return false;
+ return strncmp(str, prefix, str_lp) == 0;
+}
+
+
+bool
+sb_str_ends_with(const char *str, const char *suffix)
+{
+ int str_l = strlen(str);
+ int str_ls = strlen(suffix);
+ if (str_ls > str_l)
+ return false;
+ return strcmp(str + str_l - str_ls, suffix) == 0;
+}
+
+
+char*
+sb_str_lstrip(char *str)
+{
+ if (str == NULL)
+ return NULL;
+ int i;
+ size_t str_len = strlen(str);
+ for (i = 0; i < str_len; i++) {
+ if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
+ (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
+ (str[i] != '\v'))
+ {
+ str += i;
+ break;
+ }
+ if (i == str_len - 1) {
+ str += str_len;
+ break;
+ }
+ }
+ return str;
+}
+
+
+char*
+sb_str_rstrip(char *str)
+{
+ if (str == NULL)
+ return NULL;
+ int i;
+ size_t str_len = strlen(str);
+ for (i = str_len - 1; i >= 0; i--) {
+ if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
+ (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
+ (str[i] != '\v'))
+ {
+ str[i + 1] = '\0';
+ break;
+ }
+ if (i == 0) {
+ str[0] = '\0';
+ break;
+ }
+ }
+ return str;
+}
+
+
+char*
+sb_str_strip(char *str)
+{
+ return sb_str_lstrip(sb_str_rstrip(str));
+}
+
+
+char**
+sb_str_split(const char *str, char c, unsigned int max_pieces)
+{
+ if (str == NULL)
+ return NULL;
+ char **rv = sb_malloc(sizeof(char*));
+ unsigned int i, start = 0, count = 0;
+ for (i = 0; i < strlen(str) + 1; i++) {
+ if (str[0] == '\0')
+ break;
+ if ((str[i] == c && (!max_pieces || count + 1 < max_pieces)) || str[i] == '\0') {
+ rv = sb_realloc(rv, (count + 1) * sizeof(char*));
+ rv[count] = sb_malloc(i - start + 1);
+ memcpy(rv[count], str + start, i - start);
+ rv[count++][i - start] = '\0';
+ start = i + 1;
+ }
+ }
+ rv = sb_realloc(rv, (count + 1) * sizeof(char*));
+ rv[count] = NULL;
+ return rv;
+}
+
+
+char*
+sb_str_replace(const char *str, const char search, const char *replace)
+{
+ char **pieces = sb_str_split(str, search, 0);
+ if (pieces == NULL)
+ return NULL;
+ char* rv = sb_strv_join(pieces, replace);
+ sb_strv_free(pieces);
+ if (rv == NULL)
+ return sb_strdup(str);
+ return rv;
+}
+
+
+void
+sb_strv_free(char **strv)
+{
+ if (strv == NULL)
+ return;
+ for (size_t i = 0; strv[i] != NULL; i++)
+ free(strv[i]);
+ free(strv);
+}
+
+
+char*
+sb_strv_join(char **strv, const char *separator)
+{
+ if (strv == NULL || separator == NULL)
+ return NULL;
+ sb_string_t *str = sb_string_new();
+ for (size_t i = 0; strv[i] != NULL; i++) {
+ str = sb_string_append(str, strv[i]);
+ if (strv[i + 1] != NULL)
+ str = sb_string_append(str, separator);
+ }
+ return sb_string_free(str, false);
+}
+
+
+size_t
+sb_strv_length(char **strv)
+{
+ if (strv == NULL)
+ return 0;
+ size_t i;
+ for (i = 0; strv[i] != NULL; i++);
+ return i;
+}
+
+
+sb_string_t*
+sb_string_new(void)
+{
+ sb_string_t* rv = sb_malloc(sizeof(sb_string_t));
+ rv->str = NULL;
+ rv->len = 0;
+ rv->allocated_len = 0;
+
+ // initialize with empty string
+ rv = sb_string_append(rv, "");
+
+ return rv;
+}
+
+
+char*
+sb_string_free(sb_string_t *str, bool free_str)
+{
+ if (str == NULL)
+ return NULL;
+ char *rv = NULL;
+ if (free_str)
+ free(str->str);
+ else
+ rv = str->str;
+ free(str);
+ return rv;
+}
+
+
+sb_string_t*
+sb_string_dup(sb_string_t *str)
+{
+ if (str == NULL)
+ return NULL;
+ sb_string_t* new = sb_string_new();
+ return sb_string_append_len(new, str->str, str->len);
+}
+
+
+sb_string_t*
+sb_string_append_len(sb_string_t *str, const char *suffix, size_t len)
+{
+ if (str == NULL)
+ return NULL;
+ if (suffix == NULL)
+ return str;
+ size_t old_len = str->len;
+ str->len += len;
+ if (str->len + 1 > str->allocated_len) {
+ str->allocated_len = (((str->len + 1) / SB_STRING_CHUNK_SIZE) + 1) * SB_STRING_CHUNK_SIZE;
+ str->str = sb_realloc(str->str, str->allocated_len);
+ }
+ memcpy(str->str + old_len, suffix, len);
+ str->str[str->len] = '\0';
+ return str;
+}
+
+
+sb_string_t*
+sb_string_append(sb_string_t *str, const char *suffix)
+{
+ if (str == NULL)
+ return NULL;
+ const char *my_suffix = suffix == NULL ? "" : suffix;
+ return sb_string_append_len(str, my_suffix, strlen(my_suffix));
+}
+
+
+sb_string_t*
+sb_string_append_c(sb_string_t *str, char c)
+{
+ if (str == NULL)
+ return NULL;
+ size_t old_len = str->len;
+ str->len += 1;
+ if (str->len + 1 > str->allocated_len) {
+ str->allocated_len = (((str->len + 1) / SB_STRING_CHUNK_SIZE) + 1) * SB_STRING_CHUNK_SIZE;
+ str->str = sb_realloc(str->str, str->allocated_len);
+ }
+ str->str[old_len] = c;
+ str->str[str->len] = '\0';
+ return str;
+}
+
+
+sb_string_t*
+sb_string_append_printf(sb_string_t *str, const char *format, ...)
+{
+ if (str == NULL)
+ return NULL;
+ va_list ap;
+ va_start(ap, format);
+ char *tmp = sb_strdup_vprintf(format, ap);
+ va_end(ap);
+ str = sb_string_append(str, tmp);
+ free(tmp);
+ return str;
+}
+
+
+sb_trie_t*
+sb_trie_new(sb_free_func_t free_func)
+{
+ sb_trie_t *trie = sb_malloc(sizeof(sb_trie_t));
+ trie->root = NULL;
+ trie->free_func = free_func;
+ return trie;
+}
+
+
+static void
+sb_trie_free_node(sb_trie_t *trie, sb_trie_node_t *node)
+{
+ if (trie == NULL || node == NULL)
+ return;
+ if (node->data != NULL && trie->free_func != NULL)
+ trie->free_func(node->data);
+ sb_trie_free_node(trie, node->next);
+ sb_trie_free_node(trie, node->child);
+ free(node);
+}
+
+
+void
+sb_trie_free(sb_trie_t *trie)
+{
+ if (trie == NULL)
+ return;
+ sb_trie_free_node(trie, trie->root);
+ free(trie);
+}
+
+
+void
+sb_trie_insert(sb_trie_t *trie, const char *key, void *data)
+{
+ if (trie == NULL || key == NULL || data == NULL)
+ return;
+
+ sb_trie_node_t *parent = NULL;
+ sb_trie_node_t *previous;
+ sb_trie_node_t *current;
+ sb_trie_node_t *tmp;
+
+ while (1) {
+
+ if (trie->root == NULL || (parent != NULL && parent->child == NULL)) {
+ current = sb_malloc(sizeof(sb_trie_node_t));
+ current->key = *key;
+ current->data = NULL;
+ current->next = NULL;
+ current->child = NULL;
+ if (trie->root == NULL)
+ trie->root = current;
+ else
+ parent->child = current;
+ parent = current;
+ goto clean;
+ }
+
+ tmp = parent == NULL ? trie->root : parent->child;
+ previous = NULL;
+
+ while (tmp != NULL && tmp->key != *key) {
+ previous = tmp;
+ tmp = tmp->next;
+ }
+
+ parent = tmp;
+
+ if (previous == NULL || parent != NULL)
+ goto clean;
+
+ current = sb_malloc(sizeof(sb_trie_node_t));
+ current->key = *key;
+ current->data = NULL;
+ current->next = NULL;
+ current->child = NULL;
+ previous->next = current;
+ parent = current;
+
+clean:
+ if (*key == '\0') {
+ if (parent->data != NULL && trie->free_func != NULL)
+ trie->free_func(parent->data);
+ parent->data = data;
+ break;
+ }
+ key++;
+ }
+}
+
+
+void*
+sb_trie_lookup(sb_trie_t *trie, const char *key)
+{
+ if (trie == NULL || trie->root == NULL || key == NULL)
+ return NULL;
+
+ sb_trie_node_t *parent = trie->root;
+ sb_trie_node_t *tmp;
+ while (1) {
+ for (tmp = parent; tmp != NULL; tmp = tmp->next) {
+
+ if (tmp->key == *key) {
+ if (tmp->key == '\0')
+ return tmp->data;
+ parent = tmp->child;
+ break;
+ }
+ }
+ if (tmp == NULL)
+ return NULL;
+
+ if (*key == '\0')
+ break;
+ key++;
+ }
+ return NULL;
+}
+
+
+static void
+sb_trie_size_node(sb_trie_node_t *node, size_t *count)
+{
+ if (node == NULL || count == NULL)
+ return;
+
+ if (node->key == '\0')
+ (*count)++;
+
+ sb_trie_size_node(node->next, count);
+ sb_trie_size_node(node->child, count);
+}
+
+
+size_t
+sb_trie_size(sb_trie_t *trie)
+{
+ if (trie == NULL)
+ return 0;
+
+ size_t count = 0;
+ sb_trie_size_node(trie->root, &count);
+ return count;
+}
+
+
+static void
+sb_trie_foreach_node(sb_trie_node_t *node, sb_string_t *str,
+ sb_trie_foreach_func_t func, void *user_data)
+{
+ if (node == NULL || str == NULL || func == NULL)
+ return;
+
+ if (node->key == '\0') {
+ char *tmp = sb_string_free(str, false);
+ func(tmp, node->data, user_data);
+ free(tmp);
+ }
+
+ if (node->child != NULL) {
+ sb_string_t *child = sb_string_dup(str);
+ child = sb_string_append_c(child, node->key);
+ sb_trie_foreach_node(node->child, child, func, user_data);
+ }
+
+ if (node->next != NULL)
+ sb_trie_foreach_node(node->next, str, func, user_data);
+
+ if (node->child != NULL && node->next == NULL)
+ sb_string_free(str, true);
+}
+
+
+void
+sb_trie_foreach(sb_trie_t *trie, sb_trie_foreach_func_t func,
+ void *user_data)
+{
+ if (trie == NULL || trie->root == NULL || func == NULL)
+ return;
+
+ sb_string_t *str = sb_string_new();
+ sb_trie_foreach_node(trie->root, str, func, user_data);
+}
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..411295a
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,102 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifndef _UTILS_H
+#define _UTILS_H
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+
+// memory
+
+typedef void (*sb_free_func_t) (void *ptr);
+
+void* sb_malloc(size_t size);
+void* sb_realloc(void *ptr, size_t size);
+
+
+// slist
+
+typedef struct _sb_slist_t {
+ struct _sb_slist_t *next;
+ void *data;
+} sb_slist_t;
+
+sb_slist_t* sb_slist_append(sb_slist_t *l, void *data);
+sb_slist_t* sb_slist_prepend(sb_slist_t *l, void *data);
+void sb_slist_free(sb_slist_t *l);
+void sb_slist_free_full(sb_slist_t *l, sb_free_func_t free_func);
+size_t sb_slist_length(sb_slist_t *l);
+
+
+// strfuncs
+
+char* sb_strdup(const char *s);
+char* sb_strndup(const char *s, size_t n);
+char* sb_strdup_vprintf(const char *format, va_list ap);
+char* sb_strdup_printf(const char *format, ...);
+bool sb_str_starts_with(const char *str, const char *prefix);
+bool sb_str_ends_with(const char *str, const char *suffix);
+char* sb_str_lstrip(char *str);
+char* sb_str_rstrip(char *str);
+char* sb_str_strip(char *str);
+char** sb_str_split(const char *str, char c, unsigned int max_pieces);
+char* sb_str_replace(const char *str, const char search, const char *replace);
+void sb_strv_free(char **strv);
+char* sb_strv_join(char **strv, const char *separator);
+size_t sb_strv_length(char **strv);
+
+
+// string
+
+typedef struct {
+ char *str;
+ size_t len;
+ size_t allocated_len;
+} sb_string_t;
+
+sb_string_t* sb_string_new(void);
+char* sb_string_free(sb_string_t *str, bool free_str);
+sb_string_t* sb_string_dup(sb_string_t *str);
+sb_string_t* sb_string_append_len(sb_string_t *str, const char *suffix, size_t len);
+sb_string_t* sb_string_append(sb_string_t *str, const char *suffix);
+sb_string_t* sb_string_append_c(sb_string_t *str, char c);
+sb_string_t* sb_string_append_printf(sb_string_t *str, const char *format, ...);
+
+
+// trie
+
+typedef struct _sb_trie_node_t {
+ char key;
+ void *data;
+ struct _sb_trie_node_t *next, *child;
+} sb_trie_node_t;
+
+struct _sb_trie_t {
+ sb_trie_node_t *root;
+ sb_free_func_t free_func;
+};
+
+typedef struct _sb_trie_t sb_trie_t;
+
+typedef void (*sb_trie_foreach_func_t)(const char *key, void *data,
+ void *user_data);
+
+sb_trie_t* sb_trie_new(sb_free_func_t free_func);
+void sb_trie_free(sb_trie_t *trie);
+void sb_trie_insert(sb_trie_t *trie, const char *key, void *data);
+void* sb_trie_lookup(sb_trie_t *trie, const char *key);
+size_t sb_trie_size(sb_trie_t *trie);
+void sb_trie_foreach(sb_trie_t *trie, sb_trie_foreach_func_t func,
+ void *user_data);
+
+#endif /* _UTILS_H */
diff --git a/src/utils/mem.c b/src/utils/mem.c
deleted file mode 100644
index 693d555..0000000
--- a/src/utils/mem.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "utils.h"
-
-
-void*
-b_malloc(size_t size)
-{
- // simple things simple!
- void *rv = malloc(size);
- if (rv == NULL) {
- fprintf(stderr, "fatal error: Failed to allocate memory!\n");
- exit(1);
- }
- return rv;
-}
-
-
-void*
-b_realloc(void *ptr, size_t size)
-{
- // simple things even simpler :P
- void *rv = realloc(ptr, size);
- if (rv == NULL && size != 0) {
- fprintf(stderr, "fatal error: Failed to reallocate memory!\n");
- free(ptr);
- exit(1);
- }
- return rv;
-}
diff --git a/src/utils/slist.c b/src/utils/slist.c
deleted file mode 100644
index 9753aa7..0000000
--- a/src/utils/slist.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include "utils.h"
-
-
-b_slist_t*
-b_slist_append(b_slist_t *l, void *data)
-{
- b_slist_t *node = malloc(sizeof(b_slist_t));
- if (node == NULL) {
- l = NULL;
- return l;
- }
- node->data = data;
- node->next = NULL;
- if (l == NULL)
- l = node;
- else {
- b_slist_t *tmp;
- for (tmp = l; tmp->next != NULL; tmp = tmp->next);
- tmp->next = node;
- }
- return l;
-}
-
-
-void
-b_slist_free_full(b_slist_t *l, b_free_func_t free_func)
-{
- while (l != NULL) {
- b_slist_t *tmp = l->next;
- free_func(l->data);
- free(l);
- l = tmp;
- }
-}
-
-
-void
-b_slist_free(b_slist_t *l)
-{
- while (l != NULL) {
- b_slist_t *tmp = l->next;
- free(l);
- l = tmp;
- }
-}
-
-
-unsigned int
-b_slist_length(b_slist_t *l)
-{
- unsigned int i;
- b_slist_t *tmp;
- for (tmp = l, i = 0; tmp != NULL; tmp = tmp->next, i++);
- return i;
-}
diff --git a/src/utils/strings.c b/src/utils/strings.c
deleted file mode 100644
index 3151612..0000000
--- a/src/utils/strings.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <ctype.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "utils.h"
-
-
-char*
-b_strdup(const char *s)
-{
- if (s == NULL)
- return NULL;
- size_t l = strlen(s);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l + 1);
- return tmp;
-}
-
-
-char*
-b_strndup(const char *s, size_t n)
-{
- if (s == NULL)
- return NULL;
- size_t l = strnlen(s, n);
- char *tmp = malloc(l + 1);
- if (tmp == NULL)
- return NULL;
- memcpy(tmp, s, l);
- tmp[l] = '\0';
- return tmp;
-}
-
-
-char*
-b_strdup_vprintf(const char *format, va_list ap)
-{
- va_list ap2;
- va_copy(ap2, ap);
- int l = vsnprintf(NULL, 0, format, ap2);
- va_end(ap2);
- if (l < 0)
- return NULL;
- char *tmp = malloc(l + 1);
- if (!tmp)
- return NULL;
- int l2 = vsnprintf(tmp, l + 1, format, ap);
- if (l2 < 0) {
- free(tmp);
- return NULL;
- }
- return tmp;
-}
-
-
-char*
-b_strdup_printf(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
- va_end(ap);
- return tmp;
-}
-
-
-bool
-b_str_starts_with(const char *str, const char *prefix)
-{
- int str_l = strlen(str);
- int str_lp = strlen(prefix);
- if (str_lp > str_l)
- return false;
- return strncmp(str, prefix, str_lp) == 0;
-}
-
-
-bool
-b_str_ends_with(const char *str, const char *suffix)
-{
- int str_l = strlen(str);
- int str_ls = strlen(suffix);
- if (str_ls > str_l)
- return false;
- return strcmp(str + str_l - str_ls, suffix) == 0;
-}
-
-
-char*
-b_str_lstrip(char *str)
-{
- if (str == NULL)
- return NULL;
- int i;
- size_t str_len = strlen(str);
- for (i = 0; i < str_len; i++) {
- if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
- (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
- (str[i] != '\v'))
- {
- str += i;
- break;
- }
- if (i == str_len - 1) {
- str += str_len;
- break;
- }
- }
- return str;
-}
-
-
-char*
-b_str_rstrip(char *str)
-{
- if (str == NULL)
- return NULL;
- int i;
- size_t str_len = strlen(str);
- for (i = str_len - 1; i >= 0; i--) {
- if ((str[i] != ' ') && (str[i] != '\t') && (str[i] != '\n') &&
- (str[i] != '\r') && (str[i] != '\t') && (str[i] != '\f') &&
- (str[i] != '\v'))
- {
- str[i + 1] = '\0';
- break;
- }
- if (i == 0) {
- str[0] = '\0';
- break;
- }
- }
- return str;
-}
-
-
-char*
-b_str_strip(char *str)
-{
- return b_str_lstrip(b_str_rstrip(str));
-}
-
-
-char**
-b_str_split(const char *str, char c, unsigned int max_pieces)
-{
- if (!str)
- return NULL;
- char **rv = b_malloc(sizeof(char*));
- unsigned int i, start = 0, count = 0;
- for (i = 0; i < strlen(str) + 1; i++) {
- if (str[0] == '\0')
- break;
- if ((str[i] == c && (!max_pieces || count + 1 < max_pieces)) || str[i] == '\0') {
- rv = b_realloc(rv, (count + 1) * sizeof(char*));
- rv[count] = b_malloc(i - start + 1);
- memcpy(rv[count], str + start, i - start);
- rv[count++][i - start] = '\0';
- start = i + 1;
- }
- }
- rv = b_realloc(rv, (count + 1) * sizeof(char*));
- rv[count] = NULL;
- return rv;
-}
-
-
-char*
-b_str_replace(const char *str, const char search, const char *replace)
-{
- char **pieces = b_str_split(str, search, 0);
- if (pieces == NULL)
- return NULL;
- char* rv = b_strv_join((const char**) pieces, replace);
- b_strv_free(pieces);
- return rv;
-}
-
-
-void
-b_strv_free(char **strv)
-{
- if (strv == NULL)
- return;
- unsigned int i;
- for (i = 0; strv[i] != NULL; i++)
- free(strv[i]);
- free(strv);
-}
-
-
-char*
-b_strv_join(const char **strv, const char *separator)
-{
- if (strv == NULL)
- return NULL;
- unsigned int i = 0;
- b_string_t *str = b_string_new();
- for (i = 0; strv[i] != NULL; i++) {
- str = b_string_append(str, strv[i]);
- if (strv[i+1] != NULL)
- str = b_string_append(str, separator);
- }
- return b_string_free(str, false);
-}
-
-
-unsigned int
-b_strv_length(char **strv)
-{
- if (!strv)
- return 0;
- unsigned int i;
- for (i = 0; strv[i] != NULL; i++);
- return i;
-}
-
-
-b_string_t*
-b_string_new(void)
-{
- b_string_t* rv = b_malloc(sizeof(b_string_t));
- rv->str = NULL;
- rv->len = 0;
- rv->allocated_len = 0;
-
- // initialize with empty string
- rv = b_string_append(rv, "");
-
- return rv;
-}
-
-
-char*
-b_string_free(b_string_t *str, bool free_str)
-{
- char *rv = NULL;
- if (free_str)
- free(str->str);
- else
- rv = str->str;
- free(str);
- return rv;
-}
-
-
-b_string_t*
-b_string_append_len(b_string_t *str, const char *suffix, size_t len)
-{
- if (suffix == NULL)
- return str;
- size_t old_len = str->len;
- str->len += len;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / B_STRING_CHUNK_SIZE) + 1) * B_STRING_CHUNK_SIZE;
- str->str = b_realloc(str->str, str->allocated_len);
- }
- memcpy(str->str + old_len, suffix, len);
- str->str[str->len] = '\0';
- return str;
-}
-
-
-b_string_t*
-b_string_append(b_string_t *str, const char *suffix)
-{
- if (suffix == NULL)
- return str;
- return b_string_append_len(str, suffix, strlen(suffix));
-}
-
-
-b_string_t*
-b_string_append_c(b_string_t *str, char c)
-{
- size_t old_len = str->len;
- str->len += 1;
- if (str->len + 1 > str->allocated_len) {
- str->allocated_len = (((str->len + 1) / B_STRING_CHUNK_SIZE) + 1) * B_STRING_CHUNK_SIZE;
- str->str = b_realloc(str->str, str->allocated_len);
- }
- str->str[old_len] = c;
- str->str[str->len] = '\0';
- return str;
-}
-
-
-b_string_t*
-b_string_append_printf(b_string_t *str, const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char *tmp = b_strdup_vprintf(format, ap);
- va_end(ap);
- str = b_string_append(str, tmp);
- free(tmp);
- return str;
-}
diff --git a/src/utils/trie.c b/src/utils/trie.c
deleted file mode 100644
index 2e6a0d8..0000000
--- a/src/utils/trie.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <stdlib.h>
-#include "utils.h"
-
-
-b_trie_t*
-b_trie_new(b_free_func_t free_func)
-{
- b_trie_t *trie = b_malloc(sizeof(b_trie_t));
- trie->root = NULL;
- trie->free_func = free_func;
- return trie;
-}
-
-
-static void
-b_trie_free_node(b_trie_t *trie, b_trie_node_t *node)
-{
- if (node == NULL)
- return;
- if (node->data != NULL && trie->free_func != NULL)
- trie->free_func(node->data);
- b_trie_free_node(trie, node->next);
- b_trie_free_node(trie, node->child);
- free(node);
-}
-
-
-void
-b_trie_free(b_trie_t *trie)
-{
- if (trie == NULL)
- return;
- b_trie_free_node(trie, trie->root);
- free(trie);
-}
-
-
-void
-b_trie_insert(b_trie_t *trie, const char *key, void *data)
-{
- if (data == NULL || key == NULL)
- return;
-
- b_trie_node_t *parent = NULL;
- b_trie_node_t *previous;
- b_trie_node_t *current;
- b_trie_node_t *tmp;
-
- while (1) {
-
- if (trie->root == NULL || (parent != NULL && parent->child == NULL)) {
- current = b_malloc(sizeof(b_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- if (trie->root == NULL)
- trie->root = current;
- else
- parent->child = current;
- parent = current;
- goto clean;
- }
-
- tmp = parent == NULL ? trie->root : parent->child;
- previous = NULL;
-
- while (tmp != NULL && tmp->key != *key) {
- previous = tmp;
- tmp = tmp->next;
- }
-
- parent = tmp;
-
- if (previous == NULL || parent != NULL)
- goto clean;
-
- current = b_malloc(sizeof(b_trie_node_t));
- current->key = *key;
- current->data = NULL;
- current->next = NULL;
- current->child = NULL;
- previous->next = current;
- parent = current;
-
-clean:
- if (*key == '\0') {
- if (parent->data != NULL && trie->free_func != NULL)
- trie->free_func(parent->data);
- parent->data = data;
- break;
- }
- key++;
- }
-}
-
-
-void*
-b_trie_lookup(b_trie_t *trie, const char *key)
-{
- if (trie == NULL || trie->root == NULL || key == NULL)
- return NULL;
-
- b_trie_node_t *parent = trie->root;
- b_trie_node_t *tmp;
- while (1) {
- for (tmp = parent; tmp != NULL; tmp = tmp->next) {
-
- if (tmp->key == *key) {
- if (tmp->key == '\0')
- return tmp->data;
- parent = tmp->child;
- break;
- }
- }
- if (tmp == NULL)
- return NULL;
-
- if (*key == '\0')
- break;
- key++;
- }
- return NULL;
-}
-
-
-static void
-b_trie_size_node(b_trie_node_t *node, unsigned int *count)
-{
- if (node == NULL)
- return;
-
- if (node->key == '\0')
- (*count)++;
-
- b_trie_size_node(node->next, count);
- b_trie_size_node(node->child, count);
-}
-
-
-unsigned int
-b_trie_size(b_trie_t *trie)
-{
- if (trie == NULL)
- return 0;
-
- unsigned int count = 0;
- b_trie_size_node(trie->root, &count);
- return count;
-}
-
-
-static void
-b_trie_foreach_node(b_trie_node_t *node, b_string_t *str, void (*func)(const char *key, void *data))
-{
- if (node == NULL)
- return;
-
- if (node->key == '\0') {
- func(str->str, node->data);
- b_string_free(str, true);
- }
-
- if (node->child != NULL) {
- b_string_t *child = b_string_new();
- child = b_string_append(child, str->str);
- child = b_string_append_c(child, node->key);
- b_trie_foreach_node(node->child, child, func);
- }
-
- if (node->next != NULL)
- b_trie_foreach_node(node->next, str, func);
-
- if (node->child != NULL && node->next == NULL)
- b_string_free(str, true);
-}
-
-
-void
-b_trie_foreach(b_trie_t *trie, void (*func)(const char *key, void *data))
-{
- if (trie->root == NULL)
- return;
-
- b_string_t *str = b_string_new();
- b_trie_foreach_node(trie->root, str, func);
-}
diff --git a/src/utils/utils.h b/src/utils/utils.h
deleted file mode 100644
index dc67497..0000000
--- a/src/utils/utils.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2014-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _UTILS_UTILS_H
-#define _UTILS_UTILS_H
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdarg.h>
-
-#define B_STRING_CHUNK_SIZE 128
-
-typedef void (*b_free_func_t) (void *ptr);
-
-typedef struct _b_slist_t {
- struct _b_slist_t *next;
- void *data;
-} b_slist_t;
-
-typedef struct _b_string_t {
- char *str;
- size_t len;
- size_t allocated_len;
-} b_string_t;
-
-typedef struct _b_trie_node_t {
- char key;
- void *data;
- struct _b_trie_node_t *next, *child;
-} b_trie_node_t;
-
-typedef struct _b_trie_t {
- b_trie_node_t *root;
- b_free_func_t free_func;
-} b_trie_t;
-
-b_slist_t* b_slist_append(b_slist_t *l, void *data);
-void b_slist_free_full(b_slist_t *l, b_free_func_t free_func);
-void b_slist_free(b_slist_t *l);
-unsigned int b_slist_length(b_slist_t *l);
-
-char* b_strdup(const char *s);
-char* b_strndup(const char *s, size_t n);
-char* b_strdup_vprintf(const char *format, va_list ap);
-char* b_strdup_printf(const char *format, ...);
-bool b_str_starts_with(const char *str, const char *prefix);
-bool b_str_ends_with(const char *str, const char *suffix);
-char* b_str_lstrip(char *str);
-char* b_str_rstrip(char *str);
-char* b_str_strip(char *str);
-char** b_str_split(const char *str, char c, unsigned int max_pieces);
-char* b_str_replace(const char *str, const char search, const char *replace);
-void b_strv_free(char **strv);
-char* b_strv_join(const char **strv, const char *separator);
-unsigned int b_strv_length(char **strv);
-
-b_string_t* b_string_new(void);
-char* b_string_free(b_string_t *str, bool free_str);
-b_string_t* b_string_append_len(b_string_t *str, const char *suffix, size_t len);
-b_string_t* b_string_append(b_string_t *str, const char *suffix);
-b_string_t* b_string_append_c(b_string_t *str, char c);
-b_string_t* b_string_append_printf(b_string_t *str, const char *format, ...);
-
-b_trie_t* b_trie_new(b_free_func_t free_func);
-void b_trie_free(b_trie_t *trie);
-void b_trie_insert(b_trie_t *trie, const char *key, void *data);
-void* b_trie_lookup(b_trie_t *trie, const char *key);
-unsigned int b_trie_size(b_trie_t *trie);
-void b_trie_foreach(b_trie_t *trie, void (*func)(const char *key, void *data));
-
-void* b_malloc(size_t size);
-void* b_realloc(void *ptr, size_t size);
-
-#endif /* _UTILS_UTILS_H */
diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c
index 165810d..4f201d1 100644
--- a/tests/check_content_parser.c
+++ b/tests/check_content_parser.c
@@ -17,7 +17,7 @@
#include <string.h>
#include "../src/content-parser.h"
#include "../src/directives.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
static void
@@ -82,6 +82,7 @@ static void
test_content_parse(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# um\n"
"## dois\n"
@@ -107,8 +108,8 @@ test_content_parse(void **state)
"1. chunda\n"
"3. fuuuu\n"
"\n"
- "+ chunda2\n"
- "+ fuuuu2\n"
+ "- chunda2\n"
+ "- fuuuu2\n"
"\n"
"<style>\n"
" chunda\n"
@@ -117,9 +118,17 @@ test_content_parse(void **state)
"guda\n"
"yay\n"
"\n"
- "**bola**\n", &l);
+ "**bola**\n"
+ "-- foo-bar\n"
+ "--- bar\n"
+ "\n"
+ "-- asd\n"
+ "\n"
+ "--- lol\n", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "bola");
assert_string_equal(html,
"<h1 id=\"um\">um</h1>\n"
"<h2 id=\"dois\">dois</h2>\n"
@@ -151,8 +160,13 @@ test_content_parse(void **state)
"</style>\n"
"<p>guda\n"
"yay</p>\n"
- "<p><strong>bola</strong></p>\n");
+ "<p><strong>bola</strong>\n"
+ "&ndash; foo-bar\n"
+ "&mdash; bar</p>\n"
+ "<p>&ndash; asd</p>\n"
+ "<p>&mdash; lol</p>\n");
free(html);
+ free(d);
}
@@ -160,6 +174,7 @@ static void
test_content_parse_crlf(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# um\r\n"
"## dois\r\n"
@@ -195,9 +210,17 @@ test_content_parse_crlf(void **state)
"guda\r\n"
"yay\r\n"
"\r\n"
- "**bola**\r\n", &l);
+ "**bola**\r\n"
+ "-- foo-bar\r\n"
+ "--- bar\r\n"
+ "\r\n"
+ "-- asd\r\n"
+ "\r\n"
+ "--- lol\r\n", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "bola");
assert_string_equal(html,
"<h1 id=\"um\">um</h1>\r\n"
"<h2 id=\"dois\">dois</h2>\r\n"
@@ -229,8 +252,13 @@ test_content_parse_crlf(void **state)
"</style>\r\n"
"<p>guda\r\n"
"yay</p>\r\n"
- "<p><strong>bola</strong></p>\r\n");
+ "<p><strong>bola</strong>\r\n"
+ "&ndash; foo-bar\r\n"
+ "&mdash; bar</p>\r\n"
+ "<p>&ndash; asd</p>\r\n"
+ "<p>&mdash; lol</p>\r\n");
free(html);
+ free(d);
}
@@ -238,6 +266,7 @@ static void
test_content_parse_with_excerpt(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\n"
"\n"
@@ -246,9 +275,11 @@ test_content_parse_with_excerpt(void **state)
"..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
@@ -256,6 +287,8 @@ test_content_parse_with_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
@@ -264,15 +297,18 @@ test_content_parse_with_excerpt(void **state)
"...\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 38);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
"<p>guda\n"
"lol</p>\n");
free(html);
+ free(d);
}
@@ -280,6 +316,7 @@ static void
test_content_parse_with_excerpt_crlf(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\r\n"
"\r\n"
@@ -288,9 +325,11 @@ test_content_parse_with_excerpt_crlf(void **state)
"..\r\n"
"\r\n"
"guda\r\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 40);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\r\n"
"<p>chunda</p>\r\n"
@@ -298,6 +337,8 @@ test_content_parse_with_excerpt_crlf(void **state)
"lol</p>\r\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\r\n"
"\r\n"
@@ -306,26 +347,29 @@ test_content_parse_with_excerpt_crlf(void **state)
"...\r\n"
"\r\n"
"guda\r\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 40);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\r\n"
"<p>chunda</p>\r\n"
"<p>guda\r\n"
"lol</p>\r\n");
free(html);
+ free(d);
}
static void
test_content_parse_header(void **state)
{
- char *html = blogc_content_parse("## bola", NULL);
+ char *html = blogc_content_parse("## bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\n", NULL);
+ html = blogc_content_parse("## bola\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
@@ -334,7 +378,7 @@ test_content_parse_header(void **state)
"\n"
"## bola\n"
"\n"
- "guda\n", NULL);
+ "guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -347,11 +391,11 @@ test_content_parse_header(void **state)
static void
test_content_parse_header_crlf(void **state)
{
- char *html = blogc_content_parse("## bola", NULL);
+ char *html = blogc_content_parse("## bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\n");
free(html);
- html = blogc_content_parse("## bola\r\n", NULL);
+ html = blogc_content_parse("## bola\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<h2 id=\"bola\">bola</h2>\r\n");
free(html);
@@ -360,7 +404,7 @@ test_content_parse_header_crlf(void **state)
"\r\n"
"## bola\r\n"
"\r\n"
- "guda\r\n", NULL);
+ "guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -373,11 +417,11 @@ test_content_parse_header_crlf(void **state)
static void
test_content_parse_html(void **state)
{
- char *html = blogc_content_parse("<div>\n</div>", NULL);
+ char *html = blogc_content_parse("<div>\n</div>", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\n</div>\n");
free(html);
- html = blogc_content_parse("<div>\n</div>\n", NULL);
+ html = blogc_content_parse("<div>\n</div>\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\n</div>\n");
free(html);
@@ -387,7 +431,7 @@ test_content_parse_html(void **state)
"<div>\n"
"</div>\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -400,11 +444,11 @@ test_content_parse_html(void **state)
static void
test_content_parse_html_crlf(void **state)
{
- char *html = blogc_content_parse("<div>\r\n</div>", NULL);
+ char *html = blogc_content_parse("<div>\r\n</div>", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\r\n</div>\r\n");
free(html);
- html = blogc_content_parse("<div>\r\n</div>\r\n", NULL);
+ html = blogc_content_parse("<div>\r\n</div>\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<div>\r\n</div>\r\n");
free(html);
@@ -414,7 +458,7 @@ test_content_parse_html_crlf(void **state)
"<div>\r\n"
"</div>\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -427,14 +471,14 @@ test_content_parse_html_crlf(void **state)
static void
test_content_parse_blockquote(void **state)
{
- char *html = blogc_content_parse("> bola\n> guda", NULL);
+ char *html = blogc_content_parse("> bola\n> guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\n"
"guda</p>\n"
"</blockquote>\n");
free(html);
- html = blogc_content_parse("> bola\n> guda\n", NULL);
+ html = blogc_content_parse("> bola\n> guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\n"
@@ -445,9 +489,22 @@ test_content_parse_blockquote(void **state)
"bola\n"
"\n"
"> bola\n"
+ "\n"
+ "chunda\n", NULL, NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>bola</p>\n"
+ "<blockquote><p>bola</p>\n"
+ "</blockquote>\n"
+ "<p>chunda</p>\n");
+ free(html);
+ html = blogc_content_parse(
+ "bola\n"
+ "\n"
+ "> bola\n"
"> guda\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -462,14 +519,14 @@ test_content_parse_blockquote(void **state)
static void
test_content_parse_blockquote_crlf(void **state)
{
- char *html = blogc_content_parse("> bola\r\n> guda", NULL);
+ char *html = blogc_content_parse("> bola\r\n> guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\r\n"
"guda</p>\r\n"
"</blockquote>\r\n");
free(html);
- html = blogc_content_parse("> bola\r\n> guda\r\n", NULL);
+ html = blogc_content_parse("> bola\r\n> guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<blockquote><p>bola\r\n"
@@ -480,9 +537,22 @@ test_content_parse_blockquote_crlf(void **state)
"bola\r\n"
"\r\n"
"> bola\r\n"
+ "\r\n"
+ "chunda\r\n", NULL, NULL);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<p>bola</p>\r\n"
+ "<blockquote><p>bola</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>chunda</p>\r\n");
+ free(html);
+ html = blogc_content_parse(
+ "bola\r\n"
+ "\r\n"
+ "> bola\r\n"
"> guda\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -497,13 +567,13 @@ test_content_parse_blockquote_crlf(void **state)
static void
test_content_parse_code(void **state)
{
- char *html = blogc_content_parse(" bola\n guda", NULL);
+ char *html = blogc_content_parse(" bola\n guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\n"
"guda</code></pre>\n");
free(html);
- html = blogc_content_parse(" bola\n guda\n", NULL);
+ html = blogc_content_parse(" bola\n guda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\n"
@@ -515,7 +585,7 @@ test_content_parse_code(void **state)
" bola\n"
" guda\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -529,13 +599,13 @@ test_content_parse_code(void **state)
static void
test_content_parse_code_crlf(void **state)
{
- char *html = blogc_content_parse(" bola\r\n guda", NULL);
+ char *html = blogc_content_parse(" bola\r\n guda", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\r\n"
"guda</code></pre>\r\n");
free(html);
- html = blogc_content_parse(" bola\r\n guda\r\n", NULL);
+ html = blogc_content_parse(" bola\r\n guda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<pre><code>bola\r\n"
@@ -547,7 +617,7 @@ test_content_parse_code_crlf(void **state)
" bola\r\n"
" guda\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -561,28 +631,28 @@ test_content_parse_code_crlf(void **state)
static void
test_content_parse_horizontal_rule(void **state)
{
- char *html = blogc_content_parse("bola\nguda\n\n**", NULL);
+ char *html = blogc_content_parse("bola\nguda\n\n**", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n++++", NULL);
+ html = blogc_content_parse("bola\nguda\n\n++++", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n--\n", NULL);
+ html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n****\n", NULL);
+ html = blogc_content_parse("bola\nguda\n\n****\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
@@ -594,7 +664,7 @@ test_content_parse_horizontal_rule(void **state)
"\n"
"**\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -606,7 +676,7 @@ test_content_parse_horizontal_rule(void **state)
"\n"
"----\n"
"\n"
- "chunda\n", NULL);
+ "chunda\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\n"
@@ -619,28 +689,28 @@ test_content_parse_horizontal_rule(void **state)
static void
test_content_parse_horizontal_rule_crlf(void **state)
{
- char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL);
+ char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n++++", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n****\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
@@ -652,7 +722,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
"\r\n"
"**\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -664,7 +734,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
"\r\n"
"----\r\n"
"\r\n"
- "chunda\r\n", NULL);
+ "chunda\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola</p>\r\n"
@@ -682,7 +752,7 @@ test_content_parse_unordered_list(void **state)
"\n"
"* asd\n"
"* qwe\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -697,7 +767,7 @@ test_content_parse_unordered_list(void **state)
"\n"
"* asd\n"
"* qwe\n"
- "* zxc\n", NULL);
+ "* zxc\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -714,7 +784,7 @@ test_content_parse_unordered_list(void **state)
"* qwe\n"
"* zxc\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -734,7 +804,7 @@ test_content_parse_unordered_list(void **state)
"* zxc\n"
" 1234\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -750,7 +820,7 @@ test_content_parse_unordered_list(void **state)
html = blogc_content_parse(
"* asd\n"
"* qwe\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ul>\n"
@@ -770,7 +840,7 @@ test_content_parse_unordered_list_crlf(void **state)
"\r\n"
"* asd\r\n"
"* qwe\r\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -785,7 +855,7 @@ test_content_parse_unordered_list_crlf(void **state)
"\r\n"
"* asd\r\n"
"* qwe\r\n"
- "* zxc\r\n", NULL);
+ "* zxc\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -802,7 +872,7 @@ test_content_parse_unordered_list_crlf(void **state)
"* qwe\r\n"
"* zxc\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -822,7 +892,7 @@ test_content_parse_unordered_list_crlf(void **state)
"* zxc\r\n"
" 1234\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -838,7 +908,7 @@ test_content_parse_unordered_list_crlf(void **state)
html = blogc_content_parse(
"* asd\r\n"
"* qwe\r\n"
- "* zxc", NULL);
+ "* zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ul>\r\n"
@@ -858,7 +928,7 @@ test_content_parse_ordered_list(void **state)
"\n"
"1. asd\n"
"2. qwe\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -873,7 +943,7 @@ test_content_parse_ordered_list(void **state)
"\n"
"1. asd\n"
"2. qwe\n"
- "3. zxc\n", NULL);
+ "3. zxc\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -890,7 +960,7 @@ test_content_parse_ordered_list(void **state)
"2. qwe\n"
"3. zxc\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -910,7 +980,7 @@ test_content_parse_ordered_list(void **state)
"3. zxc\n"
" 1234\n"
"\n"
- "fuuuu\n", NULL);
+ "fuuuu\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\n"
@@ -926,7 +996,7 @@ test_content_parse_ordered_list(void **state)
html = blogc_content_parse(
"1. asd\n"
"2. qwe\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ol>\n"
@@ -946,7 +1016,7 @@ test_content_parse_ordered_list_crlf(void **state)
"\r\n"
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -961,7 +1031,7 @@ test_content_parse_ordered_list_crlf(void **state)
"\r\n"
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc\r\n", NULL);
+ "3. zxc\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -978,7 +1048,7 @@ test_content_parse_ordered_list_crlf(void **state)
"2. qwe\r\n"
"3. zxc\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -998,7 +1068,7 @@ test_content_parse_ordered_list_crlf(void **state)
"3. zxc\r\n"
" 1234\r\n"
"\r\n"
- "fuuuu\r\n", NULL);
+ "fuuuu\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>lol</p>\r\n"
@@ -1014,7 +1084,7 @@ test_content_parse_ordered_list_crlf(void **state)
html = blogc_content_parse(
"1. asd\r\n"
"2. qwe\r\n"
- "3. zxc", NULL);
+ "3. zxc", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<ol>\r\n"
@@ -1037,15 +1107,15 @@ __wrap_blogc_directive_loader(blogc_directive_ctx_t *ctx, blogc_error_t **err)
assert_null(ctx->argument);
else
assert_string_equal(ctx->argument, arg);
- assert_int_equal(b_trie_size(ctx->params), mock_type(unsigned int));
+ assert_int_equal(sb_trie_size(ctx->params), mock_type(unsigned int));
- for (unsigned int i = 0; i < b_trie_size(ctx->params); i++) {
+ for (unsigned int i = 0; i < sb_trie_size(ctx->params); i++) {
const char *key = mock_type(const char*);
const char *value = mock_type(const char*);
- assert_string_equal(b_trie_lookup(ctx->params, key), value);
+ assert_string_equal(sb_trie_lookup(ctx->params, key), value);
}
- return b_strdup("CHUNDA\n");
+ return sb_strdup("CHUNDA\n");
}
@@ -1057,7 +1127,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
char *html = blogc_content_parse(
".. bola::",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1068,7 +1138,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola::\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1079,7 +1149,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola:: ",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1090,7 +1160,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola:: \n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1101,7 +1171,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola::\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1115,7 +1185,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola::\n"
" :asd: qwe",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1129,7 +1199,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola::\n"
" :asd: qwe\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1143,7 +1213,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola::\r\n"
"\t:asd: qwe\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1160,7 +1230,7 @@ test_content_parse_directive(void **state)
".. bola::\n"
"\t\t:asd: qwe\n"
"\t\t:zxc: vbn",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1177,7 +1247,7 @@ test_content_parse_directive(void **state)
".. bola::\n"
" :asd: qwe\n"
" :zxc: vbn\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1194,7 +1264,7 @@ test_content_parse_directive(void **state)
".. bola::\r\n"
" :asd: qwe\r\n"
" :zxc: vbn\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1217,7 +1287,7 @@ test_content_parse_directive(void **state)
" :ert: zxvc\n"
" :qwe: bola\n"
"\n"
- "bola", NULL);
+ "bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1242,7 +1312,7 @@ test_content_parse_directive(void **state)
" :ert: zxvc\r\n"
" :qwe: bola\r\n"
"\r\n"
- "bola", NULL);
+ "bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1261,7 +1331,7 @@ test_content_parse_directive(void **state)
"\n"
".. bola::\n"
"\n"
- ".. bola::", NULL);
+ ".. bola::", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1280,7 +1350,7 @@ test_content_parse_directive(void **state)
"\n"
".. bola:: asd\n"
"\n"
- ".. bola:: asd\n", NULL);
+ ".. bola:: asd\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1299,7 +1369,7 @@ test_content_parse_directive(void **state)
"\r\n"
".. bola::\r\n"
"\r\n"
- ".. bola::\r\n", NULL);
+ ".. bola::\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1321,7 +1391,7 @@ test_content_parse_directive(void **state)
".. bola::\n"
" :asd: qwe\n"
"\n"
- ".. bola::", NULL);
+ ".. bola::", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1343,7 +1413,7 @@ test_content_parse_directive(void **state)
".. bola:: asd\n"
" :asd: qwe\n"
"\n"
- ".. bola:: asd\n", NULL);
+ ".. bola:: asd\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1365,7 +1435,7 @@ test_content_parse_directive(void **state)
".. bola::\n"
" :asd: qwe\n"
"\n"
- ".. bola::\n", NULL);
+ ".. bola::\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1387,7 +1457,7 @@ test_content_parse_directive(void **state)
".. bola::\r\n"
" :asd: qwe\r\n"
"\r\n"
- ".. bola::\r\n", NULL);
+ ".. bola::\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1412,7 +1482,7 @@ test_content_parse_directive(void **state)
" :asd: qwe\n"
"\n"
".. bola::\n"
- " :asd: zxc\n", NULL);
+ " :asd: zxc\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1437,7 +1507,7 @@ test_content_parse_directive(void **state)
" :asd: qwe\r\n"
"\r\n"
".. bola::\r\n"
- " :asd: zxc\r\n", NULL);
+ " :asd: zxc\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1468,7 +1538,7 @@ test_content_parse_directive(void **state)
"\n"
".. bola::\n"
" :asd: qwe\n"
- " :qwe: 456", NULL);
+ " :qwe: 456", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1499,7 +1569,7 @@ test_content_parse_directive(void **state)
"\n"
".. bola:: asd\n"
" :asd: qwe\n"
- " :qwe: 456\n", NULL);
+ " :qwe: 456\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1530,7 +1600,7 @@ test_content_parse_directive(void **state)
"\n"
".. bola::\n"
" :asd: qwe\n"
- " :qwe: 456\n", NULL);
+ " :qwe: 456\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1561,7 +1631,7 @@ test_content_parse_directive(void **state)
"\r\n"
".. bola::\r\n"
" :asd: qwe\r\n"
- " :qwe: 456\r\n", NULL);
+ " :qwe: 456\r\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1574,7 +1644,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola:: chunda",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1585,7 +1655,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola:: chunda\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1596,7 +1666,7 @@ test_content_parse_directive(void **state)
will_return(__wrap_blogc_directive_loader, 0);
html = blogc_content_parse(
".. bola:: chunda\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1610,7 +1680,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola:: chunda\n"
" :asd: qwe",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1624,7 +1694,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola:: chunda\n"
" :asd: qwe\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1638,7 +1708,7 @@ test_content_parse_directive(void **state)
html = blogc_content_parse(
".. bola:: chunda\r\n"
" :asd: qwe\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1655,7 +1725,7 @@ test_content_parse_directive(void **state)
".. bola:: chunda\n"
" :asd: qwe\n"
" :zxc: vbn",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1672,7 +1742,7 @@ test_content_parse_directive(void **state)
".. bola:: chunda\n"
" :asd: qwe\n"
" :zxc: vbn\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1689,7 +1759,7 @@ test_content_parse_directive(void **state)
".. bola:: chunda\r\n"
" :asd: qwe\r\n"
" :zxc: vbn\r\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"CHUNDA\n");
@@ -1712,7 +1782,7 @@ test_content_parse_directive(void **state)
" :ert: zxvc\n"
" :qwe: bola\n"
"\n"
- "bola", NULL);
+ "bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\n"
@@ -1737,7 +1807,7 @@ test_content_parse_directive(void **state)
" :ert: zxvc\r\n"
" :qwe: bola\r\n"
"\r\n"
- "bola", NULL);
+ "bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1773,7 +1843,7 @@ test_content_parse_directive(void **state)
" :asd: qwe\r\n"
" :ert: zxvc\r\n"
"\r\n"
- "bola", NULL);
+ "bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<h1 id=\"foo\">foo</h1>\r\n"
@@ -1785,9 +1855,176 @@ test_content_parse_directive(void **state)
static void
+test_content_parse_description(void **state)
+{
+ char *d = NULL;
+ char *html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "bar", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "qwe\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<p>qwe\n"
+ "bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "> qwe\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<blockquote><p>qwe</p>\n"
+ "</blockquote>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\n"
+ "\n"
+ "> qwe\n"
+ "> zxc\n"
+ "\n"
+ "bar\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\n"
+ "<blockquote><p>qwe\n"
+ "zxc</p>\n"
+ "</blockquote>\n"
+ "<p>bar</p>\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+}
+
+
+static void
+test_content_parse_description_crlf(void **state)
+{
+ char *d = NULL;
+ char *html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "bar", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "bar");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "qwe\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<p>qwe\r\n"
+ "bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "> qwe\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<blockquote><p>qwe</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+ d = NULL;
+ html = blogc_content_parse(
+ "# foo\r\n"
+ "\r\n"
+ "> qwe\r\n"
+ "> zxc\r\n"
+ "\r\n"
+ "bar\r\n", NULL, &d);
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<h1 id=\"foo\">foo</h1>\r\n"
+ "<blockquote><p>qwe\r\n"
+ "zxc</p>\r\n"
+ "</blockquote>\r\n"
+ "<p>bar</p>\r\n");
+ assert_non_null(d);
+ assert_string_equal(d, "qwe");
+ free(html);
+ free(d);
+}
+
+
+static void
test_content_parse_invalid_excerpt(void **state)
{
size_t l = 0;
+ char *d = NULL;
char *html = blogc_content_parse(
"# test\n"
"\n"
@@ -1795,9 +2032,11 @@ test_content_parse_invalid_excerpt(void **state)
"..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda\n"
@@ -1806,6 +2045,8 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
@@ -1813,9 +2054,11 @@ test_content_parse_invalid_excerpt(void **state)
"\n"
"...\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
@@ -1824,15 +2067,19 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
"chunda..\n"
"\n"
"guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda..");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda..</p>\n"
@@ -1840,21 +2087,26 @@ test_content_parse_invalid_excerpt(void **state)
"lol</p>\n");
free(html);
l = 0;
+ free(d);
+ d = NULL;
html = blogc_content_parse(
"# test\n"
"\n"
"chunda\n"
"\n"
"...guda\n"
- "lol", &l);
+ "lol", &l, &d);
assert_non_null(html);
assert_int_equal(l, 0);
+ assert_non_null(d);
+ assert_string_equal(d, "chunda");
assert_string_equal(html,
"<h1 id=\"test\">test</h1>\n"
"<p>chunda</p>\n"
"<p>...guda\n"
"lol</p>\n");
free(html);
+ free(d);
}
@@ -1864,7 +2116,7 @@ test_content_parse_invalid_header(void **state)
char *html = blogc_content_parse(
"asd\n"
"\n"
- "##bola\n", NULL);
+ "##bola\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>asd</p>\n"
@@ -1881,7 +2133,7 @@ test_content_parse_invalid_header_empty(void **state)
"\n"
"##\n"
"\n"
- "qwe\n", NULL);
+ "qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>asd</p>\n"
@@ -1898,7 +2150,7 @@ test_content_parse_invalid_blockquote(void **state)
char *html = blogc_content_parse(
"> asd\n"
"> bola\n"
- "> foo\n", NULL);
+ "> foo\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>&gt; asd\n"
@@ -1907,7 +2159,7 @@ test_content_parse_invalid_blockquote(void **state)
free(html);
html = blogc_content_parse(
"> asd\n"
- "> bola", NULL);
+ "> bola", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>&gt; asd\n"
@@ -1922,7 +2174,7 @@ test_content_parse_invalid_code(void **state)
char *html = blogc_content_parse(
" asd\n"
" bola\n"
- " foo\n", NULL);
+ " foo\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p> asd\n"
@@ -1932,7 +2184,7 @@ test_content_parse_invalid_code(void **state)
html = blogc_content_parse(
" asd\n"
" bola\n"
- " foo", NULL);
+ " foo", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p> asd\n"
@@ -1946,11 +2198,11 @@ static void
test_content_parse_invalid_horizontal_rule(void **state)
{
// this generates invalid html, but...
- char *html = blogc_content_parse("** asd", NULL);
+ char *html = blogc_content_parse("** asd", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p><strong> asd</p>\n");
free(html);
- html = blogc_content_parse("** asd\n", NULL);
+ html = blogc_content_parse("** asd\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p><strong> asd</p>\n");
free(html);
@@ -1963,7 +2215,7 @@ test_content_parse_invalid_unordered_list(void **state)
// more invalid html
char *html = blogc_content_parse(
"* asd\n"
- "1. qwe", NULL);
+ "1. qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1972,7 +2224,7 @@ test_content_parse_invalid_unordered_list(void **state)
html = blogc_content_parse(
"* asd\n"
"1. qwe\n"
- "\n", NULL);
+ "\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1980,7 +2232,7 @@ test_content_parse_invalid_unordered_list(void **state)
free(html);
html = blogc_content_parse(
"* asd\n"
- "1. qwe\n", NULL);
+ "1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -1989,7 +2241,7 @@ test_content_parse_invalid_unordered_list(void **state)
free(html);
html = blogc_content_parse(
"* asd\n"
- "1. qwe\n", NULL);
+ "1. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p><em> asd\n"
@@ -2002,7 +2254,7 @@ test_content_parse_invalid_unordered_list(void **state)
"* asd\n"
"1. qwe\n"
"\n"
- "poi\n", NULL);
+ "poi\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>chunda</p>\n"
@@ -2019,7 +2271,7 @@ test_content_parse_invalid_ordered_list(void **state)
// more invalid html
char *html = blogc_content_parse(
"1. asd\n"
- "* qwe", NULL);
+ "* qwe", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -2028,7 +2280,7 @@ test_content_parse_invalid_ordered_list(void **state)
html = blogc_content_parse(
"1. asd\n"
"* qwe\n"
- "\n", NULL);
+ "\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -2036,7 +2288,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1. asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -2045,7 +2297,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1. asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1. asd\n"
@@ -2058,7 +2310,7 @@ test_content_parse_invalid_ordered_list(void **state)
"1. asd\n"
"* qwe\n"
"\n"
- "poi\n", NULL);
+ "poi\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>chunda</p>\n"
@@ -2068,7 +2320,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1 asd\n"
- "* qwe\n", NULL);
+ "* qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1 asd\n"
@@ -2076,7 +2328,7 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"a. asd\n"
- "2. qwe\n", NULL);
+ "2. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>a. asd\n"
@@ -2084,18 +2336,18 @@ test_content_parse_invalid_ordered_list(void **state)
free(html);
html = blogc_content_parse(
"1.\nasd\n"
- "2. qwe\n", NULL);
+ "2. qwe\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>1.\n"
"asd\n"
"2. qwe</p>\n");
free(html);
- html = blogc_content_parse("1.\n", NULL);
+ html = blogc_content_parse("1.\n", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p>1.</p>\n");
free(html);
- html = blogc_content_parse("1 ", NULL);
+ html = blogc_content_parse("1 ", NULL, NULL);
assert_non_null(html);
assert_string_equal(html, "<p>1 </p>\n");
free(html);
@@ -2107,7 +2359,7 @@ test_content_parse_invalid_directive(void **state)
{
char *html = blogc_content_parse(
".. ",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. </p>\n");
@@ -2115,7 +2367,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. \n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. </p>\n");
@@ -2123,7 +2375,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. ",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. <br /></p>\n");
@@ -2131,7 +2383,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. \n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. <br /></p>\n");
@@ -2139,7 +2391,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. a",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. a</p>\n");
@@ -2147,7 +2399,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. a\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. a</p>\n");
@@ -2155,7 +2407,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd</p>\n");
@@ -2163,7 +2415,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd</p>\n");
@@ -2171,7 +2423,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd:",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd:</p>\n");
@@ -2179,7 +2431,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd:\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd:</p>\n");
@@ -2188,7 +2440,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2198,7 +2450,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2208,7 +2460,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :a",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2218,7 +2470,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :a\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2228,7 +2480,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2238,7 +2490,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2248,7 +2500,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as:",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2258,7 +2510,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as:\n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2268,7 +2520,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as: ",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2278,7 +2530,7 @@ test_content_parse_invalid_directive(void **state)
html = blogc_content_parse(
".. asd::\n"
" :as: \n",
- NULL);
+ NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>.. asd::\n"
@@ -2304,6 +2556,10 @@ test_content_parse_inline(void **state)
assert_non_null(html);
assert_string_equal(html, "<em>bola</em>");
free(html);
+ html = blogc_content_parse_inline("bola!");
+ assert_non_null(html);
+ assert_string_equal(html, "bola!");
+ free(html);
}
@@ -2419,10 +2675,22 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
free(html);
+ html = blogc_content_parse_inline("[bola!](http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/\">bola!</a>\n");
+ free(html);
html = blogc_content_parse_inline("[bola]\n(http://example.org/)\n");
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
free(html);
+ html = blogc_content_parse_inline("[bola]\r\n(http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
+ free(html);
+ html = blogc_content_parse_inline("[bola] \r\n (http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<a href=\"http://example.org/\">bola</a>\n");
+ free(html);
html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n");
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\">bo\nla</a>\n");
@@ -2435,6 +2703,16 @@ test_content_parse_inline_link(void **state)
assert_non_null(html);
assert_string_equal(html, "<a href=\"http://example.org/\"><code>bola(2)[3]**!\\</code></a>\n");
free(html);
+ html = blogc_content_parse_inline("test suite!)\n"
+ "depends on [cmocka](http://cmocka.org/), though.\n");
+ assert_non_null(html);
+ assert_string_equal(html, "test suite!)\n"
+ "depends on <a href=\"http://cmocka.org/\">cmocka</a>, though.\n");
+ free(html);
+ html = blogc_content_parse_inline("asd [bola]chunda(1234)");
+ assert_non_null(html);
+ assert_string_equal(html, "asd [bola]chunda(1234)");
+ free(html);
// "invalid"
html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n");
assert_non_null(html);
@@ -2516,6 +2794,42 @@ test_content_parse_inline_image(void **state)
assert_non_null(html);
assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n");
free(html);
+ html = blogc_content_parse_inline("![bola]\r\n(http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n");
+ free(html);
+ html = blogc_content_parse_inline("![bola] \r\n (http://example.org/)\n");
+ assert_non_null(html);
+ assert_string_equal(html, "<img src=\"http://example.org/\" alt=\"bola\">\n");
+ free(html);
+ html = blogc_content_parse_inline(
+ "[![This is the image alt text](picture.jpg)](https://blogc.rgm.io)");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" "
+ "alt=\"This is the image alt text\"></a>");
+ free(html);
+ html = blogc_content_parse_inline(
+ "[![This is the image alt text]\n"
+ "(picture.jpg)](https://blogc.rgm.io)");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" "
+ "alt=\"This is the image alt text\"></a>");
+ free(html);
+ html = blogc_content_parse_inline(
+ "[![This is the image alt text]\n"
+ "(picture.jpg)]\n"
+ "(https://blogc.rgm.io)");
+ assert_non_null(html);
+ assert_string_equal(html,
+ "<a href=\"https://blogc.rgm.io\"><img src=\"picture.jpg\" "
+ "alt=\"This is the image alt text\"></a>");
+ free(html);
+ html = blogc_content_parse_inline("asd ![bola]chunda(1234)");
+ assert_non_null(html);
+ assert_string_equal(html, "asd ![bola]chunda(1234)");
+ free(html);
// "invalid"
html = blogc_content_parse_inline("![bo\nla](http://example.org/)\n");
assert_non_null(html);
@@ -2613,6 +2927,36 @@ test_content_parse_inline_line_break_crlf(void **state)
}
+static void
+test_content_parse_inline_endash_emdash(void **state)
+{
+ char *html = blogc_content_parse_inline("foo -- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo &ndash; bar");
+ free(html);
+ html = blogc_content_parse_inline("foo --- bar");
+ assert_non_null(html);
+ assert_string_equal(html, "foo &mdash; bar");
+ free(html);
+ html = blogc_content_parse_inline("`foo -- bar`");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>foo -- bar</code>");
+ free(html);
+ html = blogc_content_parse_inline("`foo --- bar`");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>foo --- bar</code>");
+ free(html);
+ html = blogc_content_parse_inline("``foo -- bar``");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>foo -- bar</code>");
+ free(html);
+ html = blogc_content_parse_inline("``foo --- bar``");
+ assert_non_null(html);
+ assert_string_equal(html, "<code>foo --- bar</code>");
+ free(html);
+}
+
+
int
main(void)
{
@@ -2639,6 +2983,8 @@ main(void)
unit_test(test_content_parse_ordered_list),
unit_test(test_content_parse_ordered_list_crlf),
unit_test(test_content_parse_directive),
+ unit_test(test_content_parse_description),
+ unit_test(test_content_parse_description_crlf),
unit_test(test_content_parse_invalid_excerpt),
unit_test(test_content_parse_invalid_header),
unit_test(test_content_parse_invalid_header_empty),
@@ -2657,6 +3003,7 @@ main(void)
unit_test(test_content_parse_inline_image),
unit_test(test_content_parse_inline_line_break),
unit_test(test_content_parse_inline_line_break_crlf),
+ unit_test(test_content_parse_inline_endash_emdash),
};
return run_tests(tests);
}
diff --git a/tests/check_error.c b/tests/check_error.c
index d3af9c0..8818b00 100644
--- a/tests/check_error.c
+++ b/tests/check_error.c
@@ -16,7 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
static void
diff --git a/tests/check_loader.c b/tests/check_loader.c
index ac8bdb3..4a5dc32 100644
--- a/tests/check_loader.c
+++ b/tests/check_loader.c
@@ -18,7 +18,7 @@
#include <stdio.h>
#include "../src/template-parser.h"
#include "../src/loader.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
static void
@@ -80,11 +80,11 @@ test_template_parse_from_file(void **state)
{
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola");
- will_return(__wrap_blogc_file_get_contents, b_strdup("{{ BOLA }}\n"));
- b_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n"));
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_non_null(l);
- assert_int_equal(b_slist_length(l), 2);
+ assert_int_equal(sb_slist_length(l), 2);
blogc_template_free_stmts(l);
}
@@ -95,7 +95,7 @@ test_template_parse_from_file_null(void **state)
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola");
will_return(__wrap_blogc_file_get_contents, NULL);
- b_slist_t *l = blogc_template_parse_from_file("bola", &err);
+ sb_slist_t *l = blogc_template_parse_from_file("bola", &err);
assert_null(err);
assert_null(l);
}
@@ -106,20 +106,21 @@ test_source_parse_from_file(void **state)
{
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
- b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_trie_size(t), 5);
- assert_string_equal(b_trie_lookup(t, "ASD"), "123");
- assert_string_equal(b_trie_lookup(t, "FILENAME"), "bola");
- assert_string_equal(b_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola");
- b_trie_free(t);
+ assert_int_equal(sb_trie_size(t), 6);
+ assert_string_equal(sb_trie_lookup(t, "ASD"), "123");
+ assert_string_equal(sb_trie_lookup(t, "FILENAME"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "EXCERPT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "CONTENT"), "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola");
+ assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola");
+ sb_trie_free(t);
}
@@ -129,7 +130,7 @@ test_source_parse_from_file_null(void **state)
blogc_error_t *err = NULL;
will_return(__wrap_blogc_file_get_contents, "bola.txt");
will_return(__wrap_blogc_file_get_contents, NULL);
- b_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
+ sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err);
assert_null(err);
assert_null(t);
}
@@ -139,41 +140,41 @@ static void
test_source_parse_from_files(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 4);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 4);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -181,45 +182,45 @@ static void
test_source_parse_from_files_filter_by_tag(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: bola, chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_TAG", b_strdup("chunda"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 5);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 5);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -227,77 +228,77 @@ static void
test_source_parse_from_files_filter_by_page(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -305,78 +306,78 @@ static void
test_source_parse_from_files_filter_by_page2(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("3"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("3"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 11);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola6");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "3");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "3");
- assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "4");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola6");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2006-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "3");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "4");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -384,77 +385,77 @@ static void
test_source_parse_from_files_filter_by_page3(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -462,84 +463,84 @@ static void
test_source_parse_from_files_filter_by_page_and_tag(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"TAGS: chunda bola\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"TAGS: bola\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"TAGS: chunda\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"TAGS: yay chunda\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_TAG", b_strdup("chunda"));
- b_trie_insert(c, "FILTER_PAGE", b_strdup("2"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_TAG", sb_strdup("chunda"));
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("2"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 11);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola5");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola7");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_TAG"), "chunda");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "PREVIOUS_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "2");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 11);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola5");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola7");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2005-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2007-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_TAG"), "chunda");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "PREVIOUS_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "2");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -547,77 +548,77 @@ static void
test_source_parse_from_files_filter_by_page_invalid(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("-1"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("-1"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 2); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 10);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola2");
- assert_string_equal(b_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
- assert_string_equal(b_trie_lookup(c, "FILTER_PAGE"), "-1");
- assert_string_equal(b_trie_lookup(c, "FILTER_PER_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "CURRENT_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "NEXT_PAGE"), "2");
- assert_string_equal(b_trie_lookup(c, "FIRST_PAGE"), "1");
- assert_string_equal(b_trie_lookup(c, "LAST_PAGE"), "4");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 2); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 10);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola2");
+ assert_string_equal(sb_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2002-02-03 04:05:06");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PAGE"), "-1");
+ assert_string_equal(sb_trie_lookup(c, "FILTER_PER_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "CURRENT_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "NEXT_PAGE"), "2");
+ assert_string_equal(sb_trie_lookup(c, "FIRST_PAGE"), "1");
+ assert_string_equal(sb_trie_lookup(c, "LAST_PAGE"), "4");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -625,64 +626,64 @@ static void
test_source_parse_from_files_filter_by_page_invalid2(void **state)
{
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"DATE: 2001-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola4.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7891\n"
"DATE: 2004-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola5.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7892\n"
"DATE: 2005-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola6.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7893\n"
"DATE: 2006-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola7.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 7894\n"
"DATE: 2007-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- s = b_slist_append(s, b_strdup("bola4.txt"));
- s = b_slist_append(s, b_strdup("bola5.txt"));
- s = b_slist_append(s, b_strdup("bola6.txt"));
- s = b_slist_append(s, b_strdup("bola7.txt"));
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "FILTER_PAGE", b_strdup("5"));
- b_trie_insert(c, "FILTER_PER_PAGE", b_strdup("2"));
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ s = sb_slist_append(s, sb_strdup("bola4.txt"));
+ s = sb_slist_append(s, sb_strdup("bola5.txt"));
+ s = sb_slist_append(s, sb_strdup("bola6.txt"));
+ s = sb_slist_append(s, sb_strdup("bola7.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "FILTER_PAGE", sb_strdup("5"));
+ sb_trie_insert(c, "FILTER_PER_PAGE", sb_strdup("2"));
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- b_trie_free(c);
- b_slist_free_full(s, free);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
}
@@ -695,39 +696,39 @@ test_source_parse_from_files_without_all_dates(void **state)
"file, but not for all source files. This means that you may get wrong "
"values for 'DATE_FIRST' and 'DATE_LAST' variables.\n");
will_return(__wrap_blogc_file_get_contents, "bola1.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 123\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola2.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 456\n"
"DATE: 2002-02-03 04:05:06\n"
"--------\n"
"bola"));
will_return(__wrap_blogc_file_get_contents, "bola3.txt");
- will_return(__wrap_blogc_file_get_contents, b_strdup(
+ will_return(__wrap_blogc_file_get_contents, sb_strdup(
"ASD: 789\n"
"DATE: 2003-02-03 04:05:06\n"
"--------\n"
"bola"));
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_strdup("bola1.txt"));
- s = b_slist_append(s, b_strdup("bola2.txt"));
- s = b_slist_append(s, b_strdup("bola3.txt"));
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_strdup("bola1.txt"));
+ s = sb_slist_append(s, sb_strdup("bola2.txt"));
+ s = sb_slist_append(s, sb_strdup("bola3.txt"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_non_null(t);
- assert_int_equal(b_slist_length(t), 3); // it is enough, no need to look at the items
- assert_int_equal(b_trie_size(c), 3);
- assert_string_equal(b_trie_lookup(c, "FILENAME_FIRST"), "bola1");
- assert_string_equal(b_trie_lookup(c, "FILENAME_LAST"), "bola3");
- assert_string_equal(b_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 3); // it is enough, no need to look at the items
+ assert_int_equal(sb_trie_size(c), 3);
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_FIRST"), "bola1");
+ assert_string_equal(sb_trie_lookup(c, "FILENAME_LAST"), "bola3");
+ assert_string_equal(sb_trie_lookup(c, "DATE_LAST"), "2003-02-03 04:05:06");
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
@@ -735,16 +736,16 @@ static void
test_source_parse_from_files_null(void **state)
{
blogc_error_t *err = NULL;
- b_slist_t *s = NULL;
- b_trie_t *c = b_trie_new(free);
- b_slist_t *t = blogc_source_parse_from_files(c, s, &err);
+ sb_slist_t *s = NULL;
+ sb_trie_t *c = sb_trie_new(free);
+ sb_slist_t *t = blogc_source_parse_from_files(c, s, &err);
assert_null(err);
assert_null(t);
- assert_int_equal(b_slist_length(t), 0);
- assert_int_equal(b_trie_size(c), 0);
- b_trie_free(c);
- b_slist_free_full(s, free);
- b_slist_free_full(t, (b_free_func_t) b_trie_free);
+ assert_int_equal(sb_slist_length(t), 0);
+ assert_int_equal(sb_trie_size(c), 0);
+ sb_trie_free(c);
+ sb_slist_free_full(s, free);
+ sb_slist_free_full(t, (sb_free_func_t) sb_trie_free);
}
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index d6bc947..13e7309 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -19,10 +19,10 @@
#include "../src/renderer.h"
#include "../src/source-parser.h"
#include "../src/template-parser.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
-static b_slist_t*
+static sb_slist_t*
create_sources(unsigned int count)
{
const char *s[] = {
@@ -47,12 +47,12 @@ create_sources(unsigned int count)
};
assert_false(count > 3);
blogc_error_t *err = NULL;
- b_slist_t *l = NULL;
+ sb_slist_t *l = NULL;
for (unsigned int i = 0; i < count; i++) {
- l = b_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
+ l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err));
assert_null(err);
}
- assert_int_equal(b_slist_length(l), count);
+ assert_int_equal(sb_slist_length(l), count);
return l;
}
@@ -79,10 +79,10 @@ test_render_entry(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% foreach TAGS_ASD %}yay{% endforeach %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -104,7 +104,7 @@ test_render_entry(void **state)
"lol foo haha lol bar haha lol baz haha \n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -126,10 +126,10 @@ test_render_listing(void **state)
"{% foreach TAGS_ASD %}yay{% endforeach %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(3);
+ sb_slist_t *s = create_sources(3);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, true);
assert_string_equal(out,
@@ -153,7 +153,7 @@ test_render_listing(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -174,7 +174,7 @@ test_render_listing_empty(void **state)
"{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
char *out = blogc_render(l, NULL, NULL, true);
@@ -201,10 +201,10 @@ test_render_ifdef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -212,7 +212,7 @@ test_render_ifdef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -230,10 +230,10 @@ test_render_ifdef2(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -243,7 +243,7 @@ test_render_ifdef2(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -261,10 +261,10 @@ test_render_ifdef3(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -276,7 +276,7 @@ test_render_ifdef3(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -294,10 +294,10 @@ test_render_ifndef(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -309,7 +309,7 @@ test_render_ifndef(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -328,10 +328,10 @@ test_render_if_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -344,7 +344,7 @@ test_render_if_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -363,10 +363,10 @@ test_render_if_neq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -379,7 +379,7 @@ test_render_if_neq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -398,10 +398,10 @@ test_render_if_lt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -414,7 +414,7 @@ test_render_if_lt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -433,10 +433,10 @@ test_render_if_gt(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -449,7 +449,7 @@ test_render_if_gt(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -470,10 +470,10 @@ test_render_if_lt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -488,7 +488,7 @@ test_render_if_lt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -509,10 +509,10 @@ test_render_if_gt_eq(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -527,7 +527,7 @@ test_render_if_gt_eq(void **state)
"\n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -540,10 +540,10 @@ test_render_foreach(void **state)
"{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -551,7 +551,7 @@ test_render_foreach(void **state)
" foo bar baz \n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -565,10 +565,10 @@ test_render_foreach_if(void **state)
"{% endif %} {% endforeach %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
char *out = blogc_render(l, s, NULL, false);
assert_string_equal(out,
@@ -576,7 +576,7 @@ test_render_foreach_if(void **state)
" bar \n"
"\n");
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -596,21 +596,21 @@ test_render_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}lol{% endif %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "GUDA", b_strdup("asd"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("asd"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"bola\n"
"\n"
"lol\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -629,14 +629,14 @@ test_render_prefer_local_variable(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
- b_trie_insert(c, "GUDA", b_strdup("hehe"));
- b_trie_insert(c, "LOL", b_strdup("hmm"));
+ sb_trie_t *c = sb_trie_new(free);
+ sb_trie_insert(c, "GUDA", sb_strdup("hehe"));
+ sb_trie_insert(c, "LOL", sb_strdup("hmm"));
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -647,9 +647,9 @@ test_render_prefer_local_variable(void **state)
"\n"
"\n"
"\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -665,12 +665,12 @@ test_render_respect_variable_scope(void **state)
"{% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = create_sources(1);
+ sb_slist_t *s = create_sources(1);
assert_non_null(s);
- b_trie_t *c = b_trie_new(free);
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
@@ -679,9 +679,9 @@ test_render_respect_variable_scope(void **state)
"\n"
"asd\n"
"\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -697,22 +697,22 @@ test_render_ifcount_bug(void **state)
"{% endif %}\n"
"{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ sb_slist_t *l = blogc_template_parse(str, strlen(str), &err);
assert_non_null(l);
assert_null(err);
- b_slist_t *s = NULL;
- s = b_slist_append(s, b_trie_new(free));
- b_trie_insert(s->data, "TITLE", b_strdup("bola"));
- b_trie_t *c = b_trie_new(free);
+ sb_slist_t *s = NULL;
+ s = sb_slist_append(s, sb_trie_new(free));
+ sb_trie_insert(s->data, "TITLE", sb_strdup("bola"));
+ sb_trie_t *c = sb_trie_new(free);
char *out = blogc_render(l, s, c, false);
assert_string_equal(out,
"\n"
"<h3>bola</h3>\n"
"\n"
"\n");
- b_trie_free(c);
+ sb_trie_free(c);
blogc_template_free_stmts(l);
- b_slist_free_full(s, (b_free_func_t) b_trie_free);
+ sb_slist_free_full(s, (sb_free_func_t) sb_trie_free);
free(out);
}
@@ -720,112 +720,112 @@ test_render_ifcount_bug(void **state)
static void
test_get_variable(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_get_variable_only_local(void **state)
{
- b_trie_t *g = NULL;
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = NULL;
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
assert_string_equal(blogc_get_variable("NAME", g, l), "chunda");
assert_string_equal(blogc_get_variable("TITLE", g, l), "chunda2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(l);
+ sb_trie_free(l);
}
static void
test_get_variable_only_global(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = NULL;
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = NULL;
assert_string_equal(blogc_get_variable("NAME", g, l), "bola");
assert_string_equal(blogc_get_variable("TITLE", g, l), "bola2");
assert_null(blogc_get_variable("BOLA", g, l));
- b_trie_free(g);
+ sb_trie_free(g);
}
static void
test_format_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "DATE_FORMAT", b_strdup("%R"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE_FORMAT", sb_strdup("%R"));
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03:04");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_with_global_format(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%H -- %M"));
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%H -- %M"));
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "03 -- 04");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_format(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date("2015-01-02 03:04:05", g, l);
assert_string_equal(date, "2015-01-02 03:04:05");
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_date_without_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_t *l = b_trie_new(free);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_t *l = sb_trie_new(free);
char *date = blogc_format_date(NULL, g, l);
assert_null(date);
free(date);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "NAME", b_strdup("bola"));
- b_trie_insert(g, "TITLE", b_strdup("bola2"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "NAME", b_strdup("chunda"));
- b_trie_insert(l, "TITLE", b_strdup("chunda2"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "NAME", sb_strdup("bola"));
+ sb_trie_insert(g, "TITLE", sb_strdup("bola2"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "NAME", sb_strdup("chunda"));
+ sb_trie_insert(l, "TITLE", sb_strdup("chunda2"));
char *tmp = blogc_format_variable("NAME", g, l, NULL);
assert_string_equal(tmp, "chunda");
free(tmp);
@@ -833,37 +833,37 @@ test_format_variable(void **state)
assert_string_equal(tmp, "chunda2");
free(tmp);
assert_null(blogc_format_variable("BOLA", g, l, NULL));
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_with_date(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "DATE", b_strdup("2010-11-12 13:14:15"));
- b_trie_insert(g, "DATE_FORMAT", b_strdup("%R"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "DATE", b_strdup("2011-12-13 14:15:16"));
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "DATE", sb_strdup("2010-11-12 13:14:15"));
+ sb_trie_insert(g, "DATE_FORMAT", sb_strdup("%R"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "DATE", sb_strdup("2011-12-13 14:15:16"));
char *tmp = blogc_format_variable("DATE_FORMATTED", g, l, NULL);
assert_string_equal(tmp, "14:15");
free(tmp);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_format_variable_foreach(void **state)
{
- b_slist_t *l = NULL;
- l = b_slist_append(l, b_strdup("asd"));
- l = b_slist_append(l, b_strdup("qwe"));
+ sb_slist_t *l = NULL;
+ l = sb_slist_append(l, sb_strdup("asd"));
+ l = sb_slist_append(l, sb_strdup("qwe"));
char *tmp = blogc_format_variable("FOREACH_ITEM", NULL, NULL, l->next);
assert_string_equal(tmp, "qwe");
free(tmp);
- b_slist_free_full(l, free);
+ sb_slist_free_full(l, free);
}
@@ -877,31 +877,31 @@ test_format_variable_foreach_empty(void **state)
static void
test_split_list_variable(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "TAGS", b_strdup("asd lol hehe"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "TAGS", b_strdup("asd lol XD"));
- b_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
assert_string_equal(tmp->data, "asd");
assert_string_equal(tmp->next->data, "lol");
assert_string_equal(tmp->next->next->data, "XD");
- b_slist_free_full(tmp, free);
- b_trie_free(g);
- b_trie_free(l);
+ sb_slist_free_full(tmp, free);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
static void
test_split_list_variable_not_found(void **state)
{
- b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "TAGS", b_strdup("asd lol hehe"));
- b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "TAGS", b_strdup("asd lol XD"));
- b_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
+ sb_trie_t *g = sb_trie_new(free);
+ sb_trie_insert(g, "TAGS", sb_strdup("asd lol hehe"));
+ sb_trie_t *l = sb_trie_new(free);
+ sb_trie_insert(l, "TAGS", sb_strdup("asd lol XD"));
+ sb_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
assert_null(tmp);
- b_trie_free(g);
- b_trie_free(l);
+ sb_trie_free(g);
+ sb_trie_free(l);
}
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
index 8d6c039..d94dc70 100644
--- a/tests/check_source_parser.c
+++ b/tests/check_source_parser.c
@@ -17,7 +17,7 @@
#include <string.h>
#include "../src/source-parser.h"
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
static void
@@ -31,23 +31,24 @@ test_source_parse(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- b_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -62,23 +63,24 @@ test_source_parse_crlf(void **state)
"\r\n"
"bola\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\r\n"
"<p>bola</p>\r\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\r\n"
"\r\n"
"bola\r\n");
- b_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -95,23 +97,24 @@ test_source_parse_with_spaces(void **state)
"\n"
"bola\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "chunda");
- assert_string_equal(b_trie_lookup(source, "BOLA"), "guda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "chunda");
+ assert_string_equal(sb_trie_lookup(source, "BOLA"), "guda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n");
- b_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
}
@@ -131,21 +134,21 @@ test_source_parse_with_excerpt(void **state)
"guda\n"
"yay";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(source);
- assert_int_equal(b_trie_size(source), 5);
- assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd");
- assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda");
- assert_string_equal(b_trie_lookup(source, "EXCERPT"),
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n");
- assert_string_equal(b_trie_lookup(source, "CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
"<h1 id=\"this-is-a-test\">This is a test</h1>\n"
"<p>bola</p>\n"
"<p>guda\n"
"yay</p>\n");
- assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"),
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
"# This is a test\n"
"\n"
"bola\n"
@@ -154,7 +157,41 @@ test_source_parse_with_excerpt(void **state)
"\n"
"guda\n"
"yay");
- b_trie_free(source);
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola");
+ sb_trie_free(source);
+}
+
+
+static void
+test_source_parse_with_description(void **state)
+{
+ const char *a =
+ "VAR1: asd asd\n"
+ "VAR2: 123chunda\n"
+ "DESCRIPTION: huehuehuebrbr\n"
+ "----------\n"
+ "# This is a test\n"
+ "\n"
+ "bola\n";
+ blogc_error_t *err = NULL;
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ assert_null(err);
+ assert_non_null(source);
+ assert_int_equal(sb_trie_size(source), 6);
+ assert_string_equal(sb_trie_lookup(source, "VAR1"), "asd asd");
+ assert_string_equal(sb_trie_lookup(source, "VAR2"), "123chunda");
+ assert_string_equal(sb_trie_lookup(source, "EXCERPT"),
+ "<h1 id=\"this-is-a-test\">This is a test</h1>\n"
+ "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(source, "CONTENT"),
+ "<h1 id=\"this-is-a-test\">This is a test</h1>\n"
+ "<p>bola</p>\n");
+ assert_string_equal(sb_trie_lookup(source, "RAW_CONTENT"),
+ "# This is a test\n"
+ "\n"
+ "bola\n");
+ assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "huehuehuebrbr");
+ sb_trie_free(source);
}
@@ -163,13 +200,13 @@ test_source_parse_config_empty(void **state)
{
const char *a = "";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg, "Your source file is empty.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -178,14 +215,14 @@ test_source_parse_config_invalid_key(void **state)
{
const char *a = "bola: guda";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Can't find a configuration key or the content separator.\n"
"Error occurred near line 1, position 1: bola: guda");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -194,14 +231,14 @@ test_source_parse_config_no_key(void **state)
{
const char *a = "BOLa";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Invalid configuration key.\n"
"Error occurred near line 1, position 4: BOLa");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -210,14 +247,14 @@ test_source_parse_config_no_key2(void **state)
{
const char *a = "BOLA";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
assert_string_equal(err->msg,
"Your last configuration key is missing ':' and the value\n"
"Error occurred near line 1, position 5: BOLA");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -226,7 +263,7 @@ test_source_parse_config_no_value(void **state)
{
const char *a = "BOLA:\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -234,7 +271,7 @@ test_source_parse_config_no_value(void **state)
"Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -243,7 +280,7 @@ test_source_parse_config_no_value2(void **state)
{
const char *a = "BOLA:";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -251,7 +288,7 @@ test_source_parse_config_no_value2(void **state)
"Configuration value not provided for 'BOLA'.\n"
"Error occurred near line 1, position 6: BOLA:");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -260,7 +297,7 @@ test_source_parse_config_reserved_name(void **state)
{
const char *a = "FILENAME: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -268,7 +305,7 @@ test_source_parse_config_reserved_name(void **state)
"'FILENAME' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -277,7 +314,7 @@ test_source_parse_config_reserved_name2(void **state)
{
const char *a = "CONTENT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -285,7 +322,7 @@ test_source_parse_config_reserved_name2(void **state)
"'CONTENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -294,7 +331,7 @@ test_source_parse_config_reserved_name3(void **state)
{
const char *a = "DATE_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -302,7 +339,7 @@ test_source_parse_config_reserved_name3(void **state)
"'DATE_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -311,7 +348,7 @@ test_source_parse_config_reserved_name4(void **state)
{
const char *a = "DATE_FIRST_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -319,7 +356,7 @@ test_source_parse_config_reserved_name4(void **state)
"'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -328,7 +365,7 @@ test_source_parse_config_reserved_name5(void **state)
{
const char *a = "DATE_LAST_FORMATTED: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -336,7 +373,7 @@ test_source_parse_config_reserved_name5(void **state)
"'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -345,7 +382,7 @@ test_source_parse_config_reserved_name6(void **state)
{
const char *a = "PAGE_FIRST: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -353,7 +390,7 @@ test_source_parse_config_reserved_name6(void **state)
"'PAGE_FIRST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -362,7 +399,7 @@ test_source_parse_config_reserved_name7(void **state)
{
const char *a = "PAGE_PREVIOUS: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -370,7 +407,7 @@ test_source_parse_config_reserved_name7(void **state)
"'PAGE_PREVIOUS' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -379,7 +416,7 @@ test_source_parse_config_reserved_name8(void **state)
{
const char *a = "PAGE_CURRENT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -387,7 +424,7 @@ test_source_parse_config_reserved_name8(void **state)
"'PAGE_CURRENT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -396,7 +433,7 @@ test_source_parse_config_reserved_name9(void **state)
{
const char *a = "PAGE_NEXT: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -404,7 +441,7 @@ test_source_parse_config_reserved_name9(void **state)
"'PAGE_NEXT' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -413,7 +450,7 @@ test_source_parse_config_reserved_name10(void **state)
{
const char *a = "PAGE_LAST: asd\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -421,7 +458,7 @@ test_source_parse_config_reserved_name10(void **state)
"'PAGE_LAST' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -430,7 +467,7 @@ test_source_parse_config_reserved_name11(void **state)
{
const char *a = "BLOGC_VERSION: 1.0\r\n";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -438,7 +475,7 @@ test_source_parse_config_reserved_name11(void **state)
"'BLOGC_VERSION' variable is forbidden in source files. It will be set "
"for you by the compiler.");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -447,7 +484,7 @@ test_source_parse_config_value_no_line_ending(void **state)
{
const char *a = "BOLA: asd";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -455,7 +492,7 @@ test_source_parse_config_value_no_line_ending(void **state)
"No line ending after the configuration value for 'BOLA'.\n"
"Error occurred near line 1, position 10: BOLA: asd");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -464,7 +501,7 @@ test_source_parse_invalid_separator(void **state)
{
const char *a = "BOLA: asd\n---#";
blogc_error_t *err = NULL;
- b_trie_t *source = blogc_source_parse(a, strlen(a), &err);
+ sb_trie_t *source = blogc_source_parse(a, strlen(a), &err);
assert_null(source);
assert_non_null(err);
assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER);
@@ -472,7 +509,7 @@ test_source_parse_invalid_separator(void **state)
"Invalid content separator. Must be more than one '-' characters.\n"
"Error occurred near line 2, position 4: ---#");
blogc_error_free(err);
- b_trie_free(source);
+ sb_trie_free(source);
}
@@ -484,6 +521,7 @@ main(void)
unit_test(test_source_parse_crlf),
unit_test(test_source_parse_with_spaces),
unit_test(test_source_parse_with_excerpt),
+ unit_test(test_source_parse_with_description),
unit_test(test_source_parse_config_empty),
unit_test(test_source_parse_config_invalid_key),
unit_test(test_source_parse_config_no_key),
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c
index f655896..40a09be 100644
--- a/tests/check_template_parser.c
+++ b/tests/check_template_parser.c
@@ -17,11 +17,11 @@
#include <string.h>
#include "../src/template-parser.h"
#include "../src/error.h"
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
static void
-blogc_assert_template_stmt(b_slist_t *l, const char *value,
+blogc_assert_template_stmt(sb_slist_t *l, const char *value,
const blogc_template_stmt_type_t type)
{
blogc_template_stmt_t *stmt = l->data;
@@ -34,7 +34,7 @@ blogc_assert_template_stmt(b_slist_t *l, const char *value,
static void
-blogc_assert_template_if_stmt(b_slist_t *l, const char *variable,
+blogc_assert_template_if_stmt(sb_slist_t *l, const char *variable,
blogc_template_stmt_operator_t operator, const char *operand)
{
blogc_template_stmt_t *stmt = l->data;
@@ -64,7 +64,7 @@ test_template_parse(void **state)
"{%- foreach BOLA %}hahaha{% endforeach %}\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test",
@@ -81,7 +81,7 @@ test_template_parse(void **state)
BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\n",
BLOGC_TEMPLATE_CONTENT_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT);
blogc_assert_template_stmt(tmp->next, "\nbolao", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -144,7 +144,7 @@ test_template_parse_crlf(void **state)
"{%- foreach BOLA %}hahaha{% endforeach %}\r\n"
"{% if BOLA == \"1\\\"0\" %}aee{% endif %}";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "Test",
@@ -161,7 +161,7 @@ test_template_parse_crlf(void **state)
BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\r\n",
BLOGC_TEMPLATE_CONTENT_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT);
blogc_assert_template_stmt(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
@@ -232,7 +232,7 @@ test_template_parse_html(void **state)
" </body>\n"
"</html>\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "<html>\n <head>\n ",
@@ -251,7 +251,7 @@ test_template_parse_html(void **state)
"\n ", BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next->next,
"listing_once", BLOGC_TEMPLATE_BLOCK_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp,
"\n <title>My cool blog - Main page</title>\n ",
BLOGC_TEMPLATE_CONTENT_STMT);
@@ -342,7 +342,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
"{{ BOLA }}\n"
"{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_null(err);
assert_non_null(stmts);
blogc_assert_template_stmt(stmts, "GUDA", BLOGC_TEMPLATE_IFDEF_STMT);
@@ -358,7 +358,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state)
BLOGC_TEMPLATE_CONTENT_STMT);
blogc_assert_template_stmt(stmts->next->next->next->next->next->next,
"CHUNDA", BLOGC_TEMPLATE_IFNDEF_STMT);
- b_slist_t *tmp = stmts->next->next->next->next->next->next->next;
+ sb_slist_t *tmp = stmts->next->next->next->next->next->next->next;
blogc_assert_template_stmt(tmp, "CHUNDA", BLOGC_TEMPLATE_VARIABLE_STMT);
blogc_assert_template_stmt(tmp->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT);
blogc_assert_template_stmt(tmp->next->next, "\n",
@@ -373,7 +373,7 @@ test_template_parse_invalid_block_start(void **state)
{
const char *a = "{% ASD %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -411,7 +411,7 @@ test_template_parse_invalid_block_nested(void **state)
"{% block entry %}\n"
"{% block listing %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -429,7 +429,7 @@ test_template_parse_invalid_foreach_nested(void **state)
"{% foreach A %}\n"
"{% foreach B %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -445,7 +445,7 @@ test_template_parse_invalid_block_not_open(void **state)
{
const char *a = "{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -461,7 +461,7 @@ test_template_parse_invalid_endif_not_open(void **state)
{
const char *a = "{% block listing %}{% endif %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -478,7 +478,7 @@ test_template_parse_invalid_endforeach_not_open(void **state)
{
const char *a = "{% endforeach %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -494,7 +494,7 @@ test_template_parse_invalid_block_name(void **state)
{
const char *a = "{% chunda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -511,7 +511,7 @@ test_template_parse_invalid_block_type_start(void **state)
{
const char *a = "{% block ENTRY %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -527,7 +527,7 @@ test_template_parse_invalid_block_type(void **state)
{
const char *a = "{% block chunda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -543,7 +543,7 @@ test_template_parse_invalid_ifdef_start(void **state)
{
const char *a = "{% block entry %}{% ifdef guda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -560,7 +560,7 @@ test_template_parse_invalid_foreach_start(void **state)
{
const char *a = "{% block entry %}{% foreach guda %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -577,7 +577,7 @@ test_template_parse_invalid_ifdef_variable(void **state)
{
const char *a = "{% block entry %}{% ifdef BoLA %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -594,7 +594,7 @@ test_template_parse_invalid_ifdef_variable2(void **state)
{
const char *a = "{% block entry %}{% ifdef 0123 %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -611,7 +611,7 @@ test_template_parse_invalid_foreach_variable(void **state)
{
const char *a = "{% block entry %}{% foreach BoLA %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -628,7 +628,7 @@ test_template_parse_invalid_foreach_variable2(void **state)
{
const char *a = "{% block entry %}{% foreach 0123 %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -645,7 +645,7 @@ test_template_parse_invalid_if_operator(void **state)
{
const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -662,7 +662,7 @@ test_template_parse_invalid_if_operand(void **state)
{
const char *a = "{% block entry %}{% if BOLA == asd %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -679,7 +679,7 @@ test_template_parse_invalid_if_operand2(void **state)
{
const char *a = "{% block entry %}{% if BOLA == \"asd %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -696,7 +696,7 @@ test_template_parse_invalid_if_operand3(void **state)
{
const char *a = "{% block entry %}{% if BOLA == 0123 %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -713,7 +713,7 @@ test_template_parse_invalid_block_end(void **state)
{
const char *a = "{% block entry }}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -729,7 +729,7 @@ test_template_parse_invalid_variable_name(void **state)
{
const char *a = "{% block entry %}{{ bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -746,7 +746,7 @@ test_template_parse_invalid_variable_name2(void **state)
{
const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -763,7 +763,7 @@ test_template_parse_invalid_variable_name3(void **state)
{
const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -780,7 +780,7 @@ test_template_parse_invalid_variable_end(void **state)
{
const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -797,7 +797,7 @@ test_template_parse_invalid_close(void **state)
{
const char *a = "{% block entry %%\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -813,7 +813,7 @@ test_template_parse_invalid_close2(void **state)
{
const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -830,7 +830,7 @@ test_template_parse_invalid_if_not_closed(void **state)
{
const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -845,7 +845,7 @@ test_template_parse_invalid_block_not_closed(void **state)
{
const char *a = "{% block entry %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
@@ -859,7 +859,7 @@ test_template_parse_invalid_foreach_not_closed(void **state)
{
const char *a = "{% foreach ASD %}\n";
blogc_error_t *err = NULL;
- b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
+ sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err);
assert_non_null(err);
assert_null(stmts);
assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER);
diff --git a/tests/check_utils.c b/tests/check_utils.c
index a511dda..6a6ceca 100644
--- a/tests/check_utils.c
+++ b/tests/check_utils.c
@@ -13,38 +13,58 @@
#include <stdlib.h>
-#include "../src/utils/utils.h"
+#include "../src/utils.h"
+
+#define SB_STRING_CHUNK_SIZE 128
static void
test_slist_append(void **state)
{
- b_slist_t *l = NULL;
- l = b_slist_append(l, (void*) b_strdup("bola"));
+ sb_slist_t *l = NULL;
+ l = sb_slist_append(l, (void*) sb_strdup("bola"));
assert_non_null(l);
assert_string_equal(l->data, "bola");
assert_null(l->next);
- l = b_slist_append(l, (void*) b_strdup("guda"));
+ l = sb_slist_append(l, (void*) sb_strdup("guda"));
assert_non_null(l);
assert_string_equal(l->data, "bola");
assert_non_null(l->next);
assert_string_equal(l->next->data, "guda");
assert_null(l->next->next);
- b_slist_free_full(l, free);
+ sb_slist_free_full(l, free);
+}
+
+
+static void
+test_slist_prepend(void **state)
+{
+ sb_slist_t *l = NULL;
+ l = sb_slist_prepend(l, (void*) sb_strdup("bola"));
+ assert_non_null(l);
+ assert_string_equal(l->data, "bola");
+ assert_null(l->next);
+ l = sb_slist_prepend(l, (void*) sb_strdup("guda"));
+ assert_non_null(l);
+ assert_string_equal(l->data, "guda");
+ assert_non_null(l->next);
+ assert_string_equal(l->next->data, "bola");
+ assert_null(l->next->next);
+ sb_slist_free_full(l, free);
}
static void
test_slist_free(void **state)
{
- b_slist_t *l = NULL;
- char *t1 = b_strdup("bola");
- char *t2 = b_strdup("guda");
- char *t3 = b_strdup("chunda");
- l = b_slist_append(l, (void*) t1);
- l = b_slist_append(l, (void*) t2);
- l = b_slist_append(l, (void*) t3);
- b_slist_free(l);
+ sb_slist_t *l = NULL;
+ char *t1 = sb_strdup("bola");
+ char *t2 = sb_strdup("guda");
+ char *t3 = sb_strdup("chunda");
+ l = sb_slist_append(l, (void*) t1);
+ l = sb_slist_append(l, (void*) t2);
+ l = sb_slist_append(l, (void*) t3);
+ sb_slist_free(l);
assert_string_equal(t1, "bola");
assert_string_equal(t2, "guda");
assert_string_equal(t3, "chunda");
@@ -57,22 +77,23 @@ test_slist_free(void **state)
static void
test_slist_length(void **state)
{
- b_slist_t *l = NULL;
- l = b_slist_append(l, (void*) b_strdup("bola"));
- l = b_slist_append(l, (void*) b_strdup("guda"));
- l = b_slist_append(l, (void*) b_strdup("chunda"));
- assert_int_equal(b_slist_length(l), 3);
- b_slist_free_full(l, free);
+ sb_slist_t *l = NULL;
+ l = sb_slist_append(l, (void*) sb_strdup("bola"));
+ l = sb_slist_append(l, (void*) sb_strdup("guda"));
+ l = sb_slist_append(l, (void*) sb_strdup("chunda"));
+ assert_int_equal(sb_slist_length(l), 3);
+ sb_slist_free_full(l, free);
+ assert_int_equal(sb_slist_length(NULL), 0);
}
static void
test_strdup(void **state)
{
- char *str = b_strdup("bola");
+ char *str = sb_strdup("bola");
assert_string_equal(str, "bola");
free(str);
- str = b_strdup(NULL);
+ str = sb_strdup(NULL);
assert_null(str);
}
@@ -80,16 +101,16 @@ test_strdup(void **state)
static void
test_strndup(void **state)
{
- char *str = b_strndup("bolaguda", 4);
+ char *str = sb_strndup("bolaguda", 4);
assert_string_equal(str, "bola");
free(str);
- str = b_strndup("bolaguda", 30);
+ str = sb_strndup("bolaguda", 30);
assert_string_equal(str, "bolaguda");
free(str);
- str = b_strndup("bolaguda", 8);
+ str = sb_strndup("bolaguda", 8);
assert_string_equal(str, "bolaguda");
free(str);
- str = b_strdup(NULL);
+ str = sb_strdup(NULL);
assert_null(str);
}
@@ -97,10 +118,10 @@ test_strndup(void **state)
static void
test_strdup_printf(void **state)
{
- char *str = b_strdup_printf("bola");
+ char *str = sb_strdup_printf("bola");
assert_string_equal(str, "bola");
free(str);
- str = b_strdup_printf("bola, %s", "guda");
+ str = sb_strdup_printf("bola, %s", "guda");
assert_string_equal(str, "bola, guda");
free(str);
}
@@ -109,140 +130,146 @@ test_strdup_printf(void **state)
static void
test_str_starts_with(void **state)
{
- assert_true(b_str_starts_with("bolaguda", "bola"));
- assert_true(b_str_starts_with("bola", "bola"));
- assert_false(b_str_starts_with("gudabola", "bola"));
- assert_false(b_str_starts_with("guda", "bola"));
- assert_false(b_str_starts_with("bola", "bolaguda"));
+ assert_true(sb_str_starts_with("bolaguda", "bola"));
+ assert_true(sb_str_starts_with("bola", "bola"));
+ assert_false(sb_str_starts_with("gudabola", "bola"));
+ assert_false(sb_str_starts_with("guda", "bola"));
+ assert_false(sb_str_starts_with("bola", "bolaguda"));
}
static void
test_str_ends_with(void **state)
{
- assert_true(b_str_ends_with("bolaguda", "guda"));
- assert_true(b_str_ends_with("bola", "bola"));
- assert_false(b_str_ends_with("gudabola", "guda"));
- assert_false(b_str_ends_with("guda", "bola"));
- assert_false(b_str_ends_with("bola", "gudabola"));
+ assert_true(sb_str_ends_with("bolaguda", "guda"));
+ assert_true(sb_str_ends_with("bola", "bola"));
+ assert_false(sb_str_ends_with("gudabola", "guda"));
+ assert_false(sb_str_ends_with("guda", "bola"));
+ assert_false(sb_str_ends_with("bola", "gudabola"));
}
static void
test_str_lstrip(void **state)
{
- char *str = b_strdup(" \tbola\n \t");
- assert_string_equal(b_str_lstrip(str), "bola\n \t");
+ char *str = sb_strdup(" \tbola\n \t");
+ assert_string_equal(sb_str_lstrip(str), "bola\n \t");
free(str);
- str = b_strdup("guda");
- assert_string_equal(b_str_lstrip(str), "guda");
+ str = sb_strdup("guda");
+ assert_string_equal(sb_str_lstrip(str), "guda");
free(str);
- str = b_strdup("\n");
- assert_string_equal(b_str_lstrip(str), "");
+ str = sb_strdup("\n");
+ assert_string_equal(sb_str_lstrip(str), "");
free(str);
- str = b_strdup("\t \n");
- assert_string_equal(b_str_lstrip(str), "");
+ str = sb_strdup("\t \n");
+ assert_string_equal(sb_str_lstrip(str), "");
free(str);
- str = b_strdup("");
- assert_string_equal(b_str_lstrip(str), "");
+ str = sb_strdup("");
+ assert_string_equal(sb_str_lstrip(str), "");
free(str);
- assert_null(b_str_lstrip(NULL));
+ assert_null(sb_str_lstrip(NULL));
}
static void
test_str_rstrip(void **state)
{
- char *str = b_strdup(" \tbola\n \t");
- assert_string_equal(b_str_rstrip(str), " \tbola");
+ char *str = sb_strdup(" \tbola\n \t");
+ assert_string_equal(sb_str_rstrip(str), " \tbola");
free(str);
- str = b_strdup("guda");
- assert_string_equal(b_str_rstrip(str), "guda");
+ str = sb_strdup("guda");
+ assert_string_equal(sb_str_rstrip(str), "guda");
free(str);
- str = b_strdup("\n");
- assert_string_equal(b_str_rstrip(str), "");
+ str = sb_strdup("\n");
+ assert_string_equal(sb_str_rstrip(str), "");
free(str);
- str = b_strdup("\t \n");
- assert_string_equal(b_str_rstrip(str), "");
+ str = sb_strdup("\t \n");
+ assert_string_equal(sb_str_rstrip(str), "");
free(str);
- str = b_strdup("");
- assert_string_equal(b_str_rstrip(str), "");
+ str = sb_strdup("");
+ assert_string_equal(sb_str_rstrip(str), "");
free(str);
- assert_null(b_str_rstrip(NULL));
+ assert_null(sb_str_rstrip(NULL));
}
static void
test_str_strip(void **state)
{
- char *str = b_strdup(" \tbola\n \t");
- assert_string_equal(b_str_strip(str), "bola");
+ char *str = sb_strdup(" \tbola\n \t");
+ assert_string_equal(sb_str_strip(str), "bola");
free(str);
- str = b_strdup("guda");
- assert_string_equal(b_str_strip(str), "guda");
+ str = sb_strdup("guda");
+ assert_string_equal(sb_str_strip(str), "guda");
free(str);
- str = b_strdup("\n");
- assert_string_equal(b_str_strip(str), "");
+ str = sb_strdup("\n");
+ assert_string_equal(sb_str_strip(str), "");
free(str);
- str = b_strdup("\t \n");
- assert_string_equal(b_str_strip(str), "");
+ str = sb_strdup("\t \n");
+ assert_string_equal(sb_str_strip(str), "");
free(str);
- str = b_strdup("");
- assert_string_equal(b_str_strip(str), "");
+ str = sb_strdup("");
+ assert_string_equal(sb_str_strip(str), "");
free(str);
- assert_null(b_str_strip(NULL));
+ assert_null(sb_str_strip(NULL));
}
static void
test_str_split(void **state)
{
- char **strv = b_str_split("bola:guda:chunda", ':', 0);
+ char **strv = sb_str_split("bola:guda:chunda", ':', 0);
assert_string_equal(strv[0], "bola");
assert_string_equal(strv[1], "guda");
assert_string_equal(strv[2], "chunda");
assert_null(strv[3]);
- b_strv_free(strv);
- strv = b_str_split("bola:guda:chunda", ':', 2);
+ sb_strv_free(strv);
+ strv = sb_str_split("bola:guda:chunda", ':', 2);
assert_string_equal(strv[0], "bola");
assert_string_equal(strv[1], "guda:chunda");
assert_null(strv[2]);
- b_strv_free(strv);
- strv = b_str_split("bola:guda:chunda", ':', 1);
+ sb_strv_free(strv);
+ strv = sb_str_split("bola:guda:chunda", ':', 1);
assert_string_equal(strv[0], "bola:guda:chunda");
assert_null(strv[1]);
- b_strv_free(strv);
- strv = b_str_split("", ':', 1);
+ sb_strv_free(strv);
+ strv = sb_str_split("", ':', 1);
assert_null(strv[0]);
- b_strv_free(strv);
- assert_null(b_str_split(NULL, ':', 0));
+ sb_strv_free(strv);
+ assert_null(sb_str_split(NULL, ':', 0));
}
static void
test_str_replace(void **state)
{
- char *str = b_str_replace("bolao", 'o', "zaz");
+ char *str = sb_str_replace("bolao", 'o', "zaz");
assert_string_equal(str, "bzazlazaz");
free(str);
- str = b_str_replace("bolao", 'b', "zaz");
+ str = sb_str_replace("bolao", 'b', "zaz");
assert_string_equal(str, "zazolao");
free(str);
+ str = sb_str_replace("bolao", 'b', NULL);
+ assert_string_equal(str, "bolao");
+ free(str);
+ assert_null(sb_str_replace(NULL, 'b', "zaz"));
}
static void
test_strv_join(void **state)
{
- const char *pieces[] = {"guda","bola", "chunda", NULL};
- char *str = b_strv_join(pieces, ":");
+ char *pieces[] = {"guda","bola", "chunda", NULL};
+ char *str = sb_strv_join(pieces, ":");
assert_string_equal(str, "guda:bola:chunda");
free(str);
- const char *pieces2[] = {NULL};
- str = b_strv_join(pieces2, ":");
+ char *pieces2[] = {NULL};
+ str = sb_strv_join(pieces2, ":");
assert_string_equal(str, "");
free(str);
- assert_null(b_strv_join(NULL, ":"));
+ assert_null(sb_strv_join(pieces, NULL));
+ assert_null(sb_strv_join(NULL, ":"));
+ assert_null(sb_strv_join(NULL, NULL));
}
@@ -250,68 +277,88 @@ static void
test_strv_length(void **state)
{
char *pieces[] = {"guda","bola", "chunda", NULL};
- assert_int_equal(b_strv_length(pieces), 3);
+ assert_int_equal(sb_strv_length(pieces), 3);
char *pieces2[] = {NULL};
- assert_int_equal(b_strv_length(pieces2), 0);
- assert_int_equal(b_strv_length(NULL), 0);
+ assert_int_equal(sb_strv_length(pieces2), 0);
+ assert_int_equal(sb_strv_length(NULL), 0);
}
static void
test_string_new(void **state)
{
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
assert_non_null(str);
assert_string_equal(str->str, "");
assert_int_equal(str->len, 0);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
}
static void
test_string_free(void **state)
{
- b_string_t *str = b_string_new();
+ sb_string_t *str = sb_string_new();
free(str->str);
- str->str = b_strdup("bola");
+ str->str = sb_strdup("bola");
str->len = 4;
- str->allocated_len = B_STRING_CHUNK_SIZE;
- char *tmp = b_string_free(str, false);
+ str->allocated_len = SB_STRING_CHUNK_SIZE;
+ char *tmp = sb_string_free(str, false);
assert_string_equal(tmp, "bola");
free(tmp);
+ assert_null(sb_string_free(NULL, false));
+}
+
+
+static void
+test_string_dup(void **state)
+{
+ sb_string_t *str = sb_string_new();
+ free(str->str);
+ str->str = sb_strdup("bola");
+ str->len = 4;
+ str->allocated_len = SB_STRING_CHUNK_SIZE;
+ sb_string_t *new = sb_string_dup(str);
+ assert_non_null(new);
+ assert_string_equal(new->str, "bola");
+ assert_int_equal(new->len, 4);
+ assert_int_equal(new->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(new, true));
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_dup(NULL));
}
static void
test_string_append_len(void **state)
{
- b_string_t *str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
+ sb_string_t *str = sb_string_new();
+ str = sb_string_append_len(str, "guda", 4);
assert_non_null(str);
assert_string_equal(str->str, "guda");
assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- str = b_string_append_len(str, "bola", 4);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append_len(str, "guda", 4);
+ str = sb_string_append_len(str, "bola", 4);
assert_non_null(str);
assert_string_equal(str->str, "gudabola");
assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 3);
- str = b_string_append_len(str, "bola", 4);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append_len(str, "guda", 3);
+ str = sb_string_append_len(str, "bola", 4);
assert_non_null(str);
assert_string_equal(str->str, "gudbola");
assert_int_equal(str->len, 7);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
- str = b_string_append_len(str,
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append_len(str, "guda", 4);
+ str = sb_string_append_len(str,
"cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
"nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
"xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
@@ -321,8 +368,8 @@ test_string_append_len(void **state)
"dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
"ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
"okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600);
- str = b_string_append_len(str, NULL, 0);
- str = b_string_append_len(str,
+ str = sb_string_append_len(str, NULL, 0);
+ str = sb_string_append_len(str,
"cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
"nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
"xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
@@ -353,32 +400,40 @@ test_string_append_len(void **state)
"pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
"fkeannglvsxprqzfekdinssqymtfexf");
assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10);
- assert_null(b_string_free(str, true));
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 10);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append_len(str, NULL, 0);
+ assert_non_null(str);
+ assert_string_equal(str->str, "");
+ assert_int_equal(str->len, 0);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_append_len(NULL, "foo", 3));
}
static void
test_string_append(void **state)
{
- b_string_t *str = b_string_new();
- str = b_string_append(str, "guda");
+ sb_string_t *str = sb_string_new();
+ str = sb_string_append(str, "guda");
assert_non_null(str);
assert_string_equal(str->str, "guda");
assert_int_equal(str->len, 4);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append(str, "guda");
- str = b_string_append(str, "bola");
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append(str, "guda");
+ str = sb_string_append(str, "bola");
assert_non_null(str);
assert_string_equal(str->str, "gudabola");
assert_int_equal(str->len, 8);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
- str = b_string_new();
- str = b_string_append(str, "guda");
- str = b_string_append(str,
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append(str, "guda");
+ str = sb_string_append(str,
"cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
"nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
"xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
@@ -388,8 +443,8 @@ test_string_append(void **state)
"dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr"
"ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg"
"okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf");
- str = b_string_append(str, NULL);
- str = b_string_append(str,
+ str = sb_string_append(str, NULL);
+ str = sb_string_append(str,
"cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw"
"nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa"
"xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz"
@@ -420,18 +475,27 @@ test_string_append(void **state)
"pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba"
"fkeannglvsxprqzfekdinssqymtfexf");
assert_int_equal(str->len, 1204);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10);
- assert_null(b_string_free(str, true));
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 10);
+ assert_null(sb_string_free(str, true));
+ str = sb_string_new();
+ str = sb_string_append(str, NULL);
+ assert_non_null(str);
+ assert_string_equal(str->str, "");
+ assert_int_equal(str->len, 0);
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_append(NULL, "asd"));
+ assert_null(sb_string_append(NULL, NULL));
}
static void
test_string_append_c(void **state)
{
- b_string_t *str = b_string_new();
- str = b_string_append_len(str, "guda", 4);
+ sb_string_t *str = sb_string_new();
+ str = sb_string_append_len(str, "guda", 4);
for (int i = 0; i < 600; i++)
- str = b_string_append_c(str, 'c');
+ str = sb_string_append_c(str, 'c');
assert_non_null(str);
assert_string_equal(str->str,
"gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
@@ -444,41 +508,43 @@ test_string_append_c(void **state)
"ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
"cccccccccccccccccccccccccccccccccccccccccccccccccccc");
assert_int_equal(str->len, 604);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 5);
- assert_null(b_string_free(str, true));
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE * 5);
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_append_c(NULL, 0));
}
static void
test_string_append_printf(void **state)
{
- b_string_t *str = b_string_new();
- str = b_string_append_printf(str, "guda: %s %d", "bola", 1);
+ sb_string_t *str = sb_string_new();
+ str = sb_string_append_printf(str, "guda: %s %d", "bola", 1);
assert_non_null(str);
assert_string_equal(str->str, "guda: bola 1");
assert_int_equal(str->len, 12);
- assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE);
- assert_null(b_string_free(str, true));
+ assert_int_equal(str->allocated_len, SB_STRING_CHUNK_SIZE);
+ assert_null(sb_string_free(str, true));
+ assert_null(sb_string_append_printf(NULL, "asd"));
}
static void
test_trie_new(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
assert_non_null(trie);
assert_null(trie->root);
assert_true(trie->free_func == free);
- b_trie_free(trie);
+ sb_trie_free(trie);
}
static void
test_trie_insert(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
- b_trie_insert(trie, "bola", b_strdup("guda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -491,7 +557,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->child->child->child->child->data, "guda");
- b_trie_insert(trie, "chu", b_strdup("nda"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -513,7 +579,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->next->child->child->child->data, "nda");
- b_trie_insert(trie, "bote", b_strdup("aba"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -542,7 +608,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->child->child->next->child->child->data, "aba");
- b_trie_insert(trie, "bo", b_strdup("haha"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -573,12 +639,12 @@ test_trie_insert(void **state)
assert_true(trie->root->child->child->next->next->key == '\0');
assert_string_equal(trie->root->child->child->next->next->data, "haha");
- b_trie_free(trie);
+ sb_trie_free(trie);
- trie = b_trie_new(free);
+ trie = sb_trie_new(free);
- b_trie_insert(trie, "chu", b_strdup("nda"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
assert_true(trie->root->key == 'c');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'h');
@@ -589,7 +655,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->child->child->child->data, "nda");
- b_trie_insert(trie, "bola", b_strdup("guda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
assert_true(trie->root->key == 'c');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'h');
@@ -611,7 +677,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->next->child->child->child->child->data, "guda");
- b_trie_insert(trie, "bote", b_strdup("aba"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
assert_true(trie->root->key == 'c');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'h');
@@ -640,7 +706,7 @@ test_trie_insert(void **state)
assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba");
- b_trie_insert(trie, "bo", b_strdup("haha"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
assert_true(trie->root->key == 'c');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'h');
@@ -671,16 +737,16 @@ test_trie_insert(void **state)
assert_true(trie->root->next->child->child->next->next->key == '\0');
assert_string_equal(trie->root->next->child->child->next->next->data, "haha");
- b_trie_free(trie);
+ sb_trie_free(trie);
}
static void
test_trie_insert_duplicated(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
- b_trie_insert(trie, "bola", b_strdup("guda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -692,7 +758,7 @@ test_trie_insert_duplicated(void **state)
assert_true(trie->root->child->child->child->child->key == '\0');
assert_string_equal(trie->root->child->child->child->child->data, "guda");
- b_trie_insert(trie, "bola", b_strdup("asdf"));
+ sb_trie_insert(trie, "bola", sb_strdup("asdf"));
assert_true(trie->root->key == 'b');
assert_null(trie->root->data);
assert_true(trie->root->child->key == 'o');
@@ -704,26 +770,30 @@ test_trie_insert_duplicated(void **state)
assert_true(trie->root->child->child->child->child->key == '\0');
assert_string_equal(trie->root->child->child->child->child->data, "asdf");
- b_trie_free(trie);
+ sb_trie_free(trie);
+
+ trie = NULL;
+ sb_trie_insert(trie, "bola", NULL);
+ assert_null(trie);
}
static void
test_trie_keep_data(void **state)
{
- b_trie_t *trie = b_trie_new(NULL);
+ sb_trie_t *trie = sb_trie_new(NULL);
char *t1 = "guda";
char *t2 = "nda";
char *t3 = "aba";
char *t4 = "haha";
- b_trie_insert(trie, "bola", t1);
- b_trie_insert(trie, "chu", t2);
- b_trie_insert(trie, "bote", t3);
- b_trie_insert(trie, "bo", t4);
+ sb_trie_insert(trie, "bola", t1);
+ sb_trie_insert(trie, "chu", t2);
+ sb_trie_insert(trie, "bote", t3);
+ sb_trie_insert(trie, "bo", t4);
- b_trie_free(trie);
+ sb_trie_free(trie);
assert_string_equal(t1, "guda");
assert_string_equal(t2, "nda");
@@ -735,72 +805,74 @@ test_trie_keep_data(void **state)
static void
test_trie_lookup(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
+
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
+ assert_string_equal(sb_trie_lookup(trie, "bola"), "guda");
+ assert_string_equal(sb_trie_lookup(trie, "chu"), "nda");
+ assert_string_equal(sb_trie_lookup(trie, "bote"), "aba");
+ assert_string_equal(sb_trie_lookup(trie, "bo"), "haha");
- assert_string_equal(b_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(b_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(b_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(b_trie_lookup(trie, "bo"), "haha");
+ assert_null(sb_trie_lookup(trie, "arcoiro"));
- assert_null(b_trie_lookup(trie, "arcoiro"));
+ sb_trie_free(trie);
- b_trie_free(trie);
+ trie = sb_trie_new(free);
- trie = b_trie_new(free);
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
+ sb_trie_insert(trie, "copa", sb_strdup("bu"));
+ sb_trie_insert(trie, "b", sb_strdup("c"));
+ sb_trie_insert(trie, "test", sb_strdup("asd"));
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
+ assert_string_equal(sb_trie_lookup(trie, "bola"), "guda");
+ assert_string_equal(sb_trie_lookup(trie, "chu"), "nda");
+ assert_string_equal(sb_trie_lookup(trie, "bote"), "aba");
+ assert_string_equal(sb_trie_lookup(trie, "bo"), "haha");
- assert_string_equal(b_trie_lookup(trie, "bola"), "guda");
- assert_string_equal(b_trie_lookup(trie, "chu"), "nda");
- assert_string_equal(b_trie_lookup(trie, "bote"), "aba");
- assert_string_equal(b_trie_lookup(trie, "bo"), "haha");
+ assert_null(sb_trie_lookup(trie, "arcoiro"));
- assert_null(b_trie_lookup(trie, "arcoiro"));
+ sb_trie_free(trie);
- b_trie_free(trie);
+ assert_null(sb_trie_lookup(NULL, "bola"));
}
static void
test_trie_size(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
- assert_int_equal(b_trie_size(trie), 4);
- assert_int_equal(b_trie_size(NULL), 0);
+ assert_int_equal(sb_trie_size(trie), 4);
+ assert_int_equal(sb_trie_size(NULL), 0);
- b_trie_free(trie);
+ sb_trie_free(trie);
- trie = b_trie_new(free);
+ trie = sb_trie_new(free);
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
+ sb_trie_insert(trie, "copa", sb_strdup("bu"));
+ sb_trie_insert(trie, "b", sb_strdup("c"));
+ sb_trie_insert(trie, "test", sb_strdup("asd"));
- assert_int_equal(b_trie_size(trie), 7);
- assert_int_equal(b_trie_size(NULL), 0);
+ assert_int_equal(sb_trie_size(trie), 7);
+ assert_int_equal(sb_trie_size(NULL), 0);
- b_trie_free(trie);
+ sb_trie_free(trie);
}
@@ -809,8 +881,9 @@ static char *expected_keys[] = {"chu", "copa", "bola", "bote", "bo", "b", "test"
static char *expected_datas[] = {"nda", "bu", "guda", "aba", "haha", "c", "asd"};
static void
-mock_foreach(const char *key, void *data)
+mock_foreach(const char *key, void *data, void *user_data)
{
+ assert_string_equal(user_data, "foo");
assert_string_equal(key, expected_keys[counter]);
assert_string_equal((char*) data, expected_datas[counter++]);
}
@@ -819,20 +892,23 @@ mock_foreach(const char *key, void *data)
static void
test_trie_foreach(void **state)
{
- b_trie_t *trie = b_trie_new(free);
+ sb_trie_t *trie = sb_trie_new(free);
- b_trie_insert(trie, "chu", b_strdup("nda"));
- b_trie_insert(trie, "bola", b_strdup("guda"));
- b_trie_insert(trie, "bote", b_strdup("aba"));
- b_trie_insert(trie, "bo", b_strdup("haha"));
- b_trie_insert(trie, "copa", b_strdup("bu"));
- b_trie_insert(trie, "b", b_strdup("c"));
- b_trie_insert(trie, "test", b_strdup("asd"));
+ sb_trie_insert(trie, "chu", sb_strdup("nda"));
+ sb_trie_insert(trie, "bola", sb_strdup("guda"));
+ sb_trie_insert(trie, "bote", sb_strdup("aba"));
+ sb_trie_insert(trie, "bo", sb_strdup("haha"));
+ sb_trie_insert(trie, "copa", sb_strdup("bu"));
+ sb_trie_insert(trie, "b", sb_strdup("c"));
+ sb_trie_insert(trie, "test", sb_strdup("asd"));
counter = 0;
- b_trie_foreach(trie, mock_foreach);
+ sb_trie_foreach(trie, mock_foreach, "foo");
+ sb_trie_foreach(NULL, mock_foreach, "foo");
+ sb_trie_foreach(trie, NULL, "foo");
+ sb_trie_foreach(NULL, NULL, "foo");
- b_trie_free(trie);
+ sb_trie_free(trie);
}
@@ -843,10 +919,11 @@ main(void)
// slist
unit_test(test_slist_append),
+ unit_test(test_slist_prepend),
unit_test(test_slist_free),
unit_test(test_slist_length),
- // strings
+ // strfuncs
unit_test(test_strdup),
unit_test(test_strndup),
unit_test(test_strdup_printf),
@@ -859,8 +936,11 @@ main(void)
unit_test(test_str_replace),
unit_test(test_strv_join),
unit_test(test_strv_length),
+
+ // string
unit_test(test_string_new),
unit_test(test_string_free),
+ unit_test(test_string_dup),
unit_test(test_string_append_len),
unit_test(test_string_append),
unit_test(test_string_append_c),