aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorVicent Marti2008-06-25 11:34:58 +0000
committerVicent Marti2008-06-25 11:34:58 +0000
commitf0e63a49e38d635d70869f6eb1cda42c684fee8b (patch)
treecdeb964d63841a2c59baed3d3e024267b630c734 /common
parent8caa7d3f8b1146fafc6dff6de4f801eb2e8b61ae (diff)
downloadscummvm-rg350-f0e63a49e38d635d70869f6eb1cda42c684fee8b.tar.gz
scummvm-rg350-f0e63a49e38d635d70869f6eb1cda42c684fee8b.tar.bz2
scummvm-rg350-f0e63a49e38d635d70869f6eb1cda42c684fee8b.zip
- Reverted getHostPlatformString() from util.cpp (Yeah, Max was right)
- XMLParser now supports streams! - Added remaining key values for DrawStep parsing. - XMLParser parserError() bugfixes. svn-id: r32782
Diffstat (limited to 'common')
-rw-r--r--common/xmlparser.cpp51
-rw-r--r--common/xmlparser.h42
2 files changed, 63 insertions, 30 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index de10269cdb..4c2c4b58f1 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -36,12 +36,13 @@ using namespace Graphics;
void XMLParser::debug_testEval() {
static const char *debugConfigText =
- "</* 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";
+ "</* lol this is just assa moronic test */drawdata id = \"mainmenu_bg\" cache = true>\n"
+ "<drawstep func = \"roundedsq\" fill = \"none\" color = \"0, 1, 2\" size = \"auto\" />\n"
+ "<drawstep func = \"roundedsqXD\" fill = \"none\" color = \"0, 1, 2\" size = \"auto\"/>\n"
+ "</ drawdata>/* lol this is just a simple test*/\n"
+ "I loled";
- _text = strdup(debugConfigText);
+ _text.fillFromMem(strdup(debugConfigText));
_fileName = strdup("test_parse.xml");
Common::String test = "12, 125, 125";
@@ -50,48 +51,42 @@ void XMLParser::debug_testEval() {
}
-void XMLParser::parserError(const char *error_string, ...) {
+void XMLParser::parserError(const char *errorString, ...) {
_state = kParserError;
int pos = _pos;
- int line_count = 1;
- int line_start = -1;
- int line_width = 1;
+ int lineCount = 1;
+ int lineStart = -1;
do {
if (_text[pos] == '\n' || _text[pos] == '\r') {
- line_count++;
+ lineCount++;
- if (line_start == -1)
- line_start = pos;
+ if (lineStart == -1)
+ lineStart = MAX(pos + 1, _pos - 60);
}
} while (pos-- > 0);
- line_start = MAX(line_start, _pos - 80);
+ char lineStr[70];
+ _text.stream()->seek(lineStart, SEEK_SET);
+ _text.stream()->readLine(lineStr, 70);
- 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, lineCount);
- printf(" File <%s>, line %d:\n", _fileName, line_count);
+ printf("%s%s%s\n",
+ lineStr[0] == '<' ? "" : "...",
+ lineStr[strlen(lineStr) - 1] == '>' ? "" : "...",
+ lineStr);
- printf("%s\n", linestr);
- for (int i = 1; i < _pos - line_start; ++i)
+ for (int i = 0; i < _pos - lineStart + 3; ++i)
printf(" ");
printf("^\n");
printf("Parser error: ");
va_list args;
- va_start(args, error_string);
- vprintf(error_string, args);
+ va_start(args, errorString);
+ vprintf(errorString, args);
va_end(args);
printf("\n");
diff --git a/common/xmlparser.h b/common/xmlparser.h
index c7f7218857..d7d929cb9a 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -30,6 +30,7 @@
#include "graphics/surface.h"
#include "common/system.h"
#include "common/xmlparser.h"
+#include "common/stream.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
@@ -37,6 +38,43 @@
namespace Common {
+class XMLStream {
+protected:
+ SeekableReadStream *_stream;
+ int _pos;
+
+public:
+ XMLStream() : _stream(0), _pos(0) {}
+
+ ~XMLStream() {
+ delete _stream;
+ }
+
+ SeekableReadStream *stream() {
+ return _stream;
+ }
+
+ const char operator [](int idx) {
+ assert(_stream && idx >= 0);
+
+ if (_pos + 1 != idx)
+ _stream->seek(idx, SEEK_SET);
+
+ _pos = idx;
+
+ return _stream->readSByte();
+ }
+
+ void fillFromMem(const char *buffer, bool dispose = false) {
+ delete _stream;
+ _stream = new MemoryReadStream((const byte*)buffer, strlen(buffer), dispose);
+ }
+
+ void fillFromFile(const char *filename) {
+
+ }
+};
+
/**
* The base XMLParser class implements generic functionality for parsing
* XML-like files.
@@ -132,7 +170,7 @@ protected:
/**
* Prints an error message when parsing fails and stops the parser.
*/
- virtual void parserError(const char *errorString, ...);
+ virtual void parserError(const char *errorString, ...) GCC_PRINTF(1, 2);
/**
* Skips spaces/whitelines etc. Returns true if any spaces were skipped.
@@ -199,7 +237,7 @@ protected:
}
int _pos; /** Current position on the XML buffer. */
- char *_text; /** Buffer with the text being parsed */
+ XMLStream _text; /** Buffer with the text being parsed */
char *_fileName;
ParserState _state; /** Internal state of the parser */