0
|
1 /*
|
|
2 * $Id: kuten.c,v 1.2 2001/06/14 18:16:16 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 /*
|
|
43 ** programs for KUTEN NYUURYOKU
|
|
44 */
|
|
45
|
|
46 #include <stdio.h>
|
|
47 #include "commonhd.h"
|
|
48 #include "sdefine.h"
|
|
49 #ifdef XJUTIL
|
|
50 #include "xjutil.h"
|
|
51 #include "sxheader.h"
|
|
52 #include "xext.h"
|
|
53 #else /* XJUTIL */
|
|
54 #include "xim.h"
|
|
55 #include "sheader.h"
|
|
56 #include "ext.h"
|
|
57 #endif /* XJUTIL */
|
|
58
|
|
59 #define MAX_TEN_LENGTH 94
|
|
60
|
|
61 #define RING(ret) {ring_bell(); return(ret);}
|
|
62 #ifdef XJUTIL
|
|
63 #define MES0_NUM 117
|
|
64 #define MES1_NUM 115
|
|
65 #define MES2_NUM 116
|
|
66 #define MES3_NUM 8
|
|
67 #define SEL_RET (xjutil->sel_ret)
|
|
68 #else /* XJUTIL */
|
|
69 #define MES0_NUM 26
|
|
70 #define MES1_NUM 24
|
|
71 #define MES2_NUM 25
|
|
72 #define MES3_NUM 19
|
|
73 #define SEL_RET (xim->sel_ret)
|
|
74 #endif /* XJUTIL */
|
|
75
|
|
76 static int
|
|
77 get_ichiran (ku, in, multi, cs, lang)
|
|
78 int ku;
|
|
79 int in;
|
|
80 int multi, cs;
|
|
81 char *lang;
|
|
82 {
|
|
83 static char buf[1024];
|
|
84 static char *buf_ptr[MAX_TEN_LENGTH];
|
|
85 static int i;
|
|
86 static char *c;
|
|
87 static char kuten_title[32];
|
|
88 static int kuten_ichi_step = 0;
|
|
89 static w_char code[2];
|
|
90
|
|
91 if (kuten_ichi_step == 0)
|
|
92 {
|
|
93 code[1] = (w_char) 0;
|
|
94 for (i = 0, c = buf; i < MAX_TEN_LENGTH; i++)
|
|
95 {
|
|
96 code[0] = (((ku + 32) << 8) | ((i + 1) + 32)) & 0x7f7f;
|
|
97 code[0] |= get_cs_mask (cs);
|
|
98 buf_ptr[i] = c;
|
|
99 c += sStrcpy (c, code) + 1;
|
|
100 }
|
|
101 if (multi > 1)
|
|
102 {
|
|
103 sprintf (kuten_title, "%s %d.%2d %s", msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang), cs, ku, msg_get (cd, MES0_NUM, default_message[MES0_NUM], lang));
|
|
104 }
|
|
105 else
|
|
106 {
|
|
107 sprintf (kuten_title, "%s %2d %s", msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang), ku, msg_get (cd, MES0_NUM, default_message[MES0_NUM], lang));
|
|
108 }
|
|
109 kuten_ichi_step++;
|
|
110 }
|
|
111 if ((i = xw_select_one_element (buf_ptr, MAX_TEN_LENGTH, 0, kuten_title, KUTEN_IN, main_table[4], in)) == -1)
|
|
112 {
|
|
113 kuten_ichi_step = 0;
|
|
114 return (-1);
|
|
115 }
|
|
116 else if (i == BUFFER_IN_CONT)
|
|
117 {
|
|
118 return (BUFFER_IN_CONT);
|
|
119 }
|
|
120 kuten_ichi_step = 0;
|
|
121 code[0] = ((((ku + 32) << 8) | ((i + 1) + 32)) & 0x7f7f) | get_cs_mask (cs);
|
|
122 return ((int) code[0]);
|
|
123 }
|
|
124
|
|
125 int
|
|
126 in_kuten (in) /* returns code for a moji */
|
|
127 int in;
|
|
128 {
|
|
129 static char buffer[7];
|
|
130 static int code;
|
|
131 static int c_p = 0;
|
|
132 static int ret1, ret2;
|
|
133 static int mode = -1, mode1 = -1;
|
|
134 #ifndef XJUTIL
|
|
135 static WnnClientRec *c_c_sv = 0;
|
|
136 #endif /* !XJUTIL */
|
|
137 static int kuten_step = 0;
|
|
138 static char *lang;
|
|
139 static int cs = 0, valid_cs[3], multi, os = 0;
|
|
140 register int i, k;
|
|
141 register char t_c, *start_p;
|
|
142 unsigned char c;
|
|
143
|
|
144 #ifndef XJUTIL
|
|
145 if (in == -99)
|
|
146 {
|
|
147 end_ichiran ();
|
|
148 code = -1;
|
|
149 goto LAST;
|
|
150 }
|
|
151 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
152 {
|
|
153 RING (-1);
|
|
154 }
|
|
155 #endif /* !XJUTIL */
|
|
156 if (kuten_step == 0)
|
|
157 {
|
|
158 #ifdef XJUTIL
|
|
159 set_cswidth (xjutil->cswidth_id);
|
|
160 lang = xjutil->lang;
|
|
161 #else /* XJUTIL */
|
|
162 set_cswidth (cur_lang->cswidth_id);
|
|
163 lang = cur_lang->lang;
|
|
164 c_c_sv = c_c;
|
|
165 #endif /* !XJUTIL */
|
|
166 for (multi = 0, i = 0; i < 3; i++)
|
|
167 {
|
|
168 multi += valid_cs[i] = (get_cswidth (i) == 2) ? 1 : 0;
|
|
169 if (valid_cs[i])
|
|
170 cs = i;
|
|
171 }
|
|
172 if (multi <= 0)
|
|
173 {
|
|
174 RING (-1);
|
|
175 }
|
|
176 if (multi > 1)
|
|
177 {
|
|
178 os = 2;
|
|
179 }
|
|
180 else
|
|
181 {
|
|
182 os = 0;
|
|
183 }
|
|
184 for (k = 0; k < os + 5; buffer[k++] = ' ');
|
|
185 buffer[os + 5] = '\0';
|
|
186 c_p = 0;
|
|
187 mode = mode1 = -1;
|
|
188 kuten_step++;
|
|
189 }
|
|
190
|
|
191 start:
|
|
192 if (kuten_step == 1)
|
|
193 {
|
|
194 if (init_ichiran ((unsigned char **) NULL, 0, -1,
|
|
195 (unsigned char *) msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang),
|
|
196 (unsigned char *) msg_get (cd, MES2_NUM, default_message[MES2_NUM], lang),
|
|
197 (unsigned char *) msg_get (cd, MES3_NUM, default_message[MES3_NUM], lang), NULL, os + 5, NYUURYOKU) == -1)
|
|
198 {
|
|
199 #ifndef XJUTIL
|
|
200 c_c_sv = 0;
|
|
201 #endif /* !XJUTIL */
|
|
202 RING (-1);
|
|
203 }
|
|
204 draw_nyuu_w ((unsigned char *) buffer, 1);
|
|
205 kuten_step++;
|
|
206 return (BUFFER_IN_CONT);
|
|
207 }
|
|
208 if (kuten_step == 2)
|
|
209 {
|
|
210 c = (unsigned char) (in & 0xff);
|
|
211 #ifdef XJUTIL
|
|
212 if (!cur_root->ichi->map)
|
|
213 return (BUFFER_IN_CONT);
|
|
214 #else /* XJUTIL */
|
|
215 if (!xim->cur_j_c_root->ichi->map)
|
|
216 return (BUFFER_IN_CONT);
|
|
217 #endif /* XJUTIL */
|
|
218 if (SEL_RET == -2)
|
|
219 {
|
|
220 end_ichiran ();
|
|
221 SEL_RET = -1;
|
|
222 code = -1;
|
|
223 goto LAST;
|
|
224 }
|
|
225 if ((c == ESC) || (t_quit == main_table[5][c]))
|
|
226 {
|
|
227 end_ichiran ();
|
|
228 code = -1;
|
|
229 goto LAST;
|
|
230 #ifndef XJUTIL
|
|
231 }
|
|
232 else if (henkan_off == main_table[5][c])
|
|
233 {
|
|
234 RING (BUFFER_IN_CONT);
|
|
235 #endif /* !XJUTIL */
|
|
236 }
|
|
237 if ((c <= '9' && c >= '0') || c == '.')
|
|
238 {
|
|
239 if (os > 0)
|
|
240 {
|
|
241 if (mode >= 0)
|
|
242 {
|
|
243 if (mode1 >= 0)
|
|
244 {
|
|
245 if ((c_p - mode1) <= 2 && c != '.')
|
|
246 {
|
|
247 buffer[c_p++] = (char) c;
|
|
248 goto RET;
|
|
249 }
|
|
250 }
|
|
251 else
|
|
252 {
|
|
253 t_c = buffer[0];
|
|
254 if ((c_p - mode) <= 4 && c != '.')
|
|
255 {
|
|
256 buffer[c_p++] = c;
|
|
257 goto RET;
|
|
258 }
|
|
259 else if (mode == 1 && t_c >= '0' && t_c <= '2' && valid_cs[t_c - '0'] && (c_p - mode) <= 3 && (c_p - mode) >= 2 && c == '.')
|
|
260 {
|
|
261 mode1 = c_p;
|
|
262 buffer[c_p++] = c;
|
|
263 goto RET;
|
|
264 }
|
|
265 }
|
|
266 RING (BUFFER_IN_CONT);
|
|
267 }
|
|
268 else
|
|
269 {
|
|
270 if (c == '.')
|
|
271 {
|
|
272 if (c_p > 0 && c_p <= 2)
|
|
273 {
|
|
274 mode = c_p;
|
|
275 buffer[c_p++] = c;
|
|
276 goto RET;
|
|
277 }
|
|
278 }
|
|
279 else
|
|
280 {
|
|
281 if (c_p < 4)
|
|
282 {
|
|
283 buffer[c_p++] = c;
|
|
284 goto RET;
|
|
285 }
|
|
286 }
|
|
287 RING (BUFFER_IN_CONT);
|
|
288 }
|
|
289 }
|
|
290 else
|
|
291 {
|
|
292 if (c == '.')
|
|
293 {
|
|
294 if ((mode == -1) && 0 < c_p && c_p <= 2)
|
|
295 {
|
|
296 mode = c_p;
|
|
297 buffer[c_p++] = c;
|
|
298 goto RET;
|
|
299 }
|
|
300 }
|
|
301 else
|
|
302 {
|
|
303 if ((mode >= 0 ? (c_p - mode) <= 2 : c_p < 4))
|
|
304 {
|
|
305 buffer[c_p++] = c;
|
|
306 goto RET;
|
|
307 }
|
|
308 }
|
|
309 RING (BUFFER_IN_CONT);
|
|
310 }
|
|
311 }
|
|
312 else if (c == rubout_code && c_p)
|
|
313 {
|
|
314 if (os > 0)
|
|
315 {
|
|
316 if (mode1 >= 0 && buffer[c_p - 1] == '.')
|
|
317 {
|
|
318 mode1 = -1;
|
|
319 }
|
|
320 else if (mode >= 0 && buffer[c_p - 1] == '.')
|
|
321 {
|
|
322 mode = -1;
|
|
323 }
|
|
324 }
|
|
325 else
|
|
326 {
|
|
327 if (buffer[c_p - 1] == '.')
|
|
328 mode = -1;
|
|
329 }
|
|
330 buffer[--c_p] = ' ';
|
|
331 }
|
|
332 else if (c == rubout_code && c_p == 0)
|
|
333 {
|
|
334 end_ichiran ();
|
|
335 code = -1;
|
|
336 goto LAST;
|
|
337 }
|
|
338 else if ((c == NEWLINE) || (c == CR))
|
|
339 {
|
|
340 if (os > 0)
|
|
341 {
|
|
342 if ((mode1 >= 0 && (buffer[c_p - 1] != '.')) || (mode1 == -1 && mode >= 0 && (c_p - mode) >= 2) || (mode == -1 && c_p >= 3))
|
|
343 {
|
|
344 if (mode1 >= 0 || (mode == 1 && (c_p - mode) >= 4))
|
|
345 {
|
|
346 cs = buffer[0] - '0';
|
|
347 if (valid_cs[cs] == 0)
|
|
348 RING (BUFFER_IN_CONT);
|
|
349 start_p = &buffer[os];
|
|
350 }
|
|
351 else
|
|
352 {
|
|
353 cs = 0;
|
|
354 start_p = buffer;
|
|
355 }
|
|
356 if ((!(sscanf (start_p, "%d.%d", &ret1, &ret2) == 2) &&
|
|
357 !(((mode == -1) ? (c_p == 4) : (c_p == os + 4)) &&
|
|
358 sscanf (start_p, "%2d%2d", &ret1, &ret2) == 2) &&
|
|
359 !(((mode == -1) ? (c_p == 3) : (c_p == os + 3)) && sscanf (start_p, "%1d%2d", &ret1, &ret2) == 2)) || ret1 <= 0 || ret1 > 94 || ret2 <= 0 || ret2 > 94)
|
|
360 {
|
|
361 RING (BUFFER_IN_CONT);
|
|
362 }
|
|
363 code = (((ret1 + 32) << 8) | (ret2 + 32)) & 0x7f7f;
|
|
364 code |= get_cs_mask (cs);
|
|
365 end_ichiran ();
|
|
366 goto LAST;
|
|
367 }
|
|
368 else
|
|
369 {
|
|
370 if (mode1 >= 0 && (buffer[c_p - 1] == '.'))
|
|
371 {
|
|
372 if (sscanf (&buffer[os], "%d.", &ret1) != 1 || (ret1 <= 0 || ret1 > 94))
|
|
373 {
|
|
374 RING (BUFFER_IN_CONT);
|
|
375 }
|
|
376 }
|
|
377 else if (mode == -1 && (c_p == 1 || c_p == 2))
|
|
378 {
|
|
379 if (sscanf (&buffer[0], "%d", &ret1) != 1 || (ret1 <= 0 || ret1 > 94))
|
|
380 {
|
|
381 RING (BUFFER_IN_CONT);
|
|
382 }
|
|
383 }
|
|
384 else
|
|
385 {
|
|
386 RING (BUFFER_IN_CONT);
|
|
387 }
|
|
388 end_ichiran ();
|
|
389 kuten_step++;
|
|
390 goto NEXT;
|
|
391 }
|
|
392 RING (BUFFER_IN_CONT);
|
|
393 }
|
|
394 else
|
|
395 {
|
|
396 if (c_p >= 3 && (buffer[c_p - 1] != '.'))
|
|
397 {
|
|
398 start_p = buffer;
|
|
399 if ((!(sscanf (start_p, "%d.%d", &ret1, &ret2) == 2) &&
|
|
400 !((c_p == 4) &&
|
|
401 sscanf (start_p, "%2d%2d", &ret1, &ret2) == 2) && !((c_p == 3) && sscanf (start_p, "%1d%2d", &ret1, &ret2) == 2)) || ret1 <= 0 || ret1 > 94 || ret2 <= 0 || ret2 > 94)
|
|
402 {
|
|
403 RING (BUFFER_IN_CONT);
|
|
404 }
|
|
405 code = (((ret1 + 32) << 8) | (ret2 + 32)) & 0x7f7f;
|
|
406 code |= get_cs_mask (cs);
|
|
407 end_ichiran ();
|
|
408 goto LAST;
|
|
409 }
|
|
410 else if (c_p <= 2 && mode == -1)
|
|
411 {
|
|
412 if (sscanf (buffer, "%d", &ret1) != 1 || (ret1 <= 0 || ret1 > 94))
|
|
413 {
|
|
414 RING (BUFFER_IN_CONT);
|
|
415 }
|
|
416 end_ichiran ();
|
|
417 kuten_step++;
|
|
418 goto NEXT;
|
|
419 }
|
|
420 RING (BUFFER_IN_CONT);
|
|
421 }
|
|
422 }
|
|
423 RET:
|
|
424 draw_nyuu_w ((unsigned char *) buffer, 1);
|
|
425 return (BUFFER_IN_CONT);
|
|
426 }
|
|
427 NEXT:
|
|
428 if (kuten_step == 3)
|
|
429 {
|
|
430 if (os > 0)
|
|
431 {
|
|
432 if (mode1 >= 0)
|
|
433 {
|
|
434 cs = buffer[0] - '0';
|
|
435 }
|
|
436 else
|
|
437 {
|
|
438 cs = 0;
|
|
439 }
|
|
440 }
|
|
441 if ((code = get_ichiran (ret1, in, multi, cs, lang)) == -1)
|
|
442 {
|
|
443 kuten_step = 0;
|
|
444 goto start;
|
|
445 }
|
|
446 else if (code == BUFFER_IN_CONT)
|
|
447 {
|
|
448 return (BUFFER_IN_CONT);
|
|
449 }
|
|
450 }
|
|
451 LAST:
|
|
452 #ifndef XJUTIL
|
|
453 c_c_sv = 0;
|
|
454 #endif /* !XJUTIL */
|
|
455 kuten_step = 0;
|
|
456 return (code);
|
|
457 }
|
|
458
|
|
459 #undef RING
|
|
460
|
|
461 /*
|
|
462 Local Variables:
|
|
463 eval: (setq kanji-flag t)
|
|
464 eval: (setq kanji-fileio-code 0)
|
|
465 eval: (mode-line-kanji-code-update)
|
|
466 End:
|
|
467 */
|