diff options
author | Vicent Marti | 2008-06-25 14:19:56 +0000 |
---|---|---|
committer | Vicent Marti | 2008-06-25 14:19:56 +0000 |
commit | 2fcbb970056c9b596699f22d949fe17f9df791d3 (patch) | |
tree | 0e043bd4fa51b85fbade50d3225350c8946c8d69 /common | |
parent | f0e63a49e38d635d70869f6eb1cda42c684fee8b (diff) | |
download | scummvm-rg350-2fcbb970056c9b596699f22d949fe17f9df791d3.tar.gz scummvm-rg350-2fcbb970056c9b596699f22d949fe17f9df791d3.tar.bz2 scummvm-rg350-2fcbb970056c9b596699f22d949fe17f9df791d3.zip |
XMLParser:
- Cleanup.
- Support for file/buffer loading.
ThemeParser:
- Triangle orientation.
svn-id: r32784
Diffstat (limited to 'common')
-rw-r--r-- | common/xmlparser.cpp | 17 | ||||
-rw-r--r-- | common/xmlparser.h | 33 |
2 files changed, 32 insertions, 18 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 4c2c4b58f1..bb8754d480 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -42,16 +42,14 @@ void XMLParser::debug_testEval() { "</ drawdata>/* lol this is just a simple test*/\n" "I loled"; - _text.fillFromMem(strdup(debugConfigText)); + loadBuffer(debugConfigText); _fileName = strdup("test_parse.xml"); - Common::String test = "12, 125, 125"; - parse(); } -void XMLParser::parserError(const char *errorString, ...) { +bool XMLParser::parserError(const char *errorString, ...) { _state = kParserError; int pos = _pos; @@ -90,6 +88,8 @@ void XMLParser::parserError(const char *errorString, ...) { va_end(args); printf("\n"); + + return false; } bool XMLParser::parseActiveKey(bool closed) { @@ -248,14 +248,11 @@ bool XMLParser::parse() { } } - if (_state == kParserError) { + if (_state == kParserError) return false; - } - if (_state != kParserNeedKey || !_activeKey.empty()) { - parserError("Unexpected end of file."); - return false; - } + if (_state != kParserNeedKey || !_activeKey.empty()) + return parserError("Unexpected end of file."); return true; } diff --git a/common/xmlparser.h b/common/xmlparser.h index d7d929cb9a..5b03f54b9d 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -31,6 +31,7 @@ #include "common/system.h" #include "common/xmlparser.h" #include "common/stream.h" +#include "common/file.h" #include "common/hashmap.h" #include "common/hash-str.h" @@ -65,13 +66,9 @@ public: return _stream->readSByte(); } - void fillFromMem(const char *buffer, bool dispose = false) { + void loadStream(SeekableReadStream *stream) { delete _stream; - _stream = new MemoryReadStream((const byte*)buffer, strlen(buffer), dispose); - } - - void fillFromFile(const char *filename) { - + _stream = stream; } }; @@ -94,7 +91,10 @@ public: */ XMLParser() {} - virtual ~XMLParser() {} + virtual ~XMLParser() { + while (!_activeKey.empty()) + delete _activeKey.pop(); + } /** Active state for the parser */ enum ParserState { @@ -115,6 +115,21 @@ public: bool ignore; }; + virtual bool loadFile(const char *filename) { + Common::File *f = new Common::File; + + if (!f->open(filename, Common::File::kFileReadMode)) + return false; + + _text.loadStream(f); + return true; + } + + virtual bool loadBuffer(const char *buffer, bool disposable = false) { + _text.loadStream(new MemoryReadStream((const byte*)buffer, strlen(buffer), disposable)); + return true; + } + virtual bool parse(); void debug_testEval(); @@ -169,8 +184,10 @@ protected: /** * Prints an error message when parsing fails and stops the parser. + * Parser error always returns "false" so we can pass the return value directly + * and break down the parsing. */ - virtual void parserError(const char *errorString, ...) GCC_PRINTF(1, 2); + virtual bool parserError(const char *errorString, ...) GCC_PRINTF(1, 2); /** * Skips spaces/whitelines etc. Returns true if any spaces were skipped. |