2 * Copyright © 2006 Carl Worth
4 * This program is free software; you can redistribute it and\/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
19 #include "word-game.h"
23 static const char *subanagram_letters;
24 static char subanagram_enumerate_word[WORD_GAME_MAX_WORD_LENGTH];
25 static dict_t *subanagram_enumerate_answers;
28 subanagram_enumerate (dict_cursor_t cursor,
35 if (cursor == DICT_CURSOR_NIL)
38 if (DICT_ENTRY_IS_WORD (dict_cursor_resolve (cursor)))
39 dict_add_word (subanagram_enumerate_answers, subanagram_enumerate_word);
41 last = strlen (subanagram_enumerate_word);
43 for (i = 0; i < strlen (subanagram_letters); i++) {
46 next_seen = seen | (1 << i);
47 c = subanagram_letters[i];
48 if (c == '?' || c == '_') {
49 for (c = 'a'; c <= 'z'; c++) {
50 subanagram_enumerate_word[last] = c;
51 subanagram_enumerate (dict_cursor_next (cursor, c), next_seen);
54 subanagram_enumerate_word[last] = c;
55 subanagram_enumerate (dict_cursor_next (cursor, c), next_seen);
57 subanagram_enumerate_word[last] = '\0';
62 subanagram_expand (const char *letters, dict_t *dict, dict_t *answers)
64 subanagram_letters = letters;
65 memset (subanagram_enumerate_word, '\0', WORD_GAME_MAX_WORD_LENGTH);
66 subanagram_enumerate_answers = answers;
68 subanagram_enumerate (dict_root (dict), 0);