Fixed some issues with internationalisation
[pspp-builds.git] / intl / dcigettext.c
index f6edb95c005996f72716d29a35fa3918752c49f5..f2f01524c03c667818cb752380a7122b470f124d 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the internal dcigettext function.
-   Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000-2002 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published
 # define alloca __builtin_alloca
 # define HAVE_ALLOCA 1
 #else
-# ifdef _MSC_VER
-#  include <malloc.h>
-#  define alloca _alloca
+# if defined HAVE_ALLOCA_H || defined _LIBC
+#  include <alloca.h>
 # else
-#  if defined HAVE_ALLOCA_H || defined _LIBC
-#   include <alloca.h>
-#  else
-#   ifdef _AIX
+#  ifdef _AIX
  #pragma alloca
-#   else
-#    ifndef alloca
+#  else
+#   ifndef alloca
 char *alloca ();
-#    endif
 #   endif
 #  endif
 # endif
@@ -276,13 +271,6 @@ transcmp (p1, p2)
 }
 #endif
 
-#ifndef INTVARDEF
-# define INTVARDEF(name)
-#endif
-#ifndef INTUSE
-# define INTUSE(name) name
-#endif
-
 /* Name of the default domain used for gettext(3) prior any call to
    textdomain(3).  The default value for this is "messages".  */
 const char _nl_default_default_domain[] attribute_hidden = "messages";
@@ -296,7 +284,6 @@ const char *_nl_current_default_domain attribute_hidden
 extern const char _nl_default_dirname[];
 #else
 const char _nl_default_dirname[] = LOCALEDIR;
-INTVARDEF (_nl_default_dirname)
 #endif
 
 /* List with bindings of specific domains created by bindtextdomain()
@@ -309,15 +296,10 @@ static char *plural_lookup PARAMS ((struct loaded_l10nfile *domain,
                                    const char *translation,
                                    size_t translation_len))
      internal_function;
+static const char *category_to_name PARAMS ((int category)) internal_function;
 static const char *guess_category_value PARAMS ((int category,
                                                 const char *categoryname))
      internal_function;
-#ifdef _LIBC
-# include "../locale/localeinfo.h"
-# define category_to_name(category)    _nl_category_names[category]
-#else
-static const char *category_to_name PARAMS ((int category)) internal_function;
-#endif
 
 
 /* For those loosing systems which don't have `alloca' we have to add
@@ -455,15 +437,6 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
   if (msgid1 == NULL)
     return NULL;
 
-#ifdef _LIBC
-  if (category < 0 || category >= __LC_LAST || category == LC_ALL)
-    /* Bogus.  */
-    return (plural == 0
-           ? (char *) msgid1
-           /* Use the Germanic plural rule.  */
-           : n == 1 ? (char *) msgid1 : (char *) msgid2);
-#endif
-
   __libc_rwlock_rdlock (_nl_state_lock);
 
   /* If DOMAINNAME is NULL, we are interested in the default domain.  If
@@ -527,7 +500,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
     }
 
   if (binding == NULL)
-    dirname = (char *) INTUSE(_nl_default_dirname);
+    dirname = (char *) _nl_default_dirname;
   else if (IS_ABSOLUTE_PATH (binding->dirname))
     dirname = binding->dirname;
   else
@@ -555,9 +528,17 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
        }
 
       if (ret == NULL)
-       /* We cannot get the current working directory.  Don't signal an
-          error but simply return the default string.  */
-       goto return_untranslated;
+       {
+         /* We cannot get the current working directory.  Don't signal an
+            error but simply return the default string.  */
+         FREE_BLOCKS (block_list);
+         __libc_rwlock_unlock (_nl_state_lock);
+         __set_errno (saved_errno);
+         return (plural == 0
+                 ? (char *) msgid1
+                 /* Use the Germanic plural rule.  */
+                 : n == 1 ? (char *) msgid1 : (char *) msgid2);
+       }
 
       stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname);
     }
