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