diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2008-02-26 16:44:29 +1100 |
---|---|---|
committer | Jon Loeliger <jdl@loeliger.com> | 2008-03-23 08:00:32 -0500 |
commit | 7c635dcb2f43529bbe7903f5a6ce56984d21b964 (patch) | |
tree | 7b1e362ad8bf0060e9e1faceb58b374d969030b7 /dtc-lexer.l | |
parent | 2512a7eb5c755aeb92222748aa6a441c6840325c (diff) | |
download | device-tree-compiler-7c635dcb2f43529bbe7903f5a6ce56984d21b964.tar.gz |
dtc: Fix error reporting in push_input_file()
Error reporting in push_input_file() is a mess. One error results in
a message and exit(1), others result in a message and return 0 - which
is turned into an exit(1) at one callsite. The other callsite doesn't
check errors, but probably should. One of the error conditions gives
a message, but can only be the result of an internal programming
error, not a user error.
So. Clean that up by making push_input_file() a void function, using
die() to report errors and quit.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r-- | dtc-lexer.l | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l index 920b87f..0cd3f69 100644 --- a/dtc-lexer.l +++ b/dtc-lexer.l @@ -59,10 +59,7 @@ static int dts_version; /* = 0 */ <INCLUDE>\"[^"\n]*\" { yytext[strlen(yytext) - 1] = 0; - if (!push_input_file(yytext + 1)) { - /* Some unrecoverable error.*/ - exit(1); - } + push_input_file(yytext + 1); yy_pop_state(); } @@ -243,21 +240,16 @@ struct incl_file *incl_file_stack; static int incl_depth = 0; -int push_input_file(const char *filename) +void push_input_file(const char *filename) { struct incl_file *incl_file; struct dtc_file *newfile; struct search_path search, *searchptr = NULL; - if (!filename) { - yyerror("No include file name given."); - return 0; - } + assert(filename); - if (incl_depth++ >= MAX_INCLUDE_DEPTH) { - yyerror("Includes nested too deeply"); - return 0; - } + if (incl_depth++ >= MAX_INCLUDE_DEPTH) + die("Includes nested too deeply"); if (srcpos_file) { search.dir = srcpos_file->dir; @@ -267,11 +259,9 @@ int push_input_file(const char *filename) } newfile = dtc_open_file(filename, searchptr); - if (!newfile) { - yyerrorf("Couldn't open \"%s\": %s", - filename, strerror(errno)); - exit(1); - } + if (!newfile) + die("Couldn't open \"%s\": %s", filename, strerror(errno)); + incl_file = xmalloc(sizeof(struct incl_file)); @@ -292,8 +282,6 @@ int push_input_file(const char *filename) yylineno = 1; yyin = newfile->file; yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - - return 1; } |