0
|
1 /*
|
|
2 * $Id: jis_in.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 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 JIS 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
|
|
60 #define FROM_JIS 0x21
|
|
61 #define TO_JIS 0x7E
|
|
62 #define RING(ret) {ring_bell(); return(ret);}
|
|
63 #ifdef XJUTIL
|
|
64 #define MES1_NUM 113
|
|
65 #define MES2_NUM 114
|
|
66 #define MES3_NUM 8
|
|
67 #define SEL_RET (xjutil->sel_ret)
|
|
68 #else /* XJUTIL */
|
|
69 #define MES1_NUM 17
|
|
70 #define MES2_NUM 18
|
|
71 #define MES3_NUM 19
|
|
72 #define SEL_RET (xim->sel_ret)
|
|
73 #endif /* XJUTIL */
|
|
74
|
|
75 static int
|
|
76 hextodec (s)
|
|
77 char s;
|
|
78 {
|
|
79 register int c = (int) s;
|
|
80
|
|
81 if (c >= '0' && c <= '9')
|
|
82 {
|
|
83 return (c - '0');
|
|
84 }
|
|
85 else if (c >= 'A' && c <= 'F')
|
|
86 {
|
|
87 return (c - 'A' + 10);
|
|
88 }
|
|
89 else if (c >= 'a' && c <= 'f')
|
|
90 {
|
|
91 return (c - 'a' + 10);
|
|
92 }
|
|
93 else
|
|
94 return (-1);
|
|
95 }
|
|
96
|
|
97 static int
|
|
98 get_jis_ichiran (st, num, in, multi, cs, lang)
|
|
99 char *st;
|
|
100 int num;
|
|
101 int in;
|
|
102 int multi, cs;
|
|
103 char *lang;
|
|
104 {
|
|
105 static int from;
|
|
106 static int i;
|
|
107 static char *c;
|
|
108 static int maxh;
|
|
109 static w_char code[2];
|
|
110 static char buf[1024];
|
|
111 static char *buf_ptr[96];
|
|
112 static char jis_title[32];
|
|
113 static int jis_ichi_step = 0;
|
|
114
|
|
115 if (jis_ichi_step == 0)
|
|
116 {
|
|
117 if (num == 2)
|
|
118 {
|
|
119 from = hextodec (st[0]) << (8 + 4) | hextodec (st[1]) << 8 | 0x21;
|
|
120 from = (from & 0x7f7f) | get_cs_mask (cs);
|
|
121 maxh = 94;
|
|
122 }
|
|
123 else
|
|
124 {
|
|
125 from = hextodec (st[0]) << (8 + 4) | hextodec (st[1]) << 8 | hextodec (st[2]) << 4;
|
|
126 from = (from & 0x7f7f) | get_cs_mask (cs);
|
|
127 maxh = 16;
|
|
128 if ((from & 0xf0) == 0xf0)
|
|
129 {
|
|
130 maxh--;
|
|
131 }
|
|
132 else if ((from & 0xf0) == 0xa0)
|
|
133 {
|
|
134 maxh--;
|
|
135 from++;
|
|
136 }
|
|
137 }
|
|
138
|
|
139 code[1] = (w_char) 0;
|
|
140 for (i = 0, c = buf; i < maxh; i++)
|
|
141 {
|
|
142 code[0] = (w_char) (from + i);
|
|
143 buf_ptr[i] = c;
|
|
144 c += sStrcpy (c, code) + 1;
|
|
145 }
|
|
146 if (multi > 1)
|
|
147 {
|
|
148 sprintf (jis_title, "%s %d.0x%s", msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang), cs, st);
|
|
149 }
|
|
150 else
|
|
151 {
|
|
152 sprintf (jis_title, "%s 0x%s", msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang), st);
|
|
153 }
|
|
154 jis_ichi_step++;
|
|
155 }
|
|
156 if ((i = xw_select_one_element (buf_ptr, maxh, 0, jis_title, JIS_IN, main_table[4], in)) == -1)
|
|
157 {
|
|
158 jis_ichi_step = 0;
|
|
159 return (-1);
|
|
160 }
|
|
161 else if (i == BUFFER_IN_CONT)
|
|
162 {
|
|
163 return (BUFFER_IN_CONT);
|
|
164 }
|
|
165 jis_ichi_step = 0;
|
|
166 return (from + i);
|
|
167 }
|
|
168
|
|
169 int
|
|
170 in_jis (in) /* returns code for a moji */
|
|
171 int in;
|
|
172 {
|
|
173 static char buffer[7];
|
|
174 static int c_p = 0;
|
|
175 #ifndef XJUTIL
|
|
176 static WnnClientRec *c_c_sv = 0;
|
|
177 #endif /* !XJUTIL */
|
|
178 static int jis_step = 0;
|
|
179 static char *lang;
|
|
180 static int cs = 0, valid_cs[3], multi, os = 0, dot = 0;
|
|
181 int i, k;
|
|
182 register char t_c, *start_p;
|
|
183 unsigned char c;
|
|
184 register int code;
|
|
185
|
|
186 #ifndef XJUTIL
|
|
187 if (in == -99)
|
|
188 {
|
|
189 end_ichiran ();
|
|
190 code = -1;
|
|
191 goto LAST;
|
|
192 }
|
|
193 if (c_c_sv != 0 && c_c != c_c_sv)
|
|
194 {
|
|
195 RING (-1);
|
|
196 }
|
|
197 #endif /* !XJUTIL */
|
|
198 if (jis_step == 0)
|
|
199 {
|
|
200 #ifdef XJUTIL
|
|
201 set_cswidth (xjutil->cswidth_id);
|
|
202 lang = xjutil->lang;
|
|
203 #else /* XJUTIL */
|
|
204 set_cswidth (cur_lang->cswidth_id);
|
|
205 lang = cur_lang->lang;
|
|
206 c_c_sv = c_c;
|
|
207 #endif /* !XJUTIL */
|
|
208 cs = 0;
|
|
209 for (multi = 0, i = 0; i < 3; i++)
|
|
210 {
|
|
211 multi += valid_cs[i] = (get_cswidth (i) == 2) ? 1 : 0;
|
|
212 if (valid_cs[i])
|
|
213 cs = i;
|
|
214 }
|
|
215 if (multi <= 0)
|
|
216 {
|
|
217 RING (-1);
|
|
218 }
|
|
219 if (multi > 1)
|
|
220 {
|
|
221 os = 2;
|
|
222 }
|
|
223 else
|
|
224 {
|
|
225 os = 0;
|
|
226 }
|
|
227 for (k = 0; k < os + 5; buffer[k++] = ' ');
|
|
228 buffer[os + 5] = '\0';
|
|
229 dot = 0;
|
|
230 c_p = 0;
|
|
231 jis_step++;
|
|
232 }
|
|
233 start:
|
|
234 if (jis_step == 1)
|
|
235 {
|
|
236 if (init_ichiran ((unsigned char **) NULL, 0, -1,
|
|
237 (unsigned char *) msg_get (cd, MES1_NUM, default_message[MES1_NUM], lang),
|
|
238 (unsigned char *) msg_get (cd, MES2_NUM, default_message[MES2_NUM], lang),
|
|
239 (unsigned char *) msg_get (cd, MES3_NUM, default_message[MES3_NUM], lang), NULL, os + 5, NYUURYOKU) == -1)
|
|
240 {
|
|
241 #ifndef XJUTIL
|
|
242 c_c_sv = 0;
|
|
243 #endif /* !XJUTIL */
|
|
244 RING (-1);
|
|
245 }
|
|
246 draw_nyuu_w ((unsigned char *) buffer, 1);
|
|
247 jis_step++;
|
|
248 return (BUFFER_IN_CONT);
|
|
249 }
|
|
250 if (jis_step == 2)
|
|
251 {
|
|
252 c = (unsigned char) (in & 0xff);
|
|
253 #ifdef XJUTIL
|
|
254 if (!cur_root->ichi->map)
|
|
255 return (BUFFER_IN_CONT);
|
|
256 #else /* XJUTIL */
|
|
257 if (!xim->cur_j_c_root->ichi->map)
|
|
258 return (BUFFER_IN_CONT);
|
|
259 #endif /* XJUTIL */
|
|
260 if (SEL_RET == -2)
|
|
261 {
|
|
262 end_ichiran ();
|
|
263 SEL_RET = -1;
|
|
264 code = -1;
|
|
265 goto LAST;
|
|
266 }
|
|
267 if ((c == ESC) || (t_quit == main_table[5][c]))
|
|
268 {
|
|
269 end_ichiran ();
|
|
270 code = -1;
|
|
271 goto LAST;
|
|
272 #ifndef XJUTIL
|
|
273 }
|
|
274 else if (henkan_off == main_table[5][c])
|
|
275 {
|
|
276 RING (BUFFER_IN_CONT);
|
|
277 #endif /* !XJUTIL */
|
|
278 }
|
|
279 else if (c_p < os + 4 && ((c <= '9' && c >= '0') || (c <= 'F' && c >= 'A') || (c <= 'f' && c >= 'a') || (os > 0 && c_p == 1 && c == '.')))
|
|
280 {
|
|
281 if (c_p > 0)
|
|
282 t_c = buffer[c_p - 1];
|
|
283 if (os > 0 && c_p == 0)
|
|
284 {
|
|
285 buffer[c_p++] = c;
|
|
286 goto RET;
|
|
287 }
|
|
288 else if (os > 0 && c_p == 1)
|
|
289 {
|
|
290 if (c == '.')
|
|
291 {
|
|
292 if (t_c < '0' || t_c > '2' || valid_cs[t_c - '0'] == 0)
|
|
293 {
|
|
294 RING (BUFFER_IN_CONT);
|
|
295 }
|
|
296 buffer[c_p++] = c;
|
|
297 dot = 1;
|
|
298 goto RET;
|
|
299 }
|
|
300 else if (t_c == '0' || t_c == '1')
|
|
301 {
|
|
302 RING (BUFFER_IN_CONT);
|
|
303 }
|
|
304 else if (!((t_c == '2' || t_c == 'A' || t_c == 'a') && c == '0' || (t_c == '7' || t_c == 'F' || t_c == 'f') && (c == 'F' || c == 'f')))
|
|
305 {
|
|
306 buffer[c_p++] = c;
|
|
307 goto RET;
|
|
308 }
|
|
309 RING (BUFFER_IN_CONT);
|
|
310 }
|
|
311 else if ((c_p == os || c_p == os + 2) ? (c <= 'F' && c >= 'A') || /* For EUC */
|
|
312 (c <= 'f' && c >= 'a') || /* For EUC */
|
|
313 (c <= '7' && c >= '2') : !((t_c == '2' || t_c == 'A' || t_c == 'a') && c == '0' || (t_c == '7' || t_c == 'F' || t_c == 'f') && (c == 'F' || c == 'f')))
|
|
314 {
|
|
315 buffer[c_p++] = c;
|
|
316 goto RET;
|
|
317 }
|
|
318 else
|
|
319 {
|
|
320 RING (BUFFER_IN_CONT);
|
|
321 }
|
|
322 }
|
|
323 else if (c == rubout_code && c_p)
|
|
324 {
|
|
325 buffer[--c_p] = ' ';
|
|
326 if (c_p <= 1)
|
|
327 dot = 0;
|
|
328 goto RET;
|
|
329 }
|
|
330 else if (c == rubout_code && c_p == 0)
|
|
331 {
|
|
332 end_ichiran ();
|
|
333 code = -1;
|
|
334 goto LAST;
|
|
335 }
|
|
336 else if (c == NEWLINE || c == CR)
|
|
337 {
|
|
338 start_p = &buffer[(dot) ? os : 0];
|
|
339 if ((os > 0) ? (c_p < os || (dot && c_p < os + 2)) : (c_p < os + 2))
|
|
340 {
|
|
341 goto RET;
|
|
342 }
|
|
343 else if (c_p == os + 4 || (os > 0 && !dot && c_p == 4))
|
|
344 {
|
|
345 if (os > 0)
|
|
346 {
|
|
347 if (dot)
|
|
348 {
|
|
349 cs = hextodec (buffer[0]);
|
|
350 }
|
|
351 else
|
|
352 {
|
|
353 cs = 0;
|
|
354 }
|
|
355 }
|
|
356 code = 0;
|
|
357 for (k = 0; k < 4; k++)
|
|
358 {
|
|
359 code = code * 16 + hextodec (start_p[k]);
|
|
360 }
|
|
361 code &= 0x7f7f;
|
|
362 code |= get_cs_mask (cs);
|
|
363 end_ichiran ();
|
|
364 goto LAST;
|
|
365 }
|
|
366 end_ichiran ();
|
|
367 jis_step++;
|
|
368 goto NEXT;
|
|
369 }
|
|
370 else
|
|
371 {
|
|
372 RING (BUFFER_IN_CONT);
|
|
373 }
|
|
374 RET:
|
|
375 draw_nyuu_w ((unsigned char *) buffer, 1);
|
|
376 return (BUFFER_IN_CONT);
|
|
377 }
|
|
378 NEXT:
|
|
379 if (jis_step == 3)
|
|
380 {
|
|
381 if (os > 0)
|
|
382 {
|
|
383 if (dot)
|
|
384 {
|
|
385 cs = hextodec (buffer[0]);
|
|
386 }
|
|
387 else
|
|
388 {
|
|
389 cs = 0;
|
|
390 }
|
|
391 }
|
|
392 if ((code = get_jis_ichiran (start_p, c_p - (dot ? os : 0), in, multi, cs, lang)) == -1)
|
|
393 {
|
|
394 jis_step = 0;
|
|
395 goto start;
|
|
396 }
|
|
397 else if (code == BUFFER_IN_CONT)
|
|
398 {
|
|
399 return (BUFFER_IN_CONT);
|
|
400 }
|
|
401 }
|
|
402 LAST:
|
|
403 #ifndef XJUTIL
|
|
404 c_c_sv = 0;
|
|
405 #endif /* !XJUTIL */
|
|
406 jis_step = 0;
|
|
407 return (code);
|
|
408 }
|
|
409
|
|
410 #undef RING
|
|
411
|
|
412 /*
|
|
413 Local Variables:
|
|
414 eval: (setq kanji-flag t)
|
|
415 eval: (setq kanji-fileio-code 0)
|
|
416 eval: (mode-line-kanji-code-update)
|
|
417 End:
|
|
418 */
|