]> git.cworth.org Git - wordgame/blob - dict.h
Break wordgame.c into dict.c and grid.c in preparation for more programs
[wordgame] / dict.h
1 /*
2  * Copyright © 2006 Carl Worth
3  *
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)
7  * any later version.
8  *
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.
13  *
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."
17  */
18
19 #ifndef _DICT_H_
20 #define _DICT_H_
21
22 #include <stdint.h>
23
24 #ifndef FALSE
25 # define FALSE 0
26 #endif
27
28 #ifndef TRUE
29 # define TRUE 1
30 #endif
31
32 typedef int bool_t;
33
34 typedef struct _string {
35     size_t size;
36     char *s;
37     size_t len;
38 } string_t;
39
40 void
41 string_init (string_t *string);
42
43 void
44 string_fini (string_t *string);
45
46 void
47 string_append_char (string_t *string, char c);
48
49 void
50 string_chop (string_t *string);
51
52 void
53 chomp (char *s);
54
55 #define TRIE_FLAGS_IS_WORD      (1<<0)
56 #define TRIE_FLAGS_SEEN         (1<<1)
57
58 typedef struct _trie {
59     uint32_t flags;
60     struct _trie *next[26];
61 } trie_t;
62
63 typedef bool_t
64 (*trie_predicate_t) (trie_t *trie);
65
66 #define TRIE_CHAR_TO_INDEX(c)   (tolower (c) - 'a')
67 #define TRIE_INDEX_TO_CHAR(i)   (i + 'a')
68
69 trie_t *
70 trie_create (void);
71
72 void
73 trie_add (trie_t        *trie,
74           const char    *word_chunk);
75
76 trie_t *
77 trie_find (trie_t       *trie,
78            const char   *word_chunk);
79
80 int
81 trie_print_seen (trie_t *trie, string_t *word);
82
83 int
84 trie_print_unseen (trie_t *trie, string_t *word);
85
86 typedef struct _dict {
87     trie_t *trie;
88 } dict_t;
89
90 void
91 dict_init (dict_t       *dict,
92            const char   *filename);
93
94 void
95 dict_fini (dict_t *dict);
96
97 #endif /* _DICT_H_ */