diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-11-12 10:38:01 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-11-12 14:47:15 +0100 |
commit | cc3fc44dbfe320989e0cc011c4a727971ae18ad5 (patch) | |
tree | 5e0849f11a89e65ca3566b190ba1399c3f8c6a19 /common | |
parent | 671cf43e56e9b2b9a086f4656bd0767b7d4b2986 (diff) | |
download | barebox-cc3fc44dbfe320989e0cc011c4a727971ae18ad5.tar.gz barebox-cc3fc44dbfe320989e0cc011c4a727971ae18ad5.tar.xz |
hush: Be more informative on syntax error
Print the token that led to a syntax error, at least for the common
case.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/hush.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/common/hush.c b/common/hush.c index 3c4d2445f0..35c3c3c80f 100644 --- a/common/hush.c +++ b/common/hush.c @@ -264,8 +264,27 @@ struct in_str { #define final_printf debug -static void syntax(void) { - printf("syntax error\n"); +static void syntax(void) +{ + printf("syntax error\n"); +} + +static void syntaxf(const char *fmt, ...) +{ + va_list args; + + printf("syntax error: "); + + va_start(args, fmt); + + vprintf(fmt, args); + + va_end(args); +} + +static void syntax_unexpected_token(const char *token) +{ + syntaxf("unexpected token `%s'\n", token); } /* o_string manipulation: */ @@ -1201,7 +1220,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx) initialize_context(ctx); ctx->stack = new; } else if (ctx->w == RES_NONE || !(ctx->old_flag & (1 << r->code))) { - syntax(); + syntax_unexpected_token(r->literal); ctx->w = RES_SNTX; b_reset(dest); return 1; |