From a6e5b97e9fe20745bddd73e34e9deba57dbda216 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 6 Jun 2011 00:28:18 +0200 Subject: COMMON: Remove vfprintf call from XML parser --- common/xmlparser.cpp | 22 +++++++--------------- common/xmlparser.h | 2 +- engines/sword25/gfx/animationresource.cpp | 14 +++++++------- engines/sword25/gfx/fontresource.cpp | 12 ++++++------ gui/ThemeParser.cpp | 28 ++++++++++++++-------------- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 9bd052fb3d..ea36f0bb4a 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -23,9 +23,6 @@ // FIXME: Avoid using fprintf #define FORBIDDEN_SYMBOL_EXCEPTION_fprintf -// FIXME: Avoid using vfprintf -#define FORBIDDEN_SYMBOL_EXCEPTION_vfprintf - #include "common/xmlparser.h" #include "common/archive.h" @@ -83,7 +80,7 @@ void XMLParser::close() { _stream = 0; } -bool XMLParser::parserError(const char *errorString, ...) { +bool XMLParser::parserError(const Common::String &errStr) { _state = kParserError; const int startPosition = _stream->pos(); @@ -134,12 +131,7 @@ bool XMLParser::parserError(const char *errorString, ...) { fprintf(stderr, "%c", _stream->readByte()); fprintf(stderr, "\n\nParser error: "); - - va_list args; - va_start(args, errorString); - vfprintf(stderr, errorString, args); - va_end(args); - + fprintf(stderr, "%s", errStr.c_str()); fprintf(stderr, "\n\n"); return false; @@ -181,16 +173,16 @@ bool XMLParser::parseActiveKey(bool closed) { for (List::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) { if (i->required && !localMap.contains(i->name)) - return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str()); + return parserError("Missing required property '" + i->name + "' inside key '" + key->name + "'"); else if (localMap.contains(i->name)) keyCount--; } if (keyCount > 0) - return parserError("Unhandled property inside key '%s'.", key->name.c_str()); + return parserError("Unhandled property inside key '" + key->name + "'."); } else { - return parserError("Unexpected key in the active scope ('%s').", key->name.c_str()); + return parserError("Unexpected key in the active scope ('" + key->name + "')."); } // check if any of the parents must be ignored. @@ -205,7 +197,7 @@ bool XMLParser::parseActiveKey(bool closed) { // when keyCallback() fails, a parserError() must be set. // We set it manually in that case. if (_state != kParserError) - parserError("Unhandled exception when parsing '%s' key.", key->name.c_str()); + parserError("Unhandled exception when parsing '" + key->name + "' key."); return false; } @@ -395,7 +387,7 @@ bool XMLParser::parse() { case kParserNeedPropertyName: if (activeClosure) { if (!closeKey()) { - parserError("Missing data when closing key '%s'.", _activeKey.top()->name.c_str()); + parserError("Missing data when closing key '" + _activeKey.top()->name + "'."); break; } diff --git a/common/xmlparser.h b/common/xmlparser.h index 84fca294a0..7923e43a37 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -274,7 +274,7 @@ protected: * Parser error always returns "false" so we can pass the return value * directly and break down the parsing. */ - bool parserError(const char *errorString, ...) GCC_PRINTF(2, 3); + bool parserError(const Common::String &errStr); /** * Skips spaces/whitelines etc. diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp index a9c9cf9c29..b9d70cf87b 100644 --- a/engines/sword25/gfx/animationresource.cpp +++ b/engines/sword25/gfx/animationresource.cpp @@ -38,11 +38,11 @@ namespace Sword25 { -namespace { -const int DEFAULT_FPS = 10; -const int MIN_FPS = 1; -const int MAX_FPS = 200; -} +enum { + DEFAULT_FPS = 10, + MIN_FPS = 1, + MAX_FPS = 200 +}; AnimationResource::AnimationResource(const Common::String &filename) : Resource(filename, Resource::TYPE_ANIMATION), @@ -112,8 +112,8 @@ bool AnimationResource::parseBooleanKey(Common::String s, bool &result) { bool AnimationResource::parserCallback_animation(ParserNode *node) { if (!parseIntegerKey(node->values["fps"], 1, &_FPS) || (_FPS < MIN_FPS) || (_FPS > MAX_FPS)) { - return parserError("Illegal or missing fps attribute in tag in \"%s\". Assuming default (\"%d\").", - getFileName().c_str(), DEFAULT_FPS); + return parserError(Common::String::format("Illegal or missing fps attribute in tag in \"%s\". Assuming default (\"%d\").", + getFileName().c_str(), DEFAULT_FPS)); } // Loop type value diff --git a/engines/sword25/gfx/fontresource.cpp b/engines/sword25/gfx/fontresource.cpp index f99987fc91..7657abb5f2 100644 --- a/engines/sword25/gfx/fontresource.cpp +++ b/engines/sword25/gfx/fontresource.cpp @@ -115,23 +115,23 @@ bool FontResource::parserCallback_character(ParserNode *node) { int charCode, top, left, right, bottom; if (!parseIntegerKey(node->values["code"], 1, &charCode) || (charCode < 0) || (charCode >= 256)) { - return parserError("Illegal or missing code attribute in tag in \"%s\".", getFileName().c_str()); + return parserError("Illegal or missing code attribute in tag in '" + getFileName() + "'."); } if (!parseIntegerKey(node->values["top"], 1, &top) || (top < 0)) { - return parserError("Illegal or missing top attribute in tag in \"%s\".", getFileName().c_str()); + return parserError("Illegal or missing top attribute in tag in '" + getFileName() + "'."); } if (!parseIntegerKey(node->values["left"], 1, &left) || (left < 0)) { - return parserError("Illegal or missing left attribute in tag in \"%s\".", getFileName().c_str()); + return parserError("Illegal or missing left attribute in tag in '" + getFileName() + "'."); } if (!parseIntegerKey(node->values["right"], 1, &right) || (right < 0)) { - return parserError("Illegal or missing right attribute in tag in \"%s\".", getFileName().c_str()); + return parserError("Illegal or missing right attribute in tag in '" + getFileName() + "'."); } if (!parseIntegerKey(node->values["bottom"], 1, &bottom) || (bottom < 0)) { - return parserError("Illegal or missing bottom attribute in tag in \"%s\".", getFileName().c_str()); + return parserError("Illegal or missing bottom attribute in tag in '" + getFileName() + "'."); } - this->_characterRects[charCode] = Common::Rect(left, top, right, bottom); + _characterRects[charCode] = Common::Rect(left, top, right, bottom); return true; } diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 56ee6df5cc..5b1faa4075 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -232,7 +232,7 @@ bool ThemeParser::parserCallback_bitmap(ParserNode *node) { } if (!_theme->addBitmap(node->values["filename"])) - return parserError("Error loading Bitmap file '%s'", node->values["filename"].c_str()); + return parserError("Error loading Bitmap file '" + node->values["filename"] + "'"); return true; } @@ -252,7 +252,7 @@ bool ThemeParser::parserCallback_text(ParserNode *node) { TextColor textColorId = parseTextColorId(node->values["text_color"]); if (!_theme->addTextData(id, textDataId, textColorId, alignH, alignV)) - return parserError("Error adding Text Data for '%s'.", id.c_str()); + return parserError("Error adding Text Data for '" + id + "'."); return true; } @@ -279,13 +279,13 @@ bool ThemeParser::parserCallback_color(ParserNode *node) { Common::String name = node->values["name"]; if (_palette.contains(name)) - return parserError("Color '%s' has already been defined.", name.c_str()); + return parserError("Color '" + name + "' has already been defined."); int red, green, blue; 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());\ + return parserError("Error parsing RGB values for palette color '" + name + "'"); _palette[name].r = red; _palette[name].g = green; @@ -332,7 +332,7 @@ bool ThemeParser::parserCallback_drawstep(ParserNode *node) { drawstep->drawingCall = getDrawingFunctionCallback(functionName); if (drawstep->drawingCall == 0) - return parserError("%s is not a valid drawing function name", functionName.c_str()); + return parserError(functionName + " is not a valid drawing function name"); if (!parseDrawStep(node, drawstep, true)) return false; @@ -385,11 +385,11 @@ 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], 1, &x)) \ - return parserError("Error parsing key value for '%s'.", key_name); \ + return parserError("Error parsing key value for '" + Common::String(key_name) + "'."); \ \ drawstep->struct_name = x; \ } else if (force) { \ - return parserError("Missing necessary key '%s'.", key_name); \ + return parserError("Missing necessary key '" + Common::String(key_name) + "'."); \ } /** @@ -410,7 +410,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst blue = _palette[val].b; \ } 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());\ + return parserError("Error parsing color struct '" + val + "'");\ \ drawstep->struct_name.r = red; \ drawstep->struct_name.g = green; \ @@ -466,7 +466,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst else if (val == "right") drawstep->extraData = Graphics::VectorRenderer::kTriangleRight; else - return parserError("'%s' is not a valid value for triangle orientation.", val.c_str()); + return parserError("'" + val + "' is not a valid value for triangle orientation."); } } @@ -545,7 +545,7 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst else if (val == "gradient") drawstep->fillMode = Graphics::VectorRenderer::kFillGradient; else - return parserError("'%s' is not a valid fill mode for a shape.", stepNode->values["fill"].c_str()); + return parserError("'" + stepNode->values["fill"] + "' is not a valid fill mode for a shape."); } #undef __PARSER_ASSIGN_INT @@ -567,7 +567,7 @@ bool ThemeParser::parserCallback_def(ParserNode *node) { value = _theme->getEvaluator()->getVar(node->values["value"]); else if (!parseIntegerKey(node->values["value"], 1, &value)) - return parserError("Invalid definition for '%s'.", var.c_str()); + return parserError("Invalid definition for '" + var + "'."); _theme->getEvaluator()->setVar(var, value); return true; @@ -585,7 +585,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { var = "Globals." + node->values["name"] + "."; if (!parseCommonLayoutProps(node, var)) - return parserError("Error parsing Layout properties of '%s'.", var.c_str()); + return parserError("Error parsing Layout properties of '" + var + "'."); } else { // FIXME: Shouldn't we distinguish the name/id and the label of a widget? @@ -606,7 +606,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { width = _theme->getEvaluator()->getVar(node->values["width"]); else if (!parseIntegerKey(node->values["width"], 1, &width)) - return parserError("Corrupted width value in key for %s", var.c_str()); + return parserError("Corrupted width value in key for " + var); } if (node->values.contains("height")) { @@ -614,7 +614,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { height = _theme->getEvaluator()->getVar(node->values["height"]); else if (!parseIntegerKey(node->values["height"], 1, &height)) - return parserError("Corrupted height value in key for %s", var.c_str()); + return parserError("Corrupted height value in key for " + var); } Graphics::TextAlign alignH = Graphics::kTextAlignLeft; -- cgit v1.2.3