aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrichiesams2013-07-29 21:49:06 -0500
committerrichiesams2013-08-04 13:32:50 -0500
commitb20437a17d1a740e70dd1fa0bbf3bc6cfeb6c494 (patch)
treed0a0b1d87fc6db4eaa5748185852f91ec7aca7ca
parentcf9790a9d6407e3bfea46cea1c59abe9ab5de31c (diff)
downloadscummvm-rg350-b20437a17d1a740e70dd1fa0bbf3bc6cfeb6c494.tar.gz
scummvm-rg350-b20437a17d1a740e70dd1fa0bbf3bc6cfeb6c494.tar.bz2
scummvm-rg350-b20437a17d1a740e70dd1fa0bbf3bc6cfeb6c494.zip
ZVISION: Modify Criteria parsing to handle empty Criteria
-rw-r--r--engines/zvision/scr_file_handling.cpp46
-rw-r--r--engines/zvision/script_manager.h7
2 files changed, 32 insertions, 21 deletions
diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp
index 168a6d830a..cebb57a786 100644
--- a/engines/zvision/scr_file_handling.cpp
+++ b/engines/zvision/scr_file_handling.cpp
@@ -72,22 +72,32 @@ void ScriptManager::parsePuzzle(Puzzle &puzzle, Common::SeekableReadStream &stre
trimCommentsAndWhiteSpace(&line);
while (!line.contains('}')) {
- if (line.matchString("criteria {", true))
- puzzle.criteriaList.push_back(parseCriteria(stream));
- else if (line.matchString("results {", true))
- parseResult(stream, puzzle.resultActions);
- else if (line.matchString("flags {", true))
+ if (line.matchString("criteria {", true)) {
+ Criteria criteria;
+ if (parseCriteria(&criteria, stream)) {
+ puzzle.criteriaList.push_back(criteria);
+ }
+ } else if (line.matchString("results {", true)) {
+ parseResults(stream, puzzle.resultActions);
+ } else if (line.matchString("flags {", true)) {
puzzle.flags = parseFlags(stream);
+ }
+
+ line = stream.readLine();
+ trimCommentsAndWhiteSpace(&line);
}
}
-Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const {
- Criteria criteria;
-
+bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const {
// Loop until we find the closing brace
Common::String line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
+ // Criteria can be empty
+ if (line.contains('}')) {
+ return false;
+ }
+
while (!line.contains('}')) {
// Split the string into tokens using ' ' as a delimiter
Common::StringTokenizer tokenizer(line);
@@ -95,35 +105,35 @@ Criteria ScriptManager::parseCriteria(Common::SeekableReadStream &stream) const
// Parse the id out of the first token
token = tokenizer.nextToken();
- sscanf(token.c_str(), "[%u]", &(criteria.key));
+ sscanf(token.c_str(), "[%u]", &(criteria->key));
// Parse the operator out of the second token
token = tokenizer.nextToken();
if (token.c_str()[0] == '=')
- criteria.criteriaOperator = EQUAL_TO;
+ criteria->criteriaOperator = EQUAL_TO;
else if (token.c_str()[0] == '!')
- criteria.criteriaOperator = NOT_EQUAL_TO;
+ criteria->criteriaOperator = NOT_EQUAL_TO;
else if (token.c_str()[0] == '>')
- criteria.criteriaOperator = GREATER_THAN;
+ criteria->criteriaOperator = GREATER_THAN;
else if (token.c_str()[0] == '<')
- criteria.criteriaOperator = LESS_THAN;
+ criteria->criteriaOperator = LESS_THAN;
// First determine if the last token is an id or a value
// Then parse it into 'argument'
token = tokenizer.nextToken();
if (token.contains('[')) {
- sscanf(token.c_str(), "[%u]", &(criteria.argument));
- criteria.argumentIsAKey = true;
+ sscanf(token.c_str(), "[%u]", &(criteria->argument));
+ criteria->argumentIsAKey = true;
} else {
- sscanf(token.c_str(), "%u", &(criteria.argument));
- criteria.argumentIsAKey = false;
+ sscanf(token.c_str(), "%u", &(criteria->argument));
+ criteria->argumentIsAKey = false;
}
line = stream.readLine();
trimCommentsAndWhiteSpace(&line);
}
- return criteria;
+ return true;
}
void ScriptManager::parseResult(Common::SeekableReadStream &stream, Common::List<ResultAction *> &actionList) const {
diff --git a/engines/zvision/script_manager.h b/engines/zvision/script_manager.h
index 2d9bcc3fd5..ec16477b92 100644
--- a/engines/zvision/script_manager.h
+++ b/engines/zvision/script_manager.h
@@ -97,10 +97,11 @@ private:
* Parses the stream into a Criteria object
* Helper method for parsePuzzle.
*
- * @param stream Scr file stream
- * @return Created Criteria object
+ * @param criteria Pointer to the Criteria object to fill
+ * @param stream Scr file stream
+ * @return Whether any criteria were read
*/
- Criteria parseCriteria(Common::SeekableReadStream &stream) const;
+ bool ScriptManager::parseCriteria(Criteria *criteria, Common::SeekableReadStream &stream) const;
/**
* Parses the stream into a Results object