Alexandre Julliard : wrc: Export the convert_string_utf8() helper function.
Alexandre Julliard
julliard at winehq.org
Fri Feb 7 15:41:07 CST 2020
Module: wine
Branch: master
Commit: 20459500965c446df0b57f60555d08cb8f4007dd
URL: https://source.winehq.org/git/wine.git/?a=commit;h=20459500965c446df0b57f60555d08cb8f4007dd
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Feb 7 08:34:03 2020 +0100
wrc: Export the convert_string_utf8() helper function.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
tools/wrc/parser.y | 22 ++++++++++------------
tools/wrc/po.c | 16 +++-------------
tools/wrc/utils.c | 8 ++++++++
tools/wrc/utils.h | 1 +
4 files changed, 22 insertions(+), 25 deletions(-)
diff --git a/tools/wrc/parser.y b/tools/wrc/parser.y
index 4c2f22ac0d..f5666a0399 100644
--- a/tools/wrc/parser.y
+++ b/tools/wrc/parser.y
@@ -2161,19 +2161,17 @@ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
static raw_data_t *load_file(string_t *filename, language_t *lang)
{
FILE *fp = NULL;
- char *path;
+ char *path, *name;
raw_data_t *rd;
- string_t *name;
- int codepage = get_language_codepage(lang->id, lang->sub);
-
- /* FIXME: we may want to use utf-8 here */
- if (codepage <= 0 && filename->type != str_char)
- yyerror("Cannot convert filename to ASCII string");
- name = convert_string( filename, str_char, codepage );
- if (!(path = wpp_find_include(name->str.cstr, input_name)))
- yyerror("Cannot open file %s", name->str.cstr);
+
+ if (filename->type == str_unicode)
+ name = convert_string_utf8( filename, 0 );
+ else
+ name = xstrdup( filename->str.cstr );
+ if (!(path = wpp_find_include(name, input_name)))
+ yyerror("Cannot open file %s", name);
if (!(fp = fopen( path, "rb" )))
- yyerror("Cannot open file %s", name->str.cstr);
+ yyerror("Cannot open file %s", name);
free( path );
rd = new_raw_data();
fseek(fp, 0, SEEK_END);
@@ -2187,7 +2185,7 @@ static raw_data_t *load_file(string_t *filename, language_t *lang)
else rd->data = NULL;
fclose(fp);
rd->lvc.language = lang;
- free_string(name);
+ free(name);
return rd;
}
diff --git a/tools/wrc/po.c b/tools/wrc/po.c
index 3f5affd49f..726bed393f 100644
--- a/tools/wrc/po.c
+++ b/tools/wrc/po.c
@@ -557,14 +557,6 @@ static void po_xerror2( int severity, po_message_t message1,
static const struct po_xerror_handler po_xerror_handler = { po_xerror, po_xerror2 };
-static string_t *convert_string_utf8( const string_t *str, int codepage )
-{
- string_t *wstr = convert_string( str, str_unicode, codepage );
- string_t *ustr = convert_string( wstr, str_char, CP_UTF8 );
- free_string( wstr );
- return ustr;
-}
-
static po_message_t find_message( po_file_t po, const char *msgid, const char *msgctxt,
po_message_iterator_t *iterator )
{
@@ -589,8 +581,7 @@ static void add_po_string( po_file_t po, const string_t *msgid, const string_t *
po_message_t msg;
po_message_iterator_t iterator;
int codepage;
- string_t *str_buffer = NULL;
- char *id, *id_buffer, *context, *str = NULL;
+ char *id, *id_buffer, *context, *str = NULL, *str_buffer = NULL;
if (!msgid->size) return;
@@ -608,8 +599,7 @@ static void add_po_string( po_file_t po, const string_t *msgid, const string_t *
if (lang) codepage = get_language_codepage( lang->id, lang->sub );
else codepage = get_language_codepage( 0, 0 );
assert( codepage != -1 );
- str_buffer = convert_string_utf8( msgstr, codepage );
- str = str_buffer->str.cstr;
+ str = str_buffer = convert_string_utf8( msgstr, codepage );
if (is_english( lang )) get_message_context( &str );
}
if (!(msg = find_message( po, id, context, &iterator )))
@@ -623,7 +613,7 @@ static void add_po_string( po_file_t po, const string_t *msgid, const string_t *
if (msgid->loc.file) po_message_add_filepos( msg, msgid->loc.file, msgid->loc.line );
po_message_iterator_free( iterator );
free( id_buffer );
- if (str_buffer) free_string( str_buffer );
+ free( str_buffer );
}
struct po_file_lang
diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c
index 15bbde9d74..6ec1fe7b66 100644
--- a/tools/wrc/utils.c
+++ b/tools/wrc/utils.c
@@ -503,6 +503,14 @@ string_t *convert_string(const string_t *str, enum str_e type, int codepage)
return ret;
}
+char *convert_string_utf8( const string_t *str, int codepage )
+{
+ int len;
+ string_t *wstr = convert_string( str, str_unicode, codepage );
+ char *ret = unicode_to_utf8( wstr->str.wstr, wstr->size, &len );
+ free_string( wstr );
+ return ret;
+}
void free_string(string_t *str)
{
diff --git a/tools/wrc/utils.h b/tools/wrc/utils.h
index 15dfacdd47..f5d3385c55 100644
--- a/tools/wrc/utils.h
+++ b/tools/wrc/utils.h
@@ -47,6 +47,7 @@ void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
char *dup_basename(const char *name, const char *ext);
int compare_name_id(const name_id_t *n1, const name_id_t *n2);
string_t *convert_string(const string_t *str, enum str_e type, int codepage);
+char *convert_string_utf8( const string_t *str, int codepage );
void free_string( string_t *str );
int check_valid_utf8( const string_t *str, int codepage );
int check_unicode_conversion( const string_t *str_a, const string_t *str_w, int codepage );
More information about the wine-cvs
mailing list