From f63fb03b25b33d5c2ef5ef0eaad016b4ee4aee65 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 13 Feb 2016 01:02:12 +0100 Subject: content-parser: fixed bug that parsed text with '!' + link as image --- src/content-parser.c | 12 ++++++++---- tests/check_content_parser.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index ccb96ef..a334d28 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -231,11 +231,15 @@ blogc_content_parse_inline(const char *src) 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) { + b_string_append_c(rv, c); + break; + } + if (!is_last && src[current + 1] != '[') { + b_string_append_c(rv, c); + break; + } state = LINK_IMAGE; is_image = true; start_state = current; diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 970ec5c..e8e412a 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1360,6 +1360,10 @@ test_content_parse_inline(void **state) assert_non_null(html); assert_string_equal(html, "bola"); free(html); + html = blogc_content_parse_inline("bola!"); + assert_non_null(html); + assert_string_equal(html, "bola!"); + free(html); } @@ -1475,6 +1479,10 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola\n"); free(html); + html = blogc_content_parse_inline("[bola!](http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola!\n"); + free(html); html = blogc_content_parse_inline("[bola]\n(http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "bola\n"); @@ -1491,6 +1499,12 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola(2)[3]**!\\\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 cmocka, though.\n"); + free(html); // "invalid" html = blogc_content_parse_inline("[bola](\nhttp://example.org/)\n"); assert_non_null(html); -- cgit v1.2.3-18-g5258 From 64b4eded92d8fd720e3768d93cdf789da27f88bb Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 13 Feb 2016 01:52:41 +0100 Subject: build: explicit man rules --- Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7b52fa0..cb75753 100644 --- a/Makefile.am +++ b/Makefile.am @@ -123,7 +123,7 @@ blogc.1: man/blogc.1.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - $< > $@ + man/blogc.1.ronn > blogc.1 blogc-source.7: man/blogc-source.7.ronn $(AM_V_GEN)$(RONN) \ @@ -131,7 +131,7 @@ blogc-source.7: man/blogc-source.7.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - $< > $@ + man/blogc-source.7.ronn > blogc-source.7 blogc-template.7: man/blogc-template.7.ronn $(AM_V_GEN)$(RONN) \ @@ -139,7 +139,7 @@ blogc-template.7: man/blogc-template.7.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - $< > $@ + man/blogc-template.7.ronn > blogc-template.7 else -- cgit v1.2.3-18-g5258 From ec5df72939c31bfe644b3b56e8df5f3c04bfe0a6 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 13 Feb 2016 02:01:16 +0100 Subject: build: explicit man rules. take 2 --- Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index cb75753..832b19c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -123,7 +123,7 @@ blogc.1: man/blogc.1.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - man/blogc.1.ronn > blogc.1 + $(top_srcdir)/man/blogc.1.ronn > blogc.1 blogc-source.7: man/blogc-source.7.ronn $(AM_V_GEN)$(RONN) \ @@ -131,7 +131,7 @@ blogc-source.7: man/blogc-source.7.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - man/blogc-source.7.ronn > blogc-source.7 + $(top_srcdir)/man/blogc-source.7.ronn > blogc-source.7 blogc-template.7: man/blogc-template.7.ronn $(AM_V_GEN)$(RONN) \ @@ -139,7 +139,7 @@ blogc-template.7: man/blogc-template.7.ronn --pipe \ --organization "Rafael G. Martins" \ --manual "$(PACKAGE_NAME) Manual" \ - man/blogc-template.7.ronn > blogc-template.7 + $(top_srcdir)/man/blogc-template.7.ronn > blogc-template.7 else -- cgit v1.2.3-18-g5258 From fa40247c2f1fd263832bf581c639725463ad2b87 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 15 Feb 2016 01:31:44 +0100 Subject: README: move tests to jenkins --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f675267..3622739 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://jenkins.rgm.io/buildStatus/icon?job=blogc-tests)](https://jenkins.rgm.io/job/blogc-tests/) A blog compiler. -- cgit v1.2.3-18-g5258 From 146a058ce3fa4d8a736d6a883e90a4e0f473aeb2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 00:39:21 +0100 Subject: build: spec improvements --- blogc.spec.in | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/blogc.spec.in b/blogc.spec.in index 3d76ecb..f63daf3 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -7,28 +7,21 @@ Summary: A blog compiler URL: @PACKAGE_URL@ Source0: https://github.com/blogc/blogc/releases/download/v%{version}/blogc-%{version}.tar.xz -#BuildRequires: -#Requires: - %description blogc(1) is a blog compiler. It converts source files and templates into blog/website resources. - %prep -%setup -q -n blogc-%{version} - +%setup -q %build %configure make %{?_smp_mflags} - %install rm -rf $RPM_BUILD_ROOT %make_install - %files %{_mandir}/man*/blogc* %{_bindir}/blogc @@ -36,7 +29,6 @@ rm -rf $RPM_BUILD_ROOT %doc README.md %license LICENSE - %changelog * Mon Jan 25 2016 Rafael G. Martins 0.7.2-1 - New release. -- cgit v1.2.3-18-g5258 From 9d5dd44c68aefa006d06fbff55756a070a84b55b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 00:49:07 +0100 Subject: build: version bump --- blogc.spec.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blogc.spec.in b/blogc.spec.in index f63daf3..2716c0a 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -30,6 +30,9 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Sat Feb 20 2016 Rafael G. Martins 0.7.3-1 +- New release. + * Mon Jan 25 2016 Rafael G. Martins 0.7.2-1 - New release. -- cgit v1.2.3-18-g5258 From 31d376735ab2aaaed0934edcce676113f83a7de7 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 04:58:13 +0100 Subject: content-parser: fixed parser bug when handling links do not handle something like this as a valid link: [asd] asd (asd) --- src/content-parser.c | 13 +++++++++++-- tests/check_content_parser.c | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index a334d28..9d4adf6 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -161,6 +161,16 @@ 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 != '(') + { + b_string_append_c(rv, src[start_state]); + tmp = blogc_content_parse_inline(src + start_state + 1); + b_string_append(rv, tmp); + // no need to free here, we will exit the loop! + break; + } + switch (c) { case '\\': @@ -390,8 +400,7 @@ blogc_content_parse_inline(const char *src) b_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; + // no need to free here, its the last iteration } current++; } diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index e8e412a..73bbe9b 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1487,6 +1487,14 @@ test_content_parse_inline_link(void **state) assert_non_null(html); assert_string_equal(html, "bola\n"); free(html); + html = blogc_content_parse_inline("[bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); + html = blogc_content_parse_inline("[bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "bola\n"); + free(html); html = blogc_content_parse_inline("[bo\nla](http://example.org/)\n"); assert_non_null(html); assert_string_equal(html, "bo\nla\n"); @@ -1505,6 +1513,10 @@ test_content_parse_inline_link(void **state) assert_string_equal(html, "test suite!)\n" "depends on cmocka, 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); -- cgit v1.2.3-18-g5258 From 9902e223799f40776d1131aa0d48fc766637746e Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 14:30:40 +0100 Subject: content-parser: added more tests --- tests/check_content_parser.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 73bbe9b..048d2f2 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1598,6 +1598,18 @@ test_content_parse_inline_image(void **state) assert_non_null(html); assert_string_equal(html, "\"bola\"\n"); free(html); + html = blogc_content_parse_inline("![bola]\r\n(http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\n"); + free(html); + html = blogc_content_parse_inline("![bola] \r\n (http://example.org/)\n"); + assert_non_null(html); + assert_string_equal(html, "\"bola\"\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("![bo\nla](http://example.org/)\n"); assert_non_null(html); -- cgit v1.2.3-18-g5258 From de334a9e32d0d1d19c4aa98415cfe35866686157 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 14:31:05 +0100 Subject: man: improved content-parser docs --- man/blogc-source.7.ronn | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn index 7fa0796..5a0a485 100644 --- a/man/blogc-source.7.ronn +++ b/man/blogc-source.7.ronn @@ -209,12 +209,22 @@ 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 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. -- cgit v1.2.3-18-g5258 From b73afb052337d3c11d90efb5e90c2818063dda4d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 15:13:34 +0100 Subject: content-parser: added more tests --- tests/check_content_parser.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 048d2f2..fb56c19 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1606,6 +1606,21 @@ test_content_parse_inline_image(void **state) assert_non_null(html); assert_string_equal(html, "\"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, + ""); + 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, + ""); + free(html); html = blogc_content_parse_inline("asd ![bola]chunda(1234)"); assert_non_null(html); assert_string_equal(html, "asd ![bola]chunda(1234)"); -- cgit v1.2.3-18-g5258 From 2e62517084aa345181b8def833245053f1033f6f Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 15:19:29 +0100 Subject: build: version bump --- blogc.spec.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blogc.spec.in b/blogc.spec.in index 2716c0a..9472f2e 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -30,6 +30,9 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Sun Feb 21 2016 Rafael G. Martins 0.7.4-1 +- New release. + * Sat Feb 20 2016 Rafael G. Martins 0.7.3-1 - New release. -- cgit v1.2.3-18-g5258 From 437ea5b71f7a1f6cd5d09b28259a8e49acab7fbc Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 16:43:31 +0100 Subject: man: tests: minor documentation fix and more test coverage --- man/blogc-source.7.ronn | 11 +++++++++-- tests/check_content_parser.c | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn index 5a0a485..c2c0490 100644 --- a/man/blogc-source.7.ronn +++ b/man/blogc-source.7.ronn @@ -203,6 +203,11 @@ 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: @@ -220,10 +225,12 @@ 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 alt text and image URL: +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) + (picture.jpg)] + (https://blogc.rgm.io) ### Automatic Links diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index fb56c19..ea069a7 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1621,6 +1621,15 @@ test_content_parse_inline_image(void **state) ""); 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, + ""); + free(html); html = blogc_content_parse_inline("asd ![bola]chunda(1234)"); assert_non_null(html); assert_string_equal(html, "asd ![bola]chunda(1234)"); -- cgit v1.2.3-18-g5258 From bdff66b0013165c3ef7eff644fb276235f3dd082 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 21 Feb 2016 16:46:25 +0100 Subject: build: version bump --- blogc.spec.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blogc.spec.in b/blogc.spec.in index 9472f2e..5d9cbff 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -30,6 +30,9 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Sun Feb 21 2016 Rafael G. Martins 0.7.5-1 +- New release. + * Sun Feb 21 2016 Rafael G. Martins 0.7.4-1 - New release. -- cgit v1.2.3-18-g5258 From 3b0f9293a3432023cdca91df01418347d9781ffa Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 01:04:32 +0100 Subject: build: replace src/utils with squareball --- .gitmodules | 3 + Makefile.am | 46 +-- configure.ac | 26 ++ squareball | 1 + src/content-parser.c | 276 ++++++------- src/datetime-parser.c | 4 +- src/error.c | 12 +- src/file.c | 8 +- src/loader.c | 84 ++-- src/loader.h | 8 +- src/main.c | 52 +-- src/renderer.c | 68 ++-- src/renderer.h | 16 +- src/source-parser.c | 26 +- src/source-parser.h | 4 +- src/template-parser.c | 42 +- src/template-parser.h | 6 +- src/utils/mem.c | 42 -- src/utils/slist.c | 68 ---- src/utils/strings.c | 314 --------------- src/utils/trie.c | 199 ---------- src/utils/utils.h | 79 ---- tests/check_content_parser.c | 2 +- tests/check_error.c | 2 +- tests/check_loader.c | 544 +++++++++++++------------- tests/check_renderer.c | 288 +++++++------- tests/check_source_parser.c | 142 +++---- tests/check_template_parser.c | 80 ++-- tests/check_utils.c | 879 ------------------------------------------ 29 files changed, 885 insertions(+), 2436 deletions(-) create mode 100644 .gitmodules create mode 160000 squareball delete mode 100644 src/utils/mem.c delete mode 100644 src/utils/slist.c delete mode 100644 src/utils/strings.c delete mode 100644 src/utils/trie.c delete mode 100644 src/utils/utils.h delete mode 100644 tests/check_utils.c diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..061fb99 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "squareball"] + path = squareball + url = https://github.com/rafaelmartins/squareball.git diff --git a/Makefile.am b/Makefile.am index 832b19c..cb91a50 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,11 +1,16 @@ ## Autotools settings +if INTERNAL_SQUAREBALL +SUBDIRS = squareball +endif + ACLOCAL_AMFLAGS = -I m4 AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-tests \ --enable-ronn \ --disable-valgrind \ + --with-squareball=internal \ $(NULL) @@ -39,7 +44,6 @@ noinst_HEADERS = \ src/renderer.h \ src/source-parser.h \ src/template-parser.h \ - src/utils/utils.h \ $(NULL) noinst_LTLIBRARIES = \ @@ -66,19 +70,17 @@ 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 = \ $(AM_CFLAGS) \ -I$(top_srcdir)/src \ + $(SQUAREBALL_CFLAGS) \ $(NULL) libblogc_la_LIBADD = \ $(LIBM) \ + $(SQUAREBALL_LIBS) \ $(NULL) @@ -89,10 +91,12 @@ blogc_SOURCES = \ blogc_CFLAGS = \ $(AM_CFLAGS) \ -I$(top_srcdir)/src \ + $(SQUAREBALL_CFLAGS) \ $(NULL) blogc_LDADD = \ libblogc.la \ + $(SQUAREBALL_LIBS) \ $(NULL) @@ -167,7 +171,6 @@ check_PROGRAMS += \ tests/check_renderer \ tests/check_source_parser \ tests/check_template_parser \ - tests/check_utils \ $(NULL) tests_check_error_SOURCES = \ @@ -175,6 +178,7 @@ tests_check_error_SOURCES = \ $(NULL) tests_check_error_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -183,6 +187,7 @@ tests_check_error_LDFLAGS = \ $(NULL) tests_check_error_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -192,6 +197,7 @@ tests_check_loader_SOURCES = \ $(NULL) tests_check_loader_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -202,6 +208,7 @@ tests_check_loader_LDFLAGS = \ $(NULL) tests_check_loader_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -211,6 +218,7 @@ tests_check_content_parser_SOURCES = \ $(NULL) tests_check_content_parser_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -219,6 +227,7 @@ tests_check_content_parser_LDFLAGS = \ $(NULL) tests_check_content_parser_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -228,6 +237,7 @@ tests_check_datetime_parser_SOURCES = \ $(NULL) tests_check_datetime_parser_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -236,6 +246,7 @@ tests_check_datetime_parser_LDFLAGS = \ $(NULL) tests_check_datetime_parser_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -245,6 +256,7 @@ tests_check_renderer_SOURCES = \ $(NULL) tests_check_renderer_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -253,6 +265,7 @@ tests_check_renderer_LDFLAGS = \ $(NULL) tests_check_renderer_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -262,6 +275,7 @@ tests_check_source_parser_SOURCES = \ $(NULL) tests_check_source_parser_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -270,6 +284,7 @@ tests_check_source_parser_LDFLAGS = \ $(NULL) tests_check_source_parser_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -279,6 +294,7 @@ tests_check_template_parser_SOURCES = \ $(NULL) tests_check_template_parser_CFLAGS = \ + $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -287,23 +303,7 @@ tests_check_template_parser_LDFLAGS = \ $(NULL) tests_check_template_parser_LDADD = \ - $(CMOCKA_LIBS) \ - libblogc.la \ - $(NULL) - -tests_check_utils_SOURCES = \ - tests/check_utils.c \ - $(NULL) - -tests_check_utils_CFLAGS = \ - $(CMOCKA_CFLAGS) \ - $(NULL) - -tests_check_utils_LDFLAGS = \ - -no-install \ - $(NULL) - -tests_check_utils_LDADD = \ + $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) diff --git a/configure.ac b/configure.ac index bdb7c1e..ea03fd4 100644 --- a/configure.ac +++ b/configure.ac @@ -99,10 +99,35 @@ AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M +AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@], + [whether to use library squareball from system [default=internal]])]) +AS_IF([test "x$with_squareball" = "xsystem"], [ + PKG_CHECK_MODULES([SQUAREBALL], [squareball], [ + SQUAREBALL="system" + ], [ + AC_MSG_ERROR([library squareball requested from system but not found]) + ]) +], [ + SQUAREBALL="internal" + SQUAREBALL_CFLAGS='-I$(top_srcdir)/squareball/src' + SQUAREBALL_LIBS='$(top_builddir)/squareball/libsquareball.la' + AC_SUBST(SQUAREBALL_LIBS) + AC_SUBST(SQUAREBALL_CFLAGS) + ac_configure_args_pre="$ac_configure_args" + ac_configure_args_post="$ac_configure_args --enable-bundleme" + ac_configure_args="$ac_configure_args_post" + AC_CONFIG_COMMANDS_PRE([ac_configure_args="$ac_configure_args_pre"]) + AC_CONFIG_COMMANDS_POST([ac_configure_args="$ac_configure_args_post"]) + AC_CONFIG_SUBDIRS([squareball]) + ac_configure_args="$ac_configure_args_pre" +]) +AM_CONDITIONAL(INTERNAL_SQUAREBALL, [test "x$with_squareball" != "xsystem"]) + AC_CONFIG_FILES([ Makefile blogc.spec ]) + AC_OUTPUT AS_ECHO(" @@ -116,6 +141,7 @@ AS_ECHO(" cflags: ${CFLAGS} ldflags: ${LDFLAGS} + squareball: ${SQUAREBALL} tests: ${TESTS} ronn: ${RONN} diff --git a/squareball b/squareball new file mode 160000 index 0000000..d27a18a --- /dev/null +++ b/squareball @@ -0,0 +1 @@ +Subproject commit d27a18aa60af17504ddeb81f85407978bbbd06ed diff --git a/src/content-parser.c b/src/content-parser.c index 9d4adf6..7e2310f 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -13,7 +13,7 @@ #include #include -#include "utils/utils.h" +#include #include "content-parser.h" // this is a half ass implementation of a markdown-like syntax. bugs are @@ -25,7 +25,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') @@ -46,32 +46,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, "&"); + sb_string_append(rv, "&"); break; case '<': - b_string_append(rv, "<"); + sb_string_append(rv, "<"); break; case '>': - b_string_append(rv, ">"); + sb_string_append(rv, ">"); break; case '"': - b_string_append(rv, """); + sb_string_append(rv, """); break; case '\'': - b_string_append(rv, "'"); + sb_string_append(rv, "'"); break; case '/': - b_string_append(rv, "/"); + sb_string_append(rv, "/"); 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); } @@ -126,7 +126,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; @@ -152,7 +152,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; @@ -164,9 +164,9 @@ blogc_content_parse_inline(const char *src) if (state == LINK_TEXT_CLOSE && c != ' ' && c != '\n' && c != '\r' && c != '(') { - 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); + sb_string_append(rv, tmp); // no need to free here, we will exit the loop! break; } @@ -175,7 +175,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 (!escape) @@ -185,7 +185,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) { @@ -194,7 +194,7 @@ blogc_content_parse_inline(const char *src) (c == '_' && open_strong_und)) { if (state == LINK_CLOSED) - b_string_append(rv, ""); + sb_string_append(rv, ""); if (c == '*') open_strong_ast = false; else @@ -202,7 +202,7 @@ blogc_content_parse_inline(const char *src) break; } if (state == LINK_CLOSED) - b_string_append(rv, ""); + sb_string_append(rv, ""); if (c == '*') open_strong_ast = true; else @@ -211,7 +211,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, ""); + sb_string_append(rv, ""); if (c == '*') open_em_ast = false; else @@ -219,7 +219,7 @@ blogc_content_parse_inline(const char *src) break; } if (state == LINK_CLOSED) - b_string_append(rv, ""); + sb_string_append(rv, ""); if (c == '*') open_em_ast = true; else @@ -230,24 +230,24 @@ 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) { if (open_code || open_code_double) { - b_string_append_c(rv, c); + sb_string_append_c(rv, c); break; } if (!is_last && src[current + 1] != '[') { - b_string_append_c(rv, c); + sb_string_append_c(rv, c); break; } state = LINK_IMAGE; @@ -258,7 +258,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) { @@ -288,8 +288,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, "%s", tmp, tmp); + tmp = sb_strndup(src + start, end - start); + sb_string_append_printf(rv, "%s", tmp, tmp); end = 0; free(tmp); tmp = NULL; @@ -299,7 +299,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; @@ -307,7 +307,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 '(': @@ -317,18 +317,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, "\"%s\"", + sb_string_append_printf(rv, "\"%s\"", tmp, tmp2); else - b_string_append_printf(rv, "%s", + sb_string_append_printf(rv, "%s", tmp, tmp2); free(tmp); tmp = NULL; @@ -338,13 +338,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; @@ -353,53 +353,53 @@ blogc_content_parse_inline(const char *src) case '\r': if (state == LINK_CLOSED) { if (spaces >= 2) { - b_string_append(rv, "
"); + sb_string_append(rv, "
"); 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) - b_string_append(rv, "&"); + sb_string_append(rv, "&"); break; case '<': if (state == LINK_CLOSED) - b_string_append(rv, "<"); + sb_string_append(rv, "<"); break; case '>': if (state == LINK_CLOSED) - b_string_append(rv, ">"); + sb_string_append(rv, ">"); break; case '"': if (state == LINK_CLOSED) - b_string_append(rv, """); + sb_string_append(rv, """); break; case '\'': if (state == LINK_CLOSED) - b_string_append(rv, "'"); + sb_string_append(rv, "'"); break; case '/': if (state == LINK_CLOSED) - b_string_append(rv, "/"); + sb_string_append(rv, "/"); 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); + sb_string_append(rv, tmp); // no need to free here, its the last iteration } current++; @@ -408,7 +408,7 @@ blogc_content_parse_inline(const char *src) free(tmp); free(tmp2); - return b_string_free(rv, false); + return sb_string_free(rv, false); } @@ -468,11 +468,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; @@ -599,14 +599,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, "%s%s", + sb_string_append_printf(rv, "%s%s", header_level, parsed, header_level, line_ending); else - b_string_append_printf(rv, "%s%s", + sb_string_append_printf(rv, "%s%s", header_level, slug, parsed, header_level, line_ending); free(slug); @@ -630,8 +630,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; @@ -644,7 +644,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; @@ -652,16 +652,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); @@ -677,22 +677,22 @@ 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) { + tmp_str = sb_string_new(); + for (sb_slist_t *l = lines; 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); } tmp = blogc_content_parse(tmp_str->str, NULL); - b_string_append_printf(rv, "
%s
%s", + sb_string_append_printf(rv, "
%s
%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; @@ -708,7 +708,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; @@ -716,16 +716,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; @@ -741,18 +741,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, "
");
-                    for (b_slist_t *l = lines; l != NULL; l = l->next) {
+                    sb_string_append(rv, "
");
+                    for (sb_slist_t *l = lines; l != NULL; l = l->next) {
                         char *tmp_line = blogc_htmlentities(l->data);
                         if (l->next == NULL)
-                            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, "
%s", line_ending); - b_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%s", line_ending); + sb_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -774,7 +774,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; @@ -783,7 +783,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt) break; } if (c == '\n' || c == '\r' || is_last) { - b_string_append_printf(rv, "
%s", line_ending); + sb_string_append_printf(rv, "
%s", line_ending); state = CONTENT_START_LINE; start = current; d = '\0'; @@ -796,30 +796,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; @@ -829,8 +829,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; @@ -849,28 +849,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, "
    %s", line_ending); - for (b_slist_t *l = lines; l != NULL; l = l->next) - b_string_append_printf(rv, "
  • %s
  • %s", l->data, + sb_string_append_printf(rv, "
      %s", line_ending); + for (sb_slist_t *l = lines; l != NULL; l = l->next) + sb_string_append_printf(rv, "
    • %s
    • %s", l->data, line_ending); - b_string_append_printf(rv, "
    %s", line_ending); - b_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%s", line_ending); + sb_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -907,30 +907,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; @@ -940,8 +940,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; @@ -960,28 +960,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, "
    %s", line_ending); - for (b_slist_t *l = lines; l != NULL; l = l->next) - b_string_append_printf(rv, "
  1. %s
  2. %s", l->data, + sb_string_append_printf(rv, "
      %s", line_ending); + for (sb_slist_t *l = lines; l != NULL; l = l->next) + sb_string_append_printf(rv, "
    1. %s
    2. %s", l->data, line_ending); - b_string_append_printf(rv, "
    %s", line_ending); - b_slist_free_full(lines, free); + sb_string_append_printf(rv, "
%s", line_ending); + sb_slist_free_full(lines, free); lines = NULL; free(prefix); prefix = NULL; @@ -1005,9 +1005,9 @@ blogc_content_parse(const char *src, size_t *end_excerpt) 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, "

%s

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

%s

%s", parsed, line_ending); free(parsed); parsed = NULL; @@ -1025,5 +1025,5 @@ blogc_content_parse(const char *src, size_t *end_excerpt) current++; } - return b_string_free(rv, false); + return sb_string_free(rv, false); } diff --git a/src/datetime-parser.c b/src/datetime-parser.c index 8785a89..0aeb702 100644 --- a/src/datetime-parser.c +++ b/src/datetime-parser.c @@ -17,7 +17,7 @@ #include #include "error.h" -#include "utils/utils.h" +#include #include "datetime-parser.h" @@ -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/error.c b/src/error.c index 6256873..f05049c 100644 --- a/src/error.c +++ b/src/error.c @@ -14,16 +14,16 @@ #include #include #include -#include "utils/utils.h" +#include #include "error.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..dec7c1b 100644 --- a/src/file.c +++ b/src/file.c @@ -14,7 +14,7 @@ #include #include #include -#include "utils/utils.h" +#include #include "file.h" #include "error.h" @@ -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..8008c3a 100644 --- a/src/loader.c +++ b/src/loader.c @@ -14,7 +14,7 @@ #include #include #include -#include "utils/utils.h" +#include #include "file.h" #include "source-parser.h" #include "template-parser.h" @@ -31,7 +31,7 @@ blogc_get_filename(const char *f) if (strlen(f) == 0) return NULL; - char *filename = b_strdup(f); + char *filename = sb_strdup(f); // keep a pointer to original string char *tmp = filename; @@ -52,14 +52,14 @@ blogc_get_filename(const char *f) } } - char *final_filename = b_strdup(tmp); + char *final_filename = sb_strdup(tmp); free(filename); return final_filename; } -b_slist_t* +sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -68,13 +68,13 @@ blogc_template_parse_from_file(const char *f, blogc_error_t **err) char *s = blogc_file_get_contents(f, &len, err); if (s == NULL) return NULL; - b_slist_t *rv = blogc_template_parse(s, len, err); + sb_slist_t *rv = blogc_template_parse(s, len, err); free(s); return rv; } -b_trie_t* +sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) @@ -83,13 +83,13 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) char *s = blogc_file_get_contents(f, &len, err); if (s == NULL) return NULL; - b_trie_t *rv = blogc_source_parse(s, len, err); + sb_trie_t *rv = blogc_source_parse(s, len, err); // set FILENAME variable if (rv != NULL) { char *filename = blogc_get_filename(f); if (filename != NULL) - b_trie_insert(rv, "FILENAME", filename); + sb_trie_insert(rv, "FILENAME", filename); } free(s); @@ -97,16 +97,16 @@ blogc_source_parse_from_file(const char *f, blogc_error_t **err) } -b_slist_t* -blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) +sb_slist_t* +blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err) { blogc_error_t *tmp_err = NULL; - b_slist_t *rv = NULL; + sb_slist_t *rv = NULL; unsigned int with_date = 0; - const char *filter_tag = b_trie_lookup(conf, "FILTER_TAG"); - const char *filter_page = b_trie_lookup(conf, "FILTER_PAGE"); - const char *filter_per_page = b_trie_lookup(conf, "FILTER_PER_PAGE"); + const char *filter_tag = sb_trie_lookup(conf, "FILTER_TAG"); + const char *filter_page = sb_trie_lookup(conf, "FILTER_PAGE"); + const char *filter_per_page = sb_trie_lookup(conf, "FILTER_PER_PAGE"); long page = strtol(filter_page != NULL ? filter_page : "", NULL, 10); if (page <= 0) @@ -121,27 +121,27 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) unsigned int end = start + per_page; unsigned int counter = 0; - for (b_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { + for (sb_slist_t *tmp = l; tmp != NULL; tmp = tmp->next) { char *f = tmp->data; - b_trie_t *s = blogc_source_parse_from_file(f, &tmp_err); + sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err); if (s == NULL) { *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, "An error occurred while parsing source file: %s\n\n%s", f, tmp_err->msg); blogc_error_free(tmp_err); tmp_err = NULL; - b_slist_free_full(rv, (b_free_func_t) b_trie_free); + sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free); rv = NULL; break; } if (filter_tag != NULL) { - const char *tags_str = b_trie_lookup(s, "TAGS"); + const char *tags_str = sb_trie_lookup(s, "TAGS"); // if user wants to filter by tag and no tag is provided, skip it if (tags_str == NULL) { - b_trie_free(s); + sb_trie_free(s); continue; } - char **tags = b_str_split(tags_str, ' ', 0); + char **tags = sb_str_split(tags_str, ' ', 0); bool found = false; for (unsigned int i = 0; tags[i] != NULL; i++) { if (tags[i][0] == '\0') @@ -149,26 +149,26 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) if (0 == strcmp(tags[i], filter_tag)) found = true; } - b_strv_free(tags); + sb_strv_free(tags); if (!found) { - b_trie_free(s); + sb_trie_free(s); continue; } } if (filter_page != NULL) { if (counter < start || counter >= end) { counter++; - b_trie_free(s); + sb_trie_free(s); continue; } counter++; } - if (b_trie_lookup(s, "DATE") != NULL) + if (sb_trie_lookup(s, "DATE") != NULL) with_date++; - rv = b_slist_append(rv, s); + rv = sb_slist_append(rv, s); } - if (with_date > 0 && with_date < b_slist_length(rv)) + if (with_date > 0 && with_date < sb_slist_length(rv)) // fatal error, maybe? blogc_fprintf(stderr, "blogc: warning: 'DATE' variable provided for at least one source " @@ -176,38 +176,38 @@ blogc_source_parse_from_files(b_trie_t *conf, b_slist_t *l, blogc_error_t **err) "wrong values for 'DATE_FIRST' and 'DATE_LAST' variables.\n"); bool first = true; - for (b_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) { - b_trie_t *s = tmp->data; + for (sb_slist_t *tmp = rv; tmp != NULL; tmp = tmp->next) { + sb_trie_t *s = tmp->data; if (first) { - const char *val = b_trie_lookup(s, "DATE"); + const char *val = sb_trie_lookup(s, "DATE"); if (val != NULL) - b_trie_insert(conf, "DATE_FIRST", b_strdup(val)); - val = b_trie_lookup(s, "FILENAME"); + sb_trie_insert(conf, "DATE_FIRST", sb_strdup(val)); + val = sb_trie_lookup(s, "FILENAME"); if (val != NULL) - b_trie_insert(conf, "FILENAME_FIRST", b_strdup(val)); + sb_trie_insert(conf, "FILENAME_FIRST", sb_strdup(val)); first = false; } if (tmp->next == NULL) { // last - const char *val = b_trie_lookup(s, "DATE"); + const char *val = sb_trie_lookup(s, "DATE"); if (val != NULL) - b_trie_insert(conf, "DATE_LAST", b_strdup(val)); - val = b_trie_lookup(s, "FILENAME"); + sb_trie_insert(conf, "DATE_LAST", sb_strdup(val)); + val = sb_trie_lookup(s, "FILENAME"); if (val != NULL) - b_trie_insert(conf, "FILENAME_LAST", b_strdup(val)); + sb_trie_insert(conf, "FILENAME_LAST", sb_strdup(val)); } } if (filter_page != NULL) { unsigned int last_page = ceilf(((float) counter) / per_page); - b_trie_insert(conf, "CURRENT_PAGE", b_strdup_printf("%ld", page)); + sb_trie_insert(conf, "CURRENT_PAGE", sb_strdup_printf("%ld", page)); if (page > 1) - b_trie_insert(conf, "PREVIOUS_PAGE", b_strdup_printf("%ld", page - 1)); + sb_trie_insert(conf, "PREVIOUS_PAGE", sb_strdup_printf("%ld", page - 1)); if (page < last_page) - b_trie_insert(conf, "NEXT_PAGE", b_strdup_printf("%ld", page + 1)); - if (b_slist_length(rv) > 0) - b_trie_insert(conf, "FIRST_PAGE", b_strdup("1")); + sb_trie_insert(conf, "NEXT_PAGE", sb_strdup_printf("%ld", page + 1)); + if (sb_slist_length(rv) > 0) + sb_trie_insert(conf, "FIRST_PAGE", sb_strdup("1")); if (last_page > 0) - b_trie_insert(conf, "LAST_PAGE", b_strdup_printf("%d", last_page)); + sb_trie_insert(conf, "LAST_PAGE", sb_strdup_printf("%d", last_page)); } return rv; diff --git a/src/loader.h b/src/loader.h index c432e20..080aff6 100644 --- a/src/loader.h +++ b/src/loader.h @@ -9,13 +9,13 @@ #ifndef _LOADER_H #define _LOADER_H -#include "utils/utils.h" +#include #include "error.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/main.c b/src/main.c index f3f990b..143c836 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,7 @@ #include #include -#include "utils/utils.h" +#include #include "source-parser.h" #include "template-parser.h" #include "loader.h" @@ -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/renderer.c b/src/renderer.c index 5e07b0c..a7a7dd7 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -13,7 +13,7 @@ #include #include #include -#include "utils/utils.h" +#include #include "datetime-parser.h" #include "error.h" #include "loader.h" @@ -23,59 +23,59 @@ 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..3ff62e7 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -10,15 +10,15 @@ #define _RENDERER_H #include -#include "utils/utils.h" +#include -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..e3662a2 100644 --- a/src/source-parser.c +++ b/src/source-parser.c @@ -13,7 +13,7 @@ #include #include -#include "utils/utils.h" +#include #include "content-parser.h" #include "source-parser.h" #include "error.h" @@ -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,12 @@ 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); + tmp = sb_strndup(src + start, src_len - start); + sb_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)); + 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 +168,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 +202,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..460aedb 100644 --- a/src/source-parser.h +++ b/src/source-parser.h @@ -10,10 +10,10 @@ #define _SOURCE_PARSER_H #include -#include "utils/utils.h" +#include #include "error.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..6f23ef1 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -13,7 +13,7 @@ #include #include -#include "utils/utils.h" +#include #include "template-parser.h" #include "error.h" @@ -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..de5113e 100644 --- a/src/template-parser.h +++ b/src/template-parser.h @@ -9,7 +9,7 @@ #ifndef _TEMPLATE_PARSER_H #define _TEMPLATE_PARSER_H -#include "utils/utils.h" +#include #include "error.h" /* @@ -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/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 - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include -#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 - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#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 - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#include -#include -#include -#include -#include -#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 b8c1e63..0000000 --- a/src/utils/trie.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2016 Rafael G. Martins - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#include -#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->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 - * - * 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 -#include -#include - -#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 ea069a7..03f2213 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -16,7 +16,7 @@ #include #include #include "../src/content-parser.h" -#include "../src/utils/utils.h" +#include static void diff --git a/tests/check_error.c b/tests/check_error.c index d3af9c0..4effb08 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -16,7 +16,7 @@ #include #include #include "../src/error.h" -#include "../src/utils/utils.h" +#include static void diff --git a/tests/check_loader.c b/tests/check_loader.c index ac8bdb3..52bd056 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -18,7 +18,7 @@ #include #include "../src/template-parser.h" #include "../src/loader.h" -#include "../src/utils/utils.h" +#include 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,20 @@ 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"), "

bola

\n"); - assert_string_equal(b_trie_lookup(t, "CONTENT"), "

bola

\n"); - assert_string_equal(b_trie_lookup(t, "RAW_CONTENT"), "bola"); - b_trie_free(t); + assert_int_equal(sb_trie_size(t), 5); + 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"), "

bola

\n"); + assert_string_equal(sb_trie_lookup(t, "CONTENT"), "

bola

\n"); + assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola"); + sb_trie_free(t); } @@ -129,7 +129,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 +139,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 +181,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 +227,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 +305,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 +384,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 +462,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 +547,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 +625,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 +695,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 +735,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..e863360 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 -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" "

