diff options
author | Nicola Mettifogo | 2007-03-04 15:00:50 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-03-04 15:00:50 +0000 |
commit | 1eb2d6f6253c578735da81a6e7671ae7773d05e0 (patch) | |
tree | 03a158de2b1452dbf91d4e3e2e3bdc11a306cd7a /engines | |
parent | b440bc1a0357503c6edec22ea1182613040de41c (diff) | |
download | scummvm-rg350-1eb2d6f6253c578735da81a6e7671ae7773d05e0.tar.gz scummvm-rg350-1eb2d6f6253c578735da81a6e7671ae7773d05e0.tar.bz2 scummvm-rg350-1eb2d6f6253c578735da81a6e7671ae7773d05e0.zip |
made Script optionally take ownership and dispose input text
svn-id: r25973
Diffstat (limited to 'engines')
-rw-r--r-- | engines/parallaction/parser.cpp | 9 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 7 |
2 files changed, 12 insertions, 4 deletions
diff --git a/engines/parallaction/parser.cpp b/engines/parallaction/parser.cpp index c41452481a..ee420b2e5f 100644 --- a/engines/parallaction/parser.cpp +++ b/engines/parallaction/parser.cpp @@ -29,8 +29,13 @@ namespace Parallaction { char _tokens[20][40]; -Script::Script(const char* s) : _src(s) { +Script::Script(const char* s, bool disposeSource) : _src(s), _disposeSource(disposeSource) { + _pos = const_cast<char*>(_src); +} +Script::~Script() { + if (_disposeSource) + free(const_cast<char*>(_src)); } char *Script::readLine(char *buf, size_t bufSize) { @@ -39,7 +44,7 @@ char *Script::readLine(char *buf, size_t bufSize) { char v2 = 0; for ( _si = 0; _si<bufSize; _si++) { - v2 = *_src++; + v2 = *_pos++; if (v2 == 0xA || v2 == -1) break; if (v2 != -1 && _si < bufSize) buf[_si] = v2; } diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index c0d8613d3c..fa633676e0 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -37,10 +37,13 @@ extern char _tokens[][40]; class Script : public Common::SeekableReadStream { - const char* _src; + const char* const _src; + bool _disposeSource; + char* _pos; public: - Script(const char* s); + Script(const char* s, bool _disposeSource = false); + ~Script(); uint32 read(void *dataPtr, uint32 dataSize); |