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

tanoku at users.sourceforge.net tanoku at users.sourceforge.net
Sat Oct 18 11:14:44 CEST 2008


Revision: 34817
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34817&view=rev
Author:   tanoku
Date:     2008-10-18 09:14:43 +0000 (Sat, 18 Oct 2008)

Log Message:
-----------
Changed XML Parser to require standards-compilant XML header.
Updated STX version to 0.3

Modified Paths:
--------------
    scummvm/trunk/common/xmlparser.cpp
    scummvm/trunk/common/xmlparser.h
    scummvm/trunk/gui/theme.h
    scummvm/trunk/gui/themes/default.inc
    scummvm/trunk/gui/themes/scummclassic/THEMERC
    scummvm/trunk/gui/themes/scummclassic/classic_gfx.stx
    scummvm/trunk/gui/themes/scummclassic/classic_layout.stx
    scummvm/trunk/gui/themes/scummclassic/classic_layout_320.stx
    scummvm/trunk/gui/themes/scummclassic.zip
    scummvm/trunk/gui/themes/scummmodern/THEMERC
    scummvm/trunk/gui/themes/scummmodern/scummodern_gfx.stx
    scummvm/trunk/gui/themes/scummmodern/scummodern_layout.stx
    scummvm/trunk/gui/themes/scummmodern/scummodern_layout_320.stx
    scummvm/trunk/gui/themes/scummmodern.zip

Modified: scummvm/trunk/common/xmlparser.cpp
===================================================================
--- scummvm/trunk/common/xmlparser.cpp	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/common/xmlparser.cpp	2008-10-18 09:14:43 UTC (rev 34817)
@@ -54,7 +54,7 @@
 			lineCount++;
 	}
 	
-	_stream->seek(-middle, SEEK_CUR);
+	_stream->seek(-MIN(middle, startPosition), SEEK_CUR);
 	
 	for (int i = 0, j = 0; i < kErrorMessageWidth; ++i, ++j) {
 		c = _stream->readByte();
@@ -105,11 +105,32 @@
 	return false;
 }
 
