0
|
1 /*
|
|
2 * $Id: mknode2.c,v 1.4 2002/05/12 22:51:17 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 "commonhd.h"
|
|
36 #include "de_header.h"
|
|
37 #include "kaiseki.h"
|
|
38
|
|
39 static void lnk_jkdbn (), lnk_jksbn (), lnk_jksone (), freejktsone ();
|
|
40
|
|
41 static struct JKT_DBN *free_jkdbn_top = NULL;
|
|
42 static struct free_list *free_list_jkdbn = NULL;
|
|
43 static struct JKT_SBN *free_jksbn_top = NULL;
|
|
44 static struct free_list *free_list_jksbn = NULL;
|
|
45 static struct JKT_SONE *free_jksone_top = NULL;
|
|
46 static struct free_list *free_list_jksone = NULL;
|
|
47
|
|
48 /************************************************/
|
|
49 /* initialize link struct JKT_SONE */
|
|
50 /************************************************/
|
|
51 int
|
|
52 init_jktdbn ()
|
|
53 {
|
|
54 free_area (free_list_jkdbn);
|
|
55 if (get_area (FIRST_JKDBN_KOSUU, sizeof (struct JKT_DBN), &free_list_jkdbn) < 0)
|
|
56 return (-1);
|
|
57 lnk_jkdbn (free_list_jkdbn);
|
|
58 return (0);
|
|
59 }
|
|
60
|
|
61 /* free_jkdbn が 0 でない時に呼んだらあかんよ */
|
|
62 static void
|
|
63 lnk_jkdbn (list)
|
|
64 struct free_list *list;
|
|
65 {
|
|
66 register int n;
|
|
67 register struct JKT_DBN *wk_ptr;
|
|
68
|
|
69 free_jkdbn_top = wk_ptr = (struct JKT_DBN *) ((char *) list + sizeof (struct free_list));
|
|
70
|
|
71 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
72 wk_ptr->lnk_br = wk_ptr + 1;
|
|
73 wk_ptr->lnk_br = 0;
|
|
74 }
|
|
75
|
|
76 int
|
|
77 init_jktsbn ()
|
|
78 {
|
|
79 free_area (free_list_jksbn);
|
|
80 if (get_area (FIRST_JKSBN_KOSUU, sizeof (struct JKT_SBN), &free_list_jksbn) < 0)
|
|
81 return (-1);
|
|
82 lnk_jksbn (free_list_jksbn);
|
|
83 return (0);
|
|
84 }
|
|
85
|
|
86 /* free_jksbn が 0 でない時に呼んだらあかんよ */
|
|
87 static void
|
|
88 lnk_jksbn (list)
|
|
89 struct free_list *list;
|
|
90 {
|
|
91 register int n;
|
|
92 register struct JKT_SBN *wk_ptr;
|
|
93
|
|
94 free_jksbn_top = wk_ptr = (struct JKT_SBN *) ((char *) list + sizeof (struct free_list));
|
|
95
|
|
96 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
97 wk_ptr->lnk_br = wk_ptr + 1;
|
|
98 wk_ptr->lnk_br = 0;
|
|
99 }
|
|
100
|
|
101 int
|
|
102 init_jktsone ()
|
|
103 {
|
|
104 free_area (free_list_jksone);
|
|
105 if (get_area (FIRST_JKSONE_KOSUU, sizeof (struct JKT_SONE), &free_list_jksone) < 0)
|
|
106 return (-1);
|
|
107 lnk_jksone (free_list_jksone);
|
|
108 return (0);
|
|
109 }
|
|
110
|
|
111 /* free_jksone_top が 0 でない時に呼んだらあかんよ */
|
|
112 static void
|
|
113 lnk_jksone (list)
|
|
114 struct free_list *list;
|
|
115 {
|
|
116 register int n;
|
|
117 register struct JKT_SONE *wk_ptr;
|
|
118
|
|
119 free_jksone_top = wk_ptr = (struct JKT_SONE *) ((char *) list + sizeof (struct free_list));
|
|
120
|
|
121 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
122 wk_ptr->lnk_br = wk_ptr + 1;
|
|
123 wk_ptr->lnk_br = 0;
|
|
124 }
|
|
125
|
|
126 /*******************************************************/
|
|
127 /* struct JKT_SONE & JKT_SBN free エリア作成 */
|
|
128 /*******************************************************/
|
|
129 void
|
|
130 freejktdbn (dbn) /* struct JKT_SBN を free_area へリンク */
|
|
131 register struct JKT_DBN *dbn; /* クリアするノードのポインタ */
|
|
132 {
|
|
133 if (dbn == 0)
|
|
134 return;
|
|
135
|
|
136 freejktsbn (dbn->sbn);
|
|
137 dbn->lnk_br = free_jkdbn_top;
|
|
138 free_jkdbn_top = dbn;
|
|
139 }
|
|
140
|
|
141 void
|
|
142 freejktsbn (sbn) /* struct JKT_SBN を free_area へリンク */
|
|
143 struct JKT_SBN *sbn; /* クリアするノードのポインタ */
|
|
144 {
|
|
145 register struct JKT_SONE *sone;
|
|
146 register struct JKT_SONE *next;
|
|
147 if (sbn == 0)
|
|
148 return;
|
|
149 sbn->reference--;
|
|
150 if (sbn->reference <= 0)
|
|
151 {
|
|
152 for (sone = sbn->sbn; sone != 0;)
|
|
153 {
|
|
154 next = sone->lnk_br;
|
|
155 freejktsone (sone);
|
|
156 sone = next;
|
|
157 }
|
|
158 sbn->reference = 0;
|
|
159 sbn->lnk_br = free_jksbn_top;
|
|
160 free_jksbn_top = sbn;
|
|
161 freejktsbn (sbn->parent);
|
|
162 }
|
|
163 }
|
|
164
|
|
165 static void
|
|
166 freejktsone (sone) /* struct JKT_SONE を free_area へリンク */
|
|
167 register struct JKT_SONE *sone; /* クリアするノードのポインタ */
|
|
168 {
|
|
169 if (sone == 0)
|
|
170 return;
|
|
171 sone->lnk_br = free_jksone_top;
|
|
172 free_jksone_top = sone;
|
|
173 }
|
|
174
|
|
175 /******************************************/
|
|
176 /* JKT_SBN JKT_SONE area の獲得 */
|
|
177 /******************************************/
|
|
178 struct JKT_DBN *
|
|
179 getjktdbn ()
|
|
180 {
|
|
181 register struct JKT_DBN *rtnptr;
|
|
182
|
|
183 if (free_jkdbn_top == 0)
|
|
184 {
|
|
185 if (get_area (JKDBN_KOSUU, sizeof (struct JKT_DBN), &free_list_jkdbn) < 0)
|
|
186 return ((struct JKT_DBN *) -1);
|
|
187 lnk_jkdbn (free_list_jkdbn);
|
|
188 }
|
|
189
|
|
190 rtnptr = free_jkdbn_top;
|
|
191 free_jkdbn_top = free_jkdbn_top->lnk_br;
|
|
192 rtnptr->lnk_br = 0;
|
|
193 return (rtnptr);
|
|
194 }
|
|
195
|
|
196 struct JKT_SBN *
|
|
197 getjktsbn ()
|
|
198 {
|
|
199 register struct JKT_SBN *rtnptr;
|
|
200
|
|
201 if (free_jksbn_top == 0)
|
|
202 {
|
|
203 if (get_area (JKSBN_KOSUU, sizeof (struct JKT_SBN), &free_list_jksbn) < 0)
|
|
204 return ((struct JKT_SBN *) -1);
|
|
205 lnk_jksbn (free_list_jksbn);
|
|
206 }
|
|
207
|
|
208 rtnptr = free_jksbn_top;
|
|
209 free_jksbn_top = free_jksbn_top->lnk_br;
|
|
210 rtnptr->lnk_br = 0;
|
|
211 rtnptr->reference = 0;
|
|
212 rtnptr->status = 0;
|
|
213 return (rtnptr);
|
|
214 }
|
|
215
|
|
216 struct JKT_SONE *
|
|
217 getjktsone ()
|
|
218 {
|
|
219 register struct JKT_SONE *rtnptr;
|
|
220
|
|
221 if (free_jksone_top == 0)
|
|
222 {
|
|
223 if (get_area (JKSONE_KOSUU, sizeof (struct JKT_SONE), &free_list_jksone) < 0)
|
|
224 return ((struct JKT_SONE *) -1);
|
|
225 lnk_jksone (free_list_jksone);
|
|
226 }
|
|
227
|
|
228 rtnptr = free_jksone_top;
|
|
229 free_jksone_top = free_jksone_top->lnk_br;
|
|
230 rtnptr->lnk_br = 0;
|
|
231 rtnptr->jentptr = 0;
|
|
232 return (rtnptr);
|
|
233 }
|