From 865f23b5032171cdcd7221fce381c98f5ce6dd36 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 20 Feb 2016 13:32:33 +0900 Subject: [PATCH] wrc: Avoid locale- or Unicode-dependent case conversions. Signed-off-by: Alexandre Julliard --- tools/wrc/genres.c | 6 ++++-- tools/wrc/parser.l | 2 +- tools/wrc/parser.y | 38 ++++++++++++-------------------------- tools/wrc/utils.c | 29 +++++++++++++++++++++++++++-- tools/wrc/utils.h | 2 ++ 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/tools/wrc/genres.c b/tools/wrc/genres.c index 336e64e6f28..5b7e24c1ad9 100644 --- a/tools/wrc/genres.c +++ b/tools/wrc/genres.c @@ -263,11 +263,13 @@ static void string_to_upper(string_t *str) if(str->type == str_char) { - for (i = 0; i < str->size; i++) str->str.cstr[i] = toupper((unsigned char)str->str.cstr[i]); + for (i = 0; i < str->size; i++) + if (str->str.cstr[i] >= 'a' && str->str.cstr[i] <= 'z') str->str.cstr[i] -= 32; } else if(str->type == str_unicode) { - for (i = 0; i < str->size; i++) str->str.wstr[i] = toupperW(str->str.wstr[i]); + for (i = 0; i < str->size; i++) + if (str->str.wstr[i] >= 'a' && str->str.wstr[i] <= 'z') str->str.wstr[i] -= 32; } else { diff --git a/tools/wrc/parser.l b/tools/wrc/parser.l index 80072b2f54e..32a231b5a2e 100644 --- a/tools/wrc/parser.l +++ b/tools/wrc/parser.l @@ -250,7 +250,7 @@ static struct keyword keywords[] = { static int kw_cmp_func(const void *s1, const void *s2) { int ret; - ret = strcasecmp(KWP(s1)->keyword, KWP(s2)->keyword); + ret = compare_striA(KWP(s1)->keyword, KWP(s2)->keyword); if(!ret && (KWP(s1)->needcase || KWP(s2)->needcase)) return strcmp(KWP(s1)->keyword, KWP(s2)->keyword); else diff --git a/tools/wrc/parser.y b/tools/wrc/parser.y index b41e7d79693..0f73f906b64 100644 --- a/tools/wrc/parser.y +++ b/tools/wrc/parser.y @@ -2072,37 +2072,23 @@ static int get_class_idW(const WCHAR *cc) static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0}; static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0}; - if(!strcmpiW(szBUTTON, cc)) - return CT_BUTTON; - if(!strcmpiW(szCOMBOBOX, cc)) - return CT_COMBOBOX; - if(!strcmpiW(szLISTBOX, cc)) - return CT_LISTBOX; - if(!strcmpiW(szEDIT, cc)) - return CT_EDIT; - if(!strcmpiW(szSTATIC, cc)) - return CT_STATIC; - if(!strcmpiW(szSCROLLBAR, cc)) - return CT_SCROLLBAR; - + if(!compare_striW(szBUTTON, cc)) return CT_BUTTON; + if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX; + if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX; + if(!compare_striW(szEDIT, cc)) return CT_EDIT; + if(!compare_striW(szSTATIC, cc)) return CT_STATIC; + if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR; return -1; } static int get_class_idA(const char *cc) { - if(!strcasecmp("BUTTON", cc)) - return CT_BUTTON; - if(!strcasecmp("COMBOBOX", cc)) - return CT_COMBOBOX; - if(!strcasecmp("LISTBOX", cc)) - return CT_LISTBOX; - if(!strcasecmp("EDIT", cc)) - return CT_EDIT; - if(!strcasecmp("STATIC", cc)) - return CT_STATIC; - if(!strcasecmp("SCROLLBAR", cc)) - return CT_SCROLLBAR; - + if(!compare_striA("BUTTON", cc)) return CT_BUTTON; + if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX; + if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX; + if(!compare_striA("EDIT", cc)) return CT_EDIT; + if(!compare_striA("STATIC", cc)) return CT_STATIC; + if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR; return -1; } diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c index 5360b9522d2..800692a37ef 100644 --- a/tools/wrc/utils.c +++ b/tools/wrc/utils.c @@ -219,6 +219,31 @@ char *xstrdup(const char *str) return strcpy(s, str); } +int compare_striA( const char *str1, const char *str2 ) +{ + for (;;) + { + /* only the A-Z range is case-insensitive */ + char ch1 = (*str1 >= 'a' && *str1 <= 'z') ? *str1 + 'A' - 'a' : *str1; + char ch2 = (*str2 >= 'a' && *str2 <= 'z') ? *str2 + 'A' - 'a' : *str2; + if (!ch1 || ch1 != ch2) return ch1 - ch2; + str1++; + str2++; + } +} + +int compare_striW( const WCHAR *str1, const WCHAR *str2 ) +{ + for (;;) + { + /* only the A-Z range is case-insensitive */ + WCHAR ch1 = (*str1 >= 'a' && *str1 <= 'z') ? *str1 + 'A' - 'a' : *str1; + WCHAR ch2 = (*str2 >= 'a' && *str2 <= 'z') ? *str2 + 'A' - 'a' : *str2; + if (!ch1 || ch1 != ch2) return ch1 - ch2; + str1++; + str2++; + } +} /* ***************************************************************************** @@ -241,12 +266,12 @@ int compare_name_id(const name_id_t *n1, const name_id_t *n2) if(n1->name.s_name->type == str_char && n2->name.s_name->type == str_char) { - return strcasecmp(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr); + return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr); } else if(n1->name.s_name->type == str_unicode && n2->name.s_name->type == str_unicode) { - return strcmpiW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr); + return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr); } else { diff --git a/tools/wrc/utils.h b/tools/wrc/utils.h index 19daa09b3a9..f0e8cd6175e 100644 --- a/tools/wrc/utils.h +++ b/tools/wrc/utils.h @@ -33,6 +33,8 @@ char *xstrdup(const char *str); #define __attribute__(X) #endif +int compare_striA( const char *str1, const char *str2 ); +int compare_striW( const WCHAR *str1, const WCHAR *str2 ); char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 ))); int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));