comparison modules/canna/canna_api.c @ 3071:a80f978d8342

[xemacs-hg @ 2005-11-16 07:14:13 by stephent] Mule-ize Canna: <87mzk5yu35.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Wed, 16 Nov 2005 07:14:16 +0000
parents bd7174adf0f2
children e58f4b9ab1ad
comparison
equal deleted inserted replaced
3070:e409aa086a15 3071:a80f978d8342
1 /* CANNA interface -*- coding: euc-jp -*- 1 /* CANNA interface -*- coding: euc-jp -*-
2 2
3 Copyright (C) 1995 Free Software Foundation, Inc. 3 Copyright (C) 1995 Free Software Foundation, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 2005 Ben Wing.
5 6
6 This file is part of XEmacs. 7 This file is part of XEmacs.
7 8
8 XEmacs is free software; you can redistribute it and/or modify it 9 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
173 174
174 extern int (*jrBeepFunc) (void); 175 extern int (*jrBeepFunc) (void);
175 176
176 /* #### is this global really necessary? */ 177 /* #### is this global really necessary? */
177 #define KEYTOSTRSIZE 2048 178 #define KEYTOSTRSIZE 2048
178 static char key_buffer[KEYTOSTRSIZE]; 179 static Extbyte key_buffer[KEYTOSTRSIZE];
179 static char **warning;
180 180
181 static int canna_empty_info, canna_through_info; 181 static int canna_empty_info, canna_through_info;
182 static int canna_underline; 182 static int canna_underline;
183 static int canna_inhibit_hankakukana; 183 static int canna_inhibit_hankakukana;
184 184
198 static int IRCP_context; 198 static int IRCP_context;
199 199
200 static Lisp_Object storeResults (char *, int, jrKanjiStatus *); 200 static Lisp_Object storeResults (char *, int, jrKanjiStatus *);
201 static Lisp_Object kanjiYomiList (int, int); 201 static Lisp_Object kanjiYomiList (int, int);
202 static Lisp_Object CANNA_mode_keys (void); 202 static Lisp_Object CANNA_mode_keys (void);
203 static Lisp_Object Qeuc_jp;
204
205 #define make_euc_string(p, len) make_ext_string ((Extbyte *) p, len, Qeuc_jp)
206 #define build_euc_string(p) build_ext_string ((Extbyte *) p, Qeuc_jp)
203 207
204 #ifdef CANNA_MULE 208 #ifdef CANNA_MULE
205 static void m2c (unsigned char *, int, unsigned char *); 209 static int euc_jp_num_chars (unsigned char *, int);
206 static Lisp_Object mule_make_string (unsigned char *, int); 210 static void count_char (unsigned char *,int, int, int, Fixnum *, Fixnum *,
207 static int mule_strlen (unsigned char *, int); 211 Fixnum *);
208 static void count_char (unsigned char *,int, int, int, Fixnum *, Fixnum *, Fixnum *);
209 #define make_string mule_make_string
210 #endif 212 #endif
211 213
212 /* Lisp functions definition */ 214 /* Lisp functions definition */
213 215
214 DEFUN ("canna-key-proc", Fcanna_key_proc, 1, 1, 0, /* 216 DEFUN ("canna-key-proc", Fcanna_key_proc, 1, 1, 0, /*
232 { 234 {
233 Lisp_Object val = Qnil; 235 Lisp_Object val = Qnil;
234 236
235 if (len < 0) 237 if (len < 0)
236 { /* Error detected */ 238 { /* Error detected */
237 val = make_string ((unsigned char*) jrKanjiError, strlen (jrKanjiError)); 239 val = build_euc_string (jrKanjiError);
238 } 240 }
239 else 241 else
240 { 242 {
241 /* 確定した文字列 (the confirmed string) */ 243 /* 確定した文字列 (the confirmed string) */
242 Vcanna_kakutei_string = make_string ((unsigned char *) buf, len); 244 Vcanna_kakutei_string = make_euc_string (buf, len);
243 val = make_int (len); 245 val = make_int (len);
244 /* 確定した文字列の読みの情報... 246 /* 確定した文字列の読みの情報...
245 (info about the reading of the confirmed string) */ 247 (info about the reading of the confirmed string) */
246 Vcanna_kakutei_yomi = Vcanna_kakutei_romaji = Qnil; 248 Vcanna_kakutei_yomi = Vcanna_kakutei_romaji = Qnil;
247 if (ks->info & KanjiYomiInfo) 249 if (ks->info & KanjiYomiInfo)
252 if (len + yomilen + 1 < KEYTOSTRSIZE) 254 if (len + yomilen + 1 < KEYTOSTRSIZE)
253 { 255 {
254 int yomilen2; 256 int yomilen2;
255 257
256 Vcanna_kakutei_yomi = 258 Vcanna_kakutei_yomi =
257 make_string ((unsigned char *) p, yomilen); /* 読み (reading) */ 259 make_euc_string (p, yomilen); /* 読み (reading) */
258 p += yomilen + 1; 260 p += yomilen + 1;
259 yomilen2 = strlen (p); 261 yomilen2 = strlen (p);
260 if (len + yomilen + yomilen2 + 2 < KEYTOSTRSIZE) 262 if (len + yomilen + yomilen2 + 2 < KEYTOSTRSIZE)
261 { 263 {
262 Vcanna_kakutei_romaji = 264 Vcanna_kakutei_romaji =
263 make_string ((unsigned char *) p, yomilen2); 265 make_euc_string (p, yomilen2);
264 /* ローマ字 (romanization) */ 266 /* ローマ字 (romanization) */
265 } 267 }
266 } 268 }
267 } 269 }
268 270
270 /* 候補表示の文字列です。 272 /* 候補表示の文字列です。
271 (string for displaying candidate translations) */ 273 (string for displaying candidate translations) */
272 Vcanna_henkan_string = Qnil; 274 Vcanna_henkan_string = Qnil;
273 if (ks->length >= 0) 275 if (ks->length >= 0)
274 { 276 {
275 Vcanna_henkan_string = make_string (ks->echoStr, ks->length); 277 Vcanna_henkan_string = make_euc_string (ks->echoStr, ks->length);
276 #ifndef CANNA_MULE 278 #ifndef CANNA_MULE
277 canna_henkan_length = ks->length; 279 canna_henkan_length = ks->length;
278 canna_henkan_revPos = ks->revPos; 280 canna_henkan_revPos = ks->revPos;
279 canna_henkan_revLen = ks->revLen; 281 canna_henkan_revLen = ks->revLen;
280 #else /* CANNA_MULE */ 282 #else /* CANNA_MULE */
281 if (canna_underline) 283 if (canna_underline)
282 { 284 {
283 canna_henkan_length = mule_strlen (ks->echoStr,ks->length); 285 canna_henkan_length = euc_jp_num_chars (ks->echoStr,ks->length);
284 canna_henkan_revPos = mule_strlen (ks->echoStr,ks->revPos); 286 canna_henkan_revPos = euc_jp_num_chars (ks->echoStr,ks->revPos);
285 canna_henkan_revLen = mule_strlen (ks->echoStr+ks->revPos, 287 canna_henkan_revLen = euc_jp_num_chars (ks->echoStr+ks->revPos,
286 ks->revLen); 288 ks->revLen);
287 } 289 }
288 else 290 else
289 { 291 {
290 count_char (ks->echoStr, ks->length, ks->revPos, ks->revLen, 292 count_char (ks->echoStr, ks->length, ks->revPos, ks->revLen,
291 &canna_henkan_length, &canna_henkan_revPos, 293 &canna_henkan_length, &canna_henkan_revPos,
296 298
297 /* 一覧の情報 (information about the echo area menu) */ 299 /* 一覧の情報 (information about the echo area menu) */
298 Vcanna_ichiran_string = Qnil; 300 Vcanna_ichiran_string = Qnil;
299 if (ks->info & KanjiGLineInfo && ks->gline.length >= 0) 301 if (ks->info & KanjiGLineInfo && ks->gline.length >= 0)
300 { 302 {
301 Vcanna_ichiran_string = make_string (ks->gline.line, 303 Vcanna_ichiran_string = make_euc_string (ks->gline.line,
302 ks->gline.length); 304 ks->gline.length);
303 #ifndef CANNA_MULE 305 #ifndef CANNA_MULE
304 canna_ichiran_length = ks->gline.length; 306 canna_ichiran_length = ks->gline.length;
305 canna_ichiran_revPos = ks->gline.revPos; 307 canna_ichiran_revPos = ks->gline.revPos;
306 canna_ichiran_revLen = ks->gline.revLen; 308 canna_ichiran_revLen = ks->gline.revLen;
307 #else /* CANNA_MULE */ 309 #else /* CANNA_MULE */
314 316
315 /* モードの情報 (mode information) */ 317 /* モードの情報 (mode information) */
316 Vcanna_mode_string = Qnil; 318 Vcanna_mode_string = Qnil;
317 if (ks->info & KanjiModeInfo) 319 if (ks->info & KanjiModeInfo)
318 { 320 {
319 Vcanna_mode_string = 321 Vcanna_mode_string = build_euc_string ((Extbyte *) ks->mode);
320 make_string (ks->mode, strlen ((const char *) ks->mode));
321 } 322 }
322 323
323 /* その他の情報 (other information) */ 324 /* その他の情報 (other information) */
324 canna_empty_info = (ks->info & KanjiEmptyInfo) ? 1 : 0; 325 canna_empty_info = (ks->info & KanjiEmptyInfo) ? 1 : 0;
325 canna_through_info = (ks->info & KanjiThroughInfo) ? 1 : 0; 326 canna_through_info = (ks->info & KanjiThroughInfo) ? 1 : 0;
363 */ 364 */
364 (num, server, rcfile)) 365 (num, server, rcfile))
365 { 366 {
366 Lisp_Object val; 367 Lisp_Object val;
367 int res; 368 int res;
368 unsigned char **p, **q; 369 char **p, **q;
369 370
370 int kugiri; /* 文節区切りをするか? (display clause separator?) */ 371 int kugiri; /* 文節区切りをするか? (display clause separator?) */
371 372
372 IRCP_context = -1; 373 IRCP_context = -1;
373 374
386 { 387 {
387 jrKanjiControl (0, KC_SETSERVERNAME, (char *) 0); 388 jrKanjiControl (0, KC_SETSERVERNAME, (char *) 0);
388 } 389 }
389 else 390 else
390 { 391 {
391 char servername[256];
392
393 CHECK_STRING (server); 392 CHECK_STRING (server);
394 strncpy (servername, (const char *) XSTRING_DATA (server), 393 jrKanjiControl (0, KC_SETSERVERNAME,
395 XSTRING_LENGTH (server)); 394 /* !!#### Check encoding */
396 servername[XSTRING_LENGTH (server)] = '\0'; 395 NEW_LISP_STRING_TO_EXTERNAL (server, Qnative));
397 jrKanjiControl (0, KC_SETSERVERNAME, servername);
398 } 396 }
399 397
400 if (NILP (rcfile)) 398 if (NILP (rcfile))
401 { 399 {
402 jrKanjiControl (0, KC_SETINITFILENAME, (char *) 0); 400 jrKanjiControl (0, KC_SETINITFILENAME, (char *) 0);
403 } 401 }
404 else 402 else
405 { 403 {
406 char rcname[256];
407
408 CHECK_STRING (rcfile); 404 CHECK_STRING (rcfile);
409 strncpy (rcname, (const char *) XSTRING_DATA (rcfile), 405 jrKanjiControl (0, KC_SETINITFILENAME,
410 XSTRING_LENGTH (rcfile)); 406 NEW_LISP_STRING_TO_EXTERNAL (rcfile, Qfile_name));
411 rcname[XSTRING_LENGTH (rcfile)] = '\0'; 407 }
412 jrKanjiControl (0, KC_SETINITFILENAME, rcname); 408
413 } 409 {
414 410 char **warning = (char **) 0;
415 warning = (char **) 0;
416 #ifdef nec_ews_svr4 411 #ifdef nec_ews_svr4
417 stop_polling (); 412 stop_polling ();
418 #endif /* nec_ews_svr4 */ 413 #endif /* nec_ews_svr4 */
419 res = jrKanjiControl (0, KC_INITIALIZE, (char *)&warning); 414 res = jrKanjiControl (0, KC_INITIALIZE, (char *) &warning);
420 #ifdef nec_ews_svr4 415 #ifdef nec_ews_svr4
421 start_polling (); 416 start_polling ();
422 #endif /* nec_ews_svr4 */ 417 #endif /* nec_ews_svr4 */
423 val = Qnil; 418 val = Qnil;
424 if (warning) 419 if (warning)
425 { 420 {
426 for (p = q = (unsigned char **) warning ; *q ; q++) 421 for (p = q = warning ; *q ; q++)
427 ; 422 ;
428 while (p < q) 423 while (p < q)
429 { 424 {
430 q--; 425 q--;
431 val = Fcons (make_string (*q, strlen ((const char *) *q)), val); 426 val = Fcons (build_euc_string (*q), val);
432 } 427 }
433 } 428 }
434 val = Fcons (val, Qnil); 429 val = Fcons (val, Qnil);
430 }
435 431
436 if (res == -1) 432 if (res == -1)
437 { 433 {
438 val = Fcons (make_string ((unsigned char *) jrKanjiError, 434 val = Fcons (build_euc_string (jrKanjiError), val);
439 strlen (jrKanjiError)), val);
440 /* イニシャライズで失敗した場合。 (on initialization failure) */ 435 /* イニシャライズで失敗した場合。 (on initialization failure) */
441 return Fcons (Qnil, val); 436 return Fcons (Qnil, val);
442 } 437 }
443 else 438 else
444 { 439 {
475 This cause to write miscellaneous informations to kana-to-kanji dictionary. 470 This cause to write miscellaneous informations to kana-to-kanji dictionary.
476 */ 471 */
477 ()) 472 ())
478 { 473 {
479 Lisp_Object val; 474 Lisp_Object val;
480 unsigned char **p; 475 char **p;
481 476 char **warning = (char **) 0;
482 jrKanjiControl (0, KC_FINALIZE, (char *)&warning); 477
478 jrKanjiControl (0, KC_FINALIZE, (char *) &warning);
483 479
484 val = Qnil; 480 val = Qnil;
485 if (warning) 481 if (warning)
486 { 482 {
487 for (p = (unsigned char**) warning ; *p ; p++) 483 for (p = warning ; *p; p++)
488 { 484 {
489 val = Fcons (make_string (*p, strlen ((const char *) *p)), val); 485 /* !!#### This is almost certainly wrong; `canna-initialize
486 starts at the end of the warnings so the resulting list is
487 in the correct order. We should do the same. */
488 val = Fcons (build_euc_string (*p), val);
490 } 489 }
491 } 490 }
492 val = Fcons (val, Qnil); 491 val = Fcons (val, Qnil);
493 IRCP_context = -1; 492 IRCP_context = -1;
494 return val; 493 return val;
499 */ 498 */
500 (str)) 499 (str))
501 { 500 {
502 jrKanjiStatusWithValue ksv; 501 jrKanjiStatusWithValue ksv;
503 jrKanjiStatus ks; 502 jrKanjiStatus ks;
504 #ifdef CANNA_MULE
505 unsigned char cbuf[4096];
506 #endif
507 503
508 CHECK_STRING (str); 504 CHECK_STRING (str);
509 ksv.buffer = (unsigned char *) key_buffer; 505 ksv.buffer = (unsigned char *) key_buffer;
510 ksv.bytes_buffer = KEYTOSTRSIZE; 506 ksv.bytes_buffer = KEYTOSTRSIZE;
511 #ifndef CANNA_MULE 507 LISP_STRING_TO_SIZED_EXTERNAL (str, ks.echoStr, ks.length, Qeuc_jp);
512 ks.echoStr = XSTRING_DATA (str);
513 ks.length = XSTRING_LENGTH (str);
514 #else /* CANNA_MULE */
515 m2c (XSTRING_DATA (str), XSTRING_LENGTH (str), cbuf);
516 ks.echoStr = cbuf;
517 ks.length = strlen ((const char *) cbuf);
518 #endif /* CANNA_MULE */
519 ksv.ks = &ks; 508 ksv.ks = &ks;
520 jrKanjiControl (0, KC_DEFINEKANJI, (char *)&ksv); 509 jrKanjiControl (0, KC_DEFINEKANJI, (char *)&ksv);
521 return storeResults (key_buffer, ksv.val, ksv.ks); 510 return storeResults (key_buffer, ksv.val, ksv.ks);
522 } 511 }
523 512
575 */ 564 */
576 (yomi, roma)) 565 (yomi, roma))
577 { 566 {
578 jrKanjiStatusWithValue ksv; 567 jrKanjiStatusWithValue ksv;
579 jrKanjiStatus ks; 568 jrKanjiStatus ks;
569 Extbyte *ext;
580 570
581 CHECK_STRING (yomi); 571 CHECK_STRING (yomi);
582 #ifndef CANNA_MULE 572 LISP_STRING_TO_EXTERNAL (yomi, ext, Qeuc_jp);
583 strncpy (key_buffer, XSTRING_DATA (yomi), XSTRING_LENGTH (yomi)); 573 strncpy (key_buffer, ext, sizeof (key_buffer));
584 ks.length = XSTRING_LENGTH (yomi); 574 key_buffer[sizeof (key_buffer) - 1] = '\0';
585 key_buffer[ks.length] = '\0';
586 #else /* CANNA_MULE */
587 m2c (XSTRING_DATA (yomi), XSTRING_LENGTH (yomi),
588 (unsigned char *) key_buffer);
589 ks.length = strlen (key_buffer); 575 ks.length = strlen (key_buffer);
590 #endif /* CANNA_MULE */
591 576
592 if (NILP (roma)) 577 if (NILP (roma))
593 { 578 {
594 ks.mode = 0; 579 ks.mode = 0;
595 } 580 }
596 else 581 else
597 { 582 {
598 CHECK_STRING (roma); 583 CHECK_STRING (roma);
599 584 LISP_STRING_TO_EXTERNAL (roma, ext, Qeuc_jp);
600 #ifndef CANNA_MULE 585 ks.mode = (unsigned char *) (key_buffer + ks.length + 1);
601 strncpy (key_buffer + XSTRING_LENGTH (yomi) + 1, XSTRING_DATA (roma), 586 strncpy (key_buffer + ks.length + 1, ext,
602 XSTRING_LENGTH (roma)); 587 sizeof (key_buffer) - ks.length - 1);
603 key_buffer[XSTRING_LENGTH (yomi) + 1 + XSTRING_LENGTH (roma)] = '\0'; 588 key_buffer[sizeof (key_buffer) - 1] = '\0';
604 ks.mode = (unsigned char *)(key_buffer + XSTRING_LENGTH (yomi) + 1);
605 #else /* CANNA_MULE */
606 ks.mode = (unsigned char *)(key_buffer + ks.length + 1);
607 m2c (XSTRING_DATA (roma), XSTRING_LENGTH (roma),
608 (unsigned char *) ks.mode);
609 #endif /* CANNA_MULE */
610 } 589 }
611 590
612 ks.echoStr = (unsigned char *) key_buffer; 591 ks.echoStr = (unsigned char *) key_buffer;
613 ksv.buffer = (unsigned char *) key_buffer; /* 返値用 (return value) */ 592 ksv.buffer = (unsigned char *) key_buffer; /* 返値用 (return value) */
614 ksv.bytes_buffer = KEYTOSTRSIZE; 593 ksv.bytes_buffer = KEYTOSTRSIZE;
651 Parse customize string. 630 Parse customize string.
652 */ 631 */
653 (str)) 632 (str))
654 { 633 {
655 Lisp_Object val; 634 Lisp_Object val;
656 unsigned char **p; 635 Extbyte **p;
657 int n; 636 int n;
637 Extbyte *ext;
658 638
659 CHECK_STRING (str); 639 CHECK_STRING (str);
660 640 LISP_STRING_TO_EXTERNAL (str, ext, Qeuc_jp);
661 #ifndef CANNA_MULE 641 strncpy (key_buffer, ext, sizeof (key_buffer));
662 strncpy (key_buffer, XSTRING_DATA (str), XSTRING_LENGTH (str)); 642 key_buffer[sizeof (key_buffer) - 1] = '\0';
663 key_buffer[XSTRING_LENGTH (str)] = '\0'; 643 p = (Extbyte **) key_buffer;
664 #else /* CANNA_MULE */
665 m2c (XSTRING_DATA (str), XSTRING_LENGTH (str), (unsigned char *) key_buffer);
666 #endif /* CANNA_MULE */
667 p = (unsigned char**) key_buffer;
668 n = jrKanjiControl (0, KC_PARSE, (char *) &p); 644 n = jrKanjiControl (0, KC_PARSE, (char *) &p);
669 val = Qnil; 645 val = Qnil;
670 while (n > 0) 646 while (n > 0)
671 { 647 {
672 n--; 648 n--;
673 val = Fcons (make_string (p[n], strlen ((const char *) p[n])), val); 649 val = Fcons (build_euc_string (p[n]), val);
674 } 650 }
675 return val; 651 return val;
676 } 652 }
677 653
678 DEFUN ("canna-query-mode", Fcanna_query_mode, 0, 0, 0, /* 654 DEFUN ("canna-query-mode", Fcanna_query_mode, 0, 0, 0, /*
681 ()) 657 ())
682 { 658 {
683 char buf[256]; 659 char buf[256];
684 660
685 jrKanjiControl (0, KC_QUERYMODE, buf); 661 jrKanjiControl (0, KC_QUERYMODE, buf);
686 return make_string ((unsigned char *) buf, strlen (buf)); 662 return build_euc_string (buf);
687 } 663 }
688 664
689 /* 665 /*
690 * Functions following this line are for KKCP interface compatible 666 * Functions following this line are for KKCP interface compatible
691 * library. These functions may be used by MILK system. 667 * library. These functions may be used by MILK system.
738 Clause separator is set. 714 Clause separator is set.
739 */ 715 */
740 (yomi)) 716 (yomi))
741 { 717 {
742 int nbun; 718 int nbun;
719 Extbyte *ext;
743 720
744 CHECK_STRING (yomi); 721 CHECK_STRING (yomi);
745 if (confirmContext () == 0) 722 if (confirmContext () == 0)
746 { 723 {
747 return Qnil; 724 return Qnil;
748 } 725 }
749 #ifndef CANNA_MULE 726
750 strncpy (yomibuf, XSTRING_DATA (yomi), XSTRING_LENGTH (yomi)); 727 LISP_STRING_TO_EXTERNAL (yomi, ext, Qeuc_jp);
751 yomibuf[XSTRING_LENGTH (yomi)] = '\0'; 728 strncpy ((char *) yomibuf, ext, sizeof (yomibuf));
752 nbun = RkBgnBun (IRCP_context, XSTRING_DATA (yomi), XSTRING_LENGTH (yomi), 729 yomibuf[sizeof (yomibuf) - 1] = '\0';
730
731 nbun = RkBgnBun (IRCP_context, yomibuf, strlen ((char *) yomibuf),
753 (RK_XFER << RK_XFERBITS) | RK_KFER); 732 (RK_XFER << RK_XFERBITS) | RK_KFER);
754 #else /* CANNA_MULE */
755 m2c (XSTRING_DATA (yomi), XSTRING_LENGTH (yomi), yomibuf);
756 nbun = RkBgnBun (IRCP_context, (char *) yomibuf,
757 strlen ((const char *) yomibuf),
758 (RK_XFER << RK_XFERBITS) | RK_KFER);
759 #endif /* CANNA_MULE */
760 733
761 return kanjiYomiList (IRCP_context, nbun); 734 return kanjiYomiList (IRCP_context, nbun);
762 } 735 }
763 736
764 static Lisp_Object 737 static Lisp_Object
765 kanjiYomiList (int context, int nbun) 738 kanjiYomiList (int context, int nbun)
766 { 739 {
767 Lisp_Object val, res = Qnil; 740 Lisp_Object val, res = Qnil;
768 unsigned char RkBuf[RKBUFSIZE]; 741 UExtbyte RkBuf[RKBUFSIZE];
769 int len, i, total; 742 int len, i, total;
770 743
771 for (i = nbun ; i > 0 ; ) 744 for (i = nbun ; i > 0 ; )
772 { 745 {
773 i--; 746 i--;
774 RkGoTo (context, i); 747 RkGoTo (context, i);
775 len = RkGetKanji (context, RkBuf, RKBUFSIZE); 748 len = RkGetKanji (context, RkBuf, RKBUFSIZE);
776 val = make_string (RkBuf, len); 749 val = make_euc_string (RkBuf, len);
777 len = RkGetYomi (context, RkBuf, RKBUFSIZE); 750 len = RkGetYomi (context, RkBuf, RKBUFSIZE);
778 res = Fcons (Fcons (val, make_string (RkBuf, len)), res); 751 res = Fcons (Fcons (val, make_euc_string (RkBuf, len)), res);
779 if (i < RKBUFSIZE / 2) 752 if (i < RKBUFSIZE / 2)
780 { 753 {
781 kugiri[i] = len; 754 kugiri[i] = len;
782 } 755 }
783 } 756 }
794 Return the list of candidates. 767 Return the list of candidates.
795 */ 768 */
796 (bunsetsu)) 769 (bunsetsu))
797 { 770 {
798 int i, slen, len; 771 int i, slen, len;
799 unsigned char *p, RkBuf[RKBUFSIZE]; 772 UExtbyte *p, RkBuf[RKBUFSIZE];
800 Lisp_Object res = Qnil; 773 Lisp_Object res = Qnil;
801 774
802 CHECK_INT (bunsetsu); 775 CHECK_INT (bunsetsu);
803 if (confirmContext () == 0) 776 if (confirmContext () == 0)
804 { 777 {
807 RkGoTo (IRCP_context, XINT (bunsetsu)); 780 RkGoTo (IRCP_context, XINT (bunsetsu));
808 len = RkGetKanjiList (IRCP_context, RkBuf, RKBUFSIZE); 781 len = RkGetKanjiList (IRCP_context, RkBuf, RKBUFSIZE);
809 p = RkBuf; 782 p = RkBuf;
810 for (i = 0 ; i < len ; i++) 783 for (i = 0 ; i < len ; i++)
811 { 784 {
812 slen = strlen ((const char *) p); 785 slen = strlen ((char *) p);
813 if (NILP(res)) 786 if (NILP(res))
814 { 787 {
815 res = Fcons (make_string (p, slen), Qnil); 788 res = Fcons (make_euc_string (p, slen), Qnil);
816 } 789 }
817 else 790 else
818 { 791 {
819 XCDR (res) = Fcons (make_string (p, slen), Qnil); 792 XCDR (res) = Fcons (make_euc_string (p, slen), Qnil);
820 } 793 }
821 p += slen + 1; 794 p += slen + 1;
822 } 795 }
823 return res; 796 return res;
824 } 797 }
1102 DEFSUBR (Fcanna_henkan_next); 1075 DEFSUBR (Fcanna_henkan_next);
1103 DEFSUBR (Fcanna_bunsetu_henkou); 1076 DEFSUBR (Fcanna_bunsetu_henkou);
1104 DEFSUBR (Fcanna_henkan_kakutei); 1077 DEFSUBR (Fcanna_henkan_kakutei);
1105 DEFSUBR (Fcanna_henkan_end); 1078 DEFSUBR (Fcanna_henkan_end);
1106 DEFSUBR (Fcanna_henkan_quit); 1079 DEFSUBR (Fcanna_henkan_quit);
1080
1081 DEFSYMBOL (Qeuc_jp);
1107 } 1082 }
1108 1083
1109 void 1084 void
1110 vars_of_canna_api (void) 1085 vars_of_canna_api (void)
1111 { 1086 {
1848 } 1823 }
1849 #endif 1824 #endif
1850 #endif 1825 #endif
1851 1826
1852 #ifdef CANNA_MULE 1827 #ifdef CANNA_MULE
1853 /* To handle MULE internal code and EUC. 1828
1854 I assume CANNA can handle only Japanese EUC. */ 1829 /* Return the number of characters in an EUC-JP string. */
1855
1856 /* EUC multibyte string to MULE internal string */
1857
1858 static void
1859 c2mu (unsigned char *cp, int l, unsigned char *mp)
1860 {
1861 unsigned char ch, *ep = cp+l;
1862
1863 while ((cp < ep) && (ch = *cp))
1864 {
1865 if ((unsigned char) ch == ISO_CODE_SS2)
1866 {
1867 *mp++ = LEADING_BYTE_KATAKANA_JISX0201;
1868 cp++;
1869 }
1870 else if ((unsigned char) ch == ISO_CODE_SS3)
1871 {
1872 *mp++ = LEADING_BYTE_JAPANESE_JISX0212;
1873 cp++;
1874 *mp++ = *cp++;
1875 }
1876 else if (ch & 0x80)
1877 {
1878 *mp++ = LEADING_BYTE_JAPANESE_JISX0208;
1879 *mp++ = *cp++;
1880 }
1881 *mp++ = *cp++;
1882 }
1883 *mp = 0;
1884 }
1885
1886 /* MULE internal string to EUC multibyte string */
1887
1888 static void
1889 m2c (unsigned char *mp, int l, unsigned char *cp)
1890 {
1891 unsigned char ch, *ep = mp + l;
1892
1893 while ((mp < ep) && (ch = *mp++))
1894 {
1895 switch (ch)
1896 {
1897 case LEADING_BYTE_KATAKANA_JISX0201:
1898 *cp++ = ISO_CODE_SS2;
1899 *cp++ = *mp++;
1900 break;
1901 case LEADING_BYTE_JAPANESE_JISX0212:
1902 *cp++ = ISO_CODE_SS3;
1903 case LEADING_BYTE_JAPANESE_JISX0208:
1904 *cp++ = *mp++;
1905 *cp++ = *mp++;
1906 break;
1907 default:
1908 *cp++ = ch;
1909 break;
1910 }
1911 }
1912 *cp = 0;
1913 }
1914
1915 #undef make_string
1916
1917 /* make_string after converting EUC string to MULE internal string */
1918 static Lisp_Object
1919 mule_make_string (unsigned char *p, int l)
1920 {
1921 unsigned char cbuf[4096];
1922
1923 c2mu (p,l,cbuf);
1924 return (make_string (cbuf, strlen ((const char *) cbuf)));
1925 }
1926
1927 /* return the MULE internal string length of EUC string */
1928 /* Modified by sb to return a character count not byte count. */
1929 static int 1830 static int
1930 mule_strlen (unsigned char *p, int l) 1831 euc_jp_num_chars (unsigned char *p, int l)
1931 { 1832 {
1932 unsigned char ch, *cp = p; 1833 unsigned char ch, *cp = p;
1933 int len = 0; 1834 int len = 0;
1934 1835
1935 while ((cp < p + l) && (ch = *cp)) 1836 while ((cp < p + l) && (ch = *cp))