[PATCH xkbcomp] Reset scan state when opening a new file

Daniel Stone daniel at fooishbar.org
Thu Nov 1 17:05:12 PDT 2012


When we opened a new file after encountering a parse error, we weren't
resetting our scan state, and continued to read out of the old buffer
rather than that of the new file.

Fixes a regression introduced in 9887842e ('Use fread() instead of
getc()').

Test case:
    xkbcomp -lfhlpR "path/to/xkeyboard-config.git/symbols/*"
The Makefiles in that tree would cause parse errors, the resulting directory
file is incomplete (down from ~12000 to ~230 lines).

Reported-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 parseutils.c |    2 +-
 parseutils.h |    3 +--
 xkbcomp.c    |    2 +-
 xkbscan.c    |   10 +++++++++-
 4 files changed, 12 insertions(+), 5 deletions(-)

This has actually already been pushed.

diff --git a/parseutils.c b/parseutils.c
index 253cd9d..a1b6e9e 100644
--- a/parseutils.c
+++ b/parseutils.c
@@ -797,7 +797,7 @@ XKBParseFile(FILE * file, XkbFile ** pRtrn)
 {
     if (file)
     {
-        yyin = file;
+        scan_set_file(file);
         rtrnValue = NULL;
         if (yyparse() == 0)
         {
diff --git a/parseutils.h b/parseutils.h
index 8b8a6c1..8c381d4 100644
--- a/parseutils.h
+++ b/parseutils.h
@@ -198,11 +198,10 @@ extern int yywrap(void);
 
 extern int yylex(void);
 extern int yyparse(void);
+extern void scan_set_file(FILE *file);
 
 extern int setScanState(char * /* file */ ,
                         int     /* line */
     );
 
-extern FILE *yyin;
-
 #endif /* XKBPARSE_H */
diff --git a/xkbcomp.c b/xkbcomp.c
index 063ae87..116bcfa 100644
--- a/xkbcomp.c
+++ b/xkbcomp.c
@@ -883,7 +883,7 @@ main(int argc, char *argv[])
     XkbFileInfo result;
     Status status;
 
-    yyin = stdin;
+    scan_set_file(stdin);
     uSetEntryFile(NullString);
     uSetDebugFile(NullString);
     uSetErrorFile(NullString);
diff --git a/xkbscan.c b/xkbscan.c
index 22a034f..a05d569 100644
--- a/xkbscan.c
+++ b/xkbscan.c
@@ -37,7 +37,7 @@
 
 unsigned int scanDebug;
 
-FILE *yyin = NULL;
+static FILE *yyin;
 
 static char scanFileBuf[1024] = {0};
 char *scanFile = scanFileBuf;
@@ -269,6 +269,14 @@ tokText(int tok)
 }
 #endif
 
+void
+scan_set_file(FILE *file)
+{
+    readBufLen = 0;
+    readBufPos = 0;
+    yyin = file;
+}
+
 static int
 scanchar(void)
 {
-- 
1.7.10.4



More information about the xorg-devel mailing list