Reformatted.
[chise/xemacs-chise.git-] / src / mule-canna.c
index 069c7b5..249e21d 100644 (file)
@@ -1,4 +1,4 @@
-/* CANNA interface
+/* CANNA interface -*- coding: euc-jp -*-
 
    Copyright (C) 1995 Free Software Foundation, Inc.
    Copyright (C) 1995 Sun Microsystems, Inc.
@@ -190,6 +190,7 @@ static int IRCP_context;
 
 static Lisp_Object storeResults (unsigned char *, int, jrKanjiStatus *);
 static Lisp_Object kanjiYomiList (int, int);
+static Lisp_Object CANNA_mode_keys (void);
 
 #ifdef CANNA_MULE
 static void m2c (unsigned char *, int, unsigned char *);
@@ -326,10 +327,9 @@ No separator will be used otherwise.
 }
 
 /* For whatever reason, calling Fding directly from libCanna loses */
-static void call_Fding()
+static void
+call_Fding (void)
 {
-  extern Lisp_Object Fding();
-
   Fding (Qnil, Qnil, Qnil);
 }
 
@@ -421,8 +421,7 @@ If nil is specified for each arg, the default value will be used.
     }
   else
     {
-      extern void (*jrBeepFunc)();
-      Lisp_Object CANNA_mode_keys ();
+      extern void (*jrBeepFunc) (void);
 
       jrBeepFunc = call_Fding;
 
@@ -535,7 +534,7 @@ Change Japanese pre-edit mode.
   return val;
 }
 
