chinwag 0.1.5 → 1.2.0
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/chinwag/chinwag.c +46 -41
- data/ext/chinwag/chinwag.h +20 -12
- data/ext/chinwag/config.c +6 -6
- data/ext/chinwag/dict.c +211 -107
- data/ext/chinwag/dict.h +93 -41
- data/ext/chinwag/latin.h +2 -2
- data/ext/chinwag/rb_chinwag_ext.c +255 -167
- data/ext/chinwag/seuss.h +2 -2
- data/ext/chinwag/tokenize.c +7 -5
- data/ext/chinwag/tokenize.h +5 -2
- metadata +2 -2
data/ext/chinwag/dict.c
CHANGED
@@ -1,8 +1,45 @@
|
|
1
1
|
#include "dict.h"
|
2
2
|
|
3
|
-
|
3
|
+
// dictionary row utilities
|
4
|
+
cwdrow_t cwdrow_open();
|
5
|
+
|
6
|
+
cwdrow_t cwdrow_add_word
|
7
|
+
(cwdrow_t drow, const char* word);
|
8
|
+
|
9
|
+
cwdrow_t cwdrow_add_word_strict
|
10
|
+
(cwdrow_t drow, const char* word, U32 size);
|
11
|
+
|
12
|
+
cwdrow_t cwdrow_sort
|
13
|
+
(cwdrow_t drow);
|
14
|
+
|
15
|
+
bool cwdrow_word_blank
|
16
|
+
(cwdrow_t drow, U32 i);
|
17
|
+
|
18
|
+
bool cwdrow_word_present
|
19
|
+
(cwdrow_t drow, U32 i);
|
20
|
+
|
21
|
+
bool cwdrow_exclude
|
22
|
+
(cwdrow_t drow, char const* str);
|
23
|
+
|
24
|
+
bool cwdrow_include
|
25
|
+
(cwdrow_t drow, char const* str);
|
26
|
+
|
27
|
+
void cwdrow_close
|
28
|
+
(cwdrow_t drow);
|
29
|
+
|
30
|
+
void puts_cwdrow
|
31
|
+
(cwdrow_t drow);
|
32
|
+
|
33
|
+
// dictionary utilities
|
34
|
+
I32 cwdict_find_row_of_size
|
35
|
+
(cwdict_t dict, U32 largest);
|
36
|
+
|
37
|
+
bool cwdict_blanks
|
38
|
+
(cwdict_t dict);
|
39
|
+
|
40
|
+
cwdrow_t cwdrow_open()
|
4
41
|
{
|
5
|
-
|
42
|
+
cwdrow_t d;
|
6
43
|
|
7
44
|
// set default values
|
8
45
|
d.sorted = false;
|
@@ -14,7 +51,8 @@ drow_t open_drow()
|
|
14
51
|
return d;
|
15
52
|
}
|
16
53
|
|
17
|
-
|
54
|
+
cwdrow_t cwdrow_add_word
|
55
|
+
(cwdrow_t drow, const char* word)
|
18
56
|
{
|
19
57
|
// cache strlen of word
|
20
58
|
U32 len = strlen(word);
|
@@ -43,17 +81,19 @@ drow_t add_word_to_drow(drow_t drow, const char* word)
|
|
43
81
|
return drow;
|
44
82
|
}
|
45
83
|
|
46
|
-
|
84
|
+
cwdrow_t cwdrow_add_word_strict
|
85
|
+
(cwdrow_t drow, const char* word, U32 size)
|
47
86
|
{
|
48
|
-
if(strlen(word) == size) drow =
|
87
|
+
if(strlen(word) == size) drow = cwdrow_add_word(drow, word);
|
49
88
|
return drow;
|
50
89
|
}
|
51
90
|
|
52
|
-
|
91
|
+
cwdrow_t cwdrow_sort
|
92
|
+
(cwdrow_t drow)
|
53
93
|
{
|
54
94
|
for(U32 i = 0; i != drow.count - 1; ++i)
|
55
95
|
{
|
56
|
-
if(
|
96
|
+
if(cwdrow_word_blank(drow, i) && cwdrow_word_present(drow, i + 1))
|
57
97
|
{
|
58
98
|
// bubble next one into current one
|
59
99
|
U32 len = strlen(drow.words[i + 1]);
|
@@ -75,7 +115,8 @@ drow_t bubble_drow(drow_t drow)
|
|
75
115
|
return drow;
|
76
116
|
}
|
77
117
|
|
78
|
-
bool
|
118
|
+
bool cwdrow_word_blank
|
119
|
+
(cwdrow_t drow, U32 i)
|
79
120
|
{
|
80
121
|
if(drow.words[i] == NULL || strlen(drow.words[i]) < 1)
|
81
122
|
{
|
@@ -85,7 +126,8 @@ bool drow_word_blank(drow_t drow, U32 i)
|
|
85
126
|
return false;
|
86
127
|
}
|
87
128
|
|
88
|
-
bool
|
129
|
+
bool cwdrow_word_present
|
130
|
+
(cwdrow_t drow, U32 i)
|
89
131
|
{
|
90
132
|
if(drow.words[i] != NULL && strlen(drow.words[i]) > 0)
|
91
133
|
{
|
@@ -95,7 +137,8 @@ bool drow_word_present(drow_t drow, U32 i)
|
|
95
137
|
return false;
|
96
138
|
}
|
97
139
|
|
98
|
-
bool
|
140
|
+
bool cwdrow_exclude
|
141
|
+
(cwdrow_t drow, char const* str)
|
99
142
|
{
|
100
143
|
for(U32 i = 0; i != drow.count; ++i)
|
101
144
|
{
|
@@ -105,7 +148,8 @@ bool drow_exclude(drow_t drow, char const* str)
|
|
105
148
|
return true;
|
106
149
|
}
|
107
150
|
|
108
|
-
bool
|
151
|
+
bool cwdrow_include
|
152
|
+
(cwdrow_t drow, char const* str)
|
109
153
|
{
|
110
154
|
for(U32 i = 0; i != drow.count; ++i)
|
111
155
|
{
|
@@ -115,7 +159,8 @@ bool drow_include(drow_t drow, char const* str)
|
|
115
159
|
return false;
|
116
160
|
}
|
117
161
|
|
118
|
-
char*
|
162
|
+
char* cwdrow_sample
|
163
|
+
(cwdrow_t drow)
|
119
164
|
{
|
120
165
|
// immediately fail if empty
|
121
166
|
if(drow.count == 0) return NULL;
|
@@ -126,7 +171,19 @@ char* sample_drow(drow_t drow)
|
|
126
171
|
return drow.words[internal];
|
127
172
|
}
|
128
173
|
|
129
|
-
void
|
174
|
+
void cwdrow_close
|
175
|
+
(cwdrow_t drow)
|
176
|
+
{
|
177
|
+
for(U32 i = 0; i != drow.count; ++i)
|
178
|
+
{
|
179
|
+
if(drow.words[i]) free(drow.words[i]);
|
180
|
+
}
|
181
|
+
|
182
|
+
if(drow.words) free(drow.words);
|
183
|
+
}
|
184
|
+
|
185
|
+
void puts_cwdrow
|
186
|
+
(cwdrow_t drow)
|
130
187
|
{
|
131
188
|
#ifdef DEBUG
|
132
189
|
fprintf(stdout, "(%d)", drow.count);
|
@@ -143,19 +200,12 @@ void puts_drow(drow_t drow)
|
|
143
200
|
fprintf(stdout, "]");
|
144
201
|
}
|
145
202
|
|
146
|
-
|
147
|
-
|
148
|
-
for(U32 i = 0; i != drow.count; ++i)
|
149
|
-
{
|
150
|
-
if(drow.words[i]) free(drow.words[i]);
|
151
|
-
}
|
203
|
+
I32 cwdict_find_row_of_size
|
204
|
+
(cwdict_t dict, U32 largest);
|
152
205
|
|
153
|
-
|
154
|
-
}
|
155
|
-
|
156
|
-
dict_t open_dict()
|
206
|
+
cwdict_t cwdict_open()
|
157
207
|
{
|
158
|
-
|
208
|
+
cwdict_t d;
|
159
209
|
|
160
210
|
// set default values
|
161
211
|
d.sorted = false;
|
@@ -166,9 +216,10 @@ dict_t open_dict()
|
|
166
216
|
return d;
|
167
217
|
}
|
168
218
|
|
169
|
-
|
219
|
+
cwdict_t cwdict_open_with_name
|
220
|
+
(const char* name)
|
170
221
|
{
|
171
|
-
|
222
|
+
cwdict_t d;
|
172
223
|
|
173
224
|
// set default values
|
174
225
|
d.sorted = false;
|
@@ -182,17 +233,19 @@ dict_t open_dict_with_name(const char* name)
|
|
182
233
|
return d;
|
183
234
|
}
|
184
235
|
|
185
|
-
|
236
|
+
cwdict_t cwdict_open_with_tokens
|
237
|
+
(const char* const buffer, const char* delimiters)
|
186
238
|
{
|
187
|
-
|
239
|
+
cwdict_t d = tokenize(buffer, delimiters);
|
188
240
|
d.name = NULL;
|
189
241
|
|
190
242
|
return d;
|
191
243
|
}
|
192
244
|
|
193
|
-
|
245
|
+
cwdict_t cwdict_open_with_name_and_tokens
|
246
|
+
(const char* name, const char* const buffer, const char* delimiters)
|
194
247
|
{
|
195
|
-
|
248
|
+
cwdict_t d = tokenize(buffer, delimiters);
|
196
249
|
d.name = NULL;
|
197
250
|
|
198
251
|
d.name = (char*)malloc((strlen(name) + 1) * sizeof(char));
|
@@ -201,44 +254,49 @@ dict_t open_dict_with_name_and_tokens(const char* name, const char* const buffer
|
|
201
254
|
return d;
|
202
255
|
}
|
203
256
|
|
204
|
-
|
257
|
+
cwdict_t cwdict_add_row
|
258
|
+
(cwdict_t dict, cwdrow_t drow)
|
205
259
|
{
|
206
260
|
++dict.count;
|
207
261
|
|
208
|
-
dict.drows = (
|
262
|
+
dict.drows = (cwdrow_t*)realloc(dict.drows, sizeof(cwdrow_t) * dict.count);
|
209
263
|
dict.drows[dict.count - 1] = drow;
|
210
264
|
|
211
265
|
return dict;
|
212
266
|
}
|
213
267
|
|
214
|
-
|
268
|
+
cwdict_t cwdict_add_row_strict
|
269
|
+
(cwdict_t dict, cwdrow_t drow, U32 size)
|
215
270
|
{
|
216
|
-
if(drow.count >= size) dict =
|
271
|
+
if(drow.count >= size) dict = cwdict_add_row(dict, drow);
|
217
272
|
return dict;
|
218
273
|
}
|
219
274
|
|
220
275
|
|
221
|
-
|
276
|
+
cwdict_t cwdict_place_word
|
277
|
+
(cwdict_t dict, const char* word)
|
222
278
|
{
|
223
|
-
|
279
|
+
cwdrow_t drow = cwdrow_open();
|
224
280
|
|
225
|
-
drow =
|
226
|
-
dict =
|
281
|
+
drow = cwdrow_add_word(drow, word);
|
282
|
+
dict = cwdict_add_row(dict, drow);
|
227
283
|
|
228
284
|
return dict;
|
229
285
|
}
|
230
286
|
|
231
|
-
|
287
|
+
cwdict_t cwdict_place_words
|
288
|
+
(cwdict_t dict, const char* const* words, U32 s)
|
232
289
|
{
|
233
290
|
for(U32 i = 0; i != s; ++i)
|
234
291
|
{
|
235
|
-
dict =
|
292
|
+
dict = cwdict_place_word(dict, words[i]);
|
236
293
|
}
|
237
294
|
|
238
295
|
return dict;
|
239
296
|
}
|
240
297
|
|
241
|
-
|
298
|
+
cwdict_t cwdict_place_word_strict
|
299
|
+
(cwdict_t dict, const char* word)
|
242
300
|
{
|
243
301
|
bool inserted = false;
|
244
302
|
U32 len = strlen(word);
|
@@ -247,35 +305,36 @@ dict_t place_word_in_dict_strict(dict_t dict, const char* word)
|
|
247
305
|
{
|
248
306
|
if(dict.drows[i].largest == len)
|
249
307
|
{
|
250
|
-
dict.drows[i] =
|
308
|
+
dict.drows[i] = cwdrow_add_word(dict.drows[i], word);
|
251
309
|
inserted = true;
|
252
310
|
}
|
253
311
|
}
|
254
312
|
|
255
|
-
if(inserted == false) dict =
|
313
|
+
if(inserted == false) dict = cwdict_place_word(dict, word);
|
256
314
|
|
257
315
|
return dict;
|
258
316
|
}
|
259
317
|
|
260
|
-
|
261
|
-
U32 s)
|
318
|
+
cwdict_t cwdict_place_words_strict
|
319
|
+
(cwdict_t dict, const char* const* words, U32 s)
|
262
320
|
{
|
263
321
|
for(U32 i = 0; i != s; ++i)
|
264
322
|
{
|
265
|
-
dict =
|
323
|
+
dict = cwdict_place_word_strict(dict, words[i]);
|
266
324
|
}
|
267
325
|
|
268
326
|
return dict;
|
269
327
|
}
|
270
328
|
|
271
|
-
|
329
|
+
cwdict_t cwdict_sort
|
330
|
+
(cwdict_t dict)
|
272
331
|
{
|
273
|
-
|
332
|
+
cwdrow_t temp;
|
274
333
|
|
275
334
|
// sort individual drows' contents
|
276
335
|
for(U32 i = 0; i != dict.count; ++i)
|
277
336
|
{
|
278
|
-
dict.drows[i] =
|
337
|
+
dict.drows[i] = cwdrow_sort(dict.drows[i]);
|
279
338
|
}
|
280
339
|
|
281
340
|
// sort individual drows within dict
|
@@ -297,7 +356,8 @@ dict_t bubble_dict(dict_t dict)
|
|
297
356
|
return dict;
|
298
357
|
}
|
299
358
|
|
300
|
-
|
359
|
+
cwdict_t cwdict_prune
|
360
|
+
(cwdict_t dict, bool sorted)
|
301
361
|
{
|
302
362
|
U32 len = 0, size = 0, null_count = 0;
|
303
363
|
char* against = NULL;
|
@@ -322,7 +382,7 @@ dict_t prune_dict(dict_t dict, bool sorted)
|
|
322
382
|
}
|
323
383
|
|
324
384
|
// sort drows within dict
|
325
|
-
if(sorted) dict =
|
385
|
+
if(sorted) dict = cwdict_sort(dict);
|
326
386
|
|
327
387
|
// resize individual drows within dict
|
328
388
|
for(U32 i = 0; i != dict.count; ++i)
|
@@ -344,12 +404,19 @@ dict_t prune_dict(dict_t dict, bool sorted)
|
|
344
404
|
}
|
345
405
|
}
|
346
406
|
|
347
|
-
if(
|
407
|
+
if(cwdict_blanks(dict)) dict = cwdict_prune(dict, sorted);
|
348
408
|
|
349
409
|
return dict;
|
350
410
|
}
|
351
411
|
|
352
|
-
|
412
|
+
cwdict_t cwdict_clean
|
413
|
+
(cwdict_t dict)
|
414
|
+
{
|
415
|
+
return cwdict_prune(dict, true);
|
416
|
+
}
|
417
|
+
|
418
|
+
cwdict_t cwdict_map
|
419
|
+
(cwdict_t dict, char* (*f)(char*))
|
353
420
|
{
|
354
421
|
U32 len = 0;
|
355
422
|
char* temp = (char*)malloc(sizeof(char) * SMALL_BUFFER);
|
@@ -376,18 +443,19 @@ dict_t map_dict(dict_t dict, char* (*f)(char*))
|
|
376
443
|
return dict;
|
377
444
|
}
|
378
445
|
|
379
|
-
|
446
|
+
cwdict_t cwdict_clone
|
447
|
+
(cwdict_t dict)
|
380
448
|
{
|
381
|
-
|
449
|
+
cwdict_t new;
|
382
450
|
|
383
|
-
if(dict.name) new =
|
384
|
-
else new =
|
451
|
+
if(dict.name) new = cwdict_open_with_name(dict.name);
|
452
|
+
else new = cwdict_open();
|
385
453
|
|
386
454
|
for(U32 i = 0; i != dict.count; ++i)
|
387
455
|
{
|
388
456
|
for(U32 j = 0; j != dict.drows[i].count; ++j)
|
389
457
|
{
|
390
|
-
new =
|
458
|
+
new = cwdict_place_word_strict(new, dict.drows[i].words[j]);
|
391
459
|
}
|
392
460
|
}
|
393
461
|
|
@@ -398,12 +466,19 @@ dict_t deep_copy_dict(dict_t dict)
|
|
398
466
|
new.name[strlen(dict.name)] = '\0';
|
399
467
|
}
|
400
468
|
|
401
|
-
if(dict.sorted) new =
|
469
|
+
if(dict.sorted) new = cwdict_sort(new);
|
402
470
|
|
403
471
|
return new;
|
404
472
|
}
|
405
473
|
|
406
|
-
|
474
|
+
cwdict_t cwdict_dup
|
475
|
+
(cwdict_t dict)
|
476
|
+
{
|
477
|
+
return cwdict_clone(dict);
|
478
|
+
}
|
479
|
+
|
480
|
+
bool cwdict_exclude
|
481
|
+
(cwdict_t dict, char const* str)
|
407
482
|
{
|
408
483
|
for(U32 i = 0; i != dict.count; ++i)
|
409
484
|
{
|
@@ -416,7 +491,8 @@ bool dict_exclude(dict_t dict, char const* str)
|
|
416
491
|
return true;
|
417
492
|
}
|
418
493
|
|
419
|
-
bool
|
494
|
+
bool cwdict_include
|
495
|
+
(cwdict_t dict, char const* str)
|
420
496
|
{
|
421
497
|
for(U32 i = 0; i != dict.count; ++i)
|
422
498
|
{
|
@@ -429,20 +505,22 @@ bool dict_include(dict_t dict, char const* str)
|
|
429
505
|
return false;
|
430
506
|
}
|
431
507
|
|
432
|
-
bool
|
508
|
+
bool cwdict_blanks
|
509
|
+
(cwdict_t dict)
|
433
510
|
{
|
434
511
|
for(U32 i = 0; i != dict.count; ++i)
|
435
512
|
{
|
436
513
|
for(U32 j = 0; j != dict.drows[i].count; ++j)
|
437
514
|
{
|
438
|
-
if(
|
515
|
+
if(cwdrow_word_blank(dict.drows[i], j)) return true;
|
439
516
|
}
|
440
517
|
}
|
441
518
|
|
442
519
|
return false;
|
443
520
|
}
|
444
521
|
|
445
|
-
bool
|
522
|
+
bool cwdict_valid
|
523
|
+
(cwdict_t dict, char** error)
|
446
524
|
{
|
447
525
|
U32 count = 0;
|
448
526
|
|
@@ -455,27 +533,31 @@ bool dict_valid(dict_t dict, char** error)
|
|
455
533
|
}
|
456
534
|
}
|
457
535
|
|
458
|
-
if(
|
536
|
+
if(error)
|
459
537
|
{
|
460
|
-
|
461
|
-
|
462
|
-
|
538
|
+
if(count < MIN_DICT_SIZE)
|
539
|
+
{
|
540
|
+
*error = (char*)malloc(SMALL_BUFFER);
|
541
|
+
sprintf(*error, "too few acceptable entries (%d of %d)",count,
|
542
|
+
MIN_DICT_SIZE);
|
463
543
|
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
544
|
+
return false;
|
545
|
+
}
|
546
|
+
|
547
|
+
if(dict.sorted == false)
|
548
|
+
{
|
549
|
+
*error = (char*)malloc(SMALL_BUFFER);
|
550
|
+
sprintf(*error, "dictionary couldn't be sorted");
|
471
551
|
|
472
|
-
|
552
|
+
return false;
|
553
|
+
}
|
473
554
|
}
|
474
555
|
|
475
556
|
return true;
|
476
557
|
}
|
477
558
|
|
478
|
-
bool
|
559
|
+
bool cwdict_equal
|
560
|
+
(cwdict_t dict, cwdict_t against)
|
479
561
|
{
|
480
562
|
if(dict.count != against.count) return false;
|
481
563
|
|
@@ -493,7 +575,8 @@ bool dict_equal(dict_t dict, dict_t against)
|
|
493
575
|
return true;
|
494
576
|
}
|
495
577
|
|
496
|
-
bool
|
578
|
+
bool cwdict_inequal
|
579
|
+
(cwdict_t dict, cwdict_t against)
|
497
580
|
{
|
498
581
|
if(dict.count != against.count) return true;
|
499
582
|
|
@@ -511,10 +594,11 @@ bool dict_not_equal(dict_t dict, dict_t against)
|
|
511
594
|
return false;
|
512
595
|
}
|
513
596
|
|
514
|
-
I32
|
597
|
+
I32 cwdict_find_row_of_size
|
598
|
+
(cwdict_t dict, U32 largest)
|
515
599
|
{
|
516
600
|
// sort dict if necessary
|
517
|
-
if(dict.sorted == false) dict =
|
601
|
+
if(dict.sorted == false) dict = cwdict_prune(dict, true);
|
518
602
|
|
519
603
|
for(U32 i = 0; i != dict.count; ++i)
|
520
604
|
{
|
@@ -524,7 +608,8 @@ I32 find_drow_of_size_in_dict(dict_t dict, U32 largest)
|
|
524
608
|
return -1;
|
525
609
|
}
|
526
610
|
|
527
|
-
U32
|
611
|
+
U32 cwdict_length
|
612
|
+
(cwdict_t dict)
|
528
613
|
{
|
529
614
|
U32 total = 0;
|
530
615
|
|
@@ -533,7 +618,20 @@ U32 total_dict(dict_t dict)
|
|
533
618
|
return total;
|
534
619
|
}
|
535
620
|
|
536
|
-
U32
|
621
|
+
U32 cwdict_size
|
622
|
+
(cwdict_t dict)
|
623
|
+
{
|
624
|
+
return cwdict_length(dict);
|
625
|
+
}
|
626
|
+
|
627
|
+
U32 cwdict_count
|
628
|
+
(cwdict_t dict)
|
629
|
+
{
|
630
|
+
return cwdict_length(dict);
|
631
|
+
}
|
632
|
+
|
633
|
+
U32 cwdict_largest
|
634
|
+
(cwdict_t dict)
|
537
635
|
{
|
538
636
|
U32 largest = 0;
|
539
637
|
|
@@ -546,7 +644,8 @@ U32 dict_largest(dict_t dict)
|
|
546
644
|
return largest;
|
547
645
|
}
|
548
646
|
|
549
|
-
char*
|
647
|
+
char* cwdict_sample
|
648
|
+
(cwdict_t dict)
|
550
649
|
{
|
551
650
|
// immediately fail if empty
|
552
651
|
if(dict.count == 0) return NULL;
|
@@ -554,10 +653,11 @@ char* sample_dict(dict_t dict)
|
|
554
653
|
U32 max = (dict.count == 1 ? 0 : dict.count - 1);
|
555
654
|
U32 external = (max == 0 ? 0 : motherr(0, max));
|
556
655
|
|
557
|
-
return
|
656
|
+
return cwdrow_sample(dict.drows[external]);
|
558
657
|
}
|
559
658
|
|
560
|
-
char*
|
659
|
+
char* cwdict_join
|
660
|
+
(cwdict_t dict, char const* delimiter)
|
561
661
|
{
|
562
662
|
U32 len = 0, del_len = strlen(delimiter);
|
563
663
|
char* string = NULL; char* temp = NULL;
|
@@ -595,13 +695,26 @@ char* join_dict(dict_t dict, char const* delimiter)
|
|
595
695
|
return string;
|
596
696
|
}
|
597
697
|
|
598
|
-
|
698
|
+
cwdict_t cwdict_close
|
699
|
+
(cwdict_t dict)
|
700
|
+
{
|
701
|
+
for(U32 i = 0; i != dict.count; ++i) cwdrow_close(dict.drows[i]);
|
702
|
+
if(dict.drows) { free(dict.drows); dict.drows = NULL; }
|
703
|
+
|
704
|
+
dict.count = 0;
|
705
|
+
if(dict.name) { free(dict.name); dict.name = NULL; }
|
706
|
+
|
707
|
+
return cwdict_open();
|
708
|
+
}
|
709
|
+
|
710
|
+
void puts_cwdict
|
711
|
+
(cwdict_t dict)
|
599
712
|
{
|
600
713
|
fprintf(stdout, "[");
|
601
714
|
|
602
715
|
for(U32 i = 0; i != dict.count; ++i)
|
603
716
|
{
|
604
|
-
|
717
|
+
puts_cwdrow(dict.drows[i]);
|
605
718
|
|
606
719
|
if(i < dict.count - 1) fprintf(stdout, ",");
|
607
720
|
|
@@ -613,18 +726,8 @@ void puts_dict(dict_t dict)
|
|
613
726
|
fprintf(stdout, "]");
|
614
727
|
}
|
615
728
|
|
616
|
-
|
617
|
-
|
618
|
-
for(U32 i = 0; i != dict.count; ++i) close_drow(dict.drows[i]);
|
619
|
-
if(dict.drows) { free(dict.drows); dict.drows = NULL; }
|
620
|
-
|
621
|
-
dict.count = 0;
|
622
|
-
if(dict.name) { free(dict.name); dict.name = NULL; }
|
623
|
-
|
624
|
-
return open_dict();
|
625
|
-
}
|
626
|
-
|
627
|
-
void validate_dict(dict_t dict, char const* function_name)
|
729
|
+
void validate_cwdict
|
730
|
+
(cwdict_t dict, char const* function_name)
|
628
731
|
{
|
629
732
|
U32 count = 0;
|
630
733
|
|
@@ -656,11 +759,12 @@ void validate_dict(dict_t dict, char const* function_name)
|
|
656
759
|
}
|
657
760
|
}
|
658
761
|
|
659
|
-
|
762
|
+
cwdict_t split_into_cwdict
|
763
|
+
(const char* buffer, const char* delimiters)
|
660
764
|
{
|
661
765
|
char* tok;
|
662
766
|
char* mutable_buffer = (char*)malloc(strlen(buffer) + 1 * sizeof(char));
|
663
|
-
|
767
|
+
cwdict_t dict = cwdict_open();
|
664
768
|
|
665
769
|
// get mutable copy of buffer; a bit slower, but allows for const-ness
|
666
770
|
strcpy(mutable_buffer, buffer);
|
@@ -671,7 +775,7 @@ dict_t split(const char* buffer, const char* delimiters)
|
|
671
775
|
while(tok != NULL)
|
672
776
|
{
|
673
777
|
// add word to dict
|
674
|
-
dict =
|
778
|
+
dict = cwdict_place_word(dict, tok);
|
675
779
|
|
676
780
|
// get new tok (if any)
|
677
781
|
tok = strtok(NULL, delimiters);
|
@@ -686,20 +790,20 @@ dict_t split(const char* buffer, const char* delimiters)
|
|
686
790
|
#ifdef DICTMAIN
|
687
791
|
int main(int argc, const char *argv[])
|
688
792
|
{
|
689
|
-
|
793
|
+
cwdict_t dict = cwdict_open();
|
690
794
|
// const char * const words[]= { "the", "quick", "brown", "fox", "jumps",
|
691
795
|
// "over", "the", "lazy", "dog", "dawg" };
|
692
796
|
|
693
|
-
dict =
|
694
|
-
dict =
|
797
|
+
dict = cwdict_place_words_strict(dict, argv, argc);
|
798
|
+
dict = cwdict_prune(dict, true);
|
695
799
|
|
696
800
|
#ifdef DEBUG
|
697
801
|
fprintf(stdout, "dict.count : %d\n", dict.count);
|
698
802
|
#endif
|
699
803
|
|
700
|
-
|
804
|
+
puts_cwdict(dict); fprintf(stdout, "\n");
|
701
805
|
|
702
|
-
|
806
|
+
cwdict_close(dict);
|
703
807
|
|
704
808
|
return 0;
|
705
809
|
}
|