From 8fc49e139ba49b5ce8ed9116c5eeeb7b102886c5 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 1 Oct 2021 18:23:21 -0500 Subject: [PATCH] parser: print program name with error messages In yyerror(), prefix the line reporting the error with the program name. This makes the output consistent with the output of errx() which reports memory allocation errors. Note that this uses a GNU-only feature; if that's not desirable it's easy to do this more portably. Signed-off-by: Alex Elder Message-Id: <20211001232338.769309-18-elder@linaro.org> Signed-off-by: Bjorn Andersson --- parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/parser.c b/parser.c index e6d3f2e..b6e11af 100644 --- a/parser.c +++ b/parser.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include #include #include @@ -60,7 +62,8 @@ static void yyerror(const char *fmt, ...) va_start(ap, fmt); - fprintf(stderr, "parse error on line %u:\n\t", yyline); + fprintf(stderr, "%s: parse error on line %u:\n\t", + program_invocation_short_name, yyline); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); @@ -156,7 +159,7 @@ static struct token yylex() token.str = strdup(buf); if (!token.str) - yyerror("strdup failed in %s(), line %d\n", + yyerror("strdup() failed in %s(), line %d\n", __func__, __LINE__); list_for_each_entry(sym, &symbols, node) { if (strcmp(buf, sym->name) == 0) {