comparison src/mule-canna.c @ 448:3078fd1074e8 r21-2-39

Import from CVS: tag r21-2-39
author cvs
date Mon, 13 Aug 2007 11:38:25 +0200
parents abe6d1db359e
children c33ae14dd6d0
comparison
equal deleted inserted replaced
447:4fc5f13f3bd3 448:3078fd1074e8
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */ 21 Boston, MA 02111-1307, USA. */
22 22
23 /* Synched up with: Mule 2.3. Not in FSF. */ 23 /* Synched up with: Mule 2.3. Not in FSF. */
24 24
25 /* #### The comments in this file are mostly in EUC-formatted Japanese. 25 /* Japanese comments were translated 2000-12-06 by Stephen Turnbull
26 It would be ***soooo*** much nicer if someone could translate 26 <stephen@xemacs.org>. I haven't verified that the Japanese comments
27 them ... */ 27 were correct. YMMV, NO WARRANTY, not even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (^^;;; as the
29 Japanese say. */
28 30
29 /* 31 /*
30 32
31 Authors: Akira Kon (kon@uxd.fc.nec.co.jp) 33 Authors: Akira Kon (kon@uxd.fc.nec.co.jp)
32 Ichiro Hirakura (hirakura@uxd.fc.nec.co.jp) 34 Ichiro Hirakura (hirakura@uxd.fc.nec.co.jp)
163 #include "iroha/jrkanji.h" 165 #include "iroha/jrkanji.h"
164 #include "iroha/RK.h" 166 #include "iroha/RK.h"
165 #endif /* !CANNA2 */ 167 #endif /* !CANNA2 */
166 extern char *jrKanjiError; 168 extern char *jrKanjiError;
167 169
170 /* #### is this global really necessary? */
168 #define KEYTOSTRSIZE 2048 171 #define KEYTOSTRSIZE 2048
169 static unsigned char buf[KEYTOSTRSIZE]; 172 static unsigned char key_buffer[KEYTOSTRSIZE];
170 static char **warning; 173 static char **warning;
171 174
172 static int canna_empty_info, canna_through_info; 175 static int canna_empty_info, canna_through_info;
173 static int canna_underline; 176 static int canna_underline;
174 static int canna_inhibit_hankakukana; 177 static int canna_inhibit_hankakukana;
212 { 215 {
213 jrKanjiStatus ks; 216 jrKanjiStatus ks;
214 int len; 217 int len;
215 218
216 CHECK_CHAR_COERCE_INT (ch); 219 CHECK_CHAR_COERCE_INT (ch);
217 len = jrKanjiString (0, XCHAR (ch), buf, KEYTOSTRSIZE, &ks); 220 len = jrKanjiString (0, XCHAR (ch), key_buffer, KEYTOSTRSIZE, &ks);
218 return storeResults (buf, len, &ks); 221 return storeResults (key_buffer, len, &ks);
219 } 222 }
220 223
221 static Lisp_Object 224 static Lisp_Object
222 storeResults (unsigned char *buf, int len, jrKanjiStatus *ks) 225 storeResults (unsigned char *buf, int len, jrKanjiStatus *ks)
223 { 226 {
227 { /* Error detected */ 230 { /* Error detected */
228 val = make_string ((unsigned char*) jrKanjiError, strlen (jrKanjiError)); 231 val = make_string ((unsigned char*) jrKanjiError, strlen (jrKanjiError));
229 } 232 }
230 else 233 else
231 { 234 {
232 /* 確定した文字列 */ 235 /* 確定した文字列 (the confirmed string) */
233 Vcanna_kakutei_string = make_string (buf, len); 236 Vcanna_kakutei_string = make_string (buf, len);
234 val = make_int (len); 237 val = make_int (len);
235 /* 確定した文字列の読みの情報... */ 238 /* 確定した文字列の読みの情報...
239 (info about the reading of the confirmed string) */
236 Vcanna_kakutei_yomi = Vcanna_kakutei_romaji = Qnil; 240 Vcanna_kakutei_yomi = Vcanna_kakutei_romaji = Qnil;
237 if (ks->info & KanjiYomiInfo) 241 if (ks->info & KanjiYomiInfo)
238 { 242 {
239 unsigned char *p = buf + len + 1; 243 unsigned char *p = buf + len + 1;
240 int yomilen = strlen (p); 244 int yomilen = strlen (p);
241 245
242 if (len + yomilen + 1 < KEYTOSTRSIZE) 246 if (len + yomilen + 1 < KEYTOSTRSIZE)
243 { 247 {
244 int yomilen2; 248 int yomilen2;
245 249
246 Vcanna_kakutei_yomi = make_string (p, yomilen); /* 読み */ 250 Vcanna_kakutei_yomi = make_string (p, yomilen); /* 読み
251 (reading) */
247 p += yomilen + 1; 252 p += yomilen + 1;
248 yomilen2 = strlen (p); 253 yomilen2 = strlen (p);
249 if (len + yomilen + yomilen2 + 2 < KEYTOSTRSIZE) 254 if (len + yomilen + yomilen2 + 2 < KEYTOSTRSIZE)
250 { 255 {
251 Vcanna_kakutei_romaji = make_string (p, yomilen2); /* ローマ字 */ 256 Vcanna_kakutei_romaji = make_string (p, yomilen2);
257 /* ローマ字 (romanization) */
252 } 258 }
253 } 259 }
254 } 260 }
255 261
256 262
257 /* 候補表示の文字列です。*/ 263 /* 候補表示の文字列です。
264 (string for displaying candidate translations) */
258 Vcanna_henkan_string = Qnil; 265 Vcanna_henkan_string = Qnil;
259 if (ks->length >= 0) 266 if (ks->length >= 0)
260 { 267 {
261 Vcanna_henkan_string = make_string (ks->echoStr, ks->length); 268 Vcanna_henkan_string = make_string (ks->echoStr, ks->length);
262 #ifndef CANNA_MULE 269 #ifndef CANNA_MULE
266 #else /* CANNA_MULE */ 273 #else /* CANNA_MULE */
267 if (canna_underline) 274 if (canna_underline)
268 { 275 {
269 canna_henkan_length = mule_strlen (ks->echoStr,ks->length); 276 canna_henkan_length = mule_strlen (ks->echoStr,ks->length);
270 canna_henkan_revPos = mule_strlen (ks->echoStr,ks->revPos); 277 canna_henkan_revPos = mule_strlen (ks->echoStr,ks->revPos);
271 canna_henkan_revLen = mule_strlen (ks->echoStr+ks->revPos,ks->revLen); 278 canna_henkan_revLen = mule_strlen (ks->echoStr+ks->revPos,
279 ks->revLen);
272 } 280 }
273 else 281 else
274 { 282 {
275 count_char (ks->echoStr, ks->length, ks->revPos, ks->revLen, 283 count_char (ks->echoStr, ks->length, ks->revPos, ks->revLen,
276 &canna_henkan_length, &canna_henkan_revPos, 284 &canna_henkan_length, &canna_henkan_revPos,
277 &canna_henkan_revLen); 285 &canna_henkan_revLen);
278 } 286 }
279 #endif /* CANNA_MULE */ 287 #endif /* CANNA_MULE */
280 } 288 }
281 289
282 /* 一覧の情報 */ 290 /* 一覧の情報 (information about the echo area menu) */
283 Vcanna_ichiran_string = Qnil; 291 Vcanna_ichiran_string = Qnil;
284 if (ks->info & KanjiGLineInfo && ks->gline.length >= 0) 292 if (ks->info & KanjiGLineInfo && ks->gline.length >= 0)
285 { 293 {
286 Vcanna_ichiran_string = make_string (ks->gline.line, ks->gline.length); 294 Vcanna_ichiran_string = make_string (ks->gline.line,
295 ks->gline.length);
287 #ifndef CANNA_MULE 296 #ifndef CANNA_MULE
288 canna_ichiran_length = ks->gline.length; 297 canna_ichiran_length = ks->gline.length;
289 canna_ichiran_revPos = ks->gline.revPos; 298 canna_ichiran_revPos = ks->gline.revPos;
290 canna_ichiran_revLen = ks->gline.revLen; 299 canna_ichiran_revLen = ks->gline.revLen;
291 #else /* CANNA_MULE */ 300 #else /* CANNA_MULE */
292 count_char (ks->gline.line, ks->gline.length, 301 count_char (ks->gline.line, ks->gline.length,
293 ks->gline.revPos, ks->gline.revLen, &canna_ichiran_length, 302 ks->gline.revPos, ks->gline.revLen,
303 &canna_ichiran_length,
294 &canna_ichiran_revPos, &canna_ichiran_revLen); 304 &canna_ichiran_revPos, &canna_ichiran_revLen);
295 #endif /* CANNA_MULE */ 305 #endif /* CANNA_MULE */
296 } 306 }
297 307
298 /* モードの情報 */ 308 /* モードの情報 (mode information) */
299 Vcanna_mode_string = Qnil; 309 Vcanna_mode_string = Qnil;
300 if (ks->info & KanjiModeInfo) 310 if (ks->info & KanjiModeInfo)
301 { 311 {
302 Vcanna_mode_string = make_string (ks->mode, strlen (ks->mode)); 312 Vcanna_mode_string = make_string (ks->mode, strlen (ks->mode));
303 } 313 }
304 314
305 /* その他の情報 */ 315 /* その他の情報 (other information) */
306 canna_empty_info = (ks->info & KanjiEmptyInfo) ? 1 : 0; 316 canna_empty_info = (ks->info & KanjiEmptyInfo) ? 1 : 0;
307 canna_through_info = (ks->info & KanjiThroughInfo) ? 1 : 0; 317 canna_through_info = (ks->info & KanjiThroughInfo) ? 1 : 0;
308 } 318 }
309 319
310 return val; 320 return val;
315 If non-nil value is specified, the white space separator will be used. 325 If non-nil value is specified, the white space separator will be used.
316 No separator will be used otherwise. 326 No separator will be used otherwise.
317 */ 327 */
318 (num)) 328 (num))
319 { 329 {
320 int kugiri; /* 文節区切りをするか? */ 330 int kugiri; /* 文節区切りをするか? (display clause separator?) */
321 331
322 kugiri = NILP (num) ? 0 : 1; 332 kugiri = NILP (num) ? 0 : 1;
323 333
324 jrKanjiControl (0, KC_SETBUNSETSUKUGIRI, (char *) kugiri); 334 jrKanjiControl (0, KC_SETBUNSETSUKUGIRI, (char *) kugiri);
325 335
346 { 356 {
347 Lisp_Object val; 357 Lisp_Object val;
348 int res; 358 int res;
349 unsigned char **p, **q; 359 unsigned char **p, **q;
350 360
351 int kugiri; /* 文節区切りをするか? */ 361 int kugiri; /* 文節区切りをするか? (display clause separator?) */
352 362
353 IRCP_context = -1; 363 IRCP_context = -1;
354 364
355 if (NILP (num)) 365 if (NILP (num))
356 { 366 {
414 424
415 if (res == -1) 425 if (res == -1)
416 { 426 {
417 val = Fcons (make_string ((unsigned char*) jrKanjiError, 427 val = Fcons (make_string ((unsigned char*) jrKanjiError,
418 strlen (jrKanjiError)), val); 428 strlen (jrKanjiError)), val);
419 /* イニシャライズで失敗した場合。 */ 429 /* イニシャライズで失敗した場合。 (on initialization failure) */
420 return Fcons (Qnil, val); 430 return Fcons (Qnil, val);
421 } 431 }
422 else 432 else
423 { 433 {
424 extern void (*jrBeepFunc) (void); 434 extern void (*jrBeepFunc) (void);
436 jrKanjiControl (0, KC_SETBUNSETSUKUGIRI, (char *) kugiri); 446 jrKanjiControl (0, KC_SETBUNSETSUKUGIRI, (char *) kugiri);
437 jrKanjiControl (0, KC_SETWIDTH, (char *) 78); 447 jrKanjiControl (0, KC_SETWIDTH, (char *) 78);
438 #ifndef CANNA_MULE 448 #ifndef CANNA_MULE
439 jrKanjiControl (0, KC_INHIBITHANKAKUKANA, (char *) 1); 449 jrKanjiControl (0, KC_INHIBITHANKAKUKANA, (char *) 1);
440 #else 450 #else
441 /* mule だったら半角カタカナも使える */ 451 /* mule だったら半角カタカナも使える
452 (Mule can use half-width katakana) */
442 if (canna_inhibit_hankakukana) 453 if (canna_inhibit_hankakukana)
443 jrKanjiControl (0, KC_INHIBITHANKAKUKANA, (char *) 1); 454 jrKanjiControl (0, KC_INHIBITHANKAKUKANA, (char *) 1);
444 #endif 455 #endif
445 jrKanjiControl (0, KC_YOMIINFO, (char *) 2); /* ※2: ローマ字まで返す */ 456 jrKanjiControl (0, KC_YOMIINFO, (char *) 2); /* ※2: ローマ字まで返す
457 (*2: return to
458 romanized form) */
446 val = Fcons (Qnil, val); 459 val = Fcons (Qnil, val);
447 return Fcons (CANNA_mode_keys (), val); 460 return Fcons (CANNA_mode_keys (), val);
448 } 461 }
449 } 462 }
450 463
484 #ifdef CANNA_MULE 497 #ifdef CANNA_MULE
485 unsigned char cbuf[4096]; 498 unsigned char cbuf[4096];
486 #endif 499 #endif
487 500
488 CHECK_STRING (str); 501 CHECK_STRING (str);
489 ksv.buffer = (unsigned char *) buf; 502 ksv.buffer = (unsigned char *) key_buffer;
490 ksv.bytes_buffer = KEYTOSTRSIZE; 503 ksv.bytes_buffer = KEYTOSTRSIZE;
491 #ifndef CANNA_MULE 504 #ifndef CANNA_MULE
492 ks.echoStr = XSTRING_DATA (str); 505 ks.echoStr = XSTRING_DATA (str);
493 ks.length = XSTRING_LENGTH (str); 506 ks.length = XSTRING_LENGTH (str);
494 #else /* CANNA_MULE */ 507 #else /* CANNA_MULE */
496 ks.echoStr = cbuf; 509 ks.echoStr = cbuf;
497 ks.length = strlen (cbuf); 510 ks.length = strlen (cbuf);
498 #endif /* CANNA_MULE */ 511 #endif /* CANNA_MULE */
499 ksv.ks = &ks; 512 ksv.ks = &ks;
500 len = jrKanjiControl (0, KC_DEFINEKANJI, (char *)&ksv); 513 len = jrKanjiControl (0, KC_DEFINEKANJI, (char *)&ksv);
501 val = storeResults (buf, ksv.val, ksv.ks); 514 val = storeResults (key_buffer, ksv.val, ksv.ks);
502 return val; 515 return val;
503 } 516 }
504 517
505 DEFUN ("canna-set-width", Fcanna_set_width, 1, 1, 0, /* 518 DEFUN ("canna-set-width", Fcanna_set_width, 1, 1, 0, /*
506 Set status-line width information, which is used to display 519 Set status-line width information, which is used to display
523 jrKanjiStatus ks; 536 jrKanjiStatus ks;
524 Lisp_Object val; 537 Lisp_Object val;
525 538
526 CHECK_INT (num); 539 CHECK_INT (num);
527 540
528 ksv.buffer = (unsigned char *) buf; 541 ksv.buffer = (unsigned char *) key_buffer;
529 ksv.bytes_buffer = KEYTOSTRSIZE; 542 ksv.bytes_buffer = KEYTOSTRSIZE;
530 ksv.ks = &ks; 543 ksv.ks = &ks;
531 ksv.val = XINT (num); 544 ksv.val = XINT (num);
532 jrKanjiControl (0, KC_CHANGEMODE, (char *)&ksv); 545 jrKanjiControl (0, KC_CHANGEMODE, (char *)&ksv);
533 val = storeResults (buf, ksv.val, ksv.ks); 546 val = storeResults (key_buffer, ksv.val, ksv.ks);
534 return val; 547 return val;
535 } 548 }
536 549
537 static Lisp_Object 550 static Lisp_Object
538 CANNA_mode_keys (void) 551 CANNA_mode_keys (void)
561 jrKanjiStatusWithValue ksv; 574 jrKanjiStatusWithValue ksv;
562 jrKanjiStatus ks; 575 jrKanjiStatus ks;
563 576
564 CHECK_STRING (yomi); 577 CHECK_STRING (yomi);
565 #ifndef CANNA_MULE 578 #ifndef CANNA_MULE
566 strncpy (buf, XSTRING_DATA (yomi), XSTRING_LENGTH (yomi)); 579 strncpy (key_buffer, XSTRING_DATA (yomi), XSTRING_LENGTH (yomi));
567 ks.length = XSTRING_LENGTH (yomi); 580 ks.length = XSTRING_LENGTH (yomi);
568 buf[ks.length] = '\0'; 581 key_buffer[ks.length] = '\0';
569 #else /* CANNA_MULE */ 582 #else /* CANNA_MULE */
570 m2c (XSTRING_DATA (yomi), XSTRING_LENGTH (yomi), buf); 583 m2c (XSTRING_DATA (yomi), XSTRING_LENGTH (yomi), key_buffer);
571 ks.length = strlen (buf); 584 ks.length = strlen (key_buffer);
572 #endif /* CANNA_MULE */ 585 #endif /* CANNA_MULE */
573 586
574 if (NILP (roma)) 587 if (NILP (roma))
575 { 588 {
576 ks.mode = 0; 589 ks.mode = 0;
578 else 591 else
579 { 592 {
580 CHECK_STRING (roma); 593 CHECK_STRING (roma);
581 594
582 #ifndef CANNA_MULE 595 #ifndef CANNA_MULE
583 strncpy (buf + XSTRING_LENGTH (yomi) + 1, XSTRING_DATA (roma), 596 strncpy (key_buffer + XSTRING_LENGTH (yomi) + 1, XSTRING_DATA (roma),
584 XSTRING_LENGTH (roma)); 597 XSTRING_LENGTH (roma));
585 buf[XSTRING_LENGTH (yomi) + 1 + XSTRING_LENGTH (roma)] = '\0'; 598 key_buffer[XSTRING_LENGTH (yomi) + 1 + XSTRING_LENGTH (roma)] = '\0';
586 ks.mode = (unsigned char *)(buf + XSTRING_LENGTH (yomi) + 1); 599 ks.mode = (unsigned char *)(key_buffer + XSTRING_LENGTH (yomi) + 1);
587 #else /* CANNA_MULE */ 600 #else /* CANNA_MULE */
588 ks.mode = (unsigned char *)(buf + ks.length + 1); 601 ks.mode = (unsigned char *)(key_buffer + ks.length + 1);
589 m2c (XSTRING_DATA (roma), XSTRING_LENGTH (roma), ks.mode); 602 m2c (XSTRING_DATA (roma), XSTRING_LENGTH (roma), ks.mode);
590 #endif /* CANNA_MULE */ 603 #endif /* CANNA_MULE */
591 } 604 }
592 605
593 ks.echoStr = (unsigned char *) buf; 606 ks.echoStr = (unsigned char *) key_buffer;
594 ksv.buffer = (unsigned char *) buf; /* 返値用 */ 607 ksv.buffer = (unsigned char *) key_buffer; /* 返値用 (return value) */
595 ksv.bytes_buffer = KEYTOSTRSIZE; 608 ksv.bytes_buffer = KEYTOSTRSIZE;
596 ksv.ks = &ks; 609 ksv.ks = &ks;
597 610
598 jrKanjiControl (0, KC_STOREYOMI, (char *)&ksv); 611 jrKanjiControl (0, KC_STOREYOMI, (char *)&ksv);
599 612
600 return storeResults (buf, ksv.val, ksv.ks); 613 return storeResults (key_buffer, ksv.val, ksv.ks);
601 } 614 }
602 615
603 DEFUN ("canna-do-function", Fcanna_do_function, 1, 2, 0, /* 616 DEFUN ("canna-do-function", Fcanna_do_function, 1, 2, 0, /*
604 Do specified function at current mode. 617 Do specified function at current mode.
605 */ 618 */
611 624
612 CHECK_INT (num); 625 CHECK_INT (num);
613 626
614 if (NILP (ch)) 627 if (NILP (ch))
615 { 628 {
616 *buf = '@'; 629 *key_buffer = '@';
617 } 630 }
618 else 631 else
619 { 632 {
620 CHECK_CHAR (ch); 633 CHECK_CHAR (ch);
621 *buf = XCHAR (ch); 634 *key_buffer = XCHAR (ch);
622 } 635 }
623 636
624 ksv.buffer = (unsigned char *) buf; 637 ksv.buffer = (unsigned char *) key_buffer;
625 ksv.bytes_buffer = KEYTOSTRSIZE; 638 ksv.bytes_buffer = KEYTOSTRSIZE;
626 ksv.ks = &ks; 639 ksv.ks = &ks;
627 ksv.val = XINT (num); 640 ksv.val = XINT (num);
628 jrKanjiControl (0, KC_DO, (char *) &ksv); 641 jrKanjiControl (0, KC_DO, (char *) &ksv);
629 val = storeResults (buf, ksv.val, ksv.ks); 642 val = storeResults (key_buffer, ksv.val, ksv.ks);
630 return val; 643 return val;
631 } 644 }
632 645
633 DEFUN ("canna-parse", Fcanna_parse, 1, 1, 0, /* 646 DEFUN ("canna-parse", Fcanna_parse, 1, 1, 0, /*
634 Parse customize string. 647 Parse customize string.
640 int n; 653 int n;
641 654
642 CHECK_STRING (str); 655 CHECK_STRING (str);
643 656
644 #ifndef CANNA_MULE 657 #ifndef CANNA_MULE
645 strncpy (buf, XSTRING_DATA (str), XSTRING_LENGTH (str)); 658 strncpy (key_buffer, XSTRING_DATA (str), XSTRING_LENGTH (str));
646 buf[XSTRING_LENGTH (str)] = '\0'; 659 key_buffer[XSTRING_LENGTH (str)] = '\0';
647 #else /* CANNA_MULE */ 660 #else /* CANNA_MULE */
648 m2c (XSTRING_DATA (str), XSTRING_LENGTH (str), buf); 661 m2c (XSTRING_DATA (str), XSTRING_LENGTH (str), key_buffer);
649 #endif /* CANNA_MULE */ 662 #endif /* CANNA_MULE */
650 p = (unsigned char**) buf; 663 p = (unsigned char**) key_buffer;
651 n = jrKanjiControl (0, KC_PARSE, (char *) &p); 664 n = jrKanjiControl (0, KC_PARSE, (char *) &p);
652 val = Qnil; 665 val = Qnil;
653 while (n > 0) 666 while (n > 0)
654 { 667 {
655 n--; 668 n--;
851 { 864 {
852 if (confirmContext () == 0) 865 if (confirmContext () == 0)
853 { 866 {
854 return Qnil; 867 return Qnil;
855 } 868 }
856 RkEndBun (IRCP_context, 1); /* 学習はいつでも行って良いものなのか? */ 869 RkEndBun (IRCP_context, 1); /* 学習はいつでも行って良いものなのか?
870 (is it OK to invoke learning function
871 at arbitrary times?) */
857 return Qt; 872 return Qt;
858 } 873 }
859 874
860 DEFUN ("canna-henkan-quit", Fcanna_henkan_quit, 0, 0, 0, /* 875 DEFUN ("canna-henkan-quit", Fcanna_henkan_quit, 0, 0, 0, /*
861 Quit conversion. 876 Quit conversion.