X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dict.c;h=a9202934035d35346f0ac75905f4baa130fff9ed;hb=27fa9d9abfa5f58f70258f0d671ab1cb133a68ce;hp=50b741eb9cd5697e066d4df81e92f9c0ef6c9ef8;hpb=7787438f3c3844ab9597320213f5bd19bc6426e1;p=wordgame diff --git a/dict.c b/dict.c index 50b741e..a920293 100644 --- a/dict.c +++ b/dict.c @@ -16,24 +16,18 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." */ -/* Portably, schmortability. I want ease of programming. */ -#define _GNU_SOURCE -#include -#include +#include "dict.h" + #include #include #include -#include "dict.h" - typedef struct _string { size_t size; char *s; size_t len; } string_t; -#define TRIE_FLAGS_IS_WORD (1<<0) - typedef bool_t (*trie_predicate_t) (trie_t *trie); @@ -165,23 +159,21 @@ trie_destroy (trie_t *trie) free (trie); } -static void +static trie_t * trie_add (trie_t *trie, const char *word_chunk) { char c = word_chunk[0]; int i; - if (c == '\0') { - trie->flags |= TRIE_FLAGS_IS_WORD; - return; - } + if (c == '\0') + return trie; i = TRIE_CHAR_TO_INDEX (c); if (trie->next[i] == NULL) trie->next[i] = trie_create (); - trie_add (trie->next[i], word_chunk + 1); + return trie_add (trie->next[i], word_chunk + 1); } static trie_t * @@ -269,7 +261,10 @@ void dict_add_word (dict_t *dict, const char *word) { - trie_add (dict, word); + trie_t *trie; + + trie = trie_add (dict, word); + trie->flags |= DICT_ENTRY_FLAG_IS_WORD; } void