MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / get_usb_code_for_current_locale

Function get_usb_code_for_current_locale

dependencies/hidapi/hidapi.c:1318–1379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

get_usb_stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected