aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc/datetime-parser.c1
-rw-r--r--src/blogc/datetime-parser.h1
-rw-r--r--src/blogc/errors.c40
-rw-r--r--src/blogc/errors.h24
-rw-r--r--src/blogc/file.c1
-rw-r--r--src/blogc/file.h1
-rw-r--r--src/blogc/loader.c1
-rw-r--r--src/blogc/loader.h1
-rw-r--r--src/blogc/main.c5
-rw-r--r--src/blogc/renderer.c3
-rw-r--r--src/blogc/source-parser.c1
-rw-r--r--src/blogc/source-parser.h1
-rw-r--r--src/blogc/template-parser.c1
-rw-r--r--src/blogc/template-parser.h1
-rw-r--r--src/common/error.c29
-rw-r--r--src/common/error.h13
16 files changed, 44 insertions, 80 deletions
diff --git a/src/blogc/datetime-parser.c b/src/blogc/datetime-parser.c
index 2fd3b4f..d7481e5 100644
--- a/src/blogc/datetime-parser.c
+++ b/src/blogc/datetime-parser.c
@@ -17,7 +17,6 @@
#include <string.h>
#include "datetime-parser.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/datetime-parser.h b/src/blogc/datetime-parser.h
index 08ad3c9..fc06b62 100644
--- a/src/blogc/datetime-parser.h
+++ b/src/blogc/datetime-parser.h
@@ -9,7 +9,6 @@
#ifndef _DATETIME_H
#define _DATETIME_H
-#include "errors.h"
#include "../common/error.h"
char* blogc_convert_datetime(const char *orig, const char *format,
diff --git a/src/blogc/errors.c b/src/blogc/errors.c
deleted file mode 100644
index 6447a4a..0000000
--- a/src/blogc/errors.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "errors.h"
-#include "../common/error.h"
-
-
-void
-blogc_error_print(bc_error_t *err)
-{
- if (err == NULL)
- return;
-
- switch((blogc_error_type_t) err->type) {
- case BLOGC_ERROR_SOURCE_PARSER:
- fprintf(stderr, "blogc: error: source: %s\n", err->msg);
- break;
- case BLOGC_ERROR_TEMPLATE_PARSER:
- fprintf(stderr, "blogc: error: template: %s\n", err->msg);
- break;
- case BLOGC_ERROR_LOADER:
- fprintf(stderr, "blogc: error: loader: %s\n", err->msg);
- break;
- case BLOGC_ERROR_FILE:
- fprintf(stderr, "blogc: error: file: %s\n", err->msg);
- break;
- case BLOGC_WARNING_DATETIME_PARSER:
- fprintf(stderr, "blogc: warning: datetime: %s\n", err->msg);
- break;
- default:
- fprintf(stderr, "blogc: error: %s\n", err->msg);
- }
-}
diff --git a/src/blogc/errors.h b/src/blogc/errors.h
deleted file mode 100644
index 427d9e7..0000000
--- a/src/blogc/errors.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * blogc: A blog compiler.
- * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
- *
- * This program can be distributed under the terms of the BSD License.
- * See the file LICENSE.
- */
-
-#ifndef _ERRORS_H
-#define _ERRORS_H
-
-#include "../common/error.h"
-
-typedef enum {
- BLOGC_ERROR_SOURCE_PARSER = 1,
- BLOGC_ERROR_TEMPLATE_PARSER,
- BLOGC_ERROR_LOADER,
- BLOGC_ERROR_FILE,
- BLOGC_WARNING_DATETIME_PARSER,
-} blogc_error_type_t;
-
-void blogc_error_print(bc_error_t *err);
-
-#endif /* _ERRORS_H */
diff --git a/src/blogc/file.c b/src/blogc/file.c
index 94148fe..cede962 100644
--- a/src/blogc/file.c
+++ b/src/blogc/file.c
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <string.h>
#include "file.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utf8.h"
#include "../common/utils.h"
diff --git a/src/blogc/file.h b/src/blogc/file.h
index c509874..8213573 100644
--- a/src/blogc/file.h
+++ b/src/blogc/file.h
@@ -11,7 +11,6 @@
#include <stddef.h>
#include <stdio.h>
-#include "errors.h"
#include "../common/error.h"
#define BLOGC_FILE_CHUNK_SIZE 1024
diff --git a/src/blogc/loader.c b/src/blogc/loader.c
index 93d9eef..e8de75d 100644
--- a/src/blogc/loader.c
+++ b/src/blogc/loader.c
@@ -16,7 +16,6 @@
#include "source-parser.h"
#include "template-parser.h"
#include "loader.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/loader.h b/src/blogc/loader.h
index c8a7230..2d3ef89 100644
--- a/src/blogc/loader.h
+++ b/src/blogc/loader.h
@@ -9,7 +9,6 @@
#ifndef _LOADER_H
#define _LOADER_H
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/main.c b/src/blogc/main.c
index 8563c68..beb67d6 100644
--- a/src/blogc/main.c
+++ b/src/blogc/main.c
@@ -26,7 +26,6 @@
#include "template-parser.h"
#include "loader.h"
#include "renderer.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utf8.h"
#include "../common/utils.h"
@@ -224,7 +223,7 @@ main(int argc, char **argv)
bc_slist_t *s = blogc_source_parse_from_files(config, sources, &err);
if (err != NULL) {
- blogc_error_print(err);
+ bc_error_print(err);
rv = 2;
goto cleanup2;
}
@@ -251,7 +250,7 @@ main(int argc, char **argv)
bc_slist_t* l = blogc_template_parse_from_file(template, &err);
if (err != NULL) {
- blogc_error_print(err);
+ bc_error_print(err);
rv = 2;
goto cleanup3;
}
diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c
index 7c29818..e0f1da6 100644
--- a/src/blogc/renderer.c
+++ b/src/blogc/renderer.c
@@ -13,7 +13,6 @@
#include <stdlib.h>
#include <string.h>
#include "datetime-parser.h"
-#include "errors.h"
#include "template-parser.h"
#include "renderer.h"
#include "../common/error.h"
@@ -47,7 +46,7 @@ blogc_format_date(const char *date, bc_trie_t *global, bc_trie_t *local)
bc_error_t *err = NULL;
char *rv = blogc_convert_datetime(date, date_format, &err);
if (err != NULL) {
- blogc_error_print(err);
+ bc_error_print(err);
bc_error_free(err);
return bc_strdup(date);
}
diff --git a/src/blogc/source-parser.c b/src/blogc/source-parser.c
index 7cb929e..a3d1e09 100644
--- a/src/blogc/source-parser.c
+++ b/src/blogc/source-parser.c
@@ -11,7 +11,6 @@
#include "content-parser.h"
#include "source-parser.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/source-parser.h b/src/blogc/source-parser.h
index d920775..4ecbe28 100644
--- a/src/blogc/source-parser.h
+++ b/src/blogc/source-parser.h
@@ -10,7 +10,6 @@
#define _SOURCE_PARSER_H
#include <stddef.h>
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c
index acf8f7c..7994a9b 100644
--- a/src/blogc/template-parser.c
+++ b/src/blogc/template-parser.c
@@ -11,7 +11,6 @@
#include <string.h>
#include "template-parser.h"
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/blogc/template-parser.h b/src/blogc/template-parser.h
index 3ed3b07..e17a9a9 100644
--- a/src/blogc/template-parser.h
+++ b/src/blogc/template-parser.h
@@ -10,7 +10,6 @@
#define _TEMPLATE_PARSER_H
#include <stddef.h>
-#include "errors.h"
#include "../common/error.h"
#include "../common/utils.h"
diff --git a/src/common/error.c b/src/common/error.c
index dbc1d81..78cdc86 100644
--- a/src/common/error.c
+++ b/src/common/error.c
@@ -101,6 +101,35 @@ bc_error_parser(int type, const char *src, size_t src_len,
}
+// error handling is centralized here for the sake of simplicity :/
+void
+bc_error_print(bc_error_t *err)
+{
+ if (err == NULL)
+ return;
+
+ switch(err->type) {
+ case BLOGC_ERROR_SOURCE_PARSER:
+ fprintf(stderr, "blogc: error: source: %s\n", err->msg);
+ break;
+ case BLOGC_ERROR_TEMPLATE_PARSER:
+ fprintf(stderr, "blogc: error: template: %s\n", err->msg);
+ break;
+ case BLOGC_ERROR_LOADER:
+ fprintf(stderr, "blogc: error: loader: %s\n", err->msg);
+ break;
+ case BLOGC_ERROR_FILE:
+ fprintf(stderr, "blogc: error: file: %s\n", err->msg);
+ break;
+ case BLOGC_WARNING_DATETIME_PARSER:
+ fprintf(stderr, "blogc: warning: datetime: %s\n", err->msg);
+ break;
+ default:
+ fprintf(stderr, "blogc: error: %s\n", err->msg);
+ }
+}
+
+
void
bc_error_free(bc_error_t *err)
{
diff --git a/src/common/error.h b/src/common/error.h
index 17843ed..f2845df 100644
--- a/src/common/error.h
+++ b/src/common/error.h
@@ -11,9 +11,20 @@
#include <stddef.h>
+// error handling is centralized here for the sake of simplicity :/
+typedef enum {
+
+ // errors for src/blogc
+ BLOGC_ERROR_SOURCE_PARSER = 100,
+ BLOGC_ERROR_TEMPLATE_PARSER,
+ BLOGC_ERROR_LOADER,
+ BLOGC_ERROR_FILE,
+ BLOGC_WARNING_DATETIME_PARSER,
+} bc_error_type_t;
+
typedef struct {
char *msg;
- int type;
+ bc_error_type_t type;
} bc_error_t;
bc_error_t* bc_error_new(int type, const char *msg);