@@ -614,7 +595,16 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
         domain.  Return the MSGID.  */
       if (strcmp (single_locale, "C") == 0
          || strcmp (single_locale, "POSIX") == 0)
-       break;
+       {
+         FREE_BLOCKS (block_list);
+         __libc_rwlock_unlock (_nl_state_lock);
+         __set_errno (saved_errno);
+         return (plural == 0
+                 ? (char *) msgid1
+                 /* Use the Germanic plural rule.  */
+                 : n == 1 ? (char *) msgid1 : (char *) msgid2);
+       }
+
 
       /* Find structure describing the message catalog matching the
         DOMAINNAME and CATEGORY.  */
@@ -646,6 +636,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
              /* Found the translation of MSGID1 in domain DOMAIN:
                 starting at RETVAL, RETLEN bytes.  */
              FREE_BLOCKS (block_list);
+             __set_errno (saved_errno);
 #if defined HAVE_TSEARCH || defined _LIBC
              if (foundp == NULL)
                {
@@ -684,8 +675,6 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
                  (*foundp)->translation_length = retlen;
                }
 #endif
-             __set_errno (saved_errno);
-
              /* Now deal with plural.  */
              if (plural)
                retval = plural_lookup (domain, n, retval, retlen);
@@ -695,30 +684,7 @@ DCIGETTEXT (domainname, msgid1, msgid2, plural, n, category)
            }
        }
     }
-
- return_untranslated:
-  /* Return the untranslated MSGID.  */
-  FREE_BLOCKS (block_list);
-  __libc_rwlock_unlock (_nl_state_lock);
-#ifndef _LIBC
-  if (!ENABLE_SECURE)
-    {
-      extern void _nl_log_untranslated PARAMS ((const char *logfilename,
-                                               const char *domainname,
-                                               const char *msgid1,
-                                               const char *msgid2,
-                                               int plural));
-      const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED");
-
-      if (logfilename != NULL && logfilename[0] != '\0')
-       _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural);
-    }
-#endif
-  __set_errno (saved_errno);
-  return (plural == 0
-         ? (char *) msgid1
-         /* Use the Germanic plural rule.  */
-         : n == 1 ? (char *) msgid1 : (char *) msgid2);
+  /* NOTREACHED */
 }
 
 
@@ -1072,7 +1038,7 @@ plural_lookup (domain, n, translation, translation_len)
   return (char *) p;
 }
 
-#ifndef _LIBC
+
 /* Return string representation of locale CATEGORY.  */
 static const char *
 internal_function
@@ -1132,7 +1098,6 @@ category_to_name (category)
 
   return retval;
 }
-#endif
 
 /* Guess value of current locale from value of the environment variables.  */
 static const char *
@@ -1155,7 +1120,7 @@ guess_category_value (category, categoryname)
      `LC_xxx', and `LANG'.  On some systems this can be done by the
      `setlocale' function itself.  */
 #ifdef _LIBC
-  retval = __current_locale_name (category);
+  retval = setlocale (category, NULL);
 #else
   retval = _nl_locale_name (category, categoryname);
 #endif
@@ -1205,7 +1170,8 @@ mempcpy (dest, src, n)
 #ifdef _LIBC
 /* If we want to free all resources we have to do some work at
    program's end.  */
-libc_freeres_fn (free_mem)
+static void __attribute__ ((unused))
+free_mem (void)
 {
   void *old;
 
@@ -1213,7 +1179,7 @@ libc_freeres_fn (free_mem)
     {
       struct binding *oldp = _nl_domain_bindings;
       _nl_domain_bindings = _nl_domain_bindings->next;
-      if (oldp->dirname != INTUSE(_nl_default_dirname))
+      if (oldp->dirname != _nl_default_dirname)
        /* Yes, this is a pointer comparison.  */
        free (oldp->dirname);
       free (oldp->codeset);
@@ -1235,4 +1201,6 @@ libc_freeres_fn (free_mem)
       free (old);
     }
 }
+
+text_set_element (__libc_subfreeres, free_mem);
 #endif