bola

\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..a16a923 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -17,7 +17,7 @@ #include #include "../src/source-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include static void @@ -31,23 +31,23 @@ 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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\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); + sb_trie_free(source); } @@ -62,23 +62,23 @@ 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), 5); + 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"), "

This is a test

\r\n" "

bola

\r\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\r\n" "

bola

\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); + sb_trie_free(source); } @@ -95,23 +95,23 @@ 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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\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); + sb_trie_free(source); } @@ -131,21 +131,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), 5); + 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"), "

This is a test

\n" "

bola

\n"); - assert_string_equal(b_trie_lookup(source, "CONTENT"), + assert_string_equal(sb_trie_lookup(source, "CONTENT"), "

This is a test

\n" "

bola

\n" "

guda\n" "yay

\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 +154,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); - b_trie_free(source); + sb_trie_free(source); } @@ -163,13 +163,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 +178,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 +194,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 +210,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 +226,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 +234,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 +243,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 +251,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 +260,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 +268,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 +277,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 +285,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 +294,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 +302,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 +311,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 +319,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 +328,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 +336,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 +345,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 +353,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 +362,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 +370,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 +379,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 +387,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 +396,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 +404,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 +413,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 +421,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 +430,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 +438,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 +447,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 +455,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 +464,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 +472,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); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f655896..ed4328b 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -17,11 +17,11 @@ #include #include "../src/template-parser.h" #include "../src/error.h" -#include "../src/utils/utils.h" +#include 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) " \n" "\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, "\n \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 My cool blog - Main page\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 deleted file mode 100644 index a511dda..0000000 --- a/tests/check_utils.c +++ /dev/null @@ -1,879 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2016 Rafael G. Martins - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include -#include -#include -#include - -#include - -#include "../src/utils/utils.h" - - -static void -test_slist_append(void **state) -{ - b_slist_t *l = NULL; - l = b_slist_append(l, (void*) b_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")); - 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); -} - - -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); - assert_string_equal(t1, "bola"); - assert_string_equal(t2, "guda"); - assert_string_equal(t3, "chunda"); - free(t1); - free(t2); - free(t3); -} - - -static void -test_slist_length(void **state) -{ - 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); -} - - -static void -test_strdup(void **state) -{ - char *str = b_strdup("bola"); - assert_string_equal(str, "bola"); - free(str); - str = b_strdup(NULL); - assert_null(str); -} - - -static void -test_strndup(void **state) -{ - char *str = b_strndup("bolaguda", 4); - assert_string_equal(str, "bola"); - free(str); - str = b_strndup("bolaguda", 30); - assert_string_equal(str, "bolaguda"); - free(str); - str = b_strndup("bolaguda", 8); - assert_string_equal(str, "bolaguda"); - free(str); - str = b_strdup(NULL); - assert_null(str); -} - - -static void -test_strdup_printf(void **state) -{ - char *str = b_strdup_printf("bola"); - assert_string_equal(str, "bola"); - free(str); - str = b_strdup_printf("bola, %s", "guda"); - assert_string_equal(str, "bola, guda"); - free(str); -} - - -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")); -} - - -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")); -} - - -static void -test_str_lstrip(void **state) -{ - char *str = b_strdup(" \tbola\n \t"); - assert_string_equal(b_str_lstrip(str), "bola\n \t"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_lstrip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_lstrip(str), ""); - free(str); - assert_null(b_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"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_rstrip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_rstrip(str), ""); - free(str); - assert_null(b_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"); - free(str); - str = b_strdup("guda"); - assert_string_equal(b_str_strip(str), "guda"); - free(str); - str = b_strdup("\n"); - assert_string_equal(b_str_strip(str), ""); - free(str); - str = b_strdup("\t \n"); - assert_string_equal(b_str_strip(str), ""); - free(str); - str = b_strdup(""); - assert_string_equal(b_str_strip(str), ""); - free(str); - assert_null(b_str_strip(NULL)); -} - - -static void -test_str_split(void **state) -{ - char **strv = b_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); - 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); - assert_string_equal(strv[0], "bola:guda:chunda"); - assert_null(strv[1]); - b_strv_free(strv); - strv = b_str_split("", ':', 1); - assert_null(strv[0]); - b_strv_free(strv); - assert_null(b_str_split(NULL, ':', 0)); -} - - -static void -test_str_replace(void **state) -{ - char *str = b_str_replace("bolao", 'o', "zaz"); - assert_string_equal(str, "bzazlazaz"); - free(str); - str = b_str_replace("bolao", 'b', "zaz"); - assert_string_equal(str, "zazolao"); - free(str); -} - - -static void -test_strv_join(void **state) -{ - const char *pieces[] = {"guda","bola", "chunda", NULL}; - char *str = b_strv_join(pieces, ":"); - assert_string_equal(str, "guda:bola:chunda"); - free(str); - const char *pieces2[] = {NULL}; - str = b_strv_join(pieces2, ":"); - assert_string_equal(str, ""); - free(str); - assert_null(b_strv_join(NULL, ":")); -} - - -static void -test_strv_length(void **state) -{ - char *pieces[] = {"guda","bola", "chunda", NULL}; - assert_int_equal(b_strv_length(pieces), 3); - char *pieces2[] = {NULL}; - assert_int_equal(b_strv_length(pieces2), 0); - assert_int_equal(b_strv_length(NULL), 0); -} - - -static void -test_string_new(void **state) -{ - b_string_t *str = b_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)); -} - - -static void -test_string_free(void **state) -{ - b_string_t *str = b_string_new(); - free(str->str); - str->str = b_strdup("bola"); - str->len = 4; - str->allocated_len = B_STRING_CHUNK_SIZE; - char *tmp = b_string_free(str, false); - assert_string_equal(tmp, "bola"); - free(tmp); -} - - -static void -test_string_append_len(void **state) -{ - b_string_t *str = b_string_new(); - str = b_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_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_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, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); - str = b_string_append_len(str, NULL, 0); - str = b_string_append_len(str, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); - assert_non_null(str); - assert_string_equal(str->str, - "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" - "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" - "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" - "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" - "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" - "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" - "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" - "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" - "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" - "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" - "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" - "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" - "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" - "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" - "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" - "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" - "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" - "fkeannglvsxprqzfekdinssqymtfexf"); - assert_int_equal(str->len, 1204); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10); - assert_null(b_string_free(str, true)); -} - - -static void -test_string_append(void **state) -{ - b_string_t *str = b_string_new(); - str = b_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_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, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); - str = b_string_append(str, NULL); - str = b_string_append(str, - "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" - "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" - "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" - "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" - "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" - "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" - "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" - "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" - "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); - assert_non_null(str); - assert_string_equal(str->str, - "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" - "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" - "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" - "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" - "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" - "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" - "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" - "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" - "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" - "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" - "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" - "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" - "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" - "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" - "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" - "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" - "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" - "fkeannglvsxprqzfekdinssqymtfexf"); - assert_int_equal(str->len, 1204); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 10); - assert_null(b_string_free(str, true)); -} - - -static void -test_string_append_c(void **state) -{ - b_string_t *str = b_string_new(); - str = b_string_append_len(str, "guda", 4); - for (int i = 0; i < 600; i++) - str = b_string_append_c(str, 'c'); - assert_non_null(str); - assert_string_equal(str->str, - "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" - "cccccccccccccccccccccccccccccccccccccccccccccccccccc"); - assert_int_equal(str->len, 604); - assert_int_equal(str->allocated_len, B_STRING_CHUNK_SIZE * 5); - assert_null(b_string_free(str, true)); -} - - -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); - 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)); -} - - -static void -test_trie_new(void **state) -{ - b_trie_t *trie = b_trie_new(free); - assert_non_null(trie); - assert_null(trie->root); - assert_true(trie->free_func == free); - b_trie_free(trie); -} - - -static void -test_trie_insert(void **state) -{ - b_trie_t *trie = b_trie_new(free); - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - - b_trie_insert(trie, "chu", b_strdup("nda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - - b_trie_insert(trie, "bote", b_strdup("aba")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - assert_true(trie->root->child->child->next->key == 't'); - assert_null(trie->root->child->child->next->data); - assert_true(trie->root->child->child->next->child->key == 'e'); - assert_null(trie->root->child->child->next->child->data); - assert_true(trie->root->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); - - - b_trie_insert(trie, "bo", b_strdup("haha")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->key == 'c'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'h'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'u'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->data, "nda"); - - assert_true(trie->root->child->child->next->key == 't'); - assert_null(trie->root->child->child->next->data); - assert_true(trie->root->child->child->next->child->key == 'e'); - assert_null(trie->root->child->child->next->child->data); - assert_true(trie->root->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); - - assert_true(trie->root->child->child->next->next->key == '\0'); - assert_string_equal(trie->root->child->child->next->next->data, "haha"); - - b_trie_free(trie); - - - trie = b_trie_new(free); - - b_trie_insert(trie, "chu", b_strdup("nda")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - - b_trie_insert(trie, "bote", b_strdup("aba")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->child->child->next->key == 't'); - assert_null(trie->root->next->child->child->next->data); - assert_true(trie->root->next->child->child->next->child->key == 'e'); - assert_null(trie->root->next->child->child->next->child->data); - assert_true(trie->root->next->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); - - - b_trie_insert(trie, "bo", b_strdup("haha")); - assert_true(trie->root->key == 'c'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'h'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'u'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->data, "nda"); - - assert_true(trie->root->next->key == 'b'); - assert_null(trie->root->next->data); - assert_true(trie->root->next->child->key == 'o'); - assert_null(trie->root->next->child->data); - assert_true(trie->root->next->child->child->key == 'l'); - assert_null(trie->root->next->child->child->data); - assert_true(trie->root->next->child->child->child->key == 'a'); - assert_null(trie->root->next->child->child->child->data); - assert_true(trie->root->next->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); - - assert_true(trie->root->next->child->child->next->key == 't'); - assert_null(trie->root->next->child->child->next->data); - assert_true(trie->root->next->child->child->next->child->key == 'e'); - assert_null(trie->root->next->child->child->next->child->data); - assert_true(trie->root->next->child->child->next->child->child->key == '\0'); - assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); - - assert_true(trie->root->next->child->child->next->next->key == '\0'); - assert_string_equal(trie->root->next->child->child->next->next->data, "haha"); - - b_trie_free(trie); -} - - -static void -test_trie_insert_duplicated(void **state) -{ - b_trie_t *trie = b_trie_new(free); - - b_trie_insert(trie, "bola", b_strdup("guda")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "guda"); - - b_trie_insert(trie, "bola", b_strdup("asdf")); - assert_true(trie->root->key == 'b'); - assert_null(trie->root->data); - assert_true(trie->root->child->key == 'o'); - assert_null(trie->root->child->data); - assert_true(trie->root->child->child->key == 'l'); - assert_null(trie->root->child->child->data); - assert_true(trie->root->child->child->child->key == 'a'); - assert_null(trie->root->child->child->child->data); - assert_true(trie->root->child->child->child->child->key == '\0'); - assert_string_equal(trie->root->child->child->child->child->data, "asdf"); - - b_trie_free(trie); -} - - -static void -test_trie_keep_data(void **state) -{ - b_trie_t *trie = b_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); - - b_trie_free(trie); - - assert_string_equal(t1, "guda"); - assert_string_equal(t2, "nda"); - assert_string_equal(t3, "aba"); - assert_string_equal(t4, "haha"); -} - - -static void -test_trie_lookup(void **state) -{ - b_trie_t *trie = b_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")); - - 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(b_trie_lookup(trie, "arcoiro")); - - b_trie_free(trie); - - trie = b_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")); - - 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(b_trie_lookup(trie, "arcoiro")); - - b_trie_free(trie); -} - - -static void -test_trie_size(void **state) -{ - b_trie_t *trie = b_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")); - - assert_int_equal(b_trie_size(trie), 4); - assert_int_equal(b_trie_size(NULL), 0); - - b_trie_free(trie); - - trie = b_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")); - - assert_int_equal(b_trie_size(trie), 7); - assert_int_equal(b_trie_size(NULL), 0); - - b_trie_free(trie); -} - - -static unsigned int counter; -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) -{ - assert_string_equal(key, expected_keys[counter]); - assert_string_equal((char*) data, expected_datas[counter++]); -} - - -static void -test_trie_foreach(void **state) -{ - b_trie_t *trie = b_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")); - - counter = 0; - b_trie_foreach(trie, mock_foreach); - - b_trie_free(trie); -} - - -int -main(void) -{ - const UnitTest tests[] = { - - // slist - unit_test(test_slist_append), - unit_test(test_slist_free), - unit_test(test_slist_length), - - // strings - unit_test(test_strdup), - unit_test(test_strndup), - unit_test(test_strdup_printf), - unit_test(test_str_starts_with), - unit_test(test_str_ends_with), - unit_test(test_str_lstrip), - unit_test(test_str_rstrip), - unit_test(test_str_strip), - unit_test(test_str_split), - unit_test(test_str_replace), - unit_test(test_strv_join), - unit_test(test_strv_length), - unit_test(test_string_new), - unit_test(test_string_free), - unit_test(test_string_append_len), - unit_test(test_string_append), - unit_test(test_string_append_c), - unit_test(test_string_append_printf), - - // trie - unit_test(test_trie_new), - unit_test(test_trie_insert), - unit_test(test_trie_insert_duplicated), - unit_test(test_trie_keep_data), - unit_test(test_trie_lookup), - unit_test(test_trie_size), - unit_test(test_trie_foreach), - }; - return run_tests(tests); -} -- cgit v1.2.3-18-g5258 From cf97bd1b2d86eb2e8db5c41b0999680e9e41135d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 01:48:29 +0100 Subject: readme: minor fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3622739..d005fb5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A blog compiler. ## Quickstart -Clone the [Git repository](https://github.com/blogc/blogc) or grab the [latest release](https://github.com/blogc/blogc/releases) and extract it. +Clone the [Git repository](https://github.com/blogc/blogc) (using `--recursive` to get the submodules) or grab the [latest release](https://github.com/blogc/blogc/releases) and extract it. Inside the source directory, run the following commands: -- cgit v1.2.3-18-g5258 From 6bf110510cad22b0a4e620624b70c31a179b68c9 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 02:37:57 +0100 Subject: build: use squareball m4 macro --- configure.ac | 25 ++----------------------- squareball | 2 +- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index ea03fd4..9a637a5 100644 --- a/configure.ac +++ b/configure.ac @@ -99,29 +99,8 @@ AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M -AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@], - [whether to use library squareball from system [default=internal]])]) -AS_IF([test "x$with_squareball" = "xsystem"], [ - PKG_CHECK_MODULES([SQUAREBALL], [squareball], [ - SQUAREBALL="system" - ], [ - AC_MSG_ERROR([library squareball requested from system but not found]) - ]) -], [ - SQUAREBALL="internal" - SQUAREBALL_CFLAGS='-I$(top_srcdir)/squareball/src' - SQUAREBALL_LIBS='$(top_builddir)/squareball/libsquareball.la' - AC_SUBST(SQUAREBALL_LIBS) - AC_SUBST(SQUAREBALL_CFLAGS) - ac_configure_args_pre="$ac_configure_args" - ac_configure_args_post="$ac_configure_args --enable-bundleme" - ac_configure_args="$ac_configure_args_post" - AC_CONFIG_COMMANDS_PRE([ac_configure_args="$ac_configure_args_pre"]) - AC_CONFIG_COMMANDS_POST([ac_configure_args="$ac_configure_args_post"]) - AC_CONFIG_SUBDIRS([squareball]) - ac_configure_args="$ac_configure_args_pre" -]) -AM_CONDITIONAL(INTERNAL_SQUAREBALL, [test "x$with_squareball" != "xsystem"]) +m4_include([squareball/squareball.m4]) +SQUAREBALL_INIT AC_CONFIG_FILES([ Makefile diff --git a/squareball b/squareball index d27a18a..4a189aa 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit d27a18aa60af17504ddeb81f85407978bbbd06ed +Subproject commit 4a189aacfd7e89c99330a1cd4768352b3263428c -- cgit v1.2.3-18-g5258 From f18c5d9d5c90212100936f37a739d8238edb5cc1 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 03:59:11 +0100 Subject: build: do not use macro for squareball --- configure.ac | 28 ++++++++++++++++++++++++---- squareball | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 9a637a5..54a6522 100644 --- a/configure.ac +++ b/configure.ac @@ -99,12 +99,32 @@ AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M -m4_include([squareball/squareball.m4]) -SQUAREBALL_INIT +AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@], + [whether to use library squareball from system [default=internal]])]) +AS_IF([test "x$with_squareball" = "xsystem"], [ + SQUAREBALL="system" + PKG_CHECK_MODULES([SQUAREBALL], [squareball], , [ + AC_MSG_ERROR([library squareball requested from system but not found]) + ]) +], [ + SQUAREBALL="internal" + SQUAREBALL_CFLAGS='-I$(top_srcdir)/squareball/src' + SQUAREBALL_LIBS='$(top_builddir)/squareball/libsquareball.la' + AC_SUBST(SQUAREBALL_LIBS) + AC_SUBST(SQUAREBALL_CFLAGS) + ac_configure_args_pre="$ac_configure_args" + ac_configure_args_post="$ac_configure_args --enable-bundleme" + ac_configure_args="$ac_configure_args_post" + AC_CONFIG_COMMANDS_PRE([ac_configure_args="$ac_configure_args_pre"]) + AC_CONFIG_COMMANDS_POST([ac_configure_args="$ac_configure_args_post"]) + AC_CONFIG_SUBDIRS([squareball]) + ac_configure_args="$ac_configure_args_pre" +]) +AM_CONDITIONAL(INTERNAL_SQUAREBALL, [test "x$with_squareball" != "xsystem"]) AC_CONFIG_FILES([ - Makefile - blogc.spec + Makefile + blogc.spec ]) AC_OUTPUT diff --git a/squareball b/squareball index 4a189aa..fca42df 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit 4a189aacfd7e89c99330a1cd4768352b3263428c +Subproject commit fca42dfa4e98632f50f7e3b2cc15d7abd6775435 -- cgit v1.2.3-18-g5258 From 2c08e23777ab5bd21e8a8b2c4673f900ab82fe4f Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 26 Feb 2016 04:05:14 +0100 Subject: squareball: update --- squareball | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squareball b/squareball index fca42df..48dff16 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit fca42dfa4e98632f50f7e3b2cc15d7abd6775435 +Subproject commit 48dff1601e604289563c41ba886e7f336ded08de -- cgit v1.2.3-18-g5258 From 82f81726b0a1fb04dab5e146efee26f5a06ebe32 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 28 Feb 2016 01:47:27 +0100 Subject: squareball: update --- squareball | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squareball b/squareball index 48dff16..dfa4545 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit 48dff1601e604289563c41ba886e7f336ded08de +Subproject commit dfa454598562ebb6cd0736025e933a13e3529aad -- cgit v1.2.3-18-g5258 From be4766505708291593c96d6d0fe1b4b6c3a4261d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 28 Feb 2016 04:32:51 +0100 Subject: squareball: update --- squareball | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squareball b/squareball index dfa4545..6a256ec 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit dfa454598562ebb6cd0736025e933a13e3529aad +Subproject commit 6a256ec510fd85372102607549648fe510d2e085 -- cgit v1.2.3-18-g5258 From 9ebcb6993793d6773706e961c3bb4c57ab3ff011 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 29 Feb 2016 00:37:36 +0100 Subject: squareball: update --- squareball | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squareball b/squareball index 6a256ec..dd0430e 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit 6a256ec510fd85372102607549648fe510d2e085 +Subproject commit dd0430e75fe99aa41d638827a057f90a8090572b -- cgit v1.2.3-18-g5258 From 38a2bd81f06c7e68ac40cacc2a9bc2661461a118 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 29 Feb 2016 01:31:44 +0100 Subject: build: depend on squareball >= 0.1 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 54a6522..7985692 100644 --- a/configure.ac +++ b/configure.ac @@ -103,7 +103,7 @@ AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system [whether to use library squareball from system [default=internal]])]) AS_IF([test "x$with_squareball" = "xsystem"], [ SQUAREBALL="system" - PKG_CHECK_MODULES([SQUAREBALL], [squareball], , [ + PKG_CHECK_MODULES([SQUAREBALL], [squareball >= 0.1], , [ AC_MSG_ERROR([library squareball requested from system but not found]) ]) ], [ -- cgit v1.2.3-18-g5258 From 85be5b7505f60119a6a3522b9297247c0b925326 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 29 Feb 2016 01:32:55 +0100 Subject: build: fixed error message --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7985692..1fc00aa 100644 --- a/configure.ac +++ b/configure.ac @@ -104,7 +104,7 @@ AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system AS_IF([test "x$with_squareball" = "xsystem"], [ SQUAREBALL="system" PKG_CHECK_MODULES([SQUAREBALL], [squareball >= 0.1], , [ - AC_MSG_ERROR([library squareball requested from system but not found]) + AC_MSG_ERROR([library squareball requested from system but not found or not new enough]) ]) ], [ SQUAREBALL="internal" -- cgit v1.2.3-18-g5258 From 2d179ff17bc93c49eb58d820bdf2942face1deb3 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 29 Feb 2016 03:14:36 +0100 Subject: build: version bump --- blogc.spec.in | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/blogc.spec.in b/blogc.spec.in index 5d9cbff..2f3b787 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -1,11 +1,13 @@ -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 +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: squareball-devel %description blogc(1) is a blog compiler. It converts source files and templates into @@ -30,6 +32,9 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Mon Feb 29 2016 Rafael G. Martins 0.7.6-1 +- New release. Added new dependency. + * Sun Feb 21 2016 Rafael G. Martins 0.7.5-1 - New release. -- cgit v1.2.3-18-g5258 From f7034a9c4e26933bceb9b80c6ef492b731df3d73 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 29 Feb 2016 03:28:23 +0100 Subject: build: rpm: do not use bundled squareball --- blogc.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blogc.spec.in b/blogc.spec.in index 2f3b787..1b10635 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -17,7 +17,7 @@ blog/website resources. %setup -q %build -%configure +%configure --with-squareball=system make %{?_smp_mflags} %install -- cgit v1.2.3-18-g5258 From 2bfe68f6f9fdd34588b8dde73c1a4e96c5a54b7d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:35:16 +0100 Subject: content-parser: convert -- and --- to &ndash and &mdash --- src/content-parser.c | 15 +++++++++++++++ tests/check_content_parser.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index 7e2310f..f5e3aec 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -361,6 +361,21 @@ blogc_content_parse_inline(const char *src) } break; + case '-': + if (state != LINK_CLOSED) + break; + if (current < (src_len - 1) && src[current + 1] == '-') { + if (current < (src_len - 2) && src[current + 2] == '-') { + sb_string_append(rv, "–"); + current += 2; + } + else { + sb_string_append(rv, "—"); + current += 1; + } + } + break; + case '&': if (state == LINK_CLOSED) sb_string_append(rv, "&"); diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 03f2213..bc21317 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -106,8 +106,8 @@ test_content_parse(void **state) "1. chunda\n" "3. fuuuu\n" "\n" - "+ chunda2\n" - "+ fuuuu2\n" + "- chunda2\n" + "- fuuuu2\n" "\n" "\n" "

guda\n" "yay

\n" - "

bola

\n"); + "

bola\n" + "— foo\n" + "– bar

\n" + "

— asd

\n" + "

– lol

\n"); free(html); } @@ -194,7 +204,13 @@ test_content_parse_crlf(void **state) "guda\r\n" "yay\r\n" "\r\n" - "**bola**\r\n", &l); + "**bola**\r\n" + "-- foo\r\n" + "--- bar\r\n" + "\r\n" + "-- asd\r\n" + "\r\n" + "--- lol\r\n", &l); assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, @@ -228,7 +244,11 @@ test_content_parse_crlf(void **state) "\r\n" "

guda\r\n" "yay

\r\n" - "

bola

\r\n"); + "

