diff options
author | Nicola Mettifogo | 2008-12-13 03:37:43 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2008-12-13 03:37:43 +0000 |
commit | b3475d81787b08178c7ea413717796d987f9061c (patch) | |
tree | 41569a0662636f68ab4390ace32e7b16c9a4a5b8 | |
parent | 6724097f674c100c20a42a030bb597aa080ad339 (diff) | |
download | scummvm-rg350-b3475d81787b08178c7ea413717796d987f9061c.tar.gz scummvm-rg350-b3475d81787b08178c7ea413717796d987f9061c.tar.bz2 scummvm-rg350-b3475d81787b08178c7ea413717796d987f9061c.zip |
* Replaced char* with Common::String in the parser.
* Enforced const-correctness on related routines.
svn-id: r35326
-rw-r--r-- | engines/parallaction/balloons.cpp | 32 | ||||
-rw-r--r-- | engines/parallaction/dialogue.cpp | 20 | ||||
-rw-r--r-- | engines/parallaction/graphics.h | 12 | ||||
-rw-r--r-- | engines/parallaction/objects.cpp | 15 | ||||
-rw-r--r-- | engines/parallaction/objects.h | 15 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 22 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 6 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 12 | ||||
-rw-r--r-- | engines/parallaction/parser_ns.cpp | 43 |
9 files changed, 79 insertions, 98 deletions
diff --git a/engines/parallaction/balloons.cpp b/engines/parallaction/balloons.cpp index 70c3d5789e..60dd371b6f 100644 --- a/engines/parallaction/balloons.cpp +++ b/engines/parallaction/balloons.cpp @@ -267,10 +267,10 @@ public: ~BalloonManager_ns(); void freeBalloons(); - int setLocationBalloon(char *text, bool endGame); - int setDialogueBalloon(char *text, uint16 winding, TextColor textColor); - int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor); - void setBalloonText(uint id, char *text, TextColor textColor); + int setLocationBalloon(const char *text, bool endGame); + int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor); + int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor); + void setBalloonText(uint id, const char *text, TextColor textColor); int hitTestDialogueBalloon(int x, int y); }; @@ -327,7 +327,7 @@ int BalloonManager_ns::createBalloon(int16 w, int16 h, int16 winding, uint16 bor } -int BalloonManager_ns::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) { +int BalloonManager_ns::setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) { int16 w, h; @@ -351,7 +351,7 @@ int BalloonManager_ns::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 w return id; } -int BalloonManager_ns::setDialogueBalloon(char *text, uint16 winding, TextColor textColor) { +int BalloonManager_ns::setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) { int16 w, h; @@ -381,7 +381,7 @@ int BalloonManager_ns::setDialogueBalloon(char *text, uint16 winding, TextColor return id; } -void BalloonManager_ns::setBalloonText(uint id, char *text, TextColor textColor) { +void BalloonManager_ns::setBalloonText(uint id, const char *text, TextColor textColor) { Balloon *balloon = getBalloon(id); balloon->surface->fillRect(balloon->innerBox, 1); @@ -390,7 +390,7 @@ void BalloonManager_ns::setBalloonText(uint id, char *text, TextColor textColor) } -int BalloonManager_ns::setLocationBalloon(char *text, bool endGame) { +int BalloonManager_ns::setLocationBalloon(const char *text, bool endGame) { int16 w, h; @@ -565,10 +565,10 @@ public: ~BalloonManager_br(); void freeBalloons(); - int setLocationBalloon(char *text, bool endGame); - int setDialogueBalloon(char *text, uint16 winding, TextColor textColor); - int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor); - void setBalloonText(uint id, char *text, TextColor textColor); + int setLocationBalloon(const char *text, bool endGame); + int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor); + int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor); + void setBalloonText(uint id, const char *text, TextColor textColor); int hitTestDialogueBalloon(int x, int y); }; @@ -594,7 +594,7 @@ Graphics::Surface *BalloonManager_br::expandBalloon(Frames *data, int frameNum) return surf; } -int BalloonManager_br::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) { +int BalloonManager_br::setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) { cacheAnims(); int id = _numBalloons; @@ -630,7 +630,7 @@ int BalloonManager_br::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 w return id; } -int BalloonManager_br::setDialogueBalloon(char *text, uint16 winding, TextColor textColor) { +int BalloonManager_br::setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) { cacheAnims(); int id = _numBalloons; @@ -666,7 +666,7 @@ int BalloonManager_br::setDialogueBalloon(char *text, uint16 winding, TextColor return id; } -void BalloonManager_br::setBalloonText(uint id, char *text, TextColor textColor) { +void BalloonManager_br::setBalloonText(uint id, const char *text, TextColor textColor) { Balloon *balloon = getBalloon(id); StringWriter_BR sw(_vm->_dialogueFont); @@ -692,7 +692,7 @@ int BalloonManager_br::createBalloon(int16 w, int16 h, uint16 borderThickness) { return id; } -int BalloonManager_br::setLocationBalloon(char *text, bool endGame) { +int BalloonManager_br::setLocationBalloon(const char *text, bool endGame) { StringExtent_BR se(_vm->_dialogueFont); se.calc(text, 240); diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index a2de3cbbf3..23272d7b0f 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -173,11 +173,11 @@ bool DialogueManager::displayAnswer(uint16 i) { // display suitable answers if (((a->_yesFlags & flags) == a->_yesFlags) && ((a->_noFlags & ~flags) == a->_noFlags)) { - int id = _vm->_balloonMan->setDialogueBalloon(a->_text, 1, BalloonManager::kUnselectedColor); + int id = _vm->_balloonMan->setDialogueBalloon(a->_text.c_str(), 1, BalloonManager::kUnselectedColor); assert(id >= 0); _visAnswers[id] = i; - _askPassword = (strstr(a->_text, "%P") != NULL); + _askPassword = a->_text.contains("%P"); _numVisAnswers++; return true; @@ -203,7 +203,7 @@ bool DialogueManager::displayAnswers() { if (_numVisAnswers == 1) { int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); _vm->_gfx->setItemFrame(id, _q->_answers[0]->_mood & 0xF); - _vm->_balloonMan->setBalloonText(0, _q->_answers[_visAnswers[0]]->_text, BalloonManager::kNormalColor); + _vm->_balloonMan->setBalloonText(0, _q->_answers[_visAnswers[0]]->_text.c_str(), BalloonManager::kNormalColor); } else if (_numVisAnswers > 1) { int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y); @@ -216,9 +216,9 @@ bool DialogueManager::displayAnswers() { } bool DialogueManager::displayQuestion() { - if (!scumm_stricmp(_q->_text, "NULL")) return false; + if (!_q->_text.compareToIgnoreCase("NULL")) return false; - _vm->_balloonMan->setSingleBalloon(_q->_text, _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor); + _vm->_balloonMan->setSingleBalloon(_q->_text.c_str(), _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor); int id = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y); _vm->_gfx->setItemFrame(id, _q->_mood & 0xF); @@ -256,7 +256,7 @@ int16 DialogueManager::askPassword() { } if (_passwordChanged) { - _vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text, BalloonManager::kNormalColor); + _vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text.c_str(), BalloonManager::kNormalColor); _passwordChanged = false; } @@ -286,11 +286,11 @@ int16 DialogueManager::selectAnswerN() { if (_selection != _oldSelection) { if (_oldSelection != -1) { - _vm->_balloonMan->setBalloonText(_oldSelection, _q->_answers[_visAnswers[_oldSelection]]->_text, BalloonManager::kUnselectedColor); + _vm->_balloonMan->setBalloonText(_oldSelection, _q->_answers[_visAnswers[_oldSelection]]->_text.c_str(), BalloonManager::kUnselectedColor); } if (_selection != -1) { - _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text, BalloonManager::kSelectedColor); + _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text.c_str(), BalloonManager::kSelectedColor); _vm->_gfx->setItemFrame(0, _q->_answers[_visAnswers[_selection]]->_mood & 0xF); } } @@ -323,7 +323,7 @@ void DialogueManager::nextAnswer() { return; } - if (!scumm_stricmp(_q->_answers[0]->_text, "NULL")) { + if (!_q->_answers[0]->_text.compareToIgnoreCase("NULL")) { _answerId = 0; _state = NEXT_QUESTION; return; @@ -354,7 +354,7 @@ void DialogueManager::runAnswer() { void DialogueManager::nextQuestion() { debugC(9, kDebugDialogue, "nextQuestion\n"); - _q = _q->_answers[_answerId]->_following._question; + _q = _q->_answers[_answerId]->_followingQuestion; if (_q == 0) { _state = DIALOGUE_OVER; } else { diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index 1c540e914e..e9a7ce2877 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -141,6 +141,8 @@ public: } void create(uint16 width, uint16 height) { + free(); + w = width; internalWidth = w >> 2; h = height; @@ -221,6 +223,8 @@ public: } void create(uint16 width, uint16 height) { + free(); + w = width; internalWidth = w >> 3; h = height; @@ -467,10 +471,10 @@ public: virtual ~BalloonManager() { } virtual void freeBalloons() = 0; - virtual int setLocationBalloon(char *text, bool endGame) = 0; - virtual int setDialogueBalloon(char *text, uint16 winding, TextColor textColor) = 0; - virtual int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) = 0; - virtual void setBalloonText(uint id, char *text, TextColor textColor) = 0; + virtual int setLocationBalloon(const char *text, bool endGame) = 0; + virtual int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) = 0; + virtual int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) = 0; + virtual void setBalloonText(uint id, const char *text, TextColor textColor) = 0; virtual int hitTestDialogueBalloon(int x, int y) = 0; }; diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp index a75620e26e..59e2fb0868 100644 --- a/engines/parallaction/objects.cpp +++ b/engines/parallaction/objects.cpp @@ -173,7 +173,7 @@ Zone::~Zone() { switch (_type & 0xFFFF) { case kZoneExamine: free(u.examine->_filename); - free(u.examine->_description); + u.examine->_description.clear(); delete u.examine->_cnv; delete u.examine; break; @@ -201,7 +201,7 @@ Zone::~Zone() { case kZoneMerge: delete u.merge; break; - + case kZonePath: delete u.path; break; @@ -240,19 +240,13 @@ Dialogue::~Dialogue() { } Answer::Answer() { - _text = NULL; _mood = 0; - _following._question = NULL; + _followingQuestion = NULL; _noFlags = 0; _yesFlags = 0; } -Answer::~Answer() { - free(_text); -} - Question::Question() { - _text = NULL; _mood = 0; for (uint32 i = 0; i < NUM_ANSWERS; i++) @@ -261,12 +255,9 @@ Question::Question() { } Question::~Question() { - for (uint32 i = 0; i < NUM_ANSWERS; i++) { delete _answers[i]; } - - free(_text); } Instruction::Instruction() { diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h index eee69383b6..1ed52dd9d0 100644 --- a/engines/parallaction/objects.h +++ b/engines/parallaction/objects.h @@ -162,22 +162,20 @@ typedef Common::List<CommandPtr> CommandList; #define NUM_ANSWERS 5 struct Answer { - char* _text; + Common::String _text; uint16 _mood; - union { - Question* _question; - char* _name; - } _following; + Question* _followingQuestion; + Common::String _followingName; + CommandList _commands; uint32 _noFlags; uint32 _yesFlags; Answer(); - ~Answer(); }; struct Question { - char* _text; + Common::String _text; uint16 _mood; Answer* _answers[NUM_ANSWERS]; @@ -215,11 +213,10 @@ struct SpeakData { }; struct ExamineData { GfxObj *_cnv; - char* _description; + Common::String _description; char* _filename; ExamineData() { - _description = NULL; _filename = NULL; _cnv = NULL; } diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 652e7660d0..cb643a36a9 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -116,8 +116,6 @@ Common::Error Parallaction::init() { _location._startPosition.x = -1000; _location._startPosition.y = -1000; _location._startFrame = 0; - _location._comment = NULL; - _location._endComment = NULL; _pathBuffer = 0; @@ -265,7 +263,7 @@ void Parallaction::allocateLocationSlot(const char *name) { } -Location::Location() : _comment(0), _endComment(0) { +Location::Location() { cleanup(true); } @@ -274,8 +272,8 @@ Location::~Location() { } void Location::cleanup(bool removeAll) { - free(_comment); _comment = 0; - free(_endComment); _endComment = 0; + _comment.clear(); + _endComment.clear(); freeZones(removeAll); freeAnimations(); @@ -324,8 +322,8 @@ void Parallaction::setBackground(const char* name, const char* mask, const char* return; } -void Parallaction::showLocationComment(const char *text, bool end) { - _balloonMan->setLocationBalloon(const_cast<char*>(text), end); +void Parallaction::showLocationComment(const Common::String &text, bool end) { + _balloonMan->setLocationBalloon(text.c_str(), end); } @@ -400,7 +398,7 @@ void Parallaction::runGame() { void Parallaction::doLocationEnterTransition() { debugC(2, kDebugExec, "doLocationEnterTransition"); - if (!_location._comment) { + if (_location._comment.empty()) { return; } @@ -568,7 +566,7 @@ void Parallaction::enterCommentMode(ZonePtr z) { ExamineData *data = _commentZone->u.examine; - if (!data->_description) { + if (data->_description.empty()) { return; } @@ -581,7 +579,7 @@ void Parallaction::enterCommentMode(ZonePtr z) { } _gfx->setHalfbriteMode(true); - _balloonMan->setSingleBalloon(data->_description, 0, 90, 0, BalloonManager::kNormalColor); + _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 90, 0, BalloonManager::kNormalColor); Common::Rect r; data->_cnv->getRect(0, r); id = _gfx->setItem(data->_cnv, 140, (_screenHeight - r.height())/2); @@ -589,13 +587,13 @@ void Parallaction::enterCommentMode(ZonePtr z) { id = _gfx->setItem(_char._head, 100, 152); _gfx->setItemFrame(id, 0); } else { - _balloonMan->setSingleBalloon(data->_description, 140, 10, 0, BalloonManager::kNormalColor); + _balloonMan->setSingleBalloon(data->_description.c_str(), 140, 10, 0, BalloonManager::kNormalColor); id = _gfx->setItem(_char._talk, 190, 80); _gfx->setItemFrame(id, 0); } } else if (getGameType() == GType_BRA) { - _balloonMan->setSingleBalloon(data->_description, 0, 0, 1, BalloonManager::kNormalColor); + _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 0, 1, BalloonManager::kNormalColor); int id = _gfx->setItem(_char._talk, 10, 80); _gfx->setItemFrame(id, 0); } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index f9d9265ac6..659b52d17a 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -131,8 +131,8 @@ struct Location { CommandList _aCommands; CommandList _commands; - char *_comment; - char *_endComment; + Common::String _comment; + Common::String _endComment; ZoneList _zones; AnimationList _animations; @@ -316,7 +316,7 @@ protected: void doLocationEnterTransition(); void allocateLocationSlot(const char *name); void finalizeLocationParsing(); - void showLocationComment(const char *text, bool end); + void showLocationComment(const Common::String &text, bool end); void setupBalloonManager(); public: diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index 9c7f9e3d71..bcef8660f1 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -185,8 +185,8 @@ protected: virtual void parseHearData(ZonePtr z); virtual void parseSpeakData(ZonePtr z); - char *parseComment(); - char *parseDialogueString(); + Common::String parseComment(); + Common::String parseDialogueString(); Dialogue *parseDialogue(); void resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards); Answer *parseAnswer(); @@ -216,7 +216,7 @@ protected: } public: - LocationParser_ns(Parallaction_ns *vm) : _vm(vm), _commandsNames(0), _locationStmt(0), + LocationParser_ns(Parallaction_ns *vm) : _vm(vm), _commandsNames(0), _locationStmt(0), _locationZoneStmt(0), _locationAnimStmt(0) { } @@ -261,9 +261,8 @@ public: class LocationParser_br : public LocationParser_ns { protected: - Table *_audioCommandsNames; - Parallaction_br* _vm; + Table *_audioCommandsNames; DECLARE_UNQUALIFIED_LOCATION_PARSER(location); DECLARE_UNQUALIFIED_LOCATION_PARSER(zone); @@ -327,9 +326,8 @@ public: class ProgramParser_ns { protected: - Parser *_parser; Parallaction_ns *_vm; - + Parser *_parser; Script *_script; ProgramPtr _program; diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index d6405a4dfd..86f77e02e7 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -901,7 +901,7 @@ Answer *LocationParser_ns::parseAnswer() { _script->readLineToken(true); answer->_mood = atoi(_tokens[0]); - answer->_following._name = parseDialogueString(); + answer->_followingName = parseDialogueString(); _script->readLineToken(true); if (!scumm_stricmp(_tokens[0], "commands")) { @@ -928,27 +928,26 @@ void LocationParser_ns::resolveDialogueForwards(Dialogue *dialogue, uint numQues Answer *answer = question->_answers[j]; if (answer == 0) continue; - int16 index = forwards.lookup(answer->_following._name); - free(answer->_following._name); - answer->_following._name = 0; + int16 index = forwards.lookup(answer->_followingName.c_str()); + answer->_followingName.clear(); if (index == Table::notFound) - answer->_following._question = 0; + answer->_followingQuestion = 0; else - answer->_following._question = dialogue->_questions[index - 1]; + answer->_followingQuestion = dialogue->_questions[index - 1]; } } } -char *LocationParser_ns::parseDialogueString() { - char buf[200]; - char *line = _script->readLine(buf, 200); +Common::String LocationParser_ns::parseDialogueString() { + char buf[400]; + char *line = _script->readLine(buf, 400); if (line == 0) { return 0; } - return strdup(line); + return Common::String(line); } @@ -1265,31 +1264,25 @@ void ProgramParser_ns::init() { // a comment can appear both at location and Zone levels // comments are displayed into rectangles on the screen // -char *LocationParser_ns::parseComment() { - const int tempSize = 1000; - char temp[tempSize] = "\0"; - int len = 0; +Common::String LocationParser_ns::parseComment() { + Common::String comment; char buf[400]; do { char *line = _script->readLine(buf, 400); if (!scumm_stricmp(line, "endtext")) break; - strncat(temp, line, tempSize - len - 1); - strcat(temp, " "); - len = len + strlen(line) + 1; - } while (len < tempSize); + if (comment.size() > 0) + comment += " "; - if (len == 0) { - return 0; - } + comment += line; + } while (true); - if (len == tempSize) { - warning("overflow in LocationParser_ns::parseComment (line %i)", _script->getLine()); + if (comment.size() == 0) { + return 0; } - temp[len-1] = '\0'; // removes the last space pasted in the string - return strdup(temp); + return comment; } DECLARE_ZONE_PARSER(null) { |