From 442243257b949a11f7d1f7e83954b8a5c9d84d4c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 9 Jan 2007 22:21:53 +0100 Subject: [PATCH] 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 11d110fa33f..f9034a5451a 100644 --- a/tools/wrc/parser.l +++ b/tools/wrc/parser.l @@ -347,12 +347,13 @@ static struct keyword *iskeyword(char *kw) [^\n]* yy_pop_state(); if (pedantic) parser_warning("Unrecognized #pragma directive '%s'",yytext); \({ws}*default{ws}*\)[^\n]* current_codepage = -1; yy_pop_state(); +\({ws}*utf8{ws}*\)[^\n]* current_codepage = CP_UTF8; yy_pop_state(); \({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 2e1630d4b9f..9e736d47abb 100644 --- a/tools/wrc/utils.c +++ b/tools/wrc/utils.c @@ -244,26 +244,38 @@ string_t *convert_string(const string_t *str, enum str_e type, int codepage) { 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) -- 2.11.4.GIT