aboutsummaryrefslogtreecommitdiffstats
path: root/src/error.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-04-27 01:31:02 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-04-27 01:31:02 +0200
commit6153580a13e7e7c48e38fa446572c8adcae08084 (patch)
tree9be08616aed124c67159bf71fccd3a286bc0fe81 /src/error.c
parentc5e4f4c2d29831151bdce1802787b9cf012c3e5e (diff)
downloadblogc-6153580a13e7e7c48e38fa446572c8adcae08084.tar.gz
blogc-6153580a13e7e7c48e38fa446572c8adcae08084.tar.bz2
blogc-6153580a13e7e7c48e38fa446572c8adcae08084.zip
Revert "*: use squareball error infrastructure"
This reverts commit a2b3551dfb9460470bd79f5648bf597c517c40d4.
Diffstat (limited to 'src/error.c')
-rw-r--r--src/error.c47
1 files changed, 40 insertions, 7 deletions
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);
+}