(Mdetail_text, minput_get_description, minput_get_commands)
[m17n/m17n-lib.git] / src / coding.c
index 0dd09cd..986958b 100644 (file)
@@ -37,7 +37,7 @@
 
 /***ja
     @addtogroup m17nConv
-    @brief ¥³¡¼¥É·Ï¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API
+    @brief ¥³¡¼¥É·Ï¥ª¥Ö¥¸¥§¥¯¥È¤È¤½¤ì¤Ë´Ø¤¹¤ë API.
 
     m17n ¥é¥¤¥Ö¥é¥ê¤Ï¡¢Éä¹æ²½Ê¸»ú½¸¹ç (coded character set; CCS) ¤Îʸ
     »úÉä¹ç²½Êý¼° (character encoding scheme; CES) ¤ò @e ¥³¡¼¥É·Ï ¤È¸Æ
@@ -99,7 +99,7 @@ typedef struct
       reseting a converter.  */
   int (*resetter) (MConverter *converter);
 
-  int (*decoder) (unsigned char *str, int str_bytes, MText *mt,
+  int (*decoder) (const unsigned char *str, int str_bytes, MText *mt,
                  MConverter *converter);
 
   int (*encoder) (MText *mt, int from, int to,
@@ -390,8 +390,8 @@ encode_unsupporeted_char (int c, unsigned char *dst, unsigned char *dst_end,
 
 static int
 finish_decoding (MText *mt, MConverter *converter, int nchars,
-                unsigned char *source, unsigned char *src_end,
-                unsigned char *src,
+                const unsigned char *source, const unsigned char *src_end,
+                const unsigned char *src,
                 int error)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
@@ -420,7 +420,7 @@ finish_decoding (MText *mt, MConverter *converter, int nchars,
     {
       unsigned char *dst = mt->data + mt->nbytes;
       unsigned char *dst_end = mt->data + mt->allocated;
-      unsigned char *src_stop = src_end;
+      const unsigned char *src_stop = src_end;
       int c;
       int last_nchars = nchars;
 
@@ -511,15 +511,15 @@ reset_coding_charset (MConverter *converter)
 }
 
 static int
-decode_coding_charset (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_charset (const unsigned char *source, int src_bytes, MText *mt,
                       MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
   MCodingSystem *coding = internal->coding;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated;
   int nchars = 0;
@@ -712,15 +712,15 @@ encode_coding_charset (MText *mt, int from, int to,
 
 
 static int
-decode_coding_utf_8 (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_utf_8 (const unsigned char *source, int src_bytes, MText *mt,
                     MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
   MCodingSystem *coding = internal->coding;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated;
   int nchars = 0;
@@ -921,14 +921,14 @@ reset_coding_utf (MConverter *converter)
 }
 
 static int
-decode_coding_utf_16 (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_utf_16 (const unsigned char *source, int src_bytes, MText *mt,
                      MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated;
   int nchars = 0;
@@ -1025,14 +1025,14 @@ decode_coding_utf_16 (unsigned char *source, int src_bytes, MText *mt,
 
 
 static int
-decode_coding_utf_32 (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_utf_32 (const unsigned char *source, int src_bytes, MText *mt,
                      MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated;
   int nchars = 0;
@@ -1524,15 +1524,15 @@ find_ctext_non_standard_charset (char *charset_name)
 }
 
 static int
-decode_coding_iso_2022 (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_iso_2022 (const unsigned char *source, int src_bytes, MText *mt,
                       MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
   MCodingSystem *coding = internal->coding;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated;
   int nchars = 0;
@@ -2634,7 +2634,7 @@ reset_coding_sjis (MConverter *converter)
       MSymbol kana_sym = msymbol ("jisx0201-kana");
       MCharset *kana = MCHARSET (kana_sym);
 
-      if (! kanji_sym || ! kana_sym)
+      if (! kanji || ! kana)
        return -1;
       coding->ncharsets = 3;
       coding->charsets[1] = kanji;
@@ -2645,15 +2645,15 @@ reset_coding_sjis (MConverter *converter)
 }
 
 static int
-decode_coding_sjis (unsigned char *source, int src_bytes, MText *mt,
+decode_coding_sjis (const unsigned char *source, int src_bytes, MText *mt,
                    MConverter *converter)
 {
   MConverterStatus *internal = (MConverterStatus *) converter->internal_info;
   MCodingSystem *coding = internal->coding;
-  unsigned char *src = internal->carryover;
-  unsigned char *src_stop = src + internal->carryover_bytes;
-  unsigned char *src_end = source + src_bytes;
-  unsigned char *src_base;
+  const unsigned char *src = internal->carryover;
+  const unsigned char *src_stop = src + internal->carryover_bytes;
+  const unsigned char *src_end = source + src_bytes;
+  const unsigned char *src_base;
   unsigned char *dst = mt->data + mt->nbytes;
   unsigned char *dst_end = mt->data + mt->allocated - MAX_UTF8_CHAR_BYTES;
   int nchars = 0;
@@ -2818,14 +2818,19 @@ find_coding (MSymbol name)
 
   if (! coding)
     {
-      MPlist *param = mplist_get (coding_definition_list, name);
+      MPlist *plist, *pl;
+      MSymbol sym = msymbol__canonicalize (name);
 
-      if (! param)
+      plist = mplist_find_by_key (coding_definition_list, sym);
+      if (! plist)
        return NULL;
-      param = mplist__from_plist (param);
-      mconv_define_coding (MSYMBOL_NAME (name), param, NULL, NULL, NULL, NULL);
+      pl = MPLIST_PLIST (plist);
+      name = MPLIST_VAL (pl);
+      mconv_define_coding (MSYMBOL_NAME (name), MPLIST_NEXT (pl),
+                          NULL, NULL, NULL, NULL);
       coding = (MCodingSystem *) msymbol_get (name, Mcoding);
-      M17N_OBJECT_UNREF (param);
+      plist = mplist_pop (plist);
+      M17N_OBJECT_UNREF (plist);
     }
   return coding;
 }
@@ -3003,31 +3008,19 @@ mcoding__fini (void)
 }
 
 void
-mconv__define_coding_from_charset (MSymbol sym)
-{
-  MPlist *param = mplist (), *charsets = mplist ();
-
-  mplist_set (charsets, Msymbol, sym);
-  mplist_add (param, Mtype, Mcharset);
-  mplist_add (param, Mcharsets, charsets);
-  mconv_define_coding (msymbol_name (sym), param, NULL, NULL, NULL, NULL);
-  M17N_OBJECT_UNREF (charsets);
-  M17N_OBJECT_UNREF (param);
-}
-
-void
 mconv__register_charset_coding (MSymbol sym)
 {
-  if (! mplist_find_by_key (coding_definition_list, sym))
+  MSymbol name = msymbol__canonicalize (sym);
+
+  if (! mplist_find_by_key (coding_definition_list, name))
     {
       MPlist *param = mplist (), *charsets = mplist ();
 
       mplist_set (charsets, Msymbol, sym);
-      mplist_add (param, Msymbol, Mtype);
-      mplist_add (param, Msymbol, Mcharset);
-      mplist_add (param, Msymbol, Mcharsets);
-      mplist_add (param, Mplist, charsets);
-      mplist_put (coding_definition_list, sym, param);
+      mplist_add (param, Msymbol, sym);
+      mplist_add (param, Mtype, Mcharset);
+      mplist_add (param, Mcharsets, charsets);
+      mplist_put (coding_definition_list, name, param);
       M17N_OBJECT_UNREF (charsets);
     }
 }
@@ -3054,7 +3047,7 @@ mcoding__load_from_database ()
   MPLIST_DO (plist, def_list)
     {
       MPlist *pl;
-      MSymbol name;
+      MSymbol name, canonicalized;
 
       if (! MPLIST_PLIST_P (plist))
        MERROR (MERROR_CHARSET, -1);
@@ -3062,9 +3055,10 @@ mcoding__load_from_database ()
       if (! MPLIST_SYMBOL_P (pl))
        MERROR (MERROR_CHARSET, -1);
       name = MPLIST_SYMBOL (pl);
-      pl = MPLIST_NEXT (pl);
-      definitions = mplist_add (definitions, name, pl);
-      M17N_OBJECT_REF (pl);
+      canonicalized = msymbol__canonicalize (name);
+      pl = mplist__from_plist (MPLIST_NEXT (pl));
+      mplist_push (pl, Msymbol, name);
+      definitions = mplist_add (definitions, canonicalized, pl);
     }
 
   M17N_OBJECT_UNREF (def_list);
@@ -3082,19 +3076,19 @@ mcoding__load_from_database ()
 /*** @{ */
 /*=*/
 
-/***en @name Variables: Symbols representing a coding system */
+/***en @name Variables: Symbols representing coding systems */
 /***ja @name ÊÑ¿ô: ÄêµÁºÑ¤ß¥³¡¼¥É·Ï¤ò»ØÄꤹ¤ë¤¿¤á¤Î¥·¥ó¥Ü¥ë */
 /*** @{ */
 /*=*/
 
 /***en
-    @brief Symbol for the coding system US-ASCII
+    @brief Symbol for the coding system US-ASCII.
 
     The symbol #Mcoding_us_ascii has name <tt>"us-ascii"</tt> and
     represents a coding system for the CES US-ASCII.  */
 
 /***ja
-    @brief  US-ASCII ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief US-ASCII ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_us_ascii ¤Ï <tt>"us-ascii"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES US-ASCII ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
@@ -3103,13 +3097,13 @@ MSymbol Mcoding_us_ascii;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system ISO-8859-1
+    @brief Symbol for the coding system ISO-8859-1.
 
     The symbol #Mcoding_iso_8859_1 has name <tt>"iso-8859-1"</tt> and
     represents a coding system for the CES ISO-8859-1.  */
 
 /***ja
-    @brief ISO-8859-1 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief ISO-8859-1 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_iso_8859_1 ¤Ï <tt>"iso-8859-1"</tt> ¤È¤¤¤¦Ì¾Á°
     ¤ò»ý¤Á¡¢CES ISO-8859-1 ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£  */
@@ -3118,13 +3112,13 @@ MSymbol Mcoding_iso_8859_1;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-8
+    @brief Symbol for the coding system UTF-8.
 
     The symbol #Mcoding_utf_8 has name <tt>"utf-8"</tt> and represents
     a coding system for the CES UTF-8.  */
 
 /***ja
-    @brief UTF-8 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-8 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_8 ¤Ï <tt>"utf-8"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢CES
     UTF-8 ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
@@ -3134,7 +3128,7 @@ MSymbol Mcoding_utf_8;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-8-FULL
+    @brief Symbol for the coding system UTF-8-FULL.
 
     The symbol #Mcoding_utf_8_full has name <tt>"utf-8-full"</tt> and
     represents a coding system that is a extension of UTF-8.  This
@@ -3143,7 +3137,7 @@ MSymbol Mcoding_utf_8;
     supported by the m17n library.  */
 
 /***ja
-    @brief UTF-8-FULL ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-8-FULL ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_8_full ¤Ï <tt>"utf-8-full"</tt> ¤È¤¤¤¦Ì¾Á°¤ò
     »ý¤Á¡¢<tt>"UTF-8"</tt> ¤Î³ÈÄ¥¤Ç¤¢¤ë¥³¡¼¥É·Ï¤ò¼¨¤¹¡£¤³¤Î¥³¡¼¥É·Ï¤Ï 
@@ -3156,12 +3150,12 @@ MSymbol Mcoding_utf_8_full;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-16
+    @brief Symbol for the coding system UTF-16.
 
     The symbol #Mcoding_utf_16 has name <tt>"utf-16"</tt> and
     represents a coding system for the CES UTF-16 (RFC 2279).  */
 /***ja
-    @brief UTF-16 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-16 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_16 ¤Ï <tt>"utf-16"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-16 (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£
@@ -3171,13 +3165,13 @@ MSymbol Mcoding_utf_16;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-16BE
+    @brief Symbol for the coding system UTF-16BE.
 
     The symbol #Mcoding_utf_16be has name <tt>"utf-16be"</tt> and
     represents a coding system for the CES UTF-16BE (RFC 2279).  */
 
 /***ja
-    @brief UTF-16BE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-16BE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_16be ¤Ï <tt>"utf-16be"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-16BE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
@@ -3186,13 +3180,13 @@ MSymbol Mcoding_utf_16be;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-16LE
+    @brief Symbol for the coding system UTF-16LE.
 
     The symbol #Mcoding_utf_16le has name <tt>"utf-16le"</tt> and
     represents a coding system for the CES UTF-16LE (RFC 2279).  */
 
 /***ja
-    @brief UTF-16LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-16LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_16le ¤Ï <tt>"utf-16le"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-16LE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
@@ -3201,13 +3195,13 @@ MSymbol Mcoding_utf_16le;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-32
+    @brief Symbol for the coding system UTF-32.
 
     The symbol #Mcoding_utf_32 has name <tt>"utf-32"</tt> and
     represents a coding system for the CES UTF-32 (RFC 2279).  */
 
 /***ja
-    @brief UTF-32 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-32 ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_32 ¤Ï <tt>"utf-32"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-32 (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
@@ -3216,12 +3210,12 @@ MSymbol Mcoding_utf_32;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-32be
+    @brief Symbol for the coding system UTF-32BE.
 
     The symbol #Mcoding_utf_32be has name <tt>"utf-32be"</tt> and
     represents a coding system for the CES UTF-32BE (RFC 2279).  */
 /***ja
-    @brief UTF-32be ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-32BE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_32be ¤Ï <tt>"utf-32be"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-32BE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
@@ -3230,12 +3224,12 @@ MSymbol Mcoding_utf_32be;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system UTF-32LE
+    @brief Symbol for the coding system UTF-32LE.
 
     The symbol #Mcoding_utf_32le has name <tt>"utf-32le"</tt> and
     represents a coding system for the CES UTF-32LE (RFC 2279).  */
 /***ja
-    @brief UTF-32LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief UTF-32LE ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_utf_32le ¤Ï <tt>"utf-32le"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES UTF-32LE (RFC 2279) ÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£     */
@@ -3244,12 +3238,12 @@ MSymbol Mcoding_utf_32le;
 /*=*/
 
 /***en
-    @brief Symbol for the coding system SJIS
+    @brief Symbol for the coding system SJIS.
 
     The symbol #Mcoding_sjis has name <tt>"sjis"</tt> and represents a coding
     system for the CES Shift-JIS.  */ 
 /***ja
-    @brief SJIS ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë
+    @brief SJIS ¥³¡¼¥É·Ï¤Î¥·¥ó¥Ü¥ë.
 
     ¥·¥ó¥Ü¥ë #Mcoding_sjis has ¤Ï <tt>"sjis"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
     CES Shift-JISÍѤΥ³¡¼¥É·Ï¤ò¼¨¤¹¡£  */ 
@@ -3283,7 +3277,7 @@ MSymbol Mlittle_endian;
 /*=*/
 
 /***en
-    @name Variables: Symbols representing coding system type.  */
+    @name Variables: Symbols representing coding system types.  */
 /***ja
     @name ÊÑ¿ô¡§ ¥³¡¼¥É·Ï¤Î¥¿¥¤¥×¤ò¼¨¤¹¥·¥ó¥Ü¥ë.  */
 /*** @{ */
@@ -3313,7 +3307,7 @@ MSymbol Miso_2022;
 /*=*/
 
 /***en
-    Symbol that can be a value of the #Mflags parameter of a coding
+    Symbols that can be a value of the #Mflags parameter of a coding
     system used in an argument to the mconv_define_coding () function
     (which see).  */
 /***ja 
@@ -3355,7 +3349,7 @@ MSymbol Mfull_support;
     used a value of #Mbom parameter of the function
     mconv_define_coding () (which see).  */
 /***ja
-    @brief "maybe"¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë
+    @brief "maybe"¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¥·¥ó¥Ü¥ë.
 
     ÊÑ¿ô #Mmaybe ¤Ï <tt>"maybe"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Ä¡£¤³¤ì¤Ï´Ø¿ô 
     mconv_define_coding () ¥Ñ¥é¥á¡¼¥¿ #Mbom ¤ÎÃͤȤ·¤ÆÍѤ¤¤é¤ì¤ë¡£(¾Ü
@@ -3365,14 +3359,14 @@ MSymbol Mmaybe;
 /*=*/
 
 /***en
-    @brief The symbol @c Mcoding
+    @brief The symbol @c Mcoding.
 
     Any decoded M-text has a text property whose key is the predefined
     symbol @c Mcoding.  The name of @c Mcoding is
     <tt>"coding"</tt>.  */
 
 /***ja
-    @brief ¥·¥ó¥Ü¥ë @c Mcoding
+    @brief ¥·¥ó¥Ü¥ë @c Mcoding.
 
     ¥Ç¥³¡¼¥É¤µ¤ì¤¿ M-text ¤Ï¤¹¤Ù¤Æ¡¢¥­¡¼¤¬ÄêµÁºÑ¤ß¥·¥ó¥Ü¥ë @c Mcoding 
     ¤Ç¤¢¤ë¤è¤¦¤Ê¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£¥·¥ó¥Ü¥ë @c Mcoding ¤Ï 
@@ -3384,7 +3378,7 @@ MSymbol Mcoding;
 /*=*/
 
 /***en
-    @brief Define a coding system
+    @brief Define a coding system.
 
     The mconv_define_coding () function defines a new coding system
     and makes it accessive via a symbol whose name is $NAME.  $PLIST
@@ -3598,10 +3592,10 @@ MSymbol Mcoding;
 
     ¥¿¥¤¥×¤¬ #Mcharset ¤Ê¤é¤Ð $EXTRA_INFO ¤Ï̵»ë¤µ¤ì¤ë¡£
 
-    ¥¿¥¤¥×¤¬ #Mutf ¤Ê¤é¤Ð $EXTRA_INFO ¤Ï#MCodingInfoUTF ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç
+    ¥¿¥¤¥×¤¬ #Mutf ¤Ê¤é¤Ð $EXTRA_INFO ¤Ï #MCodingInfoUTF ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç
     ¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
 
-    ¥¿¥¤¥×¤¬ #Miso_2022¤Ê¤é¤Ð $EXTRA_INFO ¤Ï#MCodingInfoISO2022 ¤Ø¤Î¥Ý
+    ¥¿¥¤¥×¤¬ #Miso_2022¤Ê¤é¤Ð $EXTRA_INFO ¤Ï #MCodingInfoISO2022 ¤Ø¤Î¥Ý
     ¥¤¥ó¥¿¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
 
     ¥¿¥¤¥×¤¬ #Mnil ¤Ê¤é¤Ð¡¢°ú¿ô $RESETTER, $DECODER, $ENCODER ¤òÍ¿¤¨¤Ê
@@ -3682,7 +3676,7 @@ MSymbol Mcoding;
 
     <li> #Miso_6429
 
-    ¸½¾õ¤Ç¤ÏÍѤ¤¤é¤ì¤Æ¤¤¤Ê¤¤¡£
+    ¸½»þÅÀ¤Ç¤ÏÍѤ¤¤é¤ì¤Æ¤¤¤Ê¤¤¡£
 
     <li> #Mrevision_number
 
@@ -3711,7 +3705,7 @@ MSymbol Mcoding;
     <li> ¥­¡¼¤¬ #Minvocation¤ÇÃͤ¬ plist ¤Î»þ
 
     ¥¿¥¤¥×¤¬ #Miso_2022 ¤Ê¤é¤Ð¡¢Ãͤϳƽ¸¹ç¤ò¤É¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤¹¤«¤ò¼¨¤¹¡£
-    plist ¤ÎŤµ¤Ï 1 ¤Ê¤¤¤· 2 ¤Ç¤¢¤ë¡£plist ¤Î¥­¡¼¤Ï#Minteger¡¢ÃͤϽ¸
+    plist ¤ÎŤµ¤Ï 1 ¤Ê¤¤¤· 2 ¤Ç¤¢¤ë¡£plist ¤Î¥­¡¼¤Ï #Minteger¡¢ÃͤϽ¸
     ¹ç¡Êgraphic register)¤ò¼¨¤¹¿ô»ú¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ºÇ½é¤ÎÍ×ÁǤÎÃÍ
     ¤¬¿Þ·Áʸ»ú½¸¹çº¸È¾Ì̤˸ƤӽФµ¤ì¤ë½¸¹ç¤Ç¤¢¤ë¡£ plist ¤ÎŤµ¤¬ 1 ¤Ê
     ¤é¤Ð¡¢±¦È¾Ì̤ˤϲ¿¤â¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£¤½¤¦¤Ç¤±¤ì¤Ð¡¢£²¤Ä¤á¤ÎÍ×ÁǤÎÃÍ
@@ -3732,7 +3726,7 @@ MSymbol Mcoding;
     <li> ¥­¡¼¤¬ #Mlittle_endian ¤ÇÃͤ¬¥·¥ó¥Ü¥ë¤Î»þ 
 
     ¥¿¥¤¥×¤¬ #Mutf ¤Ç¥³¡¼¥É¥æ¥Ë¥Ã¥È¤Î¥Ó¥Ã¥ÈŤ¬ 16 ¤« 32¤Ê¤é¤Ð¡¢Ãͤϥ¨
-    ¥ó¥³¡¼¥É¤¬ little endian ¤«¤É¤¦¤«¤ò¼¨¤¹¡£Ãͤ¬¥Ç¥Õ¥©¥ë¥ÈÃͤÎ#Mnil 
+    ¥ó¥³¡¼¥É¤¬ little endian ¤«¤É¤¦¤«¤ò¼¨¤¹¡£Ãͤ¬¥Ç¥Õ¥©¥ë¥ÈÃͤΠ#Mnil 
     ¤Ê¤é¤Ð big endian ¤Ç¤¢¤ê¡¢¤½¤¦¤Ç¤Ê¤±¤ì¤Ð little endian ¤Ç¤¢¤ë¡£
 
     </ul>
@@ -3744,7 +3738,7 @@ MSymbol Mcoding;
     $DECODER ¤Ï¥Ð¥¤¥ÈÎó¤ò¤³¤Î¥³¡¼¥É·Ï¤Ë½¾¤Ã¤Æ¥Ç¥³¡¼¥É¤¹¤ë´Ø¿ô¤Ø¤Î¥Ý¥¤
     ¥ó¥¿¤Ç¤¢¤ë¡£¤³¤Î´Ø¿ô¤Ï°Ê²¼¤Î4°ú¿ô¤ò¤È¤ë¡£
 
-       @li ¥Ð¥¤¥ÈÎó¤Ø¤Î¥Ý¥¤¥ó¥¿
+       @li ¥Ç¥³¡¼¥É¤¹¤ë¥Ð¥¤¥ÈÎó¤Ø¤Î¥Ý¥¤¥ó¥¿
        @li ¥Ç¥³¡¼¥É¤¹¤Ù¤­¥Ð¥¤¥È¿ô
        @li ¥Ç¥³¡¼¥É·ë²Ì¤Îʸ»ú¤òÉղ乤ë M-text ¤Ø¤Î¥Ý¥¤¥ó¥¿
        @li ¥³¥ó¥Ð¡¼¥¿¥ª¥Ö¥¸¥§¥¯¥È¤Ø¤Î¥Ý¥¤¥ó¥¿
@@ -3755,7 +3749,7 @@ MSymbol Mcoding;
     $ENCODER ¤Ï M-text ¤ò¤³¤Î¥³¡¼¥É·Ï¤Ë½¾¤Ã¤Æ¥¨¥ó¥³¡¼¥É¤¹¤ë´Ø¿ô¤Ø¤Î¥Ý
     ¥¤¥ó¥¿¤Ç¤¢¤ë¡£¤³¤Î´Ø¿ô¤Ï°Ê²¼¤Î6°ú¿ô¤ò¤È¤ë¡£
 
-        @li M-text ¤Ø¤Î¥Ý¥¤¥ó¥¿
+        @li ¥¨¥ó¥³¡¼¥É¤¹¤ëM-text ¤Ø¤Î¥Ý¥¤¥ó¥¿
         @li M-text ¤Î¥¨¥ó¥³¡¼¥É³«»Ï°ÌÃÖ
         @li M-text ¤Î¥¨¥ó¥³¡¼¥É½ªÎ»°ÌÃÖ
         @li À¸À®¤·¤¿¥Ð¥¤¥È¤òÊÝ»ý¤¹¤ë¥á¥â¥êÎΰè¤Ø¤Î¥Ý¥¤¥ó¥¿
@@ -3780,9 +3774,9 @@ MSymbol Mcoding;
     @c MERROR_CODING  */
 
 MSymbol
-mconv_define_coding (char *name, MPlist *plist,
+mconv_define_coding (const char *name, MPlist *plist,
                     int (*resetter) (MConverter *),
-                    int (*decoder) (unsigned char *, int, MText *,
+                    int (*decoder) (const unsigned char *, int, MText *,
                                     MConverter *),
                     int (*encoder) (MText *, int, int,
                                     unsigned char *, int,
@@ -4016,13 +4010,13 @@ mconv_resolve_coding (MSymbol symbol)
 
 
 /***en
-    @brief List symbols representing a coding system.
+    @brief List symbols representing coding systems.
 
     The mconv_list_codings () function makes an array of symbols
     representing a coding system, stores the pointer to the array in a
     place pointed to by $SYMBOLS, and returns the length of the array.  */
 /***ja
-    @brief ¥³¡¼¥É·Ï¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤òÎóµó¤¹¤ë
+    @brief ¥³¡¼¥É·Ï¤òɽ¤ï¤¹¥·¥ó¥Ü¥ë¤òÎóµó¤¹¤ë.
 
     ´Ø¿ô mchar_list_codings () ¤Ï¡¢¥³¡¼¥É·Ï¤ò¼¨¤¹¥·¥ó¥Ü¥ë¤òʤ٤¿ÇÛÎó
     ¤òºî¤ê¡¢$SYMBOLS ¤Ç¥Ý¥¤¥ó¥È¤µ¤ì¤¿¾ì½ê¤Ë¤³¤ÎÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÃÖ¤­¡¢
@@ -4038,7 +4032,10 @@ mconv_list_codings (MSymbol **symbols)
   MTABLE_MALLOC ((*symbols), i, MERROR_CODING);
   i = 0;
   MPLIST_DO (plist, coding_definition_list)
-    (*symbols)[i++] = MPLIST_KEY (plist);
+    {
+      MPlist *pl = MPLIST_VAL (plist);
+      (*symbols)[i++] = MPLIST_SYMBOL (pl);
+    }
   for (j = 0; j < coding_list.used; j++)
     if (! mplist_find_by_key (coding_definition_list, 
                              coding_list.codings[j]->name))
@@ -4052,11 +4049,11 @@ mconv_list_codings (MSymbol **symbols)
     @brief Create a code converter bound to a buffer.
 
     The mconv_buffer_converter () function creates a pointer to a code
-    converter for coding system $CODING.  The code converter is bound
+    converter for coding system $NAME.  The code converter is bound
     to buffer area of $N bytes pointed to by $BUF.  Subsequent
     decodings and encodings are done to/from this buffer area.
 
-    $CODING can be #Mnil.  In this case, a coding system associated
+    $NAME can be #Mnil.  In this case, a coding system associated
     with the current locale (LC_CTYPE) is used.
 
     @return
@@ -4065,14 +4062,14 @@ mconv_list_codings (MSymbol **symbols)
     assigns an error code to the external variable #merror_code.  */
 
 /***ja
-    @brief ¥Ð¥Ã¥Õ¥¡¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë
+    @brief ¥Ð¥Ã¥Õ¥¡¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë.
 
-    ´Ø¿ô mconv_buffer_converter () ¤Ï¡¢¥³¡¼¥É·Ï $CODING ÍѤΥ³¡¼¥É¥³¥ó
+    ´Ø¿ô mconv_buffer_converter () ¤Ï¡¢¥³¡¼¥É·Ï $NAME ÍѤΥ³¡¼¥É¥³¥ó
     ¥Ð¡¼¥¿¤òºî¤ë¡£¤³¤Î¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ï¡¢$BUF ¤Ç¼¨¤µ¤ì¤ëÂ礭¤µ $N ¥Ð
     ¥¤¥È¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤ë¡£¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó
     ¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤ËÂФ·¤Æ¹Ô¤Ê¤ï¤ì¤ë¡£
 
-    $CODING ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
+    $NAME ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
     (LC_CTYPE) ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥³¡¼¥É·Ï¤¬»È¤ï¤ì¤ë¡£
 
     @return
@@ -4129,28 +4126,28 @@ mconv_buffer_converter (MSymbol name, unsigned char *buf, int n)
 /***en
     @brief Create a code converter bound to a stream.
 
-    The mconv_stream_converter () function create a pointer to a code
-    converter for coding system $CODING.  The code converter is bound
+    The mconv_stream_converter () function creates a pointer to a code
+    converter for coding system $NAME.  The code converter is bound
     to stream $FP.  Subsequent decodings and encodings are done
     to/from this stream.
 
-    $CODING can be #Mnil.  In this case, a coding system associated
+    $NAME can be #Mnil.  In this case, a coding system associated
     with the current locale (LC_CTYPE) is used.
 
     @return If the operation was successful, mconv_stream_converter ()
     returns the created code converter.  Otherwise it returns @c NULL
-    and assigns an error code to the external variable @c
-    merror_code.  */
+    and assigns an error code to the external variable 
+    #merror_code.  */
 
 /***ja
-    @brief ¥¹¥È¥ê¡¼¥à¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë
+    @brief ¥¹¥È¥ê¡¼¥à¤Ë·ë¤ÓÉÕ¤±¤é¤ì¤¿¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤òºî¤ë.
 
-    ´Ø¿ô mconv_stream_converter () ¤Ï¡¢¥³¡¼¥É·Ï $CODING ÍѤΥ³¡¼¥É¥³¥ó
+    ´Ø¿ô mconv_stream_converter () ¤Ï¡¢¥³¡¼¥É·Ï $NAME ÍѤΥ³¡¼¥É¥³¥ó
     ¥Ð¡¼¥¿¤òºî¤ë¡£¤³¤Î¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP ¤Ë·ë¤ÓÉÕ¤±¤é
     ¤ì¤ë¡£¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢¤³¤Î¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ
     ¹Ô¤Ê¤ï¤ì¤ë¡£
 
-    $CODING ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
+    $NAME ¤Ï #Mnil ¤Ç¤¢¤Ã¤Æ¤â¤è¤¤¡£¤³¤Î¾ì¹ç¤Ï¸½ºß¤Î¥í¥±¡¼¥ë 
     (LC_CTYPE) ¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥³¡¼¥É·Ï¤¬»È¤ï¤ì¤ë¡£
 
     @return 
@@ -4226,7 +4223,7 @@ mconv_stream_converter (MSymbol name, FILE *fp)
     applied to $CONVERTER.  Otherwise it returns 0.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò¥ê¥»¥Ã¥È¤¹¤ë
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò¥ê¥»¥Ã¥È¤¹¤ë.
 
     ´Ø¿ô mconv_reset_converter () ¤Ï¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤ò½é´ü
     ¾õÂÖ¤ËÌ᤹¡£
@@ -4259,7 +4256,7 @@ mconv_reset_converter (MConverter *converter)
     $CONVERTER.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò²òÊü¤¹¤ë
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò²òÊü¤¹¤ë.
 
     ´Ø¿ô mconv_free_converter () ¤Ï¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤ò²òÊü
     ¤¹¤ë¡£  */
@@ -4289,7 +4286,7 @@ mconv_free_converter (MConverter *converter)
     This function always returns $CONVERTER.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥Ð¥Ã¥Õ¥¡Îΰè¤ò·ë¤ÓÉÕ¤±¤ë
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥Ð¥Ã¥Õ¥¡Îΰè¤ò·ë¤ÓÉÕ¤±¤ë.
 
     ´Ø¿ô mconv_rebind_buffer () ¤Ï¡¢$BUF ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤¿Â礭¤µ $N ¥Ð
     ¥¤¥È¤Î¥Ð¥Ã¥Õ¥¡Îΰè¤ò¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ë·ë¤ÓÉÕ¤±¤ë¡£¤³¤ì
@@ -4330,7 +4327,7 @@ mconv_rebind_buffer (MConverter *converter, unsigned char *buf, int n)
     This function always returns $CONVERTER.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥¹¥È¥ê¡¼¥à¤ò·ë¤ÓÉÕ¤±¤ë
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë¥¹¥È¥ê¡¼¥à¤ò·ë¤ÓÉÕ¤±¤ë.
 
     ´Ø¿ô mconv_rebind_stream () ¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP ¤ò¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ 
     $CONVERTER ¤Ë·ë¤ÓÉÕ¤±¤ë¡£¤³¤ì°Ê¹ß¤Î¥Ç¥³¡¼¥É¤ª¤è¤Ó¥¨¥ó¥³¡¼¥É¤Ï¡¢
@@ -4370,7 +4367,8 @@ mconv_rebind_stream (MConverter *converter, FILE *fp)
 
     The mconv_decode () function decodes a byte sequence and appends
     the result at the end of M-text $MT.  The source byte sequence is
-    taken from currently bound the buffer area or the stream.
+    taken from either the buffer area or the stream that is currently
+    bound to $CONVERTER.
 
     @return
     If the operation was successful, mconv_decode () returns updated
@@ -4378,11 +4376,11 @@ mconv_rebind_stream (MConverter *converter, FILE *fp)
     the external variable #merror_code.  */
 
 /***ja
-    @brief ¥Ð¥¤¥ÈÎó¤ò M-text ¤Ë¥Ç¥³¡¼¥É¤¹¤ë
+    @brief ¥Ð¥¤¥ÈÎó¤ò M-text ¤Ë¥Ç¥³¡¼¥É¤¹¤ë.
 
     ´Ø¿ô mconv_decode () ¤Ï¡¢¥Ð¥¤¥ÈÎó¤ò¥Ç¥³¡¼¥É¤·¤Æ¤½¤Î·ë²Ì¤ò M-text
-    $MT ¤ÎËöÈø¤ËÄɲ乤롣¥Ç¥³¡¼¥É¸µ¤Î¥Ð¥¤¥ÈÎó¤Ï¡¢¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë
-    ¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é¼è¤é¤ì¤ë¡£
+    $MT ¤ÎËöÈø¤ËÄɲ乤롣¥Ç¥³¡¼¥É¸µ¤Î¥Ð¥¤¥ÈÎó¤Ï¡¢$CONVERTER ¤Ë¸½ºß·ë
+    ¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é¼è¤é¤ì¤ë¡£
 
     @return
     ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_decode () ¤Ï¹¹¿·¤µ¤ì¤¿ $MT ¤òÊÖ¤¹¡£¤½
@@ -4407,6 +4405,9 @@ mconv_decode (MConverter *converter, MText *mt)
 
   M_CHECK_READONLY (mt, NULL);
 
+  if (mt->format != MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+
   if (! mt->data)
     mtext__enlarge (mt, MAX_UTF8_CHAR_BYTES);
 
@@ -4506,7 +4507,7 @@ mconv_decode (MConverter *converter, MText *mt)
 /***en
     @brief Decode a buffer area based on a coding system.
 
-    The mconv_decode_buffer () function decodes $N bytes of buffer
+    The mconv_decode_buffer () function decodes $N bytes of the buffer
     area pointed to by $BUF based on the coding system $NAME.  A
     temporary code converter for decoding is automatically created
     and freed.
@@ -4517,7 +4518,7 @@ mconv_decode (MConverter *converter, MText *mt)
     assigns an error code to the external variable #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤ò¥Ç¥³¡¼¥É¤¹¤ë
+    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤ò¥Ç¥³¡¼¥É¤¹¤ë.
 
     ´Ø¿ô mconv_decode_buffer () ¤Ï¡¢$BUF ¤Ë¤è¤Ã¤Æ»Ø¤µ¤ì¤¿ $N ¥Ð¥¤¥È¤Î
     ¥Ð¥Ã¥Õ¥¡Îΰè¤ò¡¢¥³¡¼¥É·Ï $NAME ¤Ë´ð¤Å¤¤¤Æ¥Ç¥³¡¼¥É¤¹¤ë¡£¥Ç¥³¡¼¥É¤Ë
@@ -4568,7 +4569,7 @@ mconv_decode_buffer (MSymbol name, unsigned char *buf, int n)
     error code to the external variable #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥¹¥È¥ê¡¼¥àÆþÎϤò¥Ç¥³¡¼¥É¤¹¤ë
+    @brief ¥³¡¼¥É·Ï¤Ë´ð¤Å¤¤¤Æ¥¹¥È¥ê¡¼¥àÆþÎϤò¥Ç¥³¡¼¥É¤¹¤ë.
 
     ´Ø¿ô mconv_decode_stream () ¤Ï¡¢¥¹¥È¥ê¡¼¥à $FP ¤«¤éÆɤ߹þ¤Þ¤ì¤ë¥Ð
     ¥¤¥ÈÎóÁ´ÂΤò¡¢¥³¡¼¥É·Ï $NAME ¤Ë´ð¤Å¤¤¤Æ¥Ç¥³¡¼¥É¤¹¤ë¡£¥Ç¥³¡¼¥É¤Ëɬ
@@ -4618,11 +4619,11 @@ mconv_decode_stream (MSymbol name, FILE *fp)
     error code to the external variable #merror_code.  */
 
 /***ja
-    @brief M-text ¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë
+    @brief M-text ¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë.
 
     ´Ø¿ô mconv_encode () ¤Ï¡¢M-text $MT ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼
     ¥¿ $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼
-    ¥à¤Ë½ñ¤­¹þ¤à¡£
+    ¥à¤ËÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò½ñ¤­¹þ¤à¡£
 
     @return
     ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode () ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
@@ -4646,7 +4647,7 @@ mconv_encode (MConverter *converter, MText *mt)
 /*=*/
 
 /***en
-    @brief Encode a part of an M-text
+    @brief Encode a part of an M-text.
 
     The mconv_encode_range () function encodes the text between $FROM
     (inclusive) and $TO (exclusive) in M-text $MT and writes the
@@ -4659,12 +4660,12 @@ mconv_encode (MConverter *converter, MText *mt)
     error code to the external variable #merror_code.  */
 
 /***ja
-    @brief M-text ¤Î°ìÉô¤ò¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë
+    @brief M-text ¤Î°ìÉô¤ò¥Ð¥¤¥ÈÎó¤Ë¥¨¥ó¥³¡¼¥É¤¹¤ë.
 
     ´Ø¿ô mconv_encode_range () ¤Ï¡¢M-text $MT ¤Î $FROM ¡Ê´Þ¤à¡Ë¤«¤é 
     $TO ¡Ê´Þ¤Þ¤Ê¤¤¡Ë¤Þ¤Ç¤ÎÈϰϤΥƥ­¥¹¥È¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼
     ¥¿ $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼
-    ¥à¤Ë½ñ¤­¹þ¤à¡£
+    ¥à¤ËÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò½ñ¤­¹þ¤à¡£
 
     @return
     ¤â¤·½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_encode_range () ¤Ï½ñ¤­¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô
@@ -4759,7 +4760,7 @@ mconv_encode_range (MConverter *converter, MText *mt, int from, int to)
     an error code to the external variable #merror_code.  */
 
 /***ja
-    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤Ë½ñ¤­¹þ¤à
+    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥Ð¥Ã¥Õ¥¡Îΰè¤Ë½ñ¤­¹þ¤à.
 
     ´Ø¿ô mconv_encode_buffer () ¤ÏM-text $MT ¤ò¥³¡¼¥É·Ï $NAME ¤Ë´ð¤Å¤¤
     ¤Æ¥¨¥ó¥³¡¼¥É¤·¡¢ÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò $BUF ¤Î»Ø¤¹¥Ð¥Ã¥Õ¥¡Îΰè¤Ë½ñ¤­¹þ
@@ -4807,7 +4808,7 @@ mconv_encode_buffer (MSymbol name, MText *mt, unsigned char *buf, int n)
     an error code to the external variable #merror_code.  */
 
 /***ja
-    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥¹¥È¥ê¡¼¥à¤Ë½ñ¤­¹þ¤à
+    @brief M-text ¤ò¥¨¥ó¥³¡¼¥É¤·¤Æ¥¹¥È¥ê¡¼¥à¤Ë½ñ¤­¹þ¤à.
 
     ´Ø¿ô mconv_encode_stream () ¤ÏM-text $MT ¤ò¥³¡¼¥É·Ï $NAME ¤Ë´ð¤Å¤¤
     ¤Æ¥¨¥ó¥³¡¼¥É¤·¡¢ÆÀ¤é¤ì¤¿¥Ð¥¤¥ÈÎó¤ò¥¹¥È¥ê¡¼¥à $FP ¤Ë½ñ¤­½Ð¤¹¡£¥¨¥ó
@@ -4857,11 +4858,11 @@ mconv_encode_stream (MSymbol name, MText *mt, FILE *fp)
     #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿·Ðͳ¤Ç1ʸ»úÆɤà
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿·Ðͳ¤Ç1ʸ»úÆɤà.
 
     ´Ø¿ô mconv_getc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±
-    ¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é1ʸ»ú¤òÆɤ߹þ¤à¡£¥Ð¥¤
-    ¥ÈÎó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£$CONVERTER 
+    ¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é 1 Ê¸»ú¤òÆɤ߹þ¤à¡£¥Ð
+    ¥¤¥ÈÎó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£$CONVERTER 
     ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
 
     @return
@@ -4911,7 +4912,7 @@ mconv_getc (MConverter *converter)
     external variable #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë1ʸ»úÌ᤹
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤Ë1ʸ»úÌ᤹.
 
     ´Ø¿ô mconv_ungetc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ëʸ»ú $C ¤ò
     ²¡¤·Ì᤹¡£Ì᤹ʸ»ú¿ô¤ËÀ©¸Â¤Ï¤Ê¤¤¡£¤³¤Î¸å¤Ë mconv_getc () ¤ò¸Æ¤Ó½Ð
@@ -4960,7 +4961,7 @@ mconv_ungetc (MConverter *converter, int c)
     an error code to the external variable #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò·Ðͳ¤Ç1ʸ»ú½ñ¤¯
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò·Ðͳ¤·¤Æ1ʸ»ú½ñ¤¯.
 
     ´Ø¿ô mconv_putc () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±
     ¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤Ëʸ»ú $C ¤ò½ñ¤­½Ð¤¹¡£Ê¸»ú
@@ -5009,17 +5010,17 @@ mconv_putc (MConverter *converter, int c)
     If the operation was successful, mconv_gets () returns the
     modified $MT.  If it encounters EOF without reading a single
     character, it returns $MT without changing it.  If an error is
-    detected, it returns @c NULL and assigns an error code to @c
-    merror_code.  */
+    detected, it returns @c NULL and assigns an error code to 
+    #merror_code.  */
 
 /***ja
-    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò»È¤Ã¤Æ1¹ÔÆɤà
+    @brief ¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿¤ò»È¤Ã¤Æ1¹ÔÆɤà.
 
     ´Ø¿ô mconv_gets () ¤Ï¡¢¥³¡¼¥É¥³¥ó¥Ð¡¼¥¿ $CONVERTER ¤Ë¸½ºß·ë¤ÓÉÕ¤±
-    ¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é1¹Ô¤òÆɤ߹þ¤à¡£¥Ð¥¤¥È
-    Îó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£¥Ç¥³¡¼¥É¤µ¤ì¤¿
-    Ê¸»úÎó¤Ï M-text $MT ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£¸µ¤Î¥Ð¥¤¥ÈÎó¤Î½ªÃ¼²þ¹Ôʸ»ú
-    ¤ÏÄɲ䵤ì¤Ê¤¤¡£$CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
+    ¤é¤ì¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡Îΰ褢¤ë¤¤¤Ï¥¹¥È¥ê¡¼¥à¤«¤é 1 ¹Ô¤òÆɤ߹þ¤à¡£¥Ð¥¤
+    ¥ÈÎó¤Î¥Ç¥³¡¼¥É¤Ë¤Ï $CONVERTER ¤Î¥Ç¥³¡¼¥À¤¬ÍѤ¤¤é¤ì¤ë¡£¥Ç¥³¡¼¥É¤µ¤ì
+    ¤¿Ê¸»úÎó¤Ï M-text $MT ¤ÎËöÈø¤ËÄɲ䵤ì¤ë¡£¸µ¤Î¥Ð¥¤¥ÈÎó¤Î½ªÃ¼²þ¹Ôʸ
+    »ú¤ÏÄɲ䵤ì¤Ê¤¤¡£$CONVERTER ¤ÎÆâÉô¾õÂÖ¤ÏɬÍפ˱þ¤¸¤Æ¹¹¿·¤µ¤ì¤ë¡£
 
     @return
     ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mconv_gets () ¤ÏÊѹ¹¤µ¤ì¤¿ $MT ¤òÊÖ¤¹¡£¤â¤·1ʸ»ú
@@ -5040,6 +5041,9 @@ mconv_gets (MConverter *converter, MText *mt)
   int c;
 
   M_CHECK_READONLY (mt, NULL);
+  if (mt->format != MTEXT_FORMAT_UTF_8)
+    mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
+
   while (1)
     {
       c = mconv_getc (converter);
@@ -5048,7 +5052,7 @@ mconv_gets (MConverter *converter, MText *mt)
       mtext_cat_char (mt, c);
     }
   if (c == EOF && converter->result != MCONVERSION_RESULT_SUCCESS)
-    /* mconv_getc () sets merror_code */
+    /* mconv_getc () sets #merror_code */
     return NULL;
   return mt;
 }