From 7b42788f212079c2ef4c69c095efa50e90ca1301 Mon Sep 17 00:00:00 2001 From: Jonas Ådahl Date: Mon, 25 Jan 2016 17:28:06 +0800 Subject: scanner: Print filename on DTD validation error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't just print prefix the errors with "protocol", but the actual file name, if wayland-scanner was passed with the filename of the protocol file. If wayland-scanner is reading from stdin, errors will be prefixed with "" instead of "protocol". Signed-off-by: Jonas Ådahl Reviewed-by: David Fort Reviewed-by: Derek Foreman Reviewed-by: Bryce Harrington --- src/scanner.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/scanner.c') diff --git a/src/scanner.c b/src/scanner.c index 1d626f4..dda5473 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -71,7 +71,7 @@ usage(int ret) } static bool -is_dtd_valid(FILE *input) +is_dtd_valid(FILE *input, const char *filename) { bool rc = true; #if HAVE_LIBXML @@ -101,7 +101,7 @@ is_dtd_valid(FILE *input) abort(); } - doc = xmlCtxtReadFd(ctx, fd, "protocol", NULL, 0); + doc = xmlCtxtReadFd(ctx, fd, filename, NULL, 0); if (!doc) { fprintf(stderr, "Failed to read XML\n"); abort(); @@ -1623,6 +1623,7 @@ int main(int argc, char *argv[]) struct parse_context ctx; struct protocol protocol; FILE *input = stdin; + char *input_filename = NULL; int len; void *buf; bool help = false, core_headers = false; @@ -1678,7 +1679,8 @@ int main(int argc, char *argv[]) usage(EXIT_FAILURE); if (argc == 3) { - input = fopen(argv[1], "r"); + input_filename = argv[1]; + input = fopen(input_filename, "r"); if (input == NULL) { fprintf(stderr, "Could not open input file: %s\n", strerror(errno)); @@ -1700,9 +1702,12 @@ int main(int argc, char *argv[]) /* initialize context */ memset(&ctx, 0, sizeof ctx); ctx.protocol = &protocol; - ctx.loc.filename = ""; + if (input == stdin) + ctx.loc.filename = ""; + else + ctx.loc.filename = input_filename; - if (!is_dtd_valid(input)) { + if (!is_dtd_valid(input, ctx.loc.filename)) { fprintf(stderr, "*******************************************************\n" "* *\n" -- cgit v1.2.3-70-g09d2