diff options
-rw-r--r-- | backends/vkeybd/virtual-keyboard-parser.cpp | 6 | ||||
-rw-r--r-- | common/xmlparser.cpp | 41 | ||||
-rw-r--r-- | common/xmlparser.h | 29 | ||||
-rw-r--r-- | engines/sword25/gfx/animationresource.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/gfx/fontresource.cpp | 14 | ||||
-rw-r--r-- | gui/ThemeParser.cpp | 40 |
6 files changed, 75 insertions, 57 deletions
diff --git a/backends/vkeybd/virtual-keyboard-parser.cpp b/backends/vkeybd/virtual-keyboard-parser.cpp index 6a644e0cdf..dd11866262 100644 --- a/backends/vkeybd/virtual-keyboard-parser.cpp +++ b/backends/vkeybd/virtual-keyboard-parser.cpp @@ -270,7 +270,7 @@ bool VirtualKeyboardParser::parserCallback_layout(ParserNode *node) { int r, g, b; if (node->values.contains("transparent_color")) { - if (!parseIntegerKey(node->values["transparent_color"].c_str(), 3, &r, &g, &b)) + if (!parseIntegerKey(node->values["transparent_color"], 3, &r, &g, &b)) return parserError("Could not parse color value"); } else { // default to purple @@ -281,7 +281,7 @@ bool VirtualKeyboardParser::parserCallback_layout(ParserNode *node) { _mode->transparentColor = format.RGBToColor(r, g, b); if (node->values.contains("display_font_color")) { - if (!parseIntegerKey(node->values["display_font_color"].c_str(), 3, &r, &g, &b)) + if (!parseIntegerKey(node->values["display_font_color"], 3, &r, &g, &b)) return parserError("Could not parse color value"); } else { r = g = b = 0; // default to black @@ -336,7 +336,7 @@ byte VirtualKeyboardParser::parseFlags(const String& flags) { bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) { int x1, y1, x2, y2; - if (!parseIntegerKey(coords.c_str(), 4, &x1, &y1, &x2, &y2)) + if (!parseIntegerKey(coords, 4, &x1, &y1, &x2, &y2)) return parserError("Invalid coords for rect area"); rect.left = x1; rect.top = y1; diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 1c652fa19d..48f4f7bdf4 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -229,6 +229,47 @@ bool XMLParser::parseKeyValue(Common::String keyName) { return true; } +bool XMLParser::parseIntegerKey(const char *key, int count, ...) { + bool result; + va_list args; + va_start(args, count); + result = vparseIntegerKey(key, count, args); + va_end(args); + return result; +} + +bool XMLParser::parseIntegerKey(const Common::String &key, int count, ...) { + bool result; + va_list args; + va_start(args, count); + result = vparseIntegerKey(key.c_str(), count, args); + va_end(args); + return result; +} + +bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { + char *parseEnd; + int *num_ptr; + + while (count--) { + while (isspace(*key)) + key++; + + num_ptr = va_arg(args, int*); + *num_ptr = strtol(key, &parseEnd, 10); + + key = parseEnd; + + while (isspace(*key)) + key++; + + if (count && *key++ != ',') + return false; + } + + return (*key == 0); +} + bool XMLParser::closeKey() { bool ignore = false; bool result = true; diff --git a/common/xmlparser.h b/common/xmlparser.h index 5271917927..537fb01941 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -395,32 +395,9 @@ protected: * by reference. * @returns True if the parsing succeeded. */ - bool parseIntegerKey(const char *key, int count, ...) { - char *parseEnd; - 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); - - key = parseEnd; - - while (isspace(*key)) - key++; - - if (count && *key++ != ',') - return false; - } - - va_end(args); - return (*key == 0); - } + bool parseIntegerKey(const char *key, int count, ...); + bool parseIntegerKey(const Common::String &keyStr, int count, ...); + bool vparseIntegerKey(const char *key, int count, va_list args); bool parseXMLHeader(ParserNode *node); diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp index 96a93f1890..6609725c1b 100644 --- a/engines/sword25/gfx/animationresource.cpp +++ b/engines/sword25/gfx/animationresource.cpp @@ -116,7 +116,7 @@ bool AnimationResource::parseBooleanKey(Common::String s, bool &result) { } bool AnimationResource::parserCallback_animation(ParserNode *node) { - if (!parseIntegerKey(node->values["fps"].c_str(), 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) { + if (!parseIntegerKey(node->values["fps"], 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) { return parserError("Illegal or missing fps attribute in <animation> tag in \"%s\". Assuming default (\"%d\").", getFileName().c_str(), DEFAULT_FPS); } diff --git a/engines/sword25/gfx/fontresource.cpp b/engines/sword25/gfx/fontresource.cpp index f7d37e8bdd..cdece041db 100644 --- a/engines/sword25/gfx/fontresource.cpp +++ b/engines/sword25/gfx/fontresource.cpp @@ -93,13 +93,13 @@ bool FontResource::parserCallback_font(ParserNode *node) { // Get the attributes of the font Common::String bitmapFilename = node->values["bitmap"]; - if (!parseIntegerKey(node->values["lineheight"].c_str(), 1, &_LineHeight)) { + if (!parseIntegerKey(node->values["lineheight"], 1, &_LineHeight)) { BS_LOG_WARNINGLN("Illegal or missing lineheight attribute in <font> tag in \"%s\". Assuming default (\"%d\").", getFileName().c_str(), DEFAULT_LINEHEIGHT); _LineHeight = DEFAULT_LINEHEIGHT; } - if (!parseIntegerKey(node->values["gap"].c_str(), 1, &_GapWidth)) { + if (!parseIntegerKey(node->values["gap"], 1, &_GapWidth)) { BS_LOG_WARNINGLN("Illegal or missing gap attribute in <font> tag in \"%s\". Assuming default (\"%d\").", getFileName().c_str(), DEFAULT_GAPWIDTH); _GapWidth = DEFAULT_GAPWIDTH; @@ -131,20 +131,20 @@ bool FontResource::parserCallback_character(ParserNode *node) { // Get the attributes of the character int charCode, top, left, right, bottom; - if (!parseIntegerKey(node->values["code"].c_str(), 1, &charCode) || (charCode < 0) || (charCode >= 256)) { + if (!parseIntegerKey(node->values["code"], 1, &charCode) || (charCode < 0) || (charCode >= 256)) { return parserError("Illegal or missing code attribute in <character> tag in \"%s\".", getFileName().c_str()); } - if (!parseIntegerKey(node->values["top"].c_str(), 1, &top) || (top < 0)) { + if (!parseIntegerKey(node->values["top"], 1, &top) || (top < 0)) { return parserError("Illegal or missing top attribute in <character> tag in \"%s\".", getFileName().c_str()); } - if (!parseIntegerKey(node->values["left"].c_str(), 1, &left) || (left < 0)) { + if (!parseIntegerKey(node->values["left"], 1, &left) || (left < 0)) { return parserError("Illegal or missing left attribute in <character> tag in \"%s\".", getFileName().c_str()); } - if (!parseIntegerKey(node->values["right"].c_str(), 1, &right) || (right < 0)) { + if (!parseIntegerKey(node->values["right"], 1, &right) || (right < 0)) { return parserError("Illegal or missing right attribute in <character> tag in \"%s\".", getFileName().c_str()); } - if (!parseIntegerKey(node->values["bottom"].c_str(), 1, &bottom) || (bottom < 0)) { + if (!parseIntegerKey(node->values["bottom"], 1, &bottom) || (bottom < 0)) { return parserError("Illegal or missing bottom attribute in <character> tag in \"%s\".", getFileName().c_str()); } diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index b9a0c583b0..0daf2528dd 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -195,7 +195,7 @@ bool ThemeParser::parserCallback_text_color(ParserNode *node) { if (_palette.contains(node->values["color"])) getPaletteColor(node->values["color"], red, green, blue); - else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue)) + else if (!parseIntegerKey(node->values["color"], 3, &red, &green, &blue)) return parserError("Error parsing color value for text color definition."); if (!_theme->addTextColor(colorId, red, green, blue)) @@ -216,10 +216,10 @@ bool ThemeParser::parserCallback_cursor(ParserNode *node) { int spotx, spoty, scale; - if (!parseIntegerKey(node->values["hotspot"].c_str(), 2, &spotx, &spoty)) + if (!parseIntegerKey(node->values["hotspot"], 2, &spotx, &spoty)) return parserError("Error parsing cursor Hot Spot coordinates."); - if (!parseIntegerKey(node->values["scale"].c_str(), 1, &scale)) + if (!parseIntegerKey(node->values["scale"], 1, &scale)) return parserError("Error parsing cursor scale."); if (!_theme->createCursor(node->values["file"], spotx, spoty, scale)) @@ -286,7 +286,7 @@ bool ThemeParser::parserCallback_color(ParserNode *node) { int red, green, blue; - if (parseIntegerKey(node->values["rgb"].c_str(), 3, &red, &green, &blue) == false || + if (parseIntegerKey(node->values["rgb"], 3, &red, &green, &blue) == false || red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) return parserError("Error parsing RGB values for palette color '%s'", name.c_str());\ @@ -387,7 +387,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst */ #define __PARSER_ASSIGN_INT(struct_name, key_name, force) \ if (stepNode->values.contains(key_name)) { \ - if (!parseIntegerKey(stepNode->values[key_name].c_str(), 1, &x)) \ + if (!parseIntegerKey(stepNode->values[key_name], 1, &x)) \ return parserError("Error parsing key value for '%s'.", key_name); \ \ drawstep->struct_name = x; \ @@ -411,7 +411,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst red = _palette[val].r; \ green = _palette[val].g; \ blue = _palette[val].b; \ - } else if (parseIntegerKey(val.c_str(), 3, &red, &green, &blue) == false || \ + } else if (parseIntegerKey(val, 3, &red, &green, &blue) == false || \ red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) \ return parserError("Error parsing color struct '%s'", val.c_str());\ \ @@ -481,7 +481,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst drawstep->autoWidth = false; val = stepNode->values["width"]; - if (parseIntegerKey(val.c_str(), 1, &x)) + if (parseIntegerKey(val, 1, &x)) drawstep->w = x; else if (val == "height") drawstep->w = -1; @@ -490,7 +490,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst if (stepNode->values.contains("xpos")) { val = stepNode->values["xpos"]; - if (parseIntegerKey(val.c_str(), 1, &x)) + if (parseIntegerKey(val, 1, &x)) drawstep->x = x; else if (val == "center") drawstep->xAlign = Graphics::DrawStep::kVectorAlignCenter; @@ -509,7 +509,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst drawstep->autoHeight = false; val = stepNode->values["height"]; - if (parseIntegerKey(val.c_str(), 1, &x)) + if (parseIntegerKey(val, 1, &x)) drawstep->h = x; else if (val == "width") drawstep->h = -1; @@ -518,7 +518,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst if (stepNode->values.contains("ypos")) { val = stepNode->values["ypos"]; - if (parseIntegerKey(val.c_str(), 1, &x)) + if (parseIntegerKey(val, 1, &x)) drawstep->y = x; else if (val == "center") drawstep->yAlign = Graphics::DrawStep::kVectorAlignCenter; @@ -569,7 +569,7 @@ bool ThemeParser::parserCallback_def(ParserNode *node) { if (_theme->getEvaluator()->hasVar(node->values["value"]) == true) value = _theme->getEvaluator()->getVar(node->values["value"]); - else if (!parseIntegerKey(node->values["value"].c_str(), 1, &value)) + else if (!parseIntegerKey(node->values["value"], 1, &value)) return parserError("Invalid definition for '%s'.", var.c_str()); _theme->getEvaluator()->setVar(var, value); @@ -608,7 +608,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { if (_theme->getEvaluator()->hasVar(node->values["width"]) == true) width = _theme->getEvaluator()->getVar(node->values["width"]); - else if (!parseIntegerKey(node->values["width"].c_str(), 1, &width)) + else if (!parseIntegerKey(node->values["width"], 1, &width)) return parserError("Corrupted width value in key for %s", var.c_str()); } @@ -616,7 +616,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { if (_theme->getEvaluator()->hasVar(node->values["height"]) == true) height = _theme->getEvaluator()->getVar(node->values["height"]); - else if (!parseIntegerKey(node->values["height"].c_str(), 1, &height)) + else if (!parseIntegerKey(node->values["height"], 1, &height)) return parserError("Corrupted height value in key for %s", var.c_str()); } @@ -651,7 +651,7 @@ bool ThemeParser::parserCallback_dialog(ParserNode *node) { } if (node->values.contains("inset")) { - if (!parseIntegerKey(node->values["inset"].c_str(), 1, &inset)) + if (!parseIntegerKey(node->values["inset"], 1, &inset)) return false; } @@ -682,7 +682,7 @@ bool ThemeParser::parserCallback_layout(ParserNode *node) { int spacing = -1; if (node->values.contains("spacing")) { - if (!parseIntegerKey(node->values["spacing"].c_str(), 1, &spacing)) + if (!parseIntegerKey(node->values["spacing"], 1, &spacing)) return false; } @@ -697,7 +697,7 @@ bool ThemeParser::parserCallback_layout(ParserNode *node) { if (node->values.contains("padding")) { int paddingL, paddingR, paddingT, paddingB; - if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB)) + if (!parseIntegerKey(node->values["padding"], 4, &paddingL, &paddingR, &paddingT, &paddingB)) return false; _theme->getEvaluator()->addPadding(paddingL, paddingR, paddingT, paddingB); @@ -713,7 +713,7 @@ bool ThemeParser::parserCallback_space(ParserNode *node) { if (_theme->getEvaluator()->hasVar(node->values["size"])) size = _theme->getEvaluator()->getVar(node->values["size"]); - else if (!parseIntegerKey(node->values["size"].c_str(), 1, &size)) + else if (!parseIntegerKey(node->values["size"], 1, &size)) return parserError("Invalid value for Spacing size."); } @@ -734,7 +734,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (node->values.contains("size")) { int width, height; - if (!parseIntegerKey(node->values["size"].c_str(), 2, &width, &height)) { + if (!parseIntegerKey(node->values["size"], 2, &width, &height)) { Common::StringTokenizer tokenizer(node->values["size"], " ,"); Common::String wtoken, htoken; char *parseEnd; @@ -779,7 +779,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (node->values.contains("pos")) { int x, y; - if (!parseIntegerKey(node->values["pos"].c_str(), 2, &x, &y)) { + if (!parseIntegerKey(node->values["pos"], 2, &x, &y)) { Common::StringTokenizer tokenizer(node->values["pos"], " ,"); Common::String xpos, ypos; char *parseEnd; @@ -835,7 +835,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (node->values.contains("padding")) { int paddingL, paddingR, paddingT, paddingB; - if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB)) + if (!parseIntegerKey(node->values["padding"], 4, &paddingL, &paddingR, &paddingT, &paddingB)) return false; _theme->getEvaluator()->setVar(var + "Padding.Left", paddingL); |