(fc_decode_prop): Fix for the case of too large VAL.
[m17n/m17n-lib.git] / src / symbol.c
index c3bf5c8..75ef4f1 100644 (file)
@@ -1,5 +1,5 @@
 /* symbol.c -- symbol module.
-   Copyright (C) 2003, 2004
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -179,8 +179,8 @@ msymbol__free_table ()
        }
       symbol_table[i] = NULL;
     }
-  if (mdebug__flag & MDEBUG_FINI)
-    fprintf (stderr, "%16s %7d %7d %7d\n", "Symbol",
+  if (mdebug__flags[MDEBUG_FINI])
+    fprintf (mdebug__output, "%16s %7d %7d %7d\n", "Symbol",
             num_symbols, freed_symbols, num_symbols - freed_symbols);
   num_symbols = 0;
 }
@@ -220,13 +220,14 @@ msymbol__list (MSymbol prop)
        o convert all uppercase characters to lowercase.
        o remove all non alpha-numeric characters.
        o change the leading "ibm" to "cp".
-       o change the leading "cp" to "ibm"
+       o change the leading "windows-" to "cp".
+       o change the leading "cp" to "ibm".
        o remove the leading "iso".
     For instance:
        "ISO-8859-2" -> "88592"
        "euc-JP" -> "eucjp"
        "IBM851" -> "cp851"
-       "CP1250" -> "ibm1250"
+       "windows-1250" -> "cp250"
 
     This function is used to canonicalize charset and coding system
     names.  */
@@ -269,7 +270,15 @@ msymbol__canonicalize (MSymbol sym)
       canon[1] = 'b';
       canon[2] = 'm';
     }
-
+  else if (canon[0] == 'w' && p - canon > 7
+          && memcmp (canon + 1, "indows", 6) == 0
+          && isdigit (canon[7]))
+    {
+      /* Change "windowsXXX" to "cpXXX" */
+      canon += 5;
+      canon[0] = 'c';
+      canon[1] = 'p';
+    }
   return msymbol (canon);
 }
 
@@ -483,7 +492,8 @@ msymbol_as_managing_key (const char *name)
     The msymbol_is_managing_key () function checks if the symbol
     $SYMBOL is a managing key or not.
 
-    @return Return 1 if the symbol is a managing key.  Otherwise,
+    @return 
+    Return 1 if the symbol is a managing key.  Otherwise,
     return 0.  */
 
 int
