[PATCH] xfree86: Return non-NULL when reaching EOF with more files to parse

Dan Nicholson dbn.lists at gmail.com
Fri Jan 1 11:58:03 PST 2010


The config parser is line based, so it has to return when reaching EOF
just like when reaching EOL. In order to signal that there are still
files to parse, non-NULL must be returned. Previously, the parser was
just moving to the first line of the next file and continuing without
returning to the caller. This only works when each file ends in an empty
line.

Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
---
 hw/xfree86/parser/scan.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index b80fbfb..b26b6f6 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -226,14 +226,17 @@ xf86getNextLine(void)
 		ret = fgets(configBuf + pos, configBufLen - pos - 1,
 			    configFiles[curFileIndex].file);
 
+		/*
+		 * If we've reached EOF, prepare for the next file and don't
+		 * return NULL. Otherwise, just reset the index for parsing.
+		 */
 		if (!ret) {
-			/* stop if there are no more files */
-			if (++curFileIndex >= numFiles) {
+			if (++curFileIndex < numFiles) {
+				ret = configBuf;
+				configLineNo = 0;
+			} else
 				curFileIndex = 0;
-				break;
-			}
-			configLineNo = 0;
-			continue;
+			break;
 		}
 
 		/* search for EOL in the new block of chars */
-- 
1.6.2.5


More information about the xorg-devel mailing list