bola\r\n" + "— foo\r\n" + "– bar

\r\n" + "

— asd

\r\n" + "

– lol

\r\n"); free(html); } -- cgit v1.2.3-18-g5258 From de986bafd7d765e94059c0e88df93a352d85d7aa Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:39:45 +0100 Subject: content-parser: fixed a bug in previous patch --- src/content-parser.c | 3 +++ tests/check_content_parser.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index f5e3aec..e636636 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -374,6 +374,9 @@ blogc_content_parse_inline(const char *src) current += 1; } } + else { + sb_string_append_c(rv, c); + } break; case '&': diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index bc21317..d9d2528 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -117,7 +117,7 @@ test_content_parse(void **state) "yay\n" "\n" "**bola**\n" - "-- foo\n" + "-- foo-bar\n" "--- bar\n" "\n" "-- asd\n" @@ -157,7 +157,7 @@ test_content_parse(void **state) "

guda\n" "yay

\n" "

bola\n" - "— foo\n" + "— foo-bar\n" "– bar

\n" "

— asd

\n" "

– lol

\n"); @@ -205,7 +205,7 @@ test_content_parse_crlf(void **state) "yay\r\n" "\r\n" "**bola**\r\n" - "-- foo\r\n" + "-- foo-bar\r\n" "--- bar\r\n" "\r\n" "-- asd\r\n" @@ -245,7 +245,7 @@ test_content_parse_crlf(void **state) "

guda\r\n" "yay

\r\n" "

bola\r\n" - "— foo\r\n" + "— foo-bar\r\n" "– bar

\r\n" "

— asd

\r\n" "

– lol

\r\n"); -- cgit v1.2.3-18-g5258 From 1645987e132d063847aa95c0693570b44bb2d7d5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:46:40 +0100 Subject: content-parser: fixed em/en-dash logic --- src/content-parser.c | 4 ++-- tests/check_content_parser.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index e636636..0a87fcb 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -366,11 +366,11 @@ blogc_content_parse_inline(const char *src) break; if (current < (src_len - 1) && src[current + 1] == '-') { if (current < (src_len - 2) && src[current + 2] == '-') { - sb_string_append(rv, "–"); + sb_string_append(rv, "—"); current += 2; } else { - sb_string_append(rv, "—"); + sb_string_append(rv, "–"); current += 1; } } diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index d9d2528..b20f8d0 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -157,10 +157,10 @@ test_content_parse(void **state) "

guda\n" "yay

\n" "

bola\n" - "— foo-bar\n" - "– bar

\n" - "

— asd

\n" - "

– lol

\n"); + "– foo-bar\n" + "— bar

\n" + "

– asd

\n" + "

— lol

\n"); free(html); } @@ -245,10 +245,10 @@ test_content_parse_crlf(void **state) "

guda\r\n" "yay

\r\n" "

bola\r\n" - "— foo-bar\r\n" - "– bar

\r\n" - "

— asd

\r\n" - "

– lol

\r\n"); + "– foo-bar\r\n" + "— bar

\r\n" + "

– asd

\r\n" + "

— lol

