xref: /netbsd/external/gpl2/grep/dist/intl/localename.c (revision f7313695)
1*f7313695Schristos /*	$NetBSD: localename.c,v 1.1.1.1 2016/01/10 21:36:18 christos Exp $	*/
2*f7313695Schristos 
3*f7313695Schristos /* Determine the current selected locale.
4*f7313695Schristos    Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
5*f7313695Schristos 
6*f7313695Schristos    This program is free software; you can redistribute it and/or modify
7*f7313695Schristos    it under the terms of the GNU General Public License as published by
8*f7313695Schristos    the Free Software Foundation; either version 2, or (at your option)
9*f7313695Schristos    any later version.
10*f7313695Schristos 
11*f7313695Schristos    This program is distributed in the hope that it will be useful,
12*f7313695Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*f7313695Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*f7313695Schristos    GNU General Public License for more details.
15*f7313695Schristos 
16*f7313695Schristos    You should have received a copy of the GNU General Public License
17*f7313695Schristos    along with this program; if not, write to the Free Software Foundation,
18*f7313695Schristos    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19*f7313695Schristos 
20*f7313695Schristos /* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
21*f7313695Schristos /* Win32 code written by Tor Lillqvist <tml@iki.fi>.  */
22*f7313695Schristos 
23*f7313695Schristos #ifdef HAVE_CONFIG_H
24*f7313695Schristos # include <config.h>
25*f7313695Schristos #endif
26*f7313695Schristos 
27*f7313695Schristos #include <stdlib.h>
28*f7313695Schristos #include <locale.h>
29*f7313695Schristos 
30*f7313695Schristos #if defined _WIN32 || defined __WIN32__
31*f7313695Schristos # undef WIN32   /* avoid warning on mingw32 */
32*f7313695Schristos # define WIN32
33*f7313695Schristos #endif
34*f7313695Schristos 
35*f7313695Schristos #ifdef WIN32
36*f7313695Schristos # define WIN32_LEAN_AND_MEAN
37*f7313695Schristos # include <windows.h>
38*f7313695Schristos /* Mingw headers don't have latest language and sublanguage codes.  */
39*f7313695Schristos # ifndef LANG_AFRIKAANS
40*f7313695Schristos # define LANG_AFRIKAANS 0x36
41*f7313695Schristos # endif
42*f7313695Schristos # ifndef LANG_ALBANIAN
43*f7313695Schristos # define LANG_ALBANIAN 0x1c
44*f7313695Schristos # endif
45*f7313695Schristos # ifndef LANG_ARABIC
46*f7313695Schristos # define LANG_ARABIC 0x01
47*f7313695Schristos # endif
48*f7313695Schristos # ifndef LANG_ARMENIAN
49*f7313695Schristos # define LANG_ARMENIAN 0x2b
50*f7313695Schristos # endif
51*f7313695Schristos # ifndef LANG_ASSAMESE
52*f7313695Schristos # define LANG_ASSAMESE 0x4d
53*f7313695Schristos # endif
54*f7313695Schristos # ifndef LANG_AZERI
55*f7313695Schristos # define LANG_AZERI 0x2c
56*f7313695Schristos # endif
57*f7313695Schristos # ifndef LANG_BASQUE
58*f7313695Schristos # define LANG_BASQUE 0x2d
59*f7313695Schristos # endif
60*f7313695Schristos # ifndef LANG_BELARUSIAN
61*f7313695Schristos # define LANG_BELARUSIAN 0x23
62*f7313695Schristos # endif
63*f7313695Schristos # ifndef LANG_BENGALI
64*f7313695Schristos # define LANG_BENGALI 0x45
65*f7313695Schristos # endif
66*f7313695Schristos # ifndef LANG_CATALAN
67*f7313695Schristos # define LANG_CATALAN 0x03
68*f7313695Schristos # endif
69*f7313695Schristos # ifndef LANG_ESTONIAN
70*f7313695Schristos # define LANG_ESTONIAN 0x25
71*f7313695Schristos # endif
72*f7313695Schristos # ifndef LANG_FAEROESE
73*f7313695Schristos # define LANG_FAEROESE 0x38
74*f7313695Schristos # endif
75*f7313695Schristos # ifndef LANG_FARSI
76*f7313695Schristos # define LANG_FARSI 0x29
77*f7313695Schristos # endif
78*f7313695Schristos # ifndef LANG_GEORGIAN
79*f7313695Schristos # define LANG_GEORGIAN 0x37
80*f7313695Schristos # endif
81*f7313695Schristos # ifndef LANG_GUJARATI
82*f7313695Schristos # define LANG_GUJARATI 0x47
83*f7313695Schristos # endif
84*f7313695Schristos # ifndef LANG_HEBREW
85*f7313695Schristos # define LANG_HEBREW 0x0d
86*f7313695Schristos # endif
87*f7313695Schristos # ifndef LANG_HINDI
88*f7313695Schristos # define LANG_HINDI 0x39
89*f7313695Schristos # endif
90*f7313695Schristos # ifndef LANG_INDONESIAN
91*f7313695Schristos # define LANG_INDONESIAN 0x21
92*f7313695Schristos # endif
93*f7313695Schristos # ifndef LANG_KANNADA
94*f7313695Schristos # define LANG_KANNADA 0x4b
95*f7313695Schristos # endif
96*f7313695Schristos # ifndef LANG_KASHMIRI
97*f7313695Schristos # define LANG_KASHMIRI 0x60
98*f7313695Schristos # endif
99*f7313695Schristos # ifndef LANG_KAZAK
100*f7313695Schristos # define LANG_KAZAK 0x3f
101*f7313695Schristos # endif
102*f7313695Schristos # ifndef LANG_KONKANI
103*f7313695Schristos # define LANG_KONKANI 0x57
104*f7313695Schristos # endif
105*f7313695Schristos # ifndef LANG_LATVIAN
106*f7313695Schristos # define LANG_LATVIAN 0x26
107*f7313695Schristos # endif
108*f7313695Schristos # ifndef LANG_LITHUANIAN
109*f7313695Schristos # define LANG_LITHUANIAN 0x27
110*f7313695Schristos # endif
111*f7313695Schristos # ifndef LANG_MACEDONIAN
112*f7313695Schristos # define LANG_MACEDONIAN 0x2f
113*f7313695Schristos # endif
114*f7313695Schristos # ifndef LANG_MALAY
115*f7313695Schristos # define LANG_MALAY 0x3e
116*f7313695Schristos # endif
117*f7313695Schristos # ifndef LANG_MALAYALAM
118*f7313695Schristos # define LANG_MALAYALAM 0x4c
119*f7313695Schristos # endif
120*f7313695Schristos # ifndef LANG_MANIPURI
121*f7313695Schristos # define LANG_MANIPURI 0x58
122*f7313695Schristos # endif
123*f7313695Schristos # ifndef LANG_MARATHI
124*f7313695Schristos # define LANG_MARATHI 0x4e
125*f7313695Schristos # endif
126*f7313695Schristos # ifndef LANG_NEPALI
127*f7313695Schristos # define LANG_NEPALI 0x61
128*f7313695Schristos # endif
129*f7313695Schristos # ifndef LANG_ORIYA
130*f7313695Schristos # define LANG_ORIYA 0x48
131*f7313695Schristos # endif
132*f7313695Schristos # ifndef LANG_PUNJABI
133*f7313695Schristos # define LANG_PUNJABI 0x46
134*f7313695Schristos # endif
135*f7313695Schristos # ifndef LANG_SANSKRIT
136*f7313695Schristos # define LANG_SANSKRIT 0x4f
137*f7313695Schristos # endif
138*f7313695Schristos # ifndef LANG_SERBIAN
139*f7313695Schristos # define LANG_SERBIAN 0x1a
140*f7313695Schristos # endif
141*f7313695Schristos # ifndef LANG_SINDHI
142*f7313695Schristos # define LANG_SINDHI 0x59
143*f7313695Schristos # endif
144*f7313695Schristos # ifndef LANG_SLOVAK
145*f7313695Schristos # define LANG_SLOVAK 0x1b
146*f7313695Schristos # endif
147*f7313695Schristos # ifndef LANG_SWAHILI
148*f7313695Schristos # define LANG_SWAHILI 0x41
149*f7313695Schristos # endif
150*f7313695Schristos # ifndef LANG_TAMIL
151*f7313695Schristos # define LANG_TAMIL 0x49
152*f7313695Schristos # endif
153*f7313695Schristos # ifndef LANG_TATAR
154*f7313695Schristos # define LANG_TATAR 0x44
155*f7313695Schristos # endif
156*f7313695Schristos # ifndef LANG_TELUGU
157*f7313695Schristos # define LANG_TELUGU 0x4a
158*f7313695Schristos # endif
159*f7313695Schristos # ifndef LANG_THAI
160*f7313695Schristos # define LANG_THAI 0x1e
161*f7313695Schristos # endif
162*f7313695Schristos # ifndef LANG_UKRAINIAN
163*f7313695Schristos # define LANG_UKRAINIAN 0x22
164*f7313695Schristos # endif
165*f7313695Schristos # ifndef LANG_URDU
166*f7313695Schristos # define LANG_URDU 0x20
167*f7313695Schristos # endif
168*f7313695Schristos # ifndef LANG_UZBEK
169*f7313695Schristos # define LANG_UZBEK 0x43
170*f7313695Schristos # endif
171*f7313695Schristos # ifndef LANG_VIETNAMESE
172*f7313695Schristos # define LANG_VIETNAMESE 0x2a
173*f7313695Schristos # endif
174*f7313695Schristos # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
175*f7313695Schristos # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
176*f7313695Schristos # endif
177*f7313695Schristos # ifndef SUBLANG_ARABIC_IRAQ
178*f7313695Schristos # define SUBLANG_ARABIC_IRAQ 0x02
179*f7313695Schristos # endif
180*f7313695Schristos # ifndef SUBLANG_ARABIC_EGYPT
181*f7313695Schristos # define SUBLANG_ARABIC_EGYPT 0x03
182*f7313695Schristos # endif
183*f7313695Schristos # ifndef SUBLANG_ARABIC_LIBYA
184*f7313695Schristos # define SUBLANG_ARABIC_LIBYA 0x04
185*f7313695Schristos # endif
186*f7313695Schristos # ifndef SUBLANG_ARABIC_ALGERIA
187*f7313695Schristos # define SUBLANG_ARABIC_ALGERIA 0x05
188*f7313695Schristos # endif
189*f7313695Schristos # ifndef SUBLANG_ARABIC_MOROCCO
190*f7313695Schristos # define SUBLANG_ARABIC_MOROCCO 0x06
191*f7313695Schristos # endif
192*f7313695Schristos # ifndef SUBLANG_ARABIC_TUNISIA
193*f7313695Schristos # define SUBLANG_ARABIC_TUNISIA 0x07
194*f7313695Schristos # endif
195*f7313695Schristos # ifndef SUBLANG_ARABIC_OMAN
196*f7313695Schristos # define SUBLANG_ARABIC_OMAN 0x08
197*f7313695Schristos # endif
198*f7313695Schristos # ifndef SUBLANG_ARABIC_YEMEN
199*f7313695Schristos # define SUBLANG_ARABIC_YEMEN 0x09
200*f7313695Schristos # endif
201*f7313695Schristos # ifndef SUBLANG_ARABIC_SYRIA
202*f7313695Schristos # define SUBLANG_ARABIC_SYRIA 0x0a
203*f7313695Schristos # endif
204*f7313695Schristos # ifndef SUBLANG_ARABIC_JORDAN
205*f7313695Schristos # define SUBLANG_ARABIC_JORDAN 0x0b
206*f7313695Schristos # endif
207*f7313695Schristos # ifndef SUBLANG_ARABIC_LEBANON
208*f7313695Schristos # define SUBLANG_ARABIC_LEBANON 0x0c
209*f7313695Schristos # endif
210*f7313695Schristos # ifndef SUBLANG_ARABIC_KUWAIT
211*f7313695Schristos # define SUBLANG_ARABIC_KUWAIT 0x0d
212*f7313695Schristos # endif
213*f7313695Schristos # ifndef SUBLANG_ARABIC_UAE
214*f7313695Schristos # define SUBLANG_ARABIC_UAE 0x0e
215*f7313695Schristos # endif
216*f7313695Schristos # ifndef SUBLANG_ARABIC_BAHRAIN
217*f7313695Schristos # define SUBLANG_ARABIC_BAHRAIN 0x0f
218*f7313695Schristos # endif
219*f7313695Schristos # ifndef SUBLANG_ARABIC_QATAR
220*f7313695Schristos # define SUBLANG_ARABIC_QATAR 0x10
221*f7313695Schristos # endif
222*f7313695Schristos # ifndef SUBLANG_AZERI_LATIN
223*f7313695Schristos # define SUBLANG_AZERI_LATIN 0x01
224*f7313695Schristos # endif
225*f7313695Schristos # ifndef SUBLANG_AZERI_CYRILLIC
226*f7313695Schristos # define SUBLANG_AZERI_CYRILLIC 0x02
227*f7313695Schristos # endif
228*f7313695Schristos # ifndef SUBLANG_CHINESE_MACAU
229*f7313695Schristos # define SUBLANG_CHINESE_MACAU 0x05
230*f7313695Schristos # endif
231*f7313695Schristos # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
232*f7313695Schristos # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
233*f7313695Schristos # endif
234*f7313695Schristos # ifndef SUBLANG_ENGLISH_JAMAICA
235*f7313695Schristos # define SUBLANG_ENGLISH_JAMAICA 0x08
236*f7313695Schristos # endif
237*f7313695Schristos # ifndef SUBLANG_ENGLISH_CARIBBEAN
238*f7313695Schristos # define SUBLANG_ENGLISH_CARIBBEAN 0x09
239*f7313695Schristos # endif
240*f7313695Schristos # ifndef SUBLANG_ENGLISH_BELIZE
241*f7313695Schristos # define SUBLANG_ENGLISH_BELIZE 0x0a
242*f7313695Schristos # endif
243*f7313695Schristos # ifndef SUBLANG_ENGLISH_TRINIDAD
244*f7313695Schristos # define SUBLANG_ENGLISH_TRINIDAD 0x0b
245*f7313695Schristos # endif
246*f7313695Schristos # ifndef SUBLANG_ENGLISH_ZIMBABWE
247*f7313695Schristos # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
248*f7313695Schristos # endif
249*f7313695Schristos # ifndef SUBLANG_ENGLISH_PHILIPPINES
250*f7313695Schristos # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
251*f7313695Schristos # endif
252*f7313695Schristos # ifndef SUBLANG_FRENCH_LUXEMBOURG
253*f7313695Schristos # define SUBLANG_FRENCH_LUXEMBOURG 0x05
254*f7313695Schristos # endif
255*f7313695Schristos # ifndef SUBLANG_FRENCH_MONACO
256*f7313695Schristos # define SUBLANG_FRENCH_MONACO 0x06
257*f7313695Schristos # endif
258*f7313695Schristos # ifndef SUBLANG_GERMAN_LUXEMBOURG
259*f7313695Schristos # define SUBLANG_GERMAN_LUXEMBOURG 0x04
260*f7313695Schristos # endif
261*f7313695Schristos # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
262*f7313695Schristos # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
263*f7313695Schristos # endif
264*f7313695Schristos # ifndef SUBLANG_KASHMIRI_INDIA
265*f7313695Schristos # define SUBLANG_KASHMIRI_INDIA 0x02
266*f7313695Schristos # endif
267*f7313695Schristos # ifndef SUBLANG_MALAY_MALAYSIA
268*f7313695Schristos # define SUBLANG_MALAY_MALAYSIA 0x01
269*f7313695Schristos # endif
270*f7313695Schristos # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
271*f7313695Schristos # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
272*f7313695Schristos # endif
273*f7313695Schristos # ifndef SUBLANG_NEPALI_INDIA
274*f7313695Schristos # define SUBLANG_NEPALI_INDIA 0x02
275*f7313695Schristos # endif
276*f7313695Schristos # ifndef SUBLANG_SERBIAN_LATIN
277*f7313695Schristos # define SUBLANG_SERBIAN_LATIN 0x02
278*f7313695Schristos # endif
279*f7313695Schristos # ifndef SUBLANG_SERBIAN_CYRILLIC
280*f7313695Schristos # define SUBLANG_SERBIAN_CYRILLIC 0x03
281*f7313695Schristos # endif
282*f7313695Schristos # ifndef SUBLANG_SPANISH_GUATEMALA
283*f7313695Schristos # define SUBLANG_SPANISH_GUATEMALA 0x04
284*f7313695Schristos # endif
285*f7313695Schristos # ifndef SUBLANG_SPANISH_COSTA_RICA
286*f7313695Schristos # define SUBLANG_SPANISH_COSTA_RICA 0x05
287*f7313695Schristos # endif
288*f7313695Schristos # ifndef SUBLANG_SPANISH_PANAMA
289*f7313695Schristos # define SUBLANG_SPANISH_PANAMA 0x06
290*f7313695Schristos # endif
291*f7313695Schristos # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
292*f7313695Schristos # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
293*f7313695Schristos # endif
294*f7313695Schristos # ifndef SUBLANG_SPANISH_VENEZUELA
295*f7313695Schristos # define SUBLANG_SPANISH_VENEZUELA 0x08
296*f7313695Schristos # endif
297*f7313695Schristos # ifndef SUBLANG_SPANISH_COLOMBIA
298*f7313695Schristos # define SUBLANG_SPANISH_COLOMBIA 0x09
299*f7313695Schristos # endif
300*f7313695Schristos # ifndef SUBLANG_SPANISH_PERU
301*f7313695Schristos # define SUBLANG_SPANISH_PERU 0x0a
302*f7313695Schristos # endif
303*f7313695Schristos # ifndef SUBLANG_SPANISH_ARGENTINA
304*f7313695Schristos # define SUBLANG_SPANISH_ARGENTINA 0x0b
305*f7313695Schristos # endif
306*f7313695Schristos # ifndef SUBLANG_SPANISH_ECUADOR
307*f7313695Schristos # define SUBLANG_SPANISH_ECUADOR 0x0c
308*f7313695Schristos # endif
309*f7313695Schristos # ifndef SUBLANG_SPANISH_CHILE
310*f7313695Schristos # define SUBLANG_SPANISH_CHILE 0x0d
311*f7313695Schristos # endif
312*f7313695Schristos # ifndef SUBLANG_SPANISH_URUGUAY
313*f7313695Schristos # define SUBLANG_SPANISH_URUGUAY 0x0e
314*f7313695Schristos # endif
315*f7313695Schristos # ifndef SUBLANG_SPANISH_PARAGUAY
316*f7313695Schristos # define SUBLANG_SPANISH_PARAGUAY 0x0f
317*f7313695Schristos # endif
318*f7313695Schristos # ifndef SUBLANG_SPANISH_BOLIVIA
319*f7313695Schristos # define SUBLANG_SPANISH_BOLIVIA 0x10
320*f7313695Schristos # endif
321*f7313695Schristos # ifndef SUBLANG_SPANISH_EL_SALVADOR
322*f7313695Schristos # define SUBLANG_SPANISH_EL_SALVADOR 0x11
323*f7313695Schristos # endif
324*f7313695Schristos # ifndef SUBLANG_SPANISH_HONDURAS
325*f7313695Schristos # define SUBLANG_SPANISH_HONDURAS 0x12
326*f7313695Schristos # endif
327*f7313695Schristos # ifndef SUBLANG_SPANISH_NICARAGUA
328*f7313695Schristos # define SUBLANG_SPANISH_NICARAGUA 0x13
329*f7313695Schristos # endif
330*f7313695Schristos # ifndef SUBLANG_SPANISH_PUERTO_RICO
331*f7313695Schristos # define SUBLANG_SPANISH_PUERTO_RICO 0x14
332*f7313695Schristos # endif
333*f7313695Schristos # ifndef SUBLANG_SWEDISH_FINLAND
334*f7313695Schristos # define SUBLANG_SWEDISH_FINLAND 0x02
335*f7313695Schristos # endif
336*f7313695Schristos # ifndef SUBLANG_URDU_PAKISTAN
337*f7313695Schristos # define SUBLANG_URDU_PAKISTAN 0x01
338*f7313695Schristos # endif
339*f7313695Schristos # ifndef SUBLANG_URDU_INDIA
340*f7313695Schristos # define SUBLANG_URDU_INDIA 0x02
341*f7313695Schristos # endif
342*f7313695Schristos # ifndef SUBLANG_UZBEK_LATIN
343*f7313695Schristos # define SUBLANG_UZBEK_LATIN 0x01
344*f7313695Schristos # endif
345*f7313695Schristos # ifndef SUBLANG_UZBEK_CYRILLIC
346*f7313695Schristos # define SUBLANG_UZBEK_CYRILLIC 0x02
347*f7313695Schristos # endif
348*f7313695Schristos #endif
349*f7313695Schristos 
350*f7313695Schristos /* XPG3 defines the result of 'setlocale (category, NULL)' as:
351*f7313695Schristos    "Directs 'setlocale()' to query 'category' and return the current
352*f7313695Schristos     setting of 'local'."
353*f7313695Schristos    However it does not specify the exact format.  Neither do SUSV2 and
354*f7313695Schristos    ISO C 99.  So we can use this feature only on selected systems (e.g.
355*f7313695Schristos    those using GNU C Library).  */
356*f7313695Schristos #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
357*f7313695Schristos # define HAVE_LOCALE_NULL
358*f7313695Schristos #endif
359*f7313695Schristos 
360*f7313695Schristos /* Determine the current locale's name, and canonicalize it into XPG syntax
361*f7313695Schristos      language[_territory[.codeset]][@modifier]
362*f7313695Schristos    The codeset part in the result is not reliable; the locale_charset()
363*f7313695Schristos    should be used for codeset information instead.
364*f7313695Schristos    The result must not be freed; it is statically allocated.  */
365*f7313695Schristos 
366*f7313695Schristos const char *
_nl_locale_name(category,categoryname)367*f7313695Schristos _nl_locale_name (category, categoryname)
368*f7313695Schristos      int category;
369*f7313695Schristos      const char *categoryname;
370*f7313695Schristos {
371*f7313695Schristos   const char *retval;
372*f7313695Schristos 
373*f7313695Schristos #ifndef WIN32
374*f7313695Schristos 
375*f7313695Schristos   /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
376*f7313695Schristos      On some systems this can be done by the 'setlocale' function itself.  */
377*f7313695Schristos # if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
378*f7313695Schristos   retval = setlocale (category, NULL);
379*f7313695Schristos # else
380*f7313695Schristos   /* Setting of LC_ALL overwrites all other.  */
381*f7313695Schristos   retval = getenv ("LC_ALL");
382*f7313695Schristos   if (retval == NULL || retval[0] == '\0')
383*f7313695Schristos     {
384*f7313695Schristos       /* Next comes the name of the desired category.  */
385*f7313695Schristos       retval = getenv (categoryname);
386*f7313695Schristos       if (retval == NULL || retval[0] == '\0')
387*f7313695Schristos 	{
388*f7313695Schristos 	  /* Last possibility is the LANG environment variable.  */
389*f7313695Schristos 	  retval = getenv ("LANG");
390*f7313695Schristos 	  if (retval == NULL || retval[0] == '\0')
391*f7313695Schristos 	    /* We use C as the default domain.  POSIX says this is
392*f7313695Schristos 	       implementation defined.  */
393*f7313695Schristos 	    retval = "C";
394*f7313695Schristos 	}
395*f7313695Schristos     }
396*f7313695Schristos # endif
397*f7313695Schristos 
398*f7313695Schristos   return retval;
399*f7313695Schristos 
400*f7313695Schristos #else /* WIN32 */
401*f7313695Schristos 
402*f7313695Schristos   /* Return an XPG style locale name language[_territory][@modifier].
403*f7313695Schristos      Don't even bother determining the codeset; it's not useful in this
404*f7313695Schristos      context, because message catalogs are not specific to a single
405*f7313695Schristos      codeset.  */
406*f7313695Schristos 
407*f7313695Schristos   LCID lcid;
408*f7313695Schristos   LANGID langid;
409*f7313695Schristos   int primary, sub;
410*f7313695Schristos 
411*f7313695Schristos   /* Let the user override the system settings through environment
412*f7313695Schristos      variables, as on POSIX systems.  */
413*f7313695Schristos   retval = getenv ("LC_ALL");
414*f7313695Schristos   if (retval != NULL && retval[0] != '\0')
415*f7313695Schristos     return retval;
416*f7313695Schristos   retval = getenv (categoryname);
417*f7313695Schristos   if (retval != NULL && retval[0] != '\0')
418*f7313695Schristos     return retval;
419*f7313695Schristos   retval = getenv ("LANG");
420*f7313695Schristos   if (retval != NULL && retval[0] != '\0')
421*f7313695Schristos     return retval;
422*f7313695Schristos 
423*f7313695Schristos   /* Use native Win32 API locale ID.  */
424*f7313695Schristos   lcid = GetThreadLocale ();
425*f7313695Schristos 
426*f7313695Schristos   /* Strip off the sorting rules, keep only the language part.  */
427*f7313695Schristos   langid = LANGIDFROMLCID (lcid);
428*f7313695Schristos 
429*f7313695Schristos   /* Split into language and territory part.  */
430*f7313695Schristos   primary = PRIMARYLANGID (langid);
431*f7313695Schristos   sub = SUBLANGID (langid);
432*f7313695Schristos   switch (primary)
433*f7313695Schristos     {
434*f7313695Schristos     case LANG_AFRIKAANS: return "af_ZA";
435*f7313695Schristos     case LANG_ALBANIAN: return "sq_AL";
436*f7313695Schristos     case LANG_ARABIC:
437*f7313695Schristos       switch (sub)
438*f7313695Schristos 	{
439*f7313695Schristos 	case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
440*f7313695Schristos 	case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
441*f7313695Schristos 	case SUBLANG_ARABIC_EGYPT: return "ar_EG";
442*f7313695Schristos 	case SUBLANG_ARABIC_LIBYA: return "ar_LY";
443*f7313695Schristos 	case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
444*f7313695Schristos 	case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
445*f7313695Schristos 	case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
446*f7313695Schristos 	case SUBLANG_ARABIC_OMAN: return "ar_OM";
447*f7313695Schristos 	case SUBLANG_ARABIC_YEMEN: return "ar_YE";
448*f7313695Schristos 	case SUBLANG_ARABIC_SYRIA: return "ar_SY";
449*f7313695Schristos 	case SUBLANG_ARABIC_JORDAN: return "ar_JO";
450*f7313695Schristos 	case SUBLANG_ARABIC_LEBANON: return "ar_LB";
451*f7313695Schristos 	case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
452*f7313695Schristos 	case SUBLANG_ARABIC_UAE: return "ar_AE";
453*f7313695Schristos 	case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
454*f7313695Schristos 	case SUBLANG_ARABIC_QATAR: return "ar_QA";
455*f7313695Schristos 	}
456*f7313695Schristos       return "ar";
457*f7313695Schristos     case LANG_ARMENIAN: return "hy_AM";
458*f7313695Schristos     case LANG_ASSAMESE: return "as_IN";
459*f7313695Schristos     case LANG_AZERI:
460*f7313695Schristos       switch (sub)
461*f7313695Schristos 	{
462*f7313695Schristos 	/* FIXME: Adjust this when Azerbaijani locales appear on Unix.  */
463*f7313695Schristos 	case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
464*f7313695Schristos 	case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
465*f7313695Schristos 	}
466*f7313695Schristos       return "az";
467*f7313695Schristos     case LANG_BASQUE:
468*f7313695Schristos       return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR".  */
469*f7313695Schristos     case LANG_BELARUSIAN: return "be_BY";
470*f7313695Schristos     case LANG_BENGALI: return "bn_IN";
471*f7313695Schristos     case LANG_BULGARIAN: return "bg_BG";
472*f7313695Schristos     case LANG_CATALAN: return "ca_ES";
473*f7313695Schristos     case LANG_CHINESE:
474*f7313695Schristos       switch (sub)
475*f7313695Schristos 	{
476*f7313695Schristos 	case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
477*f7313695Schristos 	case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
478*f7313695Schristos 	case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
479*f7313695Schristos 	case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
480*f7313695Schristos 	case SUBLANG_CHINESE_MACAU: return "zh_MO";
481*f7313695Schristos 	}
482*f7313695Schristos       return "zh";
483*f7313695Schristos     case LANG_CROATIAN:		/* LANG_CROATIAN == LANG_SERBIAN
484*f7313695Schristos 				 * What used to be called Serbo-Croatian
485*f7313695Schristos 				 * should really now be two separate
486*f7313695Schristos 				 * languages because of political reasons.
487*f7313695Schristos 				 * (Says tml, who knows nothing about Serbian
488*f7313695Schristos 				 * or Croatian.)
489*f7313695Schristos 				 * (I can feel those flames coming already.)
490*f7313695Schristos 				 */
491*f7313695Schristos       switch (sub)
492*f7313695Schristos 	{
493*f7313695Schristos 	/* FIXME: How to distinguish Croatian and Latin Serbian locales?  */
494*f7313695Schristos 	case SUBLANG_SERBIAN_LATIN: return "sr_YU";
495*f7313695Schristos 	case SUBLANG_SERBIAN_CYRILLIC: return "sr_YU@cyrillic";
496*f7313695Schristos 	default: return "hr_HR";
497*f7313695Schristos 	}
498*f7313695Schristos     case LANG_CZECH: return "cs_CZ";
499*f7313695Schristos     case LANG_DANISH: return "da_DK";
500*f7313695Schristos     case LANG_DUTCH:
501*f7313695Schristos       switch (sub)
502*f7313695Schristos 	{
503*f7313695Schristos 	case SUBLANG_DUTCH: return "nl_NL";
504*f7313695Schristos 	case SUBLANG_DUTCH_BELGIAN: return "nl_BE";
505*f7313695Schristos 	}
506*f7313695Schristos       return "nl";
507*f7313695Schristos     case LANG_ENGLISH:
508*f7313695Schristos       switch (sub)
509*f7313695Schristos 	{
510*f7313695Schristos 	/* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
511*f7313695Schristos 	 * English was the language spoken in England.
512*f7313695Schristos 	 * Oh well.
513*f7313695Schristos 	 */
514*f7313695Schristos 	case SUBLANG_ENGLISH_US: return "en_US";
515*f7313695Schristos 	case SUBLANG_ENGLISH_UK: return "en_GB";
516*f7313695Schristos 	case SUBLANG_ENGLISH_AUS: return "en_AU";
517*f7313695Schristos 	case SUBLANG_ENGLISH_CAN: return "en_CA";
518*f7313695Schristos 	case SUBLANG_ENGLISH_NZ: return "en_NZ";
519*f7313695Schristos 	case SUBLANG_ENGLISH_EIRE: return "en_IE";
520*f7313695Schristos 	case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
521*f7313695Schristos 	case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
522*f7313695Schristos 	case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
523*f7313695Schristos 	case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
524*f7313695Schristos 	case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
525*f7313695Schristos 	case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
526*f7313695Schristos 	case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
527*f7313695Schristos 	}
528*f7313695Schristos       return "en";
529*f7313695Schristos     case LANG_ESTONIAN: return "et_EE";
530*f7313695Schristos     case LANG_FAEROESE: return "fo_FO";
531*f7313695Schristos     case LANG_FARSI: return "fa_IR";
532*f7313695Schristos     case LANG_FINNISH: return "fi_FI";
533*f7313695Schristos     case LANG_FRENCH:
534*f7313695Schristos       switch (sub)
535*f7313695Schristos 	{
536*f7313695Schristos 	case SUBLANG_FRENCH: return "fr_FR";
537*f7313695Schristos 	case SUBLANG_FRENCH_BELGIAN: return "fr_BE";
538*f7313695Schristos 	case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
539*f7313695Schristos 	case SUBLANG_FRENCH_SWISS: return "fr_CH";
540*f7313695Schristos 	case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
541*f7313695Schristos 	case SUBLANG_FRENCH_MONACO: return "fr_MC";
542*f7313695Schristos 	}
543*f7313695Schristos       return "fr";
544*f7313695Schristos     case LANG_GEORGIAN: return "ka_GE";
545*f7313695Schristos     case LANG_GERMAN:
546*f7313695Schristos       switch (sub)
547*f7313695Schristos 	{
548*f7313695Schristos 	case SUBLANG_GERMAN: return "de_DE";
549*f7313695Schristos 	case SUBLANG_GERMAN_SWISS: return "de_CH";
550*f7313695Schristos 	case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
551*f7313695Schristos 	case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
552*f7313695Schristos 	case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
553*f7313695Schristos 	}
554*f7313695Schristos       return "de";
555*f7313695Schristos     case LANG_GREEK: return "el_GR";
556*f7313695Schristos     case LANG_GUJARATI: return "gu_IN";
557*f7313695Schristos     case LANG_HEBREW: return "he_IL";
558*f7313695Schristos     case LANG_HINDI: return "hi_IN";
559*f7313695Schristos     case LANG_HUNGARIAN: return "hu_HU";
560*f7313695Schristos     case LANG_ICELANDIC: return "is_IS";
561*f7313695Schristos     case LANG_INDONESIAN: return "id_ID";
562*f7313695Schristos     case LANG_ITALIAN:
563*f7313695Schristos       switch (sub)
564*f7313695Schristos 	{
565*f7313695Schristos 	case SUBLANG_ITALIAN: return "it_IT";
566*f7313695Schristos 	case SUBLANG_ITALIAN_SWISS: return "it_CH";
567*f7313695Schristos 	}
568*f7313695Schristos       return "it";
569*f7313695Schristos     case LANG_JAPANESE: return "ja_JP";
570*f7313695Schristos     case LANG_KANNADA: return "kn_IN";
571*f7313695Schristos     case LANG_KASHMIRI:
572*f7313695Schristos       switch (sub)
573*f7313695Schristos 	{
574*f7313695Schristos 	case SUBLANG_DEFAULT: return "ks_PK";
575*f7313695Schristos 	case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
576*f7313695Schristos 	}
577*f7313695Schristos       return "ks";
578*f7313695Schristos     case LANG_KAZAK: return "kk_KZ";
579*f7313695Schristos     case LANG_KONKANI:
580*f7313695Schristos       /* FIXME: Adjust this when such locales appear on Unix.  */
581*f7313695Schristos       return "kok_IN";
582*f7313695Schristos     case LANG_KOREAN: return "ko_KR";
583*f7313695Schristos     case LANG_LATVIAN: return "lv_LV";
584*f7313695Schristos     case LANG_LITHUANIAN: return "lt_LT";
585*f7313695Schristos     case LANG_MACEDONIAN: return "mk_MK";
586*f7313695Schristos     case LANG_MALAY:
587*f7313695Schristos       switch (sub)
588*f7313695Schristos 	{
589*f7313695Schristos 	case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
590*f7313695Schristos 	case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
591*f7313695Schristos 	}
592*f7313695Schristos       return "ms";
593*f7313695Schristos     case LANG_MALAYALAM: return "ml_IN";
594*f7313695Schristos     case LANG_MANIPURI:
595*f7313695Schristos       /* FIXME: Adjust this when such locales appear on Unix.  */
596*f7313695Schristos       return "mni_IN";
597*f7313695Schristos     case LANG_MARATHI: return "mr_IN";
598*f7313695Schristos     case LANG_NEPALI:
599*f7313695Schristos       switch (sub)
600*f7313695Schristos 	{
601*f7313695Schristos 	case SUBLANG_DEFAULT: return "ne_NP";
602*f7313695Schristos 	case SUBLANG_NEPALI_INDIA: return "ne_IN";
603*f7313695Schristos 	}
604*f7313695Schristos       return "ne";
605*f7313695Schristos     case LANG_NORWEGIAN:
606*f7313695Schristos       switch (sub)
607*f7313695Schristos 	{
608*f7313695Schristos 	case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
609*f7313695Schristos 	case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
610*f7313695Schristos 	}
611*f7313695Schristos       return "no";
612*f7313695Schristos     case LANG_ORIYA: return "or_IN";
613*f7313695Schristos     case LANG_POLISH: return "pl_PL";
614*f7313695Schristos     case LANG_PORTUGUESE:
615*f7313695Schristos       switch (sub)
616*f7313695Schristos 	{
617*f7313695Schristos 	case SUBLANG_PORTUGUESE: return "pt_PT";
618*f7313695Schristos 	/* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
619*f7313695Schristos 	   Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
620*f7313695Schristos 	case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
621*f7313695Schristos 	}
622*f7313695Schristos       return "pt";
623*f7313695Schristos     case LANG_PUNJABI: return "pa_IN";
624*f7313695Schristos     case LANG_ROMANIAN: return "ro_RO";
625*f7313695Schristos     case LANG_RUSSIAN:
626*f7313695Schristos       return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA".  */
627*f7313695Schristos     case LANG_SANSKRIT: return "sa_IN";
628*f7313695Schristos     case LANG_SINDHI: return "sd";
629*f7313695Schristos     case LANG_SLOVAK: return "sk_SK";
630*f7313695Schristos     case LANG_SLOVENIAN: return "sl_SI";
631*f7313695Schristos     case LANG_SORBIAN:
632*f7313695Schristos       /* FIXME: Adjust this when such locales appear on Unix.  */
633*f7313695Schristos       return "wen_DE";
634*f7313695Schristos     case LANG_SPANISH:
635*f7313695Schristos       switch (sub)
636*f7313695Schristos 	{
637*f7313695Schristos 	case SUBLANG_SPANISH: return "es_ES";
638*f7313695Schristos 	case SUBLANG_SPANISH_MEXICAN: return "es_MX";
639*f7313695Schristos 	case SUBLANG_SPANISH_MODERN:
640*f7313695Schristos 	  return "es_ES@modern";	/* not seen on Unix */
641*f7313695Schristos 	case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
642*f7313695Schristos 	case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
643*f7313695Schristos 	case SUBLANG_SPANISH_PANAMA: return "es_PA";
644*f7313695Schristos 	case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
645*f7313695Schristos 	case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
646*f7313695Schristos 	case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
647*f7313695Schristos 	case SUBLANG_SPANISH_PERU: return "es_PE";
648*f7313695Schristos 	case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
649*f7313695Schristos 	case SUBLANG_SPANISH_ECUADOR: return "es_EC";
650*f7313695Schristos 	case SUBLANG_SPANISH_CHILE: return "es_CL";
651*f7313695Schristos 	case SUBLANG_SPANISH_URUGUAY: return "es_UY";
652*f7313695Schristos 	case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
653*f7313695Schristos 	case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
654*f7313695Schristos 	case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
655*f7313695Schristos 	case SUBLANG_SPANISH_HONDURAS: return "es_HN";
656*f7313695Schristos 	case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
657*f7313695Schristos 	case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
658*f7313695Schristos 	}
659*f7313695Schristos       return "es";
660*f7313695Schristos     case LANG_SWAHILI: return "sw";
661*f7313695Schristos     case LANG_SWEDISH:
662*f7313695Schristos       switch (sub)
663*f7313695Schristos 	{
664*f7313695Schristos 	case SUBLANG_DEFAULT: return "sv_SE";
665*f7313695Schristos 	case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
666*f7313695Schristos 	}
667*f7313695Schristos       return "sv";
668*f7313695Schristos     case LANG_TAMIL:
669*f7313695Schristos       return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG".  */
670*f7313695Schristos     case LANG_TATAR: return "tt";
671*f7313695Schristos     case LANG_TELUGU: return "te_IN";
672*f7313695Schristos     case LANG_THAI: return "th_TH";
673*f7313695Schristos     case LANG_TURKISH: return "tr_TR";
674*f7313695Schristos     case LANG_UKRAINIAN: return "uk_UA";
675*f7313695Schristos     case LANG_URDU:
676*f7313695Schristos       switch (sub)
677*f7313695Schristos 	{
678*f7313695Schristos 	case SUBLANG_URDU_PAKISTAN: return "ur_PK";
679*f7313695Schristos 	case SUBLANG_URDU_INDIA: return "ur_IN";
680*f7313695Schristos 	}
681*f7313695Schristos       return "ur";
682*f7313695Schristos     case LANG_UZBEK:
683*f7313695Schristos       switch (sub)
684*f7313695Schristos 	{
685*f7313695Schristos 	/* FIXME: Adjust this when Uzbek locales appear on Unix.  */
686*f7313695Schristos 	case SUBLANG_UZBEK_LATIN: return "uz_UZ@latin";
687*f7313695Schristos 	case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
688*f7313695Schristos 	}
689*f7313695Schristos       return "uz";
690*f7313695Schristos     case LANG_VIETNAMESE: return "vi_VN";
691*f7313695Schristos     default: return "C";
692*f7313695Schristos     }
693*f7313695Schristos 
694*f7313695Schristos #endif
695*f7313695Schristos }
696