diff options
| author | Vicent Marti | 2008-06-24 19:48:01 +0000 |
|---|---|---|
| committer | Vicent Marti | 2008-06-24 19:48:01 +0000 |
| commit | 8caa7d3f8b1146fafc6dff6de4f801eb2e8b61ae (patch) | |
| tree | 896c10a542fd3c4169ac8c0d218552f84834a02b /common | |
| parent | a4b4534a66bb6f24a66a27e28f7df0d390e1eea8 (diff) | |
| download | scummvm-rg350-8caa7d3f8b1146fafc6dff6de4f801eb2e8b61ae.tar.gz scummvm-rg350-8caa7d3f8b1146fafc6dff6de4f801eb2e8b61ae.tar.bz2 scummvm-rg350-8caa7d3f8b1146fafc6dff6de4f801eb2e8b61ae.zip | |
Common:
- Added function to get the active host type as a string.
XMLParser:
- Added support for ignoring keys while parsing (check documentation). Backwards compatible.
- parserError() has been revamped. Shows all kinds of detailed information regarding the error ala Python
InterfaceManager/ThemeParser:
- DrawData keys and their DrawStep subkeys are now successfully parsed and loaded into structs. That's a win.
- Bug fixes.
svn-id: r32768
Diffstat (limited to 'common')
| -rw-r--r-- | common/util.cpp | 29 | ||||
| -rw-r--r-- | common/util.h | 7 | ||||
| -rw-r--r-- | common/xmlparser.cpp | 85 | ||||
| -rw-r--r-- | common/xmlparser.h | 17 |
4 files changed, 117 insertions, 21 deletions
diff --git a/common/util.cpp b/common/util.cpp index 6f0fdcb233..51bd8bcad6 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -481,6 +481,34 @@ uint32 getEnabledSpecialDebugLevels() { return gDebugLevelsEnabled; } +const char *getHostPlatformString() { + +#if defined(__SYMBIAN32__) + return "symbian"; +#elif defined(_WIN32_WCE) || defined(_MSC_VER) || defined(__MINGW32__) || defined(UNIX) + return "pc"; +#elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__) + return "palmos"; +#elif defined(__DC__) + return "dc"; +#elif defined(__GP32__) + return "gp32"; +#elif defined(__PLAYSTATION2__) + return "ps2"; +#elif defined(__PSP__) + return "psp"; +#elif defined(__amigaos4__) + return "amigaos"; +#elif defined (__DS__) //NeilM + return "nds"; +#elif defined(__WII__) + return "wii"; +#else + return ""; +#endif + +} + } // End of namespace Common @@ -694,3 +722,4 @@ Common::String tag2string(uint32 tag) { str[4] = '\0'; return Common::String(str); } + diff --git a/common/util.h b/common/util.h index c23513596c..c4cbf35212 100644 --- a/common/util.h +++ b/common/util.h @@ -323,6 +323,13 @@ const DebugLevelContainer &listSpecialDebugLevels(); uint32 getEnabledSpecialDebugLevels(); +/** + * Return a string containing the name of the currently running host. + * E.g. returns "wii" if ScummVM is being run in a Wii, and so on. + */ +const char *getHostPlatformString(); + + } // End of namespace Common diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 7728d90d48..de10269cdb 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -36,35 +36,86 @@ using namespace Graphics; void XMLParser::debug_testEval() { static const char *debugConfigText = - "</* lol this is just a moronic test */drawdata id = \"background_default\" cache = true>\n" - "<drawstep func = \"roundedsq\" fill = \"gradient\" gradient_start = \"255, 255, 128\" gradient_end = \"128, 128, 128\" size = \"auto\"/>\n" + "</* lol this is just a moronic test */drawdata id = \"mainmenu_bg\" cache = true>\n" + "<drawstep| func = \"roundedsq\" fill = \"gradient\" gradient_start = \"255, 255, 128\" gradient_end = \"128, 128, 128\" size = \"auto\"/>\n" "//<drawstep func = \"roundedsq\" fill = \"none\" color = /*\"0, 0, 0\"*/\"0, 1, 2\" size = \"auto\"/>\n" "</ drawdata>/* lol this is just a simple test*/\n"; _text = strdup(debugConfigText); + _fileName = strdup("test_parse.xml"); Common::String test = "12, 125, 125"; - printf("\n\nRegex result: %s.\n\n", test.regexMatch("^[d]*,[d]*,[d]*$", true) ? "Success." : "Fail"); - parse(); } -void XMLParser::parserError(const char *error_string) { +void XMLParser::parserError(const char *error_string, ...) { _state = kParserError; - printf("PARSER ERROR: %s\n", error_string); + + int pos = _pos; + int line_count = 1; + int line_start = -1; + int line_width = 1; + + do { + if (_text[pos] == '\n' || _text[pos] == '\r') { + line_count++; + + if (line_start == -1) + line_start = pos; + } + } while (pos-- > 0); + + line_start = MAX(line_start, _pos - 80); + + do { + if (_text[line_start + line_width] == '\n' || _text[line_start + line_width] == '\r') + break; + } while (_text[line_start + line_width++]); + + line_width = MIN(line_width, 80); + + char linestr[81]; + strncpy(linestr, &_text[line_start] + 1, line_width ); + linestr[line_width - 1] = 0; + + printf(" File <%s>, line %d:\n", _fileName, line_count); + + printf("%s\n", linestr); + for (int i = 1; i < _pos - line_start; ++i) + printf(" "); + + printf("^\n"); + printf("Parser error: "); + + va_list args; + va_start(args, error_string); + vprintf(error_string, args); + va_end(args); + + printf("\n"); } -void XMLParser::parseActiveKey(bool closed) { - if (keyCallback(_activeKey.top()->name) == false) { - parserError("Unhandled value inside key."); - return; +bool XMLParser::parseActiveKey(bool closed) { + bool ignore = false; + + // check if any of the parents must be ignored. + // if a parent is ignored, all children are too. + for (int i = _activeKey.size() - 1; i >= 0; --i) { + if (_activeKey[i]->ignore) + ignore = true; + } + + if (ignore == false && keyCallback(_activeKey.top()->name) == false) { + return false; } if (closed) { delete _activeKey.pop(); } + + return true; } bool XMLParser::parseKeyValue(Common::String keyName) { @@ -115,7 +166,7 @@ bool XMLParser::parse() { switch (_state) { case kParserNeedKey: if (_text[_pos++] != '<') { - parserError("Expecting key start."); + parserError("Parser expecting key start."); break; } @@ -144,6 +195,7 @@ bool XMLParser::parse() { } else { ParserNode *node = new ParserNode; node->name = _token; + node->ignore = false; _activeKey.push(node); } @@ -166,9 +218,10 @@ bool XMLParser::parse() { selfClosure = (_text[_pos] == '/'); if ((selfClosure && _text[_pos + 1] == '>') || _text[_pos] == '>') { - parseActiveKey(selfClosure); - _pos += selfClosure ? 2 : 1; - _state = kParserNeedKey; + if (parseActiveKey(selfClosure)) { + _pos += selfClosure ? 2 : 1; + _state = kParserNeedKey; + } break; } @@ -181,7 +234,7 @@ bool XMLParser::parse() { case kParserNeedPropertyOperator: if (_text[_pos++] != '=') - parserError("Unexpected character after key name."); + parserError("Syntax error after key name."); else _state = kParserNeedPropertyValue; @@ -189,7 +242,7 @@ bool XMLParser::parse() { case kParserNeedPropertyValue: if (!parseKeyValue(_token)) - parserError("Unable to parse key value."); + parserError("Invalid key value."); else _state = kParserNeedPropertyName; diff --git a/common/xmlparser.h b/common/xmlparser.h index 3edc2b31e1..c7f7218857 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -74,6 +74,7 @@ public: struct ParserNode { Common::String name; Common::StringMap values; + bool ignore; }; virtual bool parse(); @@ -103,7 +104,13 @@ protected: * Remember to leave the node stack _UNCHANGED_ in your own function. Removal * of closed keys is done automatically. * - * Return true if the key was properly handled. False otherwise. + * When parsing a key, one may chose to skip it, e.g. because it's not needed + * on the current configuration. In order to ignore a key, you must set + * the "ignore" field of its KeyNode struct to "true": The key and all its children + * will then be automatically ignored by the parser. + * + * Return true if the key was properly handled (this includes the case when the + * key is being ignored). False otherwise. * See the sample implementation in GUI::ThemeParser. */ virtual bool keyCallback(Common::String keyName) { @@ -120,13 +127,12 @@ protected: * node stack and calls the keyCallback. * There's no reason to overload this. */ - virtual void parseActiveKey(bool closed); + virtual bool parseActiveKey(bool closed); /** * Prints an error message when parsing fails and stops the parser. - * TODO: More descriptive error messages. */ - virtual void parserError(const char *errorString); + virtual void parserError(const char *errorString, ...); /** * Skips spaces/whitelines etc. Returns true if any spaces were skipped. @@ -163,7 +169,7 @@ protected: if (_text[_pos] == '/' && _text[_pos + 1] == '/') { _pos += 2; - while (_text[_pos] && _text[_pos] != '\n') + while (_text[_pos] && _text[_pos] != '\n' && _text[_pos] != '\r') _pos++; return true; } @@ -194,6 +200,7 @@ protected: int _pos; /** Current position on the XML buffer. */ char *_text; /** Buffer with the text being parsed */ + char *_fileName; ParserState _state; /** Internal state of the parser */ |
