0
|
1 /*
|
|
2 * $Id: inspect.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 "sdefine.h"
|
|
44 #include "xim.h"
|
|
45 #include "sheader.h"
|
|
46 #include "config.h"
|
|
47 #include "ext.h"
|
|
48 #include "rk_spclval.h"
|
|
49 #include "rk_fundecl.h"
|
|
50
|
|
51 #define LOCAL_TBL_CNT 2
|
|
52
|
|
53 int (*local_tbl[LOCAL_TBL_CNT]) () =
|
|
54 {
|
|
55 inspectdel, inspectuse};
|
|
56
|
|
57 static int
|
|
58 xw_inspect (c, in)
|
|
59 char *c;
|
|
60 int in;
|
|
61 {
|
|
62 static int select_step = 0;
|
|
63 int d;
|
|
64 int ret;
|
|
65 static int (*func) ();
|
|
66
|
|
67 if (select_step == 0)
|
|
68 {
|
|
69 if (init_inspect ((unsigned char *) c))
|
|
70 {
|
|
71 ring_bell ();
|
|
72 return (-1);
|
|
73 }
|
|
74 select_step++;
|
|
75 return (BUFFER_IN_CONT);
|
|
76 }
|
|
77 if (select_step == 1)
|
|
78 {
|
|
79 if (in == -99)
|
|
80 {
|
|
81 end_inspect ();
|
|
82 select_step = 0;
|
|
83 return (-1);
|
|
84 }
|
|
85 if (!xim->cur_j_c_root->inspect->map)
|
|
86 return (BUFFER_IN_CONT);
|
|
87 if (xim->sel_ret == -2)
|
|
88 {
|
|
89 xim->sel_ret = -1;
|
|
90 end_inspect ();
|
|
91 select_step = 0;
|
|
92 return (-1);
|
|
93 }
|
|
94 else if (xim->sel_ret != -1)
|
|
95 {
|
|
96 d = xim->sel_ret;
|
|
97 xim->sel_ret = -1;
|
|
98 if (d >= 0 && d < LOCAL_TBL_CNT && (func = local_tbl[d]))
|
|
99 {
|
|
100 lock_inspect ();
|
|
101 select_step++;
|
|
102 }
|
|
103 else
|
|
104 {
|
|
105 return (BUFFER_IN_CONT);
|
|
106 }
|
|
107 }
|
|
108 else if ((in < 256) && (func = main_table[9][in]))
|
|
109 {
|
|
110 for (d = 0; d < LOCAL_TBL_CNT; d++)
|
|
111 {
|
|
112 if (local_tbl[d] == func)
|
|
113 {
|
|
114 lock_inspect ();
|
|
115 break;
|
|
116 }
|
|
117 }
|
|
118 select_step++;
|
|
119 }
|
|
120 else
|
|
121 {
|
|
122 ring_bell ();
|
|
123 return (BUFFER_IN_CONT);
|
|
124 }
|
|
125 }
|
|
126 if (select_step == 2)
|
|
127 {
|
|
128 ret = (*func) (in);
|
|
129 if (ret == 1 || ret == -1)
|
|
130 {
|
|
131 end_inspect ();
|
|
132 select_step = 0;
|
|
133 return (0);
|
|
134 }
|
|
135 else if (ret == BUFFER_IN_CONT)
|
|
136 {
|
|
137 return (BUFFER_IN_CONT);
|
|
138 }
|
|
139 else
|
|
140 {
|
|
141 select_step--;
|
|
142 unlock_inspect ();
|
|
143 return (BUFFER_IN_CONT);
|
|
144 }
|
|
145 }
|
|
146 return (BUFFER_IN_CONT);
|
|
147 }
|
|
148
|
|
149 int
|
|
150 inspect (bun_no, c, in)
|
|
151 int bun_no;
|
|
152 char *c;
|
|
153 int in;
|
|
154 {
|
|
155 if (xw_inspect (c, in) == BUFFER_IN_CONT)
|
|
156 {
|
|
157 return (BUFFER_IN_CONT);
|
|
158 }
|
|
159 return (1);
|
|
160 }
|
|
161
|
|
162 static int next_flag;
|
|
163 #define I_NEXT 1
|
|
164 #define I_PREV 2
|
|
165 #define I_CUR 3
|
|
166
|
|
167 static int
|
|
168 update_dic_list (buf)
|
|
169 struct wnn_buf *buf;
|
|
170 {
|
|
171 if ((dic_list_size = jl_dic_list (bun_data_, &dicinfo)) == -1)
|
|
172 {
|
|
173 errorkeyin ();
|
|
174 return (-1);
|
|
175 }
|
|
176 return (0);
|
|
177 }
|
|
178
|
|
179 static int
|
|
180 find_dic_by_no (dic_no)
|
|
181 int dic_no;
|
|
182 {
|
|
183 int j;
|
|
184
|
|
185 for (j = 0; j < dic_list_size; j++)
|
|
186 {
|
|
187 if (dicinfo[j].dic_no == dic_no)
|
|
188 return (j);
|
|
189 }
|
|
190 return (-1);
|
|
191 }
|
|
192
|
|
193 static int
|
|
194 dic_nickname (dic_no, buf)
|
|
195 int dic_no;
|
|
196 char *buf;
|
|
197 {
|
|
198 int j;
|
|
199
|
|
200 if ((j = find_dic_by_no (dic_no)) == -1)
|
|
201 return (-1);
|
|
202 if (*dicinfo[j].comment)
|
|
203 sStrcpy (buf, dicinfo[j].comment);
|
|
204 else
|
|
205 strcpy (buf, dicinfo[j].fname);
|
|
206 return (0);
|
|
207 }
|
|
208
|
|
209 static int Bun_no;
|
|
210
|
|
211 static int
|
|
212 make_string_for_ke (bun_no, buf, buf_size)
|
|
213 int bun_no;
|
|
214 char *buf;
|
|
215 int buf_size;
|
|
216 {
|
|
217 struct wnn_jl_bun *bun;
|
|
218 w_char buf1[1024];
|
|
219 w_char save_c;
|
|
220 char tmp[WNN_HINSI_NAME_LEN * 2];
|
|
221 char *lang;
|
|
222
|
|
223 lang = cur_lang->lang;
|
|
224
|
|
225 Bun_no = bun_no;
|
|
226 bun = bun_data_->bun[bun_no];
|
|
227 jl_get_kanji (bun_data_, bun_no, bun_no + 1, buf1);
|
|
228 if (print_out_func)
|
|
229 (*print_out_func) (buf1, buf1, Strlen (buf1));
|
|
230 delete_w_ss2 (buf1, Strlen (buf1));
|
|
231 sStrcpy (buf, buf1);
|
|
232 strcat (buf, " ");
|
|
233 jl_get_yomi (bun_data_, bun_no, bun_no + 1, buf1);
|
|
234 if (print_out_func)
|
|
235 (*print_out_func) (buf1, buf1, Strlen (buf1));
|
|
236 delete_w_ss2 (buf1, Strlen (buf1));
|
|
237 save_c = *(buf1 + bun->jirilen);
|
|
238 *(buf1 + bun->jirilen) = 0;
|
|
239 sStrcpy (buf + strlen (buf), buf1);
|
|
240 *(buf1 + bun->jirilen) = save_c;
|
|
241 strcat (buf, "-");
|
|
242 sStrcpy (buf + strlen (buf), buf1 + bun->jirilen);
|
|
243
|
|
244 set_escape_code (buf);
|
|
245
|
|
246 strcat (buf, " (");
|
|
247 if (bun->dic_no >= 0)
|
|
248 {
|
|
249 update_dic_list (bun_data_);
|
|
250 dic_nickname (bun->dic_no, buf + strlen (buf));
|
|
251 sStrcpy (tmp, jl_hinsi_name (bun_data_, bun->hinsi));
|
|
252 sprintf (buf + strlen (buf), ":%d %s", bun->entry, tmp);
|
|
253 if (bun->hindo != 0x7f)
|
|
254 {
|
|
255 sprintf (buf + strlen (buf), " %s:%c%d", msg_get (cd, 4, default_message[4], lang), bun->ima ? '*' : ' ', bun->hindo);
|
|
256 }
|
|
257 else
|
|
258 {
|
|
259 sprintf (buf + strlen (buf), " ---------");
|
|
260 } /* Means This entry is not used.
|
|
261 This must not appear in ordinary use! */
|
|
262
|
|
263 }
|
|
264 else
|
|
265 {
|
|
266 sStrcpy (tmp, jl_hinsi_name (bun_data_, bun->hinsi));
|
|
267 sprintf (buf + strlen (buf), "GIJI BUNSETU:%s", tmp);
|
|
268 }
|
|
269 strcat (buf, ") ");
|
|
270 sprintf (buf + strlen (buf), "%s:%d %s:%d", msg_get (cd, 5, default_message[5], lang), bun->hyoka, msg_get (cd, 6, default_message[6], lang), bun->kangovect);
|
|
271
|
|
272
|
|
273 if (bun->dai_top)
|
|
274 {
|
|
275 if (bun->daihyoka != -1)
|
|
276 {
|
|
277 sprintf (buf + strlen (buf), "(%s:%d) ", msg_get (cd, 7, default_message[7], lang), bun->daihyoka);
|
|
278 }
|
|
279 else
|
|
280 {
|
|
281 sprintf (buf + strlen (buf), "(%s:---) ", msg_get (cd, 7, default_message[7], lang));
|
|
282 }
|
|
283 }
|
|
284
|
|
285 return (0);
|
|
286 }
|
|
287
|
|
288 int
|
|
289 inspect_kouho (in)
|
|
290 int in;
|
|
291 {
|
|
292 static char buf[1024];
|
|
293 static WnnClientRec *c_c_sv = 0;
|
|
294
|
|
295 #ifdef CALLBACKS
|
|
296 if (IsPreeditCallbacks (cur_x) && cur_x->cb_redraw_needed)
|
|
297 {
|
|
298 t_print_l ();
|
|
299 c_c_sv = 0;
|
|
300 pop_func (c_c);
|
|
301 cur_x->cb_redraw_needed = 0;
|
|
302 return (0);
|
|
303 }
|
|
304 #endif /* CALLBACKS */
|
|
305
|
|
306 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
307 {
|
|
308 ring_bell ();
|
|
309 return (0);
|
|
310 }
|
|
311 if (c_c_sv == 0)
|
|
312 {
|
|
313 c_c_sv = c_c;
|
|
314 push_func (c_c, inspect_kouho);
|
|
315 next_flag = I_CUR;
|
|
316 if (make_string_for_ke (cur_bnst_, buf, sizeof (buf)) == -1)
|
|
317 {
|
|
318 print_msg_getc ("Error in inspect", NULL, NULL, NULL);
|
|
319 return (0);
|
|
320 }
|
|
321 }
|
|
322 if (inspect (cur_bnst_, buf, in) == BUFFER_IN_CONT)
|
|
323 {
|
|
324 return (BUFFER_IN_CONT);
|
|
325 }
|
|
326 #ifdef CALLBACKS
|
|
327 if (IsPreeditCallbacks (cur_x))
|
|
328 {
|
|
329 cur_x->cb_redraw_needed = 1;
|
|
330 SendCBRedraw ();
|
|
331 return (BUFFER_IN_CONT);
|
|
332 }
|
|
333 #endif /* CALLBACKS */
|
|
334 t_print_l ();
|
|
335 c_c_sv = 0;
|
|
336 pop_func (c_c);
|
|
337 return (0);
|
|
338 }
|
|
339
|
|
340 static int
|
|
341 sakujo_kouho1 (bun_no, in)
|
|
342 int bun_no;
|
|
343 int in;
|
|
344 {
|
|
345 w_char w_buf[512];
|
|
346 char buf[512];
|
|
347 int kanji_len, ret;
|
|
348 char *lang;
|
|
349 static int step = 0;
|
|
350
|
|
351 if (step == 0)
|
|
352 {
|
|
353 lang = cur_lang->lang;
|
|
354 jl_get_kanji (bun_data_, bun_no, bun_no + 1, w_buf);
|
|
355 kanji_len = jl_kanji_len (bun_data_, bun_no, bun_no + 1) - jl_fuzoku_len (bun_data_, bun_no);
|
|
356 w_buf[kanji_len] = 0;
|
|
357 sStrcpy (buf, w_buf);
|
|
358 strcat (buf, " ");
|
|
359 strcat (buf, msg_get (cd, 8, default_message[8], lang));
|
|
360 strcat (buf, ":");
|
|
361 jl_get_yomi (bun_data_, bun_no, bun_no + 1, w_buf);
|
|
362 w_buf[jl_jiri_len (bun_data_, bun_no)] = 0;
|
|
363 sStrcpy (buf + strlen (buf), w_buf);
|
|
364 strcat (buf, " ");
|
|
365 sprintf (buf + strlen (buf), "%s?", msg_get (cd, 9, default_message[9], lang));
|
|
366 step++;
|
|
367 }
|
|
368 if ((ret = yes_or_no (buf, in)) != BUFFER_IN_CONT)
|
|
369 {
|
|
370 if (ret == 1)
|
|
371 {
|
|
372 if (jl_word_delete (bun_data_, bun_data_->bun[bun_no]->dic_no, bun_data_->bun[bun_no]->entry) == -1)
|
|
373 {
|
|
374 errorkeyin ();
|
|
375 }
|
|
376 }
|
|
377 step = 0;
|
|
378 }
|
|
379 return (ret);
|
|
380 }
|
|
381
|
|
382 int
|
|
383 sakujo_kouho (in)
|
|
384 int in;
|
|
385 {
|
|
386 static WnnClientRec *c_c_sv = 0;
|
|
387
|
|
388 #ifdef CALLBACKS
|
|
389 if (IsPreeditCallbacks (cur_x) && cur_x->cb_redraw_needed)
|
|
390 {
|
|
391 t_print_l ();
|
|
392 c_c_sv = 0;
|
|
393 pop_func (c_c);
|
|
394 cur_x->cb_redraw_needed = 0;
|
|
395 return (0);
|
|
396 }
|
|
397 #endif /* CALLBACKS */
|
|
398
|
|
399 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
400 {
|
|
401 ring_bell ();
|
|
402 return (0);
|
|
403 }
|
|
404 if (c_c_sv == 0)
|
|
405 {
|
|
406 c_c_sv = c_c;
|
|
407 push_func (c_c, sakujo_kouho);
|
|
408 }
|
|
409 if (sakujo_kouho1 (cur_bnst_, in) == BUFFER_IN_CONT)
|
|
410 {
|
|
411 return (BUFFER_IN_CONT);
|
|
412 }
|
|
413 #ifdef CALLBACKS
|
|
414 if (IsPreeditCallbacks (cur_x))
|
|
415 {
|
|
416 cur_x->cb_redraw_needed = 1;
|
|
417 SendCBRedraw ();
|
|
418 return (BUFFER_IN_CONT);
|
|
419 }
|
|
420 #endif /* CALLBACKS */
|
|
421 t_print_l ();
|
|
422 c_c_sv = 0;
|
|
423 pop_func (c_c);
|
|
424 return (0);
|
|
425 }
|
|
426
|
|
427 int
|
|
428 inspectdel (in)
|
|
429 int in;
|
|
430 {
|
|
431 struct wnn_jl_bun *bun = bun_data_->bun[Bun_no];
|
|
432 w_char buf1[1024];
|
|
433 char buf[512];
|
|
434 int type, ret;
|
|
435 int kanji_len;
|
|
436 char *lang;
|
|
437 static int step = 0;
|
|
438
|
|
439 if (step == 0)
|
|
440 {
|
|
441 lang = cur_lang->lang;
|
|
442 type = dicinfo[find_dic_by_no (bun->dic_no)].type;
|
|
443 if (type != WNN_UD_DICT && type != WNN_REV_DICT && type != CWNN_REV_DICT)
|
|
444 {
|
|
445 print_msg_getc ("%s", msg_get (cd, 10, default_message[10], lang), NULL, NULL);
|
|
446 return (0);
|
|
447 }
|
|
448 if (dicinfo[find_dic_by_no (bun->dic_no)].rw == WNN_DIC_RDONLY)
|
|
449 {
|
|
450 print_msg_getc ("%s", msg_get (cd, 11, default_message[11], lang), NULL, NULL);
|
|
451 return (0);
|
|
452 }
|
|
453
|
|
454 jl_get_kanji (bun_data_, Bun_no, Bun_no + 1, buf1);
|
|
455 kanji_len = jl_kanji_len (bun_data_, Bun_no, Bun_no + 1) - jl_fuzoku_len (bun_data_, Bun_no);
|
|
456 buf1[kanji_len] = 0;
|
|
457
|
|
458 strcpy (buf, msg_get (cd, 12, default_message[12], lang));
|
|
459 sStrcpy (buf + strlen (buf), buf1);
|
|
460 sprintf (buf + strlen (buf), "%s", msg_get (cd, 13, default_message[13], lang));
|
|
461 set_escape_code (buf); /* ADD KURI */
|
|
462 step++;
|
|
463 }
|
|
464 if ((ret = yes_or_no (buf, in)) != BUFFER_IN_CONT)
|
|
465 {
|
|
466 if (ret == 1)
|
|
467 {
|
|
468 if (jl_word_delete (bun_data_, bun->dic_no, bun->entry) == -1)
|
|
469 {
|
|
470 errorkeyin ();
|
|
471 }
|
|
472 }
|
|
473 step = 0;
|
|
474 }
|
|
475 return (ret);
|
|
476 }
|
|
477
|
|
478 int
|
|
479 inspectuse (in)
|
|
480 int in;
|
|
481 {
|
|
482 struct wnn_jl_bun *bun = bun_data_->bun[Bun_no];
|
|
483 w_char buf1[1024];
|
|
484 char buf[512];
|
|
485 int kanji_len;
|
|
486 char *lang;
|
|
487 int ret;
|
|
488 static int step = 0;
|
|
489
|
|
490 if (step == 0)
|
|
491 {
|
|
492 lang = cur_lang->lang;
|
|
493 if (dicinfo[find_dic_by_no (bun->dic_no)].hindo_rw == WNN_DIC_RDONLY)
|
|
494 {
|
|
495 print_msg_getc ("%s", msg_get (cd, 14, default_message[14], lang), NULL, NULL);
|
|
496 return (0);
|
|
497 }
|
|
498 strcpy (buf, msg_get (cd, 12, default_message[12], lang));
|
|
499 jl_get_kanji (bun_data_, Bun_no, Bun_no + 1, buf1);
|
|
500 kanji_len = jl_kanji_len (bun_data_, Bun_no, Bun_no + 1) - jl_fuzoku_len (bun_data_, Bun_no);
|
|
501 buf1[kanji_len] = 0;
|
|
502 sStrcpy (buf + strlen (buf), buf1);
|
|
503 set_escape_code (buf); /* ADD KURI */
|
|
504 sprintf (buf + strlen (buf), "%s", msg_get (cd, 15, default_message[15], lang));
|
|
505 step++;
|
|
506 }
|
|
507 if ((ret = yes_or_no (buf, in)) != BUFFER_IN_CONT)
|
|
508 {
|
|
509 if (ret == 1)
|
|
510 {
|
|
511 if (jl_word_use (bun_data_, bun->dic_no, bun->entry) == -1)
|
|
512 {
|
|
513 errorkeyin ();
|
|
514 }
|
|
515 }
|
|
516 step = 0;
|
|
517 }
|
|
518 return (ret);
|
|
519 }
|
|
520
|
|
521 unsigned char *
|
|
522 next_inspect ()
|
|
523 {
|
|
524 char buf[1024];
|
|
525 char *c = buf;
|
|
526
|
|
527 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_) != WNN_SHO)
|
|
528 {
|
|
529 jl_zenkouho (bun_data_, cur_bnst_, WNN_USE_ZENGO, WNN_UNIQ);
|
|
530 }
|
|
531 jl_next (bun_data_);
|
|
532 make_kanji_buffer (cur_bnst_);
|
|
533 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
534 c_b->t_b_st = dai_top (bun_data_, cur_bnst_); /* add by KUWA */
|
|
535 c_b->t_b_end = dai_end (bun_data_, cur_bnst_); /* add by KUWA */
|
|
536 if (make_string_for_ke (cur_bnst_, buf, sizeof (buf)) == -1)
|
|
537 {
|
|
538 print_msg_getc ("Error in inspect", NULL, NULL, NULL);
|
|
539 return (NULL);
|
|
540 }
|
|
541 return ((unsigned char *) c);
|
|
542 }
|
|
543
|
|
544 unsigned char *
|
|
545 previous_inspect ()
|
|
546 {
|
|
547 char buf[1024];
|
|
548 char *c = buf;
|
|
549
|
|
550 if (jl_zenkouho_bun (bun_data_) != cur_bnst_ || jl_zenkouho_daip (bun_data_) != WNN_SHO)
|
|
551 {
|
|
552 jl_zenkouho (bun_data_, cur_bnst_, WNN_USE_ZENGO, WNN_UNIQ);
|
|
553 }
|
|
554 jl_previous (bun_data_);
|
|
555 make_kanji_buffer (cur_bnst_);
|
|
556 c_b->t_m_start = bunsetsuend[cur_bnst_];
|
|
557 c_b->t_b_st = dai_top (bun_data_, cur_bnst_); /* add by KUWA */
|
|
558 c_b->t_b_end = dai_end (bun_data_, cur_bnst_); /* add by KUWA */
|
|
559 if (make_string_for_ke (cur_bnst_, buf, sizeof (buf)) == -1)
|
|
560 {
|
|
561 print_msg_getc ("Error in inspect", NULL, NULL, NULL);
|
|
562 return (NULL);
|
|
563 }
|
|
564
|
|
565 return ((unsigned char *) c);
|
|
566 }
|