tyler-trie 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/VERSION.yml +1 -1
  2. data/ext/trie/extconf.rb +1 -3
  3. metadata +4 -65
  4. data/ext/libdatrie/AUTHORS +0 -1
  5. data/ext/libdatrie/COPYING +0 -510
  6. data/ext/libdatrie/ChangeLog +0 -410
  7. data/ext/libdatrie/INSTALL +0 -236
  8. data/ext/libdatrie/Makefile.am +0 -5
  9. data/ext/libdatrie/Makefile.in +0 -661
  10. data/ext/libdatrie/NEWS +0 -27
  11. data/ext/libdatrie/README +0 -32
  12. data/ext/libdatrie/aclocal.m4 +0 -7431
  13. data/ext/libdatrie/config.guess +0 -1516
  14. data/ext/libdatrie/config.h.in +0 -74
  15. data/ext/libdatrie/config.sub +0 -1626
  16. data/ext/libdatrie/configure +0 -22008
  17. data/ext/libdatrie/configure.ac +0 -71
  18. data/ext/libdatrie/datrie.pc.in +0 -11
  19. data/ext/libdatrie/datrie/Makefile.am +0 -35
  20. data/ext/libdatrie/datrie/Makefile.in +0 -522
  21. data/ext/libdatrie/datrie/alpha-map.c +0 -170
  22. data/ext/libdatrie/datrie/alpha-map.h +0 -36
  23. data/ext/libdatrie/datrie/darray.c +0 -674
  24. data/ext/libdatrie/datrie/darray.h +0 -229
  25. data/ext/libdatrie/datrie/fileutils.c +0 -151
  26. data/ext/libdatrie/datrie/fileutils.h +0 -36
  27. data/ext/libdatrie/datrie/libdatrie.def +0 -31
  28. data/ext/libdatrie/datrie/sb-trie.c +0 -331
  29. data/ext/libdatrie/datrie/sb-trie.h +0 -279
  30. data/ext/libdatrie/datrie/tail.c +0 -344
  31. data/ext/libdatrie/datrie/tail.h +0 -200
  32. data/ext/libdatrie/datrie/trie-private.h +0 -31
  33. data/ext/libdatrie/datrie/trie.c +0 -413
  34. data/ext/libdatrie/datrie/trie.h +0 -270
  35. data/ext/libdatrie/datrie/triedefs.h +0 -63
  36. data/ext/libdatrie/datrie/typedefs.h +0 -113
  37. data/ext/libdatrie/depcomp +0 -530
  38. data/ext/libdatrie/doc/Doxyfile.in +0 -244
  39. data/ext/libdatrie/doc/Makefile.am +0 -29
  40. data/ext/libdatrie/doc/Makefile.in +0 -352
  41. data/ext/libdatrie/install-sh +0 -323
  42. data/ext/libdatrie/ltmain.sh +0 -6938
  43. data/ext/libdatrie/man/Makefile.am +0 -4
  44. data/ext/libdatrie/man/Makefile.in +0 -381
  45. data/ext/libdatrie/man/trietool.1 +0 -107
  46. data/ext/libdatrie/missing +0 -360
  47. data/ext/libdatrie/tools/Makefile.am +0 -7
  48. data/ext/libdatrie/tools/Makefile.in +0 -460
  49. data/ext/libdatrie/tools/trietool.c +0 -308
