Mercurial > freewnn
comparison Xwnmo/xjutil/xselectele.c @ 0:bbc77ca4def5
initial import
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 13 Dec 2007 04:30:14 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bbc77ca4def5 |
---|---|
1 /* | |
2 * $Id: xselectele.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 | |
41 /* Version 4.0 | |
42 */ | |
43 #define DD_MAX 512 | |
44 | |
45 #include <stdio.h> | |
46 #include "jslib.h" | |
47 #include "commonhd.h" | |
48 #include "sdefine.h" | |
49 #include "xjutil.h" | |
50 #include "sxheader.h" | |
51 #include "rk_spclval.h" | |
52 #include "rk_fundecl.h" | |
53 #include "xext.h" | |
54 | |
55 #define printh(mm)\ | |
56 if(state == 0){\ | |
57 printf("%c.",((mm - dd[cc]) > 9)? mm - dd[cc] - 10 + 'A':mm - dd[cc] + '0');\ | |
58 printf(data[mm]);\ | |
59 }else{\ | |
60 printf("%c.",((mm > 9)? mm - 10 + 'A':mm + '0'));\ | |
61 printf(data[mm]);} | |
62 | |
63 | |
64 #define kouho_len(x) (strlen(x) + 4) | |
65 | |
66 static int cc; /* ima no gamen */ | |
67 static int kosuu; /* kosuu of elements */ | |
68 extern hilited_item; | |
69 extern max_line; | |
70 | |
71 int | |
72 xw_select_one_element_call (c, kosuu1, init, title) | |
73 char **c; | |
74 int kosuu1; | |
75 int init; | |
76 char *title; | |
77 { | |
78 int in, ret; | |
79 | |
80 for (;;) | |
81 { | |
82 if ((ret = xw_select_one_element (c, kosuu1, init, title, SENTAKU, main_table[4], in)) != BUFFER_IN_CONT) | |
83 return (ret); | |
84 in = keyin (); | |
85 } | |
86 } | |
87 | |
88 int | |
89 xw_select_one_element_keytable (c, kosuu1, init, title, bcnt, btable_t, b_tbl, key_tbl, comment) | |
90 char **c; | |
91 int kosuu1; | |
92 int init; | |
93 char *title; | |
94 int bcnt; | |
95 char *btable_t[]; | |
96 int (**b_tbl) (); | |
97 int (**key_tbl) (); | |
98 char *comment; | |
99 { | |
100 register int i; | |
101 int d; | |
102 unsigned int c1; | |
103 int ret; | |
104 | |
105 kosuu = kosuu1; | |
106 init_ichiran (c, kosuu1, init, title, (unsigned char *) "", (unsigned char *) "", comment, 0, SENTAKU); | |
107 for (;;) | |
108 { | |
109 TOP: | |
110 xjutil->sel_ret = -1; | |
111 c1 = keyin (); | |
112 if (xjutil->sel_ret == -2) | |
113 { | |
114 end_ichiran (); | |
115 romkan_clear (); | |
116 return (-1); | |
117 } | |
118 else if (xjutil->sel_ret != -1) | |
119 { | |
120 d = find_hilite (); | |
121 xjutil->sel_ret = -1; | |
122 if (d < 0 || d > kosuu) | |
123 { | |
124 ring_bell (); | |
125 continue; | |
126 } | |
127 } | |
128 else | |
129 { | |
130 if ((c1 < 256) && (key_tbl[c1] != NULL)) | |
131 { | |
132 cc = d = find_hilite (); | |
133 if (d < 0 || d > kosuu) | |
134 { | |
135 ring_bell (); | |
136 continue; | |
137 } | |
138 for (i = 0; i < bcnt; i++) | |
139 { | |
140 if (key_tbl[c1] == b_tbl[i]) | |
141 { | |
142 lock_ichiran (); | |
143 break; | |
144 } | |
145 } | |
146 ret = (*key_tbl[c1]) (); | |
147 unlock_ichiran (); | |
148 if (ret == -1) | |
149 { | |
150 end_ichiran (); | |
151 romkan_clear (); | |
152 return (-1); | |
153 } | |
154 else if (ret == 1) | |
155 { | |
156 end_ichiran (); | |
157 romkan_clear (); | |
158 return (0); | |
159 } | |
160 else | |
161 { | |
162 continue; | |
163 } | |
164 } | |
165 else | |
166 { | |
167 ring_bell (); | |
168 continue; | |
169 } | |
170 } | |
171 romkan_clear (); | |
172 if (!bcnt) | |
173 { | |
174 end_ichiran (); | |
175 return (d); | |
176 } | |
177 else | |
178 { | |
179 cc = d; | |
180 lock_ichiran (); | |
181 } | |
182 init_keytable (bcnt, btable_t); | |
183 for (;;) | |
184 { | |
185 c1 = keyin (); | |
186 if (xjutil->sel_ret == -2) | |
187 { | |
188 end_ichiran (); | |
189 end_keytable (); | |
190 romkan_clear (); | |
191 return (-1); | |
192 } | |
193 else if (xjutil->sel_ret != -1) | |
194 { | |
195 d = xjutil->sel_ret; | |
196 xjutil->sel_ret = -1; | |
197 if ((d < bcnt) && (b_tbl[d] != NULL)) | |
198 { | |
199 end_keytable (); | |
200 if ((ret = (*b_tbl[d]) ()) == 1) | |
201 { | |
202 end_ichiran (); | |
203 romkan_clear (); | |
204 return (0); | |
205 } | |
206 unlock_ichiran (); | |
207 goto TOP; | |
208 } | |
209 else | |
210 { | |
211 ring_bell (); | |
212 } | |
213 } | |
214 else | |
215 { | |
216 if ((c1 < 256) && (key_tbl[c1] != NULL)) | |
217 { | |
218 end_keytable (); | |
219 if ((ret = (*key_tbl[c1]) ()) == 1) | |
220 { | |
221 end_ichiran (); | |
222 romkan_clear (); | |
223 return (0); | |
224 } | |
225 unlock_ichiran (); | |
226 goto TOP; | |
227 } | |
228 else | |
229 { | |
230 ring_bell (); | |
231 xjutil->sel_ret = -1; | |
232 continue; | |
233 } | |
234 } | |
235 } | |
236 romkan_clear (); | |
237 } | |
238 } | |
239 | |
240 /* | |
241 * | |
242 * Functions Called during select element (dictionaries). | |
243 * | |
244 */ | |
245 | |
246 /* jishodel for kensaku */ | |
247 int | |
248 kdicdel () | |
249 { | |
250 char buf[512]; | |
251 | |
252 sprintf (buf, "%s %s %s", msg_get (cd, 77, default_message[77], xjutil->lang), dicinfo[cc].fname, msg_get (cd, 78, default_message[78], xjutil->lang)); | |
253 if (yes_or_no (buf) == 1) | |
254 { | |
255 if (dic_delete_e (cur_env, dicinfo[cc].dic_no) == -1) | |
256 { | |
257 errorkeyin (); | |
258 return (0); | |
259 } | |
260 return (1); | |
261 } | |
262 return (0); | |
263 } | |
264 | |
265 | |
266 int | |
267 kdicuse () | |
268 { | |
269 char buf[512]; | |
270 | |
271 if (dicinfo[cc].enablef) | |
272 { | |
273 sprintf (buf, "%s %s %s", msg_get (cd, 77, default_message[77], xjutil->lang), dicinfo[cc].fname, msg_get (cd, 79, default_message[89], xjutil->lang)); | |
274 } | |
275 else | |
276 { | |
277 sprintf (buf, "%s %s %s", msg_get (cd, 77, default_message[77], xjutil->lang), dicinfo[cc].fname, msg_get (cd, 80, default_message[80], xjutil->lang)); | |
278 } | |
279 if (yes_or_no (buf) == 1) | |
280 { | |
281 if (js_dic_use (cur_env, dicinfo[cc].dic_no, !dicinfo[cc].enablef) == -1) | |
282 { | |
283 if_dead_disconnect (cur_env, -1); | |
284 errorkeyin (); | |
285 return (0); | |
286 } | |
287 return (1); | |
288 } | |
289 return (0); | |
290 } | |
291 | |
292 int | |
293 kdiccom () | |
294 { | |
295 w_char com[512]; | |
296 WNN_DIC_INFO dic; | |
297 WNN_FILE_INFO_STRUCT file; | |
298 char *mes[1]; | |
299 | |
300 com[0] = 0; | |
301 mes[0] = msg_get (cd, 81, default_message[81], xjutil->lang); | |
302 init_jutil (msg_get (cd, 39, default_message[39], xjutil->lang), msg_get (cd, 8, default_message[8], xjutil->lang), 1, &mes, NULL); | |
303 cur_text->max_pos = 127; | |
304 clr_line_all (); | |
305 throw_col (0); | |
306 kk_cursor_normal (); | |
307 if (kana_in (UNDER_LINE_MODE, com, 512) == -1) | |
308 { | |
309 kk_cursor_invisible (); | |
310 end_jutil (); | |
311 return (0); | |
312 } | |
313 kk_cursor_invisible (); | |
314 end_jutil (); | |
315 if (js_dic_info (cur_env, dicinfo[cc].dic_no, &dic) < 0) | |
316 { | |
317 if_dead_disconnect (cur_env, -1); | |
318 return (0); | |
319 } | |
320 if (js_file_info (cur_env, dic.body, &file) < 0) | |
321 { | |
322 if_dead_disconnect (cur_env, -1); | |
323 return (0); | |
324 } | |
325 if (js_file_comment_set (cur_env, file.fid, com) == -1) | |
326 { | |
327 if_dead_disconnect (cur_env, -1); | |
328 errorkeyin (); | |
329 return (0); | |
330 } | |
331 return (1); | |
332 } | |
333 | |
334 /* | |
335 * | |
336 * Functions Called during select element (dic_entries). | |
337 * | |
338 */ | |
339 | |
340 /* Defined in kensaku.c */ | |
341 extern struct wnn_jdata *word_searched; | |
342 extern int del_point, ima_point, hindo_point, com_point, max_c_len; | |
343 | |
344 int | |
345 kworddel () | |
346 { | |
347 int type; | |
348 | |
349 if (cur_root->ichi->buf[cc][del_point] == 'D') | |
350 { | |
351 change_ichi_buf (cc, del_point, " "); | |
352 return (0); | |
353 } | |
354 type = dicinfo[find_dic_by_no (word_searched[cc].dic_no)].type; | |
355 if (type != WNN_UD_DICT && type != WNN_REV_DICT && type != CWNN_REV_DICT) | |
356 { | |
357 print_msg_getc (msg_get (cd, 82, default_message[82], xjutil->lang), NULL, NULL, NULL); | |
358 return (0); | |
359 } | |
360 if (dicinfo[find_dic_by_no (word_searched[cc].dic_no)].rw == WNN_DIC_RDONLY) | |
361 { | |
362 print_msg_getc (msg_get (cd, 83, default_message[83], xjutil->lang), NULL, NULL, NULL); | |
363 return (0); | |
364 } | |
365 change_ichi_buf (cc, del_point, "D"); | |
366 return (0); | |
367 } | |
368 | |
369 int | |
370 kworddel_op () | |
371 { | |
372 register int i; | |
373 char buf[512]; | |
374 Ichiran *ichi = cur_root->ichi; | |
375 | |
376 for (i = 0; i < ichi->kosuu_all; i++) | |
377 { | |
378 if (ichi->buf[i][del_point] != 'D') | |
379 continue; | |
380 strcpy (buf, msg_get (cd, 84, default_message[84], xjutil->lang)); | |
381 sStrcpy (buf + strlen (buf), word_searched[i].kanji); | |
382 sprintf (buf + strlen (buf), "%s", msg_get (cd, 85, default_message[85], xjutil->lang)); | |
383 if (yes_or_no (buf) == 1) | |
384 { | |
385 if (js_word_delete (cur_env, word_searched[i].dic_no, word_searched[i].serial) == -1) | |
386 { | |
387 if_dead_disconnect (cur_env, -1); | |
388 errorkeyin (); | |
389 } | |
390 } | |
391 } | |
392 return (1); | |
393 } | |
394 | |
395 int | |
396 kwordcom () | |
397 { | |
398 w_char com[512]; | |
399 char buf[512]; | |
400 int type, len; | |
401 char *mes[1]; | |
402 | |
403 type = dicinfo[find_dic_by_no (word_searched[cc].dic_no)].type; | |
404 if (type != WNN_UD_DICT && type != WNN_REV_DICT && type != CWNN_REV_DICT) | |
405 { | |
406 print_msg_getc (msg_get (cd, 89, default_message[89], xjutil->lang), NULL, NULL, NULL); | |
407 return (0); | |
408 } | |
409 if (dicinfo[find_dic_by_no (word_searched[cc].dic_no)].rw == WNN_DIC_RDONLY) | |
410 { | |
411 print_msg_getc (msg_get (cd, 90, default_message[90], xjutil->lang), NULL, NULL, NULL); | |
412 return (0); | |
413 } | |
414 | |
415 com[0] = 0; | |
416 mes[0] = msg_get (cd, 81, default_message[81], xjutil->lang); | |
417 init_jutil (msg_get (cd, 39, default_message[39], xjutil->lang), msg_get (cd, 8, default_message[8], xjutil->lang), 1, &mes, NULL); | |
418 cur_text->max_pos = 127; | |
419 clr_line_all (); | |
420 throw_col (0); | |
421 kk_cursor_normal (); | |
422 if (kana_in (UNDER_LINE_MODE, com, 512) == -1) | |
423 { | |
424 kk_cursor_invisible (); | |
425 end_jutil (); | |
426 return (0); | |
427 } | |
428 kk_cursor_invisible (); | |
429 end_jutil (); | |
430 if (js_word_comment_set (cur_env, word_searched[cc].dic_no, word_searched[cc].serial, com) == -1) | |
431 { | |
432 if_dead_disconnect (cur_env, -1); | |
433 errorkeyin (); | |
434 return (0); | |
435 } | |
436 bzero (buf, sizeof (buf)); | |
437 if (Strlen (com)) | |
438 { | |
439 strcpy (buf, "{"); | |
440 sStrcpy (buf + strlen (buf), com); | |
441 strcat (buf, "} "); | |
442 } | |
443 if (strlen (buf) > max_c_len) | |
444 { | |
445 len = strlen (buf) - max_c_len; | |
446 insert_space_in_ichi_buf (com_point + max_c_len, len); | |
447 max_c_len = strlen (buf); | |
448 ima_point += len; | |
449 hindo_point += len; | |
450 } | |
451 else | |
452 { | |
453 fill_space (buf, max_c_len); | |
454 } | |
455 change_ichi_buf (cc, com_point, buf); | |
456 return (0); | |
457 } | |
458 | |
459 static int | |
460 call_hindo_set (ima, hindo) | |
461 int ima; | |
462 int hindo; | |
463 { | |
464 if (js_hindo_set (cur_env, word_searched[cc].dic_no, word_searched[cc].serial, ima, hindo) == -1) | |
465 { | |
466 if_dead_disconnect (cur_env, -1); | |
467 errorkeyin (); | |
468 return (0); | |
469 } | |
470 return (1); | |
471 } | |
472 | |
473 int | |
474 kwordima () | |
475 { | |
476 if (word_searched[cc].ima) | |
477 { | |
478 if (call_hindo_set (WNN_IMA_OFF, WNN_HINDO_NOP)) | |
479 { | |
480 change_ichi_buf (cc, ima_point, " "); | |
481 word_searched[cc].ima = 0; | |
482 } | |
483 } | |
484 else | |
485 { | |
486 if (call_hindo_set (WNN_IMA_ON, WNN_HINDO_NOP)) | |
487 { | |
488 change_ichi_buf (cc, ima_point, "*"); | |
489 word_searched[cc].ima = 1; | |
490 } | |
491 } | |
492 return (0); | |
493 } | |
494 | |
495 int | |
496 kworduse () | |
497 { | |
498 int ima, hindo; | |
499 char buf[32]; | |
500 extern int wnn_word_use_initial_hindo; | |
501 | |
502 if (word_searched[cc].hindo != -1) | |
503 { | |
504 if (call_hindo_set (WNN_HINDO_NOP, WNN_ENTRY_NO_USE)) | |
505 { | |
506 change_ichi_buf (cc, ima_point, "---- "); | |
507 word_searched[cc].hindo = -1; | |
508 } | |
509 } | |
510 else | |
511 { | |
512 ima = wnn_word_use_initial_hindo & 0x80; | |
513 hindo = wnn_word_use_initial_hindo & 0x7f; | |
514 if (call_hindo_set ((ima ? WNN_IMA_ON : WNN_IMA_OFF), hindo)) | |
515 { | |
516 sprintf (buf, "%c%-3d ", (ima ? '*' : ' '), hindo); | |
517 change_ichi_buf (cc, ima_point, buf); | |
518 word_searched[cc].hindo = hindo; | |
519 word_searched[cc].ima = ima; | |
520 } | |
521 | |
522 } | |
523 return (0); | |
524 } | |
525 | |
526 int | |
527 kwordhindo () | |
528 { | |
529 int cur_hindo; | |
530 char *mes[1]; | |
531 w_char kana_buf[512]; | |
532 char st[32]; | |
533 char buf[32]; | |
534 int newhindo; | |
535 char message[80]; | |
536 | |
537 if (dicinfo[find_dic_by_no (word_searched[cc].dic_no)].hindo_rw == WNN_DIC_RDONLY) | |
538 { | |
539 print_msg_getc (msg_get (cd, 118, default_message[118], xjutil->lang), NULL, NULL, NULL); | |
540 return (0); | |
541 } | |
542 cur_hindo = word_searched[cc].hindo; | |
543 | |
544 sprintf (message, "%s %d %s", msg_get (cd, 119, default_message[119], xjutil->lang), cur_hindo, msg_get (cd, 32, default_message[32], xjutil->lang)); | |
545 | |
546 mes[0] = msg_get (cd, 33, default_message[33], xjutil->lang); | |
547 init_jutil (message, msg_get (cd, 8, default_message[8], xjutil->lang), 1, &mes, NULL); | |
548 Retry: | |
549 cur_text->max_pos = 127; | |
550 clr_line_all (); | |
551 throw_col (0); | |
552 kk_cursor_normal (); | |
553 kana_buf[0] = 0; | |
554 if (kana_in (UNDER_LINE_MODE, kana_buf, 512) == -1) | |
555 { | |
556 kk_cursor_invisible (); | |
557 end_jutil (); | |
558 return (0); | |
559 } | |
560 kk_cursor_invisible (); | |
561 if (sStrcpy_and_ck (st, kana_buf) || sscanf (st, "%d", &newhindo) <= 0) | |
562 { | |
563 print_msg_getc ("%s", msg_get (cd, 34, default_message[34], xjutil->lang), NULL, NULL); | |
564 goto Retry; | |
565 } | |
566 else if (newhindo < 0) | |
567 { | |
568 print_msg_getc ("%s", msg_get (cd, 35, default_message[35], xjutil->lang), NULL, NULL); | |
569 goto Retry; | |
570 } | |
571 | |
572 end_jutil (); | |
573 if (call_hindo_set (WNN_HINDO_NOP, newhindo)) | |
574 { | |
575 sprintf (buf, "%-3d ", newhindo); | |
576 change_ichi_buf (cc, hindo_point, buf); | |
577 word_searched[cc].hindo = newhindo; | |
578 } | |
579 return (0); | |
580 } | |
581 | |
582 /* | |
583 Local Variables: | |
584 eval: (setq kanji-flag t) | |
585 eval: (setq kanji-fileio-code 0) | |
586 eval: (mode-line-kanji-code-update) | |
587 End: | |
588 */ |