wrc: Export the convert_string_utf8() helper function.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-02-07 08:34:03 +01:00
parent 499d772cb6
commit 2045950096
4 changed files with 21 additions and 24 deletions

View File

@ -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) static raw_data_t *load_file(string_t *filename, language_t *lang)
{ {
FILE *fp = NULL; FILE *fp = NULL;
char *path; char *path, *name;
raw_data_t *rd; 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 (filename->type == str_unicode)
if (codepage <= 0 && filename->type != str_char) name = convert_string_utf8( filename, 0 );
yyerror("Cannot convert filename to ASCII string"); else
name = convert_string( filename, str_char, codepage ); name = xstrdup( filename->str.cstr );
if (!(path = wpp_find_include(name->str.cstr, input_name))) if (!(path = wpp_find_include(name, input_name)))
yyerror("Cannot open file %s", name->str.cstr); yyerror("Cannot open file %s", name);
if (!(fp = fopen( path, "rb" ))) if (!(fp = fopen( path, "rb" )))
yyerror("Cannot open file %s", name->str.cstr); yyerror("Cannot open file %s", name);
free( path ); free( path );
rd = new_raw_data(); rd = new_raw_data();
fseek(fp, 0, SEEK_END); 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; else rd->data = NULL;
fclose(fp); fclose(fp);
rd->lvc.language = lang; rd->lvc.language = lang;
free_string(name); free(name);
return rd; return rd;
} }

View File

@ -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 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, static po_message_t find_message( po_file_t po, const char *msgid, const char *msgctxt,
po_message_iterator_t *iterator ) 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_t msg;
po_message_iterator_t iterator; po_message_iterator_t iterator;
int codepage; int codepage;
string_t *str_buffer = NULL; char *id, *id_buffer, *context, *str = NULL, *str_buffer = NULL;
char *id, *id_buffer, *context, *str = NULL;
if (!msgid->size) return; 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 ); if (lang) codepage = get_language_codepage( lang->id, lang->sub );
else codepage = get_language_codepage( 0, 0 ); else codepage = get_language_codepage( 0, 0 );
assert( codepage != -1 ); assert( codepage != -1 );
str_buffer = convert_string_utf8( msgstr, codepage ); str = str_buffer = convert_string_utf8( msgstr, codepage );
str = str_buffer->str.cstr;
if (is_english( lang )) get_message_context( &str ); if (is_english( lang )) get_message_context( &str );
} }
if (!(msg = find_message( po, id, context, &iterator ))) 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 ); if (msgid->loc.file) po_message_add_filepos( msg, msgid->loc.file, msgid->loc.line );
po_message_iterator_free( iterator ); po_message_iterator_free( iterator );
free( id_buffer ); free( id_buffer );
if (str_buffer) free_string( str_buffer ); free( str_buffer );
} }
struct po_file_lang struct po_file_lang

View File

@ -503,6 +503,14 @@ string_t *convert_string(const string_t *str, enum str_e type, int codepage)
return ret; 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) void free_string(string_t *str)
{ {

View File

@ -47,6 +47,7 @@ void chat(const char *s, ...) __attribute__((format (printf, 1, 2)));
char *dup_basename(const char *name, const char *ext); char *dup_basename(const char *name, const char *ext);
int compare_name_id(const name_id_t *n1, const name_id_t *n2); 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); 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 ); void free_string( string_t *str );
int check_valid_utf8( const string_t *str, int codepage ); 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 ); int check_unicode_conversion( const string_t *str_a, const string_t *str_w, int codepage );