\r\n"); free(html); } -- cgit v1.2.3-18-g5258 From 4c3533500058efaa2cabbe08f70e0b0a64ea3e37 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 5 Mar 2016 19:46:52 +0100 Subject: man: added em/en-dashes --- man/blogc-source.7.ronn | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn index c2c0490..c49f3ce 100644 --- a/man/blogc-source.7.ronn +++ b/man/blogc-source.7.ronn @@ -243,6 +243,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 -- cgit v1.2.3-18-g5258 From bcafe3ef16bc3114b842be66cca687850d5183b6 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 7 Mar 2016 20:36:08 +0100 Subject: added travis support --- .travis.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..38480eb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,28 @@ +dist: trusty +sudo: required +language: c + +addons: + apt: + packages: + - libcmocka-dev + - valgrind + +compiler: + - clang + - gcc + +env: + - TARGET=valgrind + - TARGET=distcheck + +install: gem install ronn + +before_script: ./autogen.sh + +script: | + mkdir build && + pushd build > /dev/null && + ../configure CFLAGS="-Wall" --enable-tests --enable-ronn --enable-valgrind --disable-silent-rules && + make $TARGET && + popd > /dev/null -- cgit v1.2.3-18-g5258 From 41b676e267c2a025012d2cd4264947d746783bfe Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 7 Mar 2016 22:50:23 +0100 Subject: travis: trying to build for windows --- .travis.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38480eb..2788f8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ language: c addons: apt: packages: + - gcc-mingw-w64-i686 + - gcc-mingw-w64-x86-64 - libcmocka-dev - valgrind @@ -15,14 +17,18 @@ compiler: env: - TARGET=valgrind - TARGET=distcheck + - TARGET=w32 + - TARGET=w64 + +matrix: + exclude: + - compiler: clang + env: TARGET=w32 + - compiler: clang + env: TARGET=w64 install: gem install ronn before_script: ./autogen.sh -script: | - mkdir build && - pushd build > /dev/null && - ../configure CFLAGS="-Wall" --enable-tests --enable-ronn --enable-valgrind --disable-silent-rules && - make $TARGET && - popd > /dev/null +script: ./build-aux/build-travis.sh -- cgit v1.2.3-18-g5258 From 2542aca4a538a37061bc80cab68ef503ac063838 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 7 Mar 2016 22:54:15 +0100 Subject: travis: actually commit the build script --- .gitignore | 1 + build-aux/build-travis.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 build-aux/build-travis.sh diff --git a/.gitignore b/.gitignore index 01d2647..33a6ebf 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ Makefile.in /stamp-h1 .dirstamp /build-aux/* +!/build-aux/build-travis.sh !/build-aux/build-windows.sh !/build-aux/git-version-gen diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh new file mode 100755 index 0000000..68f8b05 --- /dev/null +++ b/build-aux/build-travis.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -ex + +rm -rf build +mkdir -p build + +MAKE_TARGET="${TARGET}" + +if test "x${TARGET}" = "xw*"; then + unset CC + export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" + export CHOST="x86_64-w64-mingw32" + test "x${TARGET}" = "xw32" && export CHOST="i686-w64-mingw32" + MAKE_TARGET="all" +else + export CFLAGS="-Wall -g" + export CONFIGURE_ARGS="--enable-tests --enable-valgrind" +fi + +pushd build > /dev/null + +../configure \ + ${CHOST:+--host=${CHOST} --target=${CHOST}} \ + --enable-ronn \ + --disable-silent-rules \ + ${CONFIGURE_ARGS} + +popd > /dev/null + +make -C build "${MAKE_TARGET}" -- cgit v1.2.3-18-g5258 From 392b63f752103eed3febd68a49daf8a653ee5eba Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 7 Mar 2016 22:59:51 +0100 Subject: travis: remove wrong quotes from build script --- build-aux/build-travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh index 68f8b05..d178495 100755 --- a/build-aux/build-travis.sh +++ b/build-aux/build-travis.sh @@ -7,7 +7,7 @@ mkdir -p build MAKE_TARGET="${TARGET}" -if test "x${TARGET}" = "xw*"; then +if test "x${TARGET}" = xw*; then unset CC export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" export CHOST="x86_64-w64-mingw32" -- cgit v1.2.3-18-g5258 From 99661b01b0dbf6a0ccb34574f599992e714ac726 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 7 Mar 2016 23:07:36 +0100 Subject: travis: fix if statement in build script --- build-aux/build-travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh index d178495..eb6262a 100755 --- a/build-aux/build-travis.sh +++ b/build-aux/build-travis.sh @@ -7,7 +7,7 @@ mkdir -p build MAKE_TARGET="${TARGET}" -if test "x${TARGET}" = xw*; then +if [[ "x${TARGET}" = xw* ]]; then unset CC export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" export CHOST="x86_64-w64-mingw32" -- cgit v1.2.3-18-g5258 From 3ca82ea98fc46e3365c514aa3398f54df91bf329 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 04:44:43 +0100 Subject: build: added make rule to build srpm --- .travis.yml | 4 ++++ Makefile.am | 10 ++++++++++ blogc.spec.in | 4 ++-- configure.ac | 25 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2788f8d..a32e4e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: - gcc-mingw-w64-i686 - gcc-mingw-w64-x86-64 - libcmocka-dev + - rpm - valgrind compiler: @@ -17,6 +18,7 @@ compiler: env: - TARGET=valgrind - TARGET=distcheck + - TARGET=dist-srpm - TARGET=w32 - TARGET=w64 @@ -26,6 +28,8 @@ matrix: env: TARGET=w32 - compiler: clang env: TARGET=w64 + - compiler: clang + env: TARGET=dist-srpm install: gem install ronn diff --git a/Makefile.am b/Makefile.am index cb91a50..1c5388d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -314,6 +314,16 @@ 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/blogc.spec.in b/blogc.spec.in index 1b10635..dc3983e 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -1,11 +1,11 @@ Name: @PACKAGE_NAME@ -Version: @PACKAGE_VERSION@ +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%{version}/blogc-%{version}.tar.xz +Source0: https://github.com/blogc/blogc/releases/download/v@PACKAGE_VERSION@/blogc-@PACKAGE_VERSION@.tar.xz BuildRequires: squareball-devel diff --git a/configure.ac b/configure.ac index 1fc00aa..ad759c6 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"], [ @@ -145,4 +169,5 @@ AS_ECHO(" ronn: ${RONN} valgrind: ${VALGRIND} + rpmbuild: ${RPMBUILD} ") -- cgit v1.2.3-18-g5258 From 9d3ec71e43bb00e9750c53cfd8f5ac095d392f5a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 05:04:51 +0100 Subject: travis: trying to create windows zip --- build-aux/build-travis.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh index eb6262a..0d656e3 100755 --- a/build-aux/build-travis.sh +++ b/build-aux/build-travis.sh @@ -29,3 +29,17 @@ pushd build > /dev/null popd > /dev/null make -C build "${MAKE_TARGET}" + +if [[ "x${TARGET}" = xw* ]]; then + VERSION="$(grep PACKAGE_VERSION config.h | cut -d\" -f2)" + DEST_DIR="blogc-${VERSION}-${TARGET}" + + rm -rf "${DEST_DIR}" + mkdir -p "${DEST_DIR}" + + cp build/.libs/blogc.exe "${DEST_DIR}/" + cp LICENSE "${DEST_DIR}/" + cp README.md "${DEST_DIR}/" + + zip "${DEST_DIR}.zip" "${DEST_DIR}"/* +fi -- cgit v1.2.3-18-g5258 From d8f0fc6cb36a9d7c153a974b5095a4efb8c8add0 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 05:10:51 +0100 Subject: travis: minor fix --- build-aux/build-travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh index 0d656e3..d400494 100755 --- a/build-aux/build-travis.sh +++ b/build-aux/build-travis.sh @@ -31,7 +31,7 @@ popd > /dev/null make -C build "${MAKE_TARGET}" if [[ "x${TARGET}" = xw* ]]; then - VERSION="$(grep PACKAGE_VERSION config.h | cut -d\" -f2)" + VERSION="$(grep PACKAGE_VERSION build/config.h | cut -d\" -f2)" DEST_DIR="blogc-${VERSION}-${TARGET}" rm -rf "${DEST_DIR}" -- cgit v1.2.3-18-g5258 From 214d09891909ce5505d7bdbc5c848a9c4be23c0d Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 20:33:21 +0100 Subject: travis: added script to upload distfiles --- .gitignore | 6 +++-- .travis.yml | 15 +++++++++++- Makefile.am | 1 - build-aux/build-travis.sh | 45 ----------------------------------- build-aux/build-windows.sh | 48 ------------------------------------- build-aux/travis-build.sh | 47 ++++++++++++++++++++++++++++++++++++ build-aux/travis-deploy.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 97 deletions(-) delete mode 100755 build-aux/build-travis.sh delete mode 100755 build-aux/build-windows.sh create mode 100755 build-aux/travis-build.sh create mode 100755 build-aux/travis-deploy.sh diff --git a/.gitignore b/.gitignore index 33a6ebf..48f0735 100644 --- a/.gitignore +++ b/.gitignore @@ -32,9 +32,9 @@ Makefile.in /stamp-h1 .dirstamp /build-aux/* -!/build-aux/build-travis.sh -!/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 @@ -67,3 +67,5 @@ blogc-*.rpm # git-version-gen /.version + +/build/ diff --git a/.travis.yml b/.travis.yml index a32e4e1..9645b60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,11 @@ env: - TARGET=w32 - TARGET=w64 +global: + - secure: JCF5qRCiY+z7jwfCamG3v5xgQZ82MVvQPee6E3zhxMa6psp1wtPRJNx9MvXQxtjAvnOdHav5Ivo29JYFtxVdrzEM/J/R3FKRmgZ71nCw9Mf/iVjIrRHwW3ofQJ9sCwbWZi1tha7yD12qGlxDKA0cAwVuRpHy/MQDiBAmZxN7XCw= + - secure: YBCsXkVyv43DadU2xiplVPFZBRb4HXpb815he6672ESuoh5VAtIrRH7UlI5z/7BLtSv0Isb2X5rBlTWAzNM8y/Ec0cYlBlmMIBWdl2CvQQSZ8x+kIK0hkADzQboU0E7ZUw13xca1R3C88UpSKH69M8AUJpj+VPgEOT1NE+M9pfw= + - secure: Ct5BdBhRsa3cjJnPUQ48NdJR6Ih2GIJiUdJFhLxxRX4nEudVDfqFB1OOwTtbPO3/RBtPDEL8BzdnZzs7BDOOJKTpoljY4GyC7LsknNVAztWrIV9vh3K6c3UijPzIcoOxGFIPPvzAm37zyS4kzMP2+7r2mZjvr1TvmXlSL59Rruw= + matrix: exclude: - compiler: clang @@ -35,4 +40,12 @@ install: gem install ronn before_script: ./autogen.sh -script: ./build-aux/build-travis.sh +script: ./build-aux/travis-build.sh + +deploy: + provider: script + script: ./build-aux/travis-deploy.sh + skip_cleanup: true + on: + repo: blogc/blogc + branch: master diff --git a/Makefile.am b/Makefile.am index 1c5388d..9554599 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,6 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \ ## File listings EXTRA_DIST = \ - build-aux/build-windows.sh \ build-aux/git-version-gen \ $(top_srcdir)/.version \ autogen.sh \ diff --git a/build-aux/build-travis.sh b/build-aux/build-travis.sh deleted file mode 100755 index d400494..0000000 --- a/build-aux/build-travis.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -ex - -rm -rf build -mkdir -p build - -MAKE_TARGET="${TARGET}" - -if [[ "x${TARGET}" = xw* ]]; then - unset CC - export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" - export CHOST="x86_64-w64-mingw32" - test "x${TARGET}" = "xw32" && export CHOST="i686-w64-mingw32" - MAKE_TARGET="all" -else - export CFLAGS="-Wall -g" - export CONFIGURE_ARGS="--enable-tests --enable-valgrind" -fi - -pushd build > /dev/null - -../configure \ - ${CHOST:+--host=${CHOST} --target=${CHOST}} \ - --enable-ronn \ - --disable-silent-rules \ - ${CONFIGURE_ARGS} - -popd > /dev/null - -make -C build "${MAKE_TARGET}" - -if [[ "x${TARGET}" = xw* ]]; then - VERSION="$(grep PACKAGE_VERSION build/config.h | cut -d\" -f2)" - DEST_DIR="blogc-${VERSION}-${TARGET}" - - rm -rf "${DEST_DIR}" - mkdir -p "${DEST_DIR}" - - cp build/.libs/blogc.exe "${DEST_DIR}/" - cp LICENSE "${DEST_DIR}/" - cp README.md "${DEST_DIR}/" - - zip "${DEST_DIR}.zip" "${DEST_DIR}"/* -fi 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..d03cafd --- /dev/null +++ b/build-aux/travis-build.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -ex + +rm -rf build +mkdir -p build + +MAKE_TARGET="${TARGET}" + +if [[ "x${TARGET}" = xw* ]]; then + unset CC + export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" + export CHOST="x86_64-w64-mingw32" + [[ "x${TARGET}" = "xw32" ]] && export CHOST="i686-w64-mingw32" + MAKE_TARGET="all" +else + export CFLAGS="-Wall -g" + export CONFIGURE_ARGS="--enable-tests --enable-valgrind" +fi + +pushd build > /dev/null + +../configure \ + ${CHOST:+--host=${CHOST} --target=${CHOST}} \ + --enable-ronn \ + --with-squareball=internal \ + --disable-silent-rules \ + ${CONFIGURE_ARGS} + +popd > /dev/null + +make -C build "${MAKE_TARGET}" + +if [[ "x${TARGET}" = xw* ]]; then + TARNAME="$(grep PACKAGE_TARNAME build/config.h | cut -d\" -f2)" + VERSION="$(grep PACKAGE_VERSION build/config.h | cut -d\" -f2)" + DEST_DIR="${TARNAME}-${VERSION}-${TARGET}" + + rm -rf "${DEST_DIR}" + mkdir -p "${DEST_DIR}" + + cp build/.libs/blogc.exe "${DEST_DIR}/" + cp LICENSE "${DEST_DIR}/" + cp README.md "${DEST_DIR}/" + + zip "build/${DEST_DIR}.zip" "${DEST_DIR}"/* +fi diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh new file mode 100755 index 0000000..267c8d5 --- /dev/null +++ b/build-aux/travis-deploy.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]]; then + echo "Nothing to deploy." + exit 0 +fi + +if [[ ! -d build ]]; then + echo "Build directory not found." + exit 1 +fi + +if [[ "x${TARGET}" = xw* ]]; then + FILES=( build/*.zip ) +elif [[ "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 -- cgit v1.2.3-18-g5258 From b8206af55ad7143fecb8c82e549571466b53680f Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 23:44:04 +0100 Subject: travis: temporary remove --silent from curl call --- build-aux/travis-deploy.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index 267c8d5..a959ccb 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -25,7 +25,6 @@ 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}" \ -- cgit v1.2.3-18-g5258 From a65ffc6535d26d87d14a2a0f96bcd61e6783e831 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 8 Mar 2016 23:52:01 +0100 Subject: travis: removed encrypted vars from .travis.yml --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9645b60..596f9db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,11 +22,6 @@ env: - TARGET=w32 - TARGET=w64 -global: - - secure: JCF5qRCiY+z7jwfCamG3v5xgQZ82MVvQPee6E3zhxMa6psp1wtPRJNx9MvXQxtjAvnOdHav5Ivo29JYFtxVdrzEM/J/R3FKRmgZ71nCw9Mf/iVjIrRHwW3ofQJ9sCwbWZi1tha7yD12qGlxDKA0cAwVuRpHy/MQDiBAmZxN7XCw= - - secure: YBCsXkVyv43DadU2xiplVPFZBRb4HXpb815he6672ESuoh5VAtIrRH7UlI5z/7BLtSv0Isb2X5rBlTWAzNM8y/Ec0cYlBlmMIBWdl2CvQQSZ8x+kIK0hkADzQboU0E7ZUw13xca1R3C88UpSKH69M8AUJpj+VPgEOT1NE+M9pfw= - - secure: Ct5BdBhRsa3cjJnPUQ48NdJR6Ih2GIJiUdJFhLxxRX4nEudVDfqFB1OOwTtbPO3/RBtPDEL8BzdnZzs7BDOOJKTpoljY4GyC7LsknNVAztWrIV9vh3K6c3UijPzIcoOxGFIPPvzAm37zyS4kzMP2+7r2mZjvr1TvmXlSL59Rruw= - matrix: exclude: - compiler: clang -- cgit v1.2.3-18-g5258 From 847aab8299bcff9d259aa5b6eb4686ae4f2fb763 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 9 Mar 2016 00:10:36 +0100 Subject: travis: optimize --- build-aux/travis-deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index a959ccb..65f162e 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -2,7 +2,7 @@ set -e -if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]]; then +if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]] && [[ "x${CC}" != xgcc ]]; then echo "Nothing to deploy." exit 0 fi @@ -25,6 +25,7 @@ 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}" \ -- cgit v1.2.3-18-g5258 From 70f1a705c4b12486dd75a4f61aeae730772b5e84 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 9 Mar 2016 00:22:41 +0100 Subject: travis: optimize --- .travis.yml | 1 + build-aux/travis-deploy.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 596f9db..84d8680 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,3 +44,4 @@ deploy: on: repo: blogc/blogc branch: master + condition: $CC = gcc diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index 65f162e..267c8d5 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -2,7 +2,7 @@ set -e -if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]] && [[ "x${CC}" != xgcc ]]; then +if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]]; then echo "Nothing to deploy." exit 0 fi -- cgit v1.2.3-18-g5258 From 9d11a1781e47d64eb8ba2f8ad6f5ab6927e0c989 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 9 Mar 2016 03:26:19 +0100 Subject: readme: added travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d005fb5..cce4fc4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # blogc -[![Build Status](https://jenkins.rgm.io/buildStatus/icon?job=blogc-tests)](https://jenkins.rgm.io/job/blogc-tests/) +[![Build Status](https://travis-ci.org/blogc/blogc.svg?branch=master)](https://travis-ci.org/blogc/blogc) A blog compiler. -- cgit v1.2.3-18-g5258 From 06db24fefadef5056cc2e14b9791a95614ba9ff2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 9 Mar 2016 03:44:56 +0100 Subject: spec: fixed source dir --- Makefile.am | 1 + blogc.spec.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 9554599..a0559ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -314,6 +314,7 @@ TESTS = \ ## Helpers: dist-srpm + if USE_RPMBUILD dist-srpm: blogc.spec dist-xz $(RPMBUILD) \ diff --git a/blogc.spec.in b/blogc.spec.in index dc3983e..142e4f0 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -14,7 +14,7 @@ blogc(1) is a blog compiler. It converts source files and templates into blog/website resources. %prep -%setup -q +%setup -q -n @PACKAGE_NAME@-@PACKAGE_VERSION@ %build %configure --with-squareball=system -- cgit v1.2.3-18-g5258 From 3ead966f48bc47444d7ec72f46e94e73557695a5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 9 Mar 2016 22:22:48 +0100 Subject: travis: improved deploy conditions --- .travis.yml | 4 +++- build-aux/travis-deploy.sh | 5 ----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84d8680..cd2d134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,4 +44,6 @@ deploy: on: repo: blogc/blogc branch: master - condition: $CC = gcc + condition: + - $CC = gcc + - $TARGET != valgrind diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index 267c8d5..71469ff 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -2,11 +2,6 @@ set -e -if [[ "x${TARGET}" != xw* ]] && [[ "x${TARGET}" != xdist* ]]; then - echo "Nothing to deploy." - exit 0 -fi - if [[ ! -d build ]]; then echo "Build directory not found." exit 1 -- cgit v1.2.3-18-g5258 From a2b3551dfb9460470bd79f5648bf597c517c40d4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 13 Mar 2016 01:48:49 +0100 Subject: *: use squareball error infrastructure --- squareball | 2 +- src/datetime-parser.c | 58 ++++++------ src/datetime-parser.h | 2 +- src/error.c | 47 ++------- src/error.h | 15 +-- src/file.c | 4 +- src/file.h | 2 +- src/loader.c | 12 +-- src/loader.h | 6 +- src/main.c | 4 +- src/renderer.c | 4 +- src/source-parser.c | 4 +- src/source-parser.h | 2 +- src/template-parser.c | 8 +- src/template-parser.h | 2 +- tests/check_datetime_parser.c | 216 +++++++++++++++++++++--------------------- tests/check_error.c | 44 ++++----- tests/check_loader.c | 30 +++--- tests/check_renderer.c | 40 ++++---- tests/check_source_parser.c | 122 ++++++++++++------------ tests/check_template_parser.c | 190 ++++++++++++++++++------------------- 21 files changed, 387 insertions(+), 427 deletions(-) diff --git a/squareball b/squareball index dd0430e..ebc0247 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit dd0430e75fe99aa41d638827a057f90a8090572b +Subproject commit ebc02478a78c83e5e62afc485a294e1c78442dbe diff --git a/src/datetime-parser.c b/src/datetime-parser.c index 0aeb702..0fa7aaf 100644 --- a/src/datetime-parser.c +++ b/src/datetime-parser.c @@ -47,14 +47,14 @@ typedef enum { char* blogc_convert_datetime(const char *orig, const char *format, - blogc_error_t **err) + sb_error_t **err) { if (err == NULL || *err != NULL) return NULL; #ifndef HAVE_TIME_H - *err = blogc_error_new(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new(BLOGC_WARNING_DATETIME_PARSER, "Your operating system does not supports the datetime functionalities " "used by blogc. Sorry."); return NULL; @@ -80,7 +80,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_YEAR; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -91,7 +91,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_THIRD_YEAR; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -102,7 +102,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FOURTH_YEAR; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid third digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -111,7 +111,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff - 1900; if (tmp < 0) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid year. Found %d, must be >= 1900.", tmp + 1900); break; @@ -120,7 +120,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_HYPHEN; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid fourth digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -131,7 +131,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_MONTH; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between year and month. " "Found '%c', must be '-'.", c); break; @@ -142,7 +142,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_MONTH; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of month. " "Found '%c', must be integer >= 0 and <= 1.", c); break; @@ -151,7 +151,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff - 1; if (tmp < 0 || tmp > 11) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid month. Found %d, must be >= 1 and <= 12.", tmp + 1); break; @@ -160,7 +160,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_HYPHEN; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of month. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -171,7 +171,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_DAY; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between month and day. " "Found '%c', must be '-'.", c); break; @@ -182,7 +182,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_DAY; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of day. " "Found '%c', must be integer >= 0 and <= 3.", c); break; @@ -191,7 +191,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 1 || tmp > 31) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid day. Found %d, must be >= 1 and <= 31.", tmp); break; @@ -200,7 +200,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SPACE; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of day. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -211,7 +211,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_HOUR; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between date and time. " "Found '%c', must be ' ' (empty space).", c); break; @@ -222,7 +222,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_HOUR; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of hours. " "Found '%c', must be integer >= 0 and <= 2.", c); break; @@ -231,7 +231,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 0 || tmp > 23) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid hours. Found %d, must be >= 0 and <= 23.", tmp); break; @@ -240,7 +240,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_COLON; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of hours. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -251,7 +251,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_MINUTE; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between hours and minutes. " "Found '%c', must be ':'.", c); break; @@ -262,7 +262,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_MINUTE; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of minutes. " "Found '%c', must be integer >= 0 and <= 5.", c); break; @@ -274,7 +274,7 @@ blogc_convert_datetime(const char *orig, const char *format, // this won't happen because we are restricting the digits // to 00-59 already, but lets keep the code here for // reference. - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid minutes. Found %d, must be >= 0 and <= 59.", tmp); break; @@ -283,7 +283,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_COLON; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of minutes. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -294,7 +294,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_SECOND; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between minutes and seconds. " "Found '%c', must be ':'.", c); break; @@ -305,7 +305,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_SECOND; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of seconds. " "Found '%c', must be integer >= 0 and <= 6.", c); break; @@ -314,7 +314,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 0 || tmp > 60) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid seconds. Found %d, must be >= 0 and <= 60.", tmp); break; @@ -323,7 +323,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_DONE; break; } - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of seconds. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -355,7 +355,7 @@ blogc_convert_datetime(const char *orig, const char *format, case DATETIME_SECOND_MINUTE: case DATETIME_FIRST_SECOND: case DATETIME_SECOND_SECOND: - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid datetime string. " "Found '%s', formats allowed are: 'yyyy-mm-dd hh:mm:ss', " "'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and 'yyyy-mm-dd'.", @@ -374,7 +374,7 @@ blogc_convert_datetime(const char *orig, const char *format, char buf[1024]; if (0 == strftime(buf, sizeof(buf), format, &t)) { - *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Failed to format DATE variable, FORMAT is too long: %s", format); return NULL; diff --git a/src/datetime-parser.h b/src/datetime-parser.h index a5087b3..b2e65a1 100644 --- a/src/datetime-parser.h +++ b/src/datetime-parser.h @@ -12,6 +12,6 @@ #include "error.h" char* blogc_convert_datetime(const char *orig, const char *format, - blogc_error_t **err); + sb_error_t **err); #endif /* _DATETIME_H */ diff --git a/src/error.c b/src/error.c index f05049c..619ae01 100644 --- a/src/error.c +++ b/src/error.c @@ -18,31 +18,8 @@ #include "error.h" -blogc_error_t* -blogc_error_new(blogc_error_type_t type, const char *msg) -{ - blogc_error_t *err = sb_malloc(sizeof(blogc_error_t)); - err->type = type; - err->msg = sb_strdup(msg); - return err; -} - - -blogc_error_t* -blogc_error_new_printf(blogc_error_type_t type, const char *format, ...) -{ - va_list ap; - va_start(ap, format); - char *tmp = sb_strdup_vprintf(format, ap); - va_end(ap); - blogc_error_t *rv = blogc_error_new(type, tmp); - free(tmp); - return rv; -} - - -blogc_error_t* -blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, +sb_error_t* +blogc_error_parser(blogc_error_code_t type, const char *src, size_t src_len, size_t current, const char *format, ...) { va_list ap; @@ -90,12 +67,12 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, char *line = sb_strndup(src + linestart, lineend - linestart); - blogc_error_t *rv = NULL; + sb_error_t *rv = NULL; if (line[0] == '\0') // "near" message isn't useful if line is empty - rv = blogc_error_new(type, msg); + rv = sb_error_new(type, msg); else - rv = blogc_error_new_printf(type, + rv = sb_error_new_printf(type, "%s\nError occurred near line %d, position %d: %s", msg, lineno, pos, line); @@ -107,12 +84,12 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, void -blogc_error_print(blogc_error_t *err) +blogc_error_print(sb_error_t *err) { if (err == NULL) return; - switch(err->type) { + switch(err->code) { case BLOGC_ERROR_SOURCE_PARSER: fprintf(stderr, "blogc: error: source: %s\n", err->msg); break; @@ -129,13 +106,3 @@ blogc_error_print(blogc_error_t *err) fprintf(stderr, "blogc: error: %s\n", err->msg); } } - - -void -blogc_error_free(blogc_error_t *err) -{ - if (err == NULL) - return; - free(err->msg); - free(err); -} diff --git a/src/error.h b/src/error.h index caa86b0..e02afed 100644 --- a/src/error.h +++ b/src/error.h @@ -11,24 +11,17 @@ #include #include +#include typedef enum { BLOGC_ERROR_SOURCE_PARSER = 1, BLOGC_ERROR_TEMPLATE_PARSER, BLOGC_ERROR_LOADER, BLOGC_WARNING_DATETIME_PARSER, -} blogc_error_type_t; +} blogc_error_code_t; -typedef struct { - char *msg; - blogc_error_type_t type; -} blogc_error_t; - -blogc_error_t* blogc_error_new(blogc_error_type_t type, const char *msg); -blogc_error_t* blogc_error_new_printf(blogc_error_type_t type, const char *format, ...); -blogc_error_t* blogc_error_parser(blogc_error_type_t type, const char *src, +sb_error_t* blogc_error_parser(blogc_error_code_t type, const char *src, size_t src_len, size_t current, const char *format, ...); -void blogc_error_print(blogc_error_t *err); -void blogc_error_free(blogc_error_t *err); +void blogc_error_print(sb_error_t *err); #endif /* _ERROR_H */ diff --git a/src/file.c b/src/file.c index dec7c1b..972f433 100644 --- a/src/file.c +++ b/src/file.c @@ -23,7 +23,7 @@ char* -blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) +blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) { if (path == NULL || err == NULL || *err != NULL) return NULL; @@ -33,7 +33,7 @@ blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) if (fp == NULL) { int tmp_errno = errno; - *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, + *err = sb_error_new_printf(BLOGC_ERROR_LOADER, "Failed to open file (%s): %s", path, strerror(tmp_errno)); return NULL; } diff --git a/src/file.h b/src/file.h index 97e5274..9c0674d 100644 --- a/src/file.h +++ b/src/file.h @@ -15,7 +15,7 @@ #define BLOGC_FILE_CHUNK_SIZE 1024 -char* blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err); +char* blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err); int blogc_fprintf(FILE *stream, const char *format, ...); #endif /* _FILE_H */ diff --git a/src/loader.c b/src/loader.c index 8008c3a..fd184e5 100644 --- a/src/loader.c +++ b/src/loader.c @@ -60,7 +60,7 @@ blogc_get_filename(const char *f) sb_slist_t* -blogc_template_parse_from_file(const char *f, blogc_error_t **err) +blogc_template_parse_from_file(const char *f, sb_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -75,7 +75,7 @@ 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) +blogc_source_parse_from_file(const char *f, sb_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -98,9 +98,9 @@ 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) +blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, sb_error_t **err) { - blogc_error_t *tmp_err = NULL; + sb_error_t *tmp_err = NULL; sb_slist_t *rv = NULL; unsigned int with_date = 0; @@ -125,10 +125,10 @@ blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **er char *f = tmp->data; sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err); if (s == NULL) { - *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, + *err = sb_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); + sb_error_free(tmp_err); tmp_err = NULL; sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free); rv = NULL; diff --git a/src/loader.h b/src/loader.h index 080aff6..8b0460e 100644 --- a/src/loader.h +++ b/src/loader.h @@ -13,9 +13,9 @@ #include "error.h" char* blogc_get_filename(const char *f); -sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err); -sb_trie_t* blogc_source_parse_from_file(const char *f, blogc_error_t **err); +sb_slist_t* blogc_template_parse_from_file(const char *f, sb_error_t **err); +sb_trie_t* blogc_source_parse_from_file(const char *f, sb_error_t **err); sb_slist_t* blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, - blogc_error_t **err); + sb_error_t **err); #endif /* _LOADER_H */ diff --git a/src/main.c b/src/main.c index 143c836..709b37e 100644 --- a/src/main.c +++ b/src/main.c @@ -210,7 +210,7 @@ main(int argc, char **argv) goto cleanup; } - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { @@ -274,7 +274,7 @@ cleanup3: blogc_template_free_stmts(l); cleanup2: sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); - blogc_error_free(err); + sb_error_free(err); cleanup: sb_trie_free(config); free(template); diff --git a/src/renderer.c b/src/renderer.c index a7a7dd7..eb58e0d 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -46,11 +46,11 @@ blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local) if (date_format == NULL) return sb_strdup(date); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *rv = blogc_convert_datetime(date, date_format, &err); if (err != NULL) { blogc_error_print(err); - blogc_error_free(err); + sb_error_free(err); return sb_strdup(date); } return rv; diff --git a/src/source-parser.c b/src/source-parser.c index e3662a2..1047f06 100644 --- a/src/source-parser.c +++ b/src/source-parser.c @@ -31,7 +31,7 @@ typedef enum { sb_trie_t* -blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) +blogc_source_parse(const char *src, size_t src_len, sb_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -97,7 +97,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) ((current - start == 13) && (0 == strncmp("BLOGC_VERSION", src + start, 13)))) { - *err = blogc_error_new_printf(BLOGC_ERROR_SOURCE_PARSER, + *err = sb_error_new_printf(BLOGC_ERROR_SOURCE_PARSER, "'%s' variable is forbidden in source files. It will " "be set for you by the compiler.", key); break; diff --git a/src/source-parser.h b/src/source-parser.h index 460aedb..fb5306c 100644 --- a/src/source-parser.h +++ b/src/source-parser.h @@ -14,6 +14,6 @@ #include "error.h" sb_trie_t* blogc_source_parse(const char *src, size_t src_len, - blogc_error_t **err); + sb_error_t **err); #endif /* _SOURCE_PARSER_H */ diff --git a/src/template-parser.c b/src/template-parser.c index 6f23ef1..d61f90a 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -53,7 +53,7 @@ typedef enum { sb_slist_t* -blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) +blogc_template_parse(const char *src, size_t src_len, sb_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -597,14 +597,14 @@ blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, start2 - 1, "Found an open double-quoted string."); else if (if_count != 0) - *err = blogc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER, + *err = sb_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER, "%d open 'ifdef' and/or 'ifndef' statements were not closed!", if_count); else if (block_state != BLOCK_CLOSED) - *err = blogc_error_new(BLOGC_ERROR_TEMPLATE_PARSER, + *err = sb_error_new(BLOGC_ERROR_TEMPLATE_PARSER, "An open block was not closed!"); else if (foreach_open) - *err = blogc_error_new(BLOGC_ERROR_TEMPLATE_PARSER, + *err = sb_error_new(BLOGC_ERROR_TEMPLATE_PARSER, "An open 'foreach' statement was not closed!"); } diff --git a/src/template-parser.h b/src/template-parser.h index de5113e..88b46e9 100644 --- a/src/template-parser.h +++ b/src/template-parser.h @@ -45,7 +45,7 @@ typedef struct { } blogc_template_stmt_t; sb_slist_t* blogc_template_parse(const char *src, size_t src_len, - blogc_error_t **err); + sb_error_t **err); void blogc_template_free_stmts(sb_slist_t *stmts); #endif /* _TEMPLATE_GRAMMAR_H */ diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c index ba5a79d..aef366e 100644 --- a/tests/check_datetime_parser.c +++ b/tests/check_datetime_parser.c @@ -24,7 +24,7 @@ static void test_convert_datetime(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -36,7 +36,7 @@ test_convert_datetime(void **state) static void test_convert_datetime_implicit_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -48,7 +48,7 @@ test_convert_datetime_implicit_seconds(void **state) static void test_convert_datetime_implicit_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -60,7 +60,7 @@ test_convert_datetime_implicit_minutes(void **state) static void test_convert_datetime_implicit_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -72,529 +72,529 @@ test_convert_datetime_implicit_hours(void **state) static void test_convert_datetime_invalid_formats(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '20', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '201', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-3', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 ', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("a010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2a10-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_3rd_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("20a0-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_4th_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("201a-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_year(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("1899-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid year. Found 1899, must be >= 1900."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_hyphen(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010 11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between year and month. Found ' ', must be '-'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-a1-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-1a-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_month(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-13-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid month. Found 13, must be >= 1 and <= 12."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_hyphen(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11 30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between month and day. Found ' ', must be '-'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-a0 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-3a 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_day(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-32 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid day. Found 32, must be >= 1 and <= 31."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_space(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30-12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between date and time. Found '-', must be ' ' " "(empty space)."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 a2:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 1a:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_hours(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 24:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid hours. Found 24, must be >= 0 and <= 23."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_colon(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12 13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between hours and minutes. Found ' ', must be ':'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:a3:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_minutes(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:1a:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_colon(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13 14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between minutes and seconds. Found ' ', must be ':'."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_1st_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:a4", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_2nd_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:1a", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_seconds(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:69", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid seconds. Found 69, must be >= 0 and <= 60."); - blogc_error_free(err); + sb_error_free(err); } static void test_convert_datetime_invalid_format_long(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:14", "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk" @@ -613,7 +613,7 @@ test_convert_datetime_invalid_format_long(void **state) "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Failed to format DATE variable, FORMAT is too long: " "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" @@ -631,7 +631,7 @@ test_convert_datetime_invalid_format_long(void **state) "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq" "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj" "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg"); - blogc_error_free(err); + sb_error_free(err); } diff --git a/tests/check_error.c b/tests/check_error.c index 4effb08..7fc3c3e 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -22,22 +22,22 @@ static void test_error_new(void **state) { - blogc_error_t *error = blogc_error_new(1, "bola %s"); + sb_error_t *error = sb_error_new(1, "bola %s"); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "bola %s"); - blogc_error_free(error); + sb_error_free(error); } static void test_error_new_printf(void **state) { - blogc_error_t *error = blogc_error_new_printf(2, "bola %s", "guda"); + sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); assert_non_null(error); - assert_int_equal(error->type, 2); + assert_int_equal(error->code, 2); assert_string_equal(error->msg, "bola guda"); - blogc_error_free(error); + sb_error_free(error); } @@ -45,32 +45,32 @@ static void test_error_parser(void **state) { const char *a = "bola\nguda\nchunda\n"; - blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); + sb_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - blogc_error_free(error); + sb_error_free(error); a = ""; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10"); - blogc_error_free(error); + sb_error_free(error); } @@ -78,26 +78,26 @@ static void test_error_parser_crlf(void **state) { const char *a = "bola\r\nguda\r\nchunda\r\n"; - blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); + sb_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - blogc_error_free(error); + sb_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->type, 1); + assert_int_equal(error->code, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - blogc_error_free(error); + sb_error_free(error); } diff --git a/tests/check_loader.c b/tests/check_loader.c index 52bd056..0db6194 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -52,7 +52,7 @@ test_get_filename(void **state) char* -__wrap_blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) +__wrap_blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) { assert_null(*err); const char *_path = mock_type(const char*); @@ -78,7 +78,7 @@ __wrap_blogc_fprintf(FILE *stream, const char *format, ...) static void test_template_parse_from_file(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n")); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -92,7 +92,7 @@ test_template_parse_from_file(void **state) static void test_template_parse_from_file_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, NULL); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -104,7 +104,7 @@ test_template_parse_from_file_null(void **state) static void test_source_parse_from_file(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" @@ -126,7 +126,7 @@ test_source_parse_from_file(void **state) static void test_source_parse_from_file_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, NULL); sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); @@ -156,7 +156,7 @@ test_source_parse_from_files(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -200,7 +200,7 @@ test_source_parse_from_files_filter_by_tag(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -268,7 +268,7 @@ test_source_parse_from_files_filter_by_page(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -346,7 +346,7 @@ test_source_parse_from_files_filter_by_page2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -425,7 +425,7 @@ test_source_parse_from_files_filter_by_page3(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -508,7 +508,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) "TAGS: yay chunda\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -588,7 +588,7 @@ test_source_parse_from_files_filter_by_page_invalid(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -666,7 +666,7 @@ test_source_parse_from_files_filter_by_page_invalid2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -711,7 +711,7 @@ test_source_parse_from_files_without_all_dates(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -734,7 +734,7 @@ test_source_parse_from_files_without_all_dates(void **state) static void test_source_parse_from_files_null(void **state) { - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *s = NULL; sb_trie_t *c = sb_trie_new(free); sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); diff --git a/tests/check_renderer.c b/tests/check_renderer.c index e863360..d71f045 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -46,7 +46,7 @@ create_sources(unsigned int count) "ahahahahahahahaha3", }; assert_false(count > 3); - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = NULL; for (unsigned int i = 0; i < count; i++) { l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); @@ -78,7 +78,7 @@ test_render_entry(void **state) "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -125,7 +125,7 @@ test_render_listing(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -173,7 +173,7 @@ test_render_listing_empty(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -200,7 +200,7 @@ test_render_ifdef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -229,7 +229,7 @@ test_render_ifdef2(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -260,7 +260,7 @@ test_render_ifdef3(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -293,7 +293,7 @@ test_render_ifndef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -327,7 +327,7 @@ test_render_if_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -362,7 +362,7 @@ test_render_if_neq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -397,7 +397,7 @@ test_render_if_lt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -432,7 +432,7 @@ test_render_if_gt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -469,7 +469,7 @@ test_render_if_lt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -508,7 +508,7 @@ test_render_if_gt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -539,7 +539,7 @@ test_render_foreach(void **state) "{% block entry %}\n" "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -564,7 +564,7 @@ test_render_foreach_if(void **state) "{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}" "{% endif %} {% endforeach %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -595,7 +595,7 @@ test_render_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}lol{% endif %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -628,7 +628,7 @@ test_render_prefer_local_variable(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -664,7 +664,7 @@ test_render_respect_variable_scope(void **state) "{% ifdef LOL %}{{ LOL }}{% endif %}\n" "{% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -696,7 +696,7 @@ test_render_ifcount_bug(void **state) "{% ifdef ASD %}ASD{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index a16a923..fba997a 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -30,7 +30,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -61,7 +61,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -94,7 +94,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -130,7 +130,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -162,13 +162,13 @@ static void test_source_parse_config_empty(void **state) { const char *a = ""; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your source file is empty."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -177,14 +177,14 @@ static void test_source_parse_config_invalid_key(void **state) { const char *a = "bola: guda"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -193,14 +193,14 @@ static void test_source_parse_config_no_key(void **state) { const char *a = "BOLa"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -209,14 +209,14 @@ static void test_source_parse_config_no_key2(void **state) { const char *a = "BOLA"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, 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); + sb_error_free(err); sb_trie_free(source); } @@ -225,15 +225,15 @@ static void test_source_parse_config_no_value(void **state) { const char *a = "BOLA:\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -242,15 +242,15 @@ static void test_source_parse_config_no_value2(void **state) { const char *a = "BOLA:"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -259,15 +259,15 @@ static void test_source_parse_config_reserved_name(void **state) { const char *a = "FILENAME: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'FILENAME' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -276,15 +276,15 @@ static void test_source_parse_config_reserved_name2(void **state) { const char *a = "CONTENT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'CONTENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -293,15 +293,15 @@ static void test_source_parse_config_reserved_name3(void **state) { const char *a = "DATE_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -310,15 +310,15 @@ static void test_source_parse_config_reserved_name4(void **state) { const char *a = "DATE_FIRST_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -327,15 +327,15 @@ static void test_source_parse_config_reserved_name5(void **state) { const char *a = "DATE_LAST_FORMATTED: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -344,15 +344,15 @@ static void test_source_parse_config_reserved_name6(void **state) { const char *a = "PAGE_FIRST: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_FIRST' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -361,15 +361,15 @@ static void test_source_parse_config_reserved_name7(void **state) { const char *a = "PAGE_PREVIOUS: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -378,15 +378,15 @@ static void test_source_parse_config_reserved_name8(void **state) { const char *a = "PAGE_CURRENT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_CURRENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -395,15 +395,15 @@ static void test_source_parse_config_reserved_name9(void **state) { const char *a = "PAGE_NEXT: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_NEXT' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -412,15 +412,15 @@ static void test_source_parse_config_reserved_name10(void **state) { const char *a = "PAGE_LAST: asd\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_LAST' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -429,15 +429,15 @@ static void test_source_parse_config_reserved_name11(void **state) { const char *a = "BLOGC_VERSION: 1.0\r\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'BLOGC_VERSION' variable is forbidden in source files. It will be set " "for you by the compiler."); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -446,15 +446,15 @@ static void test_source_parse_config_value_no_line_ending(void **state) { const char *a = "BOLA: asd"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "No line ending after the configuration value for 'BOLA'.\n" "Error occurred near line 1, position 10: BOLA: asd"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } @@ -463,15 +463,15 @@ static void test_source_parse_invalid_separator(void **state) { const char *a = "BOLA: asd\n---#"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid content separator. Must be more than one '-' characters.\n" "Error occurred near line 2, position 4: ---#"); - blogc_error_free(err); + sb_error_free(err); sb_trie_free(source); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index ed4328b..9419607 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -63,7 +63,7 @@ test_template_parse(void **state) "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -143,7 +143,7 @@ test_template_parse_crlf(void **state) "{% block listing_once %}asd{% endblock %}\r\n" "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -231,7 +231,7 @@ test_template_parse_html(void **state) " {% block listing_once %}{% endblock %}\n" " \n" "\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -341,7 +341,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -372,35 +372,35 @@ static void test_template_parse_invalid_block_start(void **state) { const char *a = "{% ASD %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); - blogc_error_free(err); + sb_error_free(err); a = "{%-- block entry %}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" "Error occurred near line 1, position 4: {%-- block entry %}"); - blogc_error_free(err); + sb_error_free(err); a = "{% block entry --%}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" "Error occurred near line 1, position 17: {% block entry --%}"); - blogc_error_free(err); + sb_error_free(err); } @@ -410,15 +410,15 @@ test_template_parse_invalid_block_nested(void **state) const char *a = "{% block entry %}\n" "{% block listing %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Blocks can't be nested.\n" "Error occurred near line 2, position 9: {% block listing %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -428,15 +428,15 @@ test_template_parse_invalid_foreach_nested(void **state) const char *a = "{% foreach A %}\n" "{% foreach B %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'foreach' statements can't be nested.\n" "Error occurred near line 2, position 11: {% foreach B %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -444,15 +444,15 @@ static void test_template_parse_invalid_block_not_open(void **state) { const char *a = "{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endblock' statement without an open 'block' statement.\n" "Error occurred near line 1, position 12: {% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -460,16 +460,16 @@ static void test_template_parse_invalid_endif_not_open(void **state) { const char *a = "{% block listing %}{% endif %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endif' statement without an open 'ifdef' or 'ifndef' statement.\n" "Error occurred near line 1, position 28: " "{% block listing %}{% endif %}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -477,15 +477,15 @@ static void test_template_parse_invalid_endforeach_not_open(void **state) { const char *a = "{% endforeach %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endforeach' statement without an open 'foreach' statement.\n" "Error occurred near line 1, position 14: {% endforeach %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -493,16 +493,16 @@ static void test_template_parse_invalid_block_name(void **state) { const char *a = "{% chunda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " "'ifndef', 'endif', 'foreach' and 'endforeach'.\n" "Error occurred near line 1, position 10: {% chunda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -510,15 +510,15 @@ static void test_template_parse_invalid_block_type_start(void **state) { const char *a = "{% block ENTRY %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 10: {% block ENTRY %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -526,15 +526,15 @@ static void test_template_parse_invalid_block_type(void **state) { const char *a = "{% block chunda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -542,16 +542,16 @@ static void test_template_parse_invalid_ifdef_start(void **state) { const char *a = "{% block entry %}{% ifdef guda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef guda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -559,16 +559,16 @@ static void test_template_parse_invalid_foreach_start(void **state) { const char *a = "{% block entry %}{% foreach guda %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% foreach guda %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -576,16 +576,16 @@ static void test_template_parse_invalid_ifdef_variable(void **state) { const char *a = "{% block entry %}{% ifdef BoLA %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 28: " "{% block entry %}{% ifdef BoLA %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -593,16 +593,16 @@ static void test_template_parse_invalid_ifdef_variable2(void **state) { const char *a = "{% block entry %}{% ifdef 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -610,16 +610,16 @@ static void test_template_parse_invalid_foreach_variable(void **state) { const char *a = "{% block entry %}{% foreach BoLA %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 30: " "{% block entry %}{% foreach BoLA %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -627,16 +627,16 @@ static void test_template_parse_invalid_foreach_variable2(void **state) { const char *a = "{% block entry %}{% foreach 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: {% block entry %}" "{% foreach 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -644,16 +644,16 @@ static void test_template_parse_invalid_if_operator(void **state) { const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% if BOLA = \"asd\" %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -661,16 +661,16 @@ static void test_template_parse_invalid_if_operand(void **state) { const char *a = "{% block entry %}{% if BOLA == asd %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == asd %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -678,16 +678,16 @@ static void test_template_parse_invalid_if_operand2(void **state) { const char *a = "{% block entry %}{% if BOLA == \"asd %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Found an open double-quoted string.\n" "Error occurred near line 1, position 31: " "{% block entry %}{% if BOLA == \"asd %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -695,16 +695,16 @@ static void test_template_parse_invalid_if_operand3(void **state) { const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == 0123 %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -712,15 +712,15 @@ static void test_template_parse_invalid_block_end(void **state) { const char *a = "{% block entry }}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '%}'.\n" "Error occurred near line 1, position 16: {% block entry }}"); - blogc_error_free(err); + sb_error_free(err); } @@ -728,16 +728,16 @@ static void test_template_parse_invalid_variable_name(void **state) { const char *a = "{% block entry %}{{ bola }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: " "{% block entry %}{{ bola }}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -745,16 +745,16 @@ static void test_template_parse_invalid_variable_name2(void **state) { const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 22: " "{% block entry %}{{ Bola }}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -762,16 +762,16 @@ static void test_template_parse_invalid_variable_name3(void **state) { const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" "{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -779,16 +779,16 @@ static void test_template_parse_invalid_variable_end(void **state) { const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}}'.\n" "Error occurred near line 1, position 26: " "{% block entry %}{{ BOLA %}{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -796,15 +796,15 @@ static void test_template_parse_invalid_close(void **state) { const char *a = "{% block entry %%\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 17: {% block entry %%"); - blogc_error_free(err); + sb_error_free(err); } @@ -812,16 +812,16 @@ static void test_template_parse_invalid_close2(void **state) { const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 27: " "{% block entry %}{{ BOLA }%{% endblock %}"); - blogc_error_free(err); + sb_error_free(err); } @@ -829,14 +829,14 @@ static void test_template_parse_invalid_if_not_closed(void **state) { const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "1 open 'ifdef' and/or 'ifndef' statements " "were not closed!"); - blogc_error_free(err); + sb_error_free(err); } @@ -844,13 +844,13 @@ static void test_template_parse_invalid_block_not_closed(void **state) { const char *a = "{% block entry %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open block was not closed!"); - blogc_error_free(err); + sb_error_free(err); } @@ -858,13 +858,13 @@ static void test_template_parse_invalid_foreach_not_closed(void **state) { const char *a = "{% foreach ASD %}\n"; - blogc_error_t *err = NULL; + sb_error_t *err = NULL; 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); + assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open 'foreach' statement was not closed!"); - blogc_error_free(err); + sb_error_free(err); } -- cgit v1.2.3-18-g5258 From 37592b57b31987519e59117d49bccd0207e67f15 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 13 Mar 2016 03:05:17 +0100 Subject: error: removed uneeded tests --- tests/check_error.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/tests/check_error.c b/tests/check_error.c index 7fc3c3e..c990b45 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -19,28 +19,6 @@ #include -static void -test_error_new(void **state) -{ - sb_error_t *error = sb_error_new(1, "bola %s"); - assert_non_null(error); - assert_int_equal(error->code, 1); - assert_string_equal(error->msg, "bola %s"); - sb_error_free(error); -} - - -static void -test_error_new_printf(void **state) -{ - sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); - assert_non_null(error); - assert_int_equal(error->code, 2); - assert_string_equal(error->msg, "bola guda"); - sb_error_free(error); -} - - static void test_error_parser(void **state) { @@ -105,8 +83,6 @@ int main(void) { const UnitTest tests[] = { - unit_test(test_error_new), - unit_test(test_error_new_printf), unit_test(test_error_parser), unit_test(test_error_parser_crlf), }; -- cgit v1.2.3-18-g5258 From c7b4bc4d64a3ce669e54b7c7dae87527d9ee3123 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 19 Mar 2016 10:36:16 +0100 Subject: main: loader: use file utils from squareball --- configure.ac | 2 +- squareball | 2 +- src/file.c | 26 +------------------------- src/main.c | 52 ++++++++++++++++------------------------------------ 4 files changed, 19 insertions(+), 63 deletions(-) diff --git a/configure.ac b/configure.ac index ad759c6..d217c90 100644 --- a/configure.ac +++ b/configure.ac @@ -119,7 +119,7 @@ AS_IF([test "x$have_cmocka" = "xyes"], , [ ]) AM_CONDITIONAL([USE_CMOCKA], [test "x$have_cmocka" = "xyes"]) -AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) +AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h libgen.h]) LT_LIB_M diff --git a/squareball b/squareball index ebc0247..10c2a01 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit ebc02478a78c83e5e62afc485a294e1c78442dbe +Subproject commit 10c2a010e3a7058c1519d5fb8c377ca0dd0c4ce2 diff --git a/src/file.c b/src/file.c index 972f433..a12fbc2 100644 --- a/src/file.c +++ b/src/file.c @@ -10,10 +10,8 @@ #include #endif /* HAVE_CONFIG_H */ -#include #include #include -#include #include #include "file.h" #include "error.h" @@ -25,29 +23,7 @@ char* blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) { - if (path == NULL || err == NULL || *err != NULL) - return NULL; - - *len = 0; - FILE *fp = fopen(path, "r"); - - if (fp == NULL) { - int tmp_errno = errno; - *err = sb_error_new_printf(BLOGC_ERROR_LOADER, - "Failed to open file (%s): %s", path, strerror(tmp_errno)); - return NULL; - } - - 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; - sb_string_append_len(str, buffer, read_len); - } - fclose(fp); - return sb_string_free(str, false); + return sb_file_get_contents(path, len, err); } diff --git a/src/main.c b/src/main.c index 709b37e..1f5c76c 100644 --- a/src/main.c +++ b/src/main.c @@ -18,6 +18,10 @@ #include #endif /* HAVE_SYS_TYPES_H */ +#ifdef HAVE_LIBGEN_H +#include +#endif /* HAVE_LIBGEN_H */ + #include #include #include @@ -68,41 +72,6 @@ blogc_print_usage(void) } -static void -blogc_mkdir_recursive(const char *filename) -{ - char *fname = sb_strdup(filename); - for (char *tmp = fname; *tmp != '\0'; tmp++) { - if (*tmp != '/' && *tmp != '\\') - continue; -#if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H) - char bkp = *tmp; - *tmp = '\0'; - if ((strlen(fname) > 0) && -#if defined(WIN32) || defined(_WIN32) - (-1 == mkdir(fname)) && -#else - (-1 == mkdir(fname, 0777)) && -#endif - (errno != EEXIST)) - { - fprintf(stderr, "blogc: error: failed to create output " - "directory (%s): %s\n", fname, strerror(errno)); - free(fname); - exit(2); - } - *tmp = bkp; -#else - // FIXME: show this warning only if actually trying to create a directory. - fprintf(stderr, "blogc: warning: can't create output directories " - "for your platform. please create the directories yourself.\n"); - break; -#endif - } - free(fname); -} - - int main(int argc, char **argv) { @@ -252,7 +221,18 @@ main(int argc, char **argv) FILE *fp = stdout; if (!write_to_stdout) { - blogc_mkdir_recursive(output); + +#ifdef HAVE_LIBGEN_H + char *_output = sb_strdup(output); + sb_mkdir_recursive(dirname(_output), &err); + free(_output); + if (err != NULL) { + blogc_error_print(err); + rv = 2; + goto cleanup4; + } +#endif + fp = fopen(output, "w"); if (fp == NULL) { fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", -- cgit v1.2.3-18-g5258 From fb15c8477e178abeb72e196f77da168e956768bf Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 6 Apr 2016 01:04:43 +0200 Subject: travis: trying to fix deploy --- .travis.yml | 15 +++------------ build-aux/travis-deploy.sh | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd2d134..0ea174c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,15 +35,6 @@ install: gem install ronn before_script: ./autogen.sh -script: ./build-aux/travis-build.sh - -deploy: - provider: script - script: ./build-aux/travis-deploy.sh - skip_cleanup: true - on: - repo: blogc/blogc - branch: master - condition: - - $CC = gcc - - $TARGET != valgrind +script: + - ./build-aux/travis-build.sh + - ./build-aux/travis-deploy.sh diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index 71469ff..0ef28bf 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -2,6 +2,21 @@ 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 -- cgit v1.2.3-18-g5258 From fc33d0b03e8755f6e98e5be5b474ac93a1f749c0 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 6 Apr 2016 02:16:18 +0200 Subject: build: update squareball --- configure.ac | 2 +- squareball | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index d217c90..16f141f 100644 --- a/configure.ac +++ b/configure.ac @@ -127,7 +127,7 @@ AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system [whether to use library squareball from system [default=internal]])]) AS_IF([test "x$with_squareball" = "xsystem"], [ SQUAREBALL="system" - PKG_CHECK_MODULES([SQUAREBALL], [squareball >= 0.1], , [ + PKG_CHECK_MODULES([SQUAREBALL], [squareball >= 0.2.0], , [ AC_MSG_ERROR([library squareball requested from system but not found or not new enough]) ]) ], [ diff --git a/squareball b/squareball index 10c2a01..e2639b0 160000 --- a/squareball +++ b/squareball @@ -1 +1 @@ -Subproject commit 10c2a010e3a7058c1519d5fb8c377ca0dd0c4ce2 +Subproject commit e2639b044e450ed54cf6e768ed2eb8b88e5c0555 -- cgit v1.2.3-18-g5258 From 6a19a55497730354f0545fbaf3ce99b4d942dbb7 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 8 Apr 2016 01:49:29 +0200 Subject: spec: restrict squareball dependency --- blogc.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blogc.spec.in b/blogc.spec.in index 142e4f0..2811f3e 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -7,7 +7,7 @@ Summary: A blog compiler URL: @PACKAGE_URL@ Source0: https://github.com/blogc/blogc/releases/download/v@PACKAGE_VERSION@/blogc-@PACKAGE_VERSION@.tar.xz -BuildRequires: squareball-devel +BuildRequires: squareball-devel >= 0.2.0 %description blogc(1) is a blog compiler. It converts source files and templates into -- cgit v1.2.3-18-g5258 From 001c16ac605ee65f5688534e42c10395db3f0d5a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 17 Apr 2016 04:01:51 +0200 Subject: content-parser: do not convert -- and --- to &ndash and &mdash inside code --- src/content-parser.c | 4 +++- tests/check_content_parser.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/content-parser.c b/src/content-parser.c index 0a87fcb..782a85d 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -364,7 +364,9 @@ blogc_content_parse_inline(const char *src) case '-': if (state != LINK_CLOSED) break; - if (current < (src_len - 1) && src[current + 1] == '-') { + 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, "—"); current += 2; diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index b20f8d0..ea3a9a2 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1751,6 +1751,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 – bar"); + free(html); + html = blogc_content_parse_inline("foo --- bar"); + assert_non_null(html); + assert_string_equal(html, "foo — bar"); + free(html); + html = blogc_content_parse_inline("`foo -- bar`"); + assert_non_null(html); + assert_string_equal(html, "foo -- bar"); + free(html); + html = blogc_content_parse_inline("`foo --- bar`"); + assert_non_null(html); + assert_string_equal(html, "foo --- bar"); + free(html); + html = blogc_content_parse_inline("``foo -- bar``"); + assert_non_null(html); + assert_string_equal(html, "foo -- bar"); + free(html); + html = blogc_content_parse_inline("``foo --- bar``"); + assert_non_null(html); + assert_string_equal(html, "foo --- bar"); + free(html); +} + + int main(void) { @@ -1793,6 +1823,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); } -- cgit v1.2.3-18-g5258 From c216deff59e2c0dd9538ced99d6b579013b3b5de Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 17 Apr 2016 04:12:08 +0200 Subject: build: version bump --- blogc.spec.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blogc.spec.in b/blogc.spec.in index 2811f3e..adec43a 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -32,6 +32,12 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %changelog +* Sun Apr 17 2016 Rafael G. Martins 0.8.1-1 +- New release. + +* Wed Apr 6 2016 Rafael G. Martins 0.8.0-1 +- New release. + * Mon Feb 29 2016 Rafael G. Martins 0.7.6-1 - New release. Added new dependency. -- cgit v1.2.3-18-g5258 From 9b2a563b4931ca39cd6dd14bf85cda627714a4b2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 20 Apr 2016 02:50:20 +0200 Subject: content-parser: extract post description from content description is the first line of the first paragraph parsed from content file. users can override it declaring DESCRIPTION variable in source file itself. this also fixes a bug with line endings when using single line blockquotes. --- src/content-parser.c | 16 +- src/content-parser.h | 3 +- src/source-parser.c | 14 +- tests/check_content_parser.c | 412 +++++++++++++++++++++++++++++++++---------- tests/check_loader.c | 3 +- tests/check_source_parser.c | 46 ++++- 6 files changed, 389 insertions(+), 105 deletions(-) diff --git a/src/content-parser.c b/src/content-parser.c index 782a85d..795cc34 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -460,7 +460,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); @@ -698,14 +698,10 @@ blogc_content_parse(const char *src, size_t *end_excerpt) case CONTENT_BLOCKQUOTE_END: if (c == '\n' || c == '\r' || is_last) { tmp_str = sb_string_new(); - for (sb_slist_t *l = lines; l != NULL; l = l->next) { - if (l->next == NULL) - sb_string_append_printf(tmp_str, "%s", l->data); - else - sb_string_append_printf(tmp_str, "%s%s", l->data, - line_ending); - } - tmp = blogc_content_parse(tmp_str->str, NULL); + 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, "
%s
%s", tmp, line_ending); free(tmp); @@ -1019,6 +1015,8 @@ 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; 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/source-parser.c b/src/source-parser.c index 1047f06..6e026d2 100644 --- a/src/source-parser.c +++ b/src/source-parser.c @@ -154,7 +154,19 @@ blogc_source_parse(const char *src, size_t src_len, sb_error_t **err) if (current == (src_len - 1)) { tmp = sb_strndup(src + start, src_len - start); sb_trie_insert(rv, "RAW_CONTENT", tmp); - content = blogc_content_parse(tmp, &end_excerpt); + 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)); diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index ea3a9a2..0eaab70 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -81,6 +81,7 @@ static void test_content_parse(void **state) { size_t l = 0; + char *d = NULL; char *html = blogc_content_parse( "# um\n" "## dois\n" @@ -122,9 +123,11 @@ test_content_parse(void **state) "\n" "-- asd\n" "\n" - "--- lol\n", &l); + "--- 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, "