-Lisp_Object
+static Lisp_Object
 CANNA_mode_keys (void)
 {
 #define CANNAWORKBUFSIZE 32
@@ -718,7 +717,8 @@ byteLen (int bun, int len)
 }
 
 DEFUN ("canna-henkan-begin", Fcanna_henkan_begin, 1, 1, 0, /*
-¤«¤Ê´Á»úÊÑ´¹¤·¤¿·ë²Ì¤òÊÖ´Ô¤¹¤ë¡£Ê¸ÀáÀڤ꤬¤·¤Æ¤¢¤ë¡£
+Return the result of kana-to-kanji conversion.
+Clause separator is set.
 */
        (yomi))
 {
@@ -773,7 +773,7 @@ kanjiYomiList (int context, int nbun)
 }
 
 DEFUN ("canna-henkan-next", Fcanna_henkan_next, 1, 1, 0, /*
-¸õÊä°ìÍ÷¤òµá¤á¤ë¡£
+Return the list of candidates.
 */
        (bunsetsu))
 {
@@ -798,7 +798,7 @@ DEFUN ("canna-henkan-next", Fcanna_henkan_next, 1, 1, 0, /*
        }
       else
        {
-         endp = XCDR (endp) = Fcons (make_string (p, slen), Qnil);
+         endp = XCDR (res) = Fcons (make_string (p, slen), Qnil);
        }
       p += slen + 1;
     }
@@ -806,7 +806,7 @@ DEFUN ("canna-henkan-next", Fcanna_henkan_next, 1, 1, 0, /*
 }
 
 DEFUN ("canna-bunsetu-henkou", Fcanna_bunsetu_henkou, 2, 2, 0, /*
-ʸÀá¤ÎŤµ¤ò»ØÄꤹ¤ë¡£
+Specify the length of a clause.
 */
        (bunsetsu, bunlen))
 {
@@ -826,7 +826,7 @@ DEFUN ("canna-bunsetu-henkou", Fcanna_bunsetu_henkou, 2, 2, 0, /*
 }
 
 DEFUN ("canna-henkan-kakutei", Fcanna_henkan_kakutei, 2, 2, 0, /*
-¸õÊäÁªÂò¡£
+Select a candidate.
 */
        (bun, kouho))
 {
@@ -845,7 +845,7 @@ DEFUN ("canna-henkan-kakutei", Fcanna_henkan_kakutei, 2, 2, 0, /*
 }
 
 DEFUN ("canna-henkan-end", Fcanna_henkan_end, 0, 0, 0, /*
-ÊÑ´¹½ªÎ»¡£
+End conversion.
 */
        ())
 {
@@ -858,7 +858,7 @@ DEFUN ("canna-henkan-end", Fcanna_henkan_end, 0, 0, 0, /*
 }
 
 DEFUN ("canna-henkan-quit", Fcanna_henkan_quit, 0, 0, 0, /*
-ÊÑ´¹½ªÎ»¡£
+Quit conversion.
 */
        ())
 {
@@ -1777,10 +1777,74 @@ For canna
 /* EUC multibyte string to MULE internal string */
 
 static void
-c2mu (char *cp, int l, char *mp)
+c2mu (unsigned char *cp, int l, unsigned char *mp)
 {
-  char ch, *ep = cp+l;
+  unsigned char        ch, *ep = cp+l;
+#ifdef UTF2000
+  Emchar chr;
 
+  while ((cp < ep) && (ch = *cp++))
+    {
+      if (ch == ISO_CODE_SS2)
+       {
+         chr = (*cp++) + MIN_CHAR_HALFWIDTH_KATAKANA - 0x20;
+       }
+      else if (ch == ISO_CODE_SS3)
+       {
+         ch = *cp++;
+         chr = MAKE_CHAR (Vcharset_japanese_jisx0212,
+                          ch & 0x7f, (*cp++) & 0x7f);
+       }
+      else if (ch & 0x80)
+       {
+         chr = MAKE_CHAR (Vcharset_japanese_jisx0208,
+                          ch & 0x7f, (*cp++) & 0x7f);
+        }
+      else
+       {
+         chr = ch;
+       }
+      if ( chr <= 0x7f )
+        {
+         *mp++ = chr;
+       }
+      else if ( chr <= 0x7ff )
+        {
+         *mp++ = (chr >> 6) | 0xc0;
+         *mp++ = (chr & 0x3f) | 0x80;
+       }
+      else if ( chr <= 0xffff )
+        {
+         *mp++ =  (chr >> 12) | 0xe0;
+         *mp++ = ((chr >>  6) & 0x3f) | 0x80;
+         *mp++ =  (chr        & 0x3f) | 0x80;
+       }
+      else if ( chr <= 0x1fffff )
+       {
+         *mp++ =  (chr >> 18) | 0xf0;
+         *mp++ = ((chr >> 12) & 0x3f) | 0x80;
+         *mp++ = ((chr >>  6) & 0x3f) | 0x80;
+         *mp++ =  (chr        & 0x3f) | 0x80;
+       }
+      else if ( chr <= 0x3ffffff )
+       {
+         *mp++ =  (chr >> 24) | 0xf8;
+         *mp++ = ((chr >> 18) & 0x3f) | 0x80;
+         *mp++ = ((chr >> 12) & 0x3f) | 0x80;
+         *mp++ = ((chr >>  6) & 0x3f) | 0x80;
+         *mp++ =  (chr        & 0x3f) | 0x80;
+       }
+      else
+        {
+         *mp++ =  (chr >> 30) | 0xfc;
+         *mp++ = ((chr >> 24) & 0x3f) | 0x80;
+         *mp++ = ((chr >> 18) & 0x3f) | 0x80;
+         *mp++ = ((chr >> 12) & 0x3f) | 0x80;
+         *mp++ = ((chr >>  6) & 0x3f) | 0x80;
+         *mp++ =  (chr        & 0x3f) | 0x80;
+       }
+    }
+#else
   while ((cp < ep) && (ch = *cp))
     {
       if ((unsigned char) ch == ISO_CODE_SS2)
@@ -1801,6 +1865,7 @@ c2mu (char *cp, int l, char *mp)
        }
       *mp++ = *cp++;
     }
+#endif
   *mp = 0;
 }
 
@@ -1810,9 +1875,74 @@ static void
 m2c (unsigned char *mp, int l, unsigned char *cp)
 {
   unsigned char        ch, *ep = mp + l;
+#ifdef UTF2000
+  unsigned char fb;
+  int len;
+  Emchar chr;
+#endif
 
   while ((mp < ep) && (ch = *mp++))
     {
+#ifdef UTF2000
+      if ( ch >= 0xfc )
+       {
+         chr = (ch & 0x01);
+         len = 5;
+       }
+      else if ( ch >= 0xf8 )
+       {
+         chr = ch & 0x03;
+         len = 4;
+       }
+      else if ( ch >= 0xf0 )
+       {
+         chr = ch & 0x07;
+         len = 3;
+       }
+      else if ( ch >= 0xe0 )
+       {
+         chr = ch & 0x0f;
+         len = 2;
+       }
+      else if ( ch >= 0xc0 )
+       {
+         chr = ch & 0x1f;
+         len = 1;
+       }
+      else
+       {
+         chr = ch;
+         len = 0;
+       }
+      for( ; len > 0; len-- )
+       {
+         ch = *mp++;
+         chr = ( chr << 6 ) | ( ch & 0x3f );
+       }
+      if ( chr <= 0x7f )
+       *cp++ = chr;
+      else if ( chr <= MAX_CHAR_HALFWIDTH_KATAKANA )
+       {
+         *cp++ = ISO_CODE_SS2;
+         *cp++ = ( chr & 0x7f ) | 0x80;
+       }
+      else
+       {
+         Lisp_Object charset;
+         int c1, c2;
+
+         BREAKUP_CHAR (chr, charset, c1, c2);
+         fb = XCHARSET_FINAL (charset);
+         switch (fb)
+           {
+           case 'D':
+             *cp++ = ISO_CODE_SS3;
+           default:
+             *cp++ = c1;
+             *cp++ = c2;
+           }
+       }
+#else
       switch (ch)
        {
        case LEADING_BYTE_KATAKANA_JISX0201:
@@ -1829,6 +1959,7 @@ m2c (unsigned char *mp, int l, unsigned char *cp)
          *cp++ = ch;
          break;
        }
+#endif
     }
   *cp = 0;
 }