@@ -1,308 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
- /*
3
- * trietool.c - Trie manipulation tool
4
- * Created: 2006-08-15
5
- * Author: Theppitak Karoonboonyanan <thep@linux.thai.net>
6
- */
7
-
8
- #include <string.h>
9
- #include <stdlib.h>
10
- #include <stdio.h>
11
- #include <ctype.h>
12
-
13
- #include <config.h>
14
- #include <datrie/sb-trie.h>
15
-
16
- typedef struct {
17
- const char *path;
18
- const char *trie_name;
19
- SBTrie *sb_trie;
20
- } ProgEnv;
21
-
22
- static int decode_switch (int argc, char *argv[], ProgEnv *env);
23
- static int decode_command (int argc, char *argv[], ProgEnv *env);
24
-
25
- static int command_add (int argc, char *argv[], ProgEnv *env);
26
- static int command_add_list (int argc, char *argv[], ProgEnv *env);
27
- static int command_delete (int argc, char *argv[], ProgEnv *env);
28
- static int command_delete_list (int argc, char *argv[], ProgEnv *env);
29
- static int command_query (int argc, char *argv[], ProgEnv *env);
30
- static int command_list (int argc, char *argv[], ProgEnv *env);
31
-
32
- static void usage (const char *prog_name, int exit_status);
33
-
34
- static char *string_trim (char *s);
35
-
36
- int
37
- main (int argc, char *argv[])
38
- {
39
- int i;
40
- ProgEnv env;
41
- int ret;
42
-
43
- env.path = ".";
44
-
45
- i = decode_switch (argc, argv, &env);
46
- if (i == argc)
47
- usage (argv[0], EXIT_FAILURE);
48
-
49
- env.trie_name = argv[i++];
50
- env.sb_trie = sb_trie_open (env.path, env.trie_name,
51
- TRIE_IO_READ | TRIE_IO_WRITE | TRIE_IO_CREATE);
52
- if (!env.sb_trie) {
53
- fprintf (stderr, "Cannot open trie '%s' at '%s'\n",
54
- env.trie_name, env.path);
55
- exit (EXIT_FAILURE);
56
- }
57
-
58
- ret = decode_command (argc - i, argv + i, &env);
59
-
60
- sb_trie_close (env.sb_trie);
61
-
62
- return ret;
63
- }
64
-
65
- static int
66
- decode_switch (int argc, char *argv[], ProgEnv *env)
67
- {
68
- int opt_idx;
69
-
70
- for (opt_idx = 1; opt_idx < argc && *argv[opt_idx] == '-'; opt_idx++) {
71
- if (strcmp (argv[opt_idx], "-h") == 0 ||
72
- strcmp (argv[opt_idx], "--help") == 0)
73
- {
74
- usage (argv[0], EXIT_FAILURE);
75
- } else if (strcmp (argv[opt_idx], "-V") == 0 ||
76
- strcmp (argv[opt_idx], "--version") == 0)
77
- {
78
- printf ("%s\n", VERSION);
79
- exit (EXIT_FAILURE);
80
- } else if (strcmp (argv[opt_idx], "-p") == 0 ||
81
- strcmp (argv[opt_idx], "--path") == 0)
82
- {
83
- env->path = argv[++opt_idx];
84
- } else if (strcmp (argv[opt_idx], "--") == 0) {
85
- ++opt_idx;
86
- break;
87
- } else {
88
- fprintf (stderr, "Unknown option: %s\n", argv[opt_idx]);
89
- exit (EXIT_FAILURE);
90
- }
91
- }
92
-
93
- return opt_idx;
94
- }
95
-
96
- static int
97
- decode_command (int argc, char *argv[], ProgEnv *env)
98
- {
99
- int opt_idx;
100
-
101
- for (opt_idx = 0; opt_idx < argc; opt_idx++) {
102
- if (strcmp (argv[opt_idx], "add") == 0) {
103
- ++opt_idx;
104
- opt_idx += command_add (argc - opt_idx, argv + opt_idx, env);
105
- } else if (strcmp (argv[opt_idx], "add-list") == 0) {
106
- ++opt_idx;
107
- opt_idx += command_add_list (argc - opt_idx, argv + opt_idx, env);
108
- } else if (strcmp (argv[opt_idx], "delete") == 0) {
109
- ++opt_idx;
110
- opt_idx += command_delete (argc - opt_idx, argv + opt_idx, env);
111
- } else if (strcmp (argv[opt_idx], "delete-list") == 0) {
112
- ++opt_idx;
113
- opt_idx += command_delete_list (argc - opt_idx, argv + opt_idx, env);
114
- } else if (strcmp (argv[opt_idx], "query") == 0) {
115
- ++opt_idx;
116
- opt_idx += command_query (argc - opt_idx, argv + opt_idx, env);
117
- } else if (strcmp (argv[opt_idx], "list") == 0) {
118
- ++opt_idx;
119
- opt_idx += command_list (argc - opt_idx, argv + opt_idx, env);
120
- } else {
121
- fprintf (stderr, "Unknown command: %s\n", argv[opt_idx]);
122
- return EXIT_FAILURE;
123
- }
124
- }
125
-
126
- return EXIT_SUCCESS;
127
- }
128
-
129
- static int
130
- command_add (int argc, char *argv[], ProgEnv *env)
131
- {
132
- int opt_idx;
133
-
134
- opt_idx = 0;
135
- while (opt_idx < argc) {
136
- const TrieChar *key;
137
- TrieData data;
138
-
139
- key = (const TrieChar *) argv[opt_idx++];
140
- data = (opt_idx < argc) ? atoi (argv[opt_idx++]) : TRIE_DATA_ERROR;
141
-
142
- if (!sb_trie_store (env->sb_trie, key, data)) {
143
- fprintf (stderr, "Failed to add entry '%s' with data %d\n",
144
- key, data);
145
- }
146
- }
147
-
148
- return opt_idx;
149
- }
150
-
151
- static int
152
- command_add_list (int argc, char *argv[], ProgEnv *env)
153
- {
154
- FILE *input;
155
- char line[256];
156
-
157
- input = fopen (argv[0], "r");
158
- if (!input) {
159
- fprintf (stderr, "add-list: Cannot open input file '%s'\n", argv[0]);
160
- return 1;
161
- }
162
-
163
- while (fgets (line, sizeof line, input)) {
164
- char *key, *data;
165
- TrieData data_val;
166
-
167
- key = string_trim (line);
168
- if ('\0' != *key) {
169
- /* find key boundary */
170
- for (data = key; *data && !strchr ("\t,", *data); ++data)
171
- ;
172
- /* mark key ending and find data begin */
173
- if ('\0' != *data) {
174
- *data++ = '\0';
175
- while (isspace (*data))
176
- ++data;
177
- }
178
- /* decode data */
179
- data_val = ('\0' != *data) ? atoi (data) : TRIE_DATA_ERROR;
180
-
181
- /* store the key */
182
- if (!sb_trie_store (env->sb_trie, (const TrieChar *) key, data_val))
183
- fprintf (stderr, "Failed to add key '%s' with data %d.\n",
184
- key, data_val);
185
- }
186
- }
187
-
188
- fclose (input);
189
-
190
- return 1;
191
- }
192
-
193
- static int
194
- command_delete (int argc, char *argv[], ProgEnv *env)
195
- {
196
- int opt_idx;
197
-
198
- for (opt_idx = 0; opt_idx < argc; opt_idx++)
199
- if (!sb_trie_delete (env->sb_trie, (const TrieChar *) argv[opt_idx]))
200
- fprintf (stderr, "No entry '%s'. Not deleted.\n", argv[opt_idx]);
201
-
202
- return opt_idx;
203
- }
204
-
205
- static int
206
- command_delete_list (int argc, char *argv[], ProgEnv *env)
207
- {
208
- FILE *input;
209
- char line[256];
210
-
211
- input = fopen (argv[0], "r");
212
- if (!input) {
213
- fprintf (stderr, "delete-list: Cannot open input file '%s'\n", argv[0]);
214
- return 1;
215
- }
216
-
217
- while (fgets (line, sizeof line, input)) {
218
- char *p;
219
-
220
- p = string_trim (line);
221
- if ('\0' != *p)
222
- if (!sb_trie_delete (env->sb_trie, (const TrieChar *) p))
223
- fprintf (stderr, "No entry '%s'. Not deleted.\n", p);
224
- }
225
-
226
- fclose (input);
227
-
228
- return 1;
229
- }
230
-
231
- static int
232
- command_query (int argc, char *argv[], ProgEnv *env)
233
- {
234
- TrieData data;
235
-
236
- if (argc == 0) {
237
- fprintf (stderr, "query: No key specified.\n");
238
- return 0;
239
- }
240
-
241
- if (sb_trie_retrieve (env->sb_trie, (const TrieChar *) argv[0], &data)) {
242
- printf ("%d\n", data);
243
- } else {
244
- fprintf (stderr, "query: Key '%s' not found.\n", argv[0]);
245
- }
246
-
247
- return 1;
248
- }
249
-
250
- static Bool
251
- list_enum_func (const SBChar *key, TrieData key_data, void *user_data)
252
- {
253
- printf ("%s\t%d\n", key, key_data);
254
- return TRUE;
255
- }
256
-
257
- static int
258
- command_list (int argc, char *argv[], ProgEnv *env)
259
- {
260
- sb_trie_enumerate (env->sb_trie, list_enum_func, (void *) 0);
261
- return 0;
262
- }
263
-
264
-
265
- static void
266
- usage (const char *prog_name, int exit_status)
267
- {
268
- printf ("%s - double-array trie manipulator\n", prog_name);
269
- printf ("Usage: %s [OPTION]... TRIE CMD ARG ...\n", prog_name);
270
- printf (
271
- "Options:\n"
272
- " -p, --path DIR set trie directory to DIR [default=.]\n"
273
- " -h, --help display this help and exit\n"
274
- " -V, --version output version information and exit\n"
275
- "\n"
276
- "Commands:\n"
277
- " add WORD DATA ... add WORD with DATA to trie\n"
278
- " add-list LISTFILE add WORD and DATA from LISTFILE to trie\n"
279
- " delete WORD ... delete WORD from trie\n"
280
- " delete-list LISTFILE delete words listed in LISTFILE from trie\n"
281
- " query WORD query WORD data from trie\n"
282
- " list list all words in trie\n"
283
- );
284
-
285
- exit (exit_status);
286
- }
287
-
288
- static char *
289
- string_trim (char *s)
290
- {
291
- char *p;
292
-
293
- /* skip leading white spaces */
294
- while (*s && isspace (*s))
295
- ++s;
296
-
297
- /* trim trailing white spaces */
298
- p = s + strlen (s) - 1;
299
- while (isspace (*p))
300
- --p;
301
- *++p = '\0';
302
-
303
- return s;
304
- }
305
-
306
- /*
307
- vi:ts=4:ai:expandtab
308
- */