| 1319 | }; |
| 1320 | |
| 1321 | uint16_t get_usb_code_for_current_locale(void) |
| 1322 | { |
| 1323 | char *locale; |
| 1324 | char search_string[64]; |
| 1325 | char *ptr; |
| 1326 | |
| 1327 | /* Get the current locale. */ |
| 1328 | locale = setlocale(0, NULL); |
| 1329 | if (!locale) |
| 1330 | return 0x0; |
| 1331 | |
| 1332 | /* Make a copy of the current locale string. */ |
| 1333 | strncpy(search_string, locale, sizeof(search_string)); |
| 1334 | search_string[sizeof(search_string)-1] = '\0'; |
| 1335 | |
| 1336 | /* Chop off the encoding part, and make it lower case. */ |
| 1337 | ptr = search_string; |
| 1338 | while (*ptr) { |
| 1339 | *ptr = tolower(*ptr); |
| 1340 | if (*ptr == '.') { |
| 1341 | *ptr = '\0'; |
| 1342 | break; |
| 1343 | } |
| 1344 | ptr++; |
| 1345 | } |
| 1346 | |
| 1347 | /* Find the entry which matches the string code of our locale. */ |
| 1348 | struct lang_map_entry *lang = lang_map; |
| 1349 | while (lang->string_code) { |
| 1350 | if (!strcmp(lang->string_code, search_string)) { |
| 1351 | return lang->usb_code; |
| 1352 | } |
| 1353 | lang++; |
| 1354 | } |
| 1355 | |
| 1356 | /* There was no match. Find with just the language only. */ |
| 1357 | /* Chop off the variant. Chop it off at the '_'. */ |
| 1358 | ptr = search_string; |
| 1359 | while (*ptr) { |
| 1360 | *ptr = tolower(*ptr); |
| 1361 | if (*ptr == '_') { |
| 1362 | *ptr = '\0'; |
| 1363 | break; |
| 1364 | } |
| 1365 | ptr++; |
| 1366 | } |
| 1367 | |
| 1368 | #if 0 // TODO: Do we need this? |
| 1369 | /* Find the entry which matches the string code of our language. */ |
| 1370 | lang = lang_map; |
| 1371 | while (lang->string_code) { |
| 1372 | if (!strcmp(lang->string_code, search_string)) { |
| 1373 | return lang->usb_code; |
| 1374 | } |
| 1375 | lang++; |
| 1376 | } |
| 1377 | #endif |
| 1378 | |