[Scummvm-cvs-logs] SF.net SVN: scummvm: [32818] scummvm/branches/gsoc2008-gui

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Sat Jun 28 02:02:54 CEST 2008


Revision: 32818
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32818&view=rev
Author:   Tanoku
Date:     2008-06-27 17:02:54 -0700 (Fri, 27 Jun 2008)

Log Message:
-----------
Improved support for parsing integers in the XML parser.
Bug fixes.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/common/xmlparser.h
    scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.h

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-06-27 09:57:38 UTC (rev 32817)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-06-28 00:02:54 UTC (rev 32818)
@@ -55,7 +55,7 @@
 		return _stream;
 	}
 
-	const char operator [](int idx) {
+	char operator [](int idx) {
 		assert(_stream && idx >= 0);
 
 		if (_pos + 1 != idx)
@@ -287,6 +287,51 @@
 		return isspace(_text[_pos]) != 0 || _text[_pos] == '>';
 	}
 
+	/**
+	 * Parses the values inside an integer key.
+	 * The count parameter specifies the number of values inside
+	 * the key, which are expected to be separated with commas.
+	 *
+	 * Sample usage:
+	 * parseIntegerKey("255, 255, 255", 3, &red, &green, &blue);
+	 * [will parse each field into its own integer]
+	 *
+	 * parseIntegerKey("1234", 1, &number);
+	 * [will parse the single number into the variable]
+	 *
+	 * @param key String containing the integers to be parsed.
+	 * @param count Number of comma-separated ints in the string.
+	 * @param ... Integer variables to store the parsed ints, passed
+	 *            by reference.
+	 * @returns True if the parsing succeeded.
+	 */
+	virtual bool parseIntegerKey(const char *key, int count, ...) {
+		char *parseEnd = 0;
+		int *num_ptr;
+
+		va_list args;
+		va_start(args, count);
+
+		while (count--) {
+			while (isspace(*key))
+				key++;
+
+			num_ptr = va_arg(args, int*);
+			*num_ptr = strtol(key, &parseEnd, 10);
+
+			while (isspace(*parseEnd))
+				parseEnd++;
+
+			if (count && *parseEnd++ != ',')
+				return false;
+
+			key = parseEnd;
+		}
+
+		va_end(args);
+		return (*parseEnd == 0);
+	}
+
 	int _pos; /** Current position on the XML buffer. */
 	XMLStream _text; /** Buffer with the text being parsed */
 	Common::String _fileName;

Modified: scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp	2008-06-27 09:57:38 UTC (rev 32817)
+++ scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp	2008-06-28 00:02:54 UTC (rev 32818)
@@ -137,7 +137,7 @@
 		warning("Could not parse custom theme '%s'.\nFalling back to default theme", themeName.c_str());
 		
 		if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure
-			error("Could not load default embeded theme.");
+			error("Could not load default embeded theme");
 	}
 
 	for (int i = 0; i < kDrawDataMAX; ++i) {

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-06-27 09:57:38 UTC (rev 32817)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-06-28 00:02:54 UTC (rev 32818)
@@ -51,7 +51,7 @@
 	"</drawdata>"
 
 	"<drawdata id = 'button_idle' cache = false>"
-		"<drawstep func = 'roundedsq' radius = '8' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' />"
+		"<drawstep func = 'roundedsq' radius = '8' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 3 />"
 	"</drawdata>"
 "</render_info>"
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-27 09:57:38 UTC (rev 32817)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-28 00:02:54 UTC (rev 32818)
@@ -175,7 +175,7 @@
 
 	int red, green, blue;
 
-	if (sscanf(colorNode->values["rgb"].c_str(), "%d, %d, %d", &red, &green, &blue) != 3 ||
+	if (parseIntegerKey(colorNode->values["rgb"].c_str(), 3, &red, &green, &blue) == false ||
 		red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)
 		return parserError("Error when parsing RGB values for palette color '%s'", name.c_str());\
 
@@ -263,7 +263,7 @@
 }
 
 bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific) {
-	int red, green, blue, w, h;
+	int red, green, blue, w, h, x;
 	Common::String val;
 
 /**
@@ -278,10 +278,10 @@
  */
 #define __PARSER_ASSIGN_INT(struct_name, key_name, force) \
 	if (stepNode->values.contains(key_name)) { \
-		if (!validateKeyInt(stepNode->values[key_name].c_str()))\
+		if (!parseIntegerKey(stepNode->values[key_name].c_str(), 1, &x)) \
 			return parserError("Error when parsing key value for '%s'.", key_name); \
 		\
-		drawstep->struct_name = atoi(stepNode->values[key_name].c_str()); \
+		drawstep->struct_name = x; \
 	} else if (force) { \
 		return parserError("Missing necessary key '%s'.", key_name); \
 	}
@@ -304,7 +304,7 @@
 			red = _palette[val].r; \
 			green = _palette[val].g; \
 			blue = _palette[val].b; \
-		} else if (sscanf(val.c_str(), "%d, %d, %d", &red, &green, &blue) != 3 || \
+		} else if (parseIntegerKey(val.c_str(), 3, &red, &green, &blue) == false || \
 			red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) \
 			return parserError("Error when parsing color struct '%s'", val.c_str());\
 		\

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-27 09:57:38 UTC (rev 32817)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-28 00:02:54 UTC (rev 32818)
@@ -325,26 +325,7 @@
 	bool parserCallback_renderInfo();
 	bool parserCallback_layoutInfo();
 	bool parserCallback_defaultSet();
-		
 
-	bool validateKeyIntSigned(const char *key) {
-		if (!isdigit(*key) && *key != '+' && *key != '-')
-			return false;
-
-		return validateKeyInt(key + 1);
-	}
-
-	bool validateKeyInt(const char *key) {
-		if (*key == 0)
-			return false;
-
-		while (*key)
-			if (!isdigit(*key++))
-				return false;
-
-		return true;
-	}
-
 	Graphics::DrawStep *newDrawStep();
 	Graphics::DrawStep *defaultDrawStep();
 	bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific);


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