aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.c2
-rw-r--r--src/source-parser.c40
2 files changed, 37 insertions, 5 deletions
diff --git a/src/error.c b/src/error.c
index 8e19e6e..3850304 100644
--- a/src/error.c
+++ b/src/error.c
@@ -69,7 +69,7 @@ blogc_error_parser(blogc_error_type_t type, const char *src, size_t src_len,
rv = blogc_error_new(type, msg);
else
rv = blogc_error_new_printf(type,
- "%s\nError occurred near to \"%s\".", msg, line);
+ "%s\nError occurred near to '%s'", msg, line);
free(msg);
free(line);
diff --git a/src/source-parser.c b/src/source-parser.c
index 322906f..60b5fe5 100644
--- a/src/source-parser.c
+++ b/src/source-parser.c
@@ -117,7 +117,7 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
}
*err = blogc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
current,
- "Invalid content separator. Must be one or more '-' characters.");
+ "Invalid content separator. Must be more than one '-' characters.");
break;
case SOURCE_CONTENT_START:
@@ -125,9 +125,9 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
state = SOURCE_CONTENT;
break;
- case SOURCE_CONTENT:
- if (current == (src_len - 1))
- b_trie_insert(rv, "CONTENT",
+ case SOURCE_CONTENT:
+ if (current == (src_len - 1))
+ b_trie_insert(rv, "CONTENT",
b_strndup(src + start, src_len - start));
break;
}
@@ -138,6 +138,38 @@ blogc_source_parse(const char *src, size_t src_len, blogc_error_t **err)
current++;
}
+ if (*err == NULL && b_trie_size(rv) == 0) {
+
+ // ok, nothing found in the config trie, but no error set either.
+ // let's try to be nice with the users and provide some reasonable
+ // output. :)
+ switch (state) {
+ case SOURCE_START:
+ *err = blogc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
+ current, "Your config file is empty.");
+ break;
+ case SOURCE_CONFIG_KEY:
+ *err = blogc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
+ current, "Your last configuration key is missing ':' and "
+ "the value");
+ break;
+ case SOURCE_CONFIG_VALUE_START:
+ *err = blogc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
+ current, "Configuration value not provided for '%s'.",
+ key);
+ break;
+ case SOURCE_CONFIG_VALUE:
+ *err = blogc_error_parser(BLOGC_ERROR_SOURCE_PARSER, src, src_len,
+ current, "No line ending after the configuration value for "
+ "'%s'.", key);
+ break;
+ case SOURCE_SEPARATOR:
+ case SOURCE_CONTENT_START:
+ case SOURCE_CONTENT:
+ break; // won't happen, and if even happen, shouldn't be fatal
+ }
+ }
+
if (*err != NULL) {
free(key);
b_trie_free(rv);