Merge commit 'origin/stable'
[pspp-builds.git] / src / libpspp / i18n.c
index 74ec1f1fdeb18c0116c95d8e30b6e12cd57381e6..64aa005612627bbc223b155abc5075e8c32e9186 100644 (file)
@@ -57,7 +57,7 @@ create_iconv (const char* tocode, const char* fromcode)
   struct hmapx_node *node;
   struct converter *converter;
 
-  hash = hsh_hash_string (tocode) ^ hsh_hash_string (fromcode);
+  hash = hash_string (tocode, hash_string (fromcode, 0));
   HMAPX_FOR_EACH_WITH_HASH (converter, node, hash, &map)
     if (!strcmp (tocode, converter->tocode)
         && !strcmp (fromcode, converter->fromcode))
@@ -68,7 +68,7 @@ create_iconv (const char* tocode, const char* fromcode)
   converter->fromcode = xstrdup (fromcode);
   converter->conv = iconv_open (tocode, fromcode);
   hmapx_insert (&map, converter, hash);
-  
+
   /* I don't think it's safe to translate this string or to use messaging
      as the convertors have not yet been set up */
   if ( (iconv_t) -1 == converter->conv && 0 != strcmp (tocode, fromcode))
@@ -128,6 +128,9 @@ recode_string (const char *to, const char *from,
 
   conv = create_iconv (to, from);
 
+  if ( (iconv_t) -1 == conv )
+       return xstrdup (text);
+
   do {
     const char *ip = text;
     result = iconv (conv, (ICONV_CONST char **) &text, &inbytes,
@@ -161,6 +164,7 @@ recode_string (const char *to, const char *from,
            break;
          default:
            /* should never happen */
+            fprintf (stderr, "Character conversion error: %s\n", strerror (the_error));
            NOT_REACHED ();
            break;
          }
@@ -186,7 +190,7 @@ i18n_init (void)
 {
 #if ENABLE_NLS
   setlocale (LC_CTYPE, "");
-#if HAVE_LC_MESSAGES
+#ifdef LC_MESSAGES
   setlocale (LC_MESSAGES, "");
 #endif
 #if HAVE_LC_PAPER
@@ -263,9 +267,12 @@ void
 i18n_done (void)
 {
   struct hmapx_node *node;
-  iconv_t conv;
-  HMAPX_FOR_EACH (conv, node, &map)
-    iconv_close (conv);
+  struct converter *cvtr;
+  HMAPX_FOR_EACH (cvtr, node, &map)
+    {
+      iconv_close (cvtr->conv);
+      free (cvtr);
+    }
 
   hmapx_destroy (&map);