0
|
1 /*
|
|
2 * $Id: jikouho.c,v 1.2 2001/06/14 18:16:16 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 1991, 1992 by Massachusetts Institute of Technology
|
|
14 *
|
|
15 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.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, or (at your option)
|
|
20 * 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 GNU Emacs; see the file COPYING. If not, write to the
|
|
29 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
30 *
|
|
31 * Commentary:
|
|
32 *
|
|
33 * Change log:
|
|
34 *
|
|
35 * Last modified date: 8,Feb.1999
|
|
36 *
|
|
37 * Code:
|
|
38 *
|
|
39 */
|
|
40 /* Version 4.0
|
|
41 */
|
|
42 #include <stdio.h>
|
|
43 #include "commonhd.h"
|
|
44 #include "sdefine.h"
|
|
45 #include "xim.h"
|
|
46 #include "sheader.h"
|
|
47 #include "ext.h"
|
|
48
|
|
49
|
|
50 /* add by KUWA */
|
|
51 int
|
|
52 dai_top (buf, bnst)
|
|
53 struct wnn_buf *buf;
|
|
54 int bnst;
|
|
55 {
|
|
56 if (bnst >= jl_bun_suu (buf))
|
|
57 return (jl_bun_suu (buf));
|
|
58 for (; bnst >= 0 && !jl_dai_top (buf, bnst); bnst--);
|
|
59 return (bnst);
|
|
60 }
|
|
61
|
|
62 int
|
|
63 dai_end (buf, bnst)
|
|
64 struct wnn_buf *buf;
|
|
65 int bnst;
|
|
66 {
|
|
67 for (bnst++; bnst < jl_bun_suu (buf) && !jl_dai_top (buf, bnst); bnst++);
|
|
68 return (bnst);
|
|
69 }
|
|
70
|
|
71 void
|
|
72 set_escape_code (x)
|
|
73 char *x;
|
|
74 {
|
|
75 int m;
|
|
76 char buf[512];
|
|
77 char *tmp;
|
|
78
|
|
79 for (m = 0, tmp = x; *tmp; tmp++)
|
|
80 {
|
|
81 if (ESCAPE_CHAR ((*tmp & 0xff)))
|
|
82 {
|
|
83 buf[m++] = '^';
|
|
84 if (*tmp == 0x7f)
|
|
85 buf[m++] = '?';
|
|
86 else
|
|
87 buf[m++] = (*tmp + 'A' - 1);
|
|
88 }
|
|
89 else
|
|
90 {
|
|
91 buf[m++] = *tmp;
|
|
92 }
|
|
93 }
|
|
94 buf[m] = '\0';
|
|
95 strcpy (x, buf);
|
|
96 }
|
|
97
|
|
98 /* ¼¡¸õÊä¤ò°ì¤Ä¤º¤Äɽ¼¨¤¹¤ë´Ø¿ô
|
|
99 num = 1 ¤Î¤È¤¼¡¸õÊä¤ò¡¢num = -1 ¤Î¤È¤Á°¸õÊä¤òɽ¼¨¤¹¤ë */
|
|
100 static int
|
|
101 jikouho (num)
|
|
102 int num;
|
|
103 {
|
|
104 int tmp;
|
|
105 int mae_p;
|
|
106 /* ÃíÌܤ·¤Æ¤¤¤ëʸÀá¤Î¼¡¸õÊ䤬¤Þ¤ÀÍÑ°Õ¤µ¤ì¤Æ¤¤¤Ê¤¤»þ¤Ï
|
|
107 ¤Þ¤º¤½¤ì¤òÍÑ°Õ¤¹¤ë¡£ */
|
|
108 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
109 if (bunsetsu_env[cur_bnst_] == bunsetsu_env[cur_bnst_ + 1])
|
|
110 mae_p = WNN_USE_ZENGO;
|
|
111 else
|
|
112 mae_p = WNN_USE_MAE;
|
|
113 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_))
|
|
114 {
|
|
115 if (jl_zenkouho (bun_data_, cur_bnst_, mae_p, WNN_UNIQ) < 0)
|
|
116 {
|
|
117 errorkeyin ();
|
|
118 return (-1);
|
|
119 }
|
|
120 }
|
|
121
|
|
122 if (num == 1)
|
|
123 jl_next (bun_data_);
|
|
124 else if (num == -1)
|
|
125 jl_previous (bun_data_);
|
|
126 else
|
|
127 return (-1);
|
|
128 make_kanji_buffer (cur_bnst_);
|
|
129
|
|
130 tmp = c_b->t_b_st;
|
|
131 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
132 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
|
|
133 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
134 t_redraw_move (bunsetsu[cur_bnst_], MIN_VAL (tmp, c_b->t_b_st), c_b->maxlen, 1);
|
|
135 check_scroll ();
|
|
136 return (0);
|
|
137 }
|
|
138
|
|
139 /* ¼¡¸õÊä¤ò°ì¤Ä¤º¤Äɽ¼¨¤¹¤ë´Ø¿ô
|
|
140 num = 1 ¤Î¤È¤¼¡¸õÊä¤ò¡¢num = -1 ¤Î¤È¤Á°¸õÊä¤òɽ¼¨¤¹¤ë */
|
|
141 static int
|
|
142 jikouho_dai (num)
|
|
143 int num;
|
|
144 {
|
|
145 int tmp;
|
|
146 int mae_p;
|
|
147 /* ÃíÌܤ·¤Æ¤¤¤ëʸÀá¤Î¼¡¸õÊ䤬¤Þ¤ÀÍÑ°Õ¤µ¤ì¤Æ¤¤¤Ê¤¤»þ¤Ï
|
|
148 ¤Þ¤º¤½¤ì¤òÍÑ°Õ¤¹¤ë¡£ */
|
|
149 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
150 if (bunsetsu_env[cur_bnst_] == bunsetsu_env[dai_end (bun_data_, cur_bnst_)])
|
|
151 mae_p = WNN_USE_ZENGO;
|
|
152 else
|
|
153 mae_p = WNN_USE_MAE;
|
|
154 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || !jl_zenkouho_daip (bun_data_))
|
|
155 {
|
|
156 if (jl_zenkouho_dai (bun_data_, cur_bnst_, dai_end (bun_data_, cur_bnst_), mae_p, WNN_UNIQ) < 0)
|
|
157 {
|
|
158 errorkeyin ();
|
|
159 return (-1);
|
|
160 }
|
|
161 }
|
|
162
|
|
163 if (num == 1)
|
|
164 jl_next_dai (bun_data_);
|
|
165 else if (num == -1)
|
|
166 jl_previous_dai (bun_data_);
|
|
167 else
|
|
168 return (-1);
|
|
169 make_kanji_buffer (cur_bnst_);
|
|
170 for (tmp = cur_bnst_ + 1; tmp < jl_bun_suu (bun_data_); tmp++)
|
|
171 bunsetsu_env[tmp] = jl_env_get (bun_data_);
|
|
172 tmp = c_b->t_b_st;
|
|
173 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
174 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
|
|
175 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
176 t_redraw_move (bunsetsu[cur_bnst_], MIN_VAL (tmp, c_b->t_b_st), c_b->maxlen, 1);
|
|
177 check_scroll ();
|
|
178 return (0);
|
|
179 }
|
|
180
|
|
181
|
|
182
|
|
183 int
|
|
184 jikouho_c ()
|
|
185 {
|
|
186 jikouho (1);
|
|
187 return (0);
|
|
188 }
|
|
189
|
|
190 int
|
|
191 zenkouho_c ()
|
|
192 {
|
|
193 jikouho (-1);
|
|
194 return (0);
|
|
195 }
|
|
196
|
|
197 int
|
|
198 jikouho_dai_c ()
|
|
199 {
|
|
200 jikouho_dai (1);
|
|
201 return (0);
|
|
202 }
|
|
203
|
|
204 int
|
|
205 zenkouho_dai_c ()
|
|
206 {
|
|
207 jikouho_dai (-1);
|
|
208 return (0);
|
|
209 }
|
|
210
|
|
211 static int
|
|
212 make_jikouho_retu (h, h_m, r, r_m)
|
|
213 char *h;
|
|
214 int h_m;
|
|
215 int r_m;
|
|
216 char *r[];
|
|
217 {
|
|
218 int k;
|
|
219 char *c = h;
|
|
220 w_char tmp[512];
|
|
221 char tmp1[512];
|
|
222
|
|
223 if (r_m <= jl_zenkouho_suu (bun_data_))
|
|
224 return (-1);
|
|
225
|
|
226 for (k = 0; k < jl_zenkouho_suu (bun_data_); k++)
|
|
227 {
|
|
228 r[k] = c;
|
|
229 tmp[0] = 0;
|
|
230 jl_get_zenkouho_kanji (bun_data_, k, tmp);
|
|
231 if (print_out_func)
|
|
232 (*print_out_func) (tmp, tmp, Strlen (tmp));
|
|
233 delete_w_ss2 (tmp, Strlen (tmp));
|
|
234 sStrcpy (tmp1, tmp);
|
|
235 if (c + strlen (tmp1) + 1 >= h_m + h)
|
|
236 {
|
|
237 return (-1);
|
|
238 }
|
|
239 set_escape_code (tmp1); /* add by KUWA */
|
|
240 strcpy (c, tmp1);
|
|
241 c += strlen (tmp1) + 1;
|
|
242 }
|
|
243 return (0);
|
|
244 }
|
|
245
|
|
246 static int
|
|
247 select_jikouho1 (daip, in)
|
|
248 int daip;
|
|
249 int in;
|
|
250 {
|
|
251 static char *j_retu[MAXJIKOUHO];
|
|
252 static char jikouho_heap[MAXJIKOUHO * 10];
|
|
253 int c;
|
|
254 int tmp;
|
|
255 static int jikouho_step = 0;
|
|
256 static WnnClientRec *c_c_sv = 0;
|
|
257 static char *lang;
|
|
258
|
|
259 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
260 {
|
|
261 ring_bell ();
|
|
262 return (-1);
|
|
263 }
|
|
264 if (jikouho_step == 0)
|
|
265 {
|
|
266 jl_env_set (bun_data_, bunsetsu_env[cur_bnst_]);
|
|
267 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_) != daip)
|
|
268 {
|
|
269 if (daip)
|
|
270 {
|
|
271 if (jl_zenkouho_dai (bun_data_, cur_bnst_, dai_end (bun_data_, cur_bnst_), WNN_USE_ZENGO, WNN_UNIQ) == -1)
|
|
272 {
|
|
273 errorkeyin ();
|
|
274 return (-1);
|
|
275 }
|
|
276 }
|
|
277 else
|
|
278 {
|
|
279 if (jl_zenkouho (bun_data_, cur_bnst_, WNN_USE_ZENGO, WNN_UNIQ) == -1)
|
|
280 {
|
|
281 errorkeyin ();
|
|
282 return (-1);
|
|
283 }
|
|
284 }
|
|
285 }
|
|
286 lang = cur_lang->lang;
|
|
287 if (make_jikouho_retu (jikouho_heap, MAXJIKOUHO * 10, j_retu, MAXJIKOUHO) == -1)
|
|
288 {
|
|
289 print_msg_getc ("%s", msg_get (cd, 3, default_message[3], lang), NULL, NULL);
|
|
290 return (-1);
|
|
291 }
|
|
292 c_c_sv = c_c;
|
|
293 jikouho_step++;
|
|
294 }
|
|
295
|
|
296 if ((c = xw_select_one_element (j_retu, jl_zenkouho_suu (bun_data_),
|
|
297 jl_c_zenkouho (bun_data_), (daip ? msg_get (cd, 2, default_message[2], lang) : msg_get (cd, 1, default_message[1], lang)), JIKOUHO, main_table[4], in)) == -1)
|
|
298 {
|
|
299 jikouho_step = 0;
|
|
300 c_c_sv = 0;
|
|
301 return (-1);
|
|
302 }
|
|
303 else if (c == BUFFER_IN_CONT)
|
|
304 {
|
|
305 return (BUFFER_IN_CONT);
|
|
306 }
|
|
307 if (daip == WNN_SHO)
|
|
308 {
|
|
309 jl_set_jikouho (bun_data_, c);
|
|
310 }
|
|
311 else
|
|
312 {
|
|
313 jl_set_jikouho_dai (bun_data_, c);
|
|
314 }
|
|
315 make_kanji_buffer (cur_bnst_);
|
|
316 for (tmp = cur_bnst_ + 1; tmp < jl_bun_suu (bun_data_); tmp++)
|
|
317 bunsetsu_env[tmp] = jl_env_get (bun_data_);
|
|
318 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
319 c_b->t_c_p = bunsetsu[cur_bnst_];
|
|
320 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
|
|
321 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
|
|
322 jikouho_step = 0;
|
|
323 c_c_sv = 0;
|
|
324 return (0);
|
|
325 }
|
|
326
|
|
327 int
|
|
328 select_jikouho (in)
|
|
329 int in;
|
|
330 {
|
|
331 int ret;
|
|
332 static WnnClientRec *c_c_sv = 0;
|
|
333
|
|
334 #ifdef CALLBACKS
|
|
335 if (IsPreeditCallbacks (cur_x) && cur_x->cb_redraw_needed)
|
|
336 {
|
|
337 redraw_line ();
|
|
338 c_c_sv = 0;
|
|
339 pop_func (c_c);
|
|
340 cur_x->cb_redraw_needed = 0;
|
|
341 return (0);
|
|
342 }
|
|
343 #endif /* CALLBACKS */
|
|
344 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
345 {
|
|
346 ring_bell ();
|
|
347 return (0);
|
|
348 }
|
|
349 if (c_c_sv == 0)
|
|
350 {
|
|
351 c_c_sv = c_c;
|
|
352 push_func (c_c, select_jikouho);
|
|
353 }
|
|
354 if ((ret = select_jikouho1 (WNN_SHO, in)) == BUFFER_IN_CONT)
|
|
355 {
|
|
356 return (BUFFER_IN_CONT);
|
|
357 }
|
|
358 else if (ret == -1)
|
|
359 {
|
|
360 if (cur_p->cur_xl->visible == 3)
|
|
361 {
|
|
362 t_print_l ();
|
|
363 }
|
|
364 }
|
|
365 else
|
|
366 {
|
|
367 #ifdef CALLBACKS
|
|
368 if (IsPreeditCallbacks (cur_x))
|
|
369 {
|
|
370 cur_x->cb_redraw_needed = 1;
|
|
371 SendCBRedraw ();
|
|
372 return (BUFFER_IN_CONT);
|
|
373 }
|
|
374 else
|
|
375 {
|
|
376 #endif /* CALLBACKS */
|
|
377 kk_cursor_invisible ();
|
|
378 redraw_line ();
|
|
379 kk_cursor_normal ();
|
|
380 #ifdef CALLBACKS
|
|
381 }
|
|
382 #endif /* CALLBACKS */
|
|
383 }
|
|
384 c_c_sv = 0;
|
|
385 pop_func (c_c);
|
|
386 check_scroll ();
|
|
387 return (0);
|
|
388 }
|
|
389
|
|
390 int
|
|
391 select_jikouho_dai (in)
|
|
392 int in;
|
|
393 {
|
|
394 int ret;
|
|
395 static WnnClientRec *c_c_sv = 0;
|
|
396
|
|
397 #ifdef CALLBACKS
|
|
398 if (IsPreeditCallbacks (cur_x) && cur_x->cb_redraw_needed)
|
|
399 {
|
|
400 redraw_line ();
|
|
401 c_c_sv = 0;
|
|
402 pop_func (c_c);
|
|
403 cur_x->cb_redraw_needed = 0;
|
|
404 return (0);
|
|
405 }
|
|
406 #endif /* CALLBACKS */
|
|
407 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
408 {
|
|
409 ring_bell ();
|
|
410 return (0);
|
|
411 }
|
|
412 if (c_c_sv == 0)
|
|
413 {
|
|
414 c_c_sv = c_c;
|
|
415 push_func (c_c, select_jikouho_dai);
|
|
416 }
|
|
417 if ((ret = select_jikouho1 (WNN_DAI, in)) == BUFFER_IN_CONT)
|
|
418 {
|
|
419 return (BUFFER_IN_CONT);
|
|
420 }
|
|
421 else if (ret == -1)
|
|
422 {
|
|
423 if (cur_p->cur_xl->visible == 3)
|
|
424 {
|
|
425 t_print_l ();
|
|
426 }
|
|
427 }
|
|
428 else
|
|
429 {
|
|
430 #ifdef CALLBACKS
|
|
431 if (IsPreeditCallbacks (cur_x))
|
|
432 {
|
|
433 cur_x->cb_redraw_needed = 1;
|
|
434 SendCBRedraw ();
|
|
435 return (BUFFER_IN_CONT);
|
|
436 }
|
|
437 else
|
|
438 {
|
|
439 #endif /* CALLBACKS */
|
|
440 kk_cursor_invisible ();
|
|
441 redraw_line ();
|
|
442 kk_cursor_normal ();
|
|
443 #ifdef CALLBACKS
|
|
444 }
|
|
445 #endif /* CALLBACKS */
|
|
446 }
|
|
447 c_c_sv = 0;
|
|
448 pop_func (c_c);
|
|
449 check_scroll ();
|
|
450 return (0);
|
|
451 }
|
|
452
|
|
453 /*
|
|
454 Local Variables:
|
|
455 eval: (setq kanji-flag t)
|
|
456 eval: (setq kanji-fileio-code 0)
|
|
457 eval: (mode-line-kanji-code-update)
|
|
458 End:
|
|
459 */
|