0
|
1 /*
|
|
2 * $Id: jikouho.c,v 1.4 2006/02/11 09:51:44 aonoto 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, 2006
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project
|
|
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
|
|
32 #ifdef HAVE_CONFIG_H
|
|
33 # include <config.h>
|
|
34 #endif
|
|
35
|
|
36 #include <stdio.h>
|
|
37 #if STDC_HEADERS
|
|
38 # include <string.h>
|
|
39 #else
|
|
40 # if HAVE_STRINGS_H
|
|
41 # include <strings.h>
|
|
42 # endif
|
|
43 #endif /* STDC_HEADERS */
|
|
44
|
|
45 #include "jllib.h"
|
|
46 #include "commonhd.h"
|
|
47 #include "sdefine.h"
|
|
48 #include "sheader.h"
|
|
49 #include "rk_spclval.h" /* defines of CHMSIG, NISEBP */
|
|
50 #include "buffer.h"
|
|
51
|
|
52
|
|
53
|
|
54 /* 次候補を一つずつ表示する関数
|
|
55 num = 1 のとき次候補を、num = -1 のとき前候補を表示する */
|
|
56 int
|
|
57 jikouho (num)
|
|
58 int num;
|
|
59 {
|
|
60 int tmp;
|
|
61 int mae_p;
|
|
62
|
|
63 if (!isconect_jserver ())
|
|
64 {
|
|
65 throw_c (0);
|
|
66 clr_line_all ();
|
|
67 change_to_insert_mode ();
|
|
68 c_b->t_m_start = 0;
|
|
69 cur_bnst_ = 0;
|
|
70 call_t_print_l (c_b->t_c_p, 1);
|
|
71 if (bun_data_)
|
|
72 jl_kill (bun_data_, 0, -1);
|
|
73 return (-1);
|
|
74 }
|
|
75 /* 注目している文節の次候補がまだ用意されていない時は
|
|
76 まずそれを用意する。 */
|
|
77 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
78 if (bunsetsu_env[cur_bnst_] == bunsetsu_env[cur_bnst_ + 1])
|
|
79 mae_p = WNN_USE_ZENGO;
|
|
80 else
|
|
81 mae_p = WNN_USE_MAE;
|
|
82 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_))
|
|
83 {
|
|
84 if (jl_zenkouho (bun_data_, cur_bnst_, mae_p, WNN_UNIQ) < 0)
|
|
85 {
|
|
86 errorkeyin ();
|
|
87 t_print_l ();
|
|
88 return (-1);
|
|
89 }
|
|
90 }
|
|
91
|
|
92 if (num == 1)
|
|
93 jl_next (bun_data_);
|
|
94 else if (num == -1)
|
|
95 jl_previous (bun_data_);
|
|
96 else
|
|
97 return (-1);
|
|
98 make_kanji_buffer (cur_bnst_);
|
|
99 tmp = c_b->t_b_st;
|
|
100 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
101 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)]; /* ADD KURI */
|
|
102 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
103 t_redraw_move (bunsetsu[cur_bnst_], min (tmp, c_b->t_b_st), c_b->maxlen, 1);
|
|
104 return (0);
|
|
105 }
|
|
106
|
|
107 /* 次候補を一つずつ表示する関数
|
|
108 num = 1 のとき次候補を、num = -1 のとき前候補を表示する */
|
|
109 int
|
|
110 jikouho_dai (num)
|
|
111 int num;
|
|
112 {
|
|
113 int tmp;
|
|
114 int mae_p;
|
|
115
|
|
116 if (!isconect_jserver ())
|
|
117 {
|
|
118 throw_c (0);
|
|
119 clr_line_all ();
|
|
120 change_to_insert_mode ();
|
|
121 c_b->t_m_start = 0;
|
|
122 cur_bnst_ = 0;
|
|
123 call_t_print_l (c_b->t_c_p, 1);
|
|
124 if (bun_data_)
|
|
125 jl_kill (bun_data_, 0, -1);
|
|
126 return (-1);
|
|
127 }
|
|
128 /* 注目している文節の次候補がまだ用意されていない時は
|
|
129 まずそれを用意する。 */
|
|
130 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
131 if (bunsetsu_env[cur_bnst_] == bunsetsu_env[dai_end (bun_data_, cur_bnst_)])
|
|
132 mae_p = WNN_USE_ZENGO;
|
|
133 else
|
|
134 mae_p = WNN_USE_MAE;
|
|
135 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || !jl_zenkouho_daip (bun_data_))
|
|
136 {
|
|
137 if (jl_zenkouho_dai (bun_data_, cur_bnst_, dai_end (bun_data_, cur_bnst_), mae_p, WNN_UNIQ) < 0)
|
|
138 {
|
|
139 errorkeyin ();
|
|
140 t_print_l ();
|
|
141 return (-1);
|
|
142 }
|
|
143 }
|
|
144
|
|
145 if (num == 1)
|
|
146 jl_next_dai (bun_data_);
|
|
147 else if (num == -1)
|
|
148 jl_previous_dai (bun_data_);
|
|
149 else
|
|
150 return (-1);
|
|
151 make_kanji_buffer (cur_bnst_);
|
|
152 for (tmp = cur_bnst_ + 1; tmp < jl_bun_suu (bun_data_); tmp++)
|
|
153 bunsetsu_env[tmp] = jl_env_get (bun_data_);
|
|
154 tmp = c_b->t_b_st;
|
|
155 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
156 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
|
|
157 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
158 t_redraw_move (bunsetsu[cur_bnst_], min (tmp, c_b->t_b_st), c_b->maxlen, 1);
|
|
159 return (0);
|
|
160 }
|
|
161
|
|
162 int
|
|
163 jikouho_c ()
|
|
164 {
|
|
165 jikouho (1);
|
|
166 return (0);
|
|
167 }
|
|
168
|
|
169 int
|
|
170 zenkouho_c ()
|
|
171 {
|
|
172 jikouho (-1);
|
|
173 return (0);
|
|
174 }
|
|
175
|
|
176 int
|
|
177 jikouho_dai_c ()
|
|
178 {
|
|
179 jikouho_dai (1);
|
|
180 return (0);
|
|
181 }
|
|
182
|
|
183 int
|
|
184 zenkouho_dai_c ()
|
|
185 {
|
|
186 jikouho_dai (-1);
|
|
187 return (0);
|
|
188 }
|
|
189
|
|
190 int
|
|
191 select_jikouho ()
|
|
192 {
|
|
193 if (select_jikouho1 (WNN_SHO) == -1)
|
|
194 {
|
|
195 t_print_l ();
|
|
196 }
|
|
197 else
|
|
198 {
|
|
199 redraw_line ();
|
|
200 }
|
|
201 return (0);
|
|
202 }
|
|
203
|
|
204 int
|
|
205 select_jikouho_dai ()
|
|
206 {
|
|
207 if (select_jikouho1 (WNN_DAI) == -1)
|
|
208 {
|
|
209 t_print_l ();
|
|
210 }
|
|
211 else
|
|
212 {
|
|
213 redraw_line ();
|
|
214 }
|
|
215 return (0);
|
|
216 }
|
|
217
|
|
218 int
|
|
219 dai_top (buf, bnst)
|
|
220 struct wnn_buf *buf;
|
|
221 int bnst;
|
|
222 {
|
|
223 if (bnst >= jl_bun_suu (buf))
|
|
224 return (jl_bun_suu (buf));
|
|
225 for (; bnst >= 0 && !jl_dai_top (buf, bnst); bnst--);
|
|
226 return (bnst);
|
|
227 }
|
|
228
|
|
229 int
|
|
230 dai_end (buf, bnst)
|
|
231 struct wnn_buf *buf;
|
|
232 int bnst;
|
|
233 {
|
|
234 for (bnst++; bnst < jl_bun_suu (buf) && !jl_dai_top (buf, bnst); bnst++);
|
|
235 return (bnst);
|
|
236 }
|
|
237
|
|
238 int
|
|
239 select_jikouho1 (daip)
|
|
240 int daip;
|
|
241 {
|
|
242 char *j_retu[MAXJIKOUHO];
|
|
243 char jikouho_heap[MAXJIKOUHO * 10];
|
|
244 int c;
|
|
245 int tmp;
|
|
246
|
|
247 if (!isconect_jserver ())
|
|
248 {
|
|
249 throw_c (0);
|
|
250 clr_line_all ();
|
|
251 change_to_insert_mode ();
|
|
252 c_b->t_m_start = 0;
|
|
253 cur_bnst_ = 0;
|
|
254 call_t_print_l (c_b->t_c_p, 1);
|
|
255 if (bun_data_)
|
|
256 jl_kill (bun_data_, 0, -1);
|
|
257 return (-1);
|
|
258 }
|
|
259
|
|
260 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_) != daip)
|
|
261 {
|
|
262 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
263 if (daip)
|
|
264 {
|
|
265 if (jl_zenkouho_dai (bun_data_, cur_bnst_, dai_end (bun_data_, cur_bnst_), WNN_USE_ZENGO, WNN_UNIQ) == -1)
|
|
266 {
|
|
267 errorkeyin ();
|
|
268 t_print_l ();
|
|
269 return (-1);
|
|
270 }
|
|
271 }
|
|
272 else
|
|
273 {
|
|
274 if (jl_zenkouho (bun_data_, cur_bnst_, WNN_USE_ZENGO, WNN_UNIQ) == -1)
|
|
275 {
|
|
276 errorkeyin ();
|
|
277 t_print_l ();
|
|
278 return (-1);
|
|
279 }
|
|
280 }
|
|
281 }
|
|
282 if (make_jikouho_retu (jikouho_heap, MAXJIKOUHO * 10, j_retu, MAXJIKOUHO) == -1)
|
|
283 {
|
|
284 print_msg_getc (MSG_GET (5));
|
|
285 /*
|
|
286 print_msg_getc("候補が多過ぎて次候補が取り出せません。(如何)");
|
|
287 */
|
|
288 return (-1);
|
|
289 }
|
|
290
|
|
291 if ((c = select_one_element (j_retu, jl_zenkouho_suu (bun_data_), jl_c_zenkouho (bun_data_), "", 0, 0, main_table[4])) == -1)
|
|
292 {
|
|
293 return (-1);
|
|
294 }
|
|
295 if (daip == WNN_SHO)
|
|
296 {
|
|
297 jl_set_jikouho (bun_data_, c);
|
|
298 }
|
|
299 else
|
|
300 {
|
|
301 jl_set_jikouho_dai (bun_data_, c);
|
|
302 }
|
|
303 make_kanji_buffer (cur_bnst_);
|
|
304 for (tmp = cur_bnst_ + 1; tmp < jl_bun_suu (bun_data_); tmp++)
|
|
305 bunsetsu_env[tmp] = jl_env_get (bun_data_);
|
|
306 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
307 c_b->t_c_p = bunsetsu[cur_bnst_];
|
|
308 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
|
|
309 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
310 return (0);
|
|
311 }
|
|
312
|
|
313
|
|
314 int
|
|
315 make_jikouho_retu (h, h_m, r, r_m)
|
|
316 char *h;
|
|
317 int h_m;
|
|
318 int r_m;
|
|
319 char *r[];
|
|
320 {
|
|
321 int k;
|
|
322 char *c = h;
|
|
323 w_char tmp[512];
|
|
324 char tmp1[512];
|
|
325
|
|
326 if (r_m <= jl_zenkouho_suu (bun_data_))
|
|
327 return (-1);
|
|
328
|
|
329 for (k = 0; k < jl_zenkouho_suu (bun_data_); k++)
|
|
330 {
|
|
331 r[k] = c;
|
|
332 tmp[0] = 0;
|
|
333 jl_get_zenkouho_kanji (bun_data_, k, tmp);
|
|
334 if (print_out_func)
|
|
335 (*print_out_func) (tmp, tmp, Strlen (tmp));
|
|
336 wnn_delete_w_ss2 (tmp, Strlen (tmp));
|
|
337
|
|
338 sStrcpy (tmp1, tmp);
|
|
339 if (c + strlen (tmp1) + 1 >= h_m + h)
|
|
340 {
|
|
341 return (-1);
|
|
342 }
|
|
343 set_escape_code (tmp1);
|
|
344 strcpy (c, tmp1);
|
|
345 c += strlen (tmp1) + 1;
|
|
346 }
|
|
347 return (0);
|
|
348 }
|
|
349
|
|
350 void
|
|
351 set_escape_code (x)
|
|
352 char *x;
|
|
353 {
|
|
354 int m;
|
|
355 char buf[512];
|
|
356 char *tmp;
|
|
357
|
|
358 for (m = 0, tmp = x; *tmp; tmp++)
|
|
359 {
|
|
360 if (ESCAPE_CHAR ((*tmp & 0xff)))
|
|
361 {
|
|
362 buf[m++] = '^';
|
|
363 if (*tmp == 0x7f)
|
|
364 buf[m++] = '?';
|
|
365 else
|
|
366 buf[m++] = (*tmp + 'A' - 1);
|
|
367 }
|
|
368 else
|
|
369 {
|
|
370 buf[m++] = *tmp;
|
|
371 }
|
|
372 }
|
|
373 buf[m] = NULL;
|
|
374 strcpy (x, buf);
|
|
375 }
|