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 --- src/source-parser.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/source-parser.c') 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; } -- 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 --- src/source-parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/source-parser.c') 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; -- 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/source-parser.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/source-parser.c') 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)); -- 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/source-parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/source-parser.c') 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; -- 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 --- src/source-parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/source-parser.c') 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 { -- cgit v1.2.3-18-g5258