aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction/parser.cpp
diff options
context:
space:
mode:
authorNicola Mettifogo2007-02-19 22:34:00 +0000
committerNicola Mettifogo2007-02-19 22:34:00 +0000
commit07077a2be484ba96c1a10c37ab0c06ce63fd294b (patch)
treebd7cbb864475d6abbba41122883ae687a23fa374 /engines/parallaction/parser.cpp
parent7290d1b18c82511b2e3b9339100e882c3e1fc8b5 (diff)
downloadscummvm-rg350-07077a2be484ba96c1a10c37ab0c06ce63fd294b.tar.gz
scummvm-rg350-07077a2be484ba96c1a10c37ab0c06ce63fd294b.tar.bz2
scummvm-rg350-07077a2be484ba96c1a10c37ab0c06ce63fd294b.zip
first step in parser simplification
svn-id: r25733
Diffstat (limited to 'engines/parallaction/parser.cpp')
-rw-r--r--engines/parallaction/parser.cpp110
1 files changed, 79 insertions, 31 deletions
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp
index 6ff753e68e..3237004450 100644
--- a/engines/parallaction/parser.cpp
+++ b/engines/parallaction/parser.cpp
@@ -22,11 +22,13 @@
#include "parallaction/defs.h"
#include "parallaction/parser.h"
+#include "parallaction/parallaction.h"
#include "parallaction/disk.h"
namespace Parallaction {
char _tokens[20][40];
+/*
static char *_src = NULL;
@@ -54,19 +56,84 @@ char *parseNextLine(char *s, uint16 count) {
return s;
}
+*/
+LocScript::LocScript(const char* s) : _src(s) {
+
+}
+
+char *LocScript::readLine(char *buf, size_t bufSize) {
+
+ uint16 _si;
+ char v2 = 0;
+ for ( _si = 0; _si<bufSize; _si++) {
+
+ v2 = *_src++;
+ if (v2 == 0xA || v2 == -1) break;
+ if (v2 != -1 && _si < bufSize) buf[_si] = v2;
+ }
+
+ if (_si == 0 && v2 == -1)
+ return 0;
+
+ buf[_si] = 0xA;
+ buf[_si+1] = '\0';
+
+ return buf;
+
+}
+
+uint32 LocScript::read(void *dataPtr, uint32 dataSize) {
+ error("binary read not supported on LocScript streams");
+}
+
+bool LocScript::eos() const {
+ error("EoS not supported on LocScript streams");
+}
+
+uint32 LocScript::pos() const {
+ error("position not supported on LocScript streams");
+}
+
+uint32 LocScript::size() const {
+ error("can't get size of LocScript streams");
+}
+
+void LocScript::seek(int32 offset, int whence) {
+ error("seek not supported on LocScript streams");
+}
+
+// looks for next token in a string
+//
+// scans 's' until one of the stop-chars in 'brk' is found
+// builds a token and return the part of the string which hasn't been parsed
+
+char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
+
+ while (*s != '\0') {
+
+ if (brk[0] == *s) break;
+ if (brk[1] == *s) break;
+ if (brk[2] == *s) break;
+
+ *tok++ = *s++;
+ }
+
+ *tok = '\0';
+ return s;
+}
//
// a comment can appear both at location and Zone levels
// comments are displayed into rectangles on the screen
//
-char *parseComment(ArchivedFile *file) {
+char *Parallaction::parseComment(ArchivedFile *file) {
char _tmp_comment[1000] = "\0";
char *v194;
do {
char v190[400];
- v194 = parseNextLine(v190, 400);
+ v194 = _locationScript->readLine(v190, 400);
v194[strlen(v194)-1] = '\0';
if (!scumm_stricmp(v194, "endtext"))
@@ -113,26 +180,29 @@ uint16 fillTokens(char* line) {
return i;
}
-uint16 parseFillBuffers() {
+uint16 fillBuffers(Common::SeekableReadStream &stream, bool errorOnEOF) {
clearTokens();
char buf[200];
char *line = NULL;
do {
- line = parseNextLine(buf, 200);
+ line = stream.readLine(buf, 200);
if (line == NULL) {
- error("unexpected end of file while parsing");
+ if (errorOnEOF)
+ error("unexpected end of file while parsing");
+ else
+ return 0;
}
line = Common::ltrim(line);
} while (strlen(line) == 0 || line[0] == '#');
return fillTokens(line);
}
-
+/*
//
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from a SeekableStream instead of a memory buffer
//
uint16 tableFillBuffers(Common::SeekableReadStream &stream) {
@@ -151,10 +221,10 @@ uint16 tableFillBuffers(Common::SeekableReadStream &stream) {
return fillTokens(line);
}
-
+*/
// FIXME
-// this function does the same Job as parseFillBuffers, except that
+// this function does the same Job as fillBuffers, except that
// it gets input from an ArchivedFile instead of a memory buffer
//
uint16 scriptFillBuffers(ArchivedFile *file) {
@@ -174,26 +244,4 @@ uint16 scriptFillBuffers(ArchivedFile *file) {
return fillTokens(line);
}
-
-// looks for next token in a string
-//
-// scans 's' until one of the stop-chars in 'brk' is found
-// builds a token and return the part of the string which hasn't been parsed
-
-char *parseNextToken(char *s, char *tok, uint16 count, const char *brk) {
-
- while (*s != '\0') {
-
- if (brk[0] == *s) break;
- if (brk[1] == *s) break;
- if (brk[2] == *s) break;
-
- *tok++ = *s++;
- }
-
- *tok = '\0';
- return s;
-}
-
-
} // namespace Parallaction