1 /*
2 * $Id: touroku.c,v 1.3 2001/06/14 18:16:08 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 /* ��Ͽ�Τ���Υ롼���� */
33
34 #include <stdio.h>
35 #include "jllib.h"
36 #include "commonhd.h"
37 #include "sdefine.h"
38 #include "sheader.h"
39 #include "rk_spclval.h"
40 #include "buffer.h"
41 #include "jslib.h"
42
43 static int touroku_start, touroku_end;
44 /* these are used only for making yomi string for registered kanji */
45
46
47 /*
48 static char *end_msg = "��Ͽ����:";
49 static char *start_msg = "��Ͽ�Ϥ�:";
50 static char *dic_choice = "����: ";
51 extern int cursor_invisible;
52 static char *msg_st = " �ɤ�:";
53 */
54
55 int touroku_mark = -1;
56
57 static int hani_settei ();
58
59 /* ��Ͽ�Τ���γ����ؿ�*/
60 void
touroku()61 touroku ()
62 {
63 int k;
64 w_char yomibuf[1024];
65 w_char message[1024];
66 w_char hani_buffer[1024];
67 char dic_name_heap[2048];
68 char *hp = dic_name_heap;
69 int hinsi;
70 int tmp;
71 char *dict_name[JISHOKOSUU];
72 static int current_dic;
73 int current = 0;
74 int size;
75 w_char comment[LENGTHKANJI];
76 /*
77 char *commessage = "������:";
78 */
79
80
81 if (update_dic_list (bun_data_) == -1)
82 {
83 errorkeyin ();
84 return;
85 }
86 for (k = 0, size = 0; k < dic_list_size; k++)
87 {
88 if ((dicinfo[k].type == WNN_UD_DICT || dicinfo[k].type == WNN_REV_DICT || dicinfo[k].type == BWNN_REV_DICT || dicinfo[k].type == CWNN_REV_DICT) && dicinfo[k].rw == 0)
89 {
90 size++;
91 }
92 }
93 if (size == 0)
94 {
95 /*
96 print_msg_getc("��Ͽ��ǽ�����μ���Ĥ⤢��ޤ���");
97 */
98 print_msg_getc (MSG_GET (42));
99 return;
100 }
101
102 repeat:
103
104 for (k = 0; k < 1024; k++)
105 {
106 yomibuf[k] = 0;
107 }
108 tmp = hani_settei (hani_buffer, 1024);
109
110 if (tmp == -1)
111 {
112 return;
113 }
114 if (Strlen (hani_buffer) >= 64)
115 {
116 /*
117 print_msg_getc("��Ͽ�ϰϤ�Ĺ��ޤ���(ǡ��)");
118 */
119 print_msg_getc (MSG_GET (43));
120 goto repeat;
121 }
122
123 message[0] = 0;
124 Strcpy (message + Strlen (message), hani_buffer);
125 Sstrcpy (message + Strlen (message), MSG_GET (41));
126 touroku_mark = -1;
127 find_yomi_for_kanji (hani_buffer, yomibuf);
128
129 kana_start:
130
131 if (kana_in_w_char_msg (message, (0x08 | 0x20), yomibuf, 1024) == -1)
132 {
133 return;
134 }
135 if (Strlen (yomibuf) >= 64)
136 {
137 /*
138 print_msg_getc("�ɤߤ�Ĺ��ޤ���(ǡ��)");
139 */
140 print_msg_getc (MSG_GET (44));
141 goto kana_start;
142 }
143 if ((hinsi = hinsi_in ()) == -1)
144 {
145 return;
146 }
147
148 for (k = 0, size = 0; k < dic_list_size; k++)
149 {
150 if ((dicinfo[k].type == WNN_UD_DICT || dicinfo[k].type == WNN_REV_DICT || dicinfo[k].type == BWNN_REV_DICT || dicinfo[k].type == CWNN_REV_DICT) && dicinfo[k].rw == 0)
151 {
152 if (*dicinfo[k].comment)
153 {
154 sStrcpy (hp, dicinfo[k].comment);
155 dict_name[size] = hp;
156 hp += strlen (hp) + 1;
157 }
158 else
159 {
160 dict_name[size] = dicinfo[k].fname;
161 }
162 if (dicinfo[k].dic_no == current_dic)
163 current = size;
164 size++;
165 }
166 }
167 if (size == 1)
168 {
169 k = 0;
170 }
171 else
172 {
173 k = select_one_element (dict_name, size, current, MSG_GET (40), strlen (MSG_GET (40)), 0, main_table[4]);
174 if (k == -1)
175 {
176 return;
177 }
178 }
179
180 /* find UD */
181 for (tmp = 0; tmp < dic_list_size; tmp++)
182 {
183 if ((dicinfo[tmp].type == WNN_UD_DICT || dicinfo[tmp].type == WNN_REV_DICT || dicinfo[tmp].type == BWNN_REV_DICT || dicinfo[tmp].type == CWNN_REV_DICT) && dicinfo[tmp].rw == 0)
184 {
185 k--;
186 if (k < 0)
187 break;
188 }
189 }
190 comment[0] = 0;
191 if (touroku_comment)
192 {
193 if (kana_in (MSG_GET (35), UNDER_LINE_MODE, comment, LENGTHYOMI) == -1)
194 {
195 comment[0] = 0;
196 }
197 }
198 if (jl_word_add (bun_data_, dicinfo[tmp].dic_no, yomibuf, hani_buffer, comment, hinsi, 0) == -1)
199 {
200 errorkeyin ();
201 return;
202 }
203 return;
204 }
205
206
207 /** key_table�˥Х���ɤ����Ѥ��ޤ�*/
208 int
t_markset()209 t_markset ()
210 {
211
212 if (c_b->t_m_start == -2)
213 {
214 return (0);
215 }
216 if (touroku_mark == -1)
217 {
218 /*
219 if(c_b->t_m_start == -1) {
220 */
221 if (c_b->t_c_p == c_b->maxlen)
222 {
223 return (0);
224 }
225 c_b->t_m_start = c_b->t_c_p;
226 /*
227 print_buf_msg(c_b->buf_msg = end_msg);
228 */
229 print_buf_msg (c_b->buf_msg = MSG_GET (38));
230 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);
231 touroku_mark = 1;
232 kk_cursor_invisible ();
233 return (0);
234 }
235 else
236 {
237 if (c_b->t_m_start == c_b->t_c_p)
238 {
239 c_b->t_m_start = -1;
240 print_buf_msg (c_b->buf_msg = MSG_GET (39));
241 touroku_mark = -1;
242 kk_cursor_normal ();
243 if (!cursor_invisible_fun)
244 t_throw ();
245 flush ();
246 return (0);
247 }
248 else
249 {
250 return (1);
251 }
252 }
253 }
254
255 void
make_touroku_buffer(bnst,cbup)256 make_touroku_buffer (bnst, cbup)
257 int bnst;
258 struct buf *cbup;
259 {
260 int k, l;
261 w_char *bp;
262 w_char *buffer_end; /** ��̾�����ѤΥХåե����κǸ� */
263
264 buffer_end = c_b->buffer + c_b->buflen - 1;
265 bp = c_b->buffer;
266 for (k = bnst; k < jl_bun_suu (bun_data_); k++)
267 {
268 if (nobasi_tijimi_mode () && k == cur_bnst_) /* �ΤФ��������ߥ⡼�� */
269 break;
270 if (k < maxbunsetsu)
271 touroku_bnst[k] = bp - c_b->buffer;
272 l = jl_get_kanji (bun_data_, k, k + 1, bp);
273 bp += l;
274 if (bp >= buffer_end)
275 {
276 k--;
277 bp -= l;
278 goto GOT_IT;
279 }
280 }
281 if (cbup->maxlen == 0)
282 { /* ��������Ͽ */
283 /* �ҥ��ȥ꤫����äƤ��롣 */
284 get_end_of_history (bp);
285 }
286 else if (nobasi_tijimi_mode ())
287 { /* �ΤФ��������ߥ⡼�� */
288 Strncpy (bp, cbup->buffer + bunsetsu[cur_bnst_], cbup->maxlen - bunsetsu[cur_bnst_]);
289 *(bp + cbup->maxlen - bunsetsu[cur_bnst_]) = 0;
290 }
291 else
292 {
293 /* ����Dz����������ʸ���� */
294 Strncpy (bp, cbup->buffer + bunsetsu[jl_bun_suu (bun_data_)], cbup->maxlen - bunsetsu[jl_bun_suu (bun_data_)]);
295 *(bp + cbup->maxlen - bunsetsu[jl_bun_suu (bun_data_)]) = 0;
296 }
297
298 GOT_IT:
299 if (k < maxbunsetsu)
300 {
301 touroku_bnst[k++] = bp - c_b->buffer;
302 touroku_bnst_cnt = k;
303 }
304 else
305 {
306 touroku_bnst[maxbunsetsu - 1] = bp - c_b->buffer;
307 touroku_bnst_cnt = maxbunsetsu;
308 }
309 }
310
311 int
hani_settei_normal(c_b)312 hani_settei_normal (c_b)
313 struct buf *c_b;
314 {
315 c_b->hanten = 0x04;
316 c_b->t_c_p = touroku_bnst[cur_bnst_];
317 c_b->buf_msg = MSG_GET (39);
318 c_b->start_col = 9;
319 touroku_mark = -1;
320 c_b->t_m_start = -1; /* -1:�ޤ����åȤ���Ƥ��ʤ� */
321 set_screen_vars_default ();
322
323 c_b->key_table = main_table[5];
324 c_b->rk_clear_tbl = romkan_clear_tbl[5];
325 c_b->key_in_fun = 0;
326 c_b->redraw_fun = redraw_nisemono;
327 c_b->ctrl_code_fun = (int (*)()) 0;
328 init_screen ();
329 return (0);
330 }
331
332 #ifdef CHINESE
333 int
hani_settei_yincod(c_b)334 hani_settei_yincod (c_b)
335 struct buf *c_b;
336 {
337 c_b->hanten = 0x04 | 0x40;
338 c_b->t_c_p = touroku_bnst[cur_bnst_];
339 c_b->buf_msg = MSG_GET (39);
340 c_b->start_col = 9;
341 c_b->t_b_st = c_b->t_c_p;
342 c_b->t_b_end = c_b->t_c_p + 1;
343 c_b->t_m_start = c_b->t_c_p + 1;
344 touroku_mark = -1;
345 kk_cursor_invisible ();
346 set_screen_vars_default ();
347
348 c_b->key_table = main_table[5];
349 c_b->rk_clear_tbl = romkan_clear_tbl[5];
350 c_b->key_in_fun = 0;
351 c_b->redraw_fun = redraw_nisemono;
352 c_b->ctrl_code_fun = (int (*)()) 0;
353 init_screen ();
354 c_b->t_m_start = -1;
355 return (0);
356 }
357 #endif /* CHINESE */
358
359
360 /* �ϰ�����롼����*/
361 static int
hani_settei(buffer,buflen)362 hani_settei (buffer, buflen)
363 w_char *buffer;
364 int buflen;
365 {
366 struct buf *c_btmp, c_b1;
367
368 c_btmp = c_b;
369 c_b = &c_b1;
370
371 c_b->buffer = buffer;
372 c_b->buflen = buflen;
373
374
375 make_touroku_buffer (0, c_btmp);
376 c_b->maxlen = Strlen (buffer);
377
378 (*hani_settei_func) (c_b);
379 if (buffer_in () == -1)
380 {
381 c_b = c_btmp;
382 kk_cursor_normal ();
383 return (-1);
384 }
385 kk_cursor_normal ();
386 Strncpy (buffer, buffer + c_b->t_m_start, c_b->t_c_p - c_b->t_m_start);
387 buffer[c_b->t_c_p - c_b->t_m_start] = 0;
388 touroku_start = c_b->t_m_start;
389 touroku_end = c_b->t_c_p;
390 c_b = c_btmp;
391 return (c_b1.t_c_p - c_b1.t_m_start);
392 }
393
394
395 void
find_yomi_for_kanji(kanji_string,yomi_buf)396 find_yomi_for_kanji (kanji_string, yomi_buf)
397 w_char *kanji_string, *yomi_buf;
398 {
399 w_char *w;
400 int k;
401 int s_bun, s_offset;
402 int e_bun, e_offset;
403 int kana_start, kana_end;
404 int ylen, klen;
405
406 for (w = kanji_string; *w; w++)
407 {
408 if (!(YOMICHAR (*w) || KATAP (*w)))
409 break;
410 }
411 if (!(*w))
412 {
413 Strcpy (yomi_buf, kanji_string);
414 for (k = Strlen (yomi_buf) - 1; k >= 0; k--)
415 {
416 yomi_buf[k] = HIRA_OF (yomi_buf[k]);
417 }
418 yomi_buf[k] = 0;
419 }
420 else
421 {
422 if (!henkan_gop ())
423 {
424 yomi_buf[0] = 0;
425 }
426 else
427 {
428 for (k = 0; k < jl_bun_suu (bun_data_) && touroku_bnst[k + 1] <= touroku_start; k++);
429 s_bun = k;
430 s_offset = touroku_start - touroku_bnst[k];
431
432 for (; k < jl_bun_suu (bun_data_) && touroku_bnst[k] < touroku_end; k++);
433 k--;
434 e_bun = k;
435 e_offset = touroku_end - touroku_bnst[k];
436
437
438 kana_end = jl_get_yomi (bun_data_, s_bun, e_bun + 1, yomi_buf) - jl_yomi_len (bun_data_, e_bun, e_bun + 1);
439
440
441 ylen = jl_yomi_len (bun_data_, s_bun, s_bun + 1);
442 klen = jl_kanji_len (bun_data_, s_bun, s_bun + 1) - (ylen - jl_jiri_len (bun_data_, s_bun));
443
444 if (s_offset < klen)
445 {
446 kana_start = 0;
447 }
448 else
449 {
450 kana_start = jl_jiri_len (bun_data_, s_bun) + s_offset - klen;
451 }
452
453 ylen = jl_yomi_len (bun_data_, e_bun, e_bun + 1);
454 klen = jl_kanji_len (bun_data_, e_bun, e_bun + 1) - (ylen - jl_jiri_len (bun_data_, e_bun));
455
456 if (e_offset < klen)
457 {
458 kana_end += jl_jiri_len (bun_data_, s_bun);
459 }
460 else
461 {
462 kana_end += jl_jiri_len (bun_data_, e_bun) + e_offset - klen;
463 }
464 Strcpy (yomi_buf, yomi_buf + kana_start, kana_end - kana_start);
465 yomi_buf[kana_end - kana_start] = 0;
466 }
467 }
468 }
469
470 int
find_end_of_tango(c)471 find_end_of_tango (c)
472 int c;
473 {
474 int k;
475 int jisyu; /* 0: katakana 1: hiragana 2:ascii 3:kanji */
476
477 if (KATAP (c_b->buffer[c]))
478 jisyu = 0;
479 else if (HIRAP (c_b->buffer[c]))
480 jisyu = 1;
481 else if (ASCIIP (c_b->buffer[c]))
482 jisyu = 2;
483 else if (KANJIP (c_b->buffer[c]))
484 jisyu = 3;
485 else
486 return (c + 1);
487
488 for (k = c + 1; k < c_b->maxlen; k++)
489 {
490 if (jisyu == 0)
491 {
492 if (!KATAP (c_b->buffer[k]))
493 break;
494 }
495 else if (jisyu == 1)
496 {
497 if (!HIRAP (c_b->buffer[k]))
498 break;
499 }
500 else if (jisyu == 2)
501 {
502 if (!ASCIIP (c_b->buffer[k]))
503 break;
504 }
505 else if (jisyu == 3)
506 {
507 if (!KANJIP (c_b->buffer[k]))
508 break;
509 }
510 }
511 return (k);
512 }
513