POSIX.1 National Language Support API for MinGW
Revisión | f3ec94b49f6b96292eb02172ba22ebf75b70a530 (tree) |
---|---|
Tiempo | 2007-08-17 20:07:55 |
Autor | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Make catopen' respect LC_ALL, overriding LC_MESSAGES environment variable, as required by POSIX, when opening message catalogues in NL_CAT_LOCALE mode.
@@ -1,3 +1,13 @@ | ||
1 | +2007-08-16 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + Make `catopen' respect LC_ALL, overriding LC_MESSAGES environment | |
4 | + variable, as required by POSIX, when opening message catalogues in | |
5 | + NL_CAT_LOCALE mode. | |
6 | + | |
7 | + * catopen.c (mc_nlspath_open): Use ... | |
8 | + (mc_nl_cat_locale_getenv): this new static function. | |
9 | + (NLS_LOCALE_STRING): Defunct macro; deleted. | |
10 | + | |
1 | 11 | 2007-07-16 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 12 | |
3 | 13 | Add manpage sources. |
@@ -9,7 +9,7 @@ | ||
9 | 9 | * POSIX compatible national language message catalogues in MinGW. |
10 | 10 | * |
11 | 11 | * Written by Keith Marshall <keithmarshall@users.sourceforge.net> |
12 | - * Last modification: 29-Dec-2006 | |
12 | + * Last modification: 08-Aug-2007 | |
13 | 13 | * |
14 | 14 | * |
15 | 15 | * This is free software. It is provided AS IS, in the hope that it may |
@@ -153,9 +153,37 @@ int mc_check_break_code( wchar_t chk, wchar_t *break_code ) | ||
153 | 153 | } |
154 | 154 | |
155 | 155 | static |
156 | +char *mc_nl_cat_locale_getenv( int flags ) | |
157 | +{ | |
158 | + char *retptr; | |
159 | + | |
160 | + /* Retrieve any appropriate LC_MESSAGES or LANG setting string | |
161 | + * from the process environment, for use in interpreting NLSPATH. | |
162 | + */ | |
163 | + if( flags & NL_CAT_LOCALE ) | |
164 | + { | |
165 | + /* When this flag is set, then we use the LC_MESSAGES setting, | |
166 | + * if any, noting that this may be overridden by LC_ALL. | |
167 | + */ | |
168 | + if( (((retptr = getenv( "LC_ALL" )) != NULL) && (*retptr != '\0')) | |
169 | + || (((retptr = getenv( "LC_MESSAGES" )) != NULL) && (*retptr != '\0')) ) | |
170 | + return retptr; | |
171 | + } | |
172 | + /* When NL_CAT_LOCALE is not set, or if LC_MESSAGES is not defined, | |
173 | + * fall back to using the LANG specification. | |
174 | + */ | |
175 | + if( ((retptr = getenv( "LANG" )) != NULL) && (*retptr != '\0') ) | |
176 | + return retptr; | |
177 | + | |
178 | + /* Fall through, if there is no appropriate specification | |
179 | + * in the process environment, returning NULL. | |
180 | + */ | |
181 | + return NULL; | |
182 | +} | |
183 | + | |
184 | +static | |
156 | 185 | int mc_nlspath_open( __const char *msgcat, unsigned flags ) |
157 | 186 | { |
158 | -# define NLS_LOCALE_STRING (flags & NL_CAT_LOCALE) ? "LC_MESSAGES" : "LANG" | |
159 | 187 | # define mc_select(PREF, ALT) (mblen((PREF), MB_CUR_MAX) > 0) ? (PREF) : (ALT) |
160 | 188 | |
161 | 189 | int fd, step, copy_index, headroom; |
@@ -299,8 +327,8 @@ int mc_nlspath_open( __const char *msgcat, unsigned flags ) | ||
299 | 327 | * present, otherwise for the system locale. |
300 | 328 | */ |
301 | 329 | if( (nls_locale != NULL) |
302 | - || ((nls_locale = getenv( NLS_LOCALE_STRING )) != NULL) | |
303 | - || ((nls_locale = setlocale( LC_MESSAGES, NULL )) != NULL) ) | |
330 | + || ((nls_locale = mc_nl_cat_locale_getenv( flags )) != NULL) | |
331 | + || ((nls_locale = setlocale( LC_MESSAGES, NULL )) != NULL) ) | |
304 | 332 | { |
305 | 333 | subst = nls_locale; |
306 | 334 | wchar_t *break_code = L"_.@"; |
@@ -468,4 +496,4 @@ nl_catd catopen( __const char *name, int flags ) | ||
468 | 496 | return (nl_catd)_mctab_( mc_open, name, flags ); |
469 | 497 | } |
470 | 498 | |
471 | -/* $RCSfile$Revision: 1.2 $: end of file */ | |
499 | +/* $RCSfile$Revision: 1.3 $: end of file */ |