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
#include <sys/types.h>
30
#if defined (HAVE_UNISTD_H)
32
#endif /* HAVE_UNISTD_H */
34
#if defined (HAVE_STDLIB_H)
37
# include "ansi_stdlib.h"
38
#endif /* HAVE_STDLIB_H */
40
#if defined (HAVE_LOCALE_H)
48
extern int _rl_convert_meta_chars_to_ascii;
49
extern int _rl_output_meta_chars;
50
extern int _rl_meta_flag;
52
/* Functions imported from shell.c */
53
extern char *get_env_value ();
55
#if !defined (HAVE_SETLOCALE)
56
/* A list of legal values for the LANG or LC_CTYPE environment variables.
57
If a locale name in this list is the value for the LC_ALL, LC_CTYPE,
58
or LANG environment variable (using the first of those with a value),
59
readline eight-bit mode is enabled. */
60
static char *legal_lang_values[] =
77
static char *normalize_codeset ();
78
static char *find_codeset ();
79
#endif /* !HAVE_SETLOCALE */
81
/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value
82
to decide the defaults for 8-bit character input and output. Returns
83
1 if we set eight-bit mode. */
87
/* If we have setlocale(3), just check the current LC_CTYPE category
88
value, and go into eight-bit mode if it's not C or POSIX. */
89
#if defined (HAVE_SETLOCALE)
92
/* Set the LC_CTYPE locale category from environment variables. */
93
t = setlocale (LC_CTYPE, "");
94
if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0))
97
_rl_convert_meta_chars_to_ascii = 0;
98
_rl_output_meta_chars = 1;
104
#else /* !HAVE_SETLOCALE */
108
/* We don't have setlocale. Finesse it. Check the environment for the
109
appropriate variables and set eight-bit mode if they have the right
111
lspec = get_env_value ("LC_ALL");
112
if (lspec == 0) lspec = get_env_value ("LC_CTYPE");
113
if (lspec == 0) lspec = get_env_value ("LANG");
114
if (lspec == 0 || (t = normalize_codeset (lspec)) == 0)
116
for (i = 0; t && legal_lang_values[i]; i++)
117
if (STREQ (t, legal_lang_values[i]))
120
_rl_convert_meta_chars_to_ascii = 0;
121
_rl_output_meta_chars = 1;
125
return (legal_lang_values[i] ? 1 : 0);
127
#endif /* !HAVE_SETLOCALE */
130
#if !defined (HAVE_SETLOCALE)
132
normalize_codeset (codeset)
139
codeset = find_codeset (codeset, &namelen);
145
for (len = 0, i = 0; i < namelen; i++)
147
if (isalnum (codeset[i]))
150
all_digits &= isdigit (codeset[i]);
154
retval = (char *)malloc ((all_digits ? 3 : 0) + len + 1);
159
/* Add `iso' to beginning of an all-digit codeset */
167
for (i = 0; i < namelen; i++)
168
if (isalpha (codeset[i]))
169
*wp++ = (isupper (codeset[i])) ? tolower (codeset[i]) : codeset[i];
170
else if (isdigit (codeset[i]))
177
/* Isolate codeset portion of locale specification. */
179
find_codeset (name, lenp)
183
char *cp, *language, *result;
185
cp = language = name;
188
while (*cp && *cp != '_' && *cp != '@' && *cp != '+' && *cp != ',')
191
/* This does not make sense: language has to be specified. As
192
an exception we allow the variable to contain only the codeset
193
name. Perhaps there are funny codeset names. */
196
*lenp = strlen (language);
201
/* Next is the territory. */
205
while (*cp && *cp != '.' && *cp != '@' && *cp != '+' && *cp != ',' && *cp != '_');
207
/* Now, finally, is the codeset. */
212
while (*cp && *cp != '@');
221
*lenp = strlen (language);
228
#endif /* !HAVE_SETLOCALE */