Mercurial > freewnn
comparison Wnn/jserver/hinsi_list.c @ 0:bbc77ca4def5
initial import
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 13 Dec 2007 04:30:14 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bbc77ca4def5 |
---|---|
1 /* | |
2 * $Id: hinsi_list.c,v 1.5 2002/05/12 22:51:16 hiroo Exp $ | |
3 */ | |
4 | |
5 /* | |
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system. | |
7 * This file is part of FreeWnn. | |
8 * | |
9 * Copyright Kyoto University Research Institute for Mathematical Sciences | |
10 * 1987, 1988, 1989, 1990, 1991, 1992 | |
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999 | |
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992 | |
13 * Copyright FreeWnn Project 1999, 2000, 2002 | |
14 * | |
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp> | |
16 * | |
17 * This program is free software; you can redistribute it and/or modify | |
18 * it under the terms of the GNU General Public License as published by | |
19 * the Free Software Foundation; either version 2 of the License, or | |
20 * (at your option) any later version. | |
21 * | |
22 * This program is distributed in the hope that it will be useful, | |
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 * GNU General Public License for more details. | |
26 * | |
27 * You should have received a copy of the GNU General Public License | |
28 * along with this program; if not, write to the Free Software | |
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
30 */ | |
31 #ifdef HAVE_CONFIG_H | |
32 # include <config.h> | |
33 #endif | |
34 | |
35 #include <stdio.h> | |
36 #if STDC_HEADERS | |
37 # include <stdlib.h> | |
38 #else | |
39 # if HAVE_MALLOC_H | |
40 # include <malloc.h> | |
41 # endif | |
42 #endif /* STDC_HEADERS */ | |
43 | |
44 #include "commonhd.h" | |
45 #include "wnn_config.h" | |
46 #include "de_header.h" | |
47 #include "wnnerror.h" | |
48 #include "jslib.h" | |
49 #include "hinsi_file.h" | |
50 #include "jdata.h" | |
51 | |
52 static int Strtime (), get_a_word (); | |
53 | |
54 void | |
55 make_hinsi_list (jtl) | |
56 struct JT *jtl; | |
57 { | |
58 int k, state, cnt = 0, wc; | |
59 w_char *j, *d, *start; | |
60 | |
61 if (jtl->maxhinsi_list == 0) | |
62 { | |
63 jtl->node = (struct wnn_hinsi_node *) malloc (0); | |
64 jtl->maxnode = 0; | |
65 return; | |
66 } | |
67 jtl->maxnode = Strtime (jtl->hinsi_list, jtl->maxhinsi_list, NODE_CHAR); | |
68 jtl->node = (struct wnn_hinsi_node *) malloc (jtl->maxnode * sizeof (struct wnn_hinsi_node) + jtl->maxhinsi_list * sizeof (w_char)); | |
69 d = (w_char *) (jtl->node + jtl->maxnode); | |
70 if (jtl->hinsi_list == NULL) | |
71 return; | |
72 j = jtl->hinsi_list; | |
73 k = -1; | |
74 for (;;) | |
75 { | |
76 wc = get_a_word (j, &start, &state); | |
77 if (state == 2 && wc == 0) | |
78 { | |
79 break; | |
80 } | |
81 Strncpy (d, start, wc); | |
82 d[wc] = 0; | |
83 if (state == 2) | |
84 { | |
85 cnt++; | |
86 break; | |
87 } | |
88 if (state == 1) | |
89 { | |
90 if (k >= 0) | |
91 jtl->node[k].kosuu = cnt; | |
92 cnt = 0; | |
93 k++; | |
94 jtl->node[k].name = d; | |
95 jtl->node[k].son = d + wc + 1; | |
96 } | |
97 else | |
98 { | |
99 cnt++; | |
100 } | |
101 d += wc + 1; | |
102 j = start + wc + 1; | |
103 } | |
104 if (k >= 0) | |
105 jtl->node[k].kosuu = cnt; | |
106 } | |
107 | |
108 | |
109 static int | |
110 Strtime (w, wc, c) | |
111 w_char *w; | |
112 int wc; | |
113 w_char c; | |
114 { | |
115 int ret = 0; | |
116 for (; wc; wc--, w++) | |
117 { | |
118 if (*w == c) | |
119 ret++; | |
120 } | |
121 return (ret); | |
122 } | |
123 | |
124 static int | |
125 get_a_word (d, startp, statep) | |
126 w_char *d, **startp; | |
127 int *statep; | |
128 { | |
129 w_char *d0 = d; | |
130 int c, wc; | |
131 for (;;) | |
132 { | |
133 if ((c = *d++) == 0) | |
134 { | |
135 *statep = 2; | |
136 *startp = d0; | |
137 return (0); | |
138 } | |
139 if (c == IGNORE_CHAR1 || c == IGNORE_CHAR2 || c == CONTINUE_CHAR || c == '\n' || c == HINSI_SEPARATE_CHAR) | |
140 { | |
141 continue; | |
142 } | |
143 if (c == COMMENT_CHAR) | |
144 { | |
145 for (; (*d++ != '\n');); | |
146 continue; | |
147 } | |
148 break; | |
149 } | |
150 *startp = d - 1; | |
151 wc = 1; | |
152 for (;; wc++) | |
153 { | |
154 if ((c = *d++) == 0) | |
155 { | |
156 *statep = 2; | |
157 return (wc); | |
158 } | |
159 if (c == IGNORE_CHAR1 || c == IGNORE_CHAR2 || c == CONTINUE_CHAR || c == '\n' || c == HINSI_SEPARATE_CHAR) | |
160 { | |
161 *statep = 0; | |
162 return (wc); | |
163 } | |
164 else if (c == NODE_CHAR) | |
165 { | |
166 *statep = 1; | |
167 return (wc); | |
168 } | |
169 } | |
170 } | |
171 | |
172 int | |
173 has_dict (n, m, w) | |
174 struct wnn_hinsi_node *n; | |
175 int m; | |
176 w_char *w; | |
177 { | |
178 int j; | |
179 for (; m; m--) | |
180 { | |
181 if (Strcmp (n[m].name, w) == 0) | |
182 for (j = n[m].kosuu; j; j--) | |
183 { | |
184 if (Strcmp (n[m].son[j], w) == 0) | |
185 return (1); | |
186 } | |
187 } | |
188 return (0); | |
189 } | |
190 | |
191 int | |
192 hinsi_table_set (jtl, table) | |
193 struct JT *jtl; | |
194 w_char *table; | |
195 { | |
196 /* | |
197 int len; | |
198 */ | |
199 | |
200 free (jtl->node); | |
201 free (jtl->hinsi_list); | |
202 | |
203 jtl->maxhinsi_list = Strlen (table); | |
204 | |
205 jtl->hinsi_list = (w_char *) malloc (jtl->maxhinsi_list * sizeof (w_char)); | |
206 Strcpy (jtl->hinsi_list, table); | |
207 make_hinsi_list (jtl); | |
208 jtl->dirty = 1; | |
209 return (0); | |
210 } |