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