2020-05-28 01:32:32 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-05-28 01:32:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-05-28 01:32:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glk/comprehend/comprehend.h"
|
2020-05-29 02:47:56 +00:00
|
|
|
#include "glk/comprehend/game.h"
|
2020-05-28 01:32:32 +00:00
|
|
|
#include "glk/comprehend/game_data.h"
|
|
|
|
#include "glk/comprehend/dictionary.h"
|
|
|
|
|
|
|
|
namespace Glk {
|
|
|
|
namespace Comprehend {
|
|
|
|
|
2020-06-03 03:14:20 +00:00
|
|
|
static bool word_match(Word *word, const char *string) {
|
2020-05-28 01:32:32 +00:00
|
|
|
/* Words less than 6 characters must match exactly */
|
2020-05-29 05:44:51 +00:00
|
|
|
if (strlen(word->_word) < 6 && strlen(string) != strlen(word->_word))
|
2020-05-28 01:32:32 +00:00
|
|
|
return false;
|
|
|
|
|
2020-05-29 05:44:51 +00:00
|
|
|
return strncmp(word->_word, string, strlen(word->_word)) == 0;
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 00:36:13 +00:00
|
|
|
Word *dict_find_word_by_string(ComprehendGame *game,
|
2021-04-15 19:20:04 +00:00
|
|
|
const char *string) {
|
2020-05-28 01:32:32 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
if (!string)
|
2021-11-13 21:40:25 +00:00
|
|
|
return nullptr;
|
2020-05-28 01:32:32 +00:00
|
|
|
|
2020-10-25 04:04:41 +00:00
|
|
|
for (i = 0; i < game->_words.size(); i++)
|
2020-05-29 19:00:47 +00:00
|
|
|
if (word_match(&game->_words[i], string))
|
|
|
|
return &game->_words[i];
|
2020-05-28 01:32:32 +00:00
|
|
|
|
2021-11-13 21:40:25 +00:00
|
|
|
return nullptr;
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 00:36:13 +00:00
|
|
|
Word *dict_find_word_by_index_type(ComprehendGame *game,
|
2021-04-15 19:20:04 +00:00
|
|
|
uint8 index, uint8 type) {
|
2020-05-28 01:32:32 +00:00
|
|
|
uint i;
|
|
|
|
|
2020-10-25 04:04:41 +00:00
|
|
|
for (i = 0; i < game->_words.size(); i++) {
|
2020-05-29 19:00:47 +00:00
|
|
|
if (game->_words[i]._index == index &&
|
2020-06-03 03:14:20 +00:00
|
|
|
game->_words[i]._type == type)
|
2020-05-29 19:00:47 +00:00
|
|
|
return &game->_words[i];
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 21:40:25 +00:00
|
|
|
return nullptr;
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 00:36:13 +00:00
|
|
|
Word *find_dict_word_by_index(ComprehendGame *game,
|
2021-04-15 19:20:04 +00:00
|
|
|
uint8 index, uint8 type_mask) {
|
2020-05-28 01:32:32 +00:00
|
|
|
uint i;
|
|
|
|
|
2020-10-25 04:04:41 +00:00
|
|
|
for (i = 0; i < game->_words.size(); i++) {
|
2020-05-29 19:00:47 +00:00
|
|
|
if (game->_words[i]._index == index &&
|
2020-06-03 03:14:20 +00:00
|
|
|
(game->_words[i]._type & type_mask) != 0)
|
2020-05-29 19:00:47 +00:00
|
|
|
return &game->_words[i];
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 21:40:25 +00:00
|
|
|
return nullptr;
|
2020-05-28 01:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 15:03:12 +00:00
|
|
|
bool dict_match_index_type(ComprehendGame *game, const char *word,
|
2021-04-15 19:20:04 +00:00
|
|
|
uint8 index, uint8 type_mask) {
|
2020-05-28 01:32:32 +00:00
|
|
|
uint i;
|
|
|
|
|
2020-10-25 04:04:41 +00:00
|
|
|
for (i = 0; i < game->_words.size(); i++)
|
2020-05-29 19:00:47 +00:00
|
|
|
if (game->_words[i]._index == index &&
|
2020-06-03 03:14:20 +00:00
|
|
|
((game->_words[i]._type & type_mask) != 0) &&
|
|
|
|
word_match(&game->_words[i], word))
|
2020-05-28 01:32:32 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Comprehend
|
|
|
|
} // namespace Glk
|