From edf5c1a3fa1cbec27fdcbf1de33203943b100004 Mon Sep 17 00:00:00 2001 From: morioka Date: Thu, 6 Mar 1997 12:45:30 +0000 Subject: [PATCH] modified for dynamic loading of Emacs/mule on Linux. --- canna.c | 302 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 252 insertions(+), 50 deletions(-) diff --git a/canna.c b/canna.c index b41f45d..475cb01 100644 --- a/canna.c +++ b/canna.c @@ -1,26 +1,28 @@ -/* - CANNA interface for NEmacs +/* CANNA interface for Emacs/mule and XEmacs/mule. - This file is a part of Canna on Nemacs. + Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1996 MORIOKA Tomohiko - Canna on Nemacs is distributed in the forms of patches - to Nemacs under the terms of the GNU EMACS GENERAL - PUBLIC LICENSE which is distributed along with GNU Emacs - by the Free Software Foundation. + This file is not part of GNU Emacs. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. - Canna on Nemacs is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A - PARTICULAR PURPOSE. See the GNU EMACS GENERAL PUBLIC - LICENSE for more details. + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - You should have received a copy of the GNU EMACS GENERAL - PUBLIC LICENSE along with Nemacs; see the file COPYING. - If not, write to the Free Software Foundation, 675 Mass - Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with GNU Emacs; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. Authors: Akira Kon (kon@d1.bs2.mt.nec.co.jp) Ichiro Hirakura (hirakura@uxp.bs2.mt.nec.co.jp) + modified by MORIOKA Tomohiko Functions defined in this file are @@ -141,7 +143,7 @@ */ #ifndef lint -static char rcs_id[] = "$Id: canna.c,v 1.35 1997-03-06 12:41:59 morioka Exp $"; +static char rcs_id[] = "$Id: canna.c,v 1.35.1.1 1997-03-06 12:45:30 morioka Exp $"; #endif #include @@ -149,18 +151,31 @@ static char rcs_id[] = "$Id: canna.c,v 1.35 1997-03-06 12:41:59 morioka Exp $"; #include "config.h" #include "lisp.h" #include "buffer.h" -#ifdef CANNA_MULE +#ifndef CANNA_NEMACS #include "charset.h" #endif +#ifdef CANNA_EMACS +#include "coding.h" +#endif + +#ifdef CANNA_EMACS +#define CHARSET_KATAKANA_JISX0201 137 +#define CHARSET_JAPANESE_JISX0208 146 +#define CHARSET_JAPANESE_JISX0212 148 +#else +#ifdef CANNA_MULE +#define CHARSET_KATAKANA_JISX0201 LCKANA +#define CHARSET_JAPANESE_JISX0208 LCJP +#define CHARSET_JAPANESE_JISX0212 LCJP2 +#define ISO_CODE_SS2 SS2 +#define ISO_CODE_SS3 SS3 +#endif /* CANNA_MULE */ +#endif -#ifdef CANNA2 #define IROHA_BC #include "canna/jrkanji.h" #include "canna/RK.h" -#else /* !CANNA2 */ -#include "iroha/jrkanji.h" -#include "iroha/RK.h" -#endif /* !CANNA2 */ + extern char *jrKanjiError; #define KEYTOSTRSIZE 2048 @@ -194,7 +209,7 @@ static Lisp_Object storeResults(); static Lisp_Object kanjiYomiList(); #endif -#ifdef CANNA_MULE +#ifndef CANNA_NEMACS #if __STDC__ static m2c(unsigned char *, int, unsigned char *); static Lisp_Object mule_make_string(unsigned char *, int); @@ -211,7 +226,7 @@ static count_char(); /* Lisp functions definition */ -DEFUN ("canna-key-proc", Fcanna_key_proc, Scanna_key_proc, +DEFUN ("canna-key-proc", Fcanna_key_proc, Scanna_key_proc, 1, 1, 0, "Translate a key input to a set of strings. The strings contain both\n\ well-formed string and intermediate result to show the translation\n\ @@ -267,7 +282,7 @@ jrKanjiStatus *ks; Vcanna_henkan_string = Qnil; if (ks->length >= 0) { Vcanna_henkan_string = make_string(ks->echoStr, ks->length); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS Vcanna_henkan_length = ks->length; Vcanna_henkan_revPos = ks->revPos; Vcanna_henkan_revLen = ks->revLen; @@ -289,7 +304,7 @@ jrKanjiStatus *ks; Vcanna_ichiran_string = Qnil; if (ks->info & KanjiGLineInfo && ks->gline.length >= 0) { Vcanna_ichiran_string = make_string(ks->gline.line, ks->gline.length); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS Vcanna_ichiran_length = ks->gline.length; Vcanna_ichiran_revPos = ks->gline.revPos; Vcanna_ichiran_revLen = ks->gline.revLen; @@ -319,14 +334,16 @@ DEFUN ("canna-set-bunsetsu-kugiri", Fcanna_set_bunsetsu, Scanna_set_bunsetsu, "This function sets the clause separator.\n\ If non-nil value is specified, the white space separator will be used.\n\ No separator will be used otherwise.") -(num) -Lisp_Object num; + (num) + Lisp_Object num; { int kugiri; /* ʸÀá¶èÀÚ¤ê¤ò¤¹¤ë¤«¡© */ kugiri = NILP(num) ? 0 : 1; jrKanjiControl(0, KC_SETBUNSETSUKUGIRI, (char *)kugiri); + + return Qnil; } DEFUN ("canna-initialize", Fcanna_initialize, Scanna_initialize, 0, 3, 0, @@ -413,7 +430,7 @@ Lisp_Object num, server, rcfile; jrBeepFunc = Fding; #ifdef KC_SETAPPNAME -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS wcKanjiControl(0, KC_SETAPPNAME, "nemacs"); #else /* CANNA_MULE */ wcKanjiControl(0, KC_SETAPPNAME, "mule"); @@ -422,7 +439,7 @@ Lisp_Object num, server, rcfile; jrKanjiControl(0, KC_SETBUNSETSUKUGIRI, (char *)kugiri); jrKanjiControl(0, KC_SETWIDTH, (char *)78); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS jrKanjiControl(0, KC_INHIBITHANKAKUKANA, (char *)1); #else /* hir, 1994.12.5 */ /* mule ¤À¤Ã¤¿¤éȾ³Ñ¥«¥¿¥«¥Ê¤â»È¤¨¤ë */ @@ -466,14 +483,14 @@ Lisp_Object str; jrKanjiStatus ks; int len; Lisp_Object val; -#ifdef CANNA_MULE +#ifndef CANNA_NEMACS unsigned char cbuf[4096]; #endif CHECK_STRING(str, 0); ksv.buffer = (unsigned char *)buf; ksv.bytes_buffer = KEYTOSTRSIZE; -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS ks.echoStr = XSTRING (str)->data; ks.length = XSTRING (str)->size; #else /* CANNA_MULE */ @@ -548,7 +565,7 @@ Lisp_Object yomi, roma; jrKanjiStatus ks; CHECK_STRING(yomi, 0); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS strncpy(buf, XSTRING(yomi)->data, XSTRING(yomi)->size); ks.length = XSTRING (yomi)->size; buf[ks.length] = '\0'; @@ -563,7 +580,7 @@ Lisp_Object yomi, roma; else { CHECK_STRING(roma, 0); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS strncpy(buf + XSTRING(yomi)->size + 1, XSTRING(roma)->data, XSTRING(roma)->size); buf[XSTRING(yomi)->size + 1 + XSTRING(roma)->size] = '\0'; @@ -627,7 +644,7 @@ Lisp_Object str; CHECK_STRING(str, 0); -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS strncpy(buf, XSTRING(str)->data, XSTRING(str)->size); buf[XSTRING(str)->size] = '\0'; #else /* CANNA_MULE */ @@ -708,7 +725,7 @@ DEFUN ("canna-henkan-begin", Fcanna_henkan_begin, Scanna_henkan_begin, if (confirmContext() == 0) { return Qnil; } -#ifndef CANNA_MULE +#ifdef CANNA_NEMACS strncpy(yomibuf, XSTRING(yomi)->data, XSTRING(yomi)->size); yomibuf[XSTRING(yomi)->size] = '\0'; nbun = RkBgnBun(IRCP_context, XSTRING(yomi)->data, XSTRING(yomi)->size, @@ -985,11 +1002,37 @@ static int Vcanna_key_Cntrl_Down = IROHA_KEY_Cntrl_Down; static Lisp_Object VCANNA; /* hir@nec, 1992.5.21 */ +#ifdef CANNA_EMACS_DL +static struct Lisp_Subr *s_canna_key_proc; +static struct Lisp_Subr *s_canna_set_bunsetsu; +static struct Lisp_Subr *s_canna_initialize; +static struct Lisp_Subr *s_canna_finalize; +static struct Lisp_Subr *s_canna_touroku_string; +static struct Lisp_Subr *s_canna_set_width; +static struct Lisp_Subr *s_canna_change_mode; +static struct Lisp_Subr *s_canna_store_yomi; +static struct Lisp_Subr *s_canna_do_function; +static struct Lisp_Subr *s_canna_parse; +static struct Lisp_Subr *s_canna_query_mode; +static struct Lisp_Subr *s_canna_henkan_begin; +static struct Lisp_Subr *s_canna_henkan_next; +static struct Lisp_Subr *s_canna_bunsetu_henkou; +static struct Lisp_Subr *s_canna_henkan_kakutei; +static struct Lisp_Subr *s_canna_henkan_end; +static struct Lisp_Subr *s_canna_henkan_quit; +#endif + +#ifndef CANNA_EMACS_DL syms_of_canna () +#else /* CANNA_EMACS_DL */ +void +emacs_canna_init () +#endif { DEFVAR_LISP ("CANNA", &VCANNA, ""); /* hir@nec, 1992.5.21 */ VCANNA = Qt; /* hir@nec, 1992.5.21 */ +#ifndef CANNA_EMACS_DL defsubr (&Scanna_key_proc); defsubr (&Scanna_initialize); defsubr (&Scanna_finalize); @@ -1001,6 +1044,70 @@ syms_of_canna () defsubr (&Scanna_parse); defsubr (&Scanna_query_mode); defsubr (&Scanna_set_bunsetsu); +#else /* CANNA_EMACS_DL */ + s_canna_key_proc + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_key_proc, s_canna_key_proc, sizeof (struct Lisp_Subr)); + defsubr (s_canna_key_proc); + + s_canna_initialize + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_initialize, s_canna_initialize, sizeof (struct Lisp_Subr)); + defsubr (s_canna_initialize); + + s_canna_finalize + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_finalize, s_canna_finalize, sizeof (struct Lisp_Subr)); + defsubr (s_canna_finalize); + + s_canna_touroku_string + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_touroku_string, s_canna_touroku_string, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_touroku_string); + + s_canna_set_width + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_set_width, s_canna_set_width, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_set_width); + + s_canna_change_mode + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_change_mode, s_canna_change_mode, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_change_mode); + + s_canna_store_yomi + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_store_yomi, s_canna_store_yomi, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_store_yomi); + + s_canna_do_function + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_do_function, s_canna_do_function, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_do_function); + + s_canna_parse + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_parse, s_canna_parse, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_parse); + + s_canna_query_mode + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_query_mode, s_canna_query_mode, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_query_mode); + + s_canna_set_bunsetsu + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_set_bunsetsu, s_canna_set_bunsetsu, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_set_bunsetsu); +#endif DEFVAR_LISP("canna-kakutei-string", &Vcanna_kakutei_string, ""); DEFVAR_LISP("canna-kakutei-yomi", &Vcanna_kakutei_yomi, ""); @@ -1021,12 +1128,50 @@ syms_of_canna () DEFVAR_BOOL ("canna-inhibit-hankakukana", &Vcanna_inhibit_hankakukana, "For canna"); /* hir, 1994.12.5 */ +#ifndef CANNA_EMACS_DL defsubr (&Scanna_henkan_begin); defsubr (&Scanna_henkan_next); defsubr (&Scanna_bunsetu_henkou); defsubr (&Scanna_henkan_kakutei); defsubr (&Scanna_henkan_end); defsubr (&Scanna_henkan_quit); +#else /* CANNA_EMACS_DL */ + s_canna_henkan_begin + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_henkan_begin, s_canna_henkan_begin, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_henkan_begin); + + s_canna_henkan_next + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_henkan_next, s_canna_henkan_next, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_henkan_next); + + s_canna_bunsetu_henkou + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_bunsetu_henkou, s_canna_bunsetu_henkou, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_bunsetu_henkou); + + s_canna_henkan_kakutei + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_henkan_kakutei, s_canna_henkan_kakutei, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_henkan_kakutei); + + s_canna_henkan_end + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_henkan_end, s_canna_henkan_end, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_henkan_end); + + s_canna_henkan_quit + = (struct Lisp_Subr *)xmalloc (sizeof (struct Lisp_Subr)); + bcopy (&Scanna_henkan_quit, s_canna_henkan_quit, + sizeof (struct Lisp_Subr)); + defsubr (s_canna_henkan_quit); +#endif DEFVAR_INT ("canna-mode-alpha-mode", &Vcanna_mode_AlphaMode, ""); DEFVAR_INT ("canna-mode-empty-mode", &Vcanna_mode_EmptyMode, ""); @@ -1201,7 +1346,64 @@ syms_of_canna () DEFVAR_INT ("canna-key-control-down", &Vcanna_key_Cntrl_Down, ""); } -#ifdef CANNA_MULE +#ifdef CANNA_EMACS_DL +void +emacs_wnnfns_fini () +{ + undefsubr (s_canna_key_proc); + free (s_canna_key_proc); + + undefsubr (s_canna_initialize); + free (s_canna_initialize); + + undefsubr (s_canna_finalize); + free (s_canna_finalize); + + undefsubr (s_canna_touroku_string); + free (s_canna_touroku_string); + + undefsubr (s_canna_set_width); + free (s_canna_set_width); + + undefsubr (s_canna_change_mode); + free (s_canna_change_mode); + + undefsubr (s_canna_store_yomi); + free (s_canna_store_yomi); + + undefsubr (s_canna_do_function); + free (s_canna_do_function); + + undefsubr (s_canna_parse); + free (s_canna_parse); + + undefsubr (s_canna_query_mode); + free (s_canna_query_mode); + + undefsubr (s_canna_set_bunsetsu); + free (s_canna_set_bunsetsu); + + undefsubr (s_canna_henkan_begin); + free (s_canna_henkan_begin); + + undefsubr (s_canna_henkan_next); + free (s_canna_henkan_next); + + undefsubr (s_canna_bunsetu_henkou); + free (s_canna_bunsetu_henkou); + + undefsubr (s_canna_henkan_kakutei); + free (s_canna_henkan_kakutei); + + undefsubr (s_canna_henkan_end); + free (s_canna_henkan_end); + + undefsubr (s_canna_henkan_quit); + free (s_canna_henkan_quit); +} +#endif + +#ifndef CANNA_NEMACS /* To handle MULE internal code and EUC. I assume CANNA can handle only Japanese EUC. */ @@ -1216,17 +1418,17 @@ char *mp; char ch, *ep = cp+l; while((cp < ep) && (ch = *cp)) { - if ((unsigned char)ch == SS2) { - *mp++ = LCKANA; + if ((unsigned char)ch == ISO_CODE_SS2) { + *mp++ = CHARSET_KATAKANA_JISX0201; cp++; } - else if ((unsigned char)ch == SS3) { - *mp++ = LCJP2; + else if ((unsigned char)ch == ISO_CODE_SS3) { + *mp++ = CHARSET_JAPANESE_JISX0212; cp++; *mp++ = *cp++; } else if(ch & 0x80) { - *mp++ = LCJP; + *mp++ = CHARSET_JAPANESE_JISX0208; *mp++ = *cp++; } *mp++ = *cp++; @@ -1246,13 +1448,13 @@ unsigned char *cp; while((mp < ep) && (ch = *mp++)) { switch (ch) { - case LCKANA: - *cp++ = SS2; + case CHARSET_KATAKANA_JISX0201: + *cp++ = ISO_CODE_SS2; *cp++ = *mp++; break; - case LCJP2: - *cp++ = SS3; - case LCJP: + case CHARSET_JAPANESE_JISX0212: + *cp++ = ISO_CODE_SS3; + case CHARSET_JAPANESE_JISX0208: *cp++ = *mp++; *cp++ = *mp++; break; @@ -1289,11 +1491,11 @@ int l; int len = 0; while((cp < p + l) && (ch = *cp)) { - if ((unsigned char)ch == SS2) { + if ((unsigned char)ch == ISO_CODE_SS2) { len += 2; cp += 2; } - else if ((unsigned char)ch == SS3) { + else if ((unsigned char)ch == ISO_CODE_SS3) { len += 3; cp += 3; } -- 1.7.10.4