int codepage = -1;
CPINFO cpinfo;
- if (!*cp_name)
+ if (!cp_name || !*cp_name)
return CP_UTF8; /* default */
- if (cp_name && *cp_name)
- for (cpi = cp_list; cpi->name; cpi++) {
- s = cp_name;
- d = cpi->name;
- for (;;) {
- while (*s && !isalnum(*s) && *s != ':')
- s++;
- while (*d && !isalnum(*d) && *d != ':')
- d++;
- if (*s == 0) {
- codepage = cpi->codepage;
- if (codepage == CP_UTF8)
- goto break_break;
- if (codepage == -1)
- return codepage;
- if (codepage == 0) {
- codepage = 65536 + (cpi - cp_list);
- goto break_break;
- }
-
- if (GetCPInfo(codepage, &cpinfo) != 0)
- goto break_break;
- }
- if (tolower(*s++) != tolower(*d++))
- break;
- }
- }
-
- if (cp_name && *cp_name) {
- d = cp_name;
- if (tolower(d[0]) == 'c' && tolower(d[1]) == 'p')
- d += 2;
- if (tolower(d[0]) == 'i' && tolower(d[1]) == 'b'
- && tolower(d[2]) == 'm')
- d += 3;
- for (s = d; *s >= '0' && *s <= '9'; s++);
- if (*s == 0 && s != d)
- codepage = atoi(d); /* CP999 or IBM999 */
-
- if (codepage == CP_ACP)
- codepage = GetACP();
- if (codepage == CP_OEMCP)
- codepage = GetOEMCP();
- if (codepage > 65535)
- codepage = -2;
+ for (cpi = cp_list; cpi->name; cpi++) {
+ s = cp_name;
+ d = cpi->name;
+ for (;;) {
+ while (*s && !isalnum(*s) && *s != ':')
+ s++;
+ while (*d && !isalnum(*d) && *d != ':')
+ d++;
+ if (*s == 0) {
+ codepage = cpi->codepage;
+ if (codepage == CP_UTF8)
+ goto break_break;
+ if (codepage == -1)
+ return codepage;
+ if (codepage == 0) {
+ codepage = 65536 + (cpi - cp_list);
+ goto break_break;
+ }
+
+ if (GetCPInfo(codepage, &cpinfo) != 0)
+ goto break_break;
+ }
+ if (tolower((unsigned char)*s++) != tolower((unsigned char)*d++))
+ break;
+ }
}
+ d = cp_name;
+ if (tolower((unsigned char)d[0]) == 'c' &&
+ tolower((unsigned char)d[1]) == 'p')
+ d += 2;
+ if (tolower((unsigned char)d[0]) == 'i' &&
+ tolower((unsigned char)d[1]) == 'b' &&
+ tolower((unsigned char)d[2]) == 'm')
+ d += 3;
+ for (s = d; *s >= '0' && *s <= '9'; s++);
+ if (*s == 0 && s != d)
+ codepage = atoi(d); /* CP999 or IBM999 */
+
+ if (codepage == CP_ACP)
+ codepage = GetACP();
+ if (codepage == CP_OEMCP)
+ codepage = GetOEMCP();
+ if (codepage > 65535)
+ codepage = -2;
+
break_break:;
if (codepage != -1) {
if (codepage != CP_UTF8 && codepage < 65536) {