1 /*
2  * wordlist.h -
3  *
4  * Written By:  MURAOKA Taro <koron@tka.att.ne.jp>
5  * Last Change: 20-Sep-2009.
6  */
7 module migemo_d.wordlist;
8 
9 
10 private static import core.memory;
11 private static import core.stdc..string;
12 
13 public struct _wordlist_t
14 {
15 	char* ptr_;
16 
17 	deprecated
18 	alias ptr = ptr_;
19 
20 	.wordlist_p next;
21 }
22 
23 public alias wordlist_t = ._wordlist_t;
24 public alias wordlist_p = ._wordlist_t*;
25 
26 public int n_wordlist_open = 0;
27 public int n_wordlist_close = 0;
28 public int n_wordlist_total = 0;
29 
30 extern (C)
31 nothrow @nogc
32 public .wordlist_p wordlist_open_len(const char* ptr_, int len)
33 
34 	do
35 	{
36 		if ((ptr_ != null) && (len >= 0)) {
37 			.wordlist_p p = cast(.wordlist_p)(core.memory.pureMalloc((*.wordlist_p).sizeof + len + 1));
38 
39 			if (p != null) {
40 				p.ptr_ = cast(char*)(p + 1);
41 				p.next = null;
42 				p.ptr_[0 .. len] = ptr_[0 .. len];
43 				p.ptr_[len] = '\0';
44 
45 				++.n_wordlist_open;
46 				.n_wordlist_total += len;
47 			}
48 
49 			return p;
50 		}
51 
52 		return null;
53 	}
54 
55 extern (C)
56 nothrow @nogc
57 public .wordlist_p wordlist_open(const char* ptr_)
58 
59 	do
60 	{
61 		.wordlist_p p;
62 
63 		if (ptr_ != null) {
64 			size_t len = core.stdc..string.strlen(ptr_);
65 			p = .wordlist_open_len(ptr_, ((len < int.max) ? (cast(int)(len)) : (int.max)));
66 		}
67 
68 		return p;
69 	}
70 
71 extern (C)
72 nothrow @nogc
73 public void wordlist_close(.wordlist_p p)
74 
75 	do
76 	{
77 		while (p != null) {
78 			.wordlist_p next = p.next;
79 
80 			++.n_wordlist_close;
81 			core.memory.pureFree(p);
82 			p = next;
83 		}
84 	}