wmc: Add support for utf-8 codepage.

This commit is contained in:
Alexandre Julliard 2009-07-10 13:03:09 +02:00
parent 2bfdff198c
commit 52f81c12db
3 changed files with 22 additions and 12 deletions

View File

@ -155,7 +155,7 @@ void set_codepage(int cp)
{
codepage = cp;
codepage_def = find_codepage(codepage);
if(!codepage_def)
if(!codepage_def && codepage != CP_UTF8)
xyyerror("Codepage %d not found; cannot process\n", codepage);
}
@ -200,8 +200,10 @@ try_again:
xyyerror(err_fatalread);
else if(!cptr)
return 0;
assert(codepage_def != NULL);
n = wine_cp_mbstowcs(codepage_def, 0, xlatebuffer, strlen(xlatebuffer)+1, inputbuffer, INPUTBUFFER_SIZE);
if (codepage_def)
n = wine_cp_mbstowcs(codepage_def, 0, xlatebuffer, strlen(xlatebuffer)+1, inputbuffer, INPUTBUFFER_SIZE);
else
n = wine_utf8_mbstowcs(0, xlatebuffer, strlen(xlatebuffer)+1, inputbuffer, INPUTBUFFER_SIZE);
if(n < 0)
internal_error(__FILE__, __LINE__, "Could not translate to unicode (%d)\n", n);
if(n <= 1)

View File

@ -251,12 +251,12 @@ cmaps : cmap
;
cmap : clan '=' tNUMBER ':' tNUMBER {
static const char err_nocp[] = "Codepage %d not builtin; cannot convert";
static const char err_nocp[] = "Codepage %d not builtin; cannot convert\n";
if(find_cpxlat($1))
xyyerror("Codepage translation already defined for language 0x%x\n", $1);
if($3 && !find_codepage($3))
if($3 && $3 != CP_UTF8 && !find_codepage($3))
xyyerror(err_nocp, $3);
if($5 && !find_codepage($5))
if($5 && $5 != CP_UTF8 && !find_codepage($5))
xyyerror(err_nocp, $5);
add_cpxlat($1, $3, $5);
}

View File

@ -100,11 +100,17 @@ static char *dup_u2c(int cp, const WCHAR *uc)
int len;
char *cptr;
const union cptable *cpdef = find_codepage(cp);
if(!cpdef)
internal_error(__FILE__, __LINE__, "Codepage %d not found (vanished?)\n", cp);
len = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, NULL, 0, NULL, NULL);
if(cpdef)
len = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, NULL, 0, NULL, NULL);
else
len = wine_utf8_wcstombs(0, uc, unistrlen(uc)+1, NULL, 0);
cptr = xmalloc(len);
if((len = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, cptr, len, NULL, NULL)) < 0)
if (cpdef)
len = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, cptr, len, NULL, NULL);
else
len = wine_utf8_wcstombs(0, uc, unistrlen(uc)+1, cptr, len);
if (len < 0)
internal_error(__FILE__, __LINE__, "Buffer overflow? code %d\n", len);
return cptr;
}
@ -385,8 +391,10 @@ static char *make_string(WCHAR *uc, int len, int codepage)
int mlen;
const union cptable *cpdef = find_codepage(codepage);
assert(cpdef != NULL);
mlen = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, NULL, 0, NULL, NULL);
if (cpdef)
mlen = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, NULL, 0, NULL, NULL);
else
mlen = wine_utf8_wcstombs(0, uc, unistrlen(uc)+1, NULL, 0);
cc = tmp = xmalloc(mlen);
if((i = wine_cp_wcstombs(cpdef, 0, uc, unistrlen(uc)+1, tmp, mlen, NULL, NULL)) < 0)
internal_error(__FILE__, __LINE__, "Buffer overflow? code %d\n", i);