@@ -676,7 +686,8 @@ msymbol_get (MSymbol symbol, MSymbol key)
     ¤½¤ÎÃͤϴؿô¥Ý¥¤¥ó¥¿ $FUNC ¤Ç¤¢¤ë¡£ */
 
 /***
-    @seealso msymbol_put (), M17N_FUNC ()  */
+    @seealso
+     msymbol_put (), M17N_FUNC ()  */
 int
 msymbol_put_func (MSymbol symbol, MSymbol key, M17NFunc func)
 {
@@ -724,9 +735,10 @@ msymbol_get_func (MSymbol symbol, MSymbol key)
 /***en
     @brief Dump a symbol.
 
-    The mdebug_dump_symbol () function prints symbol $SYMBOL in a human
-    readable way to the stderr.  $INDENT specifies how many columns to
-    indent the lines but the first one.
+    The mdebug_dump_symbol () function prints symbol $SYMBOL in a
+    human readable way to the stderr or to what specified by the
+    environment variable MDEBUG_OUTPUT_FILE.  $INDENT specifies how
+    many columns to indent the lines but the first one.
 
     @return
     This function returns $SYMBOL.
@@ -736,8 +748,9 @@ msymbol_get_func (MSymbol symbol, MSymbol key)
 /***ja
     @brief ¥·¥ó¥Ü¥ë¤ò¥À¥ó¥×¤¹¤ë.
 
-    ´Ø¿ô mdebug_dump_symbol () ¤Ï¥·¥ó¥Ü¥ë $symbol ¤ò stderr 
-    ¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+    ´Ø¿ô mdebug_dump_symbol () ¤Ï¥·¥ó¥Ü¥ë $symbol ¤òɸ½à¥¨¥é¡¼½ÐÎϤ⤷
+    ¤¯¤Ï´Ä¶­ÊÑ¿ô MDEBUG_DUMP_FONT ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë¿Í´Ö¤Ë²ÄÆɤʷÁ
+    ¤Ç°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
 
     @return
     ¤³¤Î´Ø¿ô¤Ï $SYMBOL ¤òÊÖ¤¹¡£ 
@@ -763,10 +776,10 @@ mdebug_dump_symbol (MSymbol symbol, int indent)
   else
     plist = &symbol->plist, name = symbol->name;
 
-  fprintf (stderr, "%s%s", prefix, name);
+  fprintf (mdebug__output, "%s%s", prefix, name);
   while (plist && MPLIST_KEY (plist) != Mnil)
     {
-      fprintf (stderr, ":%s", MPLIST_KEY (plist)->name);
+      fprintf (mdebug__output, ":%s", MPLIST_KEY (plist)->name);
       plist = MPLIST_NEXT (plist);
     }
   return symbol;
@@ -776,8 +789,9 @@ mdebug_dump_symbol (MSymbol symbol, int indent)
     @brief Dump all symbol names.
 
     The mdebug_dump_all_symbols () function prints names of all
-    symbols to the stderr.  $INDENT specifies how many columns to
-    indent the lines but the first one.
+    symbols to the stderr or to what specified by the environment
+    variable MDEBUG_OUTPUT_FILE.  $INDENT specifies how many columns
+    to indent the lines but the first one.
 
     @return
     This function returns #Mnil.
@@ -787,8 +801,9 @@ mdebug_dump_symbol (MSymbol symbol, int indent)
 /***ja
     @brief ¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë̾¤ò¥À¥ó¥×¤¹¤ë.
 
-    ´Ø¿ô mdebug_dump_all_symbols () ¤Ï¡¢¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë¤Î̾Á°¤ò 
-    stderr ¤Ë°õºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
+    ´Ø¿ô mdebug_dump_all_symbols () ¤Ï¡¢¤¹¤Ù¤Æ¤Î¥·¥ó¥Ü¥ë¤Î̾Á°¤òɸ½à¥¨
+    ¥é¡¼½ÐÎϤ⤷¤¯¤Ï´Ä¶­ÊÑ¿ô MDEBUG_DUMP_FONT ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë°õ
+    ºþ¤¹¤ë¡£ $INDENT ¤Ï£²¹ÔÌܰʹߤΥ¤¥ó¥Ç¥ó¥È¤ò»ØÄꤹ¤ë¡£
 
     @return
     ¤³¤Î´Ø¿ô¤Ï #Mnil ¤òÊÖ¤¹¡£ 
@@ -810,17 +825,17 @@ mdebug_dump_all_symbols (int indent)
   memset (prefix, 32, indent);
   prefix[indent] = 0;
 
-  fprintf (stderr, "(symbol-list");
+  fprintf (mdebug__output, "(symbol-list");
   for (i = n = 0; i < SYMBOL_TABLE_SIZE; i++)
     if ((sym = symbol_table[i]))
       {
-       fprintf (stderr, "\n%s  (%4d", prefix, i);
+       fprintf (mdebug__output, "\n%s  (%4d", prefix, i);
        for (; sym; sym = sym->next, n++)
-         fprintf (stderr, " '%s'", sym->name);
-       fprintf (stderr, ")");
+         fprintf (mdebug__output, " '%s'", sym->name);
+       fprintf (mdebug__output, ")");
       }
-  fprintf (stderr, "\n%s  (total %d)", prefix, n);
-  fprintf (stderr, ")");
+  fprintf (mdebug__output, "\n%s  (total %d)", prefix, n);
+  fprintf (mdebug__output, ")");
   return Mnil;
 }