1 /*
2 * $Id: touroku.c,v 1.2 2001/06/14 18:16:13 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 "jslib.h"
44 #include "commonhd.h"
45 #include "sdefine.h"
46 #include "xjutil.h"
47 #include "sxheader.h"
48 #include "rk_spclval.h"
49 #include "rk_fundecl.h"
50 #include "xext.h"
51
52 static int touroku_start, touroku_end;
53 /* these are used only for making yomi string for registered kanji */
54
55
56 int touroku_mode = 0;
57
58 static void
freeze_messages()59 freeze_messages ()
60 {
61 register int i;
62
63 for (i = 0; i < JCLIENTS; i++)
64 {
65 freeze_box (cur_root->jutil->mes_button[i]);
66 }
67 }
68
69 static void
unfreeze_messages()70 unfreeze_messages ()
71 {
72 register int i;
73
74 for (i = 0; i < JCLIENTS; i++)
75 {
76 unfreeze_box (cur_root->jutil->mes_button[i]);
77 }
78 }
79
80 static int
change_mode(mode)81 change_mode (mode)
82 int mode;
83 {
84 int ret = EXECUTE;
85
86 if (mode == MESSAGE1)
87 {
88 ret = KANJI_IN_START;
89 }
90 else if (mode == MESSAGE2)
91 {
92 ret = YOMI_IN;
93 }
94 else if (mode == MESSAGE3)
95 {
96 ret = HINSI_IN;
97 }
98 else if (mode == MESSAGE4)
99 {
100 ret = JISHO_IN;
101 }
102 return (ret);
103 }
104
105 static void
redraw_old_message(mode)106 redraw_old_message (mode)
107 int mode;
108 {
109 register JutilRec *jutil = cur_root->jutil;
110
111 if (mode == MESSAGE0)
112 {
113 unfreeze_box (jutil->button[EXEC_W]);
114 if (jutil->button[EXEC_W]->in)
115 {
116 reverse_box (jutil->button[EXEC_W], jutil->button[EXEC_W]->invertgc);
117 jutil->button[EXEC_W]->in = 0;
118 }
119 }
120 else
121 {
122 changecolor_box (jutil->mes_button[mode], 0, 0, cur_root->bg, BoxBorderPixel);
123 jutil->mes_button[mode]->in = (char) 0;
124 }
125 }
126
127 static void
redraw_new_message(mode)128 redraw_new_message (mode)
129 int mode;
130 {
131 register JutilRec *jutil = cur_root->jutil;
132
133 if (mode == MESSAGE0)
134 {
135 if (!jutil->button[EXEC_W]->in)
136 {
137 reverse_box (jutil->button[EXEC_W], jutil->button[EXEC_W]->invertgc);
138 jutil->button[EXEC_W]->in = 1;
139 }
140 freeze_box (jutil->button[EXEC_W]);
141 }
142 else
143 {
144 changecolor_box (jutil->mes_button[mode], 0, 0, cur_root->fg, BoxBorderPixel);
145 jutil->mes_button[mode]->in = (char) 1;
146 }
147 }
148
149 static void
xw_exec_mode()150 xw_exec_mode ()
151 {
152 unsigned int c1;
153 int ret;
154 JutilRec *jutil = cur_root->jutil;
155
156 jutil->mes_mode = MESSAGE0;
157 redraw_new_message (jutil->mes_mode);
158 freeze_box (jutil->button[EXEC_W]);
159 for (;;)
160 {
161 c1 = keyin ();
162 if (xjutil->sel_ret == -2)
163 {
164 touroku_mode = CANCEL;
165 xjutil->sel_ret = -1;
166 break;
167 }
168 else if (xjutil->sel_ret == 0)
169 {
170 touroku_mode = TOUROKU_GO;
171 xjutil->sel_ret = -1;
172 break;
173 }
174 else if (xjutil->sel_ret == 1)
175 {
176 touroku_mode = change_mode (jutil->mode);
177 xjutil->sel_ret = -1;
178 break;
179 }
180 else if ((c1 < 256) && (main_table[9][c1] != NULL))
181 {
182 if ((ret = (*main_table[9][c1]) ()) == 1)
183 {
184 if (jutil->mes_mode == MESSAGE0)
185 {
186 touroku_mode = TOUROKU_GO;
187 }
188 else
189 {
190 jutil->mode = jutil->mes_mode;
191 touroku_mode = change_mode (jutil->mes_mode);
192 }
193 break;
194 }
195 else if (ret == -1)
196 {
197 touroku_mode = CANCEL;
198 break;
199 }
200 }
201 else
202 {
203 ring_bell ();
204 }
205 }
206 redraw_old_message (jutil->mes_mode);
207 if (jutil->mes_mode == MESSAGE0)
208 {
209 unfreeze_box (jutil->button[EXEC_W]);
210 }
211 /*
212 if (cur_root->jutil->button[EXEC_W]->in) {
213 reverse_box(jutil->button[EXEC_W], jutil->button[EXEC_W]->invertgc);
214 jutil->button[EXEC_W]->in = 0;
215 }
216 }
217 */
218 }
219
220 int
hani_settei_normal(c_b)221 hani_settei_normal (c_b)
222 ClientBuf *c_b;
223 {
224 c_b->hanten = 0x04;
225 c_b->t_c_p = 0;
226 hanten_jutil_mes_title (MESSAGE1, 1);
227 c_b->t_m_start = -1;
228
229 c_b->key_table = main_table[5];
230 c_b->rk_clear_tbl = romkan_clear_tbl[5];
231 c_b->key_in_fun = NULL;
232 c_b->redraw_fun = redraw_nisemono;
233 c_b->ctrl_code_fun = NULL;
234 init_screen ();
235 return (0);
236 }
237
238 #ifdef CHINESE
239 int
hani_settei_yincod(c_b)240 hani_settei_yincod (c_b)
241 ClientBuf *c_b;
242 {
243 c_b->hanten = 0x04 | 0x40;
244 c_b->t_c_p = 0;
245 hanten_jutil_mes_title (MESSAGE1, 1);
246 c_b->t_b_st = c_b->t_c_p;
247 c_b->t_b_end = c_b->t_c_p + 1;
248 c_b->t_m_start = c_b->t_c_p + 1;
249 kk_cursor_invisible ();
250
251 c_b->key_table = main_table[5];
252 c_b->rk_clear_tbl = romkan_clear_tbl[5];
253 c_b->key_in_fun = NULL;
254 c_b->redraw_fun = redraw_nisemono;
255 c_b->ctrl_code_fun = NULL;
256 init_screen ();
257 c_b->t_m_start = -1;
258 return (0);
259 }
260 #endif /* CHINESE */
261
262 static int
xw_hani_settei(buffer,buflen)263 xw_hani_settei (buffer, buflen)
264 w_char *buffer;
265 int buflen;
266 {
267 ClientBuf *c_btmp, c_b1;
268
269 c_btmp = c_b;
270 c_b = &c_b1;
271
272 c_b->buffer = buffer;
273 c_b->buflen = buflen;
274
275 c_b->maxlen = Strlen (buffer);
276
277 freeze_messages ();
278 (*hani_settei_func) (c_b);
279 if (buffer_in () == -1)
280 {
281 if (touroku_mode == KANJI_IN_START || touroku_mode == KANJI_IN_END)
282 touroku_mode = CANCEL;
283 c_b = c_btmp;
284 return (-1);
285 }
286 unfreeze_messages ();
287 if (xjutil->sel_ret == -2)
288 {
289 touroku_mode = CANCEL;
290 xjutil->sel_ret = -1;
291 c_b = c_btmp;
292 return (-1);
293 }
294 else if (xjutil->sel_ret == 0)
295 {
296 touroku_mode = TOUROKU_GO;
297 xjutil->sel_ret = -1;
298 c_b = c_btmp;
299 return (0);
300 }
301 else if (xjutil->sel_ret == 1)
302 {
303 touroku_mode = change_mode (cur_root->jutil->mode);
304 if (touroku_mode == KANJI_IN_START)
305 {
306 c_b = c_btmp;
307 return (0);
308 }
309 }
310 else
311 {
312 touroku_mode = EXECUTE;
313 }
314 Strncpy (buffer, buffer + c_b->t_m_start, c_b->t_c_p - c_b->t_m_start);
315 buffer[c_b->t_c_p - c_b->t_m_start] = 0;
316 touroku_start = c_b->t_m_start;
317 touroku_end = c_b->t_c_p;
318 c_b = c_btmp;
319 return (c_b1.t_c_p - c_b1.t_m_start);
320 }
321
322 void
touroku()323 touroku ()
324 {
325 int i;
326 int ud_no, save_ud_no = -1, ud_table[WNN_MAX_JISHO_OF_AN_ENV];
327 w_char yomibuf[LENGTHYOMI + 1];
328 char *message[4];
329 char *message1[4];
330 w_char hani_buffer[1024];
331 w_char get_buffer[1024];
332 char dic_name_heap[2048];
333 char save_text[WNN_HINSI_NAME_LEN];
334 char *hp = dic_name_heap;
335 int hinsi = -1, save_hinsi = -1;
336 int tmp;
337 char *dict_name[JISHOKOSUU];
338 static int current_dic = -1;
339 int current = 0;
340 int size;
341 int kanji_set = 0, yomi_set = 0, hinsi_set = 0, jisho_set = 0;
342
343 cur_bnst_ = get_touroku_data (get_buffer);
344 if (update_dic_list () == -1)
345 {
346 errorkeyin ();
347 return;
348 }
349 for (i = 0, size = 0; i < dic_list_size; i++)
350 {
351 if ((dicinfo[i].type == WNN_UD_DICT || dicinfo[i].type == WNN_REV_DICT || dicinfo[i].type == CWNN_REV_DICT) && dicinfo[i].rw == 0)
352 {
353 if (*dicinfo[i].comment)
354 {
355 sStrcpy (hp, dicinfo[i].comment);
356 dict_name[size] = hp;
357 hp += strlen (hp) + 1;
358 }
359 else
360 {
361 dict_name[size] = dicinfo[i].fname;
362 }
363 ud_table[size] = i;
364 if (current_dic != -1 && dicinfo[i].dic_no == current_dic)
365 current = size;
366 size++;
367 }
368 }
369 if (size == 0)
370 {
371 print_msg_getc (msg_get (cd, 99, default_message[99], xjutil->lang), NULL, NULL, NULL);
372 return;
373 }
374 save_ud_no = 0;
375
376 if ((hinsi = get_default_hinsi (save_text)) != -1)
377 save_hinsi = hinsi;
378
379 message[0] = msg_get (cd, 93, default_message[93], xjutil->lang);
380 message[1] = msg_get (cd, 95, default_message[95], xjutil->lang);
381 message[2] = msg_get (cd, 96, default_message[96], xjutil->lang);
382 message[3] = msg_get (cd, 97, default_message[97], xjutil->lang);
383 message1[0] = message1[1] = message1[2] = message1[3] = NULL;
384 #ifdef nodef
385 message1[2] = hinsi_name;
386 #endif
387 if (size == 1)
388 {
389 ud_no = 0;
390 message1[3] = dict_name[ud_no];
391 }
392
393 init_jutil (msg_get (cd, 92, default_message[92], xjutil->lang), msg_get (cd, 92, default_message[92], xjutil->lang), 4, message, message1);
394 touroku_mode = KANJI_IN_START;
395
396 repeat:
397 for (;;)
398 {
399 switch (touroku_mode)
400 {
401 case KANJI_IN_START:
402 kanji_set = 0;
403 change_cur_jutil (MESSAGE1);
404 change_mes_title (MESSAGE1, msg_get (cd, 93, default_message[93], xjutil->lang), 1);
405 kk_cursor_invisible ();
406 JWMline_clear (0);
407 kk_cursor_normal ();
408 hani_buffer[0] = 0;
409 Strcpy (hani_buffer, get_buffer);
410 if ((tmp = xw_hani_settei (hani_buffer, 1024)) < 0)
411 break;
412 if ((tmp = Strlen (hani_buffer)) >= 64)
413 {
414 print_msg_getc (msg_get (cd, 100, default_message[100], xjutil->lang), NULL, NULL, NULL);
415 touroku_mode = KANJI_IN_START;
416 }
417 else if (tmp > 0)
418 {
419 kanji_set = 1;
420 }
421 kk_cursor_invisible ();
422 break;
423 case YOMI_IN:
424 yomi_set = 0;
425 for (i = 0; i < LENGTHYOMI + 1; i++)
426 {
427 yomibuf[i] = 0;
428 }
429 change_cur_jutil (MESSAGE2);
430 hanten_jutil_mes_title (MESSAGE2, 1);
431 JWMline_clear (0);
432 kk_cursor_normal ();
433 xjutil->sel_ret = -1;
434 freeze_messages ();
435 tmp = kana_in ((0x08 | 0x20), yomibuf, LENGTHYOMI);
436 unfreeze_messages ();
437 if (Strlen (yomibuf) > 0)
438 yomi_set = 1;
439 if (tmp == -1 || xjutil->sel_ret == -2)
440 {
441 touroku_mode = CANCEL;
442 }
443 else if (xjutil->sel_ret == 0)
444 {
445 touroku_mode = TOUROKU_GO;
446 }
447 else if (xjutil->sel_ret == 1)
448 {
449 touroku_mode = change_mode (cur_root->jutil->mode);
450 }
451 else
452 {
453 touroku_mode = EXECUTE;
454 }
455 hanten_jutil_mes_title (MESSAGE2, 0);
456 kk_cursor_invisible ();
457 break;
458 case HINSI_IN:
459 hinsi_set = 0;
460 change_cur_jutil (MESSAGE3);
461 hanten_jutil_mes_title (MESSAGE3, 1);
462 JWMline_clear (0);
463 kk_cursor_invisible ();
464 if ((hinsi = hinsi_in (save_text)) == -1)
465 {
466 if (save_hinsi != -1)
467 {
468 hinsi = save_hinsi;
469 JWMline_clear (0);
470 xw_jutil_write_msg (save_text);
471 hinsi_set = 1;
472 }
473 }
474 else
475 {
476 save_hinsi = hinsi;
477 hinsi_set = 1;
478 }
479 hanten_jutil_mes_title (MESSAGE3, 0);
480 if (touroku_mode == HINSI_IN)
481 touroku_mode = EXECUTE;
482 break;
483 case JISHO_IN:
484 if (size == 1)
485 {
486 touroku_mode = EXECUTE;
487 jisho_set = 1;
488 break;
489 }
490 jisho_set = 0;
491 change_cur_jutil (MESSAGE4);
492 hanten_jutil_mes_title (MESSAGE4, 1);
493 JWMline_clear (0);
494 kk_cursor_invisible ();
495 ud_no = xw_select_one_element_call (dict_name, size, current, msg_get (cd, 98, default_message[98], xjutil->lang));
496 if (ud_no == -1)
497 {
498 if (save_ud_no != -1)
499 {
500 ud_no = save_ud_no;
501 JWMline_clear (0);
502 xw_jutil_write_msg (dict_name[ud_no]);
503 jisho_set = 1;
504 }
505 }
506 else
507 {
508 save_ud_no = ud_no;
509 xw_jutil_write_msg (dict_name[ud_no]);
510 jisho_set = 1;
511 }
512 hanten_jutil_mes_title (MESSAGE4, 0);
513 /*
514 if (ud_no == -3) {
515 touroku_mode = EXECUTE;
516 } else if (ud_no == -1) {
517 touroku_mode = CANCEL;
518 } else {
519 xw_jutil_write_msg(dict_name[ud_no]);
520 }
521 */
522 if (touroku_mode == JISHO_IN)
523 touroku_mode = EXECUTE;
524 break;
525 case EXECUTE:
526 case TOUROKU_GO:
527 if (!kanji_set)
528 {
529 touroku_mode = KANJI_IN_START;
530 break;
531 }
532 else if (!yomi_set)
533 {
534 touroku_mode = YOMI_IN;
535 break;
536 }
537 else if (!hinsi_set)
538 {
539 touroku_mode = HINSI_IN;
540 break;
541 }
542 else if (!jisho_set)
543 {
544 touroku_mode = JISHO_IN;
545 break;
546 }
547 if (touroku_mode == EXECUTE)
548 {
549 xw_exec_mode ();
550 }
551 else
552 {
553 goto do_touroku;
554 }
555 break;
556 case CANCEL:
557 end_jutil ();
558 return;
559 }
560 }
561
562 do_touroku:
563 current_dic = dicinfo[ud_table[ud_no]].dic_no;
564
565 if (js_word_add (cur_env, current_dic, yomibuf, hani_buffer, "", hinsi, 0) == -1)
566 {
567 if_dead_disconnect (cur_env, -1);
568 errorkeyin ();
569 touroku_mode = EXECUTE;
570 goto repeat;
571 }
572 end_jutil ();
573 return;
574 }
575
576
577 static int
find_end_of_tango(c)578 find_end_of_tango (c)
579 int c;
580 {
581 int k;
582 int jisyu; /* 0: katakana 1: hiragana 2:ascii 3:kanji */
583
584 if (KATAP (c_b->buffer[c]))
585 jisyu = 0;
586 else if (HIRAP (c_b->buffer[c]))
587 jisyu = 1;
588 else if (ASCIIP (c_b->buffer[c]))
589 jisyu = 2;
590 else if (KANJIP (c_b->buffer[c]))
591 jisyu = 3;
592 else
593 return (c + 1);
594
595 for (k = c + 1; k < c_b->maxlen; k++)
596 {
597 if (jisyu == 0)
598 {
599 if (!KATAP (c_b->buffer[k]))
600 break;
601 }
602 else if (jisyu == 1)
603 {
604 if (!HIRAP (c_b->buffer[k]))
605 break;
606 }
607 else if (jisyu == 2)
608 {
609 if (!ASCIIP (c_b->buffer[k]))
610 break;
611 }
612 else if (jisyu == 3)
613 {
614 if (!KANJIP (c_b->buffer[k]))
615 break;
616 }
617 }
618 return (k);
619 }
620
621 int
t_markset()622 t_markset ()
623 {
624 if (xjutil->sel_ret == -2)
625 {
626 touroku_mode = CANCEL;
627 hanten_jutil_mes_title (MESSAGE1, 0);
628 xjutil->sel_ret = -1;
629 return (-1);
630 }
631
632 if (c_b->t_m_start == -2)
633 {
634 hanten_jutil_mes_title (MESSAGE1, 0);
635 return (0);
636 }
637 if (c_b->t_m_start == -1)
638 {
639 if (cur_root->jutil->mode != MESSAGE1)
640 {
641 touroku_mode = KANJI_IN_START;
642 change_mes_title (MESSAGE1, msg_get (cd, 93, default_message[93], xjutil->lang), 1);
643 return (0);
644 }
645 if (c_b->t_c_p == c_b->maxlen)
646 {
647 touroku_mode = KANJI_IN_END;
648 change_mes_title (MESSAGE1, msg_get (cd, 94, default_message[94], xjutil->lang), 1);
649 return (0);
650 }
651 c_b->t_m_start = c_b->t_c_p;
652 touroku_mode = KANJI_IN_END;
653 change_mes_title (MESSAGE1, msg_get (cd, 94, default_message[94], xjutil->lang), 1);
654 call_t_redraw_move_1 (find_end_of_tango (c_b->t_c_p), c_b->t_c_p, find_end_of_tango (c_b->t_c_p), 0, 0, 0, 2);
655 kk_cursor_invisible ();
656 return (0);
657 }
658 else
659 {
660 if (c_b->t_m_start == c_b->t_c_p)
661 {
662 c_b->t_m_start = -1;
663 touroku_mode = KANJI_IN_START;
664 change_mes_title (MESSAGE1, msg_get (cd, 93, default_message[93], xjutil->lang), 1);
665 kk_cursor_normal ();
666 return (-1);
667 }
668 else
669 {
670 if (cur_root->jutil->mode == MESSAGE1)
671 cur_root->jutil->mode = MESSAGE2;
672 hanten_jutil_mes_title (MESSAGE1, 0);
673 return (1);
674 }
675 }
676 }
677
678 int
xw_next_message()679 xw_next_message ()
680 {
681 register JutilRec *jutil = cur_root->jutil;
682
683 redraw_old_message (jutil->mes_mode);
684 if (jutil->mes_mode == MESSAGE4)
685 {
686 jutil->mes_mode = MESSAGE0;
687 }
688 else
689 {
690 jutil->mes_mode += 1;
691 }
692 redraw_new_message (jutil->mes_mode);
693 return (0);
694 }
695
696 int
xw_previous_message()697 xw_previous_message ()
698 {
699 register JutilRec *jutil = cur_root->jutil;
700
701 redraw_old_message (jutil->mes_mode);
702 if (jutil->mes_mode == MESSAGE0)
703 {
704 jutil->mes_mode = MESSAGE4;
705 }
706 else
707 {
708 jutil->mes_mode -= 1;
709 }
710 redraw_new_message (jutil->mes_mode);
711 return (0);
712 }
713