From 78ef8cf44348f99c929679d5ca32c3c70bd42b8d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 8 Feb 2022 18:01:38 +0100 Subject: [PATCH] wrc: Use compare_name_id() for resource translations. Signed-off-by: Alexandre Julliard --- tools/wrc/translation.c | 26 +++++----------------- tools/wrc/utils.c | 48 ++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/tools/wrc/translation.c b/tools/wrc/translation.c index eb0047c10b5..831daba2b85 100644 --- a/tools/wrc/translation.c +++ b/tools/wrc/translation.c @@ -274,18 +274,12 @@ static int compare_cursor_group(cursor_group_t *cursor_group1, cursor_group_t *c static int compare_control(control_t *control1, control_t *control2) { int different = 0; - char *nameid = NULL; int ignore_style; if(((control1 && !control2) || (!control1 && control2))) different = 1; if(different || !control1 || !control2) return different; - nameid = strdup(get_nameid_str(control1->ctlclass)); - if(strcmp(nameid, get_nameid_str(control2->ctlclass))) - different = 1; - free(nameid); - if (different) - return different; + if (compare_name_id( control1->ctlclass, control2->ctlclass )) return 1; /* allow the translators to set some styles */ ignore_style = 0; @@ -324,7 +318,6 @@ static int compare_control(control_t *control1, control_t *control2) { static int compare_dialog(dialog_t *dialog1, dialog_t *dialog2) { int different = 0; - char *nameid = NULL; control_t *ctrl1, *ctrl2; if(((dialog1->memopt != dialog2->memopt) || (dialog1->lvc.version != dialog2->lvc.version) || @@ -355,14 +348,9 @@ static int compare_dialog(dialog_t *dialog1, dialog_t *dialog2) { ((dialog1->gothelpid && !dialog2->gothelpid) || (!dialog1->gothelpid && dialog2->gothelpid))) different = 1; - nameid = strdup(get_nameid_str(dialog1->menu)); - if(!different && strcmp(nameid, get_nameid_str(dialog2->menu))) - different = 1; - free(nameid); - nameid = strdup(get_nameid_str(dialog1->dlgclass)); - if(!different && strcmp(nameid, get_nameid_str(dialog2->dlgclass))) - different = 1; - free(nameid); + + if (!different && compare_name_id( dialog1->menu, dialog2->menu )) return 1; + if (!different && compare_name_id( dialog1->dlgclass, dialog2->dlgclass )) return 1; ctrl1 = dialog1->controls; ctrl2 = dialog2->controls; @@ -570,15 +558,11 @@ static int compare_stringtable(stringtable_t *stringtable1, stringtable_t *strin static int compare_user(user_t *user1, user_t *user2) { int different = 0; - char *nameid = NULL; if(((user1->memopt != user2->memopt) || (user1->data->lvc.version != user2->data->lvc.version) || (user1->data->lvc.characts != user2->data->lvc.characts))) different = 1; - nameid = strdup(get_nameid_str(user1->type)); - if(!different && strcmp(nameid, get_nameid_str(user2->type))) - different = 1; - free(nameid); + if (!different) different = compare_name_id( user1->type, user2->type ); return different; } diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c index b37bb226319..647505f50f4 100644 --- a/tools/wrc/utils.c +++ b/tools/wrc/utils.c @@ -153,6 +153,19 @@ int compare_striW( const WCHAR *str1, const WCHAR *str2 ) } } +int compare_striAW( const char *str1, const WCHAR *str2 ) +{ + for (;;) + { + /* only the A-Z range is case-insensitive */ + WCHAR ch1 = (*str1 >= 'a' && *str1 <= 'z') ? *str1 + 'A' - 'a' : (unsigned char)*str1; + WCHAR ch2 = (*str2 >= 'a' && *str2 <= 'z') ? *str2 + 'A' - 'a' : *str2; + if (!ch1 || ch1 != ch2) return ch1 - ch2; + str1++; + str2++; + } +} + /* ***************************************************************************** * Function : compare_name_id @@ -165,30 +178,21 @@ int compare_striW( const WCHAR *str1, const WCHAR *str2 ) */ int compare_name_id(const name_id_t *n1, const name_id_t *n2) { - switch (n1->type) - { - case name_ord: - if (n2->type == name_ord) return n1->name.i_name - n2->name.i_name; - return 1; + if (n1->type != n2->type) return n1->type == name_ord ? 1 : -1; + if (n1->type == name_ord) return n1->name.i_name - n2->name.i_name; - case name_str: - if (n2->type == name_str) - { - if(n1->name.s_name->type == str_char - && n2->name.s_name->type == str_char) - { - return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr); - } - else - { - assert( n1->name.s_name->type == str_unicode ); - assert( n2->name.s_name->type == str_unicode ); - return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr); - } - } - return -1; + if (n1->name.s_name->type == str_char) + { + if (n2->name.s_name->type == str_char) + return compare_striA(n1->name.s_name->str.cstr, n2->name.s_name->str.cstr); + return compare_striAW(n1->name.s_name->str.cstr, n2->name.s_name->str.wstr); + } + else + { + if (n2->name.s_name->type == str_char) + return -compare_striAW(n2->name.s_name->str.cstr, n1->name.s_name->str.wstr); + return compare_striW(n1->name.s_name->str.wstr, n2->name.s_name->str.wstr); } - return 0; /* Keep the compiler happy */ } #ifdef _WIN32