/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "common/algorithm.h" #include "titanic/true_talk/tt_quotes_tree.h" #include "titanic/titanic.h" namespace Titanic { /** * Specifies the starting index for each of the three main trees */ static uint TABLE_INDEXES[3] = { 922, 1015, 1018 }; void TTquotesTree::load() { Common::SeekableReadStream *r = g_vm->_filesManager->getResource("TEXT/TREE"); for (int idx = 0; idx < QUOTES_TREE_COUNT; ++idx) { TTquotesTree::TTquotesTreeEntry &rec = _entries[idx]; assert(r->pos() < r->size()); rec._id = r->readUint32LE(); if (rec._id == 0) { // Nothing needed } else { byte type = r->readByte(); if (type == 0) { // Index to sub-table rec._subTable = &_entries[0] + r->readUint32LE(); } else { // Read in string for entry char c; while ((c = r->readByte()) != '\0') rec._string += c; } } } assert(r->pos() == r->size()); delete r; } void TTquotesTree::search(const char **str, TTquotesTreeEntry *bTree, TTtreeBuffer *buffer, int quoteId) { buffer->_strP = nullptr; (buffer + 1)->_strP = nullptr; bool flag = false; for (uint mode = bTree->_id >> 24; mode != 0; ++bTree, mode = bTree->_id >> 24) { switch (mode) { case 1: if (compareWord(str, bTree->_string.c_str())) flag = true; break; case 2: compareWord(str, bTree->_string.c_str()); break; case 5: warning("TODO: TTquotesTree::search"); break; case 7: default: break; } if (flag) { // TODO break; } } } bool TTquotesTree::compareWord(const char **str, const char *refStr) { // Skip over any spaces const char *strP = *str; while (*strP && *strP == ' ') ++strP; *str = strP; // Compare against the reference string while (*strP && *refStr && *refStr != '*') { if (*refStr == '-') { if (*strP == ' ') ++strP; } else if (*strP == *refStr) { ++strP; } else { return false; } } if (*refStr && *refStr != '*') return false; if (!*refStr && *strP && *strP != ' ') return false; if (*refStr == '*') { // Skip over to the end of the word while (*strP && *strP != ' ') ++strP; } // Pass out the new updated string position *str = strP; return true; } } // End of namespace Titanic