um

\n" "

dois

\n" @@ -162,6 +165,7 @@ test_content_parse(void **state) "

– asd

\n" "

— lol

\n"); free(html); + free(d); } @@ -169,6 +173,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" @@ -210,9 +215,11 @@ test_content_parse_crlf(void **state) "\r\n" "-- asd\r\n" "\r\n" - "--- lol\r\n", &l); + "--- 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, "

um

\r\n" "

dois

\r\n" @@ -250,6 +257,7 @@ test_content_parse_crlf(void **state) "

– asd

\r\n" "

— lol

\r\n"); free(html); + free(d); } @@ -257,6 +265,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" @@ -265,9 +274,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, "

test

\n" "

chunda

\n" @@ -275,6 +286,8 @@ test_content_parse_with_excerpt(void **state) "lol

\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -283,15 +296,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, "

test

\n" "

chunda

\n" "

guda\n" "lol

\n"); free(html); + free(d); } @@ -299,6 +315,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" @@ -307,9 +324,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, "

test

\r\n" "

chunda

\r\n" @@ -317,6 +336,8 @@ test_content_parse_with_excerpt_crlf(void **state) "lol

\r\n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\r\n" "\r\n" @@ -325,26 +346,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, "

test

\r\n" "

chunda

\r\n" "

guda\r\n" "lol

\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, "

bola

\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, "

bola

\n"); free(html); @@ -353,7 +377,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, "

bola

\n" @@ -366,11 +390,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, "

bola

\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, "

bola

\r\n"); free(html); @@ -379,7 +403,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, "

bola

\r\n" @@ -392,11 +416,11 @@ test_content_parse_header_crlf(void **state) static void test_content_parse_html(void **state) { - char *html = blogc_content_parse("
\n
", NULL); + char *html = blogc_content_parse("
\n
", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\n
\n"); free(html); - html = blogc_content_parse("
\n
\n", NULL); + html = blogc_content_parse("
\n
\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\n
\n"); free(html); @@ -406,7 +430,7 @@ test_content_parse_html(void **state) "
\n" "
\n" "\n" - "chunda\n", NULL); + "chunda\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "

bola

\n" @@ -419,11 +443,11 @@ test_content_parse_html(void **state) static void test_content_parse_html_crlf(void **state) { - char *html = blogc_content_parse("
\r\n
", NULL); + char *html = blogc_content_parse("
\r\n
", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\r\n
\r\n"); free(html); - html = blogc_content_parse("
\r\n
\r\n", NULL); + html = blogc_content_parse("
\r\n
\r\n", NULL, NULL); assert_non_null(html); assert_string_equal(html, "
\r\n
\r\n"); free(html); @@ -433,7 +457,7 @@ test_content_parse_html_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, "

bola

