LCOV - code coverage report
Current view: top level - lib/gltests - localename.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 57 65 87.7 %
Date: 2015-08-01 15:30:48 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Determine name of the currently selected locale.
       2             :    Copyright (C) 1995-2015 Free Software Foundation, Inc.
       3             : 
       4             :    This program is free software: you can redistribute it and/or modify
       5             :    it under the terms of the GNU General Public License as published by
       6             :    the Free Software Foundation; either version 3 of the License, or
       7             :    (at your option) any later version.
       8             : 
       9             :    This program is distributed in the hope that it will be useful,
      10             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :    GNU General Public License for more details.
      13             : 
      14             :    You should have received a copy of the GNU General Public License
      15             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      16             : 
      17             : /* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
      18             : /* Native Windows code written by Tor Lillqvist <tml@iki.fi>.  */
      19             : /* Mac OS X code written by Bruno Haible <bruno@clisp.org>.  */
      20             : 
      21             : #include <config.h>
      22             : 
      23             : /* Specification.  */
      24             : #ifdef IN_LIBINTL
      25             : # include "gettextP.h"
      26             : #else
      27             : # include "localename.h"
      28             : #endif
      29             : 
      30             : #include <limits.h>
      31             : #include <stddef.h>
      32             : #include <stdlib.h>
      33             : #include <locale.h>
      34             : #include <string.h>
      35             : 
      36             : #if HAVE_USELOCALE
      37             : /* Mac OS X 10.5 defines the locale_t type in <xlocale.h>.  */
      38             : # if defined __APPLE__ && defined __MACH__
      39             : #  include <xlocale.h>
      40             : # endif
      41             : # include <langinfo.h>
      42             : # if !defined IN_LIBINTL
      43             : #  include "glthread/lock.h"
      44             : # endif
      45             : # if defined __sun && HAVE_GETLOCALENAME_L
      46             : /* Solaris >= 12.  */
      47             : extern char * getlocalename_l(int, locale_t);
      48             : # endif
      49             : #endif
      50             : 
      51             : #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
      52             : # include <CoreFoundation/CFString.h>
      53             : # if HAVE_CFLOCALECOPYCURRENT
      54             : #  include <CoreFoundation/CFLocale.h>
      55             : # elif HAVE_CFPREFERENCESCOPYAPPVALUE
      56             : #  include <CoreFoundation/CFPreferences.h>
      57             : # endif
      58             : #endif
      59             : 
      60             : #if defined _WIN32 || defined __WIN32__
      61             : # define WINDOWS_NATIVE
      62             : # if !defined IN_LIBINTL
      63             : #  include "glthread/lock.h"
      64             : # endif
      65             : #endif
      66             : 
      67             : #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
      68             : # define WIN32_LEAN_AND_MEAN
      69             : # include <windows.h>
      70             : # include <winnls.h>
      71             : /* List of language codes, sorted by value:
      72             :    0x01 LANG_ARABIC
      73             :    0x02 LANG_BULGARIAN
      74             :    0x03 LANG_CATALAN
      75             :    0x04 LANG_CHINESE
      76             :    0x05 LANG_CZECH
      77             :    0x06 LANG_DANISH
      78             :    0x07 LANG_GERMAN
      79             :    0x08 LANG_GREEK
      80             :    0x09 LANG_ENGLISH
      81             :    0x0a LANG_SPANISH
      82             :    0x0b LANG_FINNISH
      83             :    0x0c LANG_FRENCH
      84             :    0x0d LANG_HEBREW
      85             :    0x0e LANG_HUNGARIAN
      86             :    0x0f LANG_ICELANDIC
      87             :    0x10 LANG_ITALIAN
      88             :    0x11 LANG_JAPANESE
      89             :    0x12 LANG_KOREAN
      90             :    0x13 LANG_DUTCH
      91             :    0x14 LANG_NORWEGIAN
      92             :    0x15 LANG_POLISH
      93             :    0x16 LANG_PORTUGUESE
      94             :    0x17 LANG_ROMANSH
      95             :    0x18 LANG_ROMANIAN
      96             :    0x19 LANG_RUSSIAN
      97             :    0x1a LANG_CROATIAN == LANG_SERBIAN
      98             :    0x1b LANG_SLOVAK
      99             :    0x1c LANG_ALBANIAN
     100             :    0x1d LANG_SWEDISH
     101             :    0x1e LANG_THAI
     102             :    0x1f LANG_TURKISH
     103             :    0x20 LANG_URDU
     104             :    0x21 LANG_INDONESIAN
     105             :    0x22 LANG_UKRAINIAN
     106             :    0x23 LANG_BELARUSIAN
     107             :    0x24 LANG_SLOVENIAN
     108             :    0x25 LANG_ESTONIAN
     109             :    0x26 LANG_LATVIAN
     110             :    0x27 LANG_LITHUANIAN
     111             :    0x28 LANG_TAJIK
     112             :    0x29 LANG_FARSI
     113             :    0x2a LANG_VIETNAMESE
     114             :    0x2b LANG_ARMENIAN
     115             :    0x2c LANG_AZERI
     116             :    0x2d LANG_BASQUE
     117             :    0x2e LANG_SORBIAN
     118             :    0x2f LANG_MACEDONIAN
     119             :    0x30 LANG_SUTU
     120             :    0x31 LANG_TSONGA
     121             :    0x32 LANG_TSWANA
     122             :    0x33 LANG_VENDA
     123             :    0x34 LANG_XHOSA
     124             :    0x35 LANG_ZULU
     125             :    0x36 LANG_AFRIKAANS
     126             :    0x37 LANG_GEORGIAN
     127             :    0x38 LANG_FAEROESE
     128             :    0x39 LANG_HINDI
     129             :    0x3a LANG_MALTESE
     130             :    0x3b LANG_SAMI
     131             :    0x3c LANG_GAELIC
     132             :    0x3d LANG_YIDDISH
     133             :    0x3e LANG_MALAY
     134             :    0x3f LANG_KAZAK
     135             :    0x40 LANG_KYRGYZ
     136             :    0x41 LANG_SWAHILI
     137             :    0x42 LANG_TURKMEN
     138             :    0x43 LANG_UZBEK
     139             :    0x44 LANG_TATAR
     140             :    0x45 LANG_BENGALI
     141             :    0x46 LANG_PUNJABI
     142             :    0x47 LANG_GUJARATI
     143             :    0x48 LANG_ORIYA
     144             :    0x49 LANG_TAMIL
     145             :    0x4a LANG_TELUGU
     146             :    0x4b LANG_KANNADA
     147             :    0x4c LANG_MALAYALAM
     148             :    0x4d LANG_ASSAMESE
     149             :    0x4e LANG_MARATHI
     150             :    0x4f LANG_SANSKRIT
     151             :    0x50 LANG_MONGOLIAN
     152             :    0x51 LANG_TIBETAN
     153             :    0x52 LANG_WELSH
     154             :    0x53 LANG_CAMBODIAN
     155             :    0x54 LANG_LAO
     156             :    0x55 LANG_BURMESE
     157             :    0x56 LANG_GALICIAN
     158             :    0x57 LANG_KONKANI
     159             :    0x58 LANG_MANIPURI
     160             :    0x59 LANG_SINDHI
     161             :    0x5a LANG_SYRIAC
     162             :    0x5b LANG_SINHALESE
     163             :    0x5c LANG_CHEROKEE
     164             :    0x5d LANG_INUKTITUT
     165             :    0x5e LANG_AMHARIC
     166             :    0x5f LANG_TAMAZIGHT
     167             :    0x60 LANG_KASHMIRI
     168             :    0x61 LANG_NEPALI
     169             :    0x62 LANG_FRISIAN
     170             :    0x63 LANG_PASHTO
     171             :    0x64 LANG_TAGALOG
     172             :    0x65 LANG_DIVEHI
     173             :    0x66 LANG_EDO
     174             :    0x67 LANG_FULFULDE
     175             :    0x68 LANG_HAUSA
     176             :    0x69 LANG_IBIBIO
     177             :    0x6a LANG_YORUBA
     178             :    0x6d LANG_BASHKIR
     179             :    0x6e LANG_LUXEMBOURGISH
     180             :    0x6f LANG_GREENLANDIC
     181             :    0x70 LANG_IGBO
     182             :    0x71 LANG_KANURI
     183             :    0x72 LANG_OROMO
     184             :    0x73 LANG_TIGRINYA
     185             :    0x74 LANG_GUARANI
     186             :    0x75 LANG_HAWAIIAN
     187             :    0x76 LANG_LATIN
     188             :    0x77 LANG_SOMALI
     189             :    0x78 LANG_YI
     190             :    0x79 LANG_PAPIAMENTU
     191             :    0x7a LANG_MAPUDUNGUN
     192             :    0x7c LANG_MOHAWK
     193             :    0x7e LANG_BRETON
     194             :    0x82 LANG_OCCITAN
     195             :    0x83 LANG_CORSICAN
     196             :    0x84 LANG_ALSATIAN
     197             :    0x85 LANG_YAKUT
     198             :    0x86 LANG_KICHE
     199             :    0x87 LANG_KINYARWANDA
     200             :    0x88 LANG_WOLOF
     201             :    0x8c LANG_DARI
     202             :    0x91 LANG_SCOTTISH_GAELIC
     203             : */
     204             : /* Mingw headers don't have latest language and sublanguage codes.  */
     205             : # ifndef LANG_AFRIKAANS
     206             : # define LANG_AFRIKAANS 0x36
     207             : # endif
     208             : # ifndef LANG_ALBANIAN
     209             : # define LANG_ALBANIAN 0x1c
     210             : # endif
     211             : # ifndef LANG_ALSATIAN
     212             : # define LANG_ALSATIAN 0x84
     213             : # endif
     214             : # ifndef LANG_AMHARIC
     215             : # define LANG_AMHARIC 0x5e
     216             : # endif
     217             : # ifndef LANG_ARABIC
     218             : # define LANG_ARABIC 0x01
     219             : # endif
     220             : # ifndef LANG_ARMENIAN
     221             : # define LANG_ARMENIAN 0x2b
     222             : # endif
     223             : # ifndef LANG_ASSAMESE
     224             : # define LANG_ASSAMESE 0x4d
     225             : # endif
     226             : # ifndef LANG_AZERI
     227             : # define LANG_AZERI 0x2c
     228             : # endif
     229             : # ifndef LANG_BASHKIR
     230             : # define LANG_BASHKIR 0x6d
     231             : # endif
     232             : # ifndef LANG_BASQUE
     233             : # define LANG_BASQUE 0x2d
     234             : # endif
     235             : # ifndef LANG_BELARUSIAN
     236             : # define LANG_BELARUSIAN 0x23
     237             : # endif
     238             : # ifndef LANG_BENGALI
     239             : # define LANG_BENGALI 0x45
     240             : # endif
     241             : # ifndef LANG_BRETON
     242             : # define LANG_BRETON 0x7e
     243             : # endif
     244             : # ifndef LANG_BURMESE
     245             : # define LANG_BURMESE 0x55
     246             : # endif
     247             : # ifndef LANG_CAMBODIAN
     248             : # define LANG_CAMBODIAN 0x53
     249             : # endif
     250             : # ifndef LANG_CATALAN
     251             : # define LANG_CATALAN 0x03
     252             : # endif
     253             : # ifndef LANG_CHEROKEE
     254             : # define LANG_CHEROKEE 0x5c
     255             : # endif
     256             : # ifndef LANG_CORSICAN
     257             : # define LANG_CORSICAN 0x83
     258             : # endif
     259             : # ifndef LANG_DARI
     260             : # define LANG_DARI 0x8c
     261             : # endif
     262             : # ifndef LANG_DIVEHI
     263             : # define LANG_DIVEHI 0x65
     264             : # endif
     265             : # ifndef LANG_EDO
     266             : # define LANG_EDO 0x66
     267             : # endif
     268             : # ifndef LANG_ESTONIAN
     269             : # define LANG_ESTONIAN 0x25
     270             : # endif
     271             : # ifndef LANG_FAEROESE
     272             : # define LANG_FAEROESE 0x38
     273             : # endif
     274             : # ifndef LANG_FARSI
     275             : # define LANG_FARSI 0x29
     276             : # endif
     277             : # ifndef LANG_FRISIAN
     278             : # define LANG_FRISIAN 0x62
     279             : # endif
     280             : # ifndef LANG_FULFULDE
     281             : # define LANG_FULFULDE 0x67
     282             : # endif
     283             : # ifndef LANG_GAELIC
     284             : # define LANG_GAELIC 0x3c
     285             : # endif
     286             : # ifndef LANG_GALICIAN
     287             : # define LANG_GALICIAN 0x56
     288             : # endif
     289             : # ifndef LANG_GEORGIAN
     290             : # define LANG_GEORGIAN 0x37
     291             : # endif
     292             : # ifndef LANG_GREENLANDIC
     293             : # define LANG_GREENLANDIC 0x6f
     294             : # endif
     295             : # ifndef LANG_GUARANI
     296             : # define LANG_GUARANI 0x74
     297             : # endif
     298             : # ifndef LANG_GUJARATI
     299             : # define LANG_GUJARATI 0x47
     300             : # endif
     301             : # ifndef LANG_HAUSA
     302             : # define LANG_HAUSA 0x68
     303             : # endif
     304             : # ifndef LANG_HAWAIIAN
     305             : # define LANG_HAWAIIAN 0x75
     306             : # endif
     307             : # ifndef LANG_HEBREW
     308             : # define LANG_HEBREW 0x0d
     309             : # endif
     310             : # ifndef LANG_HINDI
     311             : # define LANG_HINDI 0x39
     312             : # endif
     313             : # ifndef LANG_IBIBIO
     314             : # define LANG_IBIBIO 0x69
     315             : # endif
     316             : # ifndef LANG_IGBO
     317             : # define LANG_IGBO 0x70
     318             : # endif
     319             : # ifndef LANG_INDONESIAN
     320             : # define LANG_INDONESIAN 0x21
     321             : # endif
     322             : # ifndef LANG_INUKTITUT
     323             : # define LANG_INUKTITUT 0x5d
     324             : # endif
     325             : # ifndef LANG_KANNADA
     326             : # define LANG_KANNADA 0x4b
     327             : # endif
     328             : # ifndef LANG_KANURI
     329             : # define LANG_KANURI 0x71
     330             : # endif
     331             : # ifndef LANG_KASHMIRI
     332             : # define LANG_KASHMIRI 0x60
     333             : # endif
     334             : # ifndef LANG_KAZAK
     335             : # define LANG_KAZAK 0x3f
     336             : # endif
     337             : # ifndef LANG_KICHE
     338             : # define LANG_KICHE 0x86
     339             : # endif
     340             : # ifndef LANG_KINYARWANDA
     341             : # define LANG_KINYARWANDA 0x87
     342             : # endif
     343             : # ifndef LANG_KONKANI
     344             : # define LANG_KONKANI 0x57
     345             : # endif
     346             : # ifndef LANG_KYRGYZ
     347             : # define LANG_KYRGYZ 0x40
     348             : # endif
     349             : # ifndef LANG_LAO
     350             : # define LANG_LAO 0x54
     351             : # endif
     352             : # ifndef LANG_LATIN
     353             : # define LANG_LATIN 0x76
     354             : # endif
     355             : # ifndef LANG_LATVIAN
     356             : # define LANG_LATVIAN 0x26
     357             : # endif
     358             : # ifndef LANG_LITHUANIAN
     359             : # define LANG_LITHUANIAN 0x27
     360             : # endif
     361             : # ifndef LANG_LUXEMBOURGISH
     362             : # define LANG_LUXEMBOURGISH 0x6e
     363             : # endif
     364             : # ifndef LANG_MACEDONIAN
     365             : # define LANG_MACEDONIAN 0x2f
     366             : # endif
     367             : # ifndef LANG_MALAY
     368             : # define LANG_MALAY 0x3e
     369             : # endif
     370             : # ifndef LANG_MALAYALAM
     371             : # define LANG_MALAYALAM 0x4c
     372             : # endif
     373             : # ifndef LANG_MALTESE
     374             : # define LANG_MALTESE 0x3a
     375             : # endif
     376             : # ifndef LANG_MANIPURI
     377             : # define LANG_MANIPURI 0x58
     378             : # endif
     379             : # ifndef LANG_MAORI
     380             : # define LANG_MAORI 0x81
     381             : # endif
     382             : # ifndef LANG_MAPUDUNGUN
     383             : # define LANG_MAPUDUNGUN 0x7a
     384             : # endif
     385             : # ifndef LANG_MARATHI
     386             : # define LANG_MARATHI 0x4e
     387             : # endif
     388             : # ifndef LANG_MOHAWK
     389             : # define LANG_MOHAWK 0x7c
     390             : # endif
     391             : # ifndef LANG_MONGOLIAN
     392             : # define LANG_MONGOLIAN 0x50
     393             : # endif
     394             : # ifndef LANG_NEPALI
     395             : # define LANG_NEPALI 0x61
     396             : # endif
     397             : # ifndef LANG_OCCITAN
     398             : # define LANG_OCCITAN 0x82
     399             : # endif
     400             : # ifndef LANG_ORIYA
     401             : # define LANG_ORIYA 0x48
     402             : # endif
     403             : # ifndef LANG_OROMO
     404             : # define LANG_OROMO 0x72
     405             : # endif
     406             : # ifndef LANG_PAPIAMENTU
     407             : # define LANG_PAPIAMENTU 0x79
     408             : # endif
     409             : # ifndef LANG_PASHTO
     410             : # define LANG_PASHTO 0x63
     411             : # endif
     412             : # ifndef LANG_PUNJABI
     413             : # define LANG_PUNJABI 0x46
     414             : # endif
     415             : # ifndef LANG_QUECHUA
     416             : # define LANG_QUECHUA 0x6b
     417             : # endif
     418             : # ifndef LANG_ROMANSH
     419             : # define LANG_ROMANSH 0x17
     420             : # endif
     421             : # ifndef LANG_SAMI
     422             : # define LANG_SAMI 0x3b
     423             : # endif
     424             : # ifndef LANG_SANSKRIT
     425             : # define LANG_SANSKRIT 0x4f
     426             : # endif
     427             : # ifndef LANG_SCOTTISH_GAELIC
     428             : # define LANG_SCOTTISH_GAELIC 0x91
     429             : # endif
     430             : # ifndef LANG_SERBIAN
     431             : # define LANG_SERBIAN 0x1a
     432             : # endif
     433             : # ifndef LANG_SINDHI
     434             : # define LANG_SINDHI 0x59
     435             : # endif
     436             : # ifndef LANG_SINHALESE
     437             : # define LANG_SINHALESE 0x5b
     438             : # endif
     439             : # ifndef LANG_SLOVAK
     440             : # define LANG_SLOVAK 0x1b
     441             : # endif
     442             : # ifndef LANG_SOMALI
     443             : # define LANG_SOMALI 0x77
     444             : # endif
     445             : # ifndef LANG_SORBIAN
     446             : # define LANG_SORBIAN 0x2e
     447             : # endif
     448             : # ifndef LANG_SOTHO
     449             : # define LANG_SOTHO 0x6c
     450             : # endif
     451             : # ifndef LANG_SUTU
     452             : # define LANG_SUTU 0x30
     453             : # endif
     454             : # ifndef LANG_SWAHILI
     455             : # define LANG_SWAHILI 0x41
     456             : # endif
     457             : # ifndef LANG_SYRIAC
     458             : # define LANG_SYRIAC 0x5a
     459             : # endif
     460             : # ifndef LANG_TAGALOG
     461             : # define LANG_TAGALOG 0x64
     462             : # endif
     463             : # ifndef LANG_TAJIK
     464             : # define LANG_TAJIK 0x28
     465             : # endif
     466             : # ifndef LANG_TAMAZIGHT
     467             : # define LANG_TAMAZIGHT 0x5f
     468             : # endif
     469             : # ifndef LANG_TAMIL
     470             : # define LANG_TAMIL 0x49
     471             : # endif
     472             : # ifndef LANG_TATAR
     473             : # define LANG_TATAR 0x44
     474             : # endif
     475             : # ifndef LANG_TELUGU
     476             : # define LANG_TELUGU 0x4a
     477             : # endif
     478             : # ifndef LANG_THAI
     479             : # define LANG_THAI 0x1e
     480             : # endif
     481             : # ifndef LANG_TIBETAN
     482             : # define LANG_TIBETAN 0x51
     483             : # endif
     484             : # ifndef LANG_TIGRINYA
     485             : # define LANG_TIGRINYA 0x73
     486             : # endif
     487             : # ifndef LANG_TSONGA
     488             : # define LANG_TSONGA 0x31
     489             : # endif
     490             : # ifndef LANG_TSWANA
     491             : # define LANG_TSWANA 0x32
     492             : # endif
     493             : # ifndef LANG_TURKMEN
     494             : # define LANG_TURKMEN 0x42
     495             : # endif
     496             : # ifndef LANG_UIGHUR
     497             : # define LANG_UIGHUR 0x80
     498             : # endif
     499             : # ifndef LANG_UKRAINIAN
     500             : # define LANG_UKRAINIAN 0x22
     501             : # endif
     502             : # ifndef LANG_URDU
     503             : # define LANG_URDU 0x20
     504             : # endif
     505             : # ifndef LANG_UZBEK
     506             : # define LANG_UZBEK 0x43
     507             : # endif
     508             : # ifndef LANG_VENDA
     509             : # define LANG_VENDA 0x33
     510             : # endif
     511             : # ifndef LANG_VIETNAMESE
     512             : # define LANG_VIETNAMESE 0x2a
     513             : # endif
     514             : # ifndef LANG_WELSH
     515             : # define LANG_WELSH 0x52
     516             : # endif
     517             : # ifndef LANG_WOLOF
     518             : # define LANG_WOLOF 0x88
     519             : # endif
     520             : # ifndef LANG_XHOSA
     521             : # define LANG_XHOSA 0x34
     522             : # endif
     523             : # ifndef LANG_YAKUT
     524             : # define LANG_YAKUT 0x85
     525             : # endif
     526             : # ifndef LANG_YI
     527             : # define LANG_YI 0x78
     528             : # endif
     529             : # ifndef LANG_YIDDISH
     530             : # define LANG_YIDDISH 0x3d
     531             : # endif
     532             : # ifndef LANG_YORUBA
     533             : # define LANG_YORUBA 0x6a
     534             : # endif
     535             : # ifndef LANG_ZULU
     536             : # define LANG_ZULU 0x35
     537             : # endif
     538             : # ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA
     539             : # define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01
     540             : # endif
     541             : # ifndef SUBLANG_ALBANIAN_ALBANIA
     542             : # define SUBLANG_ALBANIAN_ALBANIA 0x01
     543             : # endif
     544             : # ifndef SUBLANG_ALSATIAN_FRANCE
     545             : # define SUBLANG_ALSATIAN_FRANCE 0x01
     546             : # endif
     547             : # ifndef SUBLANG_AMHARIC_ETHIOPIA
     548             : # define SUBLANG_AMHARIC_ETHIOPIA 0x01
     549             : # endif
     550             : # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
     551             : # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
     552             : # endif
     553             : # ifndef SUBLANG_ARABIC_IRAQ
     554             : # define SUBLANG_ARABIC_IRAQ 0x02
     555             : # endif
     556             : # ifndef SUBLANG_ARABIC_EGYPT
     557             : # define SUBLANG_ARABIC_EGYPT 0x03
     558             : # endif
     559             : # ifndef SUBLANG_ARABIC_LIBYA
     560             : # define SUBLANG_ARABIC_LIBYA 0x04
     561             : # endif
     562             : # ifndef SUBLANG_ARABIC_ALGERIA
     563             : # define SUBLANG_ARABIC_ALGERIA 0x05
     564             : # endif
     565             : # ifndef SUBLANG_ARABIC_MOROCCO
     566             : # define SUBLANG_ARABIC_MOROCCO 0x06
     567             : # endif
     568             : # ifndef SUBLANG_ARABIC_TUNISIA
     569             : # define SUBLANG_ARABIC_TUNISIA 0x07
     570             : # endif
     571             : # ifndef SUBLANG_ARABIC_OMAN
     572             : # define SUBLANG_ARABIC_OMAN 0x08
     573             : # endif
     574             : # ifndef SUBLANG_ARABIC_YEMEN
     575             : # define SUBLANG_ARABIC_YEMEN 0x09
     576             : # endif
     577             : # ifndef SUBLANG_ARABIC_SYRIA
     578             : # define SUBLANG_ARABIC_SYRIA 0x0a
     579             : # endif
     580             : # ifndef SUBLANG_ARABIC_JORDAN
     581             : # define SUBLANG_ARABIC_JORDAN 0x0b
     582             : # endif
     583             : # ifndef SUBLANG_ARABIC_LEBANON
     584             : # define SUBLANG_ARABIC_LEBANON 0x0c
     585             : # endif
     586             : # ifndef SUBLANG_ARABIC_KUWAIT
     587             : # define SUBLANG_ARABIC_KUWAIT 0x0d
     588             : # endif
     589             : # ifndef SUBLANG_ARABIC_UAE
     590             : # define SUBLANG_ARABIC_UAE 0x0e
     591             : # endif
     592             : # ifndef SUBLANG_ARABIC_BAHRAIN
     593             : # define SUBLANG_ARABIC_BAHRAIN 0x0f
     594             : # endif
     595             : # ifndef SUBLANG_ARABIC_QATAR
     596             : # define SUBLANG_ARABIC_QATAR 0x10
     597             : # endif
     598             : # ifndef SUBLANG_ARMENIAN_ARMENIA
     599             : # define SUBLANG_ARMENIAN_ARMENIA 0x01
     600             : # endif
     601             : # ifndef SUBLANG_ASSAMESE_INDIA
     602             : # define SUBLANG_ASSAMESE_INDIA 0x01
     603             : # endif
     604             : # ifndef SUBLANG_AZERI_LATIN
     605             : # define SUBLANG_AZERI_LATIN 0x01
     606             : # endif
     607             : # ifndef SUBLANG_AZERI_CYRILLIC
     608             : # define SUBLANG_AZERI_CYRILLIC 0x02
     609             : # endif
     610             : # ifndef SUBLANG_BASHKIR_RUSSIA
     611             : # define SUBLANG_BASHKIR_RUSSIA 0x01
     612             : # endif
     613             : # ifndef SUBLANG_BASQUE_BASQUE
     614             : # define SUBLANG_BASQUE_BASQUE 0x01
     615             : # endif
     616             : # ifndef SUBLANG_BELARUSIAN_BELARUS
     617             : # define SUBLANG_BELARUSIAN_BELARUS 0x01
     618             : # endif
     619             : # ifndef SUBLANG_BENGALI_INDIA
     620             : # define SUBLANG_BENGALI_INDIA 0x01
     621             : # endif
     622             : # ifndef SUBLANG_BENGALI_BANGLADESH
     623             : # define SUBLANG_BENGALI_BANGLADESH 0x02
     624             : # endif
     625             : # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
     626             : # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
     627             : # endif
     628             : # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
     629             : # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
     630             : # endif
     631             : # ifndef SUBLANG_BRETON_FRANCE
     632             : # define SUBLANG_BRETON_FRANCE 0x01
     633             : # endif
     634             : # ifndef SUBLANG_BULGARIAN_BULGARIA
     635             : # define SUBLANG_BULGARIAN_BULGARIA 0x01
     636             : # endif
     637             : # ifndef SUBLANG_CAMBODIAN_CAMBODIA
     638             : # define SUBLANG_CAMBODIAN_CAMBODIA 0x01
     639             : # endif
     640             : # ifndef SUBLANG_CATALAN_SPAIN
     641             : # define SUBLANG_CATALAN_SPAIN 0x01
     642             : # endif
     643             : # ifndef SUBLANG_CORSICAN_FRANCE
     644             : # define SUBLANG_CORSICAN_FRANCE 0x01
     645             : # endif
     646             : # ifndef SUBLANG_CROATIAN_CROATIA
     647             : # define SUBLANG_CROATIAN_CROATIA 0x01
     648             : # endif
     649             : # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
     650             : # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
     651             : # endif
     652             : # ifndef SUBLANG_CHINESE_MACAU
     653             : # define SUBLANG_CHINESE_MACAU 0x05
     654             : # endif
     655             : # ifndef SUBLANG_CZECH_CZECH_REPUBLIC
     656             : # define SUBLANG_CZECH_CZECH_REPUBLIC 0x01
     657             : # endif
     658             : # ifndef SUBLANG_DANISH_DENMARK
     659             : # define SUBLANG_DANISH_DENMARK 0x01
     660             : # endif
     661             : # ifndef SUBLANG_DARI_AFGHANISTAN
     662             : # define SUBLANG_DARI_AFGHANISTAN 0x01
     663             : # endif
     664             : # ifndef SUBLANG_DIVEHI_MALDIVES
     665             : # define SUBLANG_DIVEHI_MALDIVES 0x01
     666             : # endif
     667             : # ifndef SUBLANG_DUTCH_SURINAM
     668             : # define SUBLANG_DUTCH_SURINAM 0x03
     669             : # endif
     670             : # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
     671             : # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
     672             : # endif
     673             : # ifndef SUBLANG_ENGLISH_JAMAICA
     674             : # define SUBLANG_ENGLISH_JAMAICA 0x08
     675             : # endif
     676             : # ifndef SUBLANG_ENGLISH_CARIBBEAN
     677             : # define SUBLANG_ENGLISH_CARIBBEAN 0x09
     678             : # endif
     679             : # ifndef SUBLANG_ENGLISH_BELIZE
     680             : # define SUBLANG_ENGLISH_BELIZE 0x0a
     681             : # endif
     682             : # ifndef SUBLANG_ENGLISH_TRINIDAD
     683             : # define SUBLANG_ENGLISH_TRINIDAD 0x0b
     684             : # endif
     685             : # ifndef SUBLANG_ENGLISH_ZIMBABWE
     686             : # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
     687             : # endif
     688             : # ifndef SUBLANG_ENGLISH_PHILIPPINES
     689             : # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
     690             : # endif
     691             : # ifndef SUBLANG_ENGLISH_INDONESIA
     692             : # define SUBLANG_ENGLISH_INDONESIA 0x0e
     693             : # endif
     694             : # ifndef SUBLANG_ENGLISH_HONGKONG
     695             : # define SUBLANG_ENGLISH_HONGKONG 0x0f
     696             : # endif
     697             : # ifndef SUBLANG_ENGLISH_INDIA
     698             : # define SUBLANG_ENGLISH_INDIA 0x10
     699             : # endif
     700             : # ifndef SUBLANG_ENGLISH_MALAYSIA
     701             : # define SUBLANG_ENGLISH_MALAYSIA 0x11
     702             : # endif
     703             : # ifndef SUBLANG_ENGLISH_SINGAPORE
     704             : # define SUBLANG_ENGLISH_SINGAPORE 0x12
     705             : # endif
     706             : # ifndef SUBLANG_ESTONIAN_ESTONIA
     707             : # define SUBLANG_ESTONIAN_ESTONIA 0x01
     708             : # endif
     709             : # ifndef SUBLANG_FAEROESE_FAROE_ISLANDS
     710             : # define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01
     711             : # endif
     712             : # ifndef SUBLANG_FARSI_IRAN
     713             : # define SUBLANG_FARSI_IRAN 0x01
     714             : # endif
     715             : # ifndef SUBLANG_FINNISH_FINLAND
     716             : # define SUBLANG_FINNISH_FINLAND 0x01
     717             : # endif
     718             : # ifndef SUBLANG_FRENCH_LUXEMBOURG
     719             : # define SUBLANG_FRENCH_LUXEMBOURG 0x05
     720             : # endif
     721             : # ifndef SUBLANG_FRENCH_MONACO
     722             : # define SUBLANG_FRENCH_MONACO 0x06
     723             : # endif
     724             : # ifndef SUBLANG_FRENCH_WESTINDIES
     725             : # define SUBLANG_FRENCH_WESTINDIES 0x07
     726             : # endif
     727             : # ifndef SUBLANG_FRENCH_REUNION
     728             : # define SUBLANG_FRENCH_REUNION 0x08
     729             : # endif
     730             : # ifndef SUBLANG_FRENCH_CONGO
     731             : # define SUBLANG_FRENCH_CONGO 0x09
     732             : # endif
     733             : # ifndef SUBLANG_FRENCH_SENEGAL
     734             : # define SUBLANG_FRENCH_SENEGAL 0x0a
     735             : # endif
     736             : # ifndef SUBLANG_FRENCH_CAMEROON
     737             : # define SUBLANG_FRENCH_CAMEROON 0x0b
     738             : # endif
     739             : # ifndef SUBLANG_FRENCH_COTEDIVOIRE
     740             : # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
     741             : # endif
     742             : # ifndef SUBLANG_FRENCH_MALI
     743             : # define SUBLANG_FRENCH_MALI 0x0d
     744             : # endif
     745             : # ifndef SUBLANG_FRENCH_MOROCCO
     746             : # define SUBLANG_FRENCH_MOROCCO 0x0e
     747             : # endif
     748             : # ifndef SUBLANG_FRENCH_HAITI
     749             : # define SUBLANG_FRENCH_HAITI 0x0f
     750             : # endif
     751             : # ifndef SUBLANG_FRISIAN_NETHERLANDS
     752             : # define SUBLANG_FRISIAN_NETHERLANDS 0x01
     753             : # endif
     754             : # ifndef SUBLANG_GALICIAN_SPAIN
     755             : # define SUBLANG_GALICIAN_SPAIN 0x01
     756             : # endif
     757             : # ifndef SUBLANG_GEORGIAN_GEORGIA
     758             : # define SUBLANG_GEORGIAN_GEORGIA 0x01
     759             : # endif
     760             : # ifndef SUBLANG_GERMAN_LUXEMBOURG
     761             : # define SUBLANG_GERMAN_LUXEMBOURG 0x04
     762             : # endif
     763             : # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
     764             : # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
     765             : # endif
     766             : # ifndef SUBLANG_GREEK_GREECE
     767             : # define SUBLANG_GREEK_GREECE 0x01
     768             : # endif
     769             : # ifndef SUBLANG_GREENLANDIC_GREENLAND
     770             : # define SUBLANG_GREENLANDIC_GREENLAND 0x01
     771             : # endif
     772             : # ifndef SUBLANG_GUJARATI_INDIA
     773             : # define SUBLANG_GUJARATI_INDIA 0x01
     774             : # endif
     775             : # ifndef SUBLANG_HAUSA_NIGERIA_LATIN
     776             : # define SUBLANG_HAUSA_NIGERIA_LATIN 0x01
     777             : # endif
     778             : # ifndef SUBLANG_HEBREW_ISRAEL
     779             : # define SUBLANG_HEBREW_ISRAEL 0x01
     780             : # endif
     781             : # ifndef SUBLANG_HINDI_INDIA
     782             : # define SUBLANG_HINDI_INDIA 0x01
     783             : # endif
     784             : # ifndef SUBLANG_HUNGARIAN_HUNGARY
     785             : # define SUBLANG_HUNGARIAN_HUNGARY 0x01
     786             : # endif
     787             : # ifndef SUBLANG_ICELANDIC_ICELAND
     788             : # define SUBLANG_ICELANDIC_ICELAND 0x01
     789             : # endif
     790             : # ifndef SUBLANG_IGBO_NIGERIA
     791             : # define SUBLANG_IGBO_NIGERIA 0x01
     792             : # endif
     793             : # ifndef SUBLANG_INDONESIAN_INDONESIA
     794             : # define SUBLANG_INDONESIAN_INDONESIA 0x01
     795             : # endif
     796             : # ifndef SUBLANG_INUKTITUT_CANADA
     797             : # define SUBLANG_INUKTITUT_CANADA 0x01
     798             : # endif
     799             : # undef SUBLANG_INUKTITUT_CANADA_LATIN
     800             : # define SUBLANG_INUKTITUT_CANADA_LATIN 0x02
     801             : # undef SUBLANG_IRISH_IRELAND
     802             : # define SUBLANG_IRISH_IRELAND 0x02
     803             : # ifndef SUBLANG_JAPANESE_JAPAN
     804             : # define SUBLANG_JAPANESE_JAPAN 0x01
     805             : # endif
     806             : # ifndef SUBLANG_KANNADA_INDIA
     807             : # define SUBLANG_KANNADA_INDIA 0x01
     808             : # endif
     809             : # ifndef SUBLANG_KASHMIRI_INDIA
     810             : # define SUBLANG_KASHMIRI_INDIA 0x02
     811             : # endif
     812             : # ifndef SUBLANG_KAZAK_KAZAKHSTAN
     813             : # define SUBLANG_KAZAK_KAZAKHSTAN 0x01
     814             : # endif
     815             : # ifndef SUBLANG_KICHE_GUATEMALA
     816             : # define SUBLANG_KICHE_GUATEMALA 0x01
     817             : # endif
     818             : # ifndef SUBLANG_KINYARWANDA_RWANDA
     819             : # define SUBLANG_KINYARWANDA_RWANDA 0x01
     820             : # endif
     821             : # ifndef SUBLANG_KONKANI_INDIA
     822             : # define SUBLANG_KONKANI_INDIA 0x01
     823             : # endif
     824             : # ifndef SUBLANG_KYRGYZ_KYRGYZSTAN
     825             : # define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01
     826             : # endif
     827             : # ifndef SUBLANG_LAO_LAOS
     828             : # define SUBLANG_LAO_LAOS 0x01
     829             : # endif
     830             : # ifndef SUBLANG_LATVIAN_LATVIA
     831             : # define SUBLANG_LATVIAN_LATVIA 0x01
     832             : # endif
     833             : # ifndef SUBLANG_LITHUANIAN_LITHUANIA
     834             : # define SUBLANG_LITHUANIAN_LITHUANIA 0x01
     835             : # endif
     836             : # undef SUBLANG_LOWER_SORBIAN_GERMANY
     837             : # define SUBLANG_LOWER_SORBIAN_GERMANY 0x02
     838             : # ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG
     839             : # define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01
     840             : # endif
     841             : # ifndef SUBLANG_MACEDONIAN_MACEDONIA
     842             : # define SUBLANG_MACEDONIAN_MACEDONIA 0x01
     843             : # endif
     844             : # ifndef SUBLANG_MALAY_MALAYSIA
     845             : # define SUBLANG_MALAY_MALAYSIA 0x01
     846             : # endif
     847             : # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
     848             : # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
     849             : # endif
     850             : # ifndef SUBLANG_MALAYALAM_INDIA
     851             : # define SUBLANG_MALAYALAM_INDIA 0x01
     852             : # endif
     853             : # ifndef SUBLANG_MALTESE_MALTA
     854             : # define SUBLANG_MALTESE_MALTA 0x01
     855             : # endif
     856             : # ifndef SUBLANG_MAORI_NEW_ZEALAND
     857             : # define SUBLANG_MAORI_NEW_ZEALAND 0x01
     858             : # endif
     859             : # ifndef SUBLANG_MAPUDUNGUN_CHILE
     860             : # define SUBLANG_MAPUDUNGUN_CHILE 0x01
     861             : # endif
     862             : # ifndef SUBLANG_MARATHI_INDIA
     863             : # define SUBLANG_MARATHI_INDIA 0x01
     864             : # endif
     865             : # ifndef SUBLANG_MOHAWK_CANADA
     866             : # define SUBLANG_MOHAWK_CANADA 0x01
     867             : # endif
     868             : # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
     869             : # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
     870             : # endif
     871             : # ifndef SUBLANG_MONGOLIAN_PRC
     872             : # define SUBLANG_MONGOLIAN_PRC 0x02
     873             : # endif
     874             : # ifndef SUBLANG_NEPALI_NEPAL
     875             : # define SUBLANG_NEPALI_NEPAL 0x01
     876             : # endif
     877             : # ifndef SUBLANG_NEPALI_INDIA
     878             : # define SUBLANG_NEPALI_INDIA 0x02
     879             : # endif
     880             : # ifndef SUBLANG_OCCITAN_FRANCE
     881             : # define SUBLANG_OCCITAN_FRANCE 0x01
     882             : # endif
     883             : # ifndef SUBLANG_ORIYA_INDIA
     884             : # define SUBLANG_ORIYA_INDIA 0x01
     885             : # endif
     886             : # ifndef SUBLANG_PASHTO_AFGHANISTAN
     887             : # define SUBLANG_PASHTO_AFGHANISTAN 0x01
     888             : # endif
     889             : # ifndef SUBLANG_POLISH_POLAND
     890             : # define SUBLANG_POLISH_POLAND 0x01
     891             : # endif
     892             : # ifndef SUBLANG_PUNJABI_INDIA
     893             : # define SUBLANG_PUNJABI_INDIA 0x01
     894             : # endif
     895             : # ifndef SUBLANG_PUNJABI_PAKISTAN
     896             : # define SUBLANG_PUNJABI_PAKISTAN 0x02
     897             : # endif
     898             : # ifndef SUBLANG_QUECHUA_BOLIVIA
     899             : # define SUBLANG_QUECHUA_BOLIVIA 0x01
     900             : # endif
     901             : # ifndef SUBLANG_QUECHUA_ECUADOR
     902             : # define SUBLANG_QUECHUA_ECUADOR 0x02
     903             : # endif
     904             : # ifndef SUBLANG_QUECHUA_PERU
     905             : # define SUBLANG_QUECHUA_PERU 0x03
     906             : # endif
     907             : # ifndef SUBLANG_ROMANIAN_ROMANIA
     908             : # define SUBLANG_ROMANIAN_ROMANIA 0x01
     909             : # endif
     910             : # ifndef SUBLANG_ROMANIAN_MOLDOVA
     911             : # define SUBLANG_ROMANIAN_MOLDOVA 0x02
     912             : # endif
     913             : # ifndef SUBLANG_ROMANSH_SWITZERLAND
     914             : # define SUBLANG_ROMANSH_SWITZERLAND 0x01
     915             : # endif
     916             : # ifndef SUBLANG_RUSSIAN_RUSSIA
     917             : # define SUBLANG_RUSSIAN_RUSSIA 0x01
     918             : # endif
     919             : # ifndef SUBLANG_RUSSIAN_MOLDAVIA
     920             : # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
     921             : # endif
     922             : # ifndef SUBLANG_SAMI_NORTHERN_NORWAY
     923             : # define SUBLANG_SAMI_NORTHERN_NORWAY 0x01
     924             : # endif
     925             : # ifndef SUBLANG_SAMI_NORTHERN_SWEDEN
     926             : # define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02
     927             : # endif
     928             : # ifndef SUBLANG_SAMI_NORTHERN_FINLAND
     929             : # define SUBLANG_SAMI_NORTHERN_FINLAND 0x03
     930             : # endif
     931             : # ifndef SUBLANG_SAMI_LULE_NORWAY
     932             : # define SUBLANG_SAMI_LULE_NORWAY 0x04
     933             : # endif
     934             : # ifndef SUBLANG_SAMI_LULE_SWEDEN
     935             : # define SUBLANG_SAMI_LULE_SWEDEN 0x05
     936             : # endif
     937             : # ifndef SUBLANG_SAMI_SOUTHERN_NORWAY
     938             : # define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06
     939             : # endif
     940             : # ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN
     941             : # define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07
     942             : # endif
     943             : # undef SUBLANG_SAMI_SKOLT_FINLAND
     944             : # define SUBLANG_SAMI_SKOLT_FINLAND 0x08
     945             : # undef SUBLANG_SAMI_INARI_FINLAND
     946             : # define SUBLANG_SAMI_INARI_FINLAND 0x09
     947             : # ifndef SUBLANG_SANSKRIT_INDIA
     948             : # define SUBLANG_SANSKRIT_INDIA 0x01
     949             : # endif
     950             : # ifndef SUBLANG_SERBIAN_LATIN
     951             : # define SUBLANG_SERBIAN_LATIN 0x02
     952             : # endif
     953             : # ifndef SUBLANG_SERBIAN_CYRILLIC
     954             : # define SUBLANG_SERBIAN_CYRILLIC 0x03
     955             : # endif
     956             : # ifndef SUBLANG_SINDHI_INDIA
     957             : # define SUBLANG_SINDHI_INDIA 0x01
     958             : # endif
     959             : # undef SUBLANG_SINDHI_PAKISTAN
     960             : # define SUBLANG_SINDHI_PAKISTAN 0x02
     961             : # ifndef SUBLANG_SINDHI_AFGHANISTAN
     962             : # define SUBLANG_SINDHI_AFGHANISTAN 0x02
     963             : # endif
     964             : # ifndef SUBLANG_SINHALESE_SRI_LANKA
     965             : # define SUBLANG_SINHALESE_SRI_LANKA 0x01
     966             : # endif
     967             : # ifndef SUBLANG_SLOVAK_SLOVAKIA
     968             : # define SUBLANG_SLOVAK_SLOVAKIA 0x01
     969             : # endif
     970             : # ifndef SUBLANG_SLOVENIAN_SLOVENIA
     971             : # define SUBLANG_SLOVENIAN_SLOVENIA 0x01
     972             : # endif
     973             : # ifndef SUBLANG_SOTHO_SOUTH_AFRICA
     974             : # define SUBLANG_SOTHO_SOUTH_AFRICA 0x01
     975             : # endif
     976             : # ifndef SUBLANG_SPANISH_GUATEMALA
     977             : # define SUBLANG_SPANISH_GUATEMALA 0x04
     978             : # endif
     979             : # ifndef SUBLANG_SPANISH_COSTA_RICA
     980             : # define SUBLANG_SPANISH_COSTA_RICA 0x05
     981             : # endif
     982             : # ifndef SUBLANG_SPANISH_PANAMA
     983             : # define SUBLANG_SPANISH_PANAMA 0x06
     984             : # endif
     985             : # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
     986             : # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
     987             : # endif
     988             : # ifndef SUBLANG_SPANISH_VENEZUELA
     989             : # define SUBLANG_SPANISH_VENEZUELA 0x08
     990             : # endif
     991             : # ifndef SUBLANG_SPANISH_COLOMBIA
     992             : # define SUBLANG_SPANISH_COLOMBIA 0x09
     993             : # endif
     994             : # ifndef SUBLANG_SPANISH_PERU
     995             : # define SUBLANG_SPANISH_PERU 0x0a
     996             : # endif
     997             : # ifndef SUBLANG_SPANISH_ARGENTINA
     998             : # define SUBLANG_SPANISH_ARGENTINA 0x0b
     999             : # endif
    1000             : # ifndef SUBLANG_SPANISH_ECUADOR
    1001             : # define SUBLANG_SPANISH_ECUADOR 0x0c
    1002             : # endif
    1003             : # ifndef SUBLANG_SPANISH_CHILE
    1004             : # define SUBLANG_SPANISH_CHILE 0x0d
    1005             : # endif
    1006             : # ifndef SUBLANG_SPANISH_URUGUAY
    1007             : # define SUBLANG_SPANISH_URUGUAY 0x0e
    1008             : # endif
    1009             : # ifndef SUBLANG_SPANISH_PARAGUAY
    1010             : # define SUBLANG_SPANISH_PARAGUAY 0x0f
    1011             : # endif
    1012             : # ifndef SUBLANG_SPANISH_BOLIVIA
    1013             : # define SUBLANG_SPANISH_BOLIVIA 0x10
    1014             : # endif
    1015             : # ifndef SUBLANG_SPANISH_EL_SALVADOR
    1016             : # define SUBLANG_SPANISH_EL_SALVADOR 0x11
    1017             : # endif
    1018             : # ifndef SUBLANG_SPANISH_HONDURAS
    1019             : # define SUBLANG_SPANISH_HONDURAS 0x12
    1020             : # endif
    1021             : # ifndef SUBLANG_SPANISH_NICARAGUA
    1022             : # define SUBLANG_SPANISH_NICARAGUA 0x13
    1023             : # endif
    1024             : # ifndef SUBLANG_SPANISH_PUERTO_RICO
    1025             : # define SUBLANG_SPANISH_PUERTO_RICO 0x14
    1026             : # endif
    1027             : # ifndef SUBLANG_SPANISH_US
    1028             : # define SUBLANG_SPANISH_US 0x15
    1029             : # endif
    1030             : # ifndef SUBLANG_SWAHILI_KENYA
    1031             : # define SUBLANG_SWAHILI_KENYA 0x01
    1032             : # endif
    1033             : # ifndef SUBLANG_SWEDISH_SWEDEN
    1034             : # define SUBLANG_SWEDISH_SWEDEN 0x01
    1035             : # endif
    1036             : # ifndef SUBLANG_SWEDISH_FINLAND
    1037             : # define SUBLANG_SWEDISH_FINLAND 0x02
    1038             : # endif
    1039             : # ifndef SUBLANG_SYRIAC_SYRIA
    1040             : # define SUBLANG_SYRIAC_SYRIA 0x01
    1041             : # endif
    1042             : # ifndef SUBLANG_TAGALOG_PHILIPPINES
    1043             : # define SUBLANG_TAGALOG_PHILIPPINES 0x01
    1044             : # endif
    1045             : # ifndef SUBLANG_TAJIK_TAJIKISTAN
    1046             : # define SUBLANG_TAJIK_TAJIKISTAN 0x01
    1047             : # endif
    1048             : # ifndef SUBLANG_TAMAZIGHT_ARABIC
    1049             : # define SUBLANG_TAMAZIGHT_ARABIC 0x01
    1050             : # endif
    1051             : # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
    1052             : # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
    1053             : # endif
    1054             : # ifndef SUBLANG_TAMIL_INDIA
    1055             : # define SUBLANG_TAMIL_INDIA 0x01
    1056             : # endif
    1057             : # ifndef SUBLANG_TATAR_RUSSIA
    1058             : # define SUBLANG_TATAR_RUSSIA 0x01
    1059             : # endif
    1060             : # ifndef SUBLANG_TELUGU_INDIA
    1061             : # define SUBLANG_TELUGU_INDIA 0x01
    1062             : # endif
    1063             : # ifndef SUBLANG_THAI_THAILAND
    1064             : # define SUBLANG_THAI_THAILAND 0x01
    1065             : # endif
    1066             : # ifndef SUBLANG_TIBETAN_PRC
    1067             : # define SUBLANG_TIBETAN_PRC 0x01
    1068             : # endif
    1069             : # undef SUBLANG_TIBETAN_BHUTAN
    1070             : # define SUBLANG_TIBETAN_BHUTAN 0x02
    1071             : # ifndef SUBLANG_TIGRINYA_ETHIOPIA
    1072             : # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
    1073             : # endif
    1074             : # ifndef SUBLANG_TIGRINYA_ERITREA
    1075             : # define SUBLANG_TIGRINYA_ERITREA 0x02
    1076             : # endif
    1077             : # ifndef SUBLANG_TSWANA_SOUTH_AFRICA
    1078             : # define SUBLANG_TSWANA_SOUTH_AFRICA 0x01
    1079             : # endif
    1080             : # ifndef SUBLANG_TURKISH_TURKEY
    1081             : # define SUBLANG_TURKISH_TURKEY 0x01
    1082             : # endif
    1083             : # ifndef SUBLANG_TURKMEN_TURKMENISTAN
    1084             : # define SUBLANG_TURKMEN_TURKMENISTAN 0x01
    1085             : # endif
    1086             : # ifndef SUBLANG_UIGHUR_PRC
    1087             : # define SUBLANG_UIGHUR_PRC 0x01
    1088             : # endif
    1089             : # ifndef SUBLANG_UKRAINIAN_UKRAINE
    1090             : # define SUBLANG_UKRAINIAN_UKRAINE 0x01
    1091             : # endif
    1092             : # ifndef SUBLANG_UPPER_SORBIAN_GERMANY
    1093             : # define SUBLANG_UPPER_SORBIAN_GERMANY 0x01
    1094             : # endif
    1095             : # ifndef SUBLANG_URDU_PAKISTAN
    1096             : # define SUBLANG_URDU_PAKISTAN 0x01
    1097             : # endif
    1098             : # ifndef SUBLANG_URDU_INDIA
    1099             : # define SUBLANG_URDU_INDIA 0x02
    1100             : # endif
    1101             : # ifndef SUBLANG_UZBEK_LATIN
    1102             : # define SUBLANG_UZBEK_LATIN 0x01
    1103             : # endif
    1104             : # ifndef SUBLANG_UZBEK_CYRILLIC
    1105             : # define SUBLANG_UZBEK_CYRILLIC 0x02
    1106             : # endif
    1107             : # ifndef SUBLANG_VIETNAMESE_VIETNAM
    1108             : # define SUBLANG_VIETNAMESE_VIETNAM 0x01
    1109             : # endif
    1110             : # ifndef SUBLANG_WELSH_UNITED_KINGDOM
    1111             : # define SUBLANG_WELSH_UNITED_KINGDOM 0x01
    1112             : # endif
    1113             : # ifndef SUBLANG_WOLOF_SENEGAL
    1114             : # define SUBLANG_WOLOF_SENEGAL 0x01
    1115             : # endif
    1116             : # ifndef SUBLANG_XHOSA_SOUTH_AFRICA
    1117             : # define SUBLANG_XHOSA_SOUTH_AFRICA 0x01
    1118             : # endif
    1119             : # ifndef SUBLANG_YAKUT_RUSSIA
    1120             : # define SUBLANG_YAKUT_RUSSIA 0x01
    1121             : # endif
    1122             : # ifndef SUBLANG_YI_PRC
    1123             : # define SUBLANG_YI_PRC 0x01
    1124             : # endif
    1125             : # ifndef SUBLANG_YORUBA_NIGERIA
    1126             : # define SUBLANG_YORUBA_NIGERIA 0x01
    1127             : # endif
    1128             : # ifndef SUBLANG_ZULU_SOUTH_AFRICA
    1129             : # define SUBLANG_ZULU_SOUTH_AFRICA 0x01
    1130             : # endif
    1131             : /* GetLocaleInfoA operations.  */
    1132             : # ifndef LOCALE_SNAME
    1133             : # define LOCALE_SNAME 0x5c
    1134             : # endif
    1135             : # ifndef LOCALE_NAME_MAX_LENGTH
    1136             : # define LOCALE_NAME_MAX_LENGTH 85
    1137             : # endif
    1138             : #endif
    1139             : 
    1140             : 
    1141             : #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
    1142             : /* Mac OS X 10.2 or newer */
    1143             : 
    1144             : /* Canonicalize a Mac OS X locale name to a Unix locale name.
    1145             :    NAME is a sufficiently large buffer.
    1146             :    On input, it contains the Mac OS X locale name.
    1147             :    On output, it contains the Unix locale name.  */
    1148             : # if !defined IN_LIBINTL
    1149             : static
    1150             : # endif
    1151             : void
    1152             : gl_locale_name_canonicalize (char *name)
    1153             : {
    1154             :   /* This conversion is based on a posting by
    1155             :      Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
    1156             :      http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
    1157             : 
    1158             :   /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
    1159             :      ISO 3166) names.  Prior to Mac OS X 10.3, there is no API for doing this.
    1160             :      Therefore we do it ourselves, using a table based on the results of the
    1161             :      Mac OS X 10.3.8 function
    1162             :      CFLocaleCreateCanonicalLocaleIdentifierFromString().  */
    1163             :   typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
    1164             :           legacy_entry;
    1165             :   static const legacy_entry legacy_table[] = {
    1166             :     { "Afrikaans",             "af" },
    1167             :     { "Albanian",              "sq" },
    1168             :     { "Amharic",               "am" },
    1169             :     { "Arabic",                "ar" },
    1170             :     { "Armenian",              "hy" },
    1171             :     { "Assamese",              "as" },
    1172             :     { "Aymara",                "ay" },
    1173             :     { "Azerbaijani",           "az" },
    1174             :     { "Basque",                "eu" },
    1175             :     { "Belarusian",            "be" },
    1176             :     { "Belorussian",           "be" },
    1177             :     { "Bengali",               "bn" },
    1178             :     { "Brazilian Portugese",   "pt_BR" },
    1179             :     { "Brazilian Portuguese",  "pt_BR" },
    1180             :     { "Breton",                "br" },
    1181             :     { "Bulgarian",             "bg" },
    1182             :     { "Burmese",               "my" },
    1183             :     { "Byelorussian",          "be" },
    1184             :     { "Catalan",               "ca" },
    1185             :     { "Chewa",                 "ny" },
    1186             :     { "Chichewa",              "ny" },
    1187             :     { "Chinese",               "zh" },
    1188             :     { "Chinese, Simplified",   "zh_CN" },
    1189             :     { "Chinese, Traditional",  "zh_TW" },
    1190             :     { "Chinese, Tradtional",   "zh_TW" },
    1191             :     { "Croatian",              "hr" },
    1192             :     { "Czech",                 "cs" },
    1193             :     { "Danish",                "da" },
    1194             :     { "Dutch",                 "nl" },
    1195             :     { "Dzongkha",              "dz" },
    1196             :     { "English",               "en" },
    1197             :     { "Esperanto",             "eo" },
    1198             :     { "Estonian",              "et" },
    1199             :     { "Faroese",               "fo" },
    1200             :     { "Farsi",                 "fa" },
    1201             :     { "Finnish",               "fi" },
    1202             :     { "Flemish",               "nl_BE" },
    1203             :     { "French",                "fr" },
    1204             :     { "Galician",              "gl" },
    1205             :     { "Gallegan",              "gl" },
    1206             :     { "Georgian",              "ka" },
    1207             :     { "German",                "de" },
    1208             :     { "Greek",                 "el" },
    1209             :     { "Greenlandic",           "kl" },
    1210             :     { "Guarani",               "gn" },
    1211             :     { "Gujarati",              "gu" },
    1212             :     { "Hawaiian",              "haw" }, /* Yes, "haw", not "cpe".  */
    1213             :     { "Hebrew",                "he" },
    1214             :     { "Hindi",                 "hi" },
    1215             :     { "Hungarian",             "hu" },
    1216             :     { "Icelandic",             "is" },
    1217             :     { "Indonesian",            "id" },
    1218             :     { "Inuktitut",             "iu" },
    1219             :     { "Irish",                 "ga" },
    1220             :     { "Italian",               "it" },
    1221             :     { "Japanese",              "ja" },
    1222             :     { "Javanese",              "jv" },
    1223             :     { "Kalaallisut",           "kl" },
    1224             :     { "Kannada",               "kn" },
    1225             :     { "Kashmiri",              "ks" },
    1226             :     { "Kazakh",                "kk" },
    1227             :     { "Khmer",                 "km" },
    1228             :     { "Kinyarwanda",           "rw" },
    1229             :     { "Kirghiz",               "ky" },
    1230             :     { "Korean",                "ko" },
    1231             :     { "Kurdish",               "ku" },
    1232             :     { "Latin",                 "la" },
    1233             :     { "Latvian",               "lv" },
    1234             :     { "Lithuanian",            "lt" },
    1235             :     { "Macedonian",            "mk" },
    1236             :     { "Malagasy",              "mg" },
    1237             :     { "Malay",                 "ms" },
    1238             :     { "Malayalam",             "ml" },
    1239             :     { "Maltese",               "mt" },
    1240             :     { "Manx",                  "gv" },
    1241             :     { "Marathi",               "mr" },
    1242             :     { "Moldavian",             "mo" },
    1243             :     { "Mongolian",             "mn" },
    1244             :     { "Nepali",                "ne" },
    1245             :     { "Norwegian",             "nb" }, /* Yes, "nb", not the obsolete "no".  */
    1246             :     { "Nyanja",                "ny" },
    1247             :     { "Nynorsk",               "nn" },
    1248             :     { "Oriya",                 "or" },
    1249             :     { "Oromo",                 "om" },
    1250             :     { "Panjabi",               "pa" },
    1251             :     { "Pashto",                "ps" },
    1252             :     { "Persian",               "fa" },
    1253             :     { "Polish",                "pl" },
    1254             :     { "Portuguese",            "pt" },
    1255             :     { "Portuguese, Brazilian", "pt_BR" },
    1256             :     { "Punjabi",               "pa" },
    1257             :     { "Pushto",                "ps" },
    1258             :     { "Quechua",               "qu" },
    1259             :     { "Romanian",              "ro" },
    1260             :     { "Ruanda",                "rw" },
    1261             :     { "Rundi",                 "rn" },
    1262             :     { "Russian",               "ru" },
    1263             :     { "Sami",                  "se_NO" }, /* Not just "se".  */
    1264             :     { "Sanskrit",              "sa" },
    1265             :     { "Scottish",              "gd" },
    1266             :     { "Serbian",               "sr" },
    1267             :     { "Simplified Chinese",    "zh_CN" },
    1268             :     { "Sindhi",                "sd" },
    1269             :     { "Sinhalese",             "si" },
    1270             :     { "Slovak",                "sk" },
    1271             :     { "Slovenian",             "sl" },
    1272             :     { "Somali",                "so" },
    1273             :     { "Spanish",               "es" },
    1274             :     { "Sundanese",             "su" },
    1275             :     { "Swahili",               "sw" },
    1276             :     { "Swedish",               "sv" },
    1277             :     { "Tagalog",               "tl" },
    1278             :     { "Tajik",                 "tg" },
    1279             :     { "Tajiki",                "tg" },
    1280             :     { "Tamil",                 "ta" },
    1281             :     { "Tatar",                 "tt" },
    1282             :     { "Telugu",                "te" },
    1283             :     { "Thai",                  "th" },
    1284             :     { "Tibetan",               "bo" },
    1285             :     { "Tigrinya",              "ti" },
    1286             :     { "Tongan",                "to" },
    1287             :     { "Traditional Chinese",   "zh_TW" },
    1288             :     { "Turkish",               "tr" },
    1289             :     { "Turkmen",               "tk" },
    1290             :     { "Uighur",                "ug" },
    1291             :     { "Ukrainian",             "uk" },
    1292             :     { "Urdu",                  "ur" },
    1293             :     { "Uzbek",                 "uz" },
    1294             :     { "Vietnamese",            "vi" },
    1295             :     { "Welsh",                 "cy" },
    1296             :     { "Yiddish",               "yi" }
    1297             :   };
    1298             : 
    1299             :   /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
    1300             :      to Unix (ISO 639 and ISO 3166) names.  */
    1301             :   typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
    1302             :           langtag_entry;
    1303             :   static const langtag_entry langtag_table[] = {
    1304             :     /* Mac OS X has "az-Arab", "az-Cyrl", "az-Latn".
    1305             :        The default script for az on Unix is Latin.  */
    1306             :     { "az-Latn", "az" },
    1307             :     /* Mac OS X has "ga-dots".  Does not yet exist on Unix.  */
    1308             :     { "ga-dots", "ga" },
    1309             :     /* Mac OS X has "kk-Cyrl".  Does not yet exist on Unix.  */
    1310             :     /* Mac OS X has "mn-Cyrl", "mn-Mong".
    1311             :        The default script for mn on Unix is Cyrillic.  */
    1312             :     { "mn-Cyrl", "mn" },
    1313             :     /* Mac OS X has "ms-Arab", "ms-Latn".
    1314             :        The default script for ms on Unix is Latin.  */
    1315             :     { "ms-Latn", "ms" },
    1316             :     /* Mac OS X has "tg-Cyrl".
    1317             :        The default script for tg on Unix is Cyrillic.  */
    1318             :     { "tg-Cyrl", "tg" },
    1319             :     /* Mac OS X has "tk-Cyrl".  Does not yet exist on Unix.  */
    1320             :     /* Mac OS X has "tt-Cyrl".
    1321             :        The default script for tt on Unix is Cyrillic.  */
    1322             :     { "tt-Cyrl", "tt" },
    1323             :     /* Mac OS X has "zh-Hans", "zh-Hant".
    1324             :        Country codes are used to distinguish these on Unix.  */
    1325             :     { "zh-Hans", "zh_CN" },
    1326             :     { "zh-Hant", "zh_TW" }
    1327             :   };
    1328             : 
    1329             :   /* Convert script names (ISO 15924) to Unix conventions.
    1330             :      See http://www.unicode.org/iso15924/iso15924-codes.html  */
    1331             :   typedef struct { const char script[4+1]; const char unixy[9+1]; }
    1332             :           script_entry;
    1333             :   static const script_entry script_table[] = {
    1334             :     { "Arab", "arabic" },
    1335             :     { "Cyrl", "cyrillic" },
    1336             :     { "Mong", "mongolian" }
    1337             :   };
    1338             : 
    1339             :   /* Step 1: Convert using legacy_table.  */
    1340             :   if (name[0] >= 'A' && name[0] <= 'Z')
    1341             :     {
    1342             :       unsigned int i1, i2;
    1343             :       i1 = 0;
    1344             :       i2 = sizeof (legacy_table) / sizeof (legacy_entry);
    1345             :       while (i2 - i1 > 1)
    1346             :         {
    1347             :           /* At this point we know that if name occurs in legacy_table,
    1348             :              its index must be >= i1 and < i2.  */
    1349             :           unsigned int i = (i1 + i2) >> 1;
    1350             :           const legacy_entry *p = &legacy_table[i];
    1351             :           if (strcmp (name, p->legacy) < 0)
    1352             :             i2 = i;
    1353             :           else
    1354             :             i1 = i;
    1355             :         }
    1356             :       if (strcmp (name, legacy_table[i1].legacy) == 0)
    1357             :         {
    1358             :           strcpy (name, legacy_table[i1].unixy);
    1359             :           return;
    1360             :         }
    1361             :     }
    1362             : 
    1363             :   /* Step 2: Convert using langtag_table and script_table.  */
    1364             :   if (strlen (name) == 7 && name[2] == '-')
    1365             :     {
    1366             :       unsigned int i1, i2;
    1367             :       i1 = 0;
    1368             :       i2 = sizeof (langtag_table) / sizeof (langtag_entry);
    1369             :       while (i2 - i1 > 1)
    1370             :         {
    1371             :           /* At this point we know that if name occurs in langtag_table,
    1372             :              its index must be >= i1 and < i2.  */
    1373             :           unsigned int i = (i1 + i2) >> 1;
    1374             :           const langtag_entry *p = &langtag_table[i];
    1375             :           if (strcmp (name, p->langtag) < 0)
    1376             :             i2 = i;
    1377             :           else
    1378             :             i1 = i;
    1379             :         }
    1380             :       if (strcmp (name, langtag_table[i1].langtag) == 0)
    1381             :         {
    1382             :           strcpy (name, langtag_table[i1].unixy);
    1383             :           return;
    1384             :         }
    1385             : 
    1386             :       i1 = 0;
    1387             :       i2 = sizeof (script_table) / sizeof (script_entry);
    1388             :       while (i2 - i1 > 1)
    1389             :         {
    1390             :           /* At this point we know that if (name + 3) occurs in script_table,
    1391             :              its index must be >= i1 and < i2.  */
    1392             :           unsigned int i = (i1 + i2) >> 1;
    1393             :           const script_entry *p = &script_table[i];
    1394             :           if (strcmp (name + 3, p->script) < 0)
    1395             :             i2 = i;
    1396             :           else
    1397             :             i1 = i;
    1398             :         }
    1399             :       if (strcmp (name + 3, script_table[i1].script) == 0)
    1400             :         {
    1401             :           name[2] = '@';
    1402             :           strcpy (name + 3, script_table[i1].unixy);
    1403             :           return;
    1404             :         }
    1405             :     }
    1406             : 
    1407             :   /* Step 3: Convert new-style dash to Unix underscore. */
    1408             :   {
    1409             :     char *p;
    1410             :     for (p = name; *p != '\0'; p++)
    1411             :       if (*p == '-')
    1412             :         *p = '_';
    1413             :   }
    1414             : }
    1415             : 
    1416             : #endif
    1417             : 
    1418             : 
    1419             : #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
    1420             : 
    1421             : /* Canonicalize a Windows native locale name to a Unix locale name.
    1422             :    NAME is a sufficiently large buffer.
    1423             :    On input, it contains the Windows locale name.
    1424             :    On output, it contains the Unix locale name.  */
    1425             : # if !defined IN_LIBINTL
    1426             : static
    1427             : # endif
    1428             : void
    1429             : gl_locale_name_canonicalize (char *name)
    1430             : {
    1431             :   /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
    1432             :      "zh-Hant".  */
    1433             :   char *p;
    1434             : 
    1435             :   for (p = name; *p != '\0'; p++)
    1436             :     if (*p == '-')
    1437             :       {
    1438             :         *p = '_';
    1439             :         p++;
    1440             :         for (; *p != '\0'; p++)
    1441             :           {
    1442             :             if (*p >= 'a' && *p <= 'z')
    1443             :               *p += 'A' - 'a';
    1444             :             if (*p == '-')
    1445             :               {
    1446             :                 *p = '\0';
    1447             :                 return;
    1448             :               }
    1449             :           }
    1450             :         return;
    1451             :       }
    1452             : }
    1453             : 
    1454             : # if !defined IN_LIBINTL
    1455             : static
    1456             : # endif
    1457             : const char *
    1458             : gl_locale_name_from_win32_LANGID (LANGID langid)
    1459             : {
    1460             :   /* Activate the new code only when the GETTEXT_MUI environment variable is
    1461             :      set, for the time being, since the new code is not well tested.  */
    1462             :   if (getenv ("GETTEXT_MUI") != NULL)
    1463             :     {
    1464             :       static char namebuf[256];
    1465             : 
    1466             :       /* Query the system's notion of locale name.
    1467             :          On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
    1468             :          But we don't need to support systems that are so old.  */
    1469             :       if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
    1470             :                           namebuf, sizeof (namebuf) - 1))
    1471             :         {
    1472             :           /* Convert it to a Unix locale name.  */
    1473             :           gl_locale_name_canonicalize (namebuf);
    1474             :           return namebuf;
    1475             :         }
    1476             :     }
    1477             :   /* Internet Explorer has an LCID to RFC3066 name mapping stored in
    1478             :      HKEY_CLASSES_ROOT\Mime\Database\Rfc1766.  But we better don't use that
    1479             :      since IE's i18n subsystem is known to be inconsistent with the native
    1480             :      Windows base (e.g. they have different character conversion facilities
    1481             :      that produce different results).  */
    1482             :   /* Use our own table.  */
    1483             :   {
    1484             :     int primary, sub;
    1485             : 
    1486             :     /* Split into language and territory part.  */
    1487             :     primary = PRIMARYLANGID (langid);
    1488             :     sub = SUBLANGID (langid);
    1489             : 
    1490             :     /* Dispatch on language.
    1491             :        See also http://www.unicode.org/unicode/onlinedat/languages.html .
    1492             :        For details about languages, see http://www.ethnologue.com/ .  */
    1493             :     switch (primary)
    1494             :       {
    1495             :       case LANG_AFRIKAANS:
    1496             :         switch (sub)
    1497             :           {
    1498             :           case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return "af_ZA";
    1499             :           }
    1500             :         return "af";
    1501             :       case LANG_ALBANIAN:
    1502             :         switch (sub)
    1503             :           {
    1504             :           case SUBLANG_ALBANIAN_ALBANIA: return "sq_AL";
    1505             :           }
    1506             :         return "sq";
    1507             :       case LANG_ALSATIAN:
    1508             :         switch (sub)
    1509             :           {
    1510             :           case SUBLANG_ALSATIAN_FRANCE: return "gsw_FR";
    1511             :           }
    1512             :         return "gsw";
    1513             :       case LANG_AMHARIC:
    1514             :         switch (sub)
    1515             :           {
    1516             :           case SUBLANG_AMHARIC_ETHIOPIA: return "am_ET";
    1517             :           }
    1518             :         return "am";
    1519             :       case LANG_ARABIC:
    1520             :         switch (sub)
    1521             :           {
    1522             :           case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
    1523             :           case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
    1524             :           case SUBLANG_ARABIC_EGYPT: return "ar_EG";
    1525             :           case SUBLANG_ARABIC_LIBYA: return "ar_LY";
    1526             :           case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
    1527             :           case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
    1528             :           case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
    1529             :           case SUBLANG_ARABIC_OMAN: return "ar_OM";
    1530             :           case SUBLANG_ARABIC_YEMEN: return "ar_YE";
    1531             :           case SUBLANG_ARABIC_SYRIA: return "ar_SY";
    1532             :           case SUBLANG_ARABIC_JORDAN: return "ar_JO";
    1533             :           case SUBLANG_ARABIC_LEBANON: return "ar_LB";
    1534             :           case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
    1535             :           case SUBLANG_ARABIC_UAE: return "ar_AE";
    1536             :           case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
    1537             :           case SUBLANG_ARABIC_QATAR: return "ar_QA";
    1538             :           }
    1539             :         return "ar";
    1540             :       case LANG_ARMENIAN:
    1541             :         switch (sub)
    1542             :           {
    1543             :           case SUBLANG_ARMENIAN_ARMENIA: return "hy_AM";
    1544             :           }
    1545             :         return "hy";
    1546             :       case LANG_ASSAMESE:
    1547             :         switch (sub)
    1548             :           {
    1549             :           case SUBLANG_ASSAMESE_INDIA: return "as_IN";
    1550             :           }
    1551             :         return "as";
    1552             :       case LANG_AZERI:
    1553             :         switch (sub)
    1554             :           {
    1555             :           /* FIXME: Adjust this when Azerbaijani locales appear on Unix.  */
    1556             :           case 0x1e: return "az@latin";
    1557             :           case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
    1558             :           case 0x1d: return "az@cyrillic";
    1559             :           case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
    1560             :           }
    1561             :         return "az";
    1562             :       case LANG_BASHKIR:
    1563             :         switch (sub)
    1564             :           {
    1565             :           case SUBLANG_BASHKIR_RUSSIA: return "ba_RU";
    1566             :           }
    1567             :         return "ba";
    1568             :       case LANG_BASQUE:
    1569             :         switch (sub)
    1570             :           {
    1571             :           case SUBLANG_BASQUE_BASQUE: return "eu_ES";
    1572             :           }
    1573             :         return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR".  */
    1574             :       case LANG_BELARUSIAN:
    1575             :         switch (sub)
    1576             :           {
    1577             :           case SUBLANG_BELARUSIAN_BELARUS: return "be_BY";
    1578             :           }
    1579             :         return "be";
    1580             :       case LANG_BENGALI:
    1581             :         switch (sub)
    1582             :           {
    1583             :           case SUBLANG_BENGALI_INDIA: return "bn_IN";
    1584             :           case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
    1585             :           }
    1586             :         return "bn";
    1587             :       case LANG_BRETON:
    1588             :         switch (sub)
    1589             :           {
    1590             :           case SUBLANG_BRETON_FRANCE: return "br_FR";
    1591             :           }
    1592             :         return "br";
    1593             :       case LANG_BULGARIAN:
    1594             :         switch (sub)
    1595             :           {
    1596             :           case SUBLANG_BULGARIAN_BULGARIA: return "bg_BG";
    1597             :           }
    1598             :         return "bg";
    1599             :       case LANG_BURMESE:
    1600             :         switch (sub)
    1601             :           {
    1602             :           case SUBLANG_DEFAULT: return "my_MM";
    1603             :           }
    1604             :         return "my";
    1605             :       case LANG_CAMBODIAN:
    1606             :         switch (sub)
    1607             :           {
    1608             :           case SUBLANG_CAMBODIAN_CAMBODIA: return "km_KH";
    1609             :           }
    1610             :         return "km";
    1611             :       case LANG_CATALAN:
    1612             :         switch (sub)
    1613             :           {
    1614             :           case SUBLANG_CATALAN_SPAIN: return "ca_ES";
    1615             :           }
    1616             :         return "ca";
    1617             :       case LANG_CHEROKEE:
    1618             :         switch (sub)
    1619             :           {
    1620             :           case SUBLANG_DEFAULT: return "chr_US";
    1621             :           }
    1622             :         return "chr";
    1623             :       case LANG_CHINESE:
    1624             :         switch (sub)
    1625             :           {
    1626             :           case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return "zh_TW";
    1627             :           case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return "zh_CN";
    1628             :           case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; /* traditional */
    1629             :           case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; /* simplified */
    1630             :           case SUBLANG_CHINESE_MACAU: return "zh_MO"; /* traditional */
    1631             :           }
    1632             :         return "zh";
    1633             :       case LANG_CORSICAN:
    1634             :         switch (sub)
    1635             :           {
    1636             :           case SUBLANG_CORSICAN_FRANCE: return "co_FR";
    1637             :           }
    1638             :         return "co";
    1639             :       case LANG_CROATIAN:      /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN
    1640             :                                 * What used to be called Serbo-Croatian
    1641             :                                 * should really now be two separate
    1642             :                                 * languages because of political reasons.
    1643             :                                 * (Says tml, who knows nothing about Serbian
    1644             :                                 * or Croatian.)
    1645             :                                 * (I can feel those flames coming already.)
    1646             :                                 */
    1647             :         switch (sub)
    1648             :           {
    1649             :           /* Croatian */
    1650             :           case 0x00: return "hr";
    1651             :           case SUBLANG_CROATIAN_CROATIA: return "hr_HR";
    1652             :           case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA";
    1653             :           /* Serbian */
    1654             :           case 0x1f: return "sr";
    1655             :           case 0x1c: return "sr"; /* latin */
    1656             :           case SUBLANG_SERBIAN_LATIN: return "sr_CS"; /* latin */
    1657             :           case 0x09: return "sr_RS"; /* latin */
    1658             :           case 0x0b: return "sr_ME"; /* latin */
    1659             :           case 0x06: return "sr_BA"; /* latin */
    1660             :           case 0x1b: return "sr@cyrillic";
    1661             :           case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
    1662             :           case 0x0a: return "sr_RS@cyrillic";
    1663             :           case 0x0c: return "sr_ME@cyrillic";
    1664             :           case 0x07: return "sr_BA@cyrillic";
    1665             :           /* Bosnian */
    1666             :           case 0x1e: return "bs";
    1667             :           case 0x1a: return "bs"; /* latin */
    1668             :           case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; /* latin */
    1669             :           case 0x19: return "bs@cyrillic";
    1670             :           case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic";
    1671             :           }
    1672             :         return "hr";
    1673             :       case LANG_CZECH:
    1674             :         switch (sub)
    1675             :           {
    1676             :           case SUBLANG_CZECH_CZECH_REPUBLIC: return "cs_CZ";
    1677             :           }
    1678             :         return "cs";
    1679             :       case LANG_DANISH:
    1680             :         switch (sub)
    1681             :           {
    1682             :           case SUBLANG_DANISH_DENMARK: return "da_DK";
    1683             :           }
    1684             :         return "da";
    1685             :       case LANG_DARI:
    1686             :         /* FIXME: Adjust this when such locales appear on Unix.  */
    1687             :         switch (sub)
    1688             :           {
    1689             :           case SUBLANG_DARI_AFGHANISTAN: return "prs_AF";
    1690             :           }
    1691             :         return "prs";
    1692             :       case LANG_DIVEHI:
    1693             :         switch (sub)
    1694             :           {
    1695             :           case SUBLANG_DIVEHI_MALDIVES: return "dv_MV";
    1696             :           }
    1697             :         return "dv";
    1698             :       case LANG_DUTCH:
    1699             :         switch (sub)
    1700             :           {
    1701             :           case SUBLANG_DUTCH: return "nl_NL";
    1702             :           case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
    1703             :           case SUBLANG_DUTCH_SURINAM: return "nl_SR";
    1704             :           }
    1705             :         return "nl";
    1706             :       case LANG_EDO:
    1707             :         switch (sub)
    1708             :           {
    1709             :           case SUBLANG_DEFAULT: return "bin_NG";
    1710             :           }
    1711             :         return "bin";
    1712             :       case LANG_ENGLISH:
    1713             :         switch (sub)
    1714             :           {
    1715             :           /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
    1716             :            * English was the language spoken in England.
    1717             :            * Oh well.
    1718             :            */
    1719             :           case SUBLANG_ENGLISH_US: return "en_US";
    1720             :           case SUBLANG_ENGLISH_UK: return "en_GB";
    1721             :           case SUBLANG_ENGLISH_AUS: return "en_AU";
    1722             :           case SUBLANG_ENGLISH_CAN: return "en_CA";
    1723             :           case SUBLANG_ENGLISH_NZ: return "en_NZ";
    1724             :           case SUBLANG_ENGLISH_EIRE: return "en_IE";
    1725             :           case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
    1726             :           case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
    1727             :           case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
    1728             :           case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
    1729             :           case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
    1730             :           case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
    1731             :           case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
    1732             :           case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
    1733             :           case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
    1734             :           case SUBLANG_ENGLISH_INDIA: return "en_IN";
    1735             :           case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
    1736             :           case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
    1737             :           }
    1738             :         return "en";
    1739             :       case LANG_ESTONIAN:
    1740             :         switch (sub)
    1741             :           {
    1742             :           case SUBLANG_ESTONIAN_ESTONIA: return "et_EE";
    1743             :           }
    1744             :         return "et";
    1745             :       case LANG_FAEROESE:
    1746             :         switch (sub)
    1747             :           {
    1748             :           case SUBLANG_FAEROESE_FAROE_ISLANDS: return "fo_FO";
    1749             :           }
    1750             :         return "fo";
    1751             :       case LANG_FARSI:
    1752             :         switch (sub)
    1753             :           {
    1754             :           case SUBLANG_FARSI_IRAN: return "fa_IR";
    1755             :           }
    1756             :         return "fa";
    1757             :       case LANG_FINNISH:
    1758             :         switch (sub)
    1759             :           {
    1760             :           case SUBLANG_FINNISH_FINLAND: return "fi_FI";
    1761             :           }
    1762             :         return "fi";
    1763             :       case LANG_FRENCH:
    1764             :         switch (sub)
    1765             :           {
    1766             :           case SUBLANG_FRENCH: return "fr_FR";
    1767             :           case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
    1768             :           case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
    1769             :           case SUBLANG_FRENCH_SWISS: return "fr_CH";
    1770             :           case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
    1771             :           case SUBLANG_FRENCH_MONACO: return "fr_MC";
    1772             :           case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
    1773             :           case SUBLANG_FRENCH_REUNION: return "fr_RE";
    1774             :           case SUBLANG_FRENCH_CONGO: return "fr_CG";
    1775             :           case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
    1776             :           case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
    1777             :           case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
    1778             :           case SUBLANG_FRENCH_MALI: return "fr_ML";
    1779             :           case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
    1780             :           case SUBLANG_FRENCH_HAITI: return "fr_HT";
    1781             :           }
    1782             :         return "fr";
    1783             :       case LANG_FRISIAN:
    1784             :         switch (sub)
    1785             :           {
    1786             :           case SUBLANG_FRISIAN_NETHERLANDS: return "fy_NL";
    1787             :           }
    1788             :         return "fy";
    1789             :       case LANG_FULFULDE:
    1790             :         /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin.  */
    1791             :         switch (sub)
    1792             :           {
    1793             :           case SUBLANG_DEFAULT: return "ff_NG";
    1794             :           }
    1795             :         return "ff";
    1796             :       case LANG_GAELIC:
    1797             :         switch (sub)
    1798             :           {
    1799             :           case 0x01: /* SCOTTISH */
    1800             :             /* old, superseded by LANG_SCOTTISH_GAELIC */
    1801             :             return "gd_GB";
    1802             :           case SUBLANG_IRISH_IRELAND: return "ga_IE";
    1803             :           }
    1804             :         return "ga";
    1805             :       case LANG_GALICIAN:
    1806             :         switch (sub)
    1807             :           {
    1808             :           case SUBLANG_GALICIAN_SPAIN: return "gl_ES";
    1809             :           }
    1810             :         return "gl";
    1811             :       case LANG_GEORGIAN:
    1812             :         switch (sub)
    1813             :           {
    1814             :           case SUBLANG_GEORGIAN_GEORGIA: return "ka_GE";
    1815             :           }
    1816             :         return "ka";
    1817             :       case LANG_GERMAN:
    1818             :         switch (sub)
    1819             :           {
    1820             :           case SUBLANG_GERMAN: return "de_DE";
    1821             :           case SUBLANG_GERMAN_SWISS: return "de_CH";
    1822             :           case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
    1823             :           case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
    1824             :           case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
    1825             :           }
    1826             :         return "de";
    1827             :       case LANG_GREEK:
    1828             :         switch (sub)
    1829             :           {
    1830             :           case SUBLANG_GREEK_GREECE: return "el_GR";
    1831             :           }
    1832             :         return "el";
    1833             :       case LANG_GREENLANDIC:
    1834             :         switch (sub)
    1835             :           {
    1836             :           case SUBLANG_GREENLANDIC_GREENLAND: return "kl_GL";
    1837             :           }
    1838             :         return "kl";
    1839             :       case LANG_GUARANI:
    1840             :         switch (sub)
    1841             :           {
    1842             :           case SUBLANG_DEFAULT: return "gn_PY";
    1843             :           }
    1844             :         return "gn";
    1845             :       case LANG_GUJARATI:
    1846             :         switch (sub)
    1847             :           {
    1848             :           case SUBLANG_GUJARATI_INDIA: return "gu_IN";
    1849             :           }
    1850             :         return "gu";
    1851             :       case LANG_HAUSA:
    1852             :         switch (sub)
    1853             :           {
    1854             :           case 0x1f: return "ha";
    1855             :           case SUBLANG_HAUSA_NIGERIA_LATIN: return "ha_NG";
    1856             :           }
    1857             :         return "ha";
    1858             :       case LANG_HAWAIIAN:
    1859             :         /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
    1860             :            or Hawaii Creole English ("cpe_US", 600000 speakers)?  */
    1861             :         switch (sub)
    1862             :           {
    1863             :           case SUBLANG_DEFAULT: return "cpe_US";
    1864             :           }
    1865             :         return "cpe";
    1866             :       case LANG_HEBREW:
    1867             :         switch (sub)
    1868             :           {
    1869             :           case SUBLANG_HEBREW_ISRAEL: return "he_IL";
    1870             :           }
    1871             :         return "he";
    1872             :       case LANG_HINDI:
    1873             :         switch (sub)
    1874             :           {
    1875             :           case SUBLANG_HINDI_INDIA: return "hi_IN";
    1876             :           }
    1877             :         return "hi";
    1878             :       case LANG_HUNGARIAN:
    1879             :         switch (sub)
    1880             :           {
    1881             :           case SUBLANG_HUNGARIAN_HUNGARY: return "hu_HU";
    1882             :           }
    1883             :         return "hu";
    1884             :       case LANG_IBIBIO:
    1885             :         switch (sub)
    1886             :           {
    1887             :           case SUBLANG_DEFAULT: return "nic_NG";
    1888             :           }
    1889             :         return "nic";
    1890             :       case LANG_ICELANDIC:
    1891             :         switch (sub)
    1892             :           {
    1893             :           case SUBLANG_ICELANDIC_ICELAND: return "is_IS";
    1894             :           }
    1895             :         return "is";
    1896             :       case LANG_IGBO:
    1897             :         switch (sub)
    1898             :           {
    1899             :           case SUBLANG_IGBO_NIGERIA: return "ig_NG";
    1900             :           }
    1901             :         return "ig";
    1902             :       case LANG_INDONESIAN:
    1903             :         switch (sub)
    1904             :           {
    1905             :           case SUBLANG_INDONESIAN_INDONESIA: return "id_ID";
    1906             :           }
    1907             :         return "id";
    1908             :       case LANG_INUKTITUT:
    1909             :         switch (sub)
    1910             :           {
    1911             :           case 0x1e: return "iu"; /* syllabic */
    1912             :           case SUBLANG_INUKTITUT_CANADA: return "iu_CA"; /* syllabic */
    1913             :           case 0x1f: return "iu@latin";
    1914             :           case SUBLANG_INUKTITUT_CANADA_LATIN: return "iu_CA@latin";
    1915             :           }
    1916             :         return "iu";
    1917             :       case LANG_ITALIAN:
    1918             :         switch (sub)
    1919             :           {
    1920             :           case SUBLANG_ITALIAN: return "it_IT";
    1921             :           case SUBLANG_ITALIAN_SWISS: return "it_CH";
    1922             :           }
    1923             :         return "it";
    1924             :       case LANG_JAPANESE:
    1925             :         switch (sub)
    1926             :           {
    1927             :           case SUBLANG_JAPANESE_JAPAN: return "ja_JP";
    1928             :           }
    1929             :         return "ja";
    1930             :       case LANG_KANNADA:
    1931             :         switch (sub)
    1932             :           {
    1933             :           case SUBLANG_KANNADA_INDIA: return "kn_IN";
    1934             :           }
    1935             :         return "kn";
    1936             :       case LANG_KANURI:
    1937             :         switch (sub)
    1938             :           {
    1939             :           case SUBLANG_DEFAULT: return "kr_NG";
    1940             :           }
    1941             :         return "kr";
    1942             :       case LANG_KASHMIRI:
    1943             :         switch (sub)
    1944             :           {
    1945             :           case SUBLANG_DEFAULT: return "ks_PK";
    1946             :           case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
    1947             :           }
    1948             :         return "ks";
    1949             :       case LANG_KAZAK:
    1950             :         switch (sub)
    1951             :           {
    1952             :           case SUBLANG_KAZAK_KAZAKHSTAN: return "kk_KZ";
    1953             :           }
    1954             :         return "kk";
    1955             :       case LANG_KICHE:
    1956             :         /* FIXME: Adjust this when such locales appear on Unix.  */
    1957             :         switch (sub)
    1958             :           {
    1959             :           case SUBLANG_KICHE_GUATEMALA: return "qut_GT";
    1960             :           }
    1961             :         return "qut";
    1962             :       case LANG_KINYARWANDA:
    1963             :         switch (sub)
    1964             :           {
    1965             :           case SUBLANG_KINYARWANDA_RWANDA: return "rw_RW";
    1966             :           }
    1967             :         return "rw";
    1968             :       case LANG_KONKANI:
    1969             :         /* FIXME: Adjust this when such locales appear on Unix.  */
    1970             :         switch (sub)
    1971             :           {
    1972             :           case SUBLANG_KONKANI_INDIA: return "kok_IN";
    1973             :           }
    1974             :         return "kok";
    1975             :       case LANG_KOREAN:
    1976             :         switch (sub)
    1977             :           {
    1978             :           case SUBLANG_DEFAULT: return "ko_KR";
    1979             :           }
    1980             :         return "ko";
    1981             :       case LANG_KYRGYZ:
    1982             :         switch (sub)
    1983             :           {
    1984             :           case SUBLANG_KYRGYZ_KYRGYZSTAN: return "ky_KG";
    1985             :           }
    1986             :         return "ky";
    1987             :       case LANG_LAO:
    1988             :         switch (sub)
    1989             :           {
    1990             :           case SUBLANG_LAO_LAOS: return "lo_LA";
    1991             :           }
    1992             :         return "lo";
    1993             :       case LANG_LATIN:
    1994             :         switch (sub)
    1995             :           {
    1996             :           case SUBLANG_DEFAULT: return "la_VA";
    1997             :           }
    1998             :         return "la";
    1999             :       case LANG_LATVIAN:
    2000             :         switch (sub)
    2001             :           {
    2002             :           case SUBLANG_LATVIAN_LATVIA: return "lv_LV";
    2003             :           }
    2004             :         return "lv";
    2005             :       case LANG_LITHUANIAN:
    2006             :         switch (sub)
    2007             :           {
    2008             :           case SUBLANG_LITHUANIAN_LITHUANIA: return "lt_LT";
    2009             :           }
    2010             :         return "lt";
    2011             :       case LANG_LUXEMBOURGISH:
    2012             :         switch (sub)
    2013             :           {
    2014             :           case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return "lb_LU";
    2015             :           }
    2016             :         return "lb";
    2017             :       case LANG_MACEDONIAN:
    2018             :         switch (sub)
    2019             :           {
    2020             :           case SUBLANG_MACEDONIAN_MACEDONIA: return "mk_MK";
    2021             :           }
    2022             :         return "mk";
    2023             :       case LANG_MALAY:
    2024             :         switch (sub)
    2025             :           {
    2026             :           case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
    2027             :           case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
    2028             :           }
    2029             :         return "ms";
    2030             :       case LANG_MALAYALAM:
    2031             :         switch (sub)
    2032             :           {
    2033             :           case SUBLANG_MALAYALAM_INDIA: return "ml_IN";
    2034             :           }
    2035             :         return "ml";
    2036             :       case LANG_MALTESE:
    2037             :         switch (sub)
    2038             :           {
    2039             :           case SUBLANG_MALTESE_MALTA: return "mt_MT";
    2040             :           }
    2041             :         return "mt";
    2042             :       case LANG_MANIPURI:
    2043             :         /* FIXME: Adjust this when such locales appear on Unix.  */
    2044             :         switch (sub)
    2045             :           {
    2046             :           case SUBLANG_DEFAULT: return "mni_IN";
    2047             :           }
    2048             :         return "mni";
    2049             :       case LANG_MAORI:
    2050             :         switch (sub)
    2051             :           {
    2052             :           case SUBLANG_MAORI_NEW_ZEALAND: return "mi_NZ";
    2053             :           }
    2054             :         return "mi";
    2055             :       case LANG_MAPUDUNGUN:
    2056             :         switch (sub)
    2057             :           {
    2058             :           case SUBLANG_MAPUDUNGUN_CHILE: return "arn_CL";
    2059             :           }
    2060             :         return "arn";
    2061             :       case LANG_MARATHI:
    2062             :         switch (sub)
    2063             :           {
    2064             :           case SUBLANG_MARATHI_INDIA: return "mr_IN";
    2065             :           }
    2066             :         return "mr";
    2067             :       case LANG_MOHAWK:
    2068             :         switch (sub)
    2069             :           {
    2070             :           case SUBLANG_MOHAWK_CANADA: return "moh_CA";
    2071             :           }
    2072             :         return "moh";
    2073             :       case LANG_MONGOLIAN:
    2074             :         switch (sub)
    2075             :           {
    2076             :           case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return "mn_MN";
    2077             :           case SUBLANG_MONGOLIAN_PRC: case 0x1f: return "mn_CN";
    2078             :           }
    2079             :         return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN".  */
    2080             :       case LANG_NEPALI:
    2081             :         switch (sub)
    2082             :           {
    2083             :           case SUBLANG_NEPALI_NEPAL: return "ne_NP";
    2084             :           case SUBLANG_NEPALI_INDIA: return "ne_IN";
    2085             :           }
    2086             :         return "ne";
    2087             :       case LANG_NORWEGIAN:
    2088             :         switch (sub)
    2089             :           {
    2090             :           case 0x1f: return "nb";
    2091             :           case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
    2092             :           case 0x1e: return "nn";
    2093             :           case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
    2094             :           }
    2095             :         return "no";
    2096             :       case LANG_OCCITAN:
    2097             :         switch (sub)
    2098             :           {
    2099             :           case SUBLANG_OCCITAN_FRANCE: return "oc_FR";
    2100             :           }
    2101             :         return "oc";
    2102             :       case LANG_ORIYA:
    2103             :         switch (sub)
    2104             :           {
    2105             :           case SUBLANG_ORIYA_INDIA: return "or_IN";
    2106             :           }
    2107             :         return "or";
    2108             :       case LANG_OROMO:
    2109             :         switch (sub)
    2110             :           {
    2111             :           case SUBLANG_DEFAULT: return "om_ET";
    2112             :           }
    2113             :         return "om";
    2114             :       case LANG_PAPIAMENTU:
    2115             :         switch (sub)
    2116             :           {
    2117             :           case SUBLANG_DEFAULT: return "pap_AN";
    2118             :           }
    2119             :         return "pap";
    2120             :       case LANG_PASHTO:
    2121             :         switch (sub)
    2122             :           {
    2123             :           case SUBLANG_PASHTO_AFGHANISTAN: return "ps_AF";
    2124             :           }
    2125             :         return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF".  */
    2126             :       case LANG_POLISH:
    2127             :         switch (sub)
    2128             :           {
    2129             :           case SUBLANG_POLISH_POLAND: return "pl_PL";
    2130             :           }
    2131             :         return "pl";
    2132             :       case LANG_PORTUGUESE:
    2133             :         switch (sub)
    2134             :           {
    2135             :           /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
    2136             :              Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
    2137             :           case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
    2138             :           case SUBLANG_PORTUGUESE: return "pt_PT";
    2139             :           }
    2140             :         return "pt";
    2141             :       case LANG_PUNJABI:
    2142             :         switch (sub)
    2143             :           {
    2144             :           case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
    2145             :           case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
    2146             :           }
    2147             :         return "pa";
    2148             :       case LANG_QUECHUA:
    2149             :         /* Note: Microsoft uses the non-ISO language code "quz".  */
    2150             :         switch (sub)
    2151             :           {
    2152             :           case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO";
    2153             :           case SUBLANG_QUECHUA_ECUADOR: return "qu_EC";
    2154             :           case SUBLANG_QUECHUA_PERU: return "qu_PE";
    2155             :           }
    2156             :         return "qu";
    2157             :       case LANG_ROMANIAN:
    2158             :         switch (sub)
    2159             :           {
    2160             :           case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
    2161             :           case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
    2162             :           }
    2163             :         return "ro";
    2164             :       case LANG_ROMANSH:
    2165             :         switch (sub)
    2166             :           {
    2167             :           case SUBLANG_ROMANSH_SWITZERLAND: return "rm_CH";
    2168             :           }
    2169             :         return "rm";
    2170             :       case LANG_RUSSIAN:
    2171             :         switch (sub)
    2172             :           {
    2173             :           case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU";
    2174             :           case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD";
    2175             :           }
    2176             :         return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD".  */
    2177             :       case LANG_SAMI:
    2178             :         switch (sub)
    2179             :           {
    2180             :           /* Northern Sami */
    2181             :           case 0x00: return "se";
    2182             :           case SUBLANG_SAMI_NORTHERN_NORWAY: return "se_NO";
    2183             :           case SUBLANG_SAMI_NORTHERN_SWEDEN: return "se_SE";
    2184             :           case SUBLANG_SAMI_NORTHERN_FINLAND: return "se_FI";
    2185             :           /* Lule Sami */
    2186             :           case 0x1f: return "smj";
    2187             :           case SUBLANG_SAMI_LULE_NORWAY: return "smj_NO";
    2188             :           case SUBLANG_SAMI_LULE_SWEDEN: return "smj_SE";
    2189             :           /* Southern Sami */
    2190             :           case 0x1e: return "sma";
    2191             :           case SUBLANG_SAMI_SOUTHERN_NORWAY: return "sma_NO";
    2192             :           case SUBLANG_SAMI_SOUTHERN_SWEDEN: return "sma_SE";
    2193             :           /* Skolt Sami */
    2194             :           case 0x1d: return "sms";
    2195             :           case SUBLANG_SAMI_SKOLT_FINLAND: return "sms_FI";
    2196             :           /* Inari Sami */
    2197             :           case 0x1c: return "smn";
    2198             :           case SUBLANG_SAMI_INARI_FINLAND: return "smn_FI";
    2199             :           }
    2200             :         return "se"; /* or "smi"? */
    2201             :       case LANG_SANSKRIT:
    2202             :         switch (sub)
    2203             :           {
    2204             :           case SUBLANG_SANSKRIT_INDIA: return "sa_IN";
    2205             :           }
    2206             :         return "sa";
    2207             :       case LANG_SCOTTISH_GAELIC:
    2208             :         switch (sub)
    2209             :           {
    2210             :           case SUBLANG_DEFAULT: return "gd_GB";
    2211             :           }
    2212             :         return "gd";
    2213             :       case LANG_SINDHI:
    2214             :         switch (sub)
    2215             :           {
    2216             :           case SUBLANG_SINDHI_INDIA: return "sd_IN";
    2217             :           case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
    2218             :           /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/
    2219             :           }
    2220             :         return "sd";
    2221             :       case LANG_SINHALESE:
    2222             :         switch (sub)
    2223             :           {
    2224             :           case SUBLANG_SINHALESE_SRI_LANKA: return "si_LK";
    2225             :           }
    2226             :         return "si";
    2227             :       case LANG_SLOVAK:
    2228             :         switch (sub)
    2229             :           {
    2230             :           case SUBLANG_SLOVAK_SLOVAKIA: return "sk_SK";
    2231             :           }
    2232             :         return "sk";
    2233             :       case LANG_SLOVENIAN:
    2234             :         switch (sub)
    2235             :           {
    2236             :           case SUBLANG_SLOVENIAN_SLOVENIA: return "sl_SI";
    2237             :           }
    2238             :         return "sl";
    2239             :       case LANG_SOMALI:
    2240             :         switch (sub)
    2241             :           {
    2242             :           case SUBLANG_DEFAULT: return "so_SO";
    2243             :           }
    2244             :         return "so";
    2245             :       case LANG_SORBIAN:
    2246             :         /* FIXME: Adjust this when such locales appear on Unix.  */
    2247             :         switch (sub)
    2248             :           {
    2249             :           /* Upper Sorbian */
    2250             :           case 0x00: return "hsb";
    2251             :           case SUBLANG_UPPER_SORBIAN_GERMANY: return "hsb_DE";
    2252             :           /* Lower Sorbian */
    2253             :           case 0x1f: return "dsb";
    2254             :           case SUBLANG_LOWER_SORBIAN_GERMANY: return "dsb_DE";
    2255             :           }
    2256             :         return "wen";
    2257             :       case LANG_SOTHO:
    2258             :         /* <http://www.microsoft.com/globaldev/reference/lcid-all.mspx> calls
    2259             :            it "Sepedi"; according to
    2260             :            <http://www.ethnologue.com/show_language.asp?code=nso>
    2261             :            <http://www.ethnologue.com/show_language.asp?code=sot>
    2262             :            it's the same as Northern Sotho.  */
    2263             :         switch (sub)
    2264             :           {
    2265             :           case SUBLANG_SOTHO_SOUTH_AFRICA: return "nso_ZA";
    2266             :           }
    2267             :         return "nso";
    2268             :       case LANG_SPANISH:
    2269             :         switch (sub)
    2270             :           {
    2271             :           case SUBLANG_SPANISH: return "es_ES";
    2272             :           case SUBLANG_SPANISH_MEXICAN: return "es_MX";
    2273             :           case SUBLANG_SPANISH_MODERN:
    2274             :             return "es_ES@modern";      /* not seen on Unix */
    2275             :           case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
    2276             :           case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
    2277             :           case SUBLANG_SPANISH_PANAMA: return "es_PA";
    2278             :           case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
    2279             :           case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
    2280             :           case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
    2281             :           case SUBLANG_SPANISH_PERU: return "es_PE";
    2282             :           case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
    2283             :           case SUBLANG_SPANISH_ECUADOR: return "es_EC";
    2284             :           case SUBLANG_SPANISH_CHILE: return "es_CL";
    2285             :           case SUBLANG_SPANISH_URUGUAY: return "es_UY";
    2286             :           case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
    2287             :           case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
    2288             :           case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
    2289             :           case SUBLANG_SPANISH_HONDURAS: return "es_HN";
    2290             :           case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
    2291             :           case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
    2292             :           case SUBLANG_SPANISH_US: return "es_US";
    2293             :           }
    2294             :         return "es";
    2295             :       case LANG_SUTU:
    2296             :         switch (sub)
    2297             :           {
    2298             :           case SUBLANG_DEFAULT: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
    2299             :           }
    2300             :         return "bnt";
    2301             :       case LANG_SWAHILI:
    2302             :         switch (sub)
    2303             :           {
    2304             :           case SUBLANG_SWAHILI_KENYA: return "sw_KE";
    2305             :           }
    2306             :         return "sw";
    2307             :       case LANG_SWEDISH:
    2308             :         switch (sub)
    2309             :           {
    2310             :           case SUBLANG_SWEDISH_SWEDEN: return "sv_SE";
    2311             :           case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
    2312             :           }
    2313             :         return "sv";
    2314             :       case LANG_SYRIAC:
    2315             :         switch (sub)
    2316             :           {
    2317             :           case SUBLANG_SYRIAC_SYRIA: return "syr_SY"; /* An extinct language.  */
    2318             :           }
    2319             :         return "syr";
    2320             :       case LANG_TAGALOG:
    2321             :         switch (sub)
    2322             :           {
    2323             :           case SUBLANG_TAGALOG_PHILIPPINES: return "tl_PH"; /* or "fil_PH"? */
    2324             :           }
    2325             :         return "tl"; /* or "fil"? */
    2326             :       case LANG_TAJIK:
    2327             :         switch (sub)
    2328             :           {
    2329             :           case 0x1f: return "tg";
    2330             :           case SUBLANG_TAJIK_TAJIKISTAN: return "tg_TJ";
    2331             :           }
    2332             :         return "tg";
    2333             :       case LANG_TAMAZIGHT:
    2334             :         /* Note: Microsoft uses the non-ISO language code "tmz".  */
    2335             :         switch (sub)
    2336             :           {
    2337             :           /* FIXME: Adjust this when Tamazight locales appear on Unix.  */
    2338             :           case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
    2339             :           case 0x1f: return "ber@latin";
    2340             :           case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
    2341             :           }
    2342             :         return "ber";
    2343             :       case LANG_TAMIL:
    2344             :         switch (sub)
    2345             :           {
    2346             :           case SUBLANG_TAMIL_INDIA: return "ta_IN";
    2347             :           }
    2348             :         return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG".  */
    2349             :       case LANG_TATAR:
    2350             :         switch (sub)
    2351             :           {
    2352             :           case SUBLANG_TATAR_RUSSIA: return "tt_RU";
    2353             :           }
    2354             :         return "tt";
    2355             :       case LANG_TELUGU:
    2356             :         switch (sub)
    2357             :           {
    2358             :           case SUBLANG_TELUGU_INDIA: return "te_IN";
    2359             :           }
    2360             :         return "te";
    2361             :       case LANG_THAI:
    2362             :         switch (sub)
    2363             :           {
    2364             :           case SUBLANG_THAI_THAILAND: return "th_TH";
    2365             :           }
    2366             :         return "th";
    2367             :       case LANG_TIBETAN:
    2368             :         switch (sub)
    2369             :           {
    2370             :           case SUBLANG_TIBETAN_PRC:
    2371             :             /* Most Tibetans would not like "bo_CN".  But Tibet does not yet
    2372             :                have a country code of its own.  */
    2373             :             return "bo";
    2374             :           case SUBLANG_TIBETAN_BHUTAN: return "bo_BT";
    2375             :           }
    2376             :         return "bo";
    2377             :       case LANG_TIGRINYA:
    2378             :         switch (sub)
    2379             :           {
    2380             :           case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
    2381             :           case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
    2382             :           }
    2383             :         return "ti";
    2384             :       case LANG_TSONGA:
    2385             :         switch (sub)
    2386             :           {
    2387             :           case SUBLANG_DEFAULT: return "ts_ZA";
    2388             :           }
    2389             :         return "ts";
    2390             :       case LANG_TSWANA:
    2391             :         /* Spoken in South Africa, Botswana.  */
    2392             :         switch (sub)
    2393             :           {
    2394             :           case SUBLANG_TSWANA_SOUTH_AFRICA: return "tn_ZA";
    2395             :           }
    2396             :         return "tn";
    2397             :       case LANG_TURKISH:
    2398             :         switch (sub)
    2399             :           {
    2400             :           case SUBLANG_TURKISH_TURKEY: return "tr_TR";
    2401             :           }
    2402             :         return "tr";
    2403             :       case LANG_TURKMEN:
    2404             :         switch (sub)
    2405             :           {
    2406             :           case SUBLANG_TURKMEN_TURKMENISTAN: return "tk_TM";
    2407             :           }
    2408             :         return "tk";
    2409             :       case LANG_UIGHUR:
    2410             :         switch (sub)
    2411             :           {
    2412             :           case SUBLANG_UIGHUR_PRC: return "ug_CN";
    2413             :           }
    2414             :         return "ug";
    2415             :       case LANG_UKRAINIAN:
    2416             :         switch (sub)
    2417             :           {
    2418             :           case SUBLANG_UKRAINIAN_UKRAINE: return "uk_UA";
    2419             :           }
    2420             :         return "uk";
    2421             :       case LANG_URDU:
    2422             :         switch (sub)
    2423             :           {
    2424             :           case SUBLANG_URDU_PAKISTAN: return "ur_PK";
    2425             :           case SUBLANG_URDU_INDIA: return "ur_IN";
    2426             :           }
    2427             :         return "ur";
    2428             :       case LANG_UZBEK:
    2429             :         switch (sub)
    2430             :           {
    2431             :           case 0x1f: return "uz";
    2432             :           case SUBLANG_UZBEK_LATIN: return "uz_UZ";
    2433             :           case 0x1e: return "uz@cyrillic";
    2434             :           case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
    2435             :           }
    2436             :         return "uz";
    2437             :       case LANG_VENDA:
    2438             :         switch (sub)
    2439             :           {
    2440             :           case SUBLANG_DEFAULT: return "ve_ZA";
    2441             :           }
    2442             :         return "ve";
    2443             :       case LANG_VIETNAMESE:
    2444             :         switch (sub)
    2445             :           {
    2446             :           case SUBLANG_VIETNAMESE_VIETNAM: return "vi_VN";
    2447             :           }
    2448             :         return "vi";
    2449             :       case LANG_WELSH:
    2450             :         switch (sub)
    2451             :           {
    2452             :           case SUBLANG_WELSH_UNITED_KINGDOM: return "cy_GB";
    2453             :           }
    2454             :         return "cy";
    2455             :       case LANG_WOLOF:
    2456             :         switch (sub)
    2457             :           {
    2458             :           case SUBLANG_WOLOF_SENEGAL: return "wo_SN";
    2459             :           }
    2460             :         return "wo";
    2461             :       case LANG_XHOSA:
    2462             :         switch (sub)
    2463             :           {
    2464             :           case SUBLANG_XHOSA_SOUTH_AFRICA: return "xh_ZA";
    2465             :           }
    2466             :         return "xh";
    2467             :       case LANG_YAKUT:
    2468             :         switch (sub)
    2469             :           {
    2470             :           case SUBLANG_YAKUT_RUSSIA: return "sah_RU";
    2471             :           }
    2472             :         return "sah";
    2473             :       case LANG_YI:
    2474             :         switch (sub)
    2475             :           {
    2476             :           case SUBLANG_YI_PRC: return "ii_CN";
    2477             :           }
    2478             :         return "ii";
    2479             :       case LANG_YIDDISH:
    2480             :         switch (sub)
    2481             :           {
    2482             :           case SUBLANG_DEFAULT: return "yi_IL";
    2483             :           }
    2484             :         return "yi";
    2485             :       case LANG_YORUBA:
    2486             :         switch (sub)
    2487             :           {
    2488             :           case SUBLANG_YORUBA_NIGERIA: return "yo_NG";
    2489             :           }
    2490             :         return "yo";
    2491             :       case LANG_ZULU:
    2492             :         switch (sub)
    2493             :           {
    2494             :           case SUBLANG_ZULU_SOUTH_AFRICA: return "zu_ZA";
    2495             :           }
    2496             :         return "zu";
    2497             :       default: return "C";
    2498             :       }
    2499             :   }
    2500             : }
    2501             : 
    2502             : # if !defined IN_LIBINTL
    2503             : static
    2504             : # endif
    2505             : const char *
    2506             : gl_locale_name_from_win32_LCID (LCID lcid)
    2507             : {
    2508             :   LANGID langid;
    2509             : 
    2510             :   /* Strip off the sorting rules, keep only the language part.  */
    2511             :   langid = LANGIDFROMLCID (lcid);
    2512             : 
    2513             :   return gl_locale_name_from_win32_LANGID (langid);
    2514             : }
    2515             : 
    2516             : # ifdef WINDOWS_NATIVE
    2517             : 
    2518             : /* Two variables to interface between get_lcid and the EnumLocales
    2519             :    callback function below.  */
    2520             : static LCID found_lcid;
    2521             : static char lname[LC_MAX * (LOCALE_NAME_MAX_LENGTH + 1) + 1];
    2522             : 
    2523             : /* Callback function for EnumLocales.  */
    2524             : static BOOL CALLBACK
    2525             : enum_locales_fn (LPTSTR locale_num_str)
    2526             : {
    2527             :   char *endp;
    2528             :   char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
    2529             :   LCID try_lcid = strtoul (locale_num_str, &endp, 16);
    2530             : 
    2531             :   if (GetLocaleInfo (try_lcid, LOCALE_SENGLANGUAGE,
    2532             :                     locval, LOCALE_NAME_MAX_LENGTH))
    2533             :     {
    2534             :       strcat (locval, "_");
    2535             :       if (GetLocaleInfo (try_lcid, LOCALE_SENGCOUNTRY,
    2536             :                         locval + strlen (locval), LOCALE_NAME_MAX_LENGTH))
    2537             :        {
    2538             :          size_t locval_len = strlen (locval);
    2539             : 
    2540             :          if (strncmp (locval, lname, locval_len) == 0
    2541             :              && (lname[locval_len] == '.'
    2542             :                  || lname[locval_len] == '\0'))
    2543             :            {
    2544             :              found_lcid = try_lcid;
    2545             :              return FALSE;
    2546             :            }
    2547             :        }
    2548             :     }
    2549             :   return TRUE;
    2550             : }
    2551             : 
    2552             : /* This lock protects the get_lcid against multiple simultaneous calls.  */
    2553             : gl_lock_define_initialized(static, get_lcid_lock)
    2554             : 
    2555             : /* Return the Locale ID (LCID) number given the locale's name, a
    2556             :    string, in LOCALE_NAME.  This works by enumerating all the locales
    2557             :    supported by the system, until we find one whose name matches
    2558             :    LOCALE_NAME.  */
    2559             : static LCID
    2560             : get_lcid (const char *locale_name)
    2561             : {
    2562             :   /* A simple cache.  */
    2563             :   static LCID last_lcid;
    2564             :   static char last_locale[1000];
    2565             : 
    2566             :   /* Lock while looking for an LCID, to protect access to static
    2567             :      variables: last_lcid, last_locale, found_lcid, and lname.  */
    2568             :   gl_lock_lock (get_lcid_lock);
    2569             :   if (last_lcid > 0 && strcmp (locale_name, last_locale) == 0)
    2570             :     {
    2571             :       gl_lock_unlock (get_lcid_lock);
    2572             :       return last_lcid;
    2573             :     }
    2574             :   strncpy (lname, locale_name, sizeof (lname) - 1);
    2575             :   lname[sizeof (lname) - 1] = '\0';
    2576             :   found_lcid = 0;
    2577             :   EnumSystemLocales (enum_locales_fn, LCID_SUPPORTED);
    2578             :   if (found_lcid > 0)
    2579             :     {
    2580             :       last_lcid = found_lcid;
    2581             :       strcpy (last_locale, locale_name);
    2582             :     }
    2583             :   gl_lock_unlock (get_lcid_lock);
    2584             :   return found_lcid;
    2585             : }
    2586             : 
    2587             : # endif
    2588             : #endif
    2589             : 
    2590             : 
    2591             : #if HAVE_USELOCALE /* glibc, Solaris >= 12 or Mac OS X */
    2592             : 
    2593             : /* Simple hash set of strings.  We don't want to drag in lots of hash table
    2594             :    code here.  */
    2595             : 
    2596             : # define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
    2597             : 
    2598             : /* A hash function for NUL-terminated char* strings using
    2599             :    the method described by Bruno Haible.
    2600             :    See http://www.haible.de/bruno/hashfunc.html.  */
    2601             : static size_t _GL_ATTRIBUTE_PURE
    2602          72 : string_hash (const void *x)
    2603             : {
    2604          72 :   const char *s = (const char *) x;
    2605          72 :   size_t h = 0;
    2606             : 
    2607         384 :   for (; *s; s++)
    2608         312 :     h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
    2609             : 
    2610          72 :   return h;
    2611             : }
    2612             : 
    2613             : /* A hash table of fixed size.  Multiple threads can access it read-only
    2614             :    simultaneously, but only one thread can insert into it at the same time.  */
    2615             : 
    2616             : /* A node in a hash bucket collision list.  */
    2617             : struct hash_node
    2618             :   {
    2619             :     struct hash_node * volatile next;
    2620             :     char contents[100]; /* has variable size */
    2621             :   };
    2622             : 
    2623             : # define HASH_TABLE_SIZE 257
    2624             : static struct hash_node * volatile struniq_hash_table[HASH_TABLE_SIZE]
    2625             :   /* = { NULL, ..., NULL } */;
    2626             : 
    2627             : /* This lock protects the struniq_hash_table against multiple simultaneous
    2628             :    insertions.  */
    2629             : gl_lock_define_initialized(static, struniq_lock)
    2630             : 
    2631             : /* Store a copy of the given string in a string pool with indefinite extent.
    2632             :    Return a pointer to this copy.  */
    2633             : static const char *
    2634          72 : struniq (const char *string)
    2635             : {
    2636          72 :   size_t hashcode = string_hash (string);
    2637          72 :   size_t slot = hashcode % HASH_TABLE_SIZE;
    2638             :   size_t size;
    2639             :   struct hash_node *new_node;
    2640             :   struct hash_node *p;
    2641          72 :   for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
    2642          70 :     if (strcmp (p->contents, string) == 0)
    2643          70 :       return p->contents;
    2644           2 :   size = strlen (string) + 1;
    2645           2 :   new_node =
    2646             :     (struct hash_node *)
    2647           2 :     malloc (offsetof (struct hash_node, contents[0]) + size);
    2648           2 :   if (new_node == NULL)
    2649             :     /* Out of memory.  Return a statically allocated string.  */
    2650           0 :     return "C";
    2651           2 :   memcpy (new_node->contents, string, size);
    2652             :   /* Lock while inserting new_node.  */
    2653           2 :   gl_lock_lock (struniq_lock);
    2654             :   /* Check whether another thread already added the string while we were
    2655             :      waiting on the lock.  */
    2656           2 :   for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
    2657           0 :     if (strcmp (p->contents, string) == 0)
    2658             :       {
    2659           0 :         free (new_node);
    2660           0 :         new_node = p;
    2661           0 :         goto done;
    2662             :       }
    2663             :   /* Really insert new_node into the hash table.  Fill new_node entirely first,
    2664             :      because other threads may be iterating over the linked list.  */
    2665           2 :   new_node->next = struniq_hash_table[slot];
    2666           2 :   struniq_hash_table[slot] = new_node;
    2667             :  done:
    2668             :   /* Unlock after new_node is inserted.  */
    2669           2 :   gl_lock_unlock (struniq_lock);
    2670           2 :   return new_node->contents;
    2671             : }
    2672             : 
    2673             : #endif
    2674             : 
    2675             : 
    2676             : #if defined IN_LIBINTL || HAVE_USELOCALE
    2677             : 
    2678             : /* Like gl_locale_name_thread, except that the result is not in storage of
    2679             :    indefinite extent.  */
    2680             : # if !defined IN_LIBINTL
    2681             : static
    2682             : # endif
    2683             : const char *
    2684          84 : gl_locale_name_thread_unsafe (int category, const char *categoryname)
    2685             : {
    2686             : # if HAVE_USELOCALE
    2687             :   {
    2688          84 :     locale_t thread_locale = uselocale (NULL);
    2689          84 :     if (thread_locale != LC_GLOBAL_LOCALE)
    2690             :       {
    2691             : #  if __GLIBC__ >= 2 && !defined __UCLIBC__
    2692             :         /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in
    2693             :            glibc < 2.12.
    2694             :            See <http://sourceware.org/bugzilla/show_bug.cgi?id=10968>.  */
    2695          72 :         const char *name =
    2696          72 :           nl_langinfo (_NL_ITEM ((category), _NL_ITEM_INDEX (-1)));
    2697          72 :         if (name[0] == '\0')
    2698             :           /* Fallback code for glibc < 2.4, which did not implement
    2699             :              nl_langinfo (_NL_LOCALE_NAME (category)).  */
    2700           0 :           name = thread_locale->__names[category];
    2701          72 :         return name;
    2702             : #  elif defined __FreeBSD__ || (defined __APPLE__ && defined __MACH__)
    2703             :         /* FreeBSD, Mac OS X */
    2704             :         int mask;
    2705             : 
    2706             :         switch (category)
    2707             :           {
    2708             :           case LC_CTYPE:
    2709             :             mask = LC_CTYPE_MASK;
    2710             :             break;
    2711             :           case LC_NUMERIC:
    2712             :             mask = LC_NUMERIC_MASK;
    2713             :             break;
    2714             :           case LC_TIME:
    2715             :             mask = LC_TIME_MASK;
    2716             :             break;
    2717             :           case LC_COLLATE:
    2718             :             mask = LC_COLLATE_MASK;
    2719             :             break;
    2720             :           case LC_MONETARY:
    2721             :             mask = LC_MONETARY_MASK;
    2722             :             break;
    2723             :           case LC_MESSAGES:
    2724             :             mask = LC_MESSAGES_MASK;
    2725             :             break;
    2726             :           default: /* We shouldn't get here.  */
    2727             :             return "";
    2728             :           }
    2729             :         return querylocale (mask, thread_locale);
    2730             : #  elif defined __sun && HAVE_GETLOCALENAME_L
    2731             :         /* Solaris >= 12.  */
    2732             :         return getlocalename_l (category, thread_locale);
    2733             : #  elif defined __ANDROID__
    2734             :         return MB_CUR_MAX == 4 ? "C.UTF-8" : "C";
    2735             : #  endif
    2736             :       }
    2737             :   }
    2738             : # endif
    2739          12 :   return NULL;
    2740             : }
    2741             : 
    2742             : #endif
    2743             : 
    2744             : const char *
    2745          84 : gl_locale_name_thread (int category, const char *categoryname)
    2746             : {
    2747             : #if HAVE_USELOCALE
    2748          84 :   const char *name = gl_locale_name_thread_unsafe (category, categoryname);
    2749          84 :   if (name != NULL)
    2750          72 :     return struniq (name);
    2751             : #elif defined WINDOWS_NATIVE
    2752             :   if (LC_MIN <= category && category <= LC_MAX)
    2753             :     {
    2754             :       char *locname = setlocale (category, NULL);
    2755             :       LCID lcid = 0;
    2756             : 
    2757             :       /* If CATEGORY is LC_ALL, the result might be a semi-colon
    2758             :         separated list of locales.  We need only one, so we take the
    2759             :         one corresponding to LC_CTYPE, as the most important for
    2760             :         character translations.  */
    2761             :       if (strchr (locname, ';'))
    2762             :        locname = setlocale (LC_CTYPE, NULL);
    2763             : 
    2764             :       /* Convert locale name to LCID.  We don't want to use
    2765             :          LocaleNameToLCID because (a) it is only available since Vista,
    2766             :          and (b) it doesn't accept locale names returned by 'setlocale'.  */
    2767             :       lcid = get_lcid (locname);
    2768             : 
    2769             :       if (lcid > 0)
    2770             :         return gl_locale_name_from_win32_LCID (lcid);
    2771             :     }
    2772             : #endif
    2773          12 :   return NULL;
    2774             : }
    2775             : 
    2776             : /* XPG3 defines the result of 'setlocale (category, NULL)' as:
    2777             :    "Directs 'setlocale()' to query 'category' and return the current
    2778             :     setting of 'local'."
    2779             :    However it does not specify the exact format.  Neither do SUSV2 and
    2780             :    ISO C 99.  So we can use this feature only on selected systems (e.g.
    2781             :    those using GNU C Library).  */
    2782             : #if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
    2783             : # define HAVE_LOCALE_NULL
    2784             : #endif
    2785             : 
    2786             : const char *
    2787          19 : gl_locale_name_posix (int category, const char *categoryname)
    2788             : {
    2789             :   /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
    2790             :      On some systems this can be done by the 'setlocale' function itself.  */
    2791             : #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
    2792          19 :   return setlocale (category, NULL);
    2793             : #else
    2794             :   /* On other systems we ignore what setlocale reports and instead look at the
    2795             :      environment variables directly.  This is necessary
    2796             :        1. on systems which have a facility for customizing the default locale
    2797             :           (Mac OS X, native Windows, Cygwin) and where the system's setlocale()
    2798             :           function ignores this default locale (Mac OS X, Cygwin), in two cases:
    2799             :           a. when the user missed to use the setlocale() override from libintl
    2800             :              (for example by not including <libintl.h>),
    2801             :           b. when setlocale supports only the "C" locale, such as on Cygwin
    2802             :              1.5.x.  In this case even the override from libintl cannot help.
    2803             :        2. on all systems where setlocale supports only the "C" locale.  */
    2804             :   /* Strictly speaking, it is a POSIX violation to look at the environment
    2805             :      variables regardless whether setlocale has been called or not.  POSIX
    2806             :      says:
    2807             :          "For C-language programs, the POSIX locale shall be the
    2808             :           default locale when the setlocale() function is not called."
    2809             :      But we assume that all programs that use internationalized APIs call
    2810             :      setlocale (LC_ALL, "").  */
    2811             :   return gl_locale_name_environ (category, categoryname);
    2812             : #endif
    2813             : }
    2814             : 
    2815             : const char *
    2816          13 : gl_locale_name_environ (int category, const char *categoryname)
    2817             : {
    2818             :   const char *retval;
    2819             : 
    2820             :   /* Setting of LC_ALL overrides all other.  */
    2821          13 :   retval = getenv ("LC_ALL");
    2822          13 :   if (retval != NULL && retval[0] != '\0')
    2823           1 :     return retval;
    2824             :   /* Next comes the name of the desired category.  */
    2825          12 :   retval = getenv (categoryname);
    2826          12 :   if (retval != NULL && retval[0] != '\0')
    2827           3 :     return retval;
    2828             :   /* Last possibility is the LANG environment variable.  */
    2829           9 :   retval = getenv ("LANG");
    2830           9 :   if (retval != NULL && retval[0] != '\0')
    2831             :     {
    2832             : #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
    2833             :       /* Mac OS X 10.2 or newer.
    2834             :          Ignore invalid LANG value set by the Terminal application.  */
    2835             :       if (strcmp (retval, "UTF-8") != 0)
    2836             : #endif
    2837             : #if defined __CYGWIN__
    2838             :       /* Cygwin.
    2839             :          Ignore dummy LANG value set by ~/.profile.  */
    2840             :       if (strcmp (retval, "C.UTF-8") != 0)
    2841             : #endif
    2842           2 :         return retval;
    2843             :     }
    2844             : 
    2845           7 :   return NULL;
    2846             : }
    2847             : 
    2848             : const char *
    2849          13 : gl_locale_name_default (void)
    2850             : {
    2851             :   /* POSIX:2001 says:
    2852             :      "All implementations shall define a locale as the default locale, to be
    2853             :       invoked when no environment variables are set, or set to the empty
    2854             :       string.  This default locale can be the POSIX locale or any other
    2855             :       implementation-defined locale.  Some implementations may provide
    2856             :       facilities for local installation administrators to set the default
    2857             :       locale, customizing it for each location.  POSIX:2001 does not require
    2858             :       such a facility.
    2859             : 
    2860             :      The systems with such a facility are Mac OS X and Windows: They provide a
    2861             :      GUI that allows the user to choose a locale.
    2862             :        - On Mac OS X, by default, none of LC_* or LANG are set.  Starting with
    2863             :          Mac OS X 10.4 or 10.5, LANG is set for processes launched by the
    2864             :          'Terminal' application (but sometimes to an incorrect value "UTF-8").
    2865             :          When no environment variable is set, setlocale (LC_ALL, "") uses the
    2866             :          "C" locale.
    2867             :        - On native Windows, by default, none of LC_* or LANG are set.
    2868             :          When no environment variable is set, setlocale (LC_ALL, "") uses the
    2869             :          locale chosen by the user.
    2870             :        - On Cygwin 1.5.x, by default, none of LC_* or LANG are set.
    2871             :          When no environment variable is set, setlocale (LC_ALL, "") uses the
    2872             :          "C" locale.
    2873             :        - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default
    2874             :          ~/.profile is executed.
    2875             :          When no environment variable is set, setlocale (LC_ALL, "") uses the
    2876             :          "C.UTF-8" locale, which operates in the same way as the "C" locale.
    2877             :   */
    2878             : 
    2879             : #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__)
    2880             : 
    2881             :   /* The system does not have a way of setting the locale, other than the
    2882             :      POSIX specified environment variables.  We use C as default locale.  */
    2883          13 :   return "C";
    2884             : 
    2885             : #else
    2886             : 
    2887             :   /* Return an XPG style locale name language[_territory][@modifier].
    2888             :      Don't even bother determining the codeset; it's not useful in this
    2889             :      context, because message catalogs are not specific to a single
    2890             :      codeset.  */
    2891             : 
    2892             : # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
    2893             :   /* Mac OS X 10.2 or newer */
    2894             :   {
    2895             :     /* Cache the locale name, since CoreFoundation calls are expensive.  */
    2896             :     static const char *cached_localename;
    2897             : 
    2898             :     if (cached_localename == NULL)
    2899             :       {
    2900             :         char namebuf[256];
    2901             : #  if HAVE_CFLOCALECOPYCURRENT /* Mac OS X 10.3 or newer */
    2902             :         CFLocaleRef locale = CFLocaleCopyCurrent ();
    2903             :         CFStringRef name = CFLocaleGetIdentifier (locale);
    2904             : 
    2905             :         if (CFStringGetCString (name, namebuf, sizeof (namebuf),
    2906             :                                 kCFStringEncodingASCII))
    2907             :           {
    2908             :             gl_locale_name_canonicalize (namebuf);
    2909             :             cached_localename = strdup (namebuf);
    2910             :           }
    2911             :         CFRelease (locale);
    2912             : #  elif HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.2 or newer */
    2913             :         CFTypeRef value =
    2914             :           CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
    2915             :                                      kCFPreferencesCurrentApplication);
    2916             :         if (value != NULL
    2917             :             && CFGetTypeID (value) == CFStringGetTypeID ()
    2918             :             && CFStringGetCString ((CFStringRef)value,
    2919             :                                    namebuf, sizeof (namebuf),
    2920             :                                    kCFStringEncodingASCII))
    2921             :           {
    2922             :             gl_locale_name_canonicalize (namebuf);
    2923             :             cached_localename = strdup (namebuf);
    2924             :           }
    2925             : #  endif
    2926             :         if (cached_localename == NULL)
    2927             :           cached_localename = "C";
    2928             :       }
    2929             :     return cached_localename;
    2930             :   }
    2931             : 
    2932             : # endif
    2933             : 
    2934             : # if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
    2935             :   {
    2936             :     LCID lcid;
    2937             : 
    2938             :     /* Use native Windows API locale ID.  */
    2939             :     lcid = GetThreadLocale ();
    2940             : 
    2941             :     return gl_locale_name_from_win32_LCID (lcid);
    2942             :   }
    2943             : # endif
    2944             : #endif
    2945             : }
    2946             : 
    2947             : /* Determine the current locale's name, and canonicalize it into XPG syntax
    2948             :      language[_territory][.codeset][@modifier]
    2949             :    The codeset part in the result is not reliable; the locale_charset()
    2950             :    should be used for codeset information instead.
    2951             :    The result must not be freed; it is statically allocated.  */
    2952             : 
    2953             : const char *
    2954          10 : gl_locale_name (int category, const char *categoryname)
    2955             : {
    2956             :   const char *retval;
    2957             : 
    2958          10 :   retval = gl_locale_name_thread (category, categoryname);
    2959          10 :   if (retval != NULL)
    2960           0 :     return retval;
    2961             : 
    2962          10 :   retval = gl_locale_name_posix (category, categoryname);
    2963          10 :   if (retval != NULL)
    2964          10 :     return retval;
    2965             : 
    2966           0 :   return gl_locale_name_default ();
    2967             : }

Generated by: LCOV version 1.11