0
|
1 /*
|
|
2 * $Id: xutoj.c,v 1.7 2002/03/24 01:25:13 hiroo 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, 2002
|
|
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 #ifdef HAVE_CONFIG_H
|
|
33 # include <config.h>
|
|
34 #endif
|
|
35
|
|
36 #define NEED_CR
|
|
37
|
|
38 #if STDC_HEADERS
|
|
39 # include <stdlib.h>
|
|
40 # include <string.h>
|
|
41 #elif HAVE_STRINGS_H
|
|
42 # include <strings.h>
|
|
43 #endif /* STDC_HEADERS */
|
|
44
|
|
45 #include "commonhd.h"
|
|
46 #include "wnn_config.h"
|
|
47 #include "wnn_os.h"
|
|
48
|
|
49 #define ECNS_IS_UCNS 1 /* The trust CNS is CNS11643 based on ISO2022,
|
|
50 but the CNS is binded on EUC */
|
|
51
|
|
52 #define NON_LIMIT 0x7FFFFFFF
|
|
53
|
|
54 #define G0 0
|
|
55 #define G1 1
|
|
56 #define G2 2
|
|
57 #define G3 3
|
|
58 #define SS 4
|
|
59 #define GL 1
|
|
60 #define GR 2
|
|
61 #define LS0 0x0f
|
|
62 #define LS1 0x0e
|
|
63 #define LS1R 0x7e
|
|
64 #define LS2 0x6e
|
|
65 #define LS2R 0x7d
|
|
66 #define LS3 0x6f
|
|
67 #define LS3R 0x7c
|
|
68 #define SS2 0x8e
|
|
69 #define SS3 0x8f
|
|
70
|
|
71
|
|
72 #define CS_MASK 0x8080
|
|
73 #define CS0_MASK 0x0000
|
|
74 #define CS1_MASK 0x8080
|
|
75 #define CS2_MASK 0x0080
|
|
76 #define CS3_MASK 0x8000
|
|
77
|
|
78 #define CS1 0
|
|
79 #define CS2 1
|
|
80 #define CS3 2
|
|
81
|
|
82 #define UJIS_CSWIDTH "2,1,2"
|
|
83 #define UGB_CSWIDTH "2,1,2"
|
|
84 #define UKSC_CSWIDTH "2,1,2"
|
|
85
|
|
86 typedef struct _CSWidthTable
|
|
87 {
|
|
88 int cs1, cs2, cs3;
|
|
89 }
|
|
90 CSWidthTable;
|
|
91
|
|
92 typedef struct _cswidth_name_struct
|
|
93 {
|
|
94 char *lang;
|
|
95 char *name;
|
|
96 char *def_name;
|
|
97 }
|
|
98 cswidth_name_struct;
|
|
99
|
|
100 typedef struct _DesignateTable
|
|
101 {
|
|
102 unsigned char *code;
|
|
103 unsigned int mask;
|
|
104 }
|
|
105 DesignateTable;
|
|
106
|
|
107 static int _etc_cs[3] = { 2, 1, 2 };
|
|
108 static int _etc_cs_len[3] = { 2, 1, 2 };
|
|
109 static int cs_mask[3] = { 0x8080, 0x0080, 0x8000 };
|
|
110
|
|
111 static int default_glr_mode[3] = { 0, G0, G1 };
|
|
112 static int save_glr_mode[2];
|
|
113 static int default_gn_len[4] = { 1, 1, 1, 2 };
|
|
114 static unsigned int default_gn_mask[4] = { 0x00, 0x80, 0x80, 0x8000 };
|
|
115 static DesignateTable default_designate[4] = {
|
|
116 {(unsigned char *) "(B", 0x0},
|
|
117 {(unsigned char *) NULL, 0x0}
|
|
118 };
|
|
119
|
|
120 static int *glr_mode = default_glr_mode;
|
|
121 static int *gn_len = default_gn_len;
|
|
122 static unsigned int *gn_mask = default_gn_mask;
|
|
123
|
|
124 static unsigned char save_seq[6] = { '\0' };
|
|
125 static int save_seq_len = 0;
|
|
126 static int pending_esc = 0;
|
|
127 static unsigned char pending = '\0';
|
|
128 static w_char pending_mask = (w_char) 0;
|
|
129
|
|
130 static DesignateTable *designate = default_designate;
|
|
131
|
|
132 #ifdef JAPANESE
|
|
133 static DesignateTable JIS_designate[] = {
|
|
134 {(unsigned char *) "(B", 0x0},
|
|
135 {(unsigned char *) "(J", 0x0},
|
|
136 {(unsigned char *) "(I", 0x80},
|
|
137 {(unsigned char *) "$B", 0x8080},
|
|
138 {(unsigned char *) "$(B", 0x8080},
|
|
139 {(unsigned char *) ")I", 0x80},
|
|
140 {(unsigned char *) "$)B", 0x8080},
|
|
141 {(unsigned char *) "$)D", 0x8000},
|
|
142 {(unsigned char *) "$(D", 0x8000},
|
|
143 {(unsigned char *) NULL, 0x0}
|
|
144 };
|
|
145 #endif /* JAPANESE */
|
|
146
|
|
147 #ifdef CHINESE
|
|
148 #ifndef ECNS_IS_UCNS
|
|
149 static DesignateTable CNS_designate[] = {
|
|
150 {(unsigned char *) "(B", 0x0},
|
|
151 {(unsigned char *) "$)0", 0x8080},
|
|
152 {(unsigned char *) "$*1", 0x8000},
|
|
153 {NULL, 0x0}
|
|
154 };
|
|
155 #endif /* ECNS_IS_UCNS */
|
|
156 #endif /* CHINESE */
|
|
157
|
|
158 #ifdef KOREAN
|
|
159 static DesignateTable KSC_designate[] = {
|
|
160 {(unsigned char *) "(B", 0x0},
|
|
161 {(unsigned char *) "$(C", 0x8080},
|
|
162 {(unsigned char *) "$)C", 0x8080},
|
|
163 {(unsigned char *) NULL, 0x0}
|
|
164 };
|
|
165 #endif /* KOREAN */
|
|
166
|
|
167 #if defined(JAPANESE) || defined(CHINESE) || defined(KOREAN)
|
|
168 static w_char tmp_w_buf[1000];
|
|
169 #endif
|
|
170
|
|
171 static void
|
|
172 set_gn (dg)
|
|
173 DesignateTable *dg;
|
|
174 {
|
|
175 register char *p = (char *) dg->code;
|
|
176 register int len = 1, gn = 0;
|
|
177
|
|
178 if (!strcmp (p, "$B"))
|
|
179 { /* JIS */
|
|
180 gn_len[0] = 2;
|
|
181 gn_mask[0] = dg->mask;
|
|
182 return;
|
|
183 }
|
|
184 if (*p == '$')
|
|
185 {
|
|
186 len = 2;
|
|
187 p++;
|
|
188 }
|
|
189 if (*p >= '(' && *p <= '+')
|
|
190 gn = *p - '(';
|
|
191 else if (*p >= '-' && *p <= '/')
|
|
192 gn = *p - '+';
|
|
193 else
|
|
194 return;
|
|
195 gn_len[gn] = len;
|
|
196 gn_mask[gn] = dg->mask;
|
|
197 }
|
|
198
|
|
199 static int
|
|
200 check_designate (ec, eend, ret_buf)
|
|
201 unsigned char *ec, *eend, **ret_buf;
|
|
202 {
|
|
203 register unsigned char *c = ec;
|
|
204 register int i, j, ok = 0;
|
|
205
|
|
206 *ret_buf = NULL;
|
|
207 for (i = save_seq_len; c < eend; c++)
|
|
208 {
|
|
209 ok = 0;
|
|
210 save_seq[i++] = *c;
|
|
211 save_seq[i] = '\0';
|
|
212 for (j = 0; designate[j].code; j++)
|
|
213 {
|
|
214 if (!strncmp ((char *) save_seq, (char *) designate[j].code, i))
|
|
215 {
|
|
216 if (i == strlen ((char *) designate[j].code))
|
|
217 {
|
|
218 set_gn (&designate[j]);
|
|
219 save_seq_len = 0;
|
|
220 return (c - ec);
|
|
221 }
|
|
222 ok = 1;
|
|
223 break;
|
|
224 }
|
|
225 }
|
|
226 if (ok == 0)
|
|
227 {
|
|
228 *ret_buf = save_seq;
|
|
229 save_seq_len = 0;
|
|
230 return (c - ec);
|
|
231 }
|
|
232 }
|
|
233 save_seq_len = i;
|
|
234 return (c - ec - 1);
|
|
235 }
|
|
236
|
|
237 int
|
|
238 flush_designate (buf)
|
|
239 w_char *buf;
|
|
240 {
|
|
241 register w_char *c = buf;
|
|
242 register int i;
|
|
243
|
|
244 if (pending_esc)
|
|
245 {
|
|
246 *c++ = ESC;
|
|
247 pending_esc = 0;
|
|
248 return (1);
|
|
249 }
|
|
250 if (save_seq_len == 0)
|
|
251 return (0);
|
|
252 *c++ = ESC;
|
|
253 for (i = 0; i < save_seq_len; i++)
|
|
254 {
|
|
255 *c++ = save_seq[i];
|
|
256 }
|
|
257 save_seq_len = 0;
|
|
258 return ((char *) c - (char *) buf);
|
|
259 }
|
|
260
|
|
261 int
|
|
262 extc_to_intc (intc, extc, esiz)
|
|
263 w_char *intc;
|
|
264 unsigned char *extc;
|
|
265 int esiz;
|
|
266 {
|
|
267 unsigned char *eend = extc + esiz;
|
|
268 register unsigned char *ec = extc;
|
|
269 register w_char *ic = intc;
|
|
270 register int LorR = 0, i;
|
|
271 w_char tmp;
|
|
272 int ret, len;
|
|
273 unsigned char *ret_buf;
|
|
274 register unsigned char *p;
|
|
275
|
|
276 for (; ec < eend; ec++)
|
|
277 {
|
|
278 if (pending_esc)
|
|
279 {
|
|
280 pending_esc = 0;
|
|
281 goto ESC_SWITCH;
|
|
282 }
|
|
283 if (pending)
|
|
284 {
|
|
285 *ic++ = ((pending << 8 | *ec) & 0x7f7f) | pending_mask;
|
|
286 pending = '\0';
|
|
287 continue;
|
|
288 }
|
|
289 switch (*ec)
|
|
290 {
|
|
291 #ifdef JIS7
|
|
292 case LS0:
|
|
293 glr_mode[GL] = G0;
|
|
294 break;
|
|
295 case LS1:
|
|
296 glr_mode[GL] = G1;
|
|
297 break;
|
|
298 #endif /* JIS7 */
|
|
299 case SS2:
|
|
300 save_glr_mode[GL] = glr_mode[GL];
|
|
301 glr_mode[GL] = (G2 | SS);
|
|
302 break;
|
|
303 case SS3:
|
|
304 save_glr_mode[GL] = glr_mode[GL];
|
|
305 glr_mode[GL] = (G3 | SS);
|
|
306 break;
|
|
307 case ESC:
|
|
308 if (++ec == eend)
|
|
309 {
|
|
310 pending_esc = 1;
|
|
311 break;
|
|
312 }
|
|
313 ESC_SWITCH:
|
|
314 switch (*ec)
|
|
315 {
|
|
316 case LS1R:
|
|
317 glr_mode[GR] = G1;
|
|
318 break;
|
|
319 case LS2:
|
|
320 glr_mode[GL] = G2;
|
|
321 break;
|
|
322 case LS2R:
|
|
323 glr_mode[GR] = G2;
|
|
324 break;
|
|
325 case LS3:
|
|
326 glr_mode[GL] = G3;
|
|
327 break;
|
|
328 case LS3R:
|
|
329 glr_mode[GR] = G3;
|
|
330 break;
|
|
331 default:
|
|
332 ret = check_designate (ec, eend, &ret_buf);
|
|
333 ec += ret;
|
|
334 if (ret_buf)
|
|
335 {
|
|
336 *ic++ = ESC;
|
|
337 for (p = ret_buf; *p; p++)
|
|
338 *ic++ = *p;
|
|
339 }
|
|
340 break;
|
|
341 }
|
|
342 break;
|
|
343 default:
|
|
344 LorR = 0;
|
|
345 if (*ec >= 0x20 && *ec <= 0x7f)
|
|
346 { /* GL */
|
|
347 LorR = GL;
|
|
348 }
|
1
|
349 else if (*ec >= 0xa0)// && *ec <= 0xff)
|
0
|
350 { /* GR */
|
|
351 LorR = GR;
|
|
352 }
|
|
353 if (LorR)
|
|
354 {
|
|
355 len = gn_len[(glr_mode[LorR] & 0x3)];
|
|
356 if ((ec + len) > eend)
|
|
357 {
|
|
358 pending = *ec;
|
|
359 pending_mask = gn_mask[(glr_mode[LorR] & 0x3)];
|
|
360 }
|
|
361 else
|
|
362 {
|
|
363 for (tmp = (w_char) 0, i = 0; i < len; i++)
|
|
364 {
|
|
365 tmp = ((tmp << 8 | *ec++) & 0x7f7f) | gn_mask[(glr_mode[LorR] & 0x3)];
|
|
366 }
|
|
367 if (len)
|
|
368 ec -= 1;
|
|
369 *ic++ = tmp;
|
|
370 if (glr_mode[LorR] & SS)
|
|
371 glr_mode[LorR] = save_glr_mode[LorR];
|
|
372 }
|
|
373 }
|
|
374 else
|
|
375 {
|
|
376 *ic++ = *ec;
|
|
377 }
|
|
378 }
|
|
379 }
|
|
380 return ((char *) ic - (char *) intc);
|
|
381 }
|
|
382
|
|
383 int
|
|
384 through (x, y, z)
|
|
385 char *x, *y;
|
|
386 int z;
|
|
387 {
|
|
388 bcopy (y, x, z);
|
|
389 return z;
|
|
390 }
|
|
391
|
|
392 int
|
|
393 ibit8_to_ebit8 (ebit8, ibit8, ibsiz)
|
|
394 unsigned char *ebit8;
|
|
395 w_char *ibit8;
|
|
396 int ibsiz;
|
|
397 {
|
|
398 register unsigned char *eb = ebit8;
|
|
399 register w_char *ib = ibit8;
|
|
400
|
|
401 for (; ibsiz > 0; ibsiz -= sizeof (w_char))
|
|
402 {
|
|
403 *eb++ = *ib++ & 0xff;
|
|
404 }
|
|
405 return ((char *) eb - (char *) ebit8);
|
|
406 }
|
|
407
|
|
408 /** cswidth functions **/
|
|
409 unsigned int
|
|
410 create_cswidth (s)
|
|
411 char *s;
|
|
412 {
|
|
413 char tmp[2];
|
|
414 int cs = 0, css = 0, i;
|
|
415
|
|
416 if (!s || !*s)
|
|
417 return (0);
|
|
418
|
|
419 tmp[0] = tmp[1] = '\0';
|
|
420 for (i = 2; i >= 0; i--)
|
|
421 {
|
|
422 tmp[0] = *s;
|
|
423 cs = atoi (tmp);
|
|
424 if (cs > 0 && cs < 3)
|
|
425 css = (cs << (i * 8 + 4)) | css;
|
|
426 if (!*++s)
|
|
427 {
|
|
428 if (cs > 0 && cs < 3)
|
|
429 css = (cs << (i * 8)) | css;
|
|
430 break;
|
|
431 }
|
|
432 if (*s == ':')
|
|
433 {
|
|
434 if (!*++s)
|
|
435 {
|
|
436 if (cs > 0 && cs < 3)
|
|
437 css = (cs << (i * 8)) | css;
|
|
438 break;
|
|
439 }
|
|
440 tmp[0] = *s;
|
|
441 cs = atoi (tmp);
|
|
442 s++;
|
|
443 }
|
|
444 if (cs > 0 && cs < 3)
|
|
445 css = (cs << (i * 8)) | css;
|
|
446 if (!*s || *s != ',' || !*++s)
|
|
447 break;
|
|
448 }
|
|
449 return (css);
|
|
450 }
|
|
451
|
|
452 void
|
|
453 set_cswidth (id)
|
|
454 register unsigned int id;
|
|
455 {
|
|
456 _etc_cs[CS1] = (id >> 20) & 0xf;
|
|
457 _etc_cs[CS2] = (id >> 12) & 0xf;
|
|
458 _etc_cs[CS3] = (id >> 4) & 0xf;
|
|
459 _etc_cs_len[CS1] = (id >> 16) & 0xf;
|
|
460 _etc_cs_len[CS2] = (id >> 8) & 0xf;
|
|
461 _etc_cs_len[CS3] = id & 0xf;
|
|
462 return;
|
|
463 }
|
|
464
|
|
465 static cswidth_name_struct cs_width_name[] = {
|
|
466 {WNN_J_LANG, "JCSWIDTH", "2,1,2"},
|
|
467 {WNN_C_LANG, "CCSWIDTH", "2,1,2"},
|
|
468 {WNN_K_LANG, "KCSWIDTH", "2"},
|
|
469 {WNN_T_LANG, "TCSWIDTH", "2,1,2"},
|
|
470 {NULL, NULL}
|
|
471 };
|
|
472
|
|
473 char *
|
|
474 get_cswidth_name (lang)
|
|
475 register char *lang;
|
|
476 {
|
|
477 register cswidth_name_struct *p;
|
|
478 register char *name;
|
|
479 extern char *getenv ();
|
|
480
|
|
481 if (!lang || !*lang)
|
|
482 {
|
|
483 return (getenv ("CSWIDTH"));
|
|
484 }
|
|
485
|
|
486 for (p = cs_width_name; p->lang; p++)
|
|
487 {
|
|
488 if (!strncmp (lang, p->lang, strlen (lang)))
|
|
489 {
|
|
490 if ((name = getenv (p->name)) != NULL)
|
|
491 {
|
|
492 return (name);
|
|
493 }
|
|
494 else if ((name = getenv ("CSWIDTH")) != NULL)
|
|
495 {
|
|
496 return (name);
|
|
497 }
|
|
498 else
|
|
499 {
|
|
500 return (p->def_name);
|
|
501 }
|
|
502 }
|
|
503 }
|
|
504 return (NULL);
|
|
505 }
|
|
506
|
|
507 int
|
|
508 get_cswidth (cs)
|
|
509 int cs;
|
|
510 {
|
|
511 return (_etc_cs[cs]);
|
|
512 }
|
|
513
|
|
514 int
|
|
515 get_cswidth_by_char (c)
|
|
516 register unsigned char c;
|
|
517 {
|
|
518 if (c < SS2 || (c < 0xa0 && c > SS3))
|
|
519 return (1);
|
|
520 if (c == SS2)
|
|
521 return (_etc_cs[CS2] + 1);
|
|
522 if (c == SS3)
|
|
523 return (_etc_cs[CS3] + 1);
|
|
524 return (_etc_cs[CS1]);
|
|
525 }
|
|
526
|
|
527 int
|
|
528 get_cs_mask (cs)
|
|
529 int cs;
|
|
530 {
|
|
531 return (cs_mask[cs]);
|
|
532 }
|
|
533
|
|
534 int
|
|
535 columnlen (eeuc)
|
|
536 unsigned char *eeuc;
|
|
537 {
|
|
538 register int n = 0;
|
|
539 register unsigned char *c, x;
|
|
540 register int cs_id;
|
|
541
|
|
542 for (c = eeuc; *c;)
|
|
543 {
|
|
544 x = *c;
|
|
545 if (x & 0x80)
|
|
546 {
|
|
547 cs_id = ((x == SS2) ? CS2 : ((x == SS3) ? CS3 : CS1));
|
|
548 if (cs_id == CS2 || cs_id == CS3)
|
|
549 c++;
|
|
550 n += _etc_cs_len[cs_id];
|
|
551 c += _etc_cs[cs_id];
|
|
552 }
|
|
553 else
|
|
554 {
|
|
555 n++;
|
|
556 c++;
|
|
557 }
|
|
558 }
|
|
559 return (n);
|
|
560 }
|
|
561
|
|
562 int
|
|
563 columnlen_w (ieuc)
|
|
564 w_char *ieuc;
|
|
565 {
|
|
566 register int n = 0;
|
|
567 register w_char *c, x;
|
|
568 register int cs_id, mask;
|
|
569
|
|
570 for (c = ieuc; *c; c++)
|
|
571 {
|
|
572 x = *c;
|
|
573 mask = x & CS_MASK;
|
|
574 if (mask == CS0_MASK)
|
|
575 {
|
|
576 n++;
|
|
577 }
|
|
578 else
|
|
579 {
|
|
580 cs_id = (mask == cs_mask[CS3]) ? CS3 : ((mask == cs_mask[CS2]) ? CS2 : CS1);
|
|
581 n += _etc_cs_len[cs_id];
|
|
582 }
|
|
583 }
|
|
584 return (n);
|
|
585 }
|
|
586
|
|
587 int
|
|
588 ieuc_to_eeuc (eeuc, ieuc, iesiz)
|
|
589 unsigned char *eeuc;
|
|
590 w_char *ieuc;
|
|
591 int iesiz;
|
|
592 {
|
|
593 register int x;
|
|
594 register w_char *ie;
|
|
595 register unsigned char *ee;
|
|
596 register int cs_id, mask, non_limit = 0;
|
|
597 ie = ieuc;
|
|
598 ee = eeuc;
|
|
599
|
|
600 if (iesiz == -1)
|
|
601 non_limit = 1;
|
|
602 for (; (non_limit ? (*ie) : (iesiz > 0)); iesiz -= sizeof (w_char))
|
|
603 {
|
|
604 x = *ie++;
|
|
605 mask = x & CS_MASK;
|
|
606 if (mask == CS0_MASK || x == 0xffff)
|
|
607 {
|
|
608 *ee++ = x;
|
|
609 }
|
|
610 else
|
|
611 {
|
|
612 cs_id = (mask == cs_mask[CS3]) ? CS3 : ((mask == cs_mask[CS2]) ? CS2 : CS1);
|
|
613 if (_etc_cs[cs_id] <= 0)
|
|
614 continue;
|
|
615 if (cs_id == CS2)
|
|
616 *ee++ = SS2;
|
|
617 else if (cs_id == CS3)
|
|
618 *ee++ = SS3;
|
|
619 if (_etc_cs[cs_id] > 1)
|
|
620 *ee++ = (x >> 8) | 0x80;
|
|
621 if (_etc_cs[cs_id] > 0)
|
|
622 *ee++ = (x & 0xff) | 0x80;
|
|
623 }
|
|
624 }
|
|
625 return ((char *) ee - (char *) eeuc);
|
|
626 }
|
|
627
|
|
628
|
|
629 int
|
|
630 eeuc_to_ieuc (ieuc, eeuc, eesiz)
|
|
631 w_char *ieuc;
|
|
632 unsigned char *eeuc;
|
|
633 register int eesiz;
|
|
634 {
|
|
635 register unsigned char x;
|
|
636 register w_char *ie;
|
|
637 register unsigned char *ee;
|
|
638 register int cs_id, non_limit = 0;
|
|
639 ie = ieuc;
|
|
640 ee = eeuc;
|
|
641
|
|
642 if (eesiz == -1)
|
|
643 non_limit = 1;
|
|
644 for (; (non_limit ? (*ee) : (eesiz > 0));)
|
|
645 {
|
|
646 x = *ee++;
|
|
647 if (x > 0x9f || x == SS2 || x == SS3)
|
|
648 {
|
|
649 cs_id = ((x == SS2) ? CS2 : ((x == SS3) ? CS3 : CS1));
|
|
650 if (cs_id == CS2 || cs_id == CS3)
|
|
651 x = *ee++;
|
|
652 if (_etc_cs[cs_id] <= 0)
|
|
653 continue;
|
|
654 if (_etc_cs[cs_id] > 1)
|
|
655 {
|
|
656 *ie = (w_char) (x & 0x7f) << 8;
|
|
657 x = *ee++;
|
|
658 }
|
|
659 else
|
|
660 {
|
|
661 *ie = (w_char) 0;
|
|
662 }
|
|
663 *ie |= (x & 0x7f);
|
|
664 *ie++ |= cs_mask[cs_id];
|
|
665 eesiz -= _etc_cs[cs_id] + 1;
|
|
666 }
|
|
667 else
|
|
668 {
|
|
669 *ie++ = x;
|
|
670 eesiz--;
|
|
671 }
|
|
672 }
|
|
673 return ((char *) ie - (char *) ieuc);
|
|
674 }
|
|
675
|
|
676 #ifdef nodef
|
|
677 void
|
|
678 wnn_delete_ss2 (s, n)
|
|
679 register unsigned int *s;
|
|
680 register int n;
|
|
681 {
|
|
682 register unsigned int x;
|
|
683
|
|
684 for (; n != 0 && (x = *s); n--, s++)
|
|
685 {
|
|
686 if ((x & 0xff00) == 0x8e00)
|
|
687 *s &= ~0xff00;
|
|
688 if (x == 0xffffffff)
|
|
689 break;
|
|
690 }
|
|
691 }
|
|
692 #endif
|
|
693
|
|
694 void
|
|
695 wnn_delete_w_ss2 (s, n)
|
|
696 register w_char *s;
|
|
697 register int n;
|
|
698 {
|
|
699 register w_char x;
|
|
700
|
|
701 for (; n != 0 && (x = *s); n--, s++)
|
|
702 {
|
|
703 if ((x & 0xff00) == 0x8e00)
|
|
704 *s &= ~0xff00;
|
|
705 }
|
|
706 }
|
|
707
|
|
708 #ifdef nodef
|
|
709 int
|
|
710 wnn_byte_count (in)
|
|
711 register int in;
|
|
712 {
|
|
713 return (((in < 0xa0 && in != 0x00 && in != 0x8e) || in == 0xff) ? 1 : 2);
|
|
714 }
|
|
715 #endif
|
|
716
|
|
717 #define ASCII 0
|
|
718
|
|
719 #ifdef JAPANESE
|
|
720 #define HANKAKU_JIS_IN '\016'
|
|
721 #define HANKAKU_JIS_OUT '\017'
|
|
722
|
|
723 #define HANKAKU_JIS 2
|
|
724 #define ZENKAKU_JIS 1
|
|
725 #define ZENKAKU_JIS_HOJYO 3
|
|
726
|
|
727 static unsigned char *j;
|
|
728 static w_char *iu;
|
|
729 static unsigned char *eu;
|
|
730 static unsigned char *sj;
|
|
731 static unsigned char tmp_buf[2000];
|
|
732
|
|
733 static void
|
|
734 putj (x)
|
|
735 int x;
|
|
736 {
|
|
737 *j++ = x;
|
|
738 }
|
|
739
|
|
740 static void
|
|
741 puteu (x)
|
|
742 int x;
|
|
743 {
|
|
744 *eu++ = x;
|
|
745 }
|
|
746
|
|
747 static void
|
|
748 putsj (x)
|
|
749 int x;
|
|
750 {
|
|
751 *sj++ = x;
|
|
752 }
|
|
753
|
|
754 static void
|
|
755 putsjw (x)
|
|
756 int x;
|
|
757 {
|
|
758 *sj++ = x >> 8;
|
|
759 *sj++ = x;
|
|
760 }
|
|
761
|
|
762 static int oj_mode = ASCII; /* 出力時のjisコードのモード */
|
|
763 static int jtosj ();
|
|
764 extern int eujis_to_iujis ();
|
|
765
|
|
766 /* convert JIS code to shift-JIS code */
|
|
767 static int
|
|
768 jtosj (high, low)
|
|
769 unsigned high, low;
|
|
770 {
|
|
771 if (high & 1)
|
|
772 low += 0x1f;
|
|
773 else
|
|
774 low += 0x7d;
|
|
775 if (low >= 0x7f)
|
|
776 low++;
|
|
777 high = ((high - 0x21) >> 1) + 0x81;
|
|
778 if (high > 0x9f)
|
|
779 high += 0x40;
|
|
780 return ((high << 8) | low);
|
|
781 }
|
|
782
|
|
783 /* convert shift-JIS to JIS code */
|
|
784 static int
|
|
785 sjtoj (high, low)
|
|
786 register unsigned high, low;
|
|
787 {
|
|
788 high -= (high <= 0x9f) ? 0x71 : 0xb1;
|
|
789 high = high * 2;
|
|
790 if (low > 0x7f)
|
|
791 low--;
|
|
792 if (low >= 0x9e)
|
|
793 {
|
|
794 high += 2;
|
|
795 low -= 0x7d;
|
|
796 }
|
|
797 else
|
|
798 {
|
|
799 high++;
|
|
800 low -= 0x1f;
|
|
801 }
|
|
802 return ((high << 8) | low);
|
|
803 }
|
|
804
|
|
805 static void
|
|
806 jis_change_mode (mode, new_mode)
|
|
807 int *mode;
|
|
808 int new_mode;
|
|
809 {
|
|
810 if (*mode == new_mode)
|
|
811 return;
|
|
812 switch (*mode)
|
|
813 {
|
|
814 case ZENKAKU_JIS:
|
|
815 case ZENKAKU_JIS_HOJYO:
|
|
816 /* designate ISO-8859-1 rather than JIS X 0201 */
|
|
817 /* putj('\033'); putj('('); putj('J');break; */
|
|
818 putj ('\033');
|
|
819 putj ('(');
|
|
820 putj ('B');
|
|
821 break;
|
|
822 #ifdef JIS7
|
|
823 case HANKAKU_JIS:
|
|
824 putj (HANKAKU_JIS_OUT);
|
|
825 break;
|
|
826 #endif /* JIS7 */
|
|
827 default:;
|
|
828 }
|
|
829 *mode = new_mode;
|
|
830 switch (new_mode)
|
|
831 {
|
|
832 case ZENKAKU_JIS:
|
|
833 putj ('\033');
|
|
834 putj ('$');
|
|
835 putj ('B');
|
|
836 break;
|
|
837 case ZENKAKU_JIS_HOJYO:
|
|
838 putj ('\033');
|
|
839 putj ('$');
|
|
840 putj ('(');
|
|
841 putj ('D');
|
|
842 break;
|
|
843 #ifdef JIS7
|
|
844 case HANKAKU_JIS:
|
|
845 putj (HANKAKU_JIS_IN);
|
|
846 break;
|
|
847 #endif /* JIS7 */
|
|
848 default:;
|
|
849 }
|
|
850 }
|
|
851
|
|
852 #ifdef JIS7
|
|
853 /* 内部 U-jis を 7bit jis コードに変換します
|
|
854 文字列の長さを返します */
|
|
855 extern int
|
|
856 iujis_to_jis (jis, iujis, iusiz)
|
|
857 unsigned char *jis; /* jisコードになったものをおくbuf */
|
|
858 w_char *iujis; /* iujisコードのものをおいてくるbuf */
|
|
859 int iusiz; /* iujis の大きさ */
|
|
860 {
|
|
861 int x;
|
|
862 j = jis;
|
|
863 iu = iujis;
|
|
864 for (; iusiz > 0; iusiz -= sizeof (w_char))
|
|
865 {
|
|
866 x = *iu++;
|
|
867 if (((x & 0xFF00) == 0x8E00) || ((x & 0xFF80) == 0x80))
|
|
868 {
|
|
869 jis_change_mode (&oj_mode, HANKAKU_JIS);
|
|
870 putj (x & 0x7f);
|
|
871 }
|
|
872 else if ((x & 0x8080) == 0x8080)
|
|
873 {
|
|
874 jis_change_mode (&oj_mode, ZENKAKU_JIS);
|
|
875 putj ((x >> 8) & 0x7f);
|
|
876 putj (x & 0x7f);
|
|
877 }
|
|
878 else if (x & 0x8000)
|
|
879 {
|
|
880 jis_change_mode (&oj_mode, ZENKAKU_JIS_HOJYO);
|
|
881 putj ((x >> 8) & 0x7f);
|
|
882 putj (x & 0x7f);
|
|
883 }
|
|
884 else
|
|
885 {
|
|
886 jis_change_mode (&oj_mode, ASCII);
|
|
887 putj (x);
|
|
888 }
|
|
889 }
|
|
890 jis_change_mode (&oj_mode, ASCII);
|
|
891 return (j - jis);
|
|
892 }
|
|
893 #endif /* JIS7 */
|
|
894
|
|
895 /* 内部 U-jis を 8bit jis コードに変換します
|
|
896 文字列の長さを返します */
|
|
897 extern int
|
|
898 iujis_to_jis8 (jis, iujis, iusiz)
|
|
899 unsigned char *jis; /* jisコードになったものをおくbuf */
|
|
900 w_char *iujis; /* iujisコードのものをおいてくるbuf */
|
|
901 int iusiz; /* iujis の大きさ */
|
|
902 {
|
|
903 int x;
|
|
904 j = jis;
|
|
905 iu = iujis;
|
|
906 for (; iusiz > 0; iusiz -= sizeof (w_char))
|
|
907 {
|
|
908 x = *iu++;
|
|
909 if (((x & 0xFF00) == 0x8E00) || ((x & 0xFF80) == 0x80))
|
|
910 {
|
|
911 jis_change_mode (&oj_mode, ASCII);
|
|
912 putj (x & 0xff);
|
|
913 }
|
|
914 else if ((x & 0x8080) == 0x8080)
|
|
915 {
|
|
916 jis_change_mode (&oj_mode, ZENKAKU_JIS);
|
|
917 putj ((x >> 8) & 0x7f);
|
|
918 putj (x & 0x7f);
|
|
919 }
|
|
920 else if (x & 0x8000)
|
|
921 {
|
|
922 jis_change_mode (&oj_mode, ZENKAKU_JIS_HOJYO);
|
|
923 putj ((x >> 8) & 0x7f);
|
|
924 putj (x & 0x7f);
|
|
925 }
|
|
926 else
|
|
927 {
|
|
928 jis_change_mode (&oj_mode, ASCII);
|
|
929 putj (x);
|
|
930 }
|
|
931 }
|
|
932 jis_change_mode (&oj_mode, ASCII);
|
|
933 return (j - jis);
|
|
934 }
|
|
935
|
|
936
|
|
937 #ifdef JIS7
|
|
938 /* 外部 U-jis を 7bit jis コードに変換します */
|
|
939 extern int
|
|
940 eujis_to_jis (jis, eujis, eusiz)
|
|
941 unsigned char *jis, *eujis;
|
|
942 int eusiz;
|
|
943 {
|
|
944 static int kanji1 = 0;
|
|
945 static char kanji1_code = 0;
|
|
946 /* 0: normal
|
|
947 1: get SS2
|
|
948 2: get kanji 1 byte */
|
|
949 /*
|
|
950 int oj_mode;
|
|
951 */
|
|
952 int x;
|
|
953 j = jis;
|
|
954 eu = eujis;
|
|
955 /* ADD KURI */
|
|
956 if (kanji1 != 0)
|
|
957 {
|
|
958 if (kanji1 == 2)
|
|
959 {
|
|
960 putj (kanji1_code & 0x7f);
|
|
961 }
|
|
962 putj (*eu & 0x7f);
|
|
963 eusiz -= sizeof (char);
|
|
964 kanji1 = 0;
|
|
965 }
|
|
966 /* ADD KURI end */
|
|
967 /*
|
|
968 for(oj_mode=ASCII;eusiz>0;eusiz-=sizeof(char)){
|
|
969 */
|
|
970 for (; eusiz > 0; eusiz -= sizeof (char))
|
|
971 {
|
|
972 x = *eu++;
|
|
973 if ((x & 0xFF) == 0x8E)
|
|
974 {
|
|
975 jis_change_mode (&oj_mode, HANKAKU_JIS);
|
|
976 if (eusiz > 1)
|
|
977 {
|
|
978 putj (*eu++ & 0x7f);
|
|
979 eusiz -= sizeof (char);
|
|
980 }
|
|
981 else
|
|
982 {
|
|
983 kanji1 = 1;
|
|
984 }
|
|
985 }
|
|
986 else if (x & 0x80)
|
|
987 {
|
|
988 jis_change_mode (&oj_mode, ZENKAKU_JIS);
|
|
989 if (eusiz > 1)
|
|
990 {
|
|
991 putj (x & 0x7f);
|
|
992 putj (*eu++ & 0x7f);
|
|
993 eusiz -= sizeof (char);
|
|
994 }
|
|
995 else
|
|
996 {
|
|
997 kanji1 = 2;
|
|
998 kanji1_code = x & 0x7f;
|
|
999 }
|
|
1000 }
|
|
1001 else
|
|
1002 {
|
|
1003 jis_change_mode (&oj_mode, ASCII);
|
|
1004 putj (x);
|
|
1005 }
|
|
1006 }
|
|
1007 if (kanji1 == 0)
|
|
1008 jis_change_mode (&oj_mode, ASCII);
|
|
1009 return (j - jis);
|
|
1010 }
|
|
1011 #endif /* JIS7 */
|
|
1012
|
|
1013 /* 外部 U-jis を 8bit jis コードに変換します */
|
|
1014 extern int
|
|
1015 eujis_to_jis8 (jis, eujis, eusiz)
|
|
1016 unsigned char *jis, *eujis;
|
|
1017 int eusiz;
|
|
1018 {
|
|
1019 static int kanji1 = 0;
|
|
1020 static unsigned char kanji1_code = 0;
|
|
1021 /* 0: normal
|
|
1022 1: get SS2
|
|
1023 2: get kanji 1 byte */
|
|
1024 /*
|
|
1025 int oj_mode;
|
|
1026 */
|
|
1027 int x;
|
|
1028 j = jis;
|
|
1029 eu = eujis;
|
|
1030 /* ADD KURI */
|
|
1031 if (kanji1 != 0)
|
|
1032 {
|
|
1033 if (kanji1 == 2)
|
|
1034 {
|
|
1035 putj (kanji1_code & 0x7f);
|
|
1036 putj (*eu & 0x7f);
|
|
1037 }
|
|
1038 else
|
|
1039 {
|
|
1040 putj (*eu);
|
|
1041 }
|
|
1042 eusiz -= sizeof (char);
|
|
1043 kanji1 = 0;
|
|
1044 eu++;
|
|
1045 }
|
|
1046 /* ADD KURI end */
|
|
1047 /*
|
|
1048 for(oj_mode=ASCII;eusiz>0;eusiz-=sizeof(char)){
|
|
1049 */
|
|
1050 for (; eusiz > 0; eusiz -= sizeof (char))
|
|
1051 {
|
|
1052 x = *eu++;
|
|
1053 if ((x & 0xFF) == 0x8E)
|
|
1054 {
|
|
1055 jis_change_mode (&oj_mode, ASCII);
|
|
1056 if (eusiz > 1)
|
|
1057 {
|
|
1058 putj (*eu++);
|
|
1059 eusiz -= sizeof (char);
|
|
1060 }
|
|
1061 else
|
|
1062 {
|
|
1063 kanji1 = 1;
|
|
1064 }
|
|
1065 }
|
|
1066 else if (x & 0x80)
|
|
1067 {
|
|
1068 jis_change_mode (&oj_mode, ZENKAKU_JIS);
|
|
1069 if (eusiz > 1)
|
|
1070 {
|
|
1071 putj (x & 0x7f);
|
|
1072 putj (*eu++ & 0x7f);
|
|
1073 eusiz -= sizeof (char);
|
|
1074 }
|
|
1075 else
|
|
1076 {
|
|
1077 kanji1 = 2;
|
|
1078 kanji1_code = x;
|
|
1079 }
|
|
1080 }
|
|
1081 else
|
|
1082 {
|
|
1083 jis_change_mode (&oj_mode, ASCII);
|
|
1084 putj (x);
|
|
1085 }
|
|
1086 }
|
|
1087 if (kanji1 == 0)
|
|
1088 jis_change_mode (&oj_mode, ASCII);
|
|
1089 return (j - jis);
|
|
1090 }
|
|
1091
|
|
1092 /* 内部 U-jis を 外部 U-jis コードに変換します */
|
|
1093 extern int
|
|
1094 iujis_to_eujis (eujis, iujis, iusiz)
|
|
1095 unsigned char *eujis;
|
|
1096 w_char *iujis;
|
|
1097 int iusiz;
|
|
1098 {
|
|
1099 static int first = 0;
|
|
1100 static unsigned int cswidth_id;
|
|
1101
|
|
1102 if (first == 0)
|
|
1103 {
|
|
1104 cswidth_id = create_cswidth (UJIS_CSWIDTH);
|
|
1105 first++;
|
|
1106 }
|
|
1107 set_cswidth (cswidth_id);
|
|
1108 return (ieuc_to_eeuc (eujis, iujis, iusiz));
|
|
1109 }
|
|
1110
|
|
1111 int
|
|
1112 jis_to_eujis (eujis, jis, jsiz)
|
|
1113 unsigned char *eujis, *jis;
|
|
1114 int jsiz;
|
|
1115 {
|
|
1116 int len;
|
|
1117
|
|
1118 designate = JIS_designate;
|
|
1119 len = extc_to_intc (tmp_w_buf, jis, jsiz);
|
|
1120 return (iujis_to_eujis (eujis, tmp_w_buf, len));
|
|
1121 }
|
|
1122
|
|
1123 /*
|
|
1124 * Shifted JIS
|
|
1125 */
|
|
1126
|
|
1127 /* 外部 U-jis を S-jis コードに変換します
|
|
1128 文字列の長さを返します */
|
|
1129 extern int
|
|
1130 eujis_to_sjis (sjis, eujis, eusiz)
|
|
1131 unsigned char *sjis; /* sjisコードになったものをおくbuf */
|
|
1132 unsigned char *eujis; /* eujisコードのものをおいてくるbuf */
|
|
1133 int eusiz; /* eujis の大きさ */
|
|
1134 {
|
|
1135 register int x;
|
|
1136 int save = 0;
|
|
1137 sj = sjis;
|
|
1138 eu = eujis;
|
|
1139 if (save && eusiz > 0)
|
|
1140 {
|
|
1141 if (save == 0x8e)
|
|
1142 {
|
|
1143 putsj (*eu++ | 0x80);
|
|
1144 }
|
|
1145 else
|
|
1146 {
|
|
1147 putsjw (jtosj (save & 0x7F, *eu++ & 0x7F));
|
|
1148 }
|
|
1149 eusiz--;
|
|
1150 }
|
|
1151 for (; eusiz > 0;)
|
|
1152 {
|
|
1153 x = *eu++;
|
|
1154 eusiz--;
|
|
1155 if (x & 0x80)
|
|
1156 {
|
|
1157 if (eusiz <= 0)
|
|
1158 {
|
|
1159 save = x;
|
|
1160 break;
|
|
1161 }
|
|
1162 if (x == 0x8e)
|
|
1163 {
|
|
1164 putsj (*eu++ | 0x80);
|
|
1165 }
|
|
1166 else
|
|
1167 {
|
|
1168 putsjw (jtosj (x & 0x7F, *eu++ & 0x7F));
|
|
1169 }
|
|
1170 eusiz--;
|
|
1171 }
|
|
1172 else
|
|
1173 {
|
|
1174 putsj (x);
|
|
1175 }
|
|
1176 }
|
|
1177 return (sj - sjis);
|
|
1178 }
|
|
1179
|
|
1180 /* 内部 U-jis を S-jis コードに変換します
|
|
1181 文字列の長さを返します */
|
|
1182 extern int
|
|
1183 iujis_to_sjis (sjis, iujis, iusiz)
|
|
1184 unsigned char *sjis; /* sjisコードになったものをおくbuf */
|
|
1185 w_char *iujis; /* iujisコードのものをおいてくるbuf */
|
|
1186 int iusiz; /* iujis の大きさ */
|
|
1187 {
|
|
1188 register int x;
|
|
1189 sj = sjis;
|
|
1190 iu = iujis;
|
|
1191 for (; iusiz > 0; iusiz -= sizeof (w_char))
|
|
1192 {
|
|
1193 if ((x = *iu++) & 0xff00)
|
|
1194 {
|
|
1195 if ((x & 0xff00) == 0x8e00)
|
|
1196 {
|
|
1197 putsj ((x & 0xff) | 0x80);
|
|
1198 }
|
|
1199 else
|
|
1200 {
|
|
1201 putsjw (jtosj ((x >> 8) & 0x7f, x & 0x7f));
|
|
1202 }
|
|
1203 }
|
|
1204 else
|
|
1205 {
|
|
1206 putsj (x);
|
|
1207 }
|
|
1208 }
|
|
1209 return (sj - sjis);
|
|
1210 }
|
|
1211
|
|
1212 int
|
|
1213 sjis_to_iujis (iujis, sjis, ssiz)
|
|
1214 w_char *iujis; /* iujisコードになったものをおくbuf */
|
|
1215 unsigned char *sjis; /* sjisコードのものをおいてくるbuf */
|
|
1216 int ssiz; /* sjis の大き */
|
|
1217 {
|
|
1218 register int x;
|
|
1219 int save = 0;
|
|
1220 sj = sjis;
|
|
1221 iu = iujis;
|
|
1222 if (save && ssiz > 0)
|
|
1223 {
|
|
1224 *iu++ = (sjtoj (save, *sj++) | 0x8080);
|
|
1225 ssiz--;
|
|
1226 save = 0;
|
|
1227 }
|
|
1228 for (; ssiz > 0;)
|
|
1229 {
|
|
1230 x = *sj++;
|
|
1231 ssiz--;
|
|
1232 if (x & 0x80)
|
|
1233 {
|
|
1234 if (ssiz <= 0)
|
|
1235 {
|
|
1236 save = x;
|
|
1237 break;
|
|
1238 }
|
|
1239 *iu++ = ((sjtoj (x, *sj++)) | 0x8080);
|
|
1240 ssiz--;
|
|
1241 }
|
|
1242 else
|
|
1243 {
|
|
1244 *iu++ = (x);
|
|
1245 }
|
|
1246 }
|
|
1247 return ((char *) iu - (char *) iujis);
|
|
1248 }
|
|
1249
|
|
1250 int
|
|
1251 sjis_to_eujis (eujis, sjis, ssiz)
|
|
1252 unsigned char *eujis; /* eujisコードになったものをおくbuf */
|
|
1253 unsigned char *sjis; /* sjisコードのものをおいてくるbuf */
|
|
1254 int ssiz; /* sjis の大きさ */
|
|
1255 {
|
|
1256 register int x;
|
|
1257 unsigned char *sj;
|
|
1258 int save = 0;
|
|
1259 sj = sjis;
|
|
1260 eu = eujis;
|
|
1261 if (save && ssiz > 0)
|
|
1262 {
|
|
1263 x = (sjtoj (save, *sj++) | 0x8080);
|
|
1264 puteu (x >> 8);
|
|
1265 puteu (x);
|
|
1266 ssiz--;
|
|
1267 save = 0;
|
|
1268 }
|
|
1269 for (; ssiz > 0;)
|
|
1270 {
|
|
1271 x = *sj++;
|
|
1272 ssiz--;
|
|
1273 if (x & 0x80)
|
|
1274 {
|
|
1275 if (ssiz <= 0)
|
|
1276 {
|
|
1277 save = x;
|
|
1278 break;
|
|
1279 }
|
|
1280 x = (sjtoj (x, *sj++) | 0x8080); /* 変えました KUWA */
|
|
1281 puteu (x >> 8);
|
|
1282 puteu (x);
|
|
1283 ssiz--;
|
|
1284 }
|
|
1285 else
|
|
1286 {
|
|
1287 puteu (x);
|
|
1288 }
|
|
1289 }
|
|
1290 return (eu - eujis);
|
|
1291 }
|
|
1292
|
|
1293 #ifdef JIS7
|
|
1294 int
|
|
1295 sjis_to_jis (jis, sjis, siz)
|
|
1296 unsigned char *jis, *sjis;
|
|
1297 int siz;
|
|
1298 {
|
|
1299 int len;
|
|
1300 len = sjis_to_eujis (tmp_buf, sjis, siz);
|
|
1301 return (eujis_to_jis (jis, tmp_buf, len));
|
|
1302 }
|
|
1303 #endif /* JIS7 */
|
|
1304
|
|
1305 int
|
|
1306 sjis_to_jis8 (jis, sjis, siz)
|
|
1307 unsigned char *jis, *sjis;
|
|
1308 int siz;
|
|
1309 {
|
|
1310 int len;
|
|
1311 len = sjis_to_eujis (tmp_buf, sjis, siz);
|
|
1312 return (eujis_to_jis8 (jis, tmp_buf, len));
|
|
1313 }
|
|
1314
|
|
1315 int
|
|
1316 jis_to_iujis (iujis, jis, jsiz)
|
|
1317 w_char *iujis;
|
|
1318 unsigned char *jis;
|
|
1319 int jsiz;
|
|
1320 {
|
|
1321 designate = JIS_designate;
|
|
1322 return (extc_to_intc (iujis, jis, jsiz));
|
|
1323 }
|
|
1324
|
|
1325 int
|
|
1326 jis_to_sjis (sjis, jis, siz)
|
|
1327 unsigned char *sjis, *jis;
|
|
1328 int siz;
|
|
1329 {
|
|
1330 int len;
|
|
1331 len = jis_to_iujis (tmp_w_buf, jis, siz);
|
|
1332 return (iujis_to_sjis (sjis, tmp_w_buf, len));
|
|
1333 }
|
|
1334
|
|
1335 int
|
|
1336 eujis_to_iujis (iujis, eujis, eusiz)
|
|
1337 w_char *iujis;
|
|
1338 unsigned char *eujis;
|
|
1339 int eusiz;
|
|
1340 {
|
|
1341 static int first = 0;
|
|
1342 static unsigned int cswidth_id;
|
|
1343
|
|
1344 if (first == 0)
|
|
1345 {
|
|
1346 cswidth_id = create_cswidth (UJIS_CSWIDTH);
|
|
1347 first++;
|
|
1348 }
|
|
1349 set_cswidth (cswidth_id);
|
|
1350 return (eeuc_to_ieuc (iujis, eujis, eusiz));
|
|
1351 }
|
|
1352
|
|
1353 #endif /* JAPANESE */
|
|
1354
|
|
1355 #ifdef CHINESE
|
|
1356
|
|
1357 #define CNS11643_1 2
|
|
1358 #define CNS11643_2 1
|
|
1359
|
|
1360 /* The following facts are helpful for understanding:
|
|
1361 * _W, means Wei in Pinyin
|
|
1362 * _Q, means Wei in Pinyin.
|
|
1363 * 0x5e = 94, num of wchar in one _Q at 1xxxxxxx 1xxxxxxx hand
|
|
1364 * 0x3f = 63, Num of Wchar in one _Q at 1xxxxxxx 0xxxxxxx hand
|
|
1365 * Almost all the numbers in HEX are given for showing the _Q or _W
|
|
1366 */
|
|
1367
|
|
1368 #define CNS_NUM_Q 0x5e /* num of wchar in one _Q at hand */
|
|
1369 #define BIG5_NUM_11_Q 0x5e /* num of wchar in one _Q at 1xxxxxxx 1xxxxxxx hand */
|
|
1370 #define BIG5_NUM_10_Q 0x3f /* num of wchar in one _Q at 1xxxxxxx 0xxxxxxx hand */
|
|
1371
|
|
1372 #define CNS_HANZI_11_START_Q 0x24 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1373 #define CNS_HANZI_11_START_W 0x01 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1374 #define CNS_HANZI_11_END_Q 0x5D /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1375 #define CNS_HANZI_11_END_W 0x2B /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1376 #define CNS_HANZI_11_START_QM 0x01 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1377 #define CNS_HANZI_11_END_QM 0x05 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1378
|
|
1379 #define CNS_HANZI_10_START_Q 0x01 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1380 #define CNS_HANZI_10_START_W 0x01 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1381 #define CNS_HANZI_10_END_Q 0x52 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1382 #define CNS_HANZI_10_END_W 0x24 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1383
|
|
1384 #define BIG5_HANZI_11_START_Q 0x04 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1385 #define BIG5_HANZI_11_START_W 0x01 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1386 #define BIG5_HANZI_11_END_Q 0x25 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1387 #define BIG5_HANZI_11_END_W 0x5e /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1388 #define BIG5_HANZI_11_START_QM 0x01 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1389 #define BIG5_HANZI_11_END_QM 0x03 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1390
|
|
1391 #define BIG5_HANZI_10_START_Q 0x04 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1392 #define BIG5_HANZI_10_START_W 0x20 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1393 #define BIG5_HANZI_10_END_Q 0x26 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1394 #define BIG5_HANZI_10_END_W 0x5e /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1395
|
|
1396 #define BIG5_HANZI_11_START_Q2 0x29 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1397 #define BIG5_HANZI_11_START_W2 0x01 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1398 #define BIG5_HANZI_11_END_Q2 0x59 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1399 #define BIG5_HANZI_11_END_W2 0x35 /* At 1xxxxxxx 1xxxxxxx hand */
|
|
1400
|
|
1401 #define BIG5_HANZI_10_START_Q2 0x29 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1402 #define BIG5_HANZI_10_START_W2 0x20 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1403 #define BIG5_HANZI_10_END_Q2 0x59 /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1404 #define BIG5_HANZI_10_END_W2 0x5e /* At 1xxxxxxx 0xxxxxxx hand */
|
|
1405
|
|
1406 #define CNS_SYMBOL_11_START 0
|
|
1407 #define CNS_SYMBOL_11_END 0
|
|
1408 #define BIG5_SYMBOL_10_START 0
|
|
1409 #define BIG5_SYMBOL_10_END 0
|
|
1410 #define BIG5_SYMBOL_11_START 0
|
|
1411 #define BIG5_SYMBOL_11_END 0
|
|
1412
|
|
1413 #define BIG5_TO_CNS 0x0000 /* Flag for convert from BIG5 to CNS */
|
|
1414 #define CNS_TO_BIG5 0x0001 /* Flag for convert from CNS to BIG5 */
|
|
1415
|
|
1416 #define BIG5_1NUMS ((BIG5_NUM_10_Q*0x23)+(BIG5_NUM_11_Q*0x22))
|
|
1417 /* Numbers of level 1 */
|
|
1418 #define BIG5_1TO2_SKIP (0x25*(BIG5_NUM_10_Q+BIG5_NUM_11_Q))
|
|
1419 /*Location of starting level 2 */
|
|
1420
|
|
1421 #define CNS_SPACE 0x256D /* for unconvert character code */
|
|
1422
|
|
1423 /* not sequential character code on CNS level 2 */
|
|
1424 #define CNS_XK 0xa121 /* XK on Tsang Jye */
|
|
1425 #define CNS_ONLN 0xa14c /* ONLN on Tsang Jye */
|
|
1426 #define CNS_MSOK 0xa24d /* MSOK on Tsang Jye */
|
|
1427 #define CNS_TNKM 0xbf6a /* TNKM on Tsang Jye */
|
|
1428 #define CNS_CYIB 0xd54b /* CYIB on Tsang Jye */
|
|
1429 #define CNS_YIHXO 0xda28 /* YIHXO on Tsang Jye */
|
|
1430 #define CNS_MDMR 0xdd74 /* MDMR on Tsang Jye */
|
|
1431 #define CNS_COLH 0xe42f /* COLH on Tsang Jye */
|
|
1432 #define CNS_ODC 0xe761 /* ODC on Tsang Jye */
|
|
1433 #define CNS_OKHAE 0xe934 /* OKHAE on Tsang Jye */
|
|
1434 #define CNS_HBBM 0xe64d /* HBBM on Tsang Jye */
|
|
1435 #define CNS_CJTC 0xea4b /* CJTC on Tsang Jye */
|
|
1436 #define CNS_LNNXU 0xf166 /* LNNXU on Tsang Jye */
|
|
1437 #define CNS_YPYBP 0xf244 /* YPYBP on Tsang Jye */
|
|
1438 #define CNS_FDDH 0xf240 /* FDDH on Tsang Jye */
|
|
1439 #define CNS_HOOMA 0xd722 /* HOOMA on Tsang Jye */
|
|
1440
|
|
1441 /* not sequential character code on BIG5 level 2 */
|
|
1442 #define BIG5_XK 0xc940 /* XK on Tsang Jye */
|
|
1443 #define BIG5_ONLN 0xc9be /* ONLN on Tsang Jye */
|
|
1444 #define BIG5_MSOK 0xcaf7 /* MSOK on Tsang Jye */
|
|
1445 #define BIG5_TNKM 0xd77a /* TNKM on Tsang Jye */
|
|
1446 #define BIG5_CYIB 0xebf1 /* CYIB on Tsang Jye */
|
|
1447 #define BIG5_YIHXO 0xf0cb /* YIHXO on Tsang Jye */
|
|
1448 #define BIG5_MDMR 0xf056 /* MDMR on Tsang Jye */
|
|
1449 #define BIG5_COLH 0xeeeb /* COLH on Tsang Jye */
|
|
1450 #define BIG5_ODC 0xf16b /* ODC on Tsang Jye */
|
|
1451 #define BIG5_OKHAE 0xf268 /* OKHAE on Tsang Jye */
|
|
1452 #define BIG5_HBBM 0xf4b5 /* HBBM on Tsang Jye */
|
|
1453 #define BIG5_CJTC 0xf663 /* CJTC on Tsang Jye */
|
|
1454 #define BIG5_LNNXU 0xf9c4 /* LNNXU on Tsang Jye */
|
|
1455 #define BIG5_YPYBP 0xf9d5 /* YPYBP on Tsang Jye */
|
|
1456 #define BIG5_FDDH 0xf9c6 /* FDDH on Tsang Jye */
|
|
1457 #define BIG5_HOOMA 0xecde /* HOOMA on Tsang Jye */
|
|
1458 #define BIG5_MU 0xc94a /* MU on Tsang Jye */
|
|
1459 #define BIG5_GRHNE 0xddfc /* GRHNE on Tsang Jye */
|
|
1460
|
|
1461 /* This function checks if the given code is really a Hanzi in the original
|
|
1462 code definition determined by "which". If so, it returns 1. And otherwise
|
|
1463 it returns 0)
|
|
1464 */
|
|
1465 static int
|
|
1466 _is_hanzi (code, which)
|
|
1467 w_char code;
|
|
1468 int which;
|
|
1469 {
|
|
1470 register unsigned char high, low;
|
|
1471
|
|
1472 if (which == CNS_TO_BIG5)
|
|
1473 {
|
|
1474 if ((code & 0x8080) == 0x8080)
|
|
1475 { /* 1xxxxxxx 1xxxxxxx Case */
|
|
1476 high = (code >> 8) - 0xa0;
|
|
1477 low = (code & 0xff) - 0xa0;
|
|
1478 if (((high >= CNS_HANZI_11_START_Q && high < CNS_HANZI_11_END_Q) &&
|
|
1479 (low >= CNS_HANZI_11_START_W && low <= CNS_NUM_Q)) ||
|
|
1480 ((high == CNS_HANZI_11_END_Q) &&
|
|
1481 (low >= CNS_HANZI_11_START_W && low <= CNS_HANZI_11_END_W)) || ((high >= CNS_HANZI_11_START_QM && high < CNS_HANZI_11_END_QM) && (low >= CNS_HANZI_11_START_W && low <= CNS_NUM_Q)))
|
|
1482 {
|
|
1483 return (1);
|
|
1484 }
|
|
1485 else
|
|
1486 {
|
|
1487 return (0);
|
|
1488 }
|
|
1489 }
|
|
1490 else if ((code & 0x8080) == 0x8000)
|
|
1491 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1492 high = (code >> 8) - 0xa0;
|
|
1493 low = (code & 0xff) - 0x20;
|
|
1494 if (((high >= CNS_HANZI_10_START_Q && high < CNS_HANZI_10_END_Q) &&
|
|
1495 (low >= CNS_HANZI_10_START_W && low <= CNS_NUM_Q)) || ((high == CNS_HANZI_10_END_Q) && (low >= CNS_HANZI_10_START_W && low <= CNS_HANZI_10_END_W)))
|
|
1496 {
|
|
1497 return (1);
|
|
1498 }
|
|
1499 else
|
|
1500 {
|
|
1501 return (0);
|
|
1502 }
|
|
1503 }
|
|
1504 else
|
|
1505 {
|
|
1506 return (0);
|
|
1507 }
|
|
1508 }
|
|
1509 else if (which == BIG5_TO_CNS)
|
|
1510 {
|
|
1511 if ((code & 0x8080) == 0x8080)
|
|
1512 { /* 1xxxxxxx 1xxxxxxx Case */
|
|
1513 high = (code >> 8) - 0xa0;
|
|
1514 low = (code & 0xff) - 0xa0;
|
|
1515 if (((high >= BIG5_HANZI_11_START_Q && high <= BIG5_HANZI_11_END_Q) &&
|
|
1516 (low >= BIG5_HANZI_11_START_W && low <= BIG5_HANZI_11_END_W)) ||
|
|
1517 ((high >= BIG5_HANZI_11_START_QM && high <= BIG5_HANZI_11_END_QM) && (low >= BIG5_HANZI_11_START_W && low <= BIG5_HANZI_11_END_W)))
|
|
1518 {
|
|
1519 return (1);
|
|
1520 }
|
|
1521 else if (((high >= BIG5_HANZI_11_START_Q2 && high < BIG5_HANZI_11_END_Q2) &&
|
|
1522 (low >= BIG5_HANZI_11_START_W2 && low <= BIG5_HANZI_11_END_W)) || ((high == BIG5_HANZI_11_END_Q2) && (low >= BIG5_HANZI_11_START_W2 && low <= BIG5_HANZI_11_END_W2)))
|
|
1523 {
|
|
1524 return (1);
|
|
1525 }
|
|
1526 else
|
|
1527 {
|
|
1528 return (0);
|
|
1529 }
|
|
1530 }
|
|
1531 else if ((code & 0x8080) == 0x8000)
|
|
1532 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1533 high = (code >> 8) - 0xa0;
|
|
1534 low = (code & 0xff) - 0x20;
|
|
1535 if ((high >= BIG5_HANZI_10_START_Q && high <= BIG5_HANZI_10_END_Q) && (low >= BIG5_HANZI_10_START_W && low <= BIG5_HANZI_10_END_W))
|
|
1536 {
|
|
1537 return (1);
|
|
1538 }
|
|
1539 else if ((high >= BIG5_HANZI_10_START_Q2 && high <= BIG5_HANZI_10_END_Q2) && (low >= BIG5_HANZI_10_START_W2 && low <= BIG5_HANZI_10_END_W2))
|
|
1540 {
|
|
1541 return (1);
|
|
1542 }
|
|
1543 else
|
|
1544 {
|
|
1545 return (0);
|
|
1546 }
|
|
1547 }
|
|
1548 else
|
|
1549 {
|
|
1550 return (0);
|
|
1551 }
|
|
1552 }
|
|
1553 return (0);
|
|
1554 }
|
|
1555
|
|
1556 /* convert one Hanzi from BIG5 (or CNS) to CNS (or BIG5) depend on the
|
|
1557 parameter "which". This function works under the asumpsion that the
|
|
1558 give code is really a Hanzi under the original code definition. Given
|
|
1559 code value can be checked by function "_is_hanzi()" in the same file.
|
|
1560 The result Hanzi code is always returned.
|
|
1561 */
|
|
1562 static unsigned int
|
|
1563 _convert (code, which)
|
|
1564 register w_char code;
|
|
1565 int which;
|
|
1566 {
|
|
1567 unsigned int qu, wei; /* counting from 1 ------ */
|
|
1568 register unsigned int location; /* counting from 0 ---- */
|
|
1569 unsigned int loc_wei; /* counting from 0 ---- */
|
|
1570 int plant;
|
|
1571
|
|
1572 if (which == CNS_TO_BIG5)
|
|
1573 {
|
|
1574 if ((code & 0x8080) == 0x8080)
|
|
1575 { /* 1xxxxxxx 1xxxxxxx Case */
|
|
1576 if (code <= 0xa5fe && code >= 0xa1a1)
|
|
1577 {
|
|
1578 wei = (code & 0x7f);
|
|
1579 switch (((code & 0xff00) >> 8) - 0xa0)
|
|
1580 {
|
|
1581 case (1):
|
|
1582 if (wei > 0x5f)
|
|
1583 {
|
|
1584 return (0xa1a1 + (wei - 0x60));
|
|
1585 }
|
|
1586 else
|
|
1587 {
|
|
1588 return (0xa140 + (wei - 0x21));
|
|
1589 }
|
|
1590 case (2):
|
|
1591 if (wei > 0x5f)
|
|
1592 {
|
|
1593 return (0xa2a1 + (wei - 0x60));
|
|
1594 }
|
|
1595 else
|
|
1596 {
|
|
1597 return (0xa240 + (wei - 0x21));
|
|
1598 }
|
|
1599 case (3):
|
|
1600 if (wei > 0x40)
|
|
1601 {
|
|
1602 return (0xa2a1 + (wei - 0x41));
|
|
1603 }
|
|
1604 else
|
|
1605 {
|
|
1606 return (0xa25f + (wei - 0x21));
|
|
1607 }
|
|
1608 case (4):
|
|
1609 if (wei > 0x70)
|
|
1610 {
|
|
1611 return (0xa340 + (wei - 0x71));
|
|
1612 }
|
|
1613 else
|
|
1614 {
|
|
1615 return (0xa2af + (wei - 0x21));
|
|
1616 }
|
|
1617 case (5):
|
|
1618 if (wei > 0x51)
|
|
1619 {
|
|
1620 return (0xa3a1 + (wei - 0x52));
|
|
1621 }
|
|
1622 else
|
|
1623 {
|
|
1624 return (0xa34e + (wei - 0x21));
|
|
1625 }
|
|
1626 }
|
|
1627 }
|
|
1628 location = ((code >> 8) - 0xa0 - CNS_HANZI_11_START_Q) * CNS_NUM_Q + (code & 0xff) - 0xa0 - 1;
|
|
1629 if ((code > 0xebd0 && code <= 0xefdb) || (code > 0xf5c5 && code <= 0xf7c6) || (code > 0xf8ad && code <= 0xf9e1))
|
|
1630 location--;
|
|
1631 else if (code == 0xebd0)
|
|
1632 return (0xbe52);
|
|
1633 else if (code == 0xf5b5)
|
|
1634 return (0xc2cb);
|
|
1635 else if (code == 0xf8ad)
|
|
1636 return (0xc456);
|
|
1637 }
|
|
1638 else
|
|
1639 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1640 location = ((code >> 8) - 0xa0 - CNS_HANZI_10_START_Q) * CNS_NUM_Q + (code & 0xff) - 0x20 - 1;
|
|
1641 location += BIG5_1TO2_SKIP;
|
|
1642 if (code > CNS_YIHXO && code <= 0xdb3e)
|
|
1643 location--;
|
|
1644 else if ((code >= 0xa12b && code < CNS_ONLN) ||
|
|
1645 (code >= 0xa17d && code < CNS_MSOK) ||
|
|
1646 (code >= 0xa439 && code <= 0xb87d) ||
|
|
1647 (code > CNS_TNKM && code <= 0xc423) ||
|
|
1648 (code > CNS_CYIB && code < CNS_HOOMA) ||
|
|
1649 (code >= 0xdc6a && code < CNS_MDMR) ||
|
|
1650 (code >= 0xe039 && code <= 0xe242) || (code > CNS_OKHAE && code <= 0xe961) || (code > CNS_CJTC && code <= 0xec51) || (code > CNS_LNNXU && code <= 0xf233))
|
|
1651 location++;
|
|
1652 else if ((code >= 0xb87e && code < CNS_TNKM) ||
|
|
1653 (code >= 0xc424 && code < CNS_CYIB) ||
|
|
1654 (code >= 0xe243 && code <= 0xe336) ||
|
|
1655 (code > CNS_COLH && code <= 0xe437) ||
|
|
1656 (code > CNS_ODC && code < CNS_OKHAE) || (code >= 0xe962 && code < CNS_CJTC) || (code >= 0xec52 && code < CNS_LNNXU) || (code == 0xf234) || (code > CNS_FDDH && code <= CNS_YPYBP))
|
|
1657 location += 2;
|
|
1658 else if ((code >= 0xe337 && code < CNS_COLH) || (code >= 0xe438 && code <= 0xe572) || (code > CNS_HBBM && code < CNS_ODC) || (code >= 0xf235 && code < CNS_FDDH))
|
|
1659 location += 3;
|
|
1660 else if (code >= 0xe573 && code < CNS_HBBM)
|
|
1661 location += 4;
|
|
1662 else if (code == CNS_ONLN)
|
|
1663 return (BIG5_ONLN);
|
|
1664 else if (code == CNS_MSOK)
|
|
1665 return (BIG5_MSOK);
|
|
1666 else if (code == CNS_TNKM)
|
|
1667 return (BIG5_TNKM);
|
|
1668 else if (code == CNS_CYIB)
|
|
1669 return (BIG5_CYIB);
|
|
1670 else if (code == CNS_YIHXO)
|
|
1671 return (BIG5_YIHXO);
|
|
1672 else if (code == CNS_MDMR)
|
|
1673 return (BIG5_MDMR);
|
|
1674 else if (code == CNS_COLH)
|
|
1675 return (BIG5_COLH);
|
|
1676 else if (code == CNS_ODC)
|
|
1677 return (BIG5_ODC);
|
|
1678 else if (code == CNS_OKHAE)
|
|
1679 return (BIG5_OKHAE);
|
|
1680 else if (code == CNS_HBBM)
|
|
1681 return (BIG5_HBBM);
|
|
1682 else if (code == CNS_CJTC)
|
|
1683 return (BIG5_CJTC);
|
|
1684 else if (code == CNS_LNNXU)
|
|
1685 return (BIG5_LNNXU);
|
|
1686 else if (code == CNS_YPYBP)
|
|
1687 return (BIG5_YPYBP);
|
|
1688 else if (code == CNS_HOOMA)
|
|
1689 return (BIG5_HOOMA);
|
|
1690 else if (code == CNS_FDDH)
|
|
1691 return (BIG5_FDDH);
|
|
1692 }
|
|
1693 qu = location / (BIG5_NUM_10_Q + BIG5_NUM_11_Q) + BIG5_HANZI_11_START_Q;
|
|
1694 loc_wei = location % (BIG5_NUM_10_Q + BIG5_NUM_11_Q);
|
|
1695
|
|
1696 if (loc_wei < BIG5_NUM_10_Q)
|
|
1697 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1698 plant = 0xa020;
|
|
1699 wei = loc_wei + BIG5_HANZI_10_START_W;
|
|
1700 }
|
|
1701 else
|
|
1702 {
|
|
1703 plant = 0xa0a0;
|
|
1704 wei = loc_wei - BIG5_NUM_10_Q + 1; /* 1xxxxxxx 1xxxxxxx Case */
|
|
1705 }
|
|
1706 return ((qu << 8) + wei + plant);
|
|
1707 }
|
|
1708 else if (which == BIG5_TO_CNS)
|
|
1709 {
|
|
1710 if (code >= 0xa3cd && code <= 0xa140)
|
|
1711 {
|
|
1712 if (code <= 0xa1bf)
|
|
1713 {
|
|
1714 if (code & 0x80)
|
|
1715 {
|
|
1716 return (0xa1e0 + (code - 0xa1a1));
|
|
1717 }
|
|
1718 else
|
|
1719 {
|
|
1720 return (0xa1a1 + (code - 0xa140));
|
|
1721 }
|
|
1722 }
|
|
1723 else if (code <= 0xa25e)
|
|
1724 {
|
|
1725 if (code & 0x80)
|
|
1726 {
|
|
1727 return (0xa2a1 + (code - 0xa1c0));
|
|
1728 }
|
|
1729 else
|
|
1730 {
|
|
1731 return (0xa2e0 + (code - 0xa240));
|
|
1732 }
|
|
1733 }
|
|
1734 else if (code <= 0xa2ae)
|
|
1735 {
|
|
1736 if (code & 0x80)
|
|
1737 {
|
|
1738 return (0xa3c1 + (code - 0xa2a1));
|
|
1739 }
|
|
1740 else
|
|
1741 {
|
|
1742 return (0xa3a1 + (code - 0xa25f));
|
|
1743 }
|
|
1744 }
|
|
1745 else if (code <= 0xa34e)
|
|
1746 {
|
|
1747 if (code & 0x80)
|
|
1748 {
|
|
1749 return (0xa4a1 + (code - 0xa2af));
|
|
1750 }
|
|
1751 else
|
|
1752 {
|
|
1753 return (0xa4f1 + (code - 0xa340));
|
|
1754 }
|
|
1755 }
|
|
1756 else
|
|
1757 {
|
|
1758 if (code & 0x80)
|
|
1759 {
|
|
1760 return (0xa5d2 + (code - 0xa3a1));
|
|
1761 }
|
|
1762 else
|
|
1763 {
|
|
1764 return (0xa5a1 + (code - 0xa34e));
|
|
1765 }
|
|
1766 }
|
|
1767 }
|
|
1768 if ((code & 0x8080) == 0x8080)
|
|
1769 { /* 1xxxxxxx 1xxxxxxx Case */
|
|
1770 location = (((code >> 8) - 0xa0 - BIG5_HANZI_11_START_Q) * (BIG5_NUM_10_Q + BIG5_NUM_11_Q) + (code & 0xff) - 0xa0 + BIG5_NUM_10_Q - 1);
|
|
1771
|
|
1772 }
|
|
1773 else
|
|
1774 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1775 location = (((code >> 8) - 0xa0 - BIG5_HANZI_10_START_Q) * (BIG5_NUM_10_Q + BIG5_NUM_11_Q) + (code & 0xff) - 0x20 - BIG5_HANZI_10_START_W);
|
|
1776 }
|
|
1777 if (location < BIG5_1NUMS)
|
|
1778 { /* 1xxxxxxx 0xxxxxxx Case */
|
|
1779 plant = 0xa0a0;
|
|
1780 qu = location / BIG5_NUM_11_Q + CNS_HANZI_11_START_Q;
|
|
1781 wei = location % BIG5_NUM_11_Q + CNS_HANZI_11_START_W;
|
|
1782 if ((code >= 0xbbc8 && code < 0xbe52) || (code >= 0xc1ab && code < 0xc2cb) || (code >= 0xc361 && code < 0xc456))
|
|
1783 location++;
|
|
1784 else if (code == 0xbe52)
|
|
1785 return (0xebd0);
|
|
1786 else if (code == 0xc2cb)
|
|
1787 return (0xf5b5);
|
|
1788 else if (code == 0xc456)
|
|
1789 return (0xf8ad);
|
|
1790 }
|
|
1791 else
|
|
1792 { /* 1xxxxxxx 1xxxxxxx Case */
|
|
1793 location -= BIG5_1TO2_SKIP; /* For level two */
|
|
1794 if (code >= 0xeb5b && code < BIG5_CYIB)
|
|
1795 location++;
|
|
1796 else if ((code > BIG5_MU && code <= 0xc96b) ||
|
|
1797 (code > BIG5_ONLN && code <= 0xc9ec) ||
|
|
1798 (code > BIG5_MSOK && code < BIG5_TNKM) ||
|
|
1799 (code >= 0xdba7 && code < BIG5_GRHNE) ||
|
|
1800 (code >= 0xe8a3 && code <= 0xe975) ||
|
|
1801 (code > BIG5_HOOMA && code <= 0xeda9) ||
|
|
1802 (code > BIG5_COLH && code < BIG5_MDMR) || (code >= 0xf466 && code < BIG5_HBBM) || (code >= 0xf4fd && code < BIG5_CJTC) || (code >= 0xf977 && code < BIG5_LNNXU))
|
|
1803 location--;
|
|
1804 else if ((code > BIG5_TNKM && code <= 0xdba6) ||
|
|
1805 (code > BIG5_GRHNE && code <= 0xe8a2) ||
|
|
1806 (code > BIG5_MDMR && code < BIG5_YIHXO) ||
|
|
1807 (code >= 0xf163 && code < BIG5_ODC) ||
|
|
1808 (code >= 0xf375 && code <= 0xf465) || (code > BIG5_HBBM && code <= 0xf4fc) || (code > BIG5_CJTC && code <= 0xf976) || (code == 0xf9c5) || (code >= 0xf9d2 && code <= BIG5_YPYBP))
|
|
1809 location -= 2;
|
|
1810 else if ((code > BIG5_YIHXO && code <= 0xf162) || (code > BIG5_ODC && code < BIG5_OKHAE) || (code >= 0xf2c3 && code <= 0xf374) || (code > BIG5_FDDH && code <= 0xf9d1))
|
|
1811 location -= 3;
|
|
1812 else if (code > BIG5_OKHAE && code <= 0xf2c2)
|
|
1813 location -= 4;
|
|
1814 else if (code == BIG5_ONLN)
|
|
1815 return (CNS_ONLN);
|
|
1816 else if (code == BIG5_MSOK)
|
|
1817 return (CNS_MSOK);
|
|
1818 else if (code == BIG5_TNKM)
|
|
1819 return (CNS_TNKM);
|
|
1820 else if (code == BIG5_CYIB)
|
|
1821 return (CNS_CYIB);
|
|
1822 else if (code == BIG5_YIHXO)
|
|
1823 return (CNS_YIHXO);
|
|
1824 else if (code == BIG5_MDMR)
|
|
1825 return (CNS_MDMR);
|
|
1826 else if (code == BIG5_COLH)
|
|
1827 return (CNS_COLH);
|
|
1828 else if (code == BIG5_ODC)
|
|
1829 return (CNS_ODC);
|
|
1830 else if (code == BIG5_OKHAE)
|
|
1831 return (CNS_OKHAE);
|
|
1832 else if (code == BIG5_HBBM)
|
|
1833 return (CNS_HBBM);
|
|
1834 else if (code == BIG5_CJTC)
|
|
1835 return (CNS_CJTC);
|
|
1836 else if (code == BIG5_LNNXU)
|
|
1837 return (CNS_LNNXU);
|
|
1838 else if (code == BIG5_FDDH)
|
|
1839 return (CNS_FDDH);
|
|
1840 else if (code == BIG5_YPYBP)
|
|
1841 return (CNS_YPYBP);
|
|
1842 else if (code == BIG5_HOOMA)
|
|
1843 return (CNS_HOOMA);
|
|
1844 else if (code == BIG5_MU)
|
|
1845 return (CNS_SPACE);
|
|
1846 else if (code == BIG5_GRHNE)
|
|
1847 return (CNS_SPACE);
|
|
1848
|
|
1849 plant = 0xa020;
|
|
1850 qu = location / BIG5_NUM_11_Q + CNS_HANZI_10_START_Q;
|
|
1851 wei = location % BIG5_NUM_11_Q + CNS_HANZI_10_START_W;
|
|
1852 }
|
|
1853 return ((qu << 8) + wei + plant);
|
|
1854 }
|
|
1855 return (0);
|
|
1856 }
|
|
1857
|
|
1858 #ifdef ECNS_IS_UCNS
|
|
1859 int
|
|
1860 ecns_to_icns (icns, ucns, siz)
|
|
1861 w_char *icns;
|
|
1862 unsigned char *ucns;
|
|
1863 int siz;
|
|
1864 {
|
|
1865 register w_char *i = icns;
|
|
1866 register unsigned char *u = ucns, *uend = ucns + siz, x;
|
|
1867 static w_char local_pending = (w_char) 0;
|
|
1868 static unsigned char shift_mode = '\0';
|
|
1869
|
|
1870 if (siz <= 0)
|
|
1871 return (0);
|
|
1872 if (local_pending)
|
|
1873 {
|
|
1874 *i = local_pending | (*u++ & 0x7f);
|
|
1875 if (shift_mode == SS3)
|
|
1876 {
|
|
1877 *i++ |= 0x8000;
|
|
1878 shift_mode = '\0';
|
|
1879 }
|
|
1880 else
|
|
1881 {
|
|
1882 *i++ |= 0x8080;
|
|
1883 }
|
|
1884 local_pending = (w_char) 0;
|
|
1885 }
|
|
1886 if (shift_mode == SS2)
|
|
1887 {
|
|
1888 *i++ = *u++;
|
|
1889 shift_mode = '\0';
|
|
1890 }
|
|
1891 for (; u < uend;)
|
|
1892 {
|
|
1893 x = *u++;
|
|
1894 if (x == SS2)
|
|
1895 {
|
|
1896 if (u == uend)
|
|
1897 {
|
|
1898 shift_mode = SS2;
|
|
1899 break;
|
|
1900 }
|
|
1901 *i++ = *u++;
|
|
1902 break;
|
|
1903 }
|
|
1904 else if (x == SS3)
|
|
1905 {
|
|
1906 if (u == uend)
|
|
1907 {
|
|
1908 shift_mode = SS3;
|
|
1909 break;
|
|
1910 }
|
|
1911 *i = ((*u++ & 0x7f) << 8);
|
|
1912 if (u == uend)
|
|
1913 {
|
|
1914 local_pending = *i;
|
|
1915 break;
|
|
1916 }
|
|
1917 *i |= (*u++ & 0x7f);
|
|
1918 *i++ |= 0x8000;
|
|
1919 }
|
|
1920 else if (x > 0x7f)
|
|
1921 {
|
|
1922 *i = ((x & 0x7f) << 8);
|
|
1923 if (u == uend)
|
|
1924 {
|
|
1925 local_pending = *i;
|
|
1926 break;
|
|
1927 }
|
|
1928 *i |= (*u++ & 0x7f);
|
|
1929 *i++ |= 0x8080;
|
|
1930 }
|
|
1931 else
|
|
1932 {
|
|
1933 *i++ = x;
|
|
1934 }
|
|
1935 }
|
|
1936 return ((char *) i - (char *) icns);
|
|
1937 }
|
|
1938
|
|
1939 int
|
|
1940 icns_to_ecns (ucns, icns, siz)
|
|
1941 unsigned char *ucns;
|
|
1942 w_char *icns;
|
|
1943 int siz;
|
|
1944 {
|
|
1945 register unsigned char *u = ucns;
|
|
1946 register w_char *i = icns, w;
|
|
1947
|
|
1948 for (; siz > 0; siz -= sizeof (w_char))
|
|
1949 {
|
|
1950 w = *i++;
|
|
1951 if (!(w & 0xff80))
|
|
1952 { /* CS0 */
|
|
1953 *u++ = (unsigned char) w;
|
|
1954 }
|
|
1955 else if (!(w & 0xff00))
|
|
1956 { /* CS2 */
|
|
1957 *u++ = SS2;
|
|
1958 *u++ = (unsigned char) w;
|
|
1959 }
|
|
1960 else if (w & 0x80)
|
|
1961 { /* CS1 */
|
|
1962 *u++ = (unsigned char) ((w & 0xff00) >> 8);
|
|
1963 *u++ = (unsigned char) (w & 0xff);
|
|
1964 }
|
|
1965 else
|
|
1966 { /* CS3 */
|
|
1967 *u++ = SS3;
|
|
1968 *u++ = (unsigned char) ((w & 0xff00) >> 8);
|
|
1969 *u++ = (unsigned char) ((w & 0xff) | 0x80);
|
|
1970 }
|
|
1971 }
|
|
1972 return (u - ucns);
|
|
1973 }
|
|
1974 #else /* ECNS_IS_UCNS */
|
|
1975
|
|
1976 static int oc_mode = ASCII;
|
|
1977 static unsigned char *cns;
|
|
1978
|
|
1979 static void
|
|
1980 putcns (x)
|
|
1981 unsigned char x;
|
|
1982 {
|
|
1983 *cns++ = x;
|
|
1984 }
|
|
1985
|
|
1986 static void
|
|
1987 cns_change_mode (mode, new_mode)
|
|
1988 int *mode;
|
|
1989 int new_mode;
|
|
1990 {
|
|
1991 if (*mode == new_mode)
|
|
1992 return;
|
|
1993 switch (*mode = new_mode)
|
|
1994 {
|
|
1995 case CNS11643_1:
|
|
1996 putcns ('\033');
|
|
1997 putcns ('$');
|
|
1998 putcns (')');
|
|
1999 putcns ('0');
|
|
2000 break;
|
|
2001 case CNS11643_2:
|
|
2002 putcns ('\033');
|
|
2003 putcns ('$');
|
|
2004 putcns ('*');
|
|
2005 putcns ('1');
|
|
2006 break;
|
|
2007 case ASCII:
|
|
2008 /* designate ISO-8859-1 rather than JIS X 0201 */
|
|
2009 /* putcns('\033'); putcns('('); putcns('J'); break; */
|
|
2010 putcns ('\033');
|
|
2011 putcns ('(');
|
|
2012 putcns ('B');
|
|
2013 break;
|
|
2014 }
|
|
2015 }
|
|
2016
|
|
2017 int
|
|
2018 ecns_to_icns (icns, ecns, siz)
|
|
2019 w_char *icns;
|
|
2020 unsigned char *ecns;
|
|
2021 int siz;
|
|
2022 {
|
|
2023 designate = CNS_designate;
|
|
2024 return (extc_to_intc (icns, ecns, siz));
|
|
2025 }
|
|
2026
|
|
2027 int
|
|
2028 icns_to_ecns (ecns, icns, siz)
|
|
2029 unsigned char *ecns;
|
|
2030 w_char *icns;
|
|
2031 int siz;
|
|
2032 {
|
|
2033 register int i = siz;
|
|
2034 register w_char *ic, x;
|
|
2035 cns = ecns;
|
|
2036
|
|
2037 for (; i > 0; i -= sizeof (w_char))
|
|
2038 {
|
|
2039 x = *ic++;
|
|
2040 if ((x & 0x8080) == 0x8080)
|
|
2041 {
|
|
2042 cns_change_mode (&oc_mode, CNS11643_1);
|
|
2043 putcns ((x >> 8) & 0xff);
|
|
2044 putcns (x & 0xff);
|
|
2045 }
|
|
2046 else if ((x & 0x8000) == 0x8000)
|
|
2047 {
|
|
2048 cns_change_mode (&oc_mode, CNS11643_2);
|
|
2049 putcns (((x >> 8) & 0x7f) | 0x80);
|
|
2050 putcns ((x & 0x7f) | 0x80);
|
|
2051 }
|
|
2052 else
|
|
2053 {
|
|
2054 cns_change_mode (&oc_mode, ASCII);
|
|
2055 putcns (x & 0x7f);
|
|
2056 }
|
|
2057 }
|
|
2058 cns_change_mode (&oc_mode, ASCII);
|
|
2059 return (cns - ecns);
|
|
2060 }
|
|
2061 #endif /* ECNS_IS_UCNS */
|
|
2062
|
|
2063 int
|
|
2064 icns_to_big5 (big5, icns, siz)
|
|
2065 unsigned char *big5;
|
|
2066 w_char *icns;
|
|
2067 int siz;
|
|
2068 {
|
|
2069 register unsigned char *d = big5;
|
|
2070 register w_char *s = icns;
|
|
2071 register int i = siz;
|
|
2072 short code_out; /* Buffering one two-byte code */
|
|
2073
|
|
2074 if (d == NULL || s == NULL)
|
|
2075 return (-1);
|
|
2076
|
|
2077 for (; i > 0; i -= sizeof (w_char))
|
|
2078 {
|
|
2079 if (!(*s & 0xff00))
|
|
2080 { /* Ascii */
|
|
2081 if (!(*s & 0x80))
|
|
2082 {
|
|
2083 *d++ = (unsigned char) (*s++ & 0x7f);
|
|
2084 }
|
|
2085 else
|
|
2086 { /* Single Shift */
|
|
2087 *d++ = SS2;
|
|
2088 *d++ = (unsigned char) (*s++ & 0xff);
|
|
2089 }
|
|
2090 }
|
|
2091 else if (_is_hanzi (*s, CNS_TO_BIG5))
|
|
2092 {
|
|
2093 code_out = _convert (*s++, CNS_TO_BIG5);
|
|
2094 *d++ = (code_out >> 8);
|
|
2095 *d++ = code_out & 0x00ff;
|
|
2096 }
|
|
2097 else
|
|
2098 { /* Strainge codes */
|
|
2099 *d++ = (unsigned char) ((*s & 0xff00) >> 8);
|
|
2100 *d++ = (unsigned char) (*s++ & 0xff);
|
|
2101 }
|
|
2102 }
|
|
2103 *d = '\0';
|
|
2104 return (d - big5);
|
|
2105 }
|
|
2106
|
|
2107 int
|
|
2108 ecns_to_big5 (big5, ecns, siz)
|
|
2109 unsigned char *big5, *ecns;
|
|
2110 int siz;
|
|
2111 {
|
|
2112 int len;
|
|
2113 len = ecns_to_icns (tmp_w_buf, ecns, siz);
|
|
2114 return (icns_to_big5 (big5, tmp_w_buf, len));
|
|
2115 }
|
|
2116
|
|
2117 int
|
|
2118 big5_to_icns (icns, big5, siz)
|
|
2119 w_char *icns;
|
|
2120 unsigned char *big5;
|
|
2121 int siz;
|
|
2122 {
|
|
2123 register w_char *d = icns;
|
|
2124 register unsigned char *s = big5;
|
|
2125 unsigned char *send = s + siz;
|
|
2126 unsigned short code_in; /* Buffering one two-byte code */
|
|
2127
|
|
2128 if (d == NULL || s == NULL)
|
|
2129 return (-1);
|
|
2130
|
|
2131 for (; s < send; s++)
|
|
2132 {
|
|
2133 if (!(*s & 0x80))
|
|
2134 { /* Ascii */
|
|
2135 *d++ = (w_char) * s;
|
|
2136 }
|
|
2137 else if (*s == 0x8e)
|
|
2138 { /* Single Shift */
|
|
2139 *d++ = (w_char) * (++s);
|
|
2140 }
|
|
2141 else
|
|
2142 {
|
|
2143 code_in = ((*s++) << 8);
|
|
2144 code_in |= *s;
|
|
2145 if (_is_hanzi (code_in, BIG5_TO_CNS))
|
|
2146 {
|
|
2147 *d++ = _convert (code_in, BIG5_TO_CNS);
|
|
2148 }
|
|
2149 else
|
|
2150 { /* Strainge codes */
|
|
2151 *d++ = code_in;
|
|
2152 }
|
|
2153 }
|
|
2154 }
|
|
2155 *d = (w_char) 0;
|
|
2156 return ((char *) d - (char *) icns);
|
|
2157 }
|
|
2158
|
|
2159 int
|
|
2160 big5_to_ecns (ecns, big5, siz)
|
|
2161 unsigned char *ecns, *big5;
|
|
2162 int siz;
|
|
2163 {
|
|
2164 int len;
|
|
2165 len = big5_to_icns (tmp_w_buf, big5, siz);
|
|
2166 return (icns_to_ecns (ecns, tmp_w_buf, len));
|
|
2167 }
|
|
2168
|
|
2169 int
|
|
2170 iugb_to_eugb (eugb, iugb, siz)
|
|
2171 unsigned char *eugb;
|
|
2172 w_char *iugb;
|
|
2173 int siz;
|
|
2174 {
|
|
2175 static int first = 0;
|
|
2176 static unsigned int cswidth_id;
|
|
2177
|
|
2178 if (first == 0)
|
|
2179 {
|
|
2180 cswidth_id = create_cswidth (UGB_CSWIDTH);
|
|
2181 first++;
|
|
2182 }
|
|
2183 set_cswidth (cswidth_id);
|
|
2184 return (ieuc_to_eeuc (eugb, iugb, siz));
|
|
2185 }
|
|
2186
|
|
2187 int
|
|
2188 eugb_to_iugb (iugb, eugb, siz)
|
|
2189 w_char *iugb;
|
|
2190 unsigned char *eugb;
|
|
2191 int siz;
|
|
2192 {
|
|
2193 static int first = 0;
|
|
2194 static unsigned int cswidth_id;
|
|
2195
|
|
2196 if (first == 0)
|
|
2197 {
|
|
2198 cswidth_id = create_cswidth (UGB_CSWIDTH);
|
|
2199 first++;
|
|
2200 }
|
|
2201 set_cswidth (cswidth_id);
|
|
2202 return (eeuc_to_ieuc (iugb, eugb, siz));
|
|
2203 }
|
|
2204 #endif /* CHINESE */
|
|
2205
|
|
2206
|
|
2207 #ifdef KOREAN
|
|
2208
|
|
2209 #define ZENKAKU_KSC 1
|
|
2210
|
|
2211 static unsigned char *ks;
|
|
2212 static w_char *iuk;
|
|
2213 static unsigned char *euk;
|
|
2214
|
|
2215 static void
|
|
2216 putks (x)
|
|
2217 int x;
|
|
2218 {
|
|
2219 *ks++ = x;
|
|
2220 }
|
|
2221
|
|
2222 static int oks_mode = ASCII; /* 出力時のKSCコードのモード */
|
|
2223 extern int euksc_to_iuksc ();
|
|
2224
|
|
2225 static void
|
|
2226 ksc_change_mode (mode, new_mode)
|
|
2227 int *mode;
|
|
2228 int new_mode;
|
|
2229 {
|
|
2230 if (*mode == new_mode)
|
|
2231 return;
|
|
2232 switch (*mode)
|
|
2233 {
|
|
2234 case ZENKAKU_KSC:
|
|
2235 putks ('\033');
|
|
2236 putks ('(');
|
|
2237 putks ('B');
|
|
2238 break;
|
|
2239 default:;
|
|
2240 }
|
|
2241 *mode = new_mode;
|
|
2242 switch (new_mode)
|
|
2243 {
|
|
2244 case ZENKAKU_KSC:
|
|
2245 putks ('\033');
|
|
2246 putks ('$');
|
|
2247 putks ('(');
|
|
2248 putks ('C');
|
|
2249 break;
|
|
2250 default:;
|
|
2251 }
|
|
2252 }
|
|
2253
|
|
2254 /* 内部 U-ksc を ksc コードに変換します
|
|
2255 文字列の長さを返します */
|
|
2256 extern int
|
|
2257 iuksc_to_ksc (ksc, iuksc, iusiz)
|
|
2258 unsigned char *ksc; /* kscコードになったものをおくbuf */
|
|
2259 w_char *iuksc; /* iukscコードのものをおいてくるbuf */
|
|
2260 int iusiz; /* iuksc の大きさ */
|
|
2261 {
|
|
2262 int x;
|
|
2263 ks = ksc;
|
|
2264 iuk = iuksc;
|
|
2265 for (; iusiz > 0; iusiz -= sizeof (w_char))
|
|
2266 {
|
|
2267 x = *iuk++;
|
|
2268 if ((x & 0x8080) == 0x8080)
|
|
2269 {
|
|
2270 ksc_change_mode (&oks_mode, ZENKAKU_KSC);
|
|
2271 putks ((x >> 8) & 0x7f);
|
|
2272 putks (x & 0x7f);
|
|
2273 }
|
|
2274 else
|
|
2275 {
|
|
2276 ksc_change_mode (&oks_mode, ASCII);
|
|
2277 putks (x);
|
|
2278 }
|
|
2279 }
|
|
2280 ksc_change_mode (&oks_mode, ASCII);
|
|
2281 return (ks - ksc);
|
|
2282 }
|
|
2283
|
|
2284
|
|
2285 /* 外部 U-ksc を ksc コードに変換します */
|
|
2286 extern int
|
|
2287 euksc_to_ksc (ksc, euksc, eusiz)
|
|
2288 unsigned char *ksc, *euksc;
|
|
2289 int eusiz;
|
|
2290 {
|
|
2291 static int kanji1 = 0;
|
|
2292 static unsigned char kanji1_code = 0;
|
|
2293 /* 0: normal
|
|
2294 1: get SS2
|
|
2295 2: get kanji 1 byte */
|
|
2296 int x;
|
|
2297 ks = ksc;
|
|
2298 euk = euksc;
|
|
2299 if (kanji1 != 0)
|
|
2300 {
|
|
2301 if (kanji1 == 2)
|
|
2302 {
|
|
2303 putks (kanji1_code & 0x7f);
|
|
2304 putks (*euk & 0x7f);
|
|
2305 }
|
|
2306 else
|
|
2307 {
|
|
2308 putks (*euk);
|
|
2309 }
|
|
2310 eusiz -= sizeof (char);
|
|
2311 kanji1 = 0;
|
|
2312 euk++;
|
|
2313 }
|
|
2314 for (; eusiz > 0; eusiz -= sizeof (char))
|
|
2315 {
|
|
2316 x = *euk++;
|
|
2317 if (x & 0x80)
|
|
2318 {
|
|
2319 ksc_change_mode (&oks_mode, ZENKAKU_KSC);
|
|
2320 if (eusiz > 1)
|
|
2321 {
|
|
2322 putks (x & 0x7f);
|
|
2323 putks (*euk++ & 0x7f);
|
|
2324 eusiz -= sizeof (char);
|
|
2325 }
|
|
2326 else
|
|
2327 {
|
|
2328 kanji1 = 2;
|
|
2329 kanji1_code = x;
|
|
2330 }
|
|
2331 }
|
|
2332 else
|
|
2333 {
|
|
2334 ksc_change_mode (&oks_mode, ASCII);
|
|
2335 putks (x);
|
|
2336 }
|
|
2337 }
|
|
2338 if (kanji1 == 0)
|
|
2339 ksc_change_mode (&oks_mode, ASCII);
|
|
2340 return (ks - ksc);
|
|
2341 }
|
|
2342
|
|
2343 /* 内部 U-ksc を 外部 U-ksc コードに変換します */
|
|
2344 extern int
|
|
2345 iuksc_to_euksc (euksc, iuksc, iusiz)
|
|
2346 unsigned char *euksc;
|
|
2347 w_char *iuksc;
|
|
2348 int iusiz;
|
|
2349 {
|
|
2350 static int first = 0;
|
|
2351 static unsigned int cswidth_id;
|
|
2352
|
|
2353 if (first == 0)
|
|
2354 {
|
|
2355 cswidth_id = create_cswidth (UKSC_CSWIDTH);
|
|
2356 first++;
|
|
2357 }
|
|
2358 set_cswidth (cswidth_id);
|
|
2359 return (ieuc_to_eeuc (euksc, iuksc, iusiz));
|
|
2360 }
|
|
2361
|
|
2362 int
|
|
2363 ksc_to_euksc (euksc, ksc, jsiz)
|
|
2364 unsigned char *euksc, *ksc;
|
|
2365 int jsiz;
|
|
2366 {
|
|
2367 int len;
|
|
2368
|
|
2369 designate = KSC_designate;
|
|
2370 len = extc_to_intc (tmp_w_buf, ksc, jsiz);
|
|
2371 return (iuksc_to_euksc (euksc, tmp_w_buf, len));
|
|
2372 }
|
|
2373
|
|
2374 int
|
|
2375 ksc_to_iuksc (iuksc, ksc, jsiz)
|
|
2376 w_char *iuksc;
|
|
2377 unsigned char *ksc;
|
|
2378 int jsiz;
|
|
2379 {
|
|
2380 designate = KSC_designate;
|
|
2381 return (extc_to_intc (iuksc, ksc, jsiz));
|
|
2382 }
|
|
2383
|
|
2384 int
|
|
2385 euksc_to_iuksc (iuksc, euksc, eusiz)
|
|
2386 w_char *iuksc;
|
|
2387 unsigned char *euksc;
|
|
2388 int eusiz;
|
|
2389 {
|
|
2390 static int first = 0;
|
|
2391 static unsigned int cswidth_id;
|
|
2392
|
|
2393 if (first == 0)
|
|
2394 {
|
|
2395 cswidth_id = create_cswidth (UKSC_CSWIDTH);
|
|
2396 first++;
|
|
2397 }
|
|
2398 set_cswidth (cswidth_id);
|
|
2399 return (eeuc_to_ieuc (iuksc, euksc, eusiz));
|
|
2400 }
|
|
2401
|
|
2402 #endif /* KOREAN */
|