[U-Boot-Users] [DTC PATCH 1/2] Add yyerrorf() for formatted error messages.

Scott Wood
2007-12-20T16:48:23Z

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
dtc-parser.y | 16 ++++++++++++++++
srcpos.h | 1 +
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index 002ea7f..4a0181d 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -318,6 +318,22 @@ void yyerror (char const *s)
fname, yylloc.first_line, s);
}

+void yyerrorf(char const *s, ...)
+{
+ const char *fname = srcpos_filename_for_num(yylloc.filenum);
+ va_list va;
+ va_start(va, s);
+
+ if (strcmp(fname, "-") == 0)
+ fname = "stdin";
+
+ fprintf(stderr, "%s:%d ", fname, yylloc.first_line);
+ vfprintf(stderr, s, va);
+ fprintf(stderr, "\n");
+
+ va_end(va);
+}
+
unsigned long long eval_literal(const char *s, int base, int bits)
{
unsigned long long val;
diff --git a/srcpos.h b/srcpos.h
index ce7ab5b..e59c788 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -63,6 +63,7 @@ typedef struct YYLTYPE {

extern void yyerror(char const *);
+extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));

extern int srcpos_filenum;

--
1.5.3