Browse Source

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>
main
David Gibson 17 years ago committed by Jon Loeliger
parent
commit
7c635dcb2f
  1. 28
      dtc-lexer.l
  2. 2
      srcpos.h

28
dtc-lexer.l

@ -59,10 +59,7 @@ static int dts_version; /* = 0 */ @@ -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; @@ -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) @@ -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) @@ -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;
}



2
srcpos.h

@ -75,7 +75,7 @@ extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2))); @@ -75,7 +75,7 @@ extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));

extern struct dtc_file *srcpos_file;

extern int push_input_file(const char *filename);
extern void push_input_file(const char *filename);
extern int pop_input_file(void);

struct search_path {

Loading…
Cancel
Save