[Scummvm-cvs-logs] SF.net SVN: scummvm:[34819] scummvm/trunk/common

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sat Oct 18 12:11:35 CEST 2008


Revision: 34819
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34819&view=rev
Author:   Tanoku
Date:     2008-10-18 10:11:35 +0000 (Sat, 18 Oct 2008)

Log Message:
-----------
Rewrote XMLParser error() function for the 5th time.
Bugfix: Ambiguous error message when parsing an unexpected header.

Modified Paths:
--------------
    scummvm/trunk/common/xmlparser.cpp
    scummvm/trunk/common/xmlparser.h

Modified: scummvm/trunk/common/xmlparser.cpp
===================================================================
--- scummvm/trunk/common/xmlparser.cpp	2008-10-18 10:06:33 UTC (rev 34818)
+++ scummvm/trunk/common/xmlparser.cpp	2008-10-18 10:11:35 UTC (rev 34819)
@@ -38,12 +38,9 @@
 	_state = kParserError;
 	
 	const int startPosition = _stream->pos();
-	const int middle = kErrorMessageWidth / 2;
-	
 	int currentPosition = startPosition;
-	int lineCount = 1, realMiddle = 0;
-	char errorBuffer[kErrorMessageWidth];
-	char c, *errorKeyStart = 0;
+	int lineCount = 1;
+	char c = 0;
 	
 	_stream->seek(0, SEEK_SET);
 	
@@ -54,47 +51,41 @@
 			lineCount++;
 	}
 	
-	_stream->seek(-MIN(middle, startPosition), SEEK_CUR);
-	
-	for (int i = 0, j = 0; i < kErrorMessageWidth; ++i, ++j) {
+	assert(_stream->pos() == startPosition);
+	currentPosition = startPosition;
+
+	int keyOpening = 0;
+	int keyClosing = 0;
+
+	while (currentPosition-- && keyOpening == 0) {
+		_stream->seek(-2, SEEK_CUR);
 		c = _stream->readByte();
-		
-		if (c == '\n' || c == '\r') {
-			errorBuffer[i++] = ' ';
-			j++;
-			
-			while (c && isspace(c)) {
-				c = _stream->readByte();
-				j++;
-			}
-		}
-			
-		errorBuffer[i] = c;
-		if (!realMiddle && j >= middle)
-			realMiddle = i;
+
+		if (c == '<')
+			keyOpening = currentPosition - 1;
+		else if (c == '>')
+			keyClosing = currentPosition;
 	}
-		
-	for (int i = realMiddle; i >= 0; --i)
-		if (errorBuffer[i] == '<') {
-			errorKeyStart = &errorBuffer[i];
-			break;
-		}
-		
-	for (int i = realMiddle; i < kErrorMessageWidth; ++i)
-		if (errorBuffer[i] == '>') {
-			errorBuffer[i + 1] = 0;
-			break;
-		}
+
+	_stream->seek(startPosition, SEEK_SET);
+	currentPosition = startPosition;
+	while (keyClosing == 0 && c && currentPosition++) {
+		c = _stream->readByte();
+
+		if (c == '>')
+			keyClosing = currentPosition;
+	}
 	
 	fprintf(stderr, "\n  File <%s>, line %d:\n", _fileName.c_str(), lineCount);
 	
-	if (!errorKeyStart)
-		fprintf(stderr, "...%s%s\n", errorBuffer, errorBuffer[strlen(errorBuffer) - 1] == '>' ? "" : "...");
-	else
-		fprintf(stderr, "%s%s\n", errorKeyStart, errorBuffer[strlen(errorBuffer) - 1] == '>' ? "" : "...");
+	currentPosition = (keyClosing - keyOpening);
+	_stream->seek(keyOpening, SEEK_SET);
 
-	fprintf(stderr, "\nParser error: ");
+	while (currentPosition--)
+		fprintf(stderr, "%c", _stream->readByte());
 
+	fprintf(stderr, "\n\nParser error: ");
+
 	va_list args;
 	va_start(args, errorString);
 	vfprintf(stderr, errorString, args);
@@ -277,6 +268,9 @@
 				} else if (_char == '/') {
 					_char = _stream->readByte();
 					activeClosure = true;
+				} else if (_char == '?') {
+					parserError("Unexpected header. There may only be one XML header per file.");
+					break;
 				}
 
 				_state = kParserNeedKeyName;

Modified: scummvm/trunk/common/xmlparser.h
===================================================================
--- scummvm/trunk/common/xmlparser.h	2008-10-18 10:06:33 UTC (rev 34818)
+++ scummvm/trunk/common/xmlparser.h	2008-10-18 10:11:35 UTC (rev 34819)
@@ -406,7 +406,7 @@
 			_char = _stream->readByte();
 		}
 
-		return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/' || _char == '?';
+		return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/';
 	}
 
 	/**


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list