]> git.cworth.org Git - wordgame/commitdiff
Move private portions of dict from dict-impl.h back to dict.c
authorCarl Worth <cworth@raht.cworth.org>
Thu, 21 Sep 2006 09:02:39 +0000 (02:02 -0700)
committerCarl Worth <cworth@raht.cworth.org>
Thu, 21 Sep 2006 09:02:39 +0000 (02:02 -0700)
This is the punch line in the recent series of commits which removed
trie_t and string_t code from grid.c. We now finally have a nice,
clean dict_t interface for new programs to use.

dict-impl.h [deleted file]
dict.c
dict.h
grid.c

diff --git a/dict-impl.h b/dict-impl.h
deleted file mode 100644 (file)
index 78aab1c..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright © 2006 Carl Worth
- *
- * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
- */
-
-#ifndef _DICT_IMPL_H_
-#define _DICT_IMPL_H_
-
-#include <stdint.h>
-
-#ifndef FALSE
-# define FALSE 0
-#endif
-
-#ifndef TRUE
-# define TRUE 1
-#endif
-
-typedef int bool_t;
-
-typedef struct _string {
-    size_t size;
-    char *s;
-    size_t len;
-} string_t;
-
-void
-string_init (string_t *string);
-
-void
-string_fini (string_t *string);
-
-void
-string_append_char (string_t *string, char c);
-
-void
-string_chop (string_t *string);
-
-void
-chomp (char *s);
-
-#define TRIE_FLAGS_IS_WORD     (1<<0)
-
-typedef struct _trie {
-    uint32_t flags;
-    struct _trie *next[26];
-} trie_t;
-
-typedef bool_t
-(*trie_predicate_t) (trie_t *trie);
-
-#define TRIE_CHAR_TO_INDEX(c)  (tolower (c) - 'a')
-#define TRIE_INDEX_TO_CHAR(i)  (i + 'a')
-
-trie_t *
-trie_create (void);
-
-void
-trie_add (trie_t       *trie,
-         const char    *word_chunk);
-
-trie_t *
-trie_find (trie_t      *trie,
-          const char   *word_chunk);
-
-#endif /* _DICT_IMPL_H_ */
diff --git a/dict.c b/dict.c
index c364cb8110f066c9fbc71f65317fbb526778da84..f975829c1877c74e1b85001c571fcbccbd2d8ccc 100644 (file)
--- a/dict.c
+++ b/dict.c
 
 #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);
+
+#define TRIE_CHAR_TO_INDEX(c)  (tolower (c) - 'a')
+#define TRIE_INDEX_TO_CHAR(i)  (i + 'a')
+
 void *
 xmalloc (size_t size)
 {
@@ -58,6 +72,8 @@ void
 chomp (char *s)
 {
     int len = strlen (s);
+    if (len == 0)
+       return;
     if (s[len - 1] == '\n')
        s[len - 1] = '\0';
 }
diff --git a/dict.h b/dict.h
index ccc0c0b8af961570514fd232fe1e29efde80ab71..ca0e6f6e9a209efe442a3ea8083e0d2480cc7e1b 100644 (file)
--- a/dict.h
+++ b/dict.h
 #ifndef _DICT_H_
 #define _DICT_H_
 
-#include "dict-impl.h"
+#include <stdint.h>
+
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+
+typedef int bool_t;
+
+typedef struct _trie {
+    uint32_t flags;
+    struct _trie *next[26];
+} trie_t;
 
-/* Only looks opaque. Perfectly stack-allocatable */
 typedef trie_t dict_t;
 typedef trie_t *dict_cursor_t;
 typedef uint32_t dict_entry_t;
diff --git a/grid.c b/grid.c
index cce4ab768da43dcd7f8105a7cf0f38ac9328f206..960b79626ebead506ffdc371b35375801d2a6634 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -203,11 +203,12 @@ main (void)
        sprintf (prompt, "%02d:%02d ", minutes, seconds);
        response = readline (prompt);
        add_history (response);
-       chomp (response);
        if (strlen (response) == 0) {
            board_print (&board);
        } else {
            dict_entry_t *entry;
+           if (response[strlen (response) - 1] == '\n')
+               response[strlen (response) - 1] = '\0';
            entry = dict_lookup (&solution, response);
            if (DICT_ENTRY_IS_WORD (entry)) {
                if (*entry & GRID_WORD_SEEN)