0
|
1 /*
|
|
2 * $Id: mknode1.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 #if STDC_HEADERS
|
|
36 # include <stdlib.h>
|
|
37 #else
|
|
38 # if HAVE_MALLOC_H
|
|
39 # include <malloc.h>
|
|
40 # endif
|
|
41 #endif /* STDC_HEADERS */
|
|
42
|
|
43 #include "commonhd.h"
|
|
44 #include "de_header.h"
|
|
45 #include "kaiseki.h"
|
|
46
|
|
47 static void lnk_sbn ();
|
|
48
|
|
49 static struct SYO_BNSETSU *free_sbn_top = NULL;
|
|
50 static struct free_list *free_list_sbn = NULL;
|
|
51 /************************************************/
|
|
52 /* initialize link struct SYO_BNSETSU */
|
|
53 /************************************************/
|
|
54 int
|
|
55 init_sbn ()
|
|
56 {
|
|
57 free_area (free_list_sbn);
|
|
58 if (get_area (FIRST_SBN_KOSUU, sizeof (struct SYO_BNSETSU), &free_list_sbn) < 0)
|
|
59 return (-1);
|
|
60 lnk_sbn (free_list_sbn);
|
|
61 return (0);
|
|
62 }
|
|
63
|
|
64 int
|
|
65 get_area (kosuu, size, list)
|
|
66 register int kosuu;
|
|
67 register int size;
|
|
68 struct free_list **list;
|
|
69 {
|
|
70 register struct free_list *area;
|
|
71
|
|
72 if ((area = (struct free_list *) malloc (size * kosuu + sizeof (struct free_list))) == NULL)
|
|
73 {
|
|
74 wnn_errorno = WNN_MALLOC_INITIALIZE;
|
|
75 error1 ("Cannot Malloc in get_area.\n");
|
|
76 return (-1);
|
|
77 }
|
|
78 area->lnk = *list;
|
|
79 area->num = kosuu;
|
|
80 *list = area;
|
|
81 return (0);
|
|
82 }
|
|
83
|
|
84 void
|
|
85 free_area (list)
|
|
86 register struct free_list *list;
|
|
87 {
|
|
88 if (list == 0)
|
|
89 return;
|
|
90 free_area (list->lnk);
|
|
91 free (list);
|
|
92 }
|
|
93
|
|
94 /* free_sbn が 0 でない時に呼んだらあかんよ */
|
|
95 static void
|
|
96 lnk_sbn (list)
|
|
97 struct free_list *list;
|
|
98 {
|
|
99 register int n;
|
|
100 register struct SYO_BNSETSU *wk_ptr;
|
|
101
|
|
102 free_sbn_top = wk_ptr = (struct SYO_BNSETSU *) ((char *) list + sizeof (struct free_list));
|
|
103
|
|
104 for (n = list->num - 1; n > 0; wk_ptr++, n--)
|
|
105 wk_ptr->lnk_br = wk_ptr + 1;
|
|
106 wk_ptr->lnk_br = 0;
|
|
107 }
|
|
108
|
|
109
|
|
110 /*******************************************************/
|
|
111 /* struct SYO_BNSETSU & ICHBNP & KANGO free エリア作成 */
|
|
112 /*******************************************************/
|
|
113 void
|
|
114 freesbn (sbn) /* struct SYO_BNSETSU を free_area へリンク */
|
|
115 register struct SYO_BNSETSU *sbn; /* クリアするノードのポインタ */
|
|
116 {
|
|
117 if (sbn == 0)
|
|
118 return;
|
|
119 sbn->reference--;
|
|
120 if (sbn->reference <= 0)
|
|
121 {
|
|
122 sbn->lnk_br = free_sbn_top;
|
|
123 free_sbn_top = sbn;
|
|
124 }
|
|
125 }
|
|
126
|
|
127 void
|
|
128 clr_sbn_node (sbn)
|
|
129 register struct SYO_BNSETSU *sbn;
|
|
130 {
|
|
131 if (sbn == 0)
|
|
132 return;
|
|
133 if ((sbn->reference) <= 1)
|
|
134 {
|
|
135 freesbn (sbn);
|
|
136 clr_sbn_node (sbn->parent);
|
|
137 }
|
|
138 else
|
|
139 {
|
|
140 sbn->reference--;
|
|
141 }
|
|
142 }
|
|
143
|
|
144 /******************************************/
|
|
145 /* SYO_BNSETSU area の獲得 */
|
|
146 /******************************************/
|
|
147 struct SYO_BNSETSU *
|
|
148 getsbnsp ()
|
|
149 {
|
|
150 register struct SYO_BNSETSU *rtnptr;
|
|
151
|
|
152 if (free_sbn_top == 0)
|
|
153 {
|
|
154 if (get_area (SBN_KOSUU, sizeof (struct SYO_BNSETSU), &free_list_sbn) < 0)
|
|
155 return ((struct SYO_BNSETSU *) -1);
|
|
156 lnk_sbn (free_list_sbn);
|
|
157 }
|
|
158
|
|
159 rtnptr = free_sbn_top;
|
|
160 free_sbn_top = free_sbn_top->lnk_br;
|
|
161 rtnptr->lnk_br = 0;
|
|
162 rtnptr->parent = 0;
|
|
163 rtnptr->son_v = 0;
|
|
164 rtnptr->reference = 0;
|
|
165 rtnptr->jentptr = 0;
|
|
166 rtnptr->status = 0;
|
|
167 rtnptr->status_bkwd = 0;
|
|
168 return (rtnptr);
|
|
169 }
|