Imported from ../bash-2.05.tar.gz.
[platform/upstream/bash.git] / lib / readline / nls.c
index fad5201..f807995 100644 (file)
@@ -7,7 +7,7 @@
 
    The GNU Readline Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU General Public License
-   as published by the Free Software Foundation; either version 1, or
+   as published by the Free Software Foundation; either version 2, or
    (at your option) any later version.
 
    The GNU Readline Library is distributed in the hope that it will be
    The GNU General Public License is often shipped with GNU software, and
    is generally kept in a file called COPYING or LICENSE.  If you do not
    have a copy of the license, write to the Free Software Foundation,
-   675 Mass Ave, Cambridge, MA 02139, USA. */
+   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
 #define READLINE_LIBRARY
 
 #if defined (HAVE_CONFIG_H)
 #  include <config.h>
 #endif
 
+#include <sys/types.h>
+
+#include <stdio.h>
+
 #if defined (HAVE_UNISTD_H)
 #  include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 #include <ctype.h>
 
 #include "rldefs.h"
+#include "readline.h"
+#include "rlshell.h"
+#include "rlprivate.h"
 
-extern int _rl_convert_meta_chars_to_ascii;
-extern int _rl_output_meta_chars;
-extern int _rl_meta_flag;
-    
+#if !defined (HAVE_SETLOCALE)    
 /* A list of legal values for the LANG or LC_CTYPE environment variables.
    If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
    or LANG environment variable (using the first of those with a value),
@@ -63,12 +67,13 @@ static char *legal_lang_values[] =
  "iso88598",
  "iso88599",
  "iso885910",
- "koi8r",   
+ "koi8r",
   0
 };
 
-static char *normalize_codeset ();
-static char *find_codeset ();
+static char *normalize_codeset __P((char *));
+static char *find_codeset __P((char *, size_t *));
+#endif /* !HAVE_SETLOCALE */
 
 /* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
    to decide the defaults for 8-bit character input and output.  Returns
@@ -76,12 +81,33 @@ static char *find_codeset ();
 int
 _rl_init_eightbit ()
 {
+/* If we have setlocale(3), just check the current LC_CTYPE category
+   value, and go into eight-bit mode if it's not C or POSIX. */
+#if defined (HAVE_SETLOCALE)
+  char *t;
+
+  /* Set the LC_CTYPE locale category from environment variables. */
+  t = setlocale (LC_CTYPE, "");
+  if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0))
+    {
+      _rl_meta_flag = 1;
+      _rl_convert_meta_chars_to_ascii = 0;
+      _rl_output_meta_chars = 1;
+      return (1);
+    }
+  else
+    return (0);
+
+#else /* !HAVE_SETLOCALE */
   char *lspec, *t;
   int i;
 
-  lspec = getenv ("LC_ALL");
-  if (lspec == 0) lspec = getenv ("LC_CTYPE");
-  if (lspec == 0) lspec = getenv ("LANG");
+  /* We don't have setlocale.  Finesse it.  Check the environment for the
+     appropriate variables and set eight-bit mode if they have the right
+     values. */
+  lspec = sh_get_env_value ("LC_ALL");
+  if (lspec == 0) lspec = sh_get_env_value ("LC_CTYPE");
+  if (lspec == 0) lspec = sh_get_env_value ("LANG");
   if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
     return (0);
   for (i = 0; t && legal_lang_values[i]; i++)
@@ -90,15 +116,15 @@ _rl_init_eightbit ()
        _rl_meta_flag = 1;
        _rl_convert_meta_chars_to_ascii = 0;
        _rl_output_meta_chars = 1;
-#if defined (HAVE_SETLOCALE)
-       setlocale (LC_CTYPE, lspec);
-#endif
        break;
       }
   free (t);
   return (legal_lang_values[i] ? 1 : 0);
+
+#endif /* !HAVE_SETLOCALE */
 }
 
+#if !defined (HAVE_SETLOCALE)
 static char *
 normalize_codeset (codeset)
      char *codeset;
@@ -196,3 +222,4 @@ find_codeset (name, lenp)
 
   return result;
 }
+#endif /* !HAVE_SETLOCALE */