From 589ff8ad9525124bf2570a8c151bf2b831659ff4 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Fri, 26 Nov 2010 00:12:57 -0500 Subject: Refactoring error reporting Minor cleanup in the error reporting. --- ini/ini_config.h | 8 -------- ini/ini_config_priv.h | 3 +++ ini/ini_configobj.h | 8 -------- ini/ini_defines.h | 6 ++++++ ini/ini_fileobj.c | 3 ++- ini/ini_print.c | 46 +++++++++++++++++++++++++++++++++++----------- 6 files changed, 46 insertions(+), 28 deletions(-) (limited to 'ini') diff --git a/ini/ini_config.h b/ini/ini_config.h index c69e235..3b75012 100644 --- a/ini/ini_config.h +++ b/ini/ini_config.h @@ -498,14 +498,6 @@ struct parse_error { * @{ */ -/** @brief Function to return a parsing error as a string. - * - * @param[in] parsing_error Error code for the parsing error. - * - * @return Error string. - */ -const char *parsing_error_str(int parsing_error); - /** * @brief Read configuration information from a file. diff --git a/ini/ini_config_priv.h b/ini/ini_config_priv.h index 9185e14..1880c3f 100644 --- a/ini/ini_config_priv.h +++ b/ini/ini_config_priv.h @@ -78,4 +78,7 @@ void ini_cleanup_cb(const char *property, int length, void *custom_data); +/* Get parsing error */ +const char *ini_get_error_str(int parsing_error, int family); + #endif diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h index 8ecb148..81578c0 100644 --- a/ini/ini_configobj.h +++ b/ini/ini_configobj.h @@ -142,14 +142,6 @@ int ini_config_parse(struct ini_cfgfile *file_ctx, void ini_print_errors(FILE *file, char **error_list); -/* TBD rename the function */ -/** @brief Function to return a parsing error as a string. - * - * @param[in] parsing_error Error code for the parsing error. - * - * @return Error string. - */ -const char *parsing_error_str(int parsing_error); /* Merge two configurations together creating a new one */ diff --git a/ini/ini_defines.h b/ini/ini_defines.h index bead998..1d03835 100644 --- a/ini/ini_defines.h +++ b/ini/ini_defines.h @@ -95,6 +95,12 @@ */ #define COL_CLASS_INI_META COL_CLASS_INI_BASE + 4 +/* Family of errors */ +#define INI_FAMILY_PARSING 0 +#define INI_FAMILY_VALIDATION 1 +#define INI_FAMILY_GRAMMAR 2 + + /* Different error string functions can be passed as callbacks */ typedef const char * (*error_fn)(int error); diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c index 117608c..29d5f90 100644 --- a/ini/ini_fileobj.c +++ b/ini/ini_fileobj.c @@ -241,7 +241,8 @@ int ini_config_get_errors(struct ini_cfgfile *file_ctx, col_get_item_property(item, NULL), pe->error, pe->line, - parsing_error_str(pe->error)); + ini_get_error_str(pe->error, + INI_FAMILY_PARSING)); errlist[count] = line; count++; diff --git a/ini/ini_print.c b/ini/ini_print.c index f12b27e..0430976 100644 --- a/ini/ini_print.c +++ b/ini/ini_print.c @@ -66,7 +66,7 @@ /* Function to return parsing error */ -const char *parsing_error_str(int parsing_error) +static const char *parsing_error_str(int parsing_error) { const char *placeholder= _("Unknown pasing error."); const char *str_error[] = { _("Data is too long."), @@ -109,7 +109,7 @@ const char *parsing_error_str(int parsing_error) * @return Error string. */ -const char *grammar_error_str(int grammar_error) +static const char *grammar_error_str(int grammar_error) { const char *placeholder= _("Unknown grammar error."); /* THIS IS A TEMPORARY PLACEHOLDER !!!! */ @@ -150,7 +150,7 @@ const char *grammar_error_str(int grammar_error) * * @return Error string. */ -const char *validation_error_str(int validation_error) +static const char *validation_error_str(int validation_error) { const char *placeholder= _("Unknown validation error."); /* THIS IS A TEMPORARY PLACEHOLDER !!!! */ @@ -170,7 +170,30 @@ const char *validation_error_str(int validation_error) return str_error[validation_error-1]; } +/* Wrapper to print errors */ +const char *ini_get_error_str(int error, int family) +{ + const char *val; + TRACE_FLOW_ENTRY(); + + switch(family) { + case INI_FAMILY_PARSING: + val = parsing_error_str(error); + break; + case INI_FAMILY_VALIDATION: + val = validation_error_str(error); + break; + case INI_FAMILY_GRAMMAR: + val = grammar_error_str(error); + break; + default: + val = _("Unknown error category."); + break; + } + TRACE_FLOW_EXIT(); + return val; +} /* Internal function that prints errors */ static void print_error_list(FILE *file, @@ -180,7 +203,7 @@ static void print_error_list(FILE *file, char *failed_to_process, char *error_header, char *line_format, - error_fn error_function) + int family) { struct collection_iterator *iterator; int error; @@ -235,10 +258,11 @@ static void print_error_list(FILE *file, /* Put error into provided format */ pe = (struct parse_error *)(col_get_item_data(item)); fprintf(file, line_format, - col_get_item_property(item, NULL), /* Error or warning */ - pe->error, /* Error */ - pe->line, /* Line */ - error_function(pe->error)); /* Error str */ + col_get_item_property(item, NULL), /* Error or warning */ + pe->error, /* Error */ + pe->line, /* Line */ + ini_get_error_str(pe->error, + family)); /* Error str */ } } @@ -260,7 +284,7 @@ void print_file_parsing_errors(FILE *file, FAILED_TO_PROCCESS, ERROR_HEADER, LINE_FORMAT, - parsing_error_str); + INI_FAMILY_PARSING); } @@ -290,7 +314,7 @@ void print_grammar_errors(FILE *file, FAILED_TO_PROC_G, ERROR_HEADER_G, LINE_FORMAT, - grammar_error_str); + INI_FAMILY_GRAMMAR); } /* Print errors and warnings that were detected while validating INI file. @@ -319,7 +343,7 @@ void print_validation_errors(FILE *file, FAILED_TO_PROC_V, ERROR_HEADER_V, LINE_FORMAT, - validation_error_str); + INI_FAMILY_VALIDATION); } /* Print errors and warnings that were detected while parsing -- cgit