bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patches for OS/2 (2)


From: Andreas Buening
Subject: Patches for OS/2 (2)
Date: Fri, 01 Nov 2002 21:01:20 +0100

Hello!

I added a __DEBUG__ macro that causes some extra info to
be printed to stderr at runtime. It helped me a lot.

The main problem with libintl is that it is not easy to
provide precompiled executables that work on all systems
because every user may have its stuff on another drive.
If the precompiled binaries use prefix=e:/usr/local then
libintl can't find the locale files in f:/usr/local etc.
If the precompiled binaries use prefix=/usr/local then libintl
can find the files in f:/usr/local only if f: is the current
drive which means that the program result depends on the
choosen current directory.
The solution is the following: If a directory name doesn't
contain a drive letter x: then the $UNIXROOT drive letter
is assumed. If UNIXROOT is not set nothing happens.
The earlier versions of gettext used yet another environment
variable GNULOCALEDIR to overcome this issue. However, this
can't work in general. One single directory can't replace
LIBDIR, LOCALEDIR and LOCALEALIASPATH. And if your programs
are spread over several directories (/usr, /usr/local, /whereever)
then this approach sucks.
However, I haven't removed GNULOCALEDIR but I recommend not
to use it. It still overrides everything: UNIXROOT and all
configure flags like LIBDIR, LOCALEDIR and LOCALEALIASPATH,
even if I don't mention this explicitely in the following.


bindtextdom.c:
If the new binding directory doesn't contain a drive letter
add the UNIXROOT drive letter.

------------------------
--- old/gettext-0.11.5/intl/bindtextdom.c       Mon Apr 29 17:25:12 2002
+++ gnu/gettext-0.11.5/intl/bindtextdom.c       Sat Oct 19 20:26:22 2002
@@ -31,6 +31,10 @@
 #endif
 #include "gettextP.h"
 
+#ifdef __DEBUG__
+# include <stdio.h>
+#endif
+
 #ifdef _LIBC
 /* We have to handle multi-threaded applications.  */
 # include <bits/libc-lock.h>
@@ -101,6 +105,16 @@
   struct binding *binding;
   int modified;
 
+#ifdef __DEBUG__
+  {
+    static int have_printed_locale = 0;
+    if (!have_printed_locale)
+      fprintf (stderr, "DEBUG(gettext): set_binding_values(): "
+              "LOCALEDIR=%s (default)\n", _nl_default_dirname);
+    have_printed_locale = 1;
+  }
+#endif
+
   /* Some sanity checks.  */
   if (domainname == NULL || domainname[0] == '\0')
     {
@@ -261,11 +275,33 @@
                }
            }
          *dirnamep = dirname;
+
+#ifdef __EMX__
+         /* Add the UNIXROOT drive letter to get a real "absolute" path. */
+         if (dirname[0] == '/' || dirname[0] == '\\')
+           {
+             /* no drive letter */
+             const char *newdir = _nlos2_deliver_dir (dirname);
+             if (newdir != dirname)
+               {
+                 /* the new directory has been allocated */
+                 if (dirname != _nl_default_dirname)
+                   free ((char*) dirname);
+                 dirname = newdir;
+               }
+           }
+#endif
+
          new_binding->dirname = (char *) dirname;
        }
       else
        /* The default value.  */
        new_binding->dirname = (char *) _nl_default_dirname;
+
+#ifdef __DEBUG__
+      fprintf (stderr, "DEBUG(gettext): set_binding_values(): "
+              "new binding directory: %s\n", new_binding->dirname);
+#endif
 
       new_binding->codeset_cntr = 0;
 
------------------------


dcigettext.c:
Use the LOCALEDIR defined by configure as default.

------------------------
--- old/gettext-0.11.5/intl/dcigettext.c        Tue Jul 23 12:27:52 2002
+++ gnu/gettext-0.11.5/intl/dcigettext.c        Sat Oct 19 20:27:00 2002
@@ -29,6 +29,10 @@
 
 #include <sys/types.h>
 
