diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-09 03:33:14 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-09 03:33:14 +0200 |
commit | 1c8174674d522a2c55b4f143f7e0dac848e34281 (patch) | |
tree | 5cb1d9c51036fb7993bb1bd43ad99089fed77721 /src | |
parent | 9dd0fcbeaed19c362ed2d1071d2ea967572b67f4 (diff) | |
download | blogc-1c8174674d522a2c55b4f143f7e0dac848e34281.tar.gz blogc-1c8174674d522a2c55b4f143f7e0dac848e34281.tar.bz2 blogc-1c8174674d522a2c55b4f143f7e0dac848e34281.zip |
blogc: common: moved "file" to common
Diffstat (limited to 'src')
-rw-r--r-- | src/blogc/loader.c | 6 | ||||
-rw-r--r-- | src/common/error.c | 6 | ||||
-rw-r--r-- | src/common/error.h | 2 | ||||
-rw-r--r-- | src/common/file.c (renamed from src/blogc/file.c) | 19 | ||||
-rw-r--r-- | src/common/file.h (renamed from src/blogc/file.h) | 6 |
5 files changed, 18 insertions, 21 deletions
diff --git a/src/blogc/loader.c b/src/blogc/loader.c index 754723b..b182e0b 100644 --- a/src/blogc/loader.c +++ b/src/blogc/loader.c @@ -12,11 +12,11 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "file.h" #include "source-parser.h" #include "template-parser.h" #include "loader.h" #include "../common/error.h" +#include "../common/file.h" #include "../common/utils.h" @@ -63,7 +63,7 @@ blogc_template_parse_from_file(const char *f, bc_error_t **err) if (err == NULL || *err != NULL) return NULL; size_t len; - char *s = blogc_file_get_contents(f, &len, err); + char *s = bc_file_get_contents(f, &len, err); if (s == NULL) return NULL; bc_slist_t *rv = blogc_template_parse(s, len, err); @@ -78,7 +78,7 @@ blogc_source_parse_from_file(const char *f, bc_error_t **err) if (err == NULL || *err != NULL) return NULL; size_t len; - char *s = blogc_file_get_contents(f, &len, err); + char *s = bc_file_get_contents(f, &len, err); if (s == NULL) return NULL; bc_trie_t *rv = blogc_source_parse(s, len, err); diff --git a/src/common/error.c b/src/common/error.c index 1ea6e0d..a6a5f24 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -112,6 +112,9 @@ bc_error_print(bc_error_t *err) case BC_ERROR_CONFIG_PARSER: fprintf(stderr, "error: config-parser: %s\n", err->msg); break; + case BC_ERROR_FILE: + fprintf(stderr, "error: file: %s\n", err->msg); + break; case BLOGC_ERROR_SOURCE_PARSER: fprintf(stderr, "error: source: %s\n", err->msg); break; @@ -121,9 +124,6 @@ bc_error_print(bc_error_t *err) case BLOGC_ERROR_LOADER: fprintf(stderr, "error: loader: %s\n", err->msg); break; - case BLOGC_ERROR_FILE: - fprintf(stderr, "error: file: %s\n", err->msg); - break; case BLOGC_WARNING_DATETIME_PARSER: fprintf(stderr, "warning: datetime: %s\n", err->msg); break; diff --git a/src/common/error.h b/src/common/error.h index 2569538..d65a3e7 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -16,12 +16,12 @@ typedef enum { // errors for src/common BC_ERROR_CONFIG_PARSER = 1, + BC_ERROR_FILE, // 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; diff --git a/src/blogc/file.c b/src/common/file.c index 518c665..70a5631 100644 --- a/src/blogc/file.c +++ b/src/common/file.c @@ -13,16 +13,13 @@ #include <stdio.h> #include <string.h> #include "file.h" -#include "../common/error.h" -#include "../common/utf8.h" -#include "../common/utils.h" - -// this would belong to loader.c, but we need it in a separated file to be -// able to mock it when unit testing the loader functions. +#include "error.h" +#include "utf8.h" +#include "utils.h" char* -blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err) +bc_file_get_contents(const char *path, size_t *len, bc_error_t **err) { if (path == NULL || err == NULL || *err != NULL) return NULL; @@ -32,17 +29,17 @@ blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err) if (fp == NULL) { int tmp_errno = errno; - *err = bc_error_new_printf(BLOGC_ERROR_FILE, + *err = bc_error_new_printf(BC_ERROR_FILE, "Failed to open file (%s): %s", path, strerror(tmp_errno)); return NULL; } bc_string_t *str = bc_string_new(); - char buffer[BLOGC_FILE_CHUNK_SIZE]; + char buffer[BC_FILE_CHUNK_SIZE]; char *tmp; while (!feof(fp)) { - size_t read_len = fread(buffer, sizeof(char), BLOGC_FILE_CHUNK_SIZE, fp); + size_t read_len = fread(buffer, sizeof(char), BC_FILE_CHUNK_SIZE, fp); tmp = buffer; @@ -60,7 +57,7 @@ blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err) fclose(fp); if (!bc_utf8_validate_str(str)) { - *err = bc_error_new_printf(BLOGC_ERROR_FILE, + *err = bc_error_new_printf(BC_ERROR_FILE, "File content is not valid UTF-8: %s", path); bc_string_free(str, true); return NULL; diff --git a/src/blogc/file.h b/src/common/file.h index 6a0e094..e095de7 100644 --- a/src/blogc/file.h +++ b/src/common/file.h @@ -10,10 +10,10 @@ #define _FILE_H #include <stddef.h> -#include "../common/error.h" +#include "error.h" -#define BLOGC_FILE_CHUNK_SIZE 1024 +#define BC_FILE_CHUNK_SIZE 1024 -char* blogc_file_get_contents(const char *path, size_t *len, bc_error_t **err); +char* bc_file_get_contents(const char *path, size_t *len, bc_error_t **err); #endif /* _FILE_H */ |