From ae9d65b8a3f4a35bc01c8225f226e6420dfebe48 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 30 Nov 2014 09:33:52 +0100 Subject: mds-kbdc: add support for empty files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/make-tree.c | 8 ++++++++ src/mds-kbdc/mds-kbdc.c | 5 +++-- src/mds-kbdc/raw-data.c | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/mds-kbdc') diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index cdfae40..fab402b 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -1027,6 +1027,14 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_parsed_t* restrict res } } + /* Warn about empty files. */ + if (result->tree == NULL) + { + char* line = NULL; + char* end = NULL; + NEW_ERROR(0, WARNING, "file is empty"); + } + free(keyword_stack); free(tree_stack); return 0; diff --git a/src/mds-kbdc/mds-kbdc.c b/src/mds-kbdc/mds-kbdc.c index a2b5b70..318fc3c 100644 --- a/src/mds-kbdc/mds-kbdc.c +++ b/src/mds-kbdc/mds-kbdc.c @@ -20,6 +20,7 @@ #include "globals.h" #include "make-tree.h" #include "simplify-tree.h" +#include "process-includes.h" #include @@ -52,8 +53,8 @@ int main(int argc_, char** argv_) mds_kbdc_parsed_initialise(&result); process (parse_to_tree(argv[1], &result)); - //process (simplify_tree(&result)); - //process (process_includes(&result)); + process (simplify_tree(&result)); + process (process_includes(&result)); /* TODO process (validate_tree(&result)); */ /* TODO process (eliminate_dead_code(&result)); */ /* TODO process (compile_layout(&result)); */ diff --git a/src/mds-kbdc/raw-data.c b/src/mds-kbdc/raw-data.c index a1f8ec3..b0985fe 100644 --- a/src/mds-kbdc/raw-data.c +++ b/src/mds-kbdc/raw-data.c @@ -115,7 +115,8 @@ static char* read_file(const char* restrict pathname, size_t* restrict size) } /* Shrink the buffer so it is not excessively large. */ - fail_if (xxrealloc(old, content, buf_ptr, char)); + if (buf_ptr) /* Simplest way to handle empty files: let the have the initial allocation size. */ + fail_if (xxrealloc(old, content, buf_ptr, char)); /* Close file decriptor for the file. */ close(fd); -- cgit v1.2.3-70-g09d2