MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / get_usb_code_for_current_locale

Function get_usb_code_for_current_locale

lib/hidapi/libusb/hid.c:1793–1854  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1791};
1792
1793uint16_t get_usb_code_for_current_locale(void)
1794{
1795 char *locale;
1796 char search_string[64];
1797 char *ptr;
1798 struct lang_map_entry *lang;
1799
1800 /* Get the current locale. */
1801 locale = setlocale(0, NULL);
1802 if (!locale)
1803 return 0x0;
1804
1805 /* Make a copy of the current locale string. */
1806 strncpy(search_string, locale, sizeof(search_string));
1807 search_string[sizeof(search_string)-1] = '\0';
1808
1809 /* Chop off the encoding part, and make it lower case. */
1810 ptr = search_string;
1811 while (*ptr) {
1812 *ptr = tolower(*ptr);
1813 if (*ptr == '.') {
1814 *ptr = '\0';
1815 break;
1816 }
1817 ptr++;
1818 }
1819
1820 /* Find the entry which matches the string code of our locale. */
1821 lang = lang_map;
1822 while (lang->string_code) {
1823 if (!strcmp(lang->string_code, search_string)) {
1824 return lang->usb_code;
1825 }
1826 lang++;
1827 }
1828
1829 /* There was no match. Find with just the language only. */
1830 /* Chop off the variant. Chop it off at the '_'. */
1831 ptr = search_string;
1832 while (*ptr) {
1833 *ptr = tolower(*ptr);
1834 if (*ptr == '_') {
1835 *ptr = '\0';
1836 break;
1837 }
1838 ptr++;
1839 }
1840
1841#if 0 /* TODO: Do we need this? */
1842 /* Find the entry which matches the string code of our language. */
1843 lang = lang_map;
1844 while (lang->string_code) {
1845 if (!strcmp(lang->string_code, search_string)) {
1846 return lang->usb_code;
1847 }
1848 lang++;
1849 }
1850#endif

Callers 1

get_usb_stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected