1 /*
2 * $Id: uif.c,v 1.2 2001/06/14 18:16:17 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 "config.h"
45 #include "sdefine.h"
46 #include "xim.h"
47 #include "sheader.h"
48 #include "ext.h"
49 #include "rk_spclval.h"
50 #include "rk_fundecl.h"
51
52 /*
53 static int henkan_mode;
54 */
55 /* 0: select
56 1: yomi_nyuuryoku
57 2: bunsetu_nobasi
58 3: kara
59 */
60
61 static void
not_to_han_or_hira()62 not_to_han_or_hira ()
63 {
64 cur_bnst_sv = -1;
65 save_yomi[0] = 0;
66 }
67
68 static void
recover_to_han_or_hira(yomi)69 recover_to_han_or_hira (yomi)
70 register w_char *yomi;
71 {
72 int i;
73 if (cur_bnst_sv == cur_bnst_)
74 {
75 Strcpy (yomi, save_yomi);
76 }
77 else if (cur_bnst_sv >= 0 && cur_bnst_sv < cur_bnst_)
78 {
79 i = jl_yomi_len (bun_data_, cur_bnst_sv, cur_bnst_);
80 Strcpy (yomi, save_yomi + i);
81 }
82 else
83 {
84 jl_get_yomi (bun_data_, cur_bnst_, cur_bnst_sv, yomi);
85 yomi[jl_yomi_len (bun_data_, cur_bnst_, cur_bnst_sv)] = 0;
86 Strcat (yomi, save_yomi);
87 }
88 }
89
90 void
push_func(w_c,func)91 push_func (w_c, func)
92 WnnClientRec *w_c;
93 int (*func) ();
94 {
95 if (w_c->func_stack_count >= (MAX_FUNC_STACK - 1))
96 return;
97 w_c->func_stack_count++;
98 w_c->command_func_stack[w_c->func_stack_count] = func;
99 }
100
101 void
pop_func(w_c)102 pop_func (w_c)
103 WnnClientRec *w_c;
104 {
105 if (w_c->func_stack_count < 0)
106 return;
107 w_c->command_func_stack[w_c->func_stack_count] = (int (*)()) 0;
108 w_c->func_stack_count--;
109 }
110
111 static int
push_char_return(c,romkan)112 push_char_return (c, romkan)
113 int c, romkan;
114 {
115 kakutei ();
116 if (send_ascii_char && (NORMAL_CHAR (c) || c == 0x09) && is_HON (romkan))
117 {
118 if (c_b->maxlen < c_b->buflen)
119 {
120 c_b->maxlen += 1;
121 c_b->buffer[Strlen (c_b->buffer)] = (w_char) (c & 0xffff);
122 }
123 }
124 else
125 {
126 push_unget_buf (romkan);
127 }
128 return (1);
129 }
130
131 static void
change_to_henkango_mode()132 change_to_henkango_mode ()
133 {
134 c_b->key_table = main_table[0];
135 c_b->rk_clear_tbl = romkan_clear_tbl[0];
136 c_b->key_in_fun = push_char_return;
137 c_b->ctrl_code_fun = (int (*)()) 0;
138 c_b->hanten = 0x04 | 0x40;
139 henkan_mode = 0;
140 kk_cursor_invisible ();
141 }
142
143 static void
change_to_insert_mode()144 change_to_insert_mode ()
145 {
146 c_b->key_table = main_table[1];
147 c_b->rk_clear_tbl = romkan_clear_tbl[1];
148 c_b->key_in_fun = (int (*)()) 0;
149 c_b->ctrl_code_fun = (int (*)()) 0;
150 c_b->hanten = 0x08 | 0x20;
151 henkan_mode = 1;
152 kk_cursor_normal ();
153 }
154
155 static int
ignore_it_and_clear_romkan()156 ignore_it_and_clear_romkan ()
157 {
158 romkan_clear ();
159 return (0);
160 }
161
162 static void
change_to_nobasi_tijimi_mode()163 change_to_nobasi_tijimi_mode ()
164 {
165 c_b->key_table = main_table[2];
166 c_b->rk_clear_tbl = romkan_clear_tbl[2];
167 c_b->key_in_fun = ignore_it_and_clear_romkan;
168 c_b->ctrl_code_fun = (int (*)()) 0;
169 c_b->hanten = 0x04;
170 henkan_mode = 2;
171 kk_cursor_invisible ();
172 }
173
174 int
insert_char_and_change_to_insert_mode(c)175 insert_char_and_change_to_insert_mode (c)
176 int c;
177 {
178 insert_char (c);
179 t_redraw_move (c_b->t_c_p + 1, c_b->t_c_p, c_b->maxlen, 0);
180 change_to_insert_mode ();
181 if (send_ascii_char_quote == 1 && send_ascii_char == 0)
182 {
183 send_ascii_char = 1;
184 send_ascii_char_quote = 0;
185 }
186 check_scroll ();
187 return (0);
188 }
189
190 int
insert_modep()191 insert_modep ()
192 {
193 return (henkan_mode == 1);
194 }
195
196 int
empty_modep()197 empty_modep ()
198 {
199 return (henkan_mode == 3);
200 }
201
202 static int
nobasi_tijimi_mode()203 nobasi_tijimi_mode ()
204 {
205 return (henkan_mode == 2);
206 }
207
208 int
kakutei()209 kakutei ()
210 {
211 int moji_suu = 0;
212 w_char *w = 0;
213 w_char yomi[512];
214 /* conversion nashi de kakutei surubaai wo kouryo seyo. */
215
216 remember_buf[0] = 0;
217 if (jl_bun_suu (bun_data_) != 0)
218 {
219 jl_get_yomi (bun_data_, 0, -1, remember_buf);
220 }
221 if (insert_modep ())
222 {
223 moji_suu = c_b->maxlen - c_b->t_m_start;
224 if (moji_suu > 0)
225 {
226 w = remember_buf + Strlen (remember_buf);
227 Strncat (w, c_b->buffer + c_b->t_m_start, moji_suu);
228 }
229 }
230 else if (nobasi_tijimi_mode ())
231 {
232 moji_suu = jl_get_yomi (bun_data_, cur_bnst_, -1, yomi);
233 Strcpy (c_b->buffer + c_b->t_c_p, yomi);
234 c_b->maxlen = Strlen (c_b->buffer);
235 jl_kill (bun_data_, cur_bnst_, -1);
236 }
237 c_b->buffer[0] = 0;
238 if (jl_bun_suu (bun_data_) != 0)
239 {
240 jl_get_kanji (bun_data_, 0, -1, c_b->buffer);
241 if (jl_update_hindo (bun_data_, 0, -1) == -1)
242 {
243 errorkeyin ();
244 redraw_line ();
245 }
246 }
247 if (insert_modep () && moji_suu > 0 && w)
248 {
249 Strcat (c_b->buffer, w);
250 }
251 else if (nobasi_tijimi_mode () && moji_suu > 0)
252 {
253 Strcat (c_b->buffer, yomi);
254 }
255 c_b->maxlen = Strlen (c_b->buffer);
256
257 throw_col (-1);
258 clr_line_all ();
259 return (1);
260 }
261
262 int
return_it(c,romkan)263 return_it (c, romkan)
264 int c, romkan;
265 {
266 return_cl_it ();
267 return (0);
268 }
269
270 int
return_it_if_ascii(c,nisemono)271 return_it_if_ascii (c, nisemono)
272 int c;
273 int nisemono; /* it means that what romkan returned is a nisemono character. */
274 {
275 if ((NORMAL_CHAR (c) || c == 0x09) && is_HON (nisemono))
276 {
277 #ifdef nodef /* use return_cl_it() instead of xw_write(). */
278 c_b->maxlen = 1;
279 c_b->buffer[0] = c;
280 return (1);
281 #endif
282 return_cl_it ();
283 return (0);
284 }
285 else
286 {
287 insert_char_and_change_to_insert_mode (c);
288 return (0);
289 }
290 }
291
292 static void
change_to_empty_mode()293 change_to_empty_mode ()
294 {
295 c_b->key_table = main_table[3];
296 c_b->rk_clear_tbl = romkan_clear_tbl[3];
297 if (send_ascii_char)
298 {
299 c_b->key_in_fun = return_it_if_ascii;
300 }
301 else
302 {
303 c_b->key_in_fun = insert_char_and_change_to_insert_mode;
304 }
305 c_b->ctrl_code_fun = return_it;
306 c_b->hanten = 0x08 | 0x20;
307 henkan_mode = 3;
308 throw_col (0);
309 kk_cursor_normal ();
310 }
311
312 int
redraw_nisemono_c()313 redraw_nisemono_c ()
314 {
315 redraw_nisemono ();
316 if (c_b->maxlen == 0)
317 {
318 change_to_empty_mode ();
319 }
320 return (0);
321 }
322
323 int
kk(c)324 kk (c)
325 int c;
326 {
327 int len;
328
329 if (buffer_in (c) == -1)
330 return (-1);
331 pop_func (c_c);
332 if (print_out_func)
333 {
334 len = (*print_out_func) (return_buf, c_b->buffer, c_b->maxlen);
335 }
336 else
337 {
338 Strncpy (return_buf, c_b->buffer, c_b->maxlen);
339 len = c_b->maxlen;
340 }
341 delete_w_ss2 (return_buf, len);
342 clear_c_b ();
343 /***
344 romkan_clear();
345 ***/
346 return (len);
347 }
348
349 static void
initialize_vars()350 initialize_vars ()
351 {
352 cur_bnst_ = 0;
353 }
354
355 void
clear_c_b()356 clear_c_b ()
357 {
358 initialize_vars ();
359 if (bun_data_)
360 jl_kill (bun_data_, 0, -1);
361 c_b->buffer = input_buffer;
362 c_b->t_c_p = 0;
363 c_b->maxlen = 0;
364 c_b->buflen = maxchg;
365 c_b->redraw_fun = redraw_nisemono_c;
366 c_b->t_m_start = 0;
367 c_b->t_b_st = 0;
368 c_b->t_b_end = 0;
369 change_to_empty_mode ();
370 init_screen ();
371 }
372
373 void
make_kanji_buffer(bnst)374 make_kanji_buffer (bnst)
375 int bnst;
376 {
377 int k, l;
378 w_char *bp;
379 w_char *buffer_end;
380
381 buffer_end = c_b->buffer + c_b->buflen - 1;
382 if (bnst)
383 bp = c_b->buffer + bunsetsuend[bnst - 1];
384 else
385 bp = c_b->buffer;
386 for (k = bnst; k < jl_bun_suu (bun_data_); k++)
387 {
388 if (k < maxbunsetsu)
389 bunsetsu[k] = bp - c_b->buffer;
390 l = jl_get_kanji (bun_data_, k, k + 1, bp);
391 bp += l;
392 if (k < maxbunsetsu)
393 bunsetsuend[k] = bp - c_b->buffer;
394 if (bp > buffer_end)
395 {
396 c_b->maxlen = bp - c_b->buffer;
397 }
398 }
399 if (k < maxbunsetsu)
400 {
401 bunsetsu[k++] = bp - c_b->buffer;
402 bunsetsuend[k++] = bp - c_b->buffer;
403 }
404 else
405 {
406 bunsetsu[maxbunsetsu - 1] = bp - c_b->buffer;
407 bunsetsuend[maxbunsetsu - 1] = bp - c_b->buffer;
408 }
409 c_b->maxlen = bp - c_b->buffer;
410 }
411
412
413 int
isconect_jserver()414 isconect_jserver ()
415 {
416 if (c_c->use_server == 0)
417 return (0);
418 if (!jl_isconnect (bun_data_))
419 {
420 #ifdef USING_XJUTIL
421 kill_xjutil (cur_lang);
422 #endif /* USING_XJUTIL */
423 if (connect_server (cur_lang) < 0)
424 return (0);
425 }
426 if (c_c->use_server && !jl_isconnect (bun_data_))
427 {
428 print_msg_getc (" %s", msg_get (cd, 27, default_message[27], cur_lang->lang), NULL, NULL);
429 return (0);
430 }
431 return (1);
432 }
433
434 static int
ren_henkan0()435 ren_henkan0 ()
436 {
437 w_char yomi[256];
438 int moji_suu;
439 register int i;
440
441 if (!isconect_jserver ())
442 {
443 return (0);
444 }
445
446 c_b->buflen = maxchg;
447 moji_suu = c_b->maxlen - c_b->t_m_start;
448 if (moji_suu > 0)
449 {
450 int ret;
451 Strncpy (yomi, c_b->buffer + c_b->t_m_start, moji_suu);
452 yomi[moji_suu] = 0;
453 ret = jl_ren_conv (bun_data_, yomi, cur_bnst_, -1, WNN_USE_MAE);
454 for (i = cur_bnst_; i < jl_bun_suu (bun_data_); i++)
455 bunsetsu_env[i] = jl_env_get (bun_data_);
456 if (ret == -1)
457 {
458 errorkeyin ();
459 t_print_l ();
460 return (0);
461 }
462 make_kanji_buffer (0);
463 change_to_henkango_mode ();
464 c_b->t_m_start = bunsetsuend[cur_bnst_];
465 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
466 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
467 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, cur_bnst_)], c_b->maxlen, 1);
468 check_scroll ();
469 }
470 return (0);
471 }
472
473 int
ren_henkan()474 ren_henkan ()
475 {
476 jl_env_set (bun_data_, env_normal);
477 return (ren_henkan0 ());
478 }
479
480 int
kankana_ren_henkan()481 kankana_ren_henkan ()
482 {
483 if (c_c->cur_reverse_env && reverse_envrcname && *reverse_envrcname != '\0')
484 {
485 not_to_han_or_hira ();
486 jl_env_set (bun_data_, env_reverse);
487 return (ren_henkan0 ());
488 }
489 else
490 {
491 ring_bell ();
492 return (0);
493 }
494 }
495
496 static void
print_mes_dicconect_js()497 print_mes_dicconect_js ()
498 {
499 print_msg_getc (" %s", msg_get (cd, 27, default_message[27], cur_lang->lang), NULL, NULL);
500 }
501
502
503 static int
tan_conv(daip)504 tan_conv (daip)
505 int daip;
506 {
507 w_char yomi[512];
508 int moji_suu;
509 register int i;
510
511 jl_env_set (bun_data_, env_normal);
512 if (!isconect_jserver ())
513 {
514 return (0);
515 }
516
517 c_b->buflen = maxchg;
518 moji_suu = c_b->maxlen - c_b->t_m_start;
519 if (moji_suu > 0)
520 {
521 int ret;
522 Strncpy (yomi, c_b->buffer + c_b->t_m_start, moji_suu);
523 yomi[moji_suu] = 0;
524 ret = jl_tan_conv (bun_data_, yomi, cur_bnst_, -1, WNN_USE_MAE, daip);
525 if (ret == -1)
526 {
527 (*errorkeyin_func) ();
528 t_print_l ();
529 return (0);
530 }
531 for (i = cur_bnst_; i < dai_end (bun_data_, cur_bnst_); i++)
532 bunsetsu_env[i] = jl_env_get (bun_data_);
533 make_kanji_buffer (0);
534 change_to_henkango_mode ();
535 c_b->t_m_start = bunsetsuend[cur_bnst_];
536 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
537 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
538 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, cur_bnst_)], c_b->maxlen, 1);
539 }
540 return (0);
541 }
542
543 int
tan_henkan()544 tan_henkan ()
545 {
546 jl_env_set (bun_data_, env_normal);
547 return (tan_conv (WNN_SHO));
548 }
549
550 int
tan_henkan_dai()551 tan_henkan_dai ()
552 {
553 if (!c_c->cur_reverse_env)
554 return (0);
555 jl_env_set (bun_data_, env_reverse);
556 return (tan_conv (WNN_DAI));
557 }
558
559 static int
tan_henkan1(daip,env)560 tan_henkan1 (daip, env)
561 struct wnn_env *env;
562 int daip;
563 {
564 int ret;
565 int moji_suu = c_b->t_c_p - c_b->t_m_start;
566 register int i;
567
568 if (c_c->use_server == 0)
569 return (-1);
570 if (!jl_isconnect (bun_data_))
571 {
572 print_mes_dicconect_js ();
573 return (-1);
574 }
575
576 if (moji_suu == 0)
577 {
578 return (-1);
579 }
580 bunsetsu_env[cur_bnst_] = jl_env_get (bun_data_);
581 if (env == NULL)
582 {
583 ret = jl_nobi_conv (bun_data_, cur_bnst_, moji_suu, -1, WNN_USE_MAE, daip);
584 }
585 else
586 {
587 ret = jl_nobi_conv_e2 (bun_data_, env, cur_bnst_, moji_suu, -1, WNN_USE_MAE, daip);
588 }
589
590 if (ret == -1)
591 {
592 errorkeyin ();
593 return (-1);
594 }
595 make_kanji_buffer (0);
596 for (i = cur_bnst_ + 1; i < jl_bun_suu (bun_data_); i++)
597 bunsetsu_env[i] = jl_env_get (bun_data_);
598 change_to_henkango_mode ();
599 c_b->t_c_p = bunsetsu[cur_bnst_];
600 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
601 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
602 return (0);
603 }
604
605 /* nobi_conv(daip) */
606 static int
nobi_conv(daip,env)607 nobi_conv (daip, env)
608 int daip;
609 struct wnn_env *env;
610 {
611 int tmp;
612 if (c_c->use_server == 0)
613 return (0);
614 if (!jl_isconnect (bun_data_))
615 {
616 if (connect_server (cur_lang) < 0)
617 return (0);
618 }
619 tmp = c_b->t_b_st;
620 if (tan_henkan1 (daip, env) == 0)
621 {
622 c_b->t_m_start = bunsetsuend[cur_bnst_];
623 t_redraw_move (bunsetsu[cur_bnst_], MIN_VAL (tmp, c_b->t_b_st), c_b->maxlen, 1);
624 check_scroll ();
625 }
626 return (0);
627 }
628
629 int
nobi_henkan()630 nobi_henkan ()
631 {
632 return (nobi_conv (WNN_SHO, (struct wnn_env *) NULL));
633 }
634
635 int
nobi_henkan_dai()636 nobi_henkan_dai ()
637 {
638 return (nobi_conv (WNN_DAI, (struct wnn_env *) NULL));
639 }
640
641 void
henkan_if_maru(c)642 henkan_if_maru (c)
643 int c;
644 {
645 if (ISKUTENCODE (c) && c_b->key_table == main_table[1])
646 ren_henkan ();
647 }
648
649 /*yank*/
650 int
yank_c()651 yank_c ()
652 {
653 if (empty_modep ())
654 {
655 change_to_insert_mode ();
656 }
657 t_yank ();
658 return (0);
659 }
660
661 int
remember_me()662 remember_me ()
663 {
664 if (jl_bun_suu (bun_data_) == 0)
665 {
666 if (c_b->key_in_fun)
667 {
668 (*c_b->key_in_fun) (-1);
669 c_b->key_in_fun = (int (*)()) 0;
670 }
671 Strcpy (c_b->buffer, remember_buf);
672 c_b->maxlen = Strlen (remember_buf);
673 call_t_redraw_move (0, 0, c_b->maxlen, 1, 1);
674 check_scroll ();
675 }
676 return (0);
677 }
678
679 int
kill_c()680 kill_c ()
681 {
682 t_kill ();
683 if (c_b->maxlen == 0)
684 {
685 change_to_empty_mode ();
686 }
687 return (0);
688 }
689
690 int
delete_c(c,romkan)691 delete_c (c, romkan)
692 int c, romkan;
693 {
694 t_delete_char ();
695 if ((c_b->maxlen == 0) && is_HON (romkan))
696 {
697 change_to_empty_mode ();
698 }
699 return (0);
700 }
701
702 int
rubout_c(c,romkan)703 rubout_c (c, romkan)
704 int c, romkan;
705 {
706 t_rubout (c, romkan);
707 if ((c_b->maxlen == 0) && is_HON (romkan))
708 {
709 change_to_empty_mode ();
710 }
711 return (0);
712 }
713
714 int
end_bunsetsu()715 end_bunsetsu ()
716 {
717 int tmp = cur_bnst_;
718 cur_bnst_ = jl_bun_suu (bun_data_) - 1;
719 c_b->t_m_start = bunsetsuend[cur_bnst_];
720 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
721 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
722 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, tmp)], bunsetsuend[cur_bnst_], 0);
723 check_scroll ();
724 return (0);
725 }
726
727 int
top_bunsetsu()728 top_bunsetsu ()
729 {
730 int tmp = cur_bnst_;
731 cur_bnst_ = 0;
732 c_b->t_m_start = bunsetsuend[0];
733 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
734 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
735 t_redraw_move (bunsetsu[0], 0, bunsetsuend[dai_end (bun_data_, tmp) - 1], 0);
736 check_scroll ();
737 return (0);
738 }
739
740 int
forward_bunsetsu()741 forward_bunsetsu ()
742 {
743 if (cur_bnst_ < jl_bun_suu (bun_data_) - 1)
744 {
745 cur_bnst_ += 1;
746 c_b->t_m_start = bunsetsuend[cur_bnst_];
747 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
748 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
749 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, cur_bnst_ - 1)], bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1], 0);
750 check_scroll ();
751 }
752 return (0);
753 }
754
755 int
backward_bunsetsu()756 backward_bunsetsu ()
757 {
758 if (cur_bnst_ > 0)
759 {
760 cur_bnst_ -= 1;
761 c_b->t_m_start = bunsetsuend[cur_bnst_];
762 c_b->t_b_st = bunsetsu[dai_top (bun_data_, cur_bnst_)];
763 c_b->t_b_end = bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1];
764 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, cur_bnst_)], bunsetsuend[dai_end (bun_data_, cur_bnst_ + 1) - 1], 0);
765 check_scroll ();
766 }
767 return (0);
768 }
769
770 int
kaijo()771 kaijo ()
772 {
773 w_char yomi[512];
774
775 c_b->t_b_end = c_b->t_b_st;
776 t_redraw_move (bunsetsu[cur_bnst_], bunsetsu[dai_top (bun_data_, cur_bnst_)], bunsetsuend[dai_end (bun_data_, cur_bnst_) - 1], 0);
777 change_to_insert_mode ();
778 c_b->t_c_p = bunsetsu[cur_bnst_];
779 c_b->t_m_start = c_b->t_c_p;
780 if (jl_env (bun_data_) == env_normal)
781 jl_get_yomi (bun_data_, cur_bnst_, -1, yomi);
782 else if (c_c->cur_reverse_env && jl_env (bun_data_) == env_reverse)
783 jl_get_yomi (bun_data_, cur_bnst_, -1, yomi); /* kankana_ren_henkan() */
784 else
785 recover_to_han_or_hira (yomi);
786 Strcpy (c_b->buffer + c_b->t_c_p, yomi);
787 c_b->buflen = maxchg;
788 c_b->maxlen = Strlen (c_b->buffer);
789 jl_kill (bun_data_, cur_bnst_, -1);
790 call_t_redraw_move (c_b->t_c_p, c_b->t_c_p, c_b->maxlen, 1, 1);
791 check_scroll ();
792 return (0);
793 }
794
795 int
enlarge_bunsetsu()796 enlarge_bunsetsu ()
797 {
798 w_char yomi[512];
799 int area_len, len1;
800
801 area_len = (*call_jl_yomi_len_func) ();
802 len1 = jl_get_yomi (bun_data_, cur_bnst_, -1, yomi);
803
804 if (area_len < len1)
805 area_len++;
806
807 change_to_nobasi_tijimi_mode ();
808 c_b->t_m_start = c_b->t_c_p;
809 c_b->t_b_end = c_b->t_c_p;
810 Strcpy (c_b->buffer + c_b->t_m_start, yomi);
811 c_b->maxlen = Strlen (c_b->buffer);
812 t_redraw_move (c_b->t_m_start + area_len, c_b->t_m_start, c_b->maxlen, 1);
813 check_scroll ();
814 return (0);
815 }
816
817 int
smallen_bunsetsu()818 smallen_bunsetsu ()
819 {
820 w_char yomi[512];
821 int area_len;
822
823 area_len = (*call_jl_yomi_len_func) ();
824 jl_get_yomi (bun_data_, cur_bnst_, -1, yomi);
825
826 if (area_len > 1)
827 area_len--;
828
829 change_to_nobasi_tijimi_mode ();
830 c_b->t_m_start = c_b->t_c_p;
831 c_b->t_b_end = c_b->t_c_p;
832 Strcpy (c_b->buffer + c_b->t_m_start, yomi);
833 c_b->maxlen = Strlen (c_b->buffer);
834 t_redraw_move (c_b->t_m_start + area_len, c_b->t_m_start, c_b->maxlen, 1);
835 check_scroll ();
836 return (0);
837 }
838
839
840 int
send_string(c)841 send_string (c)
842 int c;
843 {
844 kakutei ();
845 c_b->buffer[c_b->maxlen] = c;
846 c_b->maxlen += 1;
847 c_b->t_c_p = c_b->maxlen;
848 return (1);
849 }
850
851 int
tijime()852 tijime ()
853 {
854 if (c_b->t_c_p > c_b->t_m_start + 1)
855 {
856 backward ();
857 }
858 return (0);
859 }
860
861 int
jmptijime()862 jmptijime ()
863 {
864 call_t_redraw_move_1 (c_b->t_m_start, c_b->t_m_start, c_b->maxlen, 1, 1, 1, (insert_modep ()? 1 : 0));
865 return (0);
866 }
867
868
869 int
henkan_forward()870 henkan_forward ()
871 {
872 if (c_c->use_server == 0)
873 return (0);
874 if (!jl_isconnect (bun_data_))
875 {
876 return (0);
877 }
878
879 if (tan_henkan1 (WNN_DAI, (struct wnn_env *) NULL) == -1)
880 {
881 return (0);
882 }
883 zenkouho_dai_c ();
884 forward_bunsetsu ();
885 return (0);
886 }
887
888 int
henkan_backward()889 henkan_backward ()
890 {
891 if (c_c->use_server == 0)
892 return (0);
893 if (!jl_isconnect (bun_data_))
894 {
895 return (0);
896 }
897
898 if (cur_bnst_ <= 0)
899 {
900 nobi_henkan_dai ();
901 }
902 else
903 {
904 if (tan_henkan1 (WNN_DAI, (struct wnn_env *) NULL) == -1)
905 {
906 return (0);
907 }
908 zenkouho_dai_c ();
909 backward_bunsetsu ();
910 }
911 return (0);
912 }
913
914 int
backward_c()915 backward_c ()
916 {
917 if (c_b->t_c_p == c_b->t_m_start)
918 {
919 if (c_b->t_c_p != 0)
920 {
921 if (!isconect_jserver ())
922 {
923 return (0);
924 }
925 ren_henkan0 ();
926 change_to_henkango_mode ();
927 backward_bunsetsu ();
928 }
929 }
930 else
931 {
932 backward_char ();
933 }
934 return (0);
935 }
936
937 int
insert_it_as_yomi()938 insert_it_as_yomi ()
939 {
940 kakutei ();
941 change_to_insert_mode ();
942 c_b->t_m_start = 0;
943 cur_bnst_ = 0;
944 call_t_print_l (c_b->t_c_p, 1);
945 if (bun_data_)
946 jl_kill (bun_data_, 0, -1);
947 return (0);
948 }
949
950 /****history *******/
951 int
previous_history()952 previous_history ()
953 {
954 int k;
955 if (jl_bun_suu (bun_data_) == 0)
956 {
957 k = previous_history1 (c_b->buffer);
958 if (k > 0)
959 {
960 change_to_insert_mode ();
961 c_b->maxlen = k;
962 c_b->t_c_p = 0;
963 call_t_print_l (c_b->t_c_p, 1);
964 }
965 }
966 return (0);
967 }
968
969 int
next_history()970 next_history ()
971 {
972 int k;
973 if (jl_bun_suu (bun_data_) == 0)
974 {
975 k = next_history1 (c_b->buffer);
976 if (k > 0)
977 {
978 change_to_insert_mode ();
979 c_b->maxlen = k;
980 c_b->t_c_p = 0;
981 call_t_print_l (c_b->t_c_p, 1);
982 }
983 }
984 return (0);
985 }
986
987 /*
988 static int send_ascii_stack = 0;
989 */
990
991 int
send_ascii()992 send_ascii ()
993 {
994 send_ascii_stack = send_ascii_char;
995 send_ascii_char = 1;
996 return (0);
997 }
998
999 int
not_send_ascii()1000 not_send_ascii ()
1001 {
1002 send_ascii_stack = send_ascii_char;
1003 send_ascii_char = 0;
1004 return (0);
1005 }
1006
1007 int
toggle_send_ascii()1008 toggle_send_ascii ()
1009 {
1010 send_ascii_stack = send_ascii_char;
1011 if (send_ascii_char == 0)
1012 {
1013 send_ascii_char = 1;
1014 }
1015 else
1016 {
1017 send_ascii_char = 0;
1018 }
1019 return (0);
1020 }
1021
1022 int
pop_send_ascii()1023 pop_send_ascii ()
1024 {
1025 send_ascii_char = send_ascii_stack;
1026 return (0);
1027 }
1028
1029 /*
1030 int send_ascii_char_quote = 0;
1031 */
1032 static void
quote_send_ascii()1033 quote_send_ascii ()
1034 {
1035 if (send_ascii_char == 1)
1036 {
1037 send_ascii_char = 0;
1038 send_ascii_char_quote = 1;
1039 }
1040 }
1041
1042 static void
check_empty_mode_keyin_fun()1043 check_empty_mode_keyin_fun ()
1044 {
1045 if (send_ascii_char)
1046 {
1047 c_b->key_in_fun = return_it_if_ascii;
1048 }
1049 else
1050 {
1051 c_b->key_in_fun = insert_char_and_change_to_insert_mode;
1052 }
1053 }
1054
1055 int
send_ascii_e()1056 send_ascii_e ()
1057 {
1058 send_ascii ();
1059 check_empty_mode_keyin_fun ();
1060 return (0);
1061 }
1062
1063 int
not_send_ascii_e()1064 not_send_ascii_e ()
1065 {
1066 not_send_ascii ();
1067 check_empty_mode_keyin_fun ();
1068 return (0);
1069 }
1070
1071 int
toggle_send_ascii_e()1072 toggle_send_ascii_e ()
1073 {
1074 toggle_send_ascii ();
1075 check_empty_mode_keyin_fun ();
1076 return (0);
1077 }
1078
1079 int
pop_send_ascii_e()1080 pop_send_ascii_e ()
1081 {
1082 pop_send_ascii ();
1083 check_empty_mode_keyin_fun ();
1084 return (0);
1085 }
1086
1087 int
quote_send_ascii_e()1088 quote_send_ascii_e ()
1089 {
1090 quote_send_ascii ();
1091 check_empty_mode_keyin_fun ();
1092 return (0);
1093 }
1094
1095 int
reconnect_server(in)1096 reconnect_server (in)
1097 int in;
1098 {
1099 static WnnClientRec *c_c_sv = 0;
1100
1101 if (c_c->use_server == 0)
1102 return (0);
1103 if (!jl_isconnect_e (env_normal) || c_c->cur_reverse_env && env_reverse && !jl_isconnect_e (env_reverse))
1104 {
1105
1106 if (c_c_sv != 0 && c_c != c_c_sv)
1107 {
1108 ring_bell ();
1109 return (0);
1110 }
1111 if (c_c_sv == 0)
1112 {
1113 c_c_sv = c_c;
1114 push_func (c_c, reconnect_server);
1115 }
1116
1117 if (reconnect_jserver_body (in) == BUFFER_IN_CONT)
1118 {
1119 return (BUFFER_IN_CONT);
1120 }
1121 c_c_sv = 0;
1122 pop_func (c_c);
1123 }
1124 return (0);
1125 }
1126
1127 int
disconnect_rev_server()1128 disconnect_rev_server ()
1129 {
1130 if (c_c->use_server == 0)
1131 return (0);
1132 return (1);
1133 }
1134
1135 int
disconnect_server(rev)1136 disconnect_server (rev)
1137 int rev;
1138 {
1139 if (c_c->use_server == 0)
1140 return (0);
1141 if (rev)
1142 {
1143 if (jl_isconnect_e (env_reverse))
1144 {
1145 jl_dic_save_all_e (env_reverse);
1146 }
1147 if (jl_isconnect_e (env_reverse))
1148 {
1149 jl_disconnect (env_reverse);
1150 env_reverse = 0;
1151 }
1152 }
1153 else
1154 {
1155 if (jl_isconnect_e (env_normal))
1156 {
1157 jl_dic_save_all_e (env_normal);
1158 }
1159 if (jl_isconnect_e (env_normal))
1160 {
1161 jl_disconnect (env_normal);
1162 env_normal = 0;
1163 }
1164 }
1165 return (1);
1166 }
1167
1168 int
henkan_off(in)1169 henkan_off (in)
1170 int in;
1171 {
1172 unsigned int c;
1173 static w_char wc[1];
1174 static int two_byte_first = 0;
1175
1176 if (in == -99)
1177 {
1178 two_byte_first = 0;
1179 quote_flag = 0;
1180 return (0);
1181 }
1182 if (c_c->command_func_stack[c_c->func_stack_count] == (int (*)()) 0)
1183 {
1184 if (IsStatusArea (cur_p)
1185 #ifdef CALLBACKS
1186 || IsStatusCallbacks (cur_x)
1187 #endif /* CALLBACKS */
1188 )
1189 {
1190 display_henkan_off_mode ();
1191 }
1192 invisual_window ();
1193 henkan_off_flag = 1;
1194 push_func (c_c, henkan_off);
1195 return (BUFFER_IN_CONT);
1196 }
1197 else if (c_c->command_func_stack[c_c->func_stack_count] != henkan_off)
1198 {
1199 ring_bell ();
1200 return (0);
1201 }
1202
1203
1204 for (;;)
1205 {
1206 c = (in & 0x0000ffff);
1207 if ((!quote_flag) && (c == quote_code))
1208 {
1209 quote_flag = 1;
1210 return (BUFFER_IN_CONT);
1211 }
1212 if ((c < TBL_SIZE) && (quote_flag == 0) && (c_b->key_table[c] == henkan_off))
1213 {
1214 break;
1215 }
1216 if (c == 0x8e || (c >= 0xa0 && c <= 0xfe))
1217 {
1218 if (two_byte_first == 1)
1219 {
1220 wc[0] += c;
1221 xw_write (wc, 1);
1222 two_byte_first = 0;
1223 quote_flag = 0;
1224 }
1225 else
1226 {
1227 wc[0] = c * 0x100;
1228 two_byte_first = 1;
1229 }
1230 }
1231 else
1232 {
1233 wc[0] = c;
1234 xw_write (wc, 1);
1235 two_byte_first = 0;
1236 }
1237 quote_flag = 0;
1238 return (BUFFER_IN_CONT);
1239 }
1240 henkan_off_flag = 0;
1241 pop_func (c_c);
1242 disp_mode ();
1243 if (!empty_modep ())
1244 {
1245 visual_window ();
1246 }
1247 return (BUFFER_IN_CONT);
1248 }
1249
1250 int
reset_c_b()1251 reset_c_b ()
1252 {
1253 if (c_c->func_stack_count >= 0)
1254 {
1255 ring_bell ();
1256 return (-1);
1257 }
1258 clear_c_b ();
1259 romkan_clear ();
1260 return (0);
1261 }
1262
1263 #ifdef CHINESE
1264 void
errorkeyin_q()1265 errorkeyin_q ()
1266 {
1267 ring_bell ();
1268 c_b->t_b_end = c_b->t_b_st;
1269 c_b->t_c_p = bunsetsu[cur_bnst_];
1270 c_b->t_m_start = c_b->t_c_p;
1271 c_b->maxlen = c_b->t_c_p;
1272 if (c_b->maxlen == 0)
1273 {
1274 change_to_empty_mode ();
1275 }
1276 }
1277 #endif /* CHINESE */
1278