\r\n" @@ -446,27 +470,40 @@ 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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\n"); free(html); + html = blogc_content_parse( + "bola\n" + "\n" + "> bola\n" + "\n" + "chunda\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "

bola

\n" + "

bola

\n" + "
\n" + "

chunda

\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, "

bola

\n" @@ -481,27 +518,40 @@ 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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\r\n"); free(html); + html = blogc_content_parse( + "bola\r\n" + "\r\n" + "> bola\r\n" + "\r\n" + "chunda\r\n", NULL, NULL); + assert_non_null(html); + assert_string_equal(html, + "

bola

\r\n" + "

bola

\r\n" + "
\r\n" + "

chunda

\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, "

bola

\r\n" @@ -516,13 +566,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, "
bola\n"
         "guda
\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, "
bola\n"
@@ -534,7 +584,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,
         "

bola

\n" @@ -548,13 +598,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, "
bola\r\n"
         "guda
\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, "
bola\r\n"
@@ -566,7 +616,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,
         "

bola

\r\n" @@ -580,28 +630,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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\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, "

bola\n" "guda

\n" "
\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, "

bola\n" @@ -613,7 +663,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, "

bola

\n" @@ -625,7 +675,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, "

bola

\n" @@ -638,28 +688,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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" "guda

\r\n" "
\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, "

bola\r\n" @@ -671,7 +721,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, "

bola

\r\n" @@ -683,7 +733,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, "

bola

\r\n" @@ -701,7 +751,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, "

lol

\n" @@ -716,7 +766,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, "

lol

\n" @@ -733,7 +783,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, "

lol

\n" @@ -753,7 +803,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, "

lol

\n" @@ -769,7 +819,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, "
    \n" @@ -789,7 +839,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, "

    lol

    \r\n" @@ -804,7 +854,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, "

    lol

    \r\n" @@ -821,7 +871,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, "

    lol

    \r\n" @@ -841,7 +891,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, "

    lol

    \r\n" @@ -857,7 +907,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, "
      \r\n" @@ -877,7 +927,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, "

      lol

      \n" @@ -892,7 +942,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, "

      lol

      \n" @@ -909,7 +959,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, "

      lol

      \n" @@ -929,7 +979,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, "

      lol

      \n" @@ -945,7 +995,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, "
        \n" @@ -965,7 +1015,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, "

        lol

        \r\n" @@ -980,7 +1030,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, "

        lol

        \r\n" @@ -997,7 +1047,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, "

        lol

        \r\n" @@ -1017,7 +1067,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, "

        lol

        \r\n" @@ -1033,7 +1083,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, "
          \r\n" @@ -1045,10 +1095,177 @@ test_content_parse_ordered_list_crlf(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, + "

          foo

          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          qwe\n" + "bar

          \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, + "

          foo

          \n" + "

          qwe

          \n" + "
          \n" + "

          bar

          \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, + "

          foo

          \n" + "

          qwe\n" + "zxc

          \n" + "
          \n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          qwe\r\n" + "bar

          \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, + "

          foo

          \r\n" + "

          qwe

          \r\n" + "
          \r\n" + "

          bar

          \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, + "

          foo

          \r\n" + "

          qwe\r\n" + "zxc

          \r\n" + "
          \r\n" + "

          bar

          \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" @@ -1056,9 +1273,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, "

          test

          \n" "

          chunda\n" @@ -1067,6 +1286,8 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \n"); free(html); l = 0; + free(d); + d = NULL; html = blogc_content_parse( "# test\n" "\n" @@ -1074,9 +1295,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, "

          test

          \n" "

          chunda

          \n" @@ -1085,15 +1308,19 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \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, "

          test

          \n" "

          chunda..

          \n" @@ -1101,21 +1328,26 @@ test_content_parse_invalid_excerpt(void **state) "lol

          \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, "

          test

          \n" "

          chunda

          \n" "

          ...guda\n" "lol

          \n"); free(html); + free(d); } @@ -1125,7 +1357,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, "

          asd

          \n" @@ -1142,7 +1374,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, "

          asd

          \n" @@ -1159,7 +1391,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, "

          > asd\n" @@ -1168,7 +1400,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, "

          > asd\n" @@ -1183,7 +1415,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, "

          asd\n" @@ -1193,7 +1425,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, "

          asd\n" @@ -1207,11 +1439,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, "

          asd

          \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, "

          asd

          \n"); free(html); @@ -1224,7 +1456,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, "

          asd\n" @@ -1233,7 +1465,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, "

          asd\n" @@ -1241,7 +1473,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, "

          asd\n" @@ -1250,7 +1482,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, "

          asd\n" @@ -1263,7 +1495,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, "

          chunda

          \n" @@ -1280,7 +1512,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, "

          1. asd\n" @@ -1289,7 +1521,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, "

          1. asd\n" @@ -1297,7 +1529,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, "

          1. asd\n" @@ -1306,7 +1538,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, "

          1. asd\n" @@ -1319,7 +1551,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, "

          chunda

          \n" @@ -1329,7 +1561,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, "

          1 asd\n" @@ -1337,7 +1569,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, "

          a. asd\n" @@ -1345,18 +1577,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, "

          1.\n" "asd\n" "2. qwe

          \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, "

          1.

          \n"); free(html); - html = blogc_content_parse("1 ", NULL); + html = blogc_content_parse("1 ", NULL, NULL); assert_non_null(html); assert_string_equal(html, "

          1

          \n"); free(html); @@ -1806,6 +2038,8 @@ main(void) unit_test(test_content_parse_unordered_list_crlf), unit_test(test_content_parse_ordered_list), unit_test(test_content_parse_ordered_list_crlf), + 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), diff --git a/tests/check_loader.c b/tests/check_loader.c index 0db6194..c0e30df 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -113,12 +113,13 @@ test_source_parse_from_file(void **state) sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); assert_null(err); assert_non_null(t); - assert_int_equal(sb_trie_size(t), 5); + 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"), "

          bola

          \n"); assert_string_equal(sb_trie_lookup(t, "CONTENT"), "

          bola

          \n"); assert_string_equal(sb_trie_lookup(t, "RAW_CONTENT"), "bola"); + assert_string_equal(sb_trie_lookup(t, "DESCRIPTION"), "bola"); sb_trie_free(t); } diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index fba997a..a2a3ddc 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -34,7 +34,7 @@ test_source_parse(void **state) 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), 5); + 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"), @@ -47,6 +47,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -65,7 +66,7 @@ test_source_parse_crlf(void **state) 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), 5); + 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"), @@ -78,6 +79,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -98,7 +100,7 @@ test_source_parse_with_spaces(void **state) 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), 5); + 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"), @@ -111,6 +113,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"); + assert_string_equal(sb_trie_lookup(source, "DESCRIPTION"), "bola"); sb_trie_free(source); } @@ -134,7 +137,7 @@ test_source_parse_with_excerpt(void **state) 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), 5); + 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"), @@ -154,6 +157,40 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"); + 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"; + sb_error_t *err = NULL; + sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); + assert_null(err); + assert_non_null(source); + assert_int_equal(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"), + "

          This is a test

          \n" + "

          bola

          \n"); + assert_string_equal(sb_trie_lookup(source, "CONTENT"), + "

          This is a test

          \n" + "

          bola

          \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); } @@ -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), -- cgit v1.2.3-18-g5258 From 25c2e03228e00f577fac4a52079c601010df4f15 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:30:12 +0200 Subject: Revert "main: loader: use file utils from squareball" This reverts commit c7b4bc4d64a3ce669e54b7c7dae87527d9ee3123. --- configure.ac | 2 +- src/file.c | 26 +++++++++++++++++++++++++- src/main.c | 52 ++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 16f141f..0bc1e19 100644 --- a/configure.ac +++ b/configure.ac @@ -119,7 +119,7 @@ AS_IF([test "x$have_cmocka" = "xyes"], , [ ]) AM_CONDITIONAL([USE_CMOCKA], [test "x$have_cmocka" = "xyes"]) -AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h libgen.h]) +AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M diff --git a/src/file.c b/src/file.c index a12fbc2..972f433 100644 --- a/src/file.c +++ b/src/file.c @@ -10,8 +10,10 @@ #include #endif /* HAVE_CONFIG_H */ +#include #include #include +#include #include #include "file.h" #include "error.h" @@ -23,7 +25,29 @@ char* blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) { - return sb_file_get_contents(path, len, err); + if (path == NULL || err == NULL || *err != NULL) + return NULL; + + *len = 0; + FILE *fp = fopen(path, "r"); + + if (fp == NULL) { + int tmp_errno = errno; + *err = sb_error_new_printf(BLOGC_ERROR_LOADER, + "Failed to open file (%s): %s", path, strerror(tmp_errno)); + return NULL; + } + + 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; + sb_string_append_len(str, buffer, read_len); + } + fclose(fp); + return sb_string_free(str, false); } diff --git a/src/main.c b/src/main.c index 1f5c76c..709b37e 100644 --- a/src/main.c +++ b/src/main.c @@ -18,10 +18,6 @@ #include #endif /* HAVE_SYS_TYPES_H */ -#ifdef HAVE_LIBGEN_H -#include -#endif /* HAVE_LIBGEN_H */ - #include #include #include @@ -72,6 +68,41 @@ blogc_print_usage(void) } +static void +blogc_mkdir_recursive(const char *filename) +{ + char *fname = sb_strdup(filename); + for (char *tmp = fname; *tmp != '\0'; tmp++) { + if (*tmp != '/' && *tmp != '\\') + continue; +#if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H) + char bkp = *tmp; + *tmp = '\0'; + if ((strlen(fname) > 0) && +#if defined(WIN32) || defined(_WIN32) + (-1 == mkdir(fname)) && +#else + (-1 == mkdir(fname, 0777)) && +#endif + (errno != EEXIST)) + { + fprintf(stderr, "blogc: error: failed to create output " + "directory (%s): %s\n", fname, strerror(errno)); + free(fname); + exit(2); + } + *tmp = bkp; +#else + // FIXME: show this warning only if actually trying to create a directory. + fprintf(stderr, "blogc: warning: can't create output directories " + "for your platform. please create the directories yourself.\n"); + break; +#endif + } + free(fname); +} + + int main(int argc, char **argv) { @@ -221,18 +252,7 @@ main(int argc, char **argv) FILE *fp = stdout; if (!write_to_stdout) { - -#ifdef HAVE_LIBGEN_H - char *_output = sb_strdup(output); - sb_mkdir_recursive(dirname(_output), &err); - free(_output); - if (err != NULL) { - blogc_error_print(err); - rv = 2; - goto cleanup4; - } -#endif - + blogc_mkdir_recursive(output); fp = fopen(output, "w"); if (fp == NULL) { fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", -- cgit v1.2.3-18-g5258 From c5e4f4c2d29831151bdce1802787b9cf012c3e5e Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:30:49 +0200 Subject: Revert "error: removed uneeded tests" This reverts commit 37592b57b31987519e59117d49bccd0207e67f15. --- tests/check_error.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/check_error.c b/tests/check_error.c index c990b45..7fc3c3e 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -19,6 +19,28 @@ #include +static void +test_error_new(void **state) +{ + sb_error_t *error = sb_error_new(1, "bola %s"); + assert_non_null(error); + assert_int_equal(error->code, 1); + assert_string_equal(error->msg, "bola %s"); + sb_error_free(error); +} + + +static void +test_error_new_printf(void **state) +{ + sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); + assert_non_null(error); + assert_int_equal(error->code, 2); + assert_string_equal(error->msg, "bola guda"); + sb_error_free(error); +} + + static void test_error_parser(void **state) { @@ -83,6 +105,8 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_error_new), + unit_test(test_error_new_printf), unit_test(test_error_parser), unit_test(test_error_parser_crlf), }; -- cgit v1.2.3-18-g5258 From 6153580a13e7e7c48e38fa446572c8adcae08084 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:31:02 +0200 Subject: Revert "*: use squareball error infrastructure" This reverts commit a2b3551dfb9460470bd79f5648bf597c517c40d4. --- src/datetime-parser.c | 58 ++++++------ src/datetime-parser.h | 2 +- src/error.c | 47 +++++++-- src/error.h | 15 ++- src/file.c | 4 +- src/file.h | 2 +- src/loader.c | 12 +-- src/loader.h | 6 +- src/main.c | 4 +- src/renderer.c | 4 +- src/source-parser.c | 4 +- src/source-parser.h | 2 +- src/template-parser.c | 8 +- src/template-parser.h | 2 +- tests/check_datetime_parser.c | 216 +++++++++++++++++++++--------------------- tests/check_error.c | 44 ++++----- tests/check_loader.c | 30 +++--- tests/check_renderer.c | 40 ++++---- tests/check_source_parser.c | 122 ++++++++++++------------ tests/check_template_parser.c | 190 ++++++++++++++++++------------------- 20 files changed, 426 insertions(+), 386 deletions(-) diff --git a/src/datetime-parser.c b/src/datetime-parser.c index 0fa7aaf..0aeb702 100644 --- a/src/datetime-parser.c +++ b/src/datetime-parser.c @@ -47,14 +47,14 @@ typedef enum { char* blogc_convert_datetime(const char *orig, const char *format, - sb_error_t **err) + blogc_error_t **err) { if (err == NULL || *err != NULL) return NULL; #ifndef HAVE_TIME_H - *err = sb_error_new(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new(BLOGC_WARNING_DATETIME_PARSER, "Your operating system does not supports the datetime functionalities " "used by blogc. Sorry."); return NULL; @@ -80,7 +80,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_YEAR; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -91,7 +91,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_THIRD_YEAR; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -102,7 +102,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FOURTH_YEAR; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid third digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -111,7 +111,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff - 1900; if (tmp < 0) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid year. Found %d, must be >= 1900.", tmp + 1900); break; @@ -120,7 +120,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_HYPHEN; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid fourth digit of year. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -131,7 +131,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_MONTH; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between year and month. " "Found '%c', must be '-'.", c); break; @@ -142,7 +142,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_MONTH; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of month. " "Found '%c', must be integer >= 0 and <= 1.", c); break; @@ -151,7 +151,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff - 1; if (tmp < 0 || tmp > 11) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid month. Found %d, must be >= 1 and <= 12.", tmp + 1); break; @@ -160,7 +160,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_HYPHEN; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of month. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -171,7 +171,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_DAY; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between month and day. " "Found '%c', must be '-'.", c); break; @@ -182,7 +182,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_DAY; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of day. " "Found '%c', must be integer >= 0 and <= 3.", c); break; @@ -191,7 +191,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 1 || tmp > 31) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid day. Found %d, must be >= 1 and <= 31.", tmp); break; @@ -200,7 +200,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SPACE; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of day. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -211,7 +211,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_HOUR; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between date and time. " "Found '%c', must be ' ' (empty space).", c); break; @@ -222,7 +222,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_HOUR; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of hours. " "Found '%c', must be integer >= 0 and <= 2.", c); break; @@ -231,7 +231,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 0 || tmp > 23) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid hours. Found %d, must be >= 0 and <= 23.", tmp); break; @@ -240,7 +240,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_COLON; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of hours. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -251,7 +251,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_MINUTE; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between hours and minutes. " "Found '%c', must be ':'.", c); break; @@ -262,7 +262,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_MINUTE; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of minutes. " "Found '%c', must be integer >= 0 and <= 5.", c); break; @@ -274,7 +274,7 @@ blogc_convert_datetime(const char *orig, const char *format, // this won't happen because we are restricting the digits // to 00-59 already, but lets keep the code here for // reference. - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid minutes. Found %d, must be >= 0 and <= 59.", tmp); break; @@ -283,7 +283,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_COLON; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of minutes. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -294,7 +294,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_FIRST_SECOND; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid separator between minutes and seconds. " "Found '%c', must be ':'.", c); break; @@ -305,7 +305,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_SECOND_SECOND; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid first digit of seconds. " "Found '%c', must be integer >= 0 and <= 6.", c); break; @@ -314,7 +314,7 @@ blogc_convert_datetime(const char *orig, const char *format, if (c >= '0' && c <= '9') { tmp += c - diff; if (tmp < 0 || tmp > 60) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid seconds. Found %d, must be >= 0 and <= 60.", tmp); break; @@ -323,7 +323,7 @@ blogc_convert_datetime(const char *orig, const char *format, state = DATETIME_DONE; break; } - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid second digit of seconds. " "Found '%c', must be integer >= 0 and <= 9.", c); break; @@ -355,7 +355,7 @@ blogc_convert_datetime(const char *orig, const char *format, case DATETIME_SECOND_MINUTE: case DATETIME_FIRST_SECOND: case DATETIME_SECOND_SECOND: - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Invalid datetime string. " "Found '%s', formats allowed are: 'yyyy-mm-dd hh:mm:ss', " "'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and 'yyyy-mm-dd'.", @@ -374,7 +374,7 @@ blogc_convert_datetime(const char *orig, const char *format, char buf[1024]; if (0 == strftime(buf, sizeof(buf), format, &t)) { - *err = sb_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, + *err = blogc_error_new_printf(BLOGC_WARNING_DATETIME_PARSER, "Failed to format DATE variable, FORMAT is too long: %s", format); return NULL; diff --git a/src/datetime-parser.h b/src/datetime-parser.h index b2e65a1..a5087b3 100644 --- a/src/datetime-parser.h +++ b/src/datetime-parser.h @@ -12,6 +12,6 @@ #include "error.h" char* blogc_convert_datetime(const char *orig, const char *format, - sb_error_t **err); + blogc_error_t **err); #endif /* _DATETIME_H */ diff --git a/src/error.c b/src/error.c index 619ae01..f05049c 100644 --- a/src/error.c +++ b/src/error.c @@ -18,8 +18,31 @@ #include "error.h" -sb_error_t* -blogc_error_parser(blogc_error_code_t type, const char *src, size_t src_len, +blogc_error_t* +blogc_error_new(blogc_error_type_t type, const char *msg) +{ + blogc_error_t *err = sb_malloc(sizeof(blogc_error_t)); + err->type = type; + err->msg = sb_strdup(msg); + return err; +} + + +blogc_error_t* +blogc_error_new_printf(blogc_error_type_t type, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + char *tmp = sb_strdup_vprintf(format, ap); + va_end(ap); + blogc_error_t *rv = blogc_error_new(type, tmp); + free(tmp); + return rv; +} + + +blogc_error_t* +blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, size_t current, const char *format, ...) { va_list ap; @@ -67,12 +90,12 @@ blogc_error_parser(blogc_error_code_t type, const char *src, size_t src_len, char *line = sb_strndup(src + linestart, lineend - linestart); - sb_error_t *rv = NULL; + blogc_error_t *rv = NULL; if (line[0] == '\0') // "near" message isn't useful if line is empty - rv = sb_error_new(type, msg); + rv = blogc_error_new(type, msg); else - rv = sb_error_new_printf(type, + rv = blogc_error_new_printf(type, "%s\nError occurred near line %d, position %d: %s", msg, lineno, pos, line); @@ -84,12 +107,12 @@ blogc_error_parser(blogc_error_code_t type, const char *src, size_t src_len, void -blogc_error_print(sb_error_t *err) +blogc_error_print(blogc_error_t *err) { if (err == NULL) return; - switch(err->code) { + switch(err->type) { case BLOGC_ERROR_SOURCE_PARSER: fprintf(stderr, "blogc: error: source: %s\n", err->msg); break; @@ -106,3 +129,13 @@ blogc_error_print(sb_error_t *err) fprintf(stderr, "blogc: error: %s\n", err->msg); } } + + +void +blogc_error_free(blogc_error_t *err) +{ + if (err == NULL) + return; + free(err->msg); + free(err); +} diff --git a/src/error.h b/src/error.h index e02afed..caa86b0 100644 --- a/src/error.h +++ b/src/error.h @@ -11,17 +11,24 @@ #include #include -#include typedef enum { BLOGC_ERROR_SOURCE_PARSER = 1, BLOGC_ERROR_TEMPLATE_PARSER, BLOGC_ERROR_LOADER, BLOGC_WARNING_DATETIME_PARSER, -} blogc_error_code_t; +} blogc_error_type_t; -sb_error_t* blogc_error_parser(blogc_error_code_t type, const char *src, +typedef struct { + char *msg; + blogc_error_type_t type; +} blogc_error_t; + +blogc_error_t* blogc_error_new(blogc_error_type_t type, const char *msg); +blogc_error_t* blogc_error_new_printf(blogc_error_type_t type, const char *format, ...); +blogc_error_t* blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len, size_t current, const char *format, ...); -void blogc_error_print(sb_error_t *err); +void blogc_error_print(blogc_error_t *err); +void blogc_error_free(blogc_error_t *err); #endif /* _ERROR_H */ diff --git a/src/file.c b/src/file.c index 972f433..dec7c1b 100644 --- a/src/file.c +++ b/src/file.c @@ -23,7 +23,7 @@ char* -blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) +blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) { if (path == NULL || err == NULL || *err != NULL) return NULL; @@ -33,7 +33,7 @@ blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) if (fp == NULL) { int tmp_errno = errno; - *err = sb_error_new_printf(BLOGC_ERROR_LOADER, + *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, "Failed to open file (%s): %s", path, strerror(tmp_errno)); return NULL; } diff --git a/src/file.h b/src/file.h index 9c0674d..97e5274 100644 --- a/src/file.h +++ b/src/file.h @@ -15,7 +15,7 @@ #define BLOGC_FILE_CHUNK_SIZE 1024 -char* blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err); +char* blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err); int blogc_fprintf(FILE *stream, const char *format, ...); #endif /* _FILE_H */ diff --git a/src/loader.c b/src/loader.c index fd184e5..8008c3a 100644 --- a/src/loader.c +++ b/src/loader.c @@ -60,7 +60,7 @@ blogc_get_filename(const char *f) sb_slist_t* -blogc_template_parse_from_file(const char *f, sb_error_t **err) +blogc_template_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -75,7 +75,7 @@ blogc_template_parse_from_file(const char *f, sb_error_t **err) sb_trie_t* -blogc_source_parse_from_file(const char *f, sb_error_t **err) +blogc_source_parse_from_file(const char *f, blogc_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -98,9 +98,9 @@ blogc_source_parse_from_file(const char *f, sb_error_t **err) sb_slist_t* -blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, sb_error_t **err) +blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, blogc_error_t **err) { - sb_error_t *tmp_err = NULL; + blogc_error_t *tmp_err = NULL; sb_slist_t *rv = NULL; unsigned int with_date = 0; @@ -125,10 +125,10 @@ blogc_source_parse_from_files(sb_trie_t *conf, sb_slist_t *l, sb_error_t **err) char *f = tmp->data; sb_trie_t *s = blogc_source_parse_from_file(f, &tmp_err); if (s == NULL) { - *err = sb_error_new_printf(BLOGC_ERROR_LOADER, + *err = blogc_error_new_printf(BLOGC_ERROR_LOADER, "An error occurred while parsing source file: %s\n\n%s", f, tmp_err->msg); - sb_error_free(tmp_err); + blogc_error_free(tmp_err); tmp_err = NULL; sb_slist_free_full(rv, (sb_free_func_t) sb_trie_free); rv = NULL; diff --git a/src/loader.h b/src/loader.h index 8b0460e..080aff6 100644 --- a/src/loader.h +++ b/src/loader.h @@ -13,9 +13,9 @@ #include "error.h" char* blogc_get_filename(const char *f); -sb_slist_t* blogc_template_parse_from_file(const char *f, sb_error_t **err); -sb_trie_t* blogc_source_parse_from_file(const char *f, sb_error_t **err); +sb_slist_t* blogc_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, - sb_error_t **err); + blogc_error_t **err); #endif /* _LOADER_H */ diff --git a/src/main.c b/src/main.c index 709b37e..143c836 100644 --- a/src/main.c +++ b/src/main.c @@ -210,7 +210,7 @@ main(int argc, char **argv) goto cleanup; } - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err); if (err != NULL) { @@ -274,7 +274,7 @@ cleanup3: blogc_template_free_stmts(l); cleanup2: sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); - sb_error_free(err); + blogc_error_free(err); cleanup: sb_trie_free(config); free(template); diff --git a/src/renderer.c b/src/renderer.c index eb58e0d..a7a7dd7 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -46,11 +46,11 @@ blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local) if (date_format == NULL) return sb_strdup(date); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *rv = blogc_convert_datetime(date, date_format, &err); if (err != NULL) { blogc_error_print(err); - sb_error_free(err); + blogc_error_free(err); return sb_strdup(date); } return rv; diff --git a/src/source-parser.c b/src/source-parser.c index 6e026d2..67c3717 100644 --- a/src/source-parser.c +++ b/src/source-parser.c @@ -31,7 +31,7 @@ typedef enum { sb_trie_t* -blogc_source_parse(const char *src, size_t src_len, sb_error_t **err) +blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -97,7 +97,7 @@ blogc_source_parse(const char *src, size_t src_len, sb_error_t **err) ((current - start == 13) && (0 == strncmp("BLOGC_VERSION", src + start, 13)))) { - *err = sb_error_new_printf(BLOGC_ERROR_SOURCE_PARSER, + *err = blogc_error_new_printf(BLOGC_ERROR_SOURCE_PARSER, "'%s' variable is forbidden in source files. It will " "be set for you by the compiler.", key); break; diff --git a/src/source-parser.h b/src/source-parser.h index fb5306c..460aedb 100644 --- a/src/source-parser.h +++ b/src/source-parser.h @@ -14,6 +14,6 @@ #include "error.h" sb_trie_t* blogc_source_parse(const char *src, size_t src_len, - sb_error_t **err); + blogc_error_t **err); #endif /* _SOURCE_PARSER_H */ diff --git a/src/template-parser.c b/src/template-parser.c index d61f90a..6f23ef1 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -53,7 +53,7 @@ typedef enum { sb_slist_t* -blogc_template_parse(const char *src, size_t src_len, sb_error_t **err) +blogc_template_parse(const char *src, size_t src_len, blogc_error_t **err) { if (err == NULL || *err != NULL) return NULL; @@ -597,14 +597,14 @@ blogc_template_parse(const char *src, size_t src_len, sb_error_t **err) *err = blogc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, start2 - 1, "Found an open double-quoted string."); else if (if_count != 0) - *err = sb_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER, + *err = blogc_error_new_printf(BLOGC_ERROR_TEMPLATE_PARSER, "%d open 'ifdef' and/or 'ifndef' statements were not closed!", if_count); else if (block_state != BLOCK_CLOSED) - *err = sb_error_new(BLOGC_ERROR_TEMPLATE_PARSER, + *err = blogc_error_new(BLOGC_ERROR_TEMPLATE_PARSER, "An open block was not closed!"); else if (foreach_open) - *err = sb_error_new(BLOGC_ERROR_TEMPLATE_PARSER, + *err = blogc_error_new(BLOGC_ERROR_TEMPLATE_PARSER, "An open 'foreach' statement was not closed!"); } diff --git a/src/template-parser.h b/src/template-parser.h index 88b46e9..de5113e 100644 --- a/src/template-parser.h +++ b/src/template-parser.h @@ -45,7 +45,7 @@ typedef struct { } blogc_template_stmt_t; sb_slist_t* blogc_template_parse(const char *src, size_t src_len, - sb_error_t **err); + blogc_error_t **err); void blogc_template_free_stmts(sb_slist_t *stmts); #endif /* _TEMPLATE_GRAMMAR_H */ diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c index aef366e..ba5a79d 100644 --- a/tests/check_datetime_parser.c +++ b/tests/check_datetime_parser.c @@ -24,7 +24,7 @@ static void test_convert_datetime(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -36,7 +36,7 @@ test_convert_datetime(void **state) static void test_convert_datetime_implicit_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -48,7 +48,7 @@ test_convert_datetime_implicit_seconds(void **state) static void test_convert_datetime_implicit_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -60,7 +60,7 @@ test_convert_datetime_implicit_minutes(void **state) static void test_convert_datetime_implicit_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(err); @@ -72,529 +72,529 @@ test_convert_datetime_implicit_hours(void **state) static void test_convert_datetime_invalid_formats(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("20", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '20', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("201", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '201', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-3", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-3', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 ", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 ', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); err = NULL; dt = blogc_convert_datetime("2010-11-30 12:13:1", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid datetime string. Found '2010-11-30 12:13:1', formats allowed are: " "'yyyy-mm-dd hh:mm:ss', 'yyyy-mm-dd hh:ss', 'yyyy-mm-dd hh' and " "'yyyy-mm-dd'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("a010-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2a10-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_3rd_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("20a0-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid third digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_4th_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("201a-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid fourth digit of year. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_year(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("1899-11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid year. Found 1899, must be >= 1900."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_hyphen(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010 11-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between year and month. Found ' ', must be '-'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-a1-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of month. Found 'a', must be integer >= 0 and <= 1."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-1a-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of month. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_month(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-13-30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid month. Found 13, must be >= 1 and <= 12."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_hyphen(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11 30 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between month and day. Found ' ', must be '-'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-a0 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of day. Found 'a', must be integer >= 0 and <= 3."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-3a 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of day. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_day(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-32 12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid day. Found 32, must be >= 1 and <= 31."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_space(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30-12:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between date and time. Found '-', must be ' ' " "(empty space)."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 a2:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of hours. Found 'a', must be integer >= 0 and <= 2."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 1a:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of hours. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_hours(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 24:13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid hours. Found 24, must be >= 0 and <= 23."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_colon(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12 13:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between hours and minutes. Found ' ', must be ':'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:a3:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of minutes. Found 'a', must be integer >= 0 and <= 5."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_minutes(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:1a:14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of minutes. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_colon(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13 14", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid separator between minutes and seconds. Found ' ', must be ':'."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_1st_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:a4", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid first digit of seconds. Found 'a', must be integer >= 0 and <= 6."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_2nd_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-11-30 12:13:1a", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid second digit of seconds. Found 'a', must be integer >= 0 and <= 9."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_seconds(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:69", "%b %d, %Y, %I:%M:%S %p GMT", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Invalid seconds. Found 69, must be >= 0 and <= 60."); - sb_error_free(err); + blogc_error_free(err); } static void test_convert_datetime_invalid_format_long(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; char *dt = blogc_convert_datetime("2010-12-30 12:13:14", "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" "yjsiimtfdeveeeayqvvnthimbqotumngxxenurxhsvyaftwsfdtxqnjluvtcwfkomfffrk" @@ -613,7 +613,7 @@ test_convert_datetime_invalid_format_long(void **state) "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg", &err); assert_null(dt); assert_non_null(err); - assert_int_equal(err->code, BLOGC_WARNING_DATETIME_PARSER); + assert_int_equal(err->type, BLOGC_WARNING_DATETIME_PARSER); assert_string_equal(err->msg, "Failed to format DATE variable, FORMAT is too long: " "bovhsuhxwybfrxoluiejaoqpmoylgvkrjtnuntmcgtupwabexkapnklvkwmddmplfqopvb" @@ -631,7 +631,7 @@ test_convert_datetime_invalid_format_long(void **state) "uaeruwnphdjonqagjatjladqhvlxppyaqgvwpjqggnsccmkjvbxqykaejvgeajqpitkwsq" "gmjiaopomnnlewidhgbgqlblotrnuyokspuvbckqhwnhmgcwyyitmlelnehdvclojvyswj" "jgipsincitulscikxviaruryfraeqssykeftcphtndlfhdxokg"); - sb_error_free(err); + blogc_error_free(err); } diff --git a/tests/check_error.c b/tests/check_error.c index 7fc3c3e..4effb08 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -22,22 +22,22 @@ static void test_error_new(void **state) { - sb_error_t *error = sb_error_new(1, "bola %s"); + blogc_error_t *error = blogc_error_new(1, "bola %s"); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "bola %s"); - sb_error_free(error); + blogc_error_free(error); } static void test_error_new_printf(void **state) { - sb_error_t *error = sb_error_new_printf(2, "bola %s", "guda"); + blogc_error_t *error = blogc_error_new_printf(2, "bola %s", "guda"); assert_non_null(error); - assert_int_equal(error->code, 2); + assert_int_equal(error->type, 2); assert_string_equal(error->msg, "bola guda"); - sb_error_free(error); + blogc_error_free(error); } @@ -45,32 +45,32 @@ static void test_error_parser(void **state) { const char *a = "bola\nguda\nchunda\n"; - sb_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); + blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\nguda\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - sb_error_free(error); + blogc_error_free(error); a = ""; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10"); - sb_error_free(error); + blogc_error_free(error); } @@ -78,26 +78,26 @@ static void test_error_parser_crlf(void **state) { const char *a = "bola\r\nguda\r\nchunda\r\n"; - sb_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); + blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 13, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 3, position 2: chunda"); - sb_error_free(error); + blogc_error_free(error); a = "bola\r\nguda\r\nchunda"; error = blogc_error_parser(1, a, strlen(a), 0, "asd %d", 10); assert_non_null(error); - assert_int_equal(error->code, 1); + assert_int_equal(error->type, 1); assert_string_equal(error->msg, "asd 10\nError occurred near line 1, position 1: bola"); - sb_error_free(error); + blogc_error_free(error); } diff --git a/tests/check_loader.c b/tests/check_loader.c index c0e30df..a07376a 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -52,7 +52,7 @@ test_get_filename(void **state) char* -__wrap_blogc_file_get_contents(const char *path, size_t *len, sb_error_t **err) +__wrap_blogc_file_get_contents(const char *path, size_t *len, blogc_error_t **err) { assert_null(*err); const char *_path = mock_type(const char*); @@ -78,7 +78,7 @@ __wrap_blogc_fprintf(FILE *stream, const char *format, ...) static void test_template_parse_from_file(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, sb_strdup("{{ BOLA }}\n")); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -92,7 +92,7 @@ test_template_parse_from_file(void **state) static void test_template_parse_from_file_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola"); will_return(__wrap_blogc_file_get_contents, NULL); sb_slist_t *l = blogc_template_parse_from_file("bola", &err); @@ -104,7 +104,7 @@ test_template_parse_from_file_null(void **state) static void test_source_parse_from_file(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, sb_strdup( "ASD: 123\n" @@ -127,7 +127,7 @@ test_source_parse_from_file(void **state) static void test_source_parse_from_file_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; will_return(__wrap_blogc_file_get_contents, "bola.txt"); will_return(__wrap_blogc_file_get_contents, NULL); sb_trie_t *t = blogc_source_parse_from_file("bola.txt", &err); @@ -157,7 +157,7 @@ test_source_parse_from_files(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -201,7 +201,7 @@ test_source_parse_from_files_filter_by_tag(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -269,7 +269,7 @@ test_source_parse_from_files_filter_by_page(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -347,7 +347,7 @@ test_source_parse_from_files_filter_by_page2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -426,7 +426,7 @@ test_source_parse_from_files_filter_by_page3(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -509,7 +509,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) "TAGS: yay chunda\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -589,7 +589,7 @@ test_source_parse_from_files_filter_by_page_invalid(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -667,7 +667,7 @@ test_source_parse_from_files_filter_by_page_invalid2(void **state) "DATE: 2007-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -712,7 +712,7 @@ test_source_parse_from_files_without_all_dates(void **state) "DATE: 2003-02-03 04:05:06\n" "--------\n" "bola")); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; s = sb_slist_append(s, sb_strdup("bola1.txt")); s = sb_slist_append(s, sb_strdup("bola2.txt")); @@ -735,7 +735,7 @@ test_source_parse_from_files_without_all_dates(void **state) static void test_source_parse_from_files_null(void **state) { - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *s = NULL; sb_trie_t *c = sb_trie_new(free); sb_slist_t *t = blogc_source_parse_from_files(c, s, &err); diff --git a/tests/check_renderer.c b/tests/check_renderer.c index d71f045..e863360 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -46,7 +46,7 @@ create_sources(unsigned int count) "ahahahahahahahaha3", }; assert_false(count > 3); - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = NULL; for (unsigned int i = 0; i < count; i++) { l = sb_slist_append(l, blogc_source_parse(s[i], strlen(s[i]), &err)); @@ -78,7 +78,7 @@ test_render_entry(void **state) "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -125,7 +125,7 @@ test_render_listing(void **state) "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -173,7 +173,7 @@ test_render_listing_empty(void **state) "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -200,7 +200,7 @@ test_render_ifdef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -229,7 +229,7 @@ test_render_ifdef2(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -260,7 +260,7 @@ test_render_ifdef3(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -293,7 +293,7 @@ test_render_ifndef(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -327,7 +327,7 @@ test_render_if_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -362,7 +362,7 @@ test_render_if_neq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -397,7 +397,7 @@ test_render_if_lt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -432,7 +432,7 @@ test_render_if_gt(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -469,7 +469,7 @@ test_render_if_lt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -508,7 +508,7 @@ test_render_if_gt_eq(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -539,7 +539,7 @@ test_render_foreach(void **state) "{% block entry %}\n" "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -564,7 +564,7 @@ test_render_foreach_if(void **state) "{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}" "{% endif %} {% endforeach %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -595,7 +595,7 @@ test_render_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}lol{% endif %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -628,7 +628,7 @@ test_render_prefer_local_variable(void **state) "{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -664,7 +664,7 @@ test_render_respect_variable_scope(void **state) "{% ifdef LOL %}{{ LOL }}{% endif %}\n" "{% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); @@ -696,7 +696,7 @@ test_render_ifcount_bug(void **state) "{% ifdef ASD %}ASD{% endif %}\n" "{% endif %}\n" "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); assert_null(err); diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index a2a3ddc..0f891dd 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -30,7 +30,7 @@ test_source_parse(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -62,7 +62,7 @@ test_source_parse_crlf(void **state) "# This is a test\r\n" "\r\n" "bola\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -96,7 +96,7 @@ test_source_parse_with_spaces(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -133,7 +133,7 @@ test_source_parse_with_excerpt(void **state) "\n" "guda\n" "yay"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); @@ -199,13 +199,13 @@ static void test_source_parse_config_empty(void **state) { const char *a = ""; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Your source file is empty."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -214,14 +214,14 @@ static void test_source_parse_config_invalid_key(void **state) { const char *a = "bola: guda"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -230,14 +230,14 @@ static void test_source_parse_config_no_key(void **state) { const char *a = "BOLa"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -246,14 +246,14 @@ static void test_source_parse_config_no_key2(void **state) { const char *a = "BOLA"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + 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"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -262,15 +262,15 @@ static void test_source_parse_config_no_value(void **state) { const char *a = "BOLA:\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -279,15 +279,15 @@ static void test_source_parse_config_no_value2(void **state) { const char *a = "BOLA:"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Configuration value not provided for 'BOLA'.\n" "Error occurred near line 1, position 6: BOLA:"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -296,15 +296,15 @@ static void test_source_parse_config_reserved_name(void **state) { const char *a = "FILENAME: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'FILENAME' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -313,15 +313,15 @@ static void test_source_parse_config_reserved_name2(void **state) { const char *a = "CONTENT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'CONTENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -330,15 +330,15 @@ static void test_source_parse_config_reserved_name3(void **state) { const char *a = "DATE_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -347,15 +347,15 @@ static void test_source_parse_config_reserved_name4(void **state) { const char *a = "DATE_FIRST_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_FIRST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -364,15 +364,15 @@ static void test_source_parse_config_reserved_name5(void **state) { const char *a = "DATE_LAST_FORMATTED: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'DATE_LAST_FORMATTED' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -381,15 +381,15 @@ static void test_source_parse_config_reserved_name6(void **state) { const char *a = "PAGE_FIRST: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_FIRST' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -398,15 +398,15 @@ static void test_source_parse_config_reserved_name7(void **state) { const char *a = "PAGE_PREVIOUS: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_PREVIOUS' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -415,15 +415,15 @@ static void test_source_parse_config_reserved_name8(void **state) { const char *a = "PAGE_CURRENT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_CURRENT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -432,15 +432,15 @@ static void test_source_parse_config_reserved_name9(void **state) { const char *a = "PAGE_NEXT: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_NEXT' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -449,15 +449,15 @@ static void test_source_parse_config_reserved_name10(void **state) { const char *a = "PAGE_LAST: asd\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'PAGE_LAST' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -466,15 +466,15 @@ static void test_source_parse_config_reserved_name11(void **state) { const char *a = "BLOGC_VERSION: 1.0\r\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "'BLOGC_VERSION' variable is forbidden in source files. It will be set " "for you by the compiler."); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -483,15 +483,15 @@ static void test_source_parse_config_value_no_line_ending(void **state) { const char *a = "BOLA: asd"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "No line ending after the configuration value for 'BOLA'.\n" "Error occurred near line 1, position 10: BOLA: asd"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } @@ -500,15 +500,15 @@ static void test_source_parse_invalid_separator(void **state) { const char *a = "BOLA: asd\n---#"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(source); assert_non_null(err); - assert_int_equal(err->code, BLOGC_ERROR_SOURCE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_SOURCE_PARSER); assert_string_equal(err->msg, "Invalid content separator. Must be more than one '-' characters.\n" "Error occurred near line 2, position 4: ---#"); - sb_error_free(err); + blogc_error_free(err); sb_trie_free(source); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index 9419607..ed4328b 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -63,7 +63,7 @@ test_template_parse(void **state) "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -143,7 +143,7 @@ test_template_parse_crlf(void **state) "{% block listing_once %}asd{% endblock %}\r\n" "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -231,7 +231,7 @@ test_template_parse_html(void **state) " {% block listing_once %}
    {% endblock %}\n" " \n" "\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -341,7 +341,7 @@ test_template_parse_ifdef_and_var_outside_block(void **state) "{% ifdef GUDA %}bola{% endif %}\n" "{{ BOLA }}\n" "{% ifndef CHUNDA %}{{ CHUNDA }}{% endif %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); @@ -372,35 +372,35 @@ static void test_template_parse_invalid_block_start(void **state) { const char *a = "{% ASD %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); - sb_error_free(err); + blogc_error_free(err); a = "{%-- block entry %}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" "Error occurred near line 1, position 4: {%-- block entry %}"); - sb_error_free(err); + blogc_error_free(err); a = "{% block entry --%}\n"; err = NULL; stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" "Error occurred near line 1, position 17: {% block entry --%}"); - sb_error_free(err); + blogc_error_free(err); } @@ -410,15 +410,15 @@ test_template_parse_invalid_block_nested(void **state) const char *a = "{% block entry %}\n" "{% block listing %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Blocks can't be nested.\n" "Error occurred near line 2, position 9: {% block listing %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -428,15 +428,15 @@ test_template_parse_invalid_foreach_nested(void **state) const char *a = "{% foreach A %}\n" "{% foreach B %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'foreach' statements can't be nested.\n" "Error occurred near line 2, position 11: {% foreach B %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -444,15 +444,15 @@ static void test_template_parse_invalid_block_not_open(void **state) { const char *a = "{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endblock' statement without an open 'block' statement.\n" "Error occurred near line 1, position 12: {% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -460,16 +460,16 @@ static void test_template_parse_invalid_endif_not_open(void **state) { const char *a = "{% block listing %}{% endif %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endif' statement without an open 'ifdef' or 'ifndef' statement.\n" "Error occurred near line 1, position 28: " "{% block listing %}{% endif %}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -477,15 +477,15 @@ static void test_template_parse_invalid_endforeach_not_open(void **state) { const char *a = "{% endforeach %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "'endforeach' statement without an open 'foreach' statement.\n" "Error occurred near line 1, position 14: {% endforeach %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -493,16 +493,16 @@ static void test_template_parse_invalid_block_name(void **state) { const char *a = "{% chunda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " "'ifndef', 'endif', 'foreach' and 'endforeach'.\n" "Error occurred near line 1, position 10: {% chunda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -510,15 +510,15 @@ static void test_template_parse_invalid_block_type_start(void **state) { const char *a = "{% block ENTRY %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 10: {% block ENTRY %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -526,15 +526,15 @@ static void test_template_parse_invalid_block_type(void **state) { const char *a = "{% block chunda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -542,16 +542,16 @@ static void test_template_parse_invalid_ifdef_start(void **state) { const char *a = "{% block entry %}{% ifdef guda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef guda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -559,16 +559,16 @@ static void test_template_parse_invalid_foreach_start(void **state) { const char *a = "{% block entry %}{% foreach guda %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% foreach guda %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -576,16 +576,16 @@ static void test_template_parse_invalid_ifdef_variable(void **state) { const char *a = "{% block entry %}{% ifdef BoLA %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 28: " "{% block entry %}{% ifdef BoLA %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -593,16 +593,16 @@ static void test_template_parse_invalid_ifdef_variable2(void **state) { const char *a = "{% block entry %}{% ifdef 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 27: " "{% block entry %}{% ifdef 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -610,16 +610,16 @@ static void test_template_parse_invalid_foreach_variable(void **state) { const char *a = "{% block entry %}{% foreach BoLA %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 30: " "{% block entry %}{% foreach BoLA %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -627,16 +627,16 @@ static void test_template_parse_invalid_foreach_variable2(void **state) { const char *a = "{% block entry %}{% foreach 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid foreach variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 29: {% block entry %}" "{% foreach 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -644,16 +644,16 @@ static void test_template_parse_invalid_if_operator(void **state) { const char *a = "{% block entry %}{% if BOLA = \"asd\" %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operator. Must be '<', '>', '<=', '>=', '==' or '!='.\n" "Error occurred near line 1, position 29: " "{% block entry %}{% if BOLA = \"asd\" %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -661,16 +661,16 @@ static void test_template_parse_invalid_if_operand(void **state) { const char *a = "{% block entry %}{% if BOLA == asd %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == asd %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -678,16 +678,16 @@ static void test_template_parse_invalid_if_operand2(void **state) { const char *a = "{% block entry %}{% if BOLA == \"asd %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Found an open double-quoted string.\n" "Error occurred near line 1, position 31: " "{% block entry %}{% if BOLA == \"asd %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -695,16 +695,16 @@ static void test_template_parse_invalid_if_operand3(void **state) { const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == 0123 %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -712,15 +712,15 @@ static void test_template_parse_invalid_block_end(void **state) { const char *a = "{% block entry }}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '%}'.\n" "Error occurred near line 1, position 16: {% block entry }}"); - sb_error_free(err); + blogc_error_free(err); } @@ -728,16 +728,16 @@ static void test_template_parse_invalid_variable_name(void **state) { const char *a = "{% block entry %}{{ bola }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: " "{% block entry %}{{ bola }}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -745,16 +745,16 @@ static void test_template_parse_invalid_variable_name2(void **state) { const char *a = "{% block entry %}{{ Bola }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must be uppercase letter, number or '_'.\n" "Error occurred near line 1, position 22: " "{% block entry %}{{ Bola }}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -762,16 +762,16 @@ static void test_template_parse_invalid_variable_name3(void **state) { const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid variable name. Must begin with uppercase letter.\n" "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" "{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -779,16 +779,16 @@ static void test_template_parse_invalid_variable_end(void **state) { const char *a = "{% block entry %}{{ BOLA %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}}'.\n" "Error occurred near line 1, position 26: " "{% block entry %}{{ BOLA %}{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -796,15 +796,15 @@ static void test_template_parse_invalid_close(void **state) { const char *a = "{% block entry %%\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 17: {% block entry %%"); - sb_error_free(err); + blogc_error_free(err); } @@ -812,16 +812,16 @@ static void test_template_parse_invalid_close2(void **state) { const char *a = "{% block entry %}{{ BOLA }%{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement syntax. Must end with '}'.\n" "Error occurred near line 1, position 27: " "{% block entry %}{{ BOLA }%{% endblock %}"); - sb_error_free(err); + blogc_error_free(err); } @@ -829,14 +829,14 @@ static void test_template_parse_invalid_if_not_closed(void **state) { const char *a = "{% block entry %}{% ifdef BOLA %}{% endblock %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "1 open 'ifdef' and/or 'ifndef' statements " "were not closed!"); - sb_error_free(err); + blogc_error_free(err); } @@ -844,13 +844,13 @@ static void test_template_parse_invalid_block_not_closed(void **state) { const char *a = "{% block entry %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open block was not closed!"); - sb_error_free(err); + blogc_error_free(err); } @@ -858,13 +858,13 @@ static void test_template_parse_invalid_foreach_not_closed(void **state) { const char *a = "{% foreach ASD %}\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_non_null(err); assert_null(stmts); - assert_int_equal(err->code, BLOGC_ERROR_TEMPLATE_PARSER); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "An open 'foreach' statement was not closed!"); - sb_error_free(err); + blogc_error_free(err); } -- cgit v1.2.3-18-g5258 From 74b2ee22a6b60d53b1241e0c52284b288e561599 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 01:38:10 +0200 Subject: moved squareball back to blogc source tree. i don't have enough time to maintain a separated library at this point, and worry about soname bump, library stability, etc. all the code is trivial enough to be copied around, and all the utils are implemented as single file now, to make it easier to copy. --- .gitmodules | 3 - Makefile.am | 43 +- configure.ac | 24 -- squareball | 1 - src/utils.c | 612 ++++++++++++++++++++++++++++ src/utils.h | 102 +++++ tests/check_source_parser.c | 2 +- tests/check_utils.c | 959 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 1694 insertions(+), 52 deletions(-) delete mode 100644 .gitmodules delete mode 160000 squareball create mode 100644 src/utils.c create mode 100644 src/utils.h create mode 100644 tests/check_utils.c diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 061fb99..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "squareball"] - path = squareball - url = https://github.com/rafaelmartins/squareball.git diff --git a/Makefile.am b/Makefile.am index a0559ea..8237508 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,16 +1,11 @@ ## Autotools settings -if INTERNAL_SQUAREBALL -SUBDIRS = squareball -endif - ACLOCAL_AMFLAGS = -I m4 AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-tests \ --enable-ronn \ --disable-valgrind \ - --with-squareball=internal \ $(NULL) @@ -43,6 +38,7 @@ noinst_HEADERS = \ src/renderer.h \ src/source-parser.h \ src/template-parser.h \ + src/utils.h \ $(NULL) noinst_LTLIBRARIES = \ @@ -69,17 +65,16 @@ libblogc_la_SOURCES = \ src/renderer.c \ src/source-parser.c \ src/template-parser.c \ + src/utils.c \ $(NULL) libblogc_la_CFLAGS = \ $(AM_CFLAGS) \ -I$(top_srcdir)/src \ - $(SQUAREBALL_CFLAGS) \ $(NULL) libblogc_la_LIBADD = \ $(LIBM) \ - $(SQUAREBALL_LIBS) \ $(NULL) @@ -90,12 +85,10 @@ blogc_SOURCES = \ blogc_CFLAGS = \ $(AM_CFLAGS) \ -I$(top_srcdir)/src \ - $(SQUAREBALL_CFLAGS) \ $(NULL) blogc_LDADD = \ libblogc.la \ - $(SQUAREBALL_LIBS) \ $(NULL) @@ -170,6 +163,7 @@ check_PROGRAMS += \ tests/check_renderer \ tests/check_source_parser \ tests/check_template_parser \ + tests/check_utils \ $(NULL) tests_check_error_SOURCES = \ @@ -177,7 +171,6 @@ tests_check_error_SOURCES = \ $(NULL) tests_check_error_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -186,7 +179,6 @@ tests_check_error_LDFLAGS = \ $(NULL) tests_check_error_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -196,7 +188,6 @@ tests_check_loader_SOURCES = \ $(NULL) tests_check_loader_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -207,7 +198,6 @@ tests_check_loader_LDFLAGS = \ $(NULL) tests_check_loader_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -217,7 +207,6 @@ tests_check_content_parser_SOURCES = \ $(NULL) tests_check_content_parser_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -226,7 +215,6 @@ tests_check_content_parser_LDFLAGS = \ $(NULL) tests_check_content_parser_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -236,7 +224,6 @@ tests_check_datetime_parser_SOURCES = \ $(NULL) tests_check_datetime_parser_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -245,7 +232,6 @@ tests_check_datetime_parser_LDFLAGS = \ $(NULL) tests_check_datetime_parser_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -255,7 +241,6 @@ tests_check_renderer_SOURCES = \ $(NULL) tests_check_renderer_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -264,7 +249,6 @@ tests_check_renderer_LDFLAGS = \ $(NULL) tests_check_renderer_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -274,7 +258,6 @@ tests_check_source_parser_SOURCES = \ $(NULL) tests_check_source_parser_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -283,7 +266,6 @@ tests_check_source_parser_LDFLAGS = \ $(NULL) tests_check_source_parser_LDADD = \ - $(SQUAREBALL_LIBS) \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) @@ -293,7 +275,6 @@ tests_check_template_parser_SOURCES = \ $(NULL) tests_check_template_parser_CFLAGS = \ - $(SQUAREBALL_CFLAGS) \ $(CMOCKA_CFLAGS) \ $(NULL) @@ -302,7 +283,23 @@ tests_check_template_parser_LDFLAGS = \ $(NULL) tests_check_template_parser_LDADD = \ - $(SQUAREBALL_LIBS) \ + $(CMOCKA_LIBS) \ + libblogc.la \ + $(NULL) + +tests_check_utils_SOURCES = \ + tests/check_utils.c \ + $(NULL) + +tests_check_utils_CFLAGS = \ + $(CMOCKA_CFLAGS) \ + $(NULL) + +tests_check_utils_LDFLAGS = \ + -no-install \ + $(NULL) + +tests_check_utils_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ $(NULL) diff --git a/configure.ac b/configure.ac index 0bc1e19..1e7366e 100644 --- a/configure.ac +++ b/configure.ac @@ -123,29 +123,6 @@ AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M -AC_ARG_WITH([squareball], [AS_HELP_STRING([--with-squareball=@<:@internal/system@:>@], - [whether to use library squareball from system [default=internal]])]) -AS_IF([test "x$with_squareball" = "xsystem"], [ - SQUAREBALL="system" - PKG_CHECK_MODULES([SQUAREBALL], [squareball >= 0.2.0], , [ - AC_MSG_ERROR([library squareball requested from system but not found or not new enough]) - ]) -], [ - SQUAREBALL="internal" - SQUAREBALL_CFLAGS='-I$(top_srcdir)/squareball/src' - SQUAREBALL_LIBS='$(top_builddir)/squareball/libsquareball.la' - AC_SUBST(SQUAREBALL_LIBS) - AC_SUBST(SQUAREBALL_CFLAGS) - ac_configure_args_pre="$ac_configure_args" - ac_configure_args_post="$ac_configure_args --enable-bundleme" - ac_configure_args="$ac_configure_args_post" - AC_CONFIG_COMMANDS_PRE([ac_configure_args="$ac_configure_args_pre"]) - AC_CONFIG_COMMANDS_POST([ac_configure_args="$ac_configure_args_post"]) - AC_CONFIG_SUBDIRS([squareball]) - ac_configure_args="$ac_configure_args_pre" -]) -AM_CONDITIONAL(INTERNAL_SQUAREBALL, [test "x$with_squareball" != "xsystem"]) - AC_CONFIG_FILES([ Makefile blogc.spec @@ -164,7 +141,6 @@ AS_ECHO(" cflags: ${CFLAGS} ldflags: ${LDFLAGS} - squareball: ${SQUAREBALL} tests: ${TESTS} ronn: ${RONN} diff --git a/squareball b/squareball deleted file mode 160000 index e2639b0..0000000 --- a/squareball +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e2639b044e450ed54cf6e768ed2eb8b88e5c0555 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#define SB_STRING_CHUNK_SIZE 128 + +#include +#include +#include +#include +#include +#include +#include + +#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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifndef _UTILS_H +#define _UTILS_H + +#include +#include +#include +#include +#include + + +// 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/tests/check_source_parser.c b/tests/check_source_parser.c index 0f891dd..477399c 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -173,7 +173,7 @@ test_source_parse_with_description(void **state) "# This is a test\n" "\n" "bola\n"; - sb_error_t *err = NULL; + blogc_error_t *err = NULL; sb_trie_t *source = blogc_source_parse(a, strlen(a), &err); assert_null(err); assert_non_null(source); diff --git a/tests/check_utils.c b/tests/check_utils.c new file mode 100644 index 0000000..6a6ceca --- /dev/null +++ b/tests/check_utils.c @@ -0,0 +1,959 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2014-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#include +#include +#include +#include + +#include + +#include "../src/utils.h" + +#define SB_STRING_CHUNK_SIZE 128 + + +static void +test_slist_append(void **state) +{ + 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 = 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); + 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) +{ + 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"); + free(t1); + free(t2); + free(t3); +} + + +static void +test_slist_length(void **state) +{ + 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 = sb_strdup("bola"); + assert_string_equal(str, "bola"); + free(str); + str = sb_strdup(NULL); + assert_null(str); +} + + +static void +test_strndup(void **state) +{ + char *str = sb_strndup("bolaguda", 4); + assert_string_equal(str, "bola"); + free(str); + str = sb_strndup("bolaguda", 30); + assert_string_equal(str, "bolaguda"); + free(str); + str = sb_strndup("bolaguda", 8); + assert_string_equal(str, "bolaguda"); + free(str); + str = sb_strdup(NULL); + assert_null(str); +} + + +static void +test_strdup_printf(void **state) +{ + char *str = sb_strdup_printf("bola"); + assert_string_equal(str, "bola"); + free(str); + str = sb_strdup_printf("bola, %s", "guda"); + assert_string_equal(str, "bola, guda"); + free(str); +} + + +static void +test_str_starts_with(void **state) +{ + 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(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 = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_lstrip(str), "bola\n \t"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_lstrip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_lstrip(str), ""); + free(str); + assert_null(sb_str_lstrip(NULL)); +} + + +static void +test_str_rstrip(void **state) +{ + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_rstrip(str), " \tbola"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_rstrip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_rstrip(str), ""); + free(str); + assert_null(sb_str_rstrip(NULL)); +} + + +static void +test_str_strip(void **state) +{ + char *str = sb_strdup(" \tbola\n \t"); + assert_string_equal(sb_str_strip(str), "bola"); + free(str); + str = sb_strdup("guda"); + assert_string_equal(sb_str_strip(str), "guda"); + free(str); + str = sb_strdup("\n"); + assert_string_equal(sb_str_strip(str), ""); + free(str); + str = sb_strdup("\t \n"); + assert_string_equal(sb_str_strip(str), ""); + free(str); + str = sb_strdup(""); + assert_string_equal(sb_str_strip(str), ""); + free(str); + assert_null(sb_str_strip(NULL)); +} + + +static void +test_str_split(void **state) +{ + 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]); + 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]); + sb_strv_free(strv); + strv = sb_str_split("bola:guda:chunda", ':', 1); + assert_string_equal(strv[0], "bola:guda:chunda"); + assert_null(strv[1]); + sb_strv_free(strv); + strv = sb_str_split("", ':', 1); + assert_null(strv[0]); + sb_strv_free(strv); + assert_null(sb_str_split(NULL, ':', 0)); +} + + +static void +test_str_replace(void **state) +{ + char *str = sb_str_replace("bolao", 'o', "zaz"); + assert_string_equal(str, "bzazlazaz"); + free(str); + 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) +{ + char *pieces[] = {"guda","bola", "chunda", NULL}; + char *str = sb_strv_join(pieces, ":"); + assert_string_equal(str, "guda:bola:chunda"); + free(str); + char *pieces2[] = {NULL}; + str = sb_strv_join(pieces2, ":"); + assert_string_equal(str, ""); + free(str); + assert_null(sb_strv_join(pieces, NULL)); + assert_null(sb_strv_join(NULL, ":")); + assert_null(sb_strv_join(NULL, NULL)); +} + + +static void +test_strv_length(void **state) +{ + char *pieces[] = {"guda","bola", "chunda", NULL}; + assert_int_equal(sb_strv_length(pieces), 3); + char *pieces2[] = {NULL}; + assert_int_equal(sb_strv_length(pieces2), 0); + assert_int_equal(sb_strv_length(NULL), 0); +} + + +static void +test_string_new(void **state) +{ + 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, SB_STRING_CHUNK_SIZE); + assert_null(sb_string_free(str, true)); +} + + +static void +test_string_free(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; + 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) +{ + 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, 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, 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, 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" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); + str = sb_string_append_len(str, NULL, 0); + str = sb_string_append_len(str, + "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" + "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" + "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf", 600); + assert_non_null(str); + assert_string_equal(str->str, + "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" + "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" + "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" + "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" + "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" + "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" + "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" + "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" + "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" + "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" + "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" + "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" + "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" + "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" + "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" + "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" + "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" + "fkeannglvsxprqzfekdinssqymtfexf"); + assert_int_equal(str->len, 1204); + assert_int_equal(str->allocated_len, 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) +{ + 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, 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, 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" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); + str = sb_string_append(str, NULL); + str = sb_string_append(str, + "cwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcw" + "nnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwa" + "xfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevaz" + "dxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcec" + "hgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbc" + "sbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnd" + "dxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnr" + "ftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtg" + "okxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexf"); + assert_non_null(str); + assert_string_equal(str->str, + "gudacwlwmwxxmvjnwtidmjehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjid" + "zkcwnnqhxhneolbwqlctcxmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtax" + "jiwaxfhfyzymtffusoqywaruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqv" + "evazdxrewtgapkompnviiyielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywh" + "qcechgrwzaglzogwjvqncjzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxj" + "rsbcsbfvpylgjznsuhxcxoqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqd" + "atnddxntikgoqlidfnmdhxzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvw" + "srnrftzfeyasjpxoevyptpdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsf" + "nwtgokxhegoifakimxbbafkeannglvsxprqzfekdinssqymtfexfcwlwmwxxmvjnwtidm" + "jehzdeexbxjnjowruxjrqpgpfhmvwgqeacdjissntmbtsjidzkcwnnqhxhneolbwqlctc" + "xmrsutolrjikpavxombpfpjyaqltgvzrjidotalcuwrwxtaxjiwaxfhfyzymtffusoqyw" + "aruxpybwggukltspqqmghzpqstvcvlqbkhquihzndnrvkaqvevazdxrewtgapkompnvii" + "yielanoyowgqhssntyvcvqqtfjmkphywbkvzfyttaalttywhqcechgrwzaglzogwjvqnc" + "jzodaqsblcbpcdpxmrtctzginvtkckhqvdplgjvbzrnarcxjrsbcsbfvpylgjznsuhxcx" + "oqbpxowmsrgwimxjgyzwwmryqvstwzkglgeezelvpvkwefqdatnddxntikgoqlidfnmdh" + "xzevqzlzubvyleeksdirmmttqthhkvfjggznpmarcamacpvwsrnrftzfeyasjpxoevypt" + "pdnqokswiondusnuymqwaryrmdgscbnuilxtypuynckancsfnwtgokxhegoifakimxbba" + "fkeannglvsxprqzfekdinssqymtfexf"); + assert_int_equal(str->len, 1204); + assert_int_equal(str->allocated_len, 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) +{ + sb_string_t *str = sb_string_new(); + str = sb_string_append_len(str, "guda", 4); + for (int i = 0; i < 600; i++) + str = sb_string_append_c(str, 'c'); + assert_non_null(str); + assert_string_equal(str->str, + "gudaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" + "cccccccccccccccccccccccccccccccccccccccccccccccccccc"); + assert_int_equal(str->len, 604); + assert_int_equal(str->allocated_len, 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) +{ + 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, 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) +{ + sb_trie_t *trie = sb_trie_new(free); + assert_non_null(trie); + assert_null(trie->root); + assert_true(trie->free_func == free); + sb_trie_free(trie); +} + + +static void +test_trie_insert(void **state) +{ + sb_trie_t *trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + assert_true(trie->root->child->child->next->key == 't'); + assert_null(trie->root->child->child->next->data); + assert_true(trie->root->child->child->next->child->key == 'e'); + assert_null(trie->root->child->child->next->child->data); + assert_true(trie->root->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->key == 'c'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'h'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'u'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->data, "nda"); + + assert_true(trie->root->child->child->next->key == 't'); + assert_null(trie->root->child->child->next->data); + assert_true(trie->root->child->child->next->child->key == 'e'); + assert_null(trie->root->child->child->next->child->data); + assert_true(trie->root->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->next->child->child->data, "aba"); + + assert_true(trie->root->child->child->next->next->key == '\0'); + assert_string_equal(trie->root->child->child->next->next->data, "haha"); + + sb_trie_free(trie); + + + trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->child->child->next->key == 't'); + assert_null(trie->root->next->child->child->next->data); + assert_true(trie->root->next->child->child->next->child->key == 'e'); + assert_null(trie->root->next->child->child->next->child->data); + assert_true(trie->root->next->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); + + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'u'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->data, "nda"); + + assert_true(trie->root->next->key == 'b'); + assert_null(trie->root->next->data); + assert_true(trie->root->next->child->key == 'o'); + assert_null(trie->root->next->child->data); + assert_true(trie->root->next->child->child->key == 'l'); + assert_null(trie->root->next->child->child->data); + assert_true(trie->root->next->child->child->child->key == 'a'); + assert_null(trie->root->next->child->child->child->data); + assert_true(trie->root->next->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->child->child->data, "guda"); + + assert_true(trie->root->next->child->child->next->key == 't'); + assert_null(trie->root->next->child->child->next->data); + assert_true(trie->root->next->child->child->next->child->key == 'e'); + assert_null(trie->root->next->child->child->next->child->data); + assert_true(trie->root->next->child->child->next->child->child->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->child->child->data, "aba"); + + assert_true(trie->root->next->child->child->next->next->key == '\0'); + assert_string_equal(trie->root->next->child->child->next->next->data, "haha"); + + sb_trie_free(trie); +} + + +static void +test_trie_insert_duplicated(void **state) +{ + sb_trie_t *trie = sb_trie_new(free); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "guda"); + + 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'); + assert_null(trie->root->child->data); + assert_true(trie->root->child->child->key == 'l'); + assert_null(trie->root->child->child->data); + assert_true(trie->root->child->child->child->key == 'a'); + assert_null(trie->root->child->child->child->data); + assert_true(trie->root->child->child->child->child->key == '\0'); + assert_string_equal(trie->root->child->child->child->child->data, "asdf"); + + sb_trie_free(trie); + + trie = NULL; + sb_trie_insert(trie, "bola", NULL); + assert_null(trie); +} + + +static void +test_trie_keep_data(void **state) +{ + sb_trie_t *trie = sb_trie_new(NULL); + + char *t1 = "guda"; + char *t2 = "nda"; + char *t3 = "aba"; + char *t4 = "haha"; + + sb_trie_insert(trie, "bola", t1); + sb_trie_insert(trie, "chu", t2); + sb_trie_insert(trie, "bote", t3); + sb_trie_insert(trie, "bo", t4); + + sb_trie_free(trie); + + assert_string_equal(t1, "guda"); + assert_string_equal(t2, "nda"); + assert_string_equal(t3, "aba"); + assert_string_equal(t4, "haha"); +} + + +static void +test_trie_lookup(void **state) +{ + 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")); + + 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_null(sb_trie_lookup(trie, "arcoiro")); + + sb_trie_free(trie); + + trie = sb_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")); + + 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_null(sb_trie_lookup(trie, "arcoiro")); + + sb_trie_free(trie); + + assert_null(sb_trie_lookup(NULL, "bola")); +} + + +static void +test_trie_size(void **state) +{ + 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")); + + assert_int_equal(sb_trie_size(trie), 4); + assert_int_equal(sb_trie_size(NULL), 0); + + sb_trie_free(trie); + + trie = sb_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")); + + assert_int_equal(sb_trie_size(trie), 7); + assert_int_equal(sb_trie_size(NULL), 0); + + sb_trie_free(trie); +} + + +static unsigned int counter; +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, void *user_data) +{ + assert_string_equal(user_data, "foo"); + assert_string_equal(key, expected_keys[counter]); + assert_string_equal((char*) data, expected_datas[counter++]); +} + + +static void +test_trie_foreach(void **state) +{ + sb_trie_t *trie = sb_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")); + + counter = 0; + 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"); + + sb_trie_free(trie); +} + + +int +main(void) +{ + const UnitTest tests[] = { + + // slist + unit_test(test_slist_append), + unit_test(test_slist_prepend), + unit_test(test_slist_free), + unit_test(test_slist_length), + + // strfuncs + unit_test(test_strdup), + unit_test(test_strndup), + unit_test(test_strdup_printf), + unit_test(test_str_starts_with), + unit_test(test_str_ends_with), + unit_test(test_str_lstrip), + unit_test(test_str_rstrip), + unit_test(test_str_strip), + unit_test(test_str_split), + unit_test(test_str_replace), + unit_test(test_strv_join), + unit_test(test_strv_length), + + // string + unit_test(test_string_new), + unit_test(test_string_free), + unit_test(test_string_dup), + unit_test(test_string_append_len), + unit_test(test_string_append), + unit_test(test_string_append_c), + unit_test(test_string_append_printf), + + // trie + unit_test(test_trie_new), + unit_test(test_trie_insert), + unit_test(test_trie_insert_duplicated), + unit_test(test_trie_keep_data), + unit_test(test_trie_lookup), + unit_test(test_trie_size), + unit_test(test_trie_foreach), + }; + return run_tests(tests); +} -- cgit v1.2.3-18-g5258 From 9699bf0ce6b34c0d05c509925f3367f2200caad5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 02:34:19 +0200 Subject: remove squareball for good --- blogc.spec.in | 4 +--- build-aux/travis-build.sh | 1 - src/content-parser.c | 2 +- src/datetime-parser.c | 2 +- src/error.c | 2 +- src/file.c | 2 +- src/loader.c | 2 +- src/loader.h | 2 +- src/main.c | 2 +- src/renderer.c | 2 +- src/renderer.h | 2 +- src/source-parser.c | 2 +- src/source-parser.h | 2 +- src/template-parser.c | 2 +- src/template-parser.h | 2 +- tests/check_content_parser.c | 2 +- tests/check_error.c | 2 +- tests/check_loader.c | 2 +- tests/check_renderer.c | 2 +- tests/check_source_parser.c | 2 +- tests/check_template_parser.c | 2 +- 21 files changed, 20 insertions(+), 23 deletions(-) diff --git a/blogc.spec.in b/blogc.spec.in index adec43a..cc39b12 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -7,8 +7,6 @@ Summary: A blog compiler URL: @PACKAGE_URL@ Source0: https://github.com/blogc/blogc/releases/download/v@PACKAGE_VERSION@/blogc-@PACKAGE_VERSION@.tar.xz -BuildRequires: squareball-devel >= 0.2.0 - %description blogc(1) is a blog compiler. It converts source files and templates into blog/website resources. @@ -17,7 +15,7 @@ blog/website resources. %setup -q -n @PACKAGE_NAME@-@PACKAGE_VERSION@ %build -%configure --with-squareball=system +%configure make %{?_smp_mflags} %install diff --git a/build-aux/travis-build.sh b/build-aux/travis-build.sh index d03cafd..1fcac10 100755 --- a/build-aux/travis-build.sh +++ b/build-aux/travis-build.sh @@ -23,7 +23,6 @@ pushd build > /dev/null ../configure \ ${CHOST:+--host=${CHOST} --target=${CHOST}} \ --enable-ronn \ - --with-squareball=internal \ --disable-silent-rules \ ${CONFIGURE_ARGS} diff --git a/src/content-parser.c b/src/content-parser.c index 795cc34..0c99e31 100644 --- a/src/content-parser.c +++ b/src/content-parser.c @@ -13,8 +13,8 @@ #include #include -#include #include "content-parser.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. diff --git a/src/datetime-parser.c b/src/datetime-parser.c index 0aeb702..ad65ff7 100644 --- a/src/datetime-parser.c +++ b/src/datetime-parser.c @@ -17,8 +17,8 @@ #include #include "error.h" -#include #include "datetime-parser.h" +#include "utils.h" typedef enum { diff --git a/src/error.c b/src/error.c index f05049c..586386a 100644 --- a/src/error.c +++ b/src/error.c @@ -14,8 +14,8 @@ #include #include #include -#include #include "error.h" +#include "utils.h" blogc_error_t* diff --git a/src/file.c b/src/file.c index dec7c1b..f784d93 100644 --- a/src/file.c +++ b/src/file.c @@ -14,9 +14,9 @@ #include #include #include -#include #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. diff --git a/src/loader.c b/src/loader.c index 8008c3a..5ca0aac 100644 --- a/src/loader.c +++ b/src/loader.c @@ -14,12 +14,12 @@ #include #include #include -#include #include "file.h" #include "source-parser.h" #include "template-parser.h" #include "loader.h" #include "error.h" +#include "utils.h" char* diff --git a/src/loader.h b/src/loader.h index 080aff6..32b58be 100644 --- a/src/loader.h +++ b/src/loader.h @@ -9,8 +9,8 @@ #ifndef _LOADER_H #define _LOADER_H -#include #include "error.h" +#include "utils.h" char* blogc_get_filename(const char *f); sb_slist_t* blogc_template_parse_from_file(const char *f, blogc_error_t **err); diff --git a/src/main.c b/src/main.c index 143c836..2338c9e 100644 --- a/src/main.c +++ b/src/main.c @@ -24,12 +24,12 @@ #include #include -#include #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" diff --git a/src/renderer.c b/src/renderer.c index a7a7dd7..5af3b8a 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -13,13 +13,13 @@ #include #include #include -#include #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* diff --git a/src/renderer.h b/src/renderer.h index 3ff62e7..2982ee8 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -10,7 +10,7 @@ #define _RENDERER_H #include -#include +#include "utils.h" const char* blogc_get_variable(const char *name, sb_trie_t *global, sb_trie_t *local); char* blogc_format_date(const char *date, sb_trie_t *global, sb_trie_t *local); diff --git a/src/source-parser.c b/src/source-parser.c index 67c3717..f250bd3 100644 --- a/src/source-parser.c +++ b/src/source-parser.c @@ -13,10 +13,10 @@ #include #include -#include #include "content-parser.h" #include "source-parser.h" #include "error.h" +#include "utils.h" typedef enum { diff --git a/src/source-parser.h b/src/source-parser.h index 460aedb..5cadf95 100644 --- a/src/source-parser.h +++ b/src/source-parser.h @@ -10,8 +10,8 @@ #define _SOURCE_PARSER_H #include -#include #include "error.h" +#include "utils.h" sb_trie_t* blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err); diff --git a/src/template-parser.c b/src/template-parser.c index 6f23ef1..525f5f5 100644 --- a/src/template-parser.c +++ b/src/template-parser.c @@ -13,9 +13,9 @@ #include #include -#include #include "template-parser.h" #include "error.h" +#include "utils.h" typedef enum { diff --git a/src/template-parser.h b/src/template-parser.h index de5113e..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 #include "error.h" +#include "utils.h" /* * note: whitespace cleaners are NOT added to ast. we fix strings right during diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 0eaab70..2444ebb 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -16,7 +16,7 @@ #include #include #include "../src/content-parser.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_error.c b/tests/check_error.c index 4effb08..8818b00 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -16,7 +16,7 @@ #include #include #include "../src/error.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_loader.c b/tests/check_loader.c index a07376a..4a5dc32 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -18,7 +18,7 @@ #include #include "../src/template-parser.h" #include "../src/loader.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_renderer.c b/tests/check_renderer.c index e863360..13e7309 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -19,7 +19,7 @@ #include "../src/renderer.h" #include "../src/source-parser.h" #include "../src/template-parser.h" -#include +#include "../src/utils.h" static sb_slist_t* diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 477399c..d94dc70 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -17,7 +17,7 @@ #include #include "../src/source-parser.h" #include "../src/error.h" -#include +#include "../src/utils.h" static void diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index ed4328b..40a09be 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -17,7 +17,7 @@ #include #include "../src/template-parser.h" #include "../src/error.h" -#include +#include "../src/utils.h" static void -- cgit v1.2.3-18-g5258 From 6f975248895d0300c6fd8783b1138bdd4be00bcc Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 03:22:31 +0200 Subject: blogc-git-receiver: import external tool to blogc repository still in the effort to reduce maintenance work, I'm importing blogc-git-receiver tool to the main blogc repository. the tool is build by default, if needed headers are found. that means that it will probably only be built for posix-compliant operating systems. --- .gitignore | 3 +- Makefile.am | 55 ++++- build-aux/travis-build.sh | 3 +- configure.ac | 42 +++- src/blogc-git-receiver.c | 502 ++++++++++++++++++++++++++++++++++++++++++++++ src/blogc.c | 285 ++++++++++++++++++++++++++ src/main.c | 285 -------------------------- 7 files changed, 874 insertions(+), 301 deletions(-) create mode 100644 src/blogc-git-receiver.c create mode 100644 src/blogc.c delete mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index 48f0735..911360f 100644 --- a/.gitignore +++ b/.gitignore @@ -44,8 +44,9 @@ Makefile.in /blogc*.[17] blogc*.html -# blogc +# binaries /blogc +/blogc-git-receiver # tests /tests/check_content_parser diff --git a/Makefile.am b/Makefile.am index 8237508..934e1cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-tests \ --enable-ronn \ --disable-valgrind \ + --enable-git-receiver \ $(NULL) @@ -43,6 +44,7 @@ noinst_HEADERS = \ noinst_LTLIBRARIES = \ libblogc.la \ + libblogc_utils.la \ $(NULL) noinst_PROGRAMS = \ @@ -52,6 +54,12 @@ bin_PROGRAMS = \ blogc \ $(NULL) +if BUILD_GIT_RECEIVER +bin_PROGRAMS += \ + blogc-git-receiver \ + $(NULL) +endif + check_PROGRAMS = \ $(NULL) @@ -65,7 +73,6 @@ libblogc_la_SOURCES = \ src/renderer.c \ src/source-parser.c \ src/template-parser.c \ - src/utils.c \ $(NULL) libblogc_la_CFLAGS = \ @@ -78,8 +85,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 = \ @@ -89,9 +106,26 @@ 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 + + ## Build rules: man pages EXTRA_DIST += \ @@ -107,6 +141,14 @@ dist_man_MANS = \ blogc-template.7 \ $(NULL) +if BUILD_GIT_RECEIVER +EXTRA_DIST += \ + $(NULL) + +dist_man_MANS += \ + $(NULL) +endif + MAINTAINERCLEANFILES += \ $(dist_man_MANS) \ $(NULL) @@ -181,6 +223,7 @@ tests_check_error_LDFLAGS = \ tests_check_error_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_loader_SOURCES = \ @@ -200,6 +243,7 @@ tests_check_loader_LDFLAGS = \ tests_check_loader_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_content_parser_SOURCES = \ @@ -217,6 +261,7 @@ tests_check_content_parser_LDFLAGS = \ tests_check_content_parser_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_datetime_parser_SOURCES = \ @@ -234,6 +279,7 @@ tests_check_datetime_parser_LDFLAGS = \ tests_check_datetime_parser_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_renderer_SOURCES = \ @@ -251,6 +297,7 @@ tests_check_renderer_LDFLAGS = \ tests_check_renderer_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_source_parser_SOURCES = \ @@ -268,6 +315,7 @@ tests_check_source_parser_LDFLAGS = \ tests_check_source_parser_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_template_parser_SOURCES = \ @@ -285,6 +333,7 @@ tests_check_template_parser_LDFLAGS = \ tests_check_template_parser_LDADD = \ $(CMOCKA_LIBS) \ libblogc.la \ + libblogc_utils.la \ $(NULL) tests_check_utils_SOURCES = \ @@ -301,7 +350,7 @@ tests_check_utils_LDFLAGS = \ tests_check_utils_LDADD = \ $(CMOCKA_LIBS) \ - libblogc.la \ + libblogc_utils.la \ $(NULL) endif diff --git a/build-aux/travis-build.sh b/build-aux/travis-build.sh index 1fcac10..4187575 100755 --- a/build-aux/travis-build.sh +++ b/build-aux/travis-build.sh @@ -13,9 +13,10 @@ if [[ "x${TARGET}" = xw* ]]; then export CHOST="x86_64-w64-mingw32" [[ "x${TARGET}" = "xw32" ]] && export CHOST="i686-w64-mingw32" MAKE_TARGET="all" + CONFIGURE_ARGS="--disable-git-receiver" else export CFLAGS="-Wall -g" - export CONFIGURE_ARGS="--enable-tests --enable-valgrind" + CONFIGURE_ARGS="--enable-tests --enable-valgrind" fi pushd build > /dev/null diff --git a/configure.ac b/configure.ac index 1e7366e..858db59 100644 --- a/configure.ac +++ b/configure.ac @@ -119,6 +119,24 @@ 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([--disable-git-receiver], + [disable blogc-git-receiver build])) +AS_IF([test "x$enable_git_receiver" != "xno"], [ + 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 + ], [ + have_git_receiver=no + ]) +]) +AS_IF([test "x$have_git_receiver" = "xyes"], , [ + AS_IF([test "x$enable_git_receiver" = "xyes"], [ + AC_MSG_ERROR([blogc-git-receiver requested but required headers not found]) + ]) +]) +AM_CONDITIONAL([BUILD_GIT_RECEIVER], [test "x$have_git_receiver" = "xyes"]) + AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M @@ -131,19 +149,21 @@ AC_CONFIG_FILES([ 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} - tests: ${TESTS} + tests: ${TESTS} - ronn: ${RONN} - valgrind: ${VALGRIND} - rpmbuild: ${RPMBUILD} + ronn: ${RONN} + valgrind: ${VALGRIND} + rpmbuild: ${RPMBUILD} ") 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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.c b/src/blogc.c new file mode 100644 index 0000000..2338c9e --- /dev/null +++ b/src/blogc.c @@ -0,0 +1,285 @@ +/* + * blogc: A blog compiler. + * Copyright (C) 2015-2016 Rafael G. Martins + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_SYS_STAT_H +#include +#endif /* HAVE_SYS_STAT_H */ + +#ifdef HAVE_SYS_TYPES_H +#include +#endif /* HAVE_SYS_TYPES_H */ + +#include +#include +#include +#include +#include + +#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" +#endif + + +static void +blogc_print_help(void) +{ + printf( + "usage:\n" + " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" + " [-o OUTPUT] [SOURCE ...] - A blog compiler.\n" + "\n" + "positional arguments:\n" + " SOURCE source file(s)\n" + "\n" + "optional arguments:\n" + " -h show this help message and exit\n" + " -v show version and exit\n" + " -l build listing page, from multiple source files\n" + " -D KEY=VALUE set global configuration parameter\n" + " -p KEY show the value of a global configuration parameter\n" + " after source parsing and exit\n" + " -t TEMPLATE template file\n" + " -o OUTPUT output file\n"); +} + + +static void +blogc_print_usage(void) +{ + printf( + "usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" + " [-o OUTPUT] [SOURCE ...]\n"); +} + + +static void +blogc_mkdir_recursive(const char *filename) +{ + char *fname = sb_strdup(filename); + for (char *tmp = fname; *tmp != '\0'; tmp++) { + if (*tmp != '/' && *tmp != '\\') + continue; +#if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H) + char bkp = *tmp; + *tmp = '\0'; + if ((strlen(fname) > 0) && +#if defined(WIN32) || defined(_WIN32) + (-1 == mkdir(fname)) && +#else + (-1 == mkdir(fname, 0777)) && +#endif + (errno != EEXIST)) + { + fprintf(stderr, "blogc: error: failed to create output " + "directory (%s): %s\n", fname, strerror(errno)); + free(fname); + exit(2); + } + *tmp = bkp; +#else + // FIXME: show this warning only if actually trying to create a directory. + fprintf(stderr, "blogc: warning: can't create output directories " + "for your platform. please create the directories yourself.\n"); + break; +#endif + } + free(fname); +} + + +int +main(int argc, char **argv) +{ + setlocale(LC_ALL, ""); + + int rv = 0; + + bool listing = false; + char *template = NULL; + char *output = NULL; + char *print = NULL; + char *tmp = NULL; + char **pieces = NULL; + + sb_slist_t *sources = NULL; + sb_trie_t *config = sb_trie_new(free); + sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION)); + + for (unsigned int i = 1; i < argc; i++) { + tmp = NULL; + if (argv[i][0] == '-') { + switch (argv[i][1]) { + case 'h': + blogc_print_help(); + goto cleanup; + case 'v': + printf("%s\n", PACKAGE_STRING); + goto cleanup; + case 'l': + listing = true; + break; + case 't': + if (argv[i][2] != '\0') + template = sb_strdup(argv[i] + 2); + else if (i + 1 < argc) + template = sb_strdup(argv[++i]); + break; + case 'o': + if (argv[i][2] != '\0') + output = sb_strdup(argv[i] + 2); + else if (i + 1 < argc) + output = sb_strdup(argv[++i]); + break; + case 'p': + if (argv[i][2] != '\0') + print = sb_strdup(argv[i] + 2); + else if (i + 1 < argc) + print = sb_strdup(argv[++i]); + break; + case 'D': + if (argv[i][2] != '\0') + tmp = argv[i] + 2; + else if (i + 1 < argc) + tmp = argv[++i]; + if (tmp != NULL) { + 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); + sb_strv_free(pieces); + rv = 2; + goto cleanup; + } + for (unsigned int j = 0; pieces[0][j] != '\0'; j++) { + if (!((pieces[0][j] >= 'A' && pieces[0][j] <= 'Z') || + pieces[0][j] == '_')) + { + fprintf(stderr, "blogc: error: invalid value " + "for -D (configuration key must be uppercase " + "with '_'): %s\n", pieces[0]); + sb_strv_free(pieces); + rv = 2; + goto cleanup; + } + } + sb_trie_insert(config, pieces[0], sb_strdup(pieces[1])); + sb_strv_free(pieces); + pieces = NULL; + } + break; + default: + blogc_print_usage(); + fprintf(stderr, "blogc: error: invalid argument: -%c\n", + argv[i][1]); + rv = 2; + goto cleanup; + } + } + else + sources = sb_slist_append(sources, sb_strdup(argv[i])); + } + + 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 && sb_slist_length(sources) > 1) { + blogc_print_usage(); + fprintf(stderr, "blogc: error: only one source file should be provided, " + "if running without '-l'\n"); + rv = 2; + goto cleanup; + } + + blogc_error_t *err = NULL; + + sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err); + if (err != NULL) { + blogc_error_print(err); + rv = 2; + goto cleanup2; + } + + sb_slist_t* l = blogc_template_parse_from_file(template, &err); + if (err != NULL) { + blogc_error_print(err); + rv = 2; + goto cleanup3; + } + + if (print != NULL) { + const char *val = sb_trie_lookup(config, print); + if (val == NULL) { + fprintf(stderr, "blogc: error: configuration variable not found: %s\n", + print); + rv = 2; + } + else { + printf("%s\n", val); + } + goto cleanup3; + } + + if (template == NULL) { + blogc_print_usage(); + fprintf(stderr, "blogc: error: argument -t is required when rendering content\n"); + rv = 2; + goto cleanup3; + } + + char *out = blogc_render(l, s, config, listing); + + bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-"))); + + FILE *fp = stdout; + if (!write_to_stdout) { + blogc_mkdir_recursive(output); + fp = fopen(output, "w"); + if (fp == NULL) { + fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", + output, strerror(errno)); + rv = 2; + goto cleanup4; + } + } + + if (out != NULL) + fprintf(fp, "%s", out); + + if (!write_to_stdout) + fclose(fp); + +cleanup4: + free(out); +cleanup3: + blogc_template_free_stmts(l); +cleanup2: + sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); + blogc_error_free(err); +cleanup: + sb_trie_free(config); + free(template); + free(output); + free(print); + sb_slist_free_full(sources, free); + return rv; +} diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 2338c9e..0000000 --- a/src/main.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2015-2016 Rafael G. Martins - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /* HAVE_CONFIG_H */ - -#ifdef HAVE_SYS_STAT_H -#include -#endif /* HAVE_SYS_STAT_H */ - -#ifdef HAVE_SYS_TYPES_H -#include -#endif /* HAVE_SYS_TYPES_H */ - -#include -#include -#include -#include -#include - -#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" -#endif - - -static void -blogc_print_help(void) -{ - printf( - "usage:\n" - " blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" - " [-o OUTPUT] [SOURCE ...] - A blog compiler.\n" - "\n" - "positional arguments:\n" - " SOURCE source file(s)\n" - "\n" - "optional arguments:\n" - " -h show this help message and exit\n" - " -v show version and exit\n" - " -l build listing page, from multiple source files\n" - " -D KEY=VALUE set global configuration parameter\n" - " -p KEY show the value of a global configuration parameter\n" - " after source parsing and exit\n" - " -t TEMPLATE template file\n" - " -o OUTPUT output file\n"); -} - - -static void -blogc_print_usage(void) -{ - printf( - "usage: blogc [-h] [-v] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" - " [-o OUTPUT] [SOURCE ...]\n"); -} - - -static void -blogc_mkdir_recursive(const char *filename) -{ - char *fname = sb_strdup(filename); - for (char *tmp = fname; *tmp != '\0'; tmp++) { - if (*tmp != '/' && *tmp != '\\') - continue; -#if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H) - char bkp = *tmp; - *tmp = '\0'; - if ((strlen(fname) > 0) && -#if defined(WIN32) || defined(_WIN32) - (-1 == mkdir(fname)) && -#else - (-1 == mkdir(fname, 0777)) && -#endif - (errno != EEXIST)) - { - fprintf(stderr, "blogc: error: failed to create output " - "directory (%s): %s\n", fname, strerror(errno)); - free(fname); - exit(2); - } - *tmp = bkp; -#else - // FIXME: show this warning only if actually trying to create a directory. - fprintf(stderr, "blogc: warning: can't create output directories " - "for your platform. please create the directories yourself.\n"); - break; -#endif - } - free(fname); -} - - -int -main(int argc, char **argv) -{ - setlocale(LC_ALL, ""); - - int rv = 0; - - bool listing = false; - char *template = NULL; - char *output = NULL; - char *print = NULL; - char *tmp = NULL; - char **pieces = NULL; - - sb_slist_t *sources = NULL; - sb_trie_t *config = sb_trie_new(free); - sb_trie_insert(config, "BLOGC_VERSION", sb_strdup(PACKAGE_VERSION)); - - for (unsigned int i = 1; i < argc; i++) { - tmp = NULL; - if (argv[i][0] == '-') { - switch (argv[i][1]) { - case 'h': - blogc_print_help(); - goto cleanup; - case 'v': - printf("%s\n", PACKAGE_STRING); - goto cleanup; - case 'l': - listing = true; - break; - case 't': - if (argv[i][2] != '\0') - template = sb_strdup(argv[i] + 2); - else if (i + 1 < argc) - template = sb_strdup(argv[++i]); - break; - case 'o': - if (argv[i][2] != '\0') - output = sb_strdup(argv[i] + 2); - else if (i + 1 < argc) - output = sb_strdup(argv[++i]); - break; - case 'p': - if (argv[i][2] != '\0') - print = sb_strdup(argv[i] + 2); - else if (i + 1 < argc) - print = sb_strdup(argv[++i]); - break; - case 'D': - if (argv[i][2] != '\0') - tmp = argv[i] + 2; - else if (i + 1 < argc) - tmp = argv[++i]; - if (tmp != NULL) { - 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); - sb_strv_free(pieces); - rv = 2; - goto cleanup; - } - for (unsigned int j = 0; pieces[0][j] != '\0'; j++) { - if (!((pieces[0][j] >= 'A' && pieces[0][j] <= 'Z') || - pieces[0][j] == '_')) - { - fprintf(stderr, "blogc: error: invalid value " - "for -D (configuration key must be uppercase " - "with '_'): %s\n", pieces[0]); - sb_strv_free(pieces); - rv = 2; - goto cleanup; - } - } - sb_trie_insert(config, pieces[0], sb_strdup(pieces[1])); - sb_strv_free(pieces); - pieces = NULL; - } - break; - default: - blogc_print_usage(); - fprintf(stderr, "blogc: error: invalid argument: -%c\n", - argv[i][1]); - rv = 2; - goto cleanup; - } - } - else - sources = sb_slist_append(sources, sb_strdup(argv[i])); - } - - 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 && sb_slist_length(sources) > 1) { - blogc_print_usage(); - fprintf(stderr, "blogc: error: only one source file should be provided, " - "if running without '-l'\n"); - rv = 2; - goto cleanup; - } - - blogc_error_t *err = NULL; - - sb_slist_t *s = blogc_source_parse_from_files(config, sources, &err); - if (err != NULL) { - blogc_error_print(err); - rv = 2; - goto cleanup2; - } - - sb_slist_t* l = blogc_template_parse_from_file(template, &err); - if (err != NULL) { - blogc_error_print(err); - rv = 2; - goto cleanup3; - } - - if (print != NULL) { - const char *val = sb_trie_lookup(config, print); - if (val == NULL) { - fprintf(stderr, "blogc: error: configuration variable not found: %s\n", - print); - rv = 2; - } - else { - printf("%s\n", val); - } - goto cleanup3; - } - - if (template == NULL) { - blogc_print_usage(); - fprintf(stderr, "blogc: error: argument -t is required when rendering content\n"); - rv = 2; - goto cleanup3; - } - - char *out = blogc_render(l, s, config, listing); - - bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-"))); - - FILE *fp = stdout; - if (!write_to_stdout) { - blogc_mkdir_recursive(output); - fp = fopen(output, "w"); - if (fp == NULL) { - fprintf(stderr, "blogc: error: failed to open output file (%s): %s\n", - output, strerror(errno)); - rv = 2; - goto cleanup4; - } - } - - if (out != NULL) - fprintf(fp, "%s", out); - - if (!write_to_stdout) - fclose(fp); - -cleanup4: - free(out); -cleanup3: - blogc_template_free_stmts(l); -cleanup2: - sb_slist_free_full(s, (sb_free_func_t) sb_trie_free); - blogc_error_free(err); -cleanup: - sb_trie_free(config); - free(template); - free(output); - free(print); - sb_slist_free_full(sources, free); - return rv; -} -- cgit v1.2.3-18-g5258 From c4b294c890c28004d33f650b7af5064c4099f608 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 03:51:42 +0200 Subject: blogc-runserver: import external tool to blogc repository still in the effort to reduce maintenance work, I'm importing blogc-runserver tool to the main blogc repository. the tool is build by default, if needed headers and libraries are found. --- .gitignore | 1 + .travis.yml | 2 + Makefile.am | 35 +++++ build-aux/travis-build.sh | 4 +- configure.ac | 29 ++++ src/blogc-runserver.c | 389 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 458 insertions(+), 2 deletions(-) create mode 100644 src/blogc-runserver.c diff --git a/.gitignore b/.gitignore index 911360f..e0ac2c9 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ blogc*.html # binaries /blogc /blogc-git-receiver +/blogc-runserver # tests /tests/check_content_parser diff --git a/.travis.yml b/.travis.yml index 0ea174c..c4bd479 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ addons: - gcc-mingw-w64-i686 - gcc-mingw-w64-x86-64 - libcmocka-dev + - libmagic-dev + - libevent-dev - rpm - valgrind diff --git a/Makefile.am b/Makefile.am index 934e1cc..7e42b6d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,7 @@ AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-ronn \ --disable-valgrind \ --enable-git-receiver \ + --enable-runserver \ $(NULL) @@ -60,6 +61,12 @@ bin_PROGRAMS += \ $(NULL) endif +if BUILD_RUNSERVER +bin_PROGRAMS += \ + blogc-runserver \ + $(NULL) +endif + check_PROGRAMS = \ $(NULL) @@ -126,6 +133,26 @@ blogc_git_receiver_LDADD = \ 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 += \ @@ -149,6 +176,14 @@ dist_man_MANS += \ $(NULL) endif +if BUILD_RUNSERVER +EXTRA_DIST += \ + $(NULL) + +dist_man_MANS += \ + $(NULL) +endif + MAINTAINERCLEANFILES += \ $(dist_man_MANS) \ $(NULL) diff --git a/build-aux/travis-build.sh b/build-aux/travis-build.sh index 4187575..e16e5c7 100755 --- a/build-aux/travis-build.sh +++ b/build-aux/travis-build.sh @@ -13,10 +13,10 @@ if [[ "x${TARGET}" = xw* ]]; then export CHOST="x86_64-w64-mingw32" [[ "x${TARGET}" = "xw32" ]] && export CHOST="i686-w64-mingw32" MAKE_TARGET="all" - CONFIGURE_ARGS="--disable-git-receiver" + CONFIGURE_ARGS="--disable-tests --disable-valgrind --disable-git-receiver --disable-runserver" else export CFLAGS="-Wall -g" - CONFIGURE_ARGS="--enable-tests --enable-valgrind" + CONFIGURE_ARGS="--enable-tests --enable-valgrind --enable-git-receiver --enable-runserver" fi pushd build > /dev/null diff --git a/configure.ac b/configure.ac index 858db59..b468d4b 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,34 @@ AS_IF([test "x$have_git_receiver" = "xyes"], , [ ]) AM_CONDITIONAL([BUILD_GIT_RECEIVER], [test "x$have_git_receiver" = "xyes"]) +RUNSERVER="disabled" +AC_ARG_ENABLE([runserver], AS_HELP_STRING([--disable-runserver], + [disable blogc-runserver build])) +AS_IF([test "x$enable_runserver" != "xno"], [ + AC_CHECK_LIB(magic, [magic_open], [ + MAGIC_LIBS="-lmagic" + PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0], [ + AC_CHECK_HEADERS([sys/types.h sys/stat.h signal.h stdarg.h fcntl.h unistd.h magic.h], [ + AC_SUBST(MAGIC_LIBS) + RUNSERVER="enabled" + have_runserver=yes + ], [ + have_runserver=no + ]) + ], [ + have_runserver=no + ]) + ], [ + have_runserver=no + ]) +]) +AS_IF([test "x$have_runserver" = "xyes"], , [ + AS_IF([test "x$enable_runserver" = "xyes"], [ + AC_MSG_ERROR([blogc-runserver requested but required dependencies not found]) + ]) +]) +AM_CONDITIONAL([BUILD_RUNSERVER], [test "x$have_runserver" = "xyes"]) + AC_CHECK_HEADERS([sys/types.h sys/stat.h time.h]) LT_LIB_M @@ -160,6 +188,7 @@ AS_ECHO(" ldflags: ${LDFLAGS} blogc-git-receiver: ${GIT_RECEIVER} + blogc-runserver: ${RUNSERVER} tests: ${TESTS} 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3-18-g5258 From 16f8e17db537472993de3435e74f05c3dc9fb801 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 20:16:26 +0200 Subject: build: keep tools disabled by default --- configure.ac | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index b468d4b..0e36070 100644 --- a/configure.ac +++ b/configure.ac @@ -120,48 +120,35 @@ 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([--disable-git-receiver], - [disable blogc-git-receiver build])) -AS_IF([test "x$enable_git_receiver" != "xno"], [ +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 ], [ - have_git_receiver=no - ]) -]) -AS_IF([test "x$have_git_receiver" = "xyes"], , [ - AS_IF([test "x$enable_git_receiver" = "xyes"], [ - AC_MSG_ERROR([blogc-git-receiver requested but required headers not found]) + 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([--disable-runserver], - [disable blogc-runserver build])) -AS_IF([test "x$enable_runserver" != "xno"], [ - AC_CHECK_LIB(magic, [magic_open], [ - MAGIC_LIBS="-lmagic" - PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0], [ - AC_CHECK_HEADERS([sys/types.h sys/stat.h signal.h stdarg.h fcntl.h unistd.h magic.h], [ - AC_SUBST(MAGIC_LIBS) - RUNSERVER="enabled" - have_runserver=yes - ], [ - have_runserver=no - ]) - ], [ - have_runserver=no - ]) - ], [ - have_runserver=no +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]) ]) -]) -AS_IF([test "x$have_runserver" = "xyes"], , [ - AS_IF([test "x$enable_runserver" = "xyes"], [ - AC_MSG_ERROR([blogc-runserver requested but required dependencies 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"]) -- cgit v1.2.3-18-g5258 From 8228eff55065858c73bea00e643b7f7f81e14ace Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 21:30:58 +0200 Subject: fixed readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cce4fc4..4450099 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A blog compiler. ## Quickstart -Clone the [Git repository](https://github.com/blogc/blogc) (using `--recursive` to get the submodules) or grab the [latest release](https://github.com/blogc/blogc/releases) and extract it. +Clone the [Git repository](https://github.com/blogc/blogc) or grab the [latest release](https://github.com/blogc/blogc/releases) and extract it. Inside the source directory, run the following commands: -- cgit v1.2.3-18-g5258 From 88c2393ec8bc9a6d19394e6c5d0bff77368f0704 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 27 Apr 2016 21:55:21 +0200 Subject: build: support tools in spec file --- blogc.spec.in | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/blogc.spec.in b/blogc.spec.in index cc39b12..85b41c1 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -6,16 +6,33 @@ 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 + +%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 @@ -23,12 +40,21 @@ rm -rf $RPM_BUILD_ROOT %make_install %files -%{_mandir}/man*/blogc* +%{_mandir}/man*/blogc.* +%{_mandir}/man*/blogc-source.* +%{_mandir}/man*/blogc-template.* %{_bindir}/blogc - %doc README.md %license LICENSE +%files git-receiver +%{_bindir}/blogc-git-receiver +%license LICENSE + +%files runserver +%{_bindir}/blogc-runserver +%license LICENSE + %changelog * Sun Apr 17 2016 Rafael G. Martins 0.8.1-1 - New release. -- cgit v1.2.3-18-g5258 From 4b62c5dbb57fabdf48f72e142442af6c6a3334b9 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 28 Apr 2016 03:08:34 +0200 Subject: build: drop windows support --- .travis.yml | 8 -------- build-aux/travis-build.sh | 38 ++++++-------------------------------- build-aux/travis-deploy.sh | 4 +--- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4bd479..15c4906 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ language: c addons: apt: packages: - - gcc-mingw-w64-i686 - - gcc-mingw-w64-x86-64 - libcmocka-dev - libmagic-dev - libevent-dev @@ -21,15 +19,9 @@ env: - TARGET=valgrind - TARGET=distcheck - TARGET=dist-srpm - - TARGET=w32 - - TARGET=w64 matrix: exclude: - - compiler: clang - env: TARGET=w32 - - compiler: clang - env: TARGET=w64 - compiler: clang env: TARGET=dist-srpm diff --git a/build-aux/travis-build.sh b/build-aux/travis-build.sh index e16e5c7..53cf589 100755 --- a/build-aux/travis-build.sh +++ b/build-aux/travis-build.sh @@ -5,43 +5,17 @@ set -ex rm -rf build mkdir -p build -MAKE_TARGET="${TARGET}" - -if [[ "x${TARGET}" = xw* ]]; then - unset CC - export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" - export CHOST="x86_64-w64-mingw32" - [[ "x${TARGET}" = "xw32" ]] && export CHOST="i686-w64-mingw32" - MAKE_TARGET="all" - CONFIGURE_ARGS="--disable-tests --disable-valgrind --disable-git-receiver --disable-runserver" -else - export CFLAGS="-Wall -g" - CONFIGURE_ARGS="--enable-tests --enable-valgrind --enable-git-receiver --enable-runserver" -fi - pushd build > /dev/null ../configure \ - ${CHOST:+--host=${CHOST} --target=${CHOST}} \ + CFLAGS="-Wall -g" \ --enable-ronn \ --disable-silent-rules \ - ${CONFIGURE_ARGS} + --enable-tests \ + --enable-valgrind \ + --enable-git-receiver \ + --enable-runserver popd > /dev/null -make -C build "${MAKE_TARGET}" - -if [[ "x${TARGET}" = xw* ]]; then - TARNAME="$(grep PACKAGE_TARNAME build/config.h | cut -d\" -f2)" - VERSION="$(grep PACKAGE_VERSION build/config.h | cut -d\" -f2)" - DEST_DIR="${TARNAME}-${VERSION}-${TARGET}" - - rm -rf "${DEST_DIR}" - mkdir -p "${DEST_DIR}" - - cp build/.libs/blogc.exe "${DEST_DIR}/" - cp LICENSE "${DEST_DIR}/" - cp README.md "${DEST_DIR}/" - - zip "build/${DEST_DIR}.zip" "${DEST_DIR}"/* -fi +make -C build "${TARGET}" diff --git a/build-aux/travis-deploy.sh b/build-aux/travis-deploy.sh index 0ef28bf..51aac3e 100755 --- a/build-aux/travis-deploy.sh +++ b/build-aux/travis-deploy.sh @@ -22,9 +22,7 @@ if [[ ! -d build ]]; then exit 1 fi -if [[ "x${TARGET}" = xw* ]]; then - FILES=( build/*.zip ) -elif [[ "x${TARGET}" = "xdist-srpm" ]]; then +if [[ "x${TARGET}" = "xdist-srpm" ]]; then FILES=( build/*.src.rpm ) else FILES=( build/*.{*.tar.{gz,bz2,xz},zip} ) -- cgit v1.2.3-18-g5258 From ca6fb024c9632b73713432e30fce978a99f42213 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 29 Apr 2016 00:57:10 +0200 Subject: man: added man page for blogc-git-receiver --- Makefile.am | 13 +++++ blogc.spec.in | 1 + man/blogc-git-receiver.1.ronn | 126 ++++++++++++++++++++++++++++++++++++++++++ man/index.txt | 16 ++++-- 4 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 man/blogc-git-receiver.1.ronn diff --git a/Makefile.am b/Makefile.am index 7e42b6d..78b29e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -170,9 +170,11 @@ dist_man_MANS = \ if BUILD_GIT_RECEIVER EXTRA_DIST += \ + man/blogc-git-receiver.1.ronn \ $(NULL) dist_man_MANS += \ + blogc-git-receiver.1 \ $(NULL) endif @@ -198,6 +200,14 @@ blogc.1: man/blogc.1.ronn --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-source.7: man/blogc-source.7.ronn $(AM_V_GEN)$(RONN) \ --roff \ @@ -219,6 +229,9 @@ 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-source.7: $(AM_V_GEN)echo "error: ronn not found. failed to build man page: $@"; exit 1 diff --git a/blogc.spec.in b/blogc.spec.in index 85b41c1..65af54f 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -48,6 +48,7 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %files git-receiver +%{_mandir}/man*/blogc-git-receiver.* %{_bindir}/blogc-git-receiver %license LICENSE diff --git a/man/blogc-git-receiver.1.ronn b/man/blogc-git-receiver.1.ronn new file mode 100644 index 0000000..4eadece --- /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`) + +## 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: + +## AUTHOR + +Rafael G. Martins <> + +## SEE ALSO + +blogc(1), git(7), chsh(1), su(1), make(1) diff --git a/man/index.txt b/man/index.txt index a85e2a0..7f78f2a 100644 --- a/man/index.txt +++ b/man/index.txt @@ -1,9 +1,13 @@ # 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-source(7) blogc-source.7.ronn +blogc-template(7) blogc-template.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) -- cgit v1.2.3-18-g5258 From d4003fcfc88df94831cb4a20e890816954f64129 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 29 Apr 2016 01:17:38 +0200 Subject: man: added man page for blogc-runserver --- Makefile.am | 13 ++++++++++++ blogc.spec.in | 1 + man/blogc-git-receiver.1.ronn | 2 +- man/blogc-runserver.1.ronn | 48 +++++++++++++++++++++++++++++++++++++++++++ man/index.txt | 1 + 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 man/blogc-runserver.1.ronn diff --git a/Makefile.am b/Makefile.am index 78b29e0..6b428cb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -180,9 +180,11 @@ endif if BUILD_RUNSERVER EXTRA_DIST += \ + man/blogc-runserver.1.ronn \ $(NULL) dist_man_MANS += \ + blogc-runserver.1 \ $(NULL) endif @@ -208,6 +210,14 @@ blogc-git-receiver.1: man/blogc-git-receiver.1.ronn --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) \ --roff \ @@ -232,6 +242,9 @@ blogc.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 diff --git a/blogc.spec.in b/blogc.spec.in index 65af54f..292ed17 100644 --- a/blogc.spec.in +++ b/blogc.spec.in @@ -53,6 +53,7 @@ rm -rf $RPM_BUILD_ROOT %license LICENSE %files runserver +%{_mandir}/man*/blogc-runserver.* %{_bindir}/blogc-runserver %license LICENSE diff --git a/man/blogc-git-receiver.1.ronn b/man/blogc-git-receiver.1.ronn index 4eadece..e26ed09 100644 --- a/man/blogc-git-receiver.1.ronn +++ b/man/blogc-git-receiver.1.ronn @@ -1,4 +1,4 @@ -blogc-git-receiver(1) -- A simple login shell/git hook to deploy blogc websites +blogc-git-receiver(1) -- a simple login shell/git hook to deploy blogc websites =============================================================================== ## SYNOPSIS 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` ] [`-p` ]
    +`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` : + HTTP server listen address, defaults to `127.0.0.1`. + + * `-p` : + HTTP server listen port, defaults to `8080`. + + * `-v`: + Show program name, version and exit. + + * `-h`: + Show help message and exit. + +## ARGUMENTS + + * : + HTTP server document root. + +## BUGS + +Please report any issues to: + +## AUTHOR + +Rafael G. Martins <> + +## SEE ALSO + +blogc(1) diff --git a/man/index.txt b/man/index.txt index 7f78f2a..40a80d6 100644 --- a/man/index.txt +++ b/man/index.txt @@ -1,6 +1,7 @@ # manuals 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 -- cgit v1.2.3-18-g5258 From 81c441e147390cb4b707ae9f1dca42481d6bacb2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 29 Apr 2016 01:50:25 +0200 Subject: build: fix man page dist --- Makefile.am | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6b428cb..e18be01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I m4 AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-tests \ - --enable-ronn \ + --disable-ronn \ --disable-valgrind \ --enable-git-receiver \ --enable-runserver \ @@ -157,9 +157,13 @@ endif 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/index.txt \ + blogc-git-receiver.1 \ + blogc-runserver.1 \ $(NULL) dist_man_MANS = \ @@ -169,20 +173,12 @@ dist_man_MANS = \ $(NULL) if BUILD_GIT_RECEIVER -EXTRA_DIST += \ - man/blogc-git-receiver.1.ronn \ - $(NULL) - dist_man_MANS += \ blogc-git-receiver.1 \ $(NULL) endif if BUILD_RUNSERVER -EXTRA_DIST += \ - man/blogc-runserver.1.ronn \ - $(NULL) - dist_man_MANS += \ blogc-runserver.1 \ $(NULL) -- cgit v1.2.3-18-g5258 From 8f1f1388f163ab396a5e8a8f9c8f2a49346bc0fd Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 29 Apr 2016 02:06:26 +0200 Subject: updated readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4450099..bd27cae 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3-18-g5258 From 82035fc222e8f7cb63c9573d5e9c7b5fea9d1943 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 29 Apr 2016 04:43:48 +0200 Subject: updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd27cae..d5b968e 100644 --- a/README.md +++ b/README.md @@ -26,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). -- cgit v1.2.3-18-g5258 From 114b36f95116f62bfcf9d79e441ab81aed35454b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 30 Apr 2016 02:41:00 +0200 Subject: man: added blogc-pagination(7) --- Makefile.am | 13 +++++ man/blogc-pagination.7.ronn | 122 ++++++++++++++++++++++++++++++++++++++++++++ man/blogc-source.7.ronn | 4 ++ man/blogc.1.ronn | 4 +- man/index.txt | 1 + 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 man/blogc-pagination.7.ronn diff --git a/Makefile.am b/Makefile.am index e18be01..d3ab12c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -161,6 +161,7 @@ EXTRA_DIST += \ 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 \ @@ -170,6 +171,7 @@ dist_man_MANS = \ blogc.1 \ blogc-source.7 \ blogc-template.7 \ + blogc-pagination.7 \ $(NULL) if BUILD_GIT_RECEIVER @@ -230,6 +232,14 @@ blogc-template.7: man/blogc-template.7.ronn --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: @@ -247,6 +257,9 @@ blogc-source.7: 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 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 %} +
      + {% ifdef PREVIOUS_PAGE %} + + {% endif %} + {% ifdef NEXT_PAGE %} + + {% endif %} +
    + {% 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: + +## AUTHOR + +Rafael G. Martins <> + +## SEE ALSO + +blogc(1), blogc-source(7), blogc-template(7) diff --git a/man/blogc-source.7.ronn b/man/blogc-source.7.ronn index c49f3ce..1a2cc76 100644 --- a/man/blogc-source.7.ronn +++ b/man/blogc-source.7.ronn @@ -45,6 +45,10 @@ 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. + ## SOURCE CONTENT - BLOCK ELEMENTS ### Paragraphs 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` : 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`