Module: wine Branch: master Commit: 442243257b949a11f7d1f7e83954b8a5c9d84d4c URL: http://source.winehq.org/git/wine.git/?a=commit;h=442243257b949a11f7d1f7e839...
Author: Alexandre Julliard julliard@winehq.org Date: Tue Jan 9 22:21:53 2007 +0100
wrc: Added support for utf-8 codepage.
---
tools/wrc/parser.l | 3 ++- tools/wrc/utils.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/tools/wrc/parser.l b/tools/wrc/parser.l index 11d110f..f9034a5 100644 --- a/tools/wrc/parser.l +++ b/tools/wrc/parser.l @@ -347,12 +347,13 @@ static struct keyword *iskeyword(char *k <pp_pragma>[^\n]* yy_pop_state(); if (pedantic) parser_warning("Unrecognized #pragma directive '%s'",yytext);
<pp_code_page>({ws}*default{ws}*)[^\n]* current_codepage = -1; yy_pop_state(); +<pp_code_page>({ws}*utf8{ws}*)[^\n]* current_codepage = CP_UTF8; yy_pop_state(); <pp_code_page>({ws}*[0-9]+{ws}*)[^\n]* { char *p = yytext; yy_pop_state(); while (*p < '0' || *p > '9') p++; current_codepage = strtol( p, NULL, 10 ); - if (current_codepage && !wine_cp_get_table( current_codepage )) + if (current_codepage && current_codepage != CP_UTF8 && !wine_cp_get_table( current_codepage )) { parser_error("Codepage %d not supported", current_codepage); current_codepage = 0; diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c index 2e1630d..9e736d4 100644 --- a/tools/wrc/utils.c +++ b/tools/wrc/utils.c @@ -244,26 +244,38 @@ string_t *convert_string(const string_t { const union cptable *cptable = codepage ? wine_cp_get_table( codepage ) : NULL; string_t *ret = xmalloc(sizeof(*ret)); + int res;
- if (!cptable && str->type != type) - error( "Current language is Unicode only, cannot convert strings" ); + if (!codepage && str->type != type) + parser_error( "Current language is Unicode only, cannot convert string" );
if((str->type == str_char) && (type == str_unicode)) { - ret->type = str_unicode; - ret->size = wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, NULL, 0 ); + ret->type = str_unicode; + ret->size = cptable ? wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, NULL, 0 ) + : wine_utf8_mbstowcs( 0, str->str.cstr, str->size, NULL, 0 ); ret->str.wstr = xmalloc( (ret->size+1) * sizeof(WCHAR) ); - wine_cp_mbstowcs( cptable, 0, str->str.cstr, str->size, ret->str.wstr, ret->size ); + if (cptable) + res = wine_cp_mbstowcs( cptable, MB_ERR_INVALID_CHARS, str->str.cstr, str->size, + ret->str.wstr, ret->size ); + else + res = wine_utf8_mbstowcs( MB_ERR_INVALID_CHARS, str->str.cstr, str->size, + ret->str.wstr, ret->size ); + if (res == -2) + parser_error( "Invalid character in string '%.*s' for codepage %u\n", + str->size, str->str.cstr, codepage ); ret->str.wstr[ret->size] = 0; } else if((str->type == str_unicode) && (type == str_char)) { - ret->type = str_char; - ret->size = wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, - NULL, 0, NULL, NULL ); + ret->type = str_char; + ret->size = cptable ? wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, NULL, 0, NULL, NULL ) + : wine_utf8_wcstombs( str->str.wstr, str->size, NULL, 0 ); ret->str.cstr = xmalloc( ret->size + 1 ); - wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, ret->str.cstr, ret->size, - NULL, NULL ); + if (cptable) + wine_cp_wcstombs( cptable, 0, str->str.wstr, str->size, ret->str.cstr, ret->size, NULL, NULL ); + else + wine_utf8_wcstombs( str->str.wstr, str->size, ret->str.cstr, ret->size ); ret->str.cstr[ret->size] = 0; } else if(str->type == str_unicode)