+#ifdef __DEBUG__
+# include <stdio.h>
+#endif
+
 #ifdef __GNUC__
 # define alloca __builtin_alloca
 # define HAVE_ALLOCA 1
@@ -280,11 +284,7 @@
      = _nl_default_default_domain;
 
 /* Contains the default location of the message catalogs.  */
-#if defined __EMX__
-extern const char _nl_default_dirname[];
-#else
 const char _nl_default_dirname[] = LOCALEDIR;
-#endif
 
 /* List with bindings of specific domains created by bindtextdomain()
    calls.  */
@@ -433,6 +433,16 @@
 #endif
   size_t domainname_len;
 
+# ifdef __DEBUG__
+  {
+    static int have_printed_locale = 0;
+    if (!have_printed_locale)
+      fprintf (stderr, "DEBUG(gettext): dcigettext(): "
+              "LOCALEDIR=%s (default)\n", _nl_default_dirname);
+    have_printed_locale = 1;
+  }
+# endif
+
   /* If no real MSGID is given return NULL.  */
   if (msgid1 == NULL)
     return NULL;
@@ -559,7 +569,6 @@
   /* Creating working area.  */
   single_locale = (char *) alloca (strlen (categoryvalue) + 1);
   ADD_BLOCK (block_list, single_locale);
-
 
   /* Search for the given string.  This is a loop because we perhaps
      got an ordered list of languages to consider for the translation.  */
------------------------


loadmsgcat.c:
Initialize _nl_msg_cat_cntr with 0. It's a bad programming style
not to do so and under some circumstances it can lead to problems
with the OS/2 linker.

------------------------
--- old/gettext-0.11.5/intl/loadmsgcat.c        Tue Jul 23 17:19:20 2002
+++ gnu/gettext-0.11.5/intl/loadmsgcat.c        Sat Oct 19 20:14:50 2002
@@ -53,6 +53,10 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef __DEBUG__
+# include <stdio.h>
+#endif
+
 #if defined HAVE_UNISTD_H || defined _LIBC
 # include <unistd.h>
 #endif
@@ -493,7 +497,7 @@
 /* We need a sign, whether a new catalog was loaded, which can be associated
    with all translations.  This is important if the translations are
    cached by one of GCC's features.  */
-int _nl_msg_cat_cntr;
+int _nl_msg_cat_cntr = 0;
 
 
 /* Expand a system dependent string segment.  Return NULL if unsupported.  */
@@ -829,6 +833,11 @@
 # endif
                }
            }
+#ifdef __DEBUG__
+         fprintf (stderr, "DEBUG(gettext): _nl_init_domain_conv(): "
+                  "(charset: %s -> outcharset: %s)\n", charset,
+                  outcharset);
+#endif
 
 # ifdef _LIBC
          /* We always want to use transliteration.  */
@@ -856,6 +865,12 @@
 
              domain->conv = iconv_open (outcharset, charset);
 
+#ifdef __DEBUG__
+             fprintf (stderr, "DEBUG(gettext): _nl_init_domain_conv(): "
+                      "(charset: %s -> outcharset: %s)\n", charset, 
+                      outcharset);
+#endif
+
              freea (outcharset);
            }
          else
@@ -864,6 +879,12 @@
 #  endif
 # endif
 
+#ifdef __DEBUG__
+       fprintf (stderr, "DEBUG(gettext): _nl_init_domain_conv(): "
+               "(charset: %s -> outcharset: %s)\n", charset,
+               outcharset);
+#endif
+
          freea (charset);
        }
 #endif /* _LIBC || HAVE_ICONV */
@@ -929,6 +950,13 @@
 
   /* Try to open the addressed file.  */
   fd = open (domain_file->filename, O_RDONLY | O_BINARY);
+
+# ifdef __DEBUG__
+  fprintf (stderr, "DEBUG(gettext): _nl_load_domain(): "
+          "reading message file %s (%s)\n", domain_file->filename,
+          (fd != -1) ? "success" : "failed");
+# endif
+
   if (fd == -1)
     return;
 
------------------------


localealias.c:
Replace the hardcoded LOCALEALIASPATH by adding the UNIXROOT
drive letter to all directories.

