1 /* nls.c -- skeletal internationalization code. */
3 /* Copyright (C) 1996 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library, a library for
6 reading lines of text with interactive input and history editing.
8 The GNU Readline Library is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 1, or
11 (at your option) any later version.
13 The GNU Readline Library is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 The GNU General Public License is often shipped with GNU software, and
19 is generally kept in a file called COPYING or LICENSE. If you do not
20 have a copy of the license, write to the Free Software Foundation,
21 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #define READLINE_LIBRARY
24 #if defined (HAVE_CONFIG_H)
28 #if defined (HAVE_UNISTD_H)
30 #endif /* HAVE_UNISTD_H */
32 #if defined (HAVE_STDLIB_H)
35 # include "ansi_stdlib.h"
36 #endif /* HAVE_STDLIB_H */
38 #if defined (HAVE_LOCALE_H)
46 extern int _rl_convert_meta_chars_to_ascii;
47 extern int _rl_output_meta_chars;
48 extern int _rl_meta_flag;
50 /* A list of legal values for the LANG or LC_CTYPE environment variables.
51 If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
52 or LANG environment variable (using the first of those with a value),
53 readline eight-bit mode is enabled. */
54 static char *legal_lang_values[] =
70 static char *normalize_codeset ();
71 static char *find_codeset ();
73 /* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
74 to decide the defaults for 8-bit character input and output. Returns
75 1 if we set eight-bit mode. */
82 lspec = getenv ("LC_ALL");
83 if (lspec == 0) lspec = getenv ("LC_CTYPE");
84 if (lspec == 0) lspec = getenv ("LANG");
85 if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
87 for (i = 0; t && legal_lang_values[i]; i++)
88 if (STREQ (t, legal_lang_values[i]))
91 _rl_convert_meta_chars_to_ascii = 0;
92 _rl_output_meta_chars = 1;
93 #if defined (HAVE_SETLOCALE)
94 setlocale (LC_CTYPE, lspec);
99 return (legal_lang_values[i] ? 1 : 0);
103 normalize_codeset (codeset)
110 codeset = find_codeset (codeset, &namelen);
116 for (len = 0, i = 0; i < namelen; i++)
118 if (isalnum (codeset[i]))
121 all_digits &= isdigit (codeset[i]);
125 retval = (char *)malloc ((all_digits ? 3 : 0) + len + 1);
130 /* Add `iso' to beginning of an all-digit codeset */
138 for (i = 0; i < namelen; i++)
139 if (isalpha (codeset[i]))
140 *wp++ = (isupper (codeset[i])) ? tolower (codeset[i]) : codeset[i];
141 else if (isdigit (codeset[i]))
148 /* Isolate codeset portion of locale specification. */
150 find_codeset (name, lenp)
154 char *cp, *language, *result;
156 cp = language = name;
159 while (*cp && *cp != '_' && *cp != '@' && *cp != '+' && *cp != ',')
162 /* This does not make sense: language has to be specified. As
163 an exception we allow the variable to contain only the codeset
164 name. Perhaps there are funny codeset names. */
167 *lenp = strlen (language);
172 /* Next is the territory. */
176 while (*cp && *cp != '.' && *cp != '@' && *cp != '+' && *cp != ',' && *cp != '_');
178 /* Now, finally, is the codeset. */
183 while (*cp && *cp != '@');
192 *lenp = strlen (language);