Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
9.6 KiB

  1. #include "stdinc.h"
  2. #include "util.h"
  3. typedef struct _SXS_CULTURE_INFO
  4. {
  5. LANGID ParentLangID;
  6. LANGID ChildLangID;
  7. USHORT CultureStringCch;
  8. PCWSTR CultureString;
  9. } SXS_CULTURE_INFO, *PSXS_CULTURE_INFO;
  10. typedef const struct _SXS_CULTURE_INFO *PCSXS_CULTURE_INFO;
  11. static const SXS_CULTURE_INFO s_rgCultures[] =
  12. {
  13. { 0x0001, 0x0000, 2, L"ar" },
  14. { 0x0002, 0x0000, 2, L"bg" },
  15. { 0x0003, 0x0000, 2, L"ca" },
  16. { 0x0004, 0x0000, 6, L"zh-CHS" },
  17. { 0x0005, 0x0000, 2, L"cs" },
  18. { 0x0006, 0x0000, 2, L"da" },
  19. { 0x0007, 0x0000, 2, L"de" },
  20. { 0x0008, 0x0000, 2, L"el" },
  21. { 0x0009, 0x0000, 2, L"en" },
  22. { 0x000a, 0x0000, 2, L"es" },
  23. { 0x000b, 0x0000, 2, L"fi" },
  24. { 0x000c, 0x0000, 2, L"fr" },
  25. { 0x000d, 0x0000, 2, L"he" },
  26. { 0x000e, 0x0000, 2, L"hu" },
  27. { 0x000f, 0x0000, 2, L"is" },
  28. { 0x0010, 0x0000, 2, L"it" },
  29. { 0x0011, 0x0000, 2, L"ja" },
  30. { 0x0012, 0x0000, 2, L"ko" },
  31. { 0x0013, 0x0000, 2, L"nl" },
  32. { 0x0014, 0x0000, 2, L"no" },
  33. { 0x0015, 0x0000, 2, L"pl" },
  34. { 0x0016, 0x0000, 2, L"pt" },
  35. { 0x0018, 0x0000, 2, L"ro" },
  36. { 0x0019, 0x0000, 2, L"ru" },
  37. { 0x001a, 0x0000, 2, L"hr" },
  38. { 0x001b, 0x0000, 2, L"sk" },
  39. { 0x001c, 0x0000, 2, L"sq" },
  40. { 0x001d, 0x0000, 2, L"sv" },
  41. { 0x001e, 0x0000, 2, L"th" },
  42. { 0x001f, 0x0000, 2, L"tr" },
  43. { 0x0020, 0x0000, 2, L"ur" },
  44. { 0x0021, 0x0000, 2, L"id" },
  45. { 0x0022, 0x0000, 2, L"uk" },
  46. { 0x0023, 0x0000, 2, L"be" },
  47. { 0x0024, 0x0000, 2, L"sl" },
  48. { 0x0025, 0x0000, 2, L"et" },
  49. { 0x0026, 0x0000, 2, L"lv" },
  50. { 0x0027, 0x0000, 2, L"lt" },
  51. { 0x0029, 0x0000, 2, L"fa" },
  52. { 0x002a, 0x0000, 2, L"vi" },
  53. { 0x002b, 0x0000, 2, L"hy" },
  54. { 0x002c, 0x0000, 2, L"az" },
  55. { 0x002d, 0x0000, 2, L"eu" },
  56. { 0x002f, 0x0000, 2, L"mk" },
  57. { 0x0036, 0x0000, 2, L"af" },
  58. { 0x0037, 0x0000, 2, L"ka" },
  59. { 0x0038, 0x0000, 2, L"fo" },
  60. { 0x0039, 0x0000, 2, L"hi" },
  61. { 0x003e, 0x0000, 2, L"ms" },
  62. { 0x003f, 0x0000, 2, L"kk" },
  63. { 0x0040, 0x0000, 2, L"ky" },
  64. { 0x0041, 0x0000, 2, L"sw" },
  65. { 0x0043, 0x0000, 2, L"uz" },
  66. { 0x0044, 0x0000, 2, L"tt" },
  67. { 0x0046, 0x0000, 2, L"pa" },
  68. { 0x0047, 0x0000, 2, L"gu" },
  69. { 0x0049, 0x0000, 2, L"ta" },
  70. { 0x004a, 0x0000, 2, L"te" },
  71. { 0x004b, 0x0000, 2, L"kn" },
  72. { 0x004e, 0x0000, 2, L"mr" },
  73. { 0x004f, 0x0000, 2, L"sa" },
  74. { 0x0050, 0x0000, 2, L"mn" },
  75. { 0x0056, 0x0000, 2, L"gl" },
  76. { 0x0057, 0x0000, 3, L"kok" },
  77. { 0x005a, 0x0000, 3, L"syr" },
  78. { 0x0065, 0x0000, 3, L"div" },
  79. { 0x0401, 0x0001, 5, L"ar-SA" },
  80. { 0x0402, 0x0002, 5, L"bg-BG" },
  81. { 0x0403, 0x0003, 5, L"ca-ES" },
  82. { 0x0404, 0x7c04, 5, L"zh-TW" },
  83. { 0x0405, 0x0005, 5, L"cs-CZ" },
  84. { 0x0406, 0x0006, 5, L"da-DK" },
  85. { 0x0407, 0x0007, 5, L"de-DE" },
  86. { 0x0408, 0x0008, 5, L"el-GR" },
  87. { 0x0409, 0x0009, 5, L"en-US" },
  88. { 0x040b, 0x000b, 5, L"fi-FI" },
  89. { 0x040c, 0x000c, 5, L"fr-FR" },
  90. { 0x040d, 0x000d, 5, L"he-IL" },
  91. { 0x040e, 0x000e, 5, L"hu-HU" },
  92. { 0x040f, 0x000f, 5, L"is-IS" },
  93. { 0x0410, 0x0010, 5, L"it-IT" },
  94. { 0x0411, 0x0011, 5, L"ja-JP" },
  95. { 0x0412, 0x0012, 5, L"ko-KR" },
  96. { 0x0413, 0x0013, 5, L"nl-NL" },
  97. { 0x0414, 0x0014, 5, L"nb-NO" },
  98. { 0x0415, 0x0015, 5, L"pl-PL" },
  99. { 0x0416, 0x0016, 5, L"pt-BR" },
  100. { 0x0418, 0x0018, 5, L"ro-RO" },
  101. { 0x0419, 0x0019, 5, L"ru-RU" },
  102. { 0x041a, 0x001a, 5, L"hr-HR" },
  103. { 0x041b, 0x001b, 5, L"sk-SK" },
  104. { 0x041c, 0x001c, 5, L"sq-AL" },
  105. { 0x041d, 0x001d, 5, L"sv-SE" },
  106. { 0x041e, 0x001e, 5, L"th-TH" },
  107. { 0x041f, 0x001f, 5, L"tr-TR" },
  108. { 0x0420, 0x0020, 5, L"ur-PK" },
  109. { 0x0421, 0x0021, 5, L"id-ID" },
  110. { 0x0422, 0x0022, 5, L"uk-UA" },
  111. { 0x0423, 0x0023, 5, L"be-BY" },
  112. { 0x0424, 0x0024, 5, L"sl-SI" },
  113. { 0x0425, 0x0025, 5, L"et-EE" },
  114. { 0x0426, 0x0026, 5, L"lv-LV" },
  115. { 0x0427, 0x0027, 5, L"lt-LT" },
  116. { 0x0429, 0x0029, 5, L"fa-IR" },
  117. { 0x042a, 0x002a, 5, L"vi-VN" },
  118. { 0x042b, 0x002b, 5, L"hy-AM" },
  119. { 0x042c, 0x002c, 10, L"az-AZ-Latn" },
  120. { 0x042d, 0x002d, 5, L"eu-ES" },
  121. { 0x042f, 0x002f, 5, L"mk-MK" },
  122. { 0x0436, 0x0036, 5, L"af-ZA" },
  123. { 0x0437, 0x0037, 5, L"ka-GE" },
  124. { 0x0438, 0x0038, 5, L"fo-FO" },
  125. { 0x0439, 0x0039, 5, L"hi-IN" },
  126. { 0x043e, 0x003e, 5, L"ms-MY" },
  127. { 0x043f, 0x003f, 5, L"kk-KZ" },
  128. { 0x0440, 0x0040, 5, L"ky-KZ" },
  129. { 0x0441, 0x0041, 5, L"sw-KE" },
  130. { 0x0443, 0x0043, 10, L"uz-UZ-Latn" },
  131. { 0x0444, 0x0044, 5, L"tt-RU" },
  132. { 0x0446, 0x0046, 5, L"pa-IN" },
  133. { 0x0447, 0x0047, 5, L"gu-IN" },
  134. { 0x0449, 0x0049, 5, L"ta-IN" },
  135. { 0x044a, 0x004a, 5, L"te-IN" },
  136. { 0x044b, 0x004b, 5, L"kn-IN" },
  137. { 0x044e, 0x004e, 5, L"mr-IN" },
  138. { 0x044f, 0x004f, 5, L"sa-IN" },
  139. { 0x0450, 0x0050, 5, L"mn-MN" },
  140. { 0x0456, 0x0056, 5, L"gl-ES" },
  141. { 0x0457, 0x0057, 6, L"kok-IN" },
  142. { 0x045a, 0x005a, 6, L"syr-SY" },
  143. { 0x0465, 0x0065, 6, L"div-MV" },
  144. { 0x0801, 0x0001, 5, L"ar-IQ" },
  145. { 0x0804, 0x0004, 5, L"zh-CN" },
  146. { 0x0807, 0x0007, 5, L"de-CH" },
  147. { 0x0809, 0x0009, 5, L"en-GB" },
  148. { 0x080a, 0x000a, 5, L"es-MX" },
  149. { 0x080c, 0x000c, 5, L"fr-BE" },
  150. { 0x0810, 0x0010, 5, L"it-CH" },
  151. { 0x0813, 0x0013, 5, L"nl-BE" },
  152. { 0x0814, 0x0014, 5, L"nn-NO" },
  153. { 0x0816, 0x0016, 5, L"pt-PT" },
  154. { 0x081a, 0x001a, 10, L"sr-SP-Latn" },
  155. { 0x081d, 0x001d, 5, L"sv-FI" },
  156. { 0x082c, 0x002c, 10, L"az-AZ-Cyrl" },
  157. { 0x083e, 0x003e, 5, L"ms-BN" },
  158. { 0x0843, 0x0043, 10, L"uz-UZ-Cyrl" },
  159. { 0x0c01, 0x0001, 5, L"ar-EG" },
  160. { 0x0c04, 0x7c04, 5, L"zh-HK" },
  161. { 0x0c07, 0x0007, 5, L"de-AT" },
  162. { 0x0c09, 0x0009, 5, L"en-AU" },
  163. { 0x0c0a, 0x000a, 5, L"es-ES" },
  164. { 0x0c0c, 0x000c, 5, L"fr-CA" },
  165. { 0x0c1a, 0x001a, 10, L"sr-SP-Cyrl" },
  166. { 0x1001, 0x0001, 5, L"ar-LY" },
  167. { 0x1004, 0x0004, 5, L"zh-SG" },
  168. { 0x1007, 0x0007, 5, L"de-LU" },
  169. { 0x1009, 0x0009, 5, L"en-CA" },
  170. { 0x100a, 0x000a, 5, L"es-GT" },
  171. { 0x100c, 0x000c, 5, L"fr-CH" },
  172. { 0x1401, 0x0001, 5, L"ar-DZ" },
  173. { 0x1404, 0x0004, 5, L"zh-MO" },
  174. { 0x1407, 0x0007, 5, L"de-LI" },
  175. { 0x1409, 0x0009, 5, L"en-NZ" },
  176. { 0x140a, 0x000a, 5, L"es-CR" },
  177. { 0x140c, 0x000c, 5, L"fr-LU" },
  178. { 0x1801, 0x0001, 5, L"ar-MA" },
  179. { 0x1809, 0x0009, 5, L"en-IE" },
  180. { 0x180a, 0x000a, 5, L"es-PA" },
  181. { 0x180c, 0x000c, 5, L"fr-MC" },
  182. { 0x1c01, 0x0001, 5, L"ar-TN" },
  183. { 0x1c09, 0x0009, 5, L"en-ZA" },
  184. { 0x1c0a, 0x000a, 5, L"es-DO" },
  185. { 0x2001, 0x0001, 5, L"ar-OM" },
  186. { 0x2009, 0x0009, 5, L"en-JM" },
  187. { 0x200a, 0x000a, 5, L"es-VE" },
  188. { 0x2401, 0x0001, 5, L"ar-YE" },
  189. { 0x2409, 0x0009, 5, L"en-CB" },
  190. { 0x240a, 0x000a, 5, L"es-CO" },
  191. { 0x2801, 0x0001, 5, L"ar-SY" },
  192. { 0x2809, 0x0009, 5, L"en-BZ" },
  193. { 0x280a, 0x000a, 5, L"es-PE" },
  194. { 0x2c01, 0x0001, 5, L"ar-JO" },
  195. { 0x2c09, 0x0009, 5, L"en-TT" },
  196. { 0x2c0a, 0x000a, 5, L"es-AR" },
  197. { 0x3001, 0x0001, 5, L"ar-LB" },
  198. { 0x3009, 0x0009, 5, L"en-ZW" },
  199. { 0x300a, 0x000a, 5, L"es-EC" },
  200. { 0x3401, 0x0001, 5, L"ar-KW" },
  201. { 0x3409, 0x0009, 5, L"en-PH" },
  202. { 0x340a, 0x000a, 5, L"es-CL" },
  203. { 0x3801, 0x0001, 5, L"ar-AE" },
  204. { 0x380a, 0x000a, 5, L"es-UY" },
  205. { 0x3c01, 0x0001, 5, L"ar-BH" },
  206. { 0x3c0a, 0x000a, 5, L"es-PY" },
  207. { 0x4001, 0x0001, 5, L"ar-QA" },
  208. { 0x400a, 0x000a, 5, L"es-BO" },
  209. { 0x440a, 0x000a, 5, L"es-SV" },
  210. { 0x480a, 0x000a, 5, L"es-HN" },
  211. { 0x4c0a, 0x000a, 5, L"es-NI" },
  212. { 0x500a, 0x000a, 5, L"es-PR" },
  213. { 0x7c04, 0x0000, 6, L"zh-CHT" },
  214. };
  215. int __cdecl bsearch_callback(const void *pv1, const void *pv2)
  216. {
  217. PCSXS_CULTURE_INFO p1 = (PCSXS_CULTURE_INFO) pv1;
  218. PCSXS_CULTURE_INFO p2 = (PCSXS_CULTURE_INFO) pv2;
  219. if (p1->ParentLangID < p2->ParentLangID)
  220. return -1;
  221. else if (p1->ParentLangID == p2->ParentLangID)
  222. return 0;
  223. return 1;
  224. }
  225. BOOL
  226. SxspMapLANGIDToCultures(
  227. LANGID langid,
  228. CBaseStringBuffer &rbuffGeneric,
  229. CBaseStringBuffer &rbuffSpecific
  230. )
  231. {
  232. BOOL fSuccess = FALSE;
  233. FN_TRACE_WIN32(fSuccess);
  234. SXS_CULTURE_INFO Key;
  235. PCSXS_CULTURE_INFO p1 = NULL;
  236. PCSXS_CULTURE_INFO p2 = NULL;
  237. rbuffGeneric.Clear();
  238. rbuffSpecific.Clear();
  239. Key.ParentLangID = langid;
  240. p1 = (PCSXS_CULTURE_INFO) bsearch(&Key, s_rgCultures, NUMBER_OF(s_rgCultures), sizeof(SXS_CULTURE_INFO), &bsearch_callback);
  241. if (p1 != NULL)
  242. {
  243. Key.ParentLangID = p1->ChildLangID;
  244. p2 = (PCSXS_CULTURE_INFO) bsearch(&Key, s_rgCultures, NUMBER_OF(s_rgCultures), sizeof(SXS_CULTURE_INFO), &bsearch_callback);
  245. }
  246. if (p1 != NULL)
  247. IFW32FALSE_EXIT(rbuffSpecific.Win32Assign(p1->CultureString, p1->CultureStringCch));
  248. if (p2 != NULL)
  249. IFW32FALSE_EXIT(rbuffGeneric.Win32Assign(p2->CultureString, p2->CultureStringCch));
  250. fSuccess = TRUE;
  251. Exit:
  252. return fSuccess;
  253. }
  254. BOOL
  255. SxspMapCultureToLANGID(
  256. PCWSTR pcwszCultureString,
  257. LANGID &lid,
  258. PBOOL pfFound
  259. )
  260. {
  261. FN_PROLOG_WIN32
  262. ULONG ul;
  263. PARAMETER_CHECK(pcwszCultureString != NULL);
  264. if ( pfFound ) *pfFound = TRUE;
  265. lid = 0x0;
  266. for ( ul = 0; ul < NUMBER_OF(s_rgCultures); ul++ )
  267. {
  268. if (lstrcmpiW(pcwszCultureString, s_rgCultures[ul].CultureString) == 0)
  269. {
  270. lid = s_rgCultures[ul].ParentLangID;
  271. break;
  272. }
  273. }
  274. if ( ul == NUMBER_OF(s_rgCultures) && pfFound )
  275. *pfFound = FALSE;
  276. FN_EPILOG
  277. }