+bool XMLParser::parseXMLHeader(ParserNode *node) {
+	assert(node->header);
+	
+	if (_activeKey.size() != 1)
+		return parserError("XML Header is expected in the global scope.");
+		
+	if (!node->values.contains("version"))
+		return parserError("Missing XML version in XML header.");
+		
+	if (node->values["version"] != "1.0")
+		return parserError("Unsupported XML version.");
+		
+	return true;
+}
+
 bool XMLParser::parseActiveKey(bool closed) {
 	bool ignore = false;
 	assert(_activeKey.empty() == false);
 
 	ParserNode *key = _activeKey.top();
+	
+	if (key->name == "xml" && key->header == true) {
+		assert(closed);
+		return parseXMLHeader(key) && closeKey();
+	}
+	
 	XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;
 	
 	if (layout->children.contains(key->name)) {
@@ -217,9 +238,10 @@
 	cleanup();
 
 	bool activeClosure = false;
-	bool selfClosure = false;
+	bool activeHeader = false;
+	bool selfClosure;
 
-	_state = kParserNeedKey;
+	_state = kParserNeedHeader;
 	_activeKey.clear();
 
 	_char = _stream->readByte();
@@ -232,6 +254,7 @@
 			continue;
 
 		switch (_state) {
+			case kParserNeedHeader:
 			case kParserNeedKey:
 				if (_char != '<') {
 					parserError("Parser expecting key start.");
@@ -243,8 +266,16 @@
 					break;
 				}
 
-				if (_char == '/') { // FIXME: What if it's a comment start
+				if (_state == kParserNeedHeader) {
+					if (_char != '?') {
+						parserError("Expecting XML header.");
+						break;
+					}
+					
 					_char = _stream->readByte();
+					activeHeader = true;
+				} else if (_char == '/') {
+					_char = _stream->readByte();
 					activeClosure = true;
 				}
 
@@ -266,6 +297,7 @@
 					ParserNode *node = allocNode(); //new ParserNode;
 					node->name = _token;
 					node->ignore = false;
+					node->header = activeHeader;
 					node->depth = _activeKey.size();
 					node->layout = 0;
 					_activeKey.push(node);
@@ -291,23 +323,29 @@
 					_char = _stream->readByte();
 					break;
 				}
-
+				
 				selfClosure = false;
 
-				if (_char == '/') { // FIXME: comment start?
+				if (_char == '/' || (_char == '?' && activeHeader)) {
 					selfClosure = true;
 					_char = _stream->readByte();
 				}
 
 				if (_char == '>') {
-					if (parseActiveKey(selfClosure)) {
+					if (activeHeader && !selfClosure) {
+						parserError("XML Header must be self-closed.");
+					} else if (parseActiveKey(selfClosure)) {
 						_char = _stream->readByte();
 						_state = kParserNeedKey;
 					}
+					
+					activeHeader = false;
 					break;
 				}
-
-				if (!parseToken()) 
+				
+				if (selfClosure)
+					parserError("Expecting key closure after '/' symbol.");
+				else if (!parseToken()) 
 					parserError("Error when parsing key value.");
 				else 
 					_state = kParserNeedPropertyOperator;

Modified: scummvm/trunk/common/xmlparser.h
===================================================================
--- scummvm/trunk/common/xmlparser.h	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/common/xmlparser.h	2008-10-18 09:14:43 UTC (rev 34817)
@@ -129,6 +129,7 @@
 
 	/** Active state for the parser */
 	enum ParserState {
+		kParserNeedHeader,
 		kParserNeedKey,
 		kParserNeedKeyName,
 
@@ -166,6 +167,7 @@
 		Common::String name;
 		Common::StringMap values;
 		bool ignore;
+		bool header;
 		int depth;
 		XMLKeyLayout *layout;
 	};
@@ -404,7 +406,7 @@
 			_char = _stream->readByte();
 		}
 
-		return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/';
+		return isspace(_char) != 0 || _char == '>' || _char == '=' || _char == '/' || _char == '?';
 	}
 
 	/**
@@ -451,6 +453,8 @@
 		va_end(args);
 		return (*key == 0);
 	}
+	
+	bool parseXMLHeader(ParserNode *node);
 
 	/**
 	 * Overload if your parser needs to support parsing the same file

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/theme.h	2008-10-18 09:14:43 UTC (rev 34817)
@@ -35,7 +35,7 @@
 #include "graphics/fontman.h"
 
 #define THEME_VERSION 24
-#define SCUMMVM_THEME_VERSION_STR "SCUMMVM_STX0.2"
+#define SCUMMVM_THEME_VERSION_STR "SCUMMVM_STX0.3"
 
 namespace GUI {
 

Modified: scummvm/trunk/gui/themes/default.inc
===================================================================
--- scummvm/trunk/gui/themes/default.inc	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/default.inc	2008-10-18 09:14:43 UTC (rev 34817)
@@ -1,3 +1,4 @@
+"<?xml version = '1.0'?> "
 "<render_info> "
 "<palette> "
 "<color name = 'black' "
@@ -304,6 +305,7 @@
 "/> "
 "</drawdata> "
 "</render_info> "
+"<?xml version = '1.0'?> "
 "<layout_info resolution = '-320xY, -256x240'> "
 "<globals> "
 "<def var = 'Line.Height' value = '16' /> "
@@ -907,6 +909,7 @@
 "</layout> "
 "</dialog> "
 "</layout_info> "
+"<?xml version = '1.0'?> "
 "<layout_info resolution = '320xY, 256x240'> "
 "<globals> "
 "<def var = 'Line.Height' value = '12' /> "

Modified: scummvm/trunk/gui/themes/scummclassic/THEMERC
===================================================================
--- scummvm/trunk/gui/themes/scummclassic/THEMERC	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummclassic/THEMERC	2008-10-18 09:14:43 UTC (rev 34817)
@@ -1 +1 @@
-[SCUMMVM_STX0.2:ScummVM Classic Theme:No Author]
\ No newline at end of file
+[SCUMMVM_STX0.3:ScummVM Classic Theme:No Author]
\ No newline at end of file

Modified: scummvm/trunk/gui/themes/scummclassic/classic_gfx.stx
===================================================================
--- scummvm/trunk/gui/themes/scummclassic/classic_gfx.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummclassic/classic_gfx.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <render_info>
 	<palette>
 		<color name = 'black'

Modified: scummvm/trunk/gui/themes/scummclassic/classic_layout.stx
===================================================================
--- scummvm/trunk/gui/themes/scummclassic/classic_layout.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummclassic/classic_layout.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <layout_info resolution = '-320xY, -256x240'>
 	<globals>
 		<def var = 'Line.Height' value = '16' />

Modified: scummvm/trunk/gui/themes/scummclassic/classic_layout_320.stx
===================================================================
--- scummvm/trunk/gui/themes/scummclassic/classic_layout_320.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummclassic/classic_layout_320.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <layout_info resolution = "320xY, 256x240">
 	<globals>
 		<def var = 'Line.Height' value = '12' />

Modified: scummvm/trunk/gui/themes/scummclassic.zip
===================================================================
(Binary files differ)

Modified: scummvm/trunk/gui/themes/scummmodern/THEMERC
===================================================================
--- scummvm/trunk/gui/themes/scummmodern/THEMERC	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummmodern/THEMERC	2008-10-18 09:14:43 UTC (rev 34817)
@@ -1 +1 @@
-[SCUMMVM_STX0.2:ScummVM Modern Theme:No Author]
\ No newline at end of file
+[SCUMMVM_STX0.3:ScummVM Modern Theme:No Author]
\ No newline at end of file

Modified: scummvm/trunk/gui/themes/scummmodern/scummodern_gfx.stx
===================================================================
--- scummvm/trunk/gui/themes/scummmodern/scummodern_gfx.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummmodern/scummodern_gfx.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <render_info>
 	<palette>
 		<color name = 'darkred'

Modified: scummvm/trunk/gui/themes/scummmodern/scummodern_layout.stx
===================================================================
--- scummvm/trunk/gui/themes/scummmodern/scummodern_layout.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummmodern/scummodern_layout.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <layout_info resolution = '-320xY, -256x240'>
 	<globals>
 		<def var = 'Line.Height' value = '16' />

Modified: scummvm/trunk/gui/themes/scummmodern/scummodern_layout_320.stx
===================================================================
--- scummvm/trunk/gui/themes/scummmodern/scummodern_layout_320.stx	2008-10-18 01:44:12 UTC (rev 34816)
+++ scummvm/trunk/gui/themes/scummmodern/scummodern_layout_320.stx	2008-10-18 09:14:43 UTC (rev 34817)
@@ -22,7 +22,7 @@
  - $Id$
  -
  -->
-
+<?xml version = "1.0"?>
 <layout_info resolution = "320xY, 256x240">
 	<globals>
 		<def var = 'Line.Height' value = '12' />

Modified: scummvm/trunk/gui/themes/scummmodern.zip
===================================================================
(Binary files differ)


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