------------------------
--- old/gettext-0.11.5/intl/localealias.c       Mon Dec 17 17:33:20 2001
+++ gnu/gettext-0.11.5/intl/localealias.c       Sat Oct 19 22:21:56 2002
@@ -135,7 +135,7 @@
 _nl_expand_alias (name)
     const char *name;
 {
-  static const char *locale_alias_path;
+  static const char *locale_alias_path = NULL;
   struct alias_map *retval;
   const char *result = NULL;
   size_t added;
@@ -144,8 +144,25 @@
   __libc_lock_lock (lock);
 #endif
 
+#ifndef __EMX__
   if (locale_alias_path == NULL)
     locale_alias_path = LOCALE_ALIAS_PATH;
+#else
+  /* _nlos2_deliver_path() may prepend a drive letter to
+     LOCALE_ALIAS_PATH or deliver GNULOCALEDIR or be a no op. */
+  if (locale_alias_path == NULL)
+    locale_alias_path = _nlos2_deliver_path(LOCALE_ALIAS_PATH);
+#endif
+
+#ifdef __DEBUG__
+  {
+    static int have_printed_localealias = 0;
+    if (!have_printed_localealias)
+      fprintf(stderr, "DEBUG(gettext): _nl_expand_alias(): "
+             "LOCALE_ALIAS_PATH=%s\n", locale_alias_path);
+    have_printed_localealias = 1;
+  }
+#endif  
 
   do
     {
@@ -218,6 +235,13 @@
 #endif
 
   fp = fopen (full_fname, "r");
+
+#ifdef __DEBUG__
+  fprintf(stderr, "DEBUG(gettext): read_alias_file(): "
+         "open locale alias file %s (%s)\n",
+          full_fname, (fp != NULL) ? "success" : "failed");
+#endif
+
   freea (full_fname);
   if (fp == NULL)
     return 0;
------------------------


localcharset.c:
Moved most of the OS/2 specific code to os2compat.c.
Add UNIXROOT drive letter to LIBDIR.
Try to find out the current OS/2 charset. If that's not possible
use the default code for non Win32 systems.
Use a more general function to strcmp() the codeset with the
existing aliases. In this case e.g. "de_DE" (the usual LANG
for Germany) is identical with the first string that contains
"de_DE" (which is "de_DE.ISO-8859-1"). Otherwise no correct
codeset is selected due to the entries in charset.alias.

------------------------
--- old/gettext-0.11.5/intl/localcharset.c      Fri May 10 10:37:08 2002
+++ gnu/gettext-0.11.5/intl/localcharset.c      Fri Nov  1 20:57:22 2002
@@ -42,11 +42,6 @@
 # define WIN32
 #endif
 
-#if defined __EMX__
-/* Assume EMX program runs on OS/2, even if compiled under DOS.  */
-# define OS2
-#endif
-
 #if !defined WIN32
 # if HAVE_LANGINFO_CODESET
 #  include <langinfo.h>
@@ -59,10 +54,6 @@
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
 #endif
-#if defined OS2
-# define INCL_DOS
-# include <os2.h>
-#endif
 
 #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
   /* Win32, OS/2, DOS */
@@ -112,10 +103,35 @@
     {
 #if !defined WIN32
       FILE *fp;
+
+# ifndef __EMX__
       const char *dir = LIBDIR;
+# else
+      static const char *dir = NULL;
+# endif
+
       const char *base = "charset.alias";
       char *file_name;
 
+# ifdef __EMX__
+      /* _nlos2_deliver_dir() may prepend a drive letter to
+        LIBDIR or deliver GNULOCALEDIR or be a no op.
+        Use a static variable so that _nlos2_deliver_dir()
+        is called exactly once for LIBDIR. */
+      if (dir == NULL)
+       dir = _nlos2_deliver_dir(LIBDIR);
+# endif
+
+# ifdef __DEBUG__
+      {
+       static int have_printed_libdir = 0;
+       if (!have_printed_libdir)
+         fprintf (stderr, "DEBUG(gettext): get_charset_aliases(): "
+                  "LIBDIR=%s\n", dir);
+       have_printed_libdir = 1;
+      }
+# endif
+
       /* Concatenate dir and base into freshly allocated file_name.  */
       {
        size_t dir_len = strlen (dir);
@@ -132,8 +148,15 @@
       }
 
       if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
-       /* Out of memory or file not found, treat it as empty.  */
-       cp = "";
+       {
+         /* Out of memory or file not found, treat it as empty.  */
+         cp = "";
+# ifdef __DEBUG__
+         fprintf (stderr, "DEBUG(gettext): get_charset_aliases(): "
+                   "cannot read charset alias file: %s\n",
+                   (file_name != NULL) ? file_name : "NULL");
+# endif
+       }
       else
        {
          /* Parse the file's contents.  */
@@ -144,6 +167,12 @@
          size_t res_size = 0;
          size_t l1, l2;
 
+# ifdef __DEBUG__
+         fprintf( stderr,
+                  "DEBUG(gettext) get_charset_aliases(): "
+                  "reading charset alias file: %s\n", file_name);
+# endif
+
          for (;;)
            {
              c = getc (fp);
@@ -244,7 +273,7 @@
   const char *codeset;
   const char *aliases;
 
-#if !(defined WIN32 || defined OS2)
+#if !defined (WIN32)
 
 # if HAVE_LANGINFO_CODESET
 
@@ -256,6 +285,13 @@
   /* On old systems which lack it, use setlocale or getenv.  */
   const char *locale = NULL;
 
+#  ifdef __EMX__
+  /* Try to determine the current charset. */
+  codeset = _nlos2_get_charset();
+  if (codeset != NULL)
+    return codeset;
+#  endif
+
   /* But most old systems don't have a complete set of locales.  Some
      (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
      use setlocale here; it would return "C" when it doesn't support the
@@ -288,65 +324,16 @@
   /* Woe32 has a function returning the locale's codepage as a number.  */
   sprintf (buf, "CP%u", GetACP ());
   codeset = buf;
-
-#elif defined OS2
-
-  const char *locale;
-  static char buf[2 + 10 + 1];
-  ULONG cp[3];
-  ULONG cplen;
-
-  /* Allow user to override the codeset, as set in the operating system,
-     with standard language environment variables.  */
-  locale = getenv ("LC_ALL");
-  if (locale == NULL || locale[0] == '\0')
-    {
-      locale = getenv ("LC_CTYPE");
-      if (locale == NULL || locale[0] == '\0')
-       locale = getenv ("LANG");
-    }
-  if (locale != NULL && locale[0] != '\0')
-    {
-      /* If the locale name contains an encoding after the dot, return it.  */
-      const char *dot = strchr (locale, '.');
-
-      if (dot != NULL)
-       {
-         const char *modifier;
-
-         dot++;
-         /* Look for the possible @... trailer and remove it, if any.  */
-         modifier = strchr (dot, '@');
-         if (modifier == NULL)
-           return dot;
-         if (modifier - dot < sizeof (buf))
-           {
-             memcpy (buf, dot, modifier - dot);
-             buf [modifier - dot] = '\0';
-             return buf;
-           }
-       }
-
-      /* Resolve through the charset.alias file.  */
-      codeset = locale;
-    }
-  else
-    {
-      /* OS/2 has a function returning the locale's codepage as a number.  */
-      if (DosQueryCp (sizeof (cp), cp, &cplen))
-       codeset = "";
-      else
-       {
-         sprintf (buf, "CP%u", cp[0]);
-         codeset = buf;
-       }
-    }
-
 #endif
 
   if (codeset == NULL)
     /* The canonical name cannot be determined.  */
     codeset = "";
+
+#ifdef __EMX__
+  /* Wouldn't _nlos2_cmp_codeset() be a better replacement for all systems? */
+# define strcmp(codeset, aliases) _nlos2_cmp_codeset(codeset, aliases)
+#endif
 
   /* Resolve alias. */
   for (aliases = get_charset_aliases ();
------------------------


Bye,
Andreas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]