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/error.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/error.c') 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; -- 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/error.c | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) (limited to 'src/error.c') 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); -} -- 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/error.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'src/error.c') 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); +} -- 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/error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/error.c') 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* -- cgit v1.2.3-18-g5258