From 3f0f7fa08bea272fa61b0fde5d7783aa44b1ff25 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sat, 28 Jun 2008 00:02:54 +0000 Subject: Improved support for parsing integers in the XML parser. Bug fixes. svn-id: r32818 --- gui/InterfaceManager.cpp | 2 +- gui/ThemeDefaultXML.cpp | 2 +- gui/ThemeParser.cpp | 10 +++++----- gui/ThemeParser.h | 19 ------------------- 4 files changed, 7 insertions(+), 26 deletions(-) (limited to 'gui') diff --git a/gui/InterfaceManager.cpp b/gui/InterfaceManager.cpp index cbaf1bbf5b..7a779df593 100644 --- a/gui/InterfaceManager.cpp +++ b/gui/InterfaceManager.cpp @@ -137,7 +137,7 @@ bool InterfaceManager::loadTheme(Common::String themeName) { 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) { diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp index 0d9faf0768..cd571e680e 100644 --- a/gui/ThemeDefaultXML.cpp +++ b/gui/ThemeDefaultXML.cpp @@ -51,7 +51,7 @@ bool InterfaceManager::loadDefaultXML() { "" "" - "" + "" "" "" diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 671a4a543e..8dc02297b7 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -175,7 +175,7 @@ bool ThemeParser::parserCallback_color() { 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::parserCallback_DRAWDATA() { } 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 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst */ #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 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst 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());\ \ diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index 2a7e0999d5..55f39d8a44 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -325,25 +325,6 @@ protected: 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(); -- cgit v1.2.3