From 587829f398c9215731f32a6849110a799b91dab1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 30 Nov 2014 10:52:38 +0100 Subject: mds-kbdc: transfer of errors after inclusion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/process-includes.c | 61 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'src/mds-kbdc') diff --git a/src/mds-kbdc/process-includes.c b/src/mds-kbdc/process-includes.c index 1e9c5ff..9677671 100644 --- a/src/mds-kbdc/process-includes.c +++ b/src/mds-kbdc/process-includes.c @@ -58,6 +58,65 @@ static mds_kbdc_parsed_t* restrict result; +/** + * Transfer errors from an included tree + * + * @param subresult The results of the processed include + * @param tree The include statement + */ +static int transfer_errors(mds_kbdc_parsed_t* restrict subresult, mds_kbdc_tree_include_t* restrict tree) +{ + mds_kbdc_parse_error_t** errors = NULL; + mds_kbdc_parse_error_t* suberror; + size_t errors_ptr = 0, i; + int saved_errno; + + /* List errors backwards, so that we can easily insert “included from here”-notes. */ + fail_if (xmalloc(errors, subresult->errors_ptr * 2, mds_kbdc_parse_error_t*)); + while (subresult->errors_ptr--) + { + suberror = subresult->errors[subresult->errors_ptr]; + if (suberror->severity > MDS_KBDC_PARSE_ERROR_NOTE) + { + NEW_ERROR(tree, NOTE, "included from here"); + errors[errors_ptr++] = error; + result->errors[--(result->errors_ptr)] = NULL; + } + errors[errors_ptr++] = suberror; + subresult->errors[subresult->errors_ptr] = NULL; + } + + /* Append errors. */ + for (i = 0; i < errors_ptr; errors[i++] = NULL) + { + if (result->errors_ptr + 1 >= result->errors_size) + { + size_t new_errors_size = result->errors_size ? (result->errors_size << 1) : 2; + mds_kbdc_parse_error_t** new_errors = result->errors; + + fail_if (xrealloc(new_errors, new_errors_size, mds_kbdc_parse_error_t*)); + result->errors = new_errors; + result->errors_size = new_errors_size; + } + + result->errors[result->errors_ptr++] = errors[i]; + result->errors[result->errors_ptr] = NULL; + } + + free(errors); + return 0; + pfail: + saved_errno = errno; + while (errors_ptr--) + if (errors[errors_ptr] == NULL) + break; + else + mds_kbdc_parse_error_free(errors[errors_ptr]); + free(errors); + return errno = saved_errno, -1; +} + + /** * Process an include-statement * @@ -126,7 +185,7 @@ static int process_include(mds_kbdc_tree_include_t* restrict tree) result->severest_error_level = subresult.severest_error_level; /* Move over errors. */ - /* TODO */ + fail_if (transfer_errors(&subresult, tree)); /* Release resources. */ mds_kbdc_parsed_destroy(&subresult); -- cgit v1.2.3-70-g09d2