wmc: Always output resource strings in Unicode format.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-02-06 18:08:52 +01:00
parent ccfabb323b
commit f504135e38
7 changed files with 66 additions and 161 deletions

View File

@ -188,14 +188,6 @@ const language_t *find_language(unsigned id)
#ifdef _WIN32 #ifdef _WIN32
static BOOL CALLBACK proc( char *cp )
{
CPINFOEXA info;
GetCPInfoExA( atoi(cp), 0, &info );
printf("%-5s %s\n", cp, info.CodePageName );
return TRUE;
}
int is_valid_codepage(int id) int is_valid_codepage(int id)
{ {
return IsValidCodePage( id ); return IsValidCodePage( id );
@ -206,11 +198,6 @@ int wmc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *d
return MultiByteToWideChar( codepage, flags, src, srclen, dst, dstlen ); return MultiByteToWideChar( codepage, flags, src, srclen, dst, dstlen );
} }
int wmc_wcstombs( int codepage, int flags, const WCHAR *src, int srclen, char *dst, int dstlen )
{
return WideCharToMultiByte( codepage, flags, src, srclen, dst, dstlen, NULL, NULL );
}
#else /* _WIN32 */ #else /* _WIN32 */
#include "wine/unicode.h" #include "wine/unicode.h"
@ -225,9 +212,4 @@ int wmc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *d
return wine_cp_mbstowcs( wine_cp_get_table( codepage ), flags, src, srclen, dst, dstlen ); return wine_cp_mbstowcs( wine_cp_get_table( codepage ), flags, src, srclen, dst, dstlen );
} }
int wmc_wcstombs( int codepage, int flags, const WCHAR *src, int srclen, char *dst, int dstlen )
{
return wine_cp_wcstombs( wine_cp_get_table( codepage ), flags, src, srclen, dst, dstlen, NULL, NULL );
}
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@ -34,6 +34,5 @@ void show_languages(void);
const language_t *find_language(unsigned id); const language_t *find_language(unsigned id);
int is_valid_codepage(int id); int is_valid_codepage(int id);
int wmc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *dst, int dstlen ); int wmc_mbstowcs( int codepage, int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
int wmc_wcstombs( int codepage, int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
#endif #endif

View File

@ -590,7 +590,7 @@ static lan_blk_t *block_messages(node_t *head)
int nmsg = 0; int nmsg = 0;
int i; int i;
int nl; int nl;
int factor = unicodeout ? 2 : 1; int factor = 2;
for(ndp = head; ndp; ndp = ndp->next) for(ndp = head; ndp; ndp = ndp->next)
{ {

View File

@ -93,11 +93,6 @@ int pedantic = 0;
*/ */
int unicodein = 0; int unicodein = 0;
/*
* Unicode output (-U option)
*/
int unicodeout = 0;
/* /*
* Inline the messagetables (don't write *.bin files; -i option) * Inline the messagetables (don't write *.bin files; -i option)
*/ */
@ -249,8 +244,7 @@ int main(int argc,char *argv[])
case 'u': case 'u':
unicodein = 1; unicodein = 1;
break; break;
case 'U': case 'U': /* ignored for backwards compatibility */
unicodeout = 1;
break; break;
case 'v': case 'v':
show_languages(); show_languages();
@ -295,7 +289,6 @@ int main(int argc,char *argv[])
else if (output_name && strendswith( output_name, ".pot" )) output_format = FORMAT_POT; else if (output_name && strendswith( output_name, ".pot" )) output_format = FORMAT_POT;
else output_format = FORMAT_RC; else output_format = FORMAT_RC;
} }
if (output_format == FORMAT_RES) unicodeout = 1;
/* Generate appropriate outfile names */ /* Generate appropriate outfile names */
if(!output_name) if(!output_name)

View File

@ -42,7 +42,6 @@ extern int byteorder;
extern int decimal; extern int decimal;
extern int custombit; extern int custombit;
extern int unicodein; extern int unicodein;
extern int unicodeout;
extern int rcinline; extern int rcinline;
extern char *output_name; extern char *output_name;

View File

@ -59,10 +59,8 @@ gettext convention, in particular in must contain one \fI.po\fR file for
each language, and a LINGUAS file listing the available languages. each language, and a LINGUAS file listing the available languages.
.TP .TP
.B \-u .B \-u
Assume that the inputfile is in unicode. Assume that the input file is in Unicode or UTF-8 format and skip
.TP codepage conversions.
.B \-U
Write resource output in unicode formatted messagetable(s).
.TP .TP
.B \-v .B \-v
Show all supported codepages and languages. Show all supported codepages and languages.

View File

@ -306,15 +306,13 @@ static void write_rcbin(FILE *fp)
} }
} }
static char *make_string(WCHAR *uc, int len, int codepage) static char *make_string(WCHAR *uc, int len)
{ {
char *str = xmalloc(7*len + 1); char *str = xmalloc(7*len + 12);
char *cptr = str; char *cptr = str;
int i; int i;
int b; int b;
if (!codepage || codepage == CP_UTF8)
{
*cptr++ = ' '; *cptr++ = ' ';
*cptr++ = 'L'; *cptr++ = 'L';
*cptr++ = '"'; *cptr++ = '"';
@ -339,7 +337,7 @@ static char *make_string(WCHAR *uc, int len, int codepage)
} }
else else
{ {
int n = sprintf(cptr, "\\x%04x", *uc & 0xffff); int n = sprintf(cptr, "\\x%04x", *uc);
cptr += n; cptr += n;
b += n; b += n;
} }
@ -356,10 +354,7 @@ static char *make_string(WCHAR *uc, int len, int codepage)
b = 0; b = 0;
} }
} }
if (unicodeout)
len = (len + 1) & ~1; len = (len + 1) & ~1;
else
len = (len + 3) & ~3;
for(; i < len; i++) for(; i < len; i++)
{ {
*cptr++ = '\\'; *cptr++ = '\\';
@ -371,65 +366,6 @@ static char *make_string(WCHAR *uc, int len, int codepage)
} }
*cptr++ = '"'; *cptr++ = '"';
*cptr = '\0'; *cptr = '\0';
}
else
{
char *tmp, *cc;
int unilen = unistrlen(uc) + 1;
cc = tmp = xmalloc( unilen * 2 );
wmc_wcstombs( codepage, 0, uc, unilen, cptr, unilen * 2 );
*cptr++ = ' ';
*cptr++ = '"';
for(i = b = 0; i < len; i++, cc++)
{
switch(*cc)
{
case '\a': *cptr++ = '\\'; *cptr++ = 'a'; b += 2; break;
case '\b': *cptr++ = '\\'; *cptr++ = 'b'; b += 2; break;
case '\f': *cptr++ = '\\'; *cptr++ = 'f'; b += 2; break;
case '\n': *cptr++ = '\\'; *cptr++ = 'n'; b += 2; break;
case '\r': *cptr++ = '\\'; *cptr++ = 'r'; b += 2; break;
case '\t': *cptr++ = '\\'; *cptr++ = 't'; b += 2; break;
case '\v': *cptr++ = '\\'; *cptr++ = 'v'; b += 2; break;
case '\\': *cptr++ = '\\'; *cptr++ = '\\'; b += 2; break;
case '"': *cptr++ = '\\'; *cptr++ = '"'; b += 2; break;
default:
if(isprint(*cc))
{
*cptr++ = *cc;
b++;
}
else
{
int n = sprintf(cptr, "\\x%02x", *cc & 0xff);
cptr += n;
b += n;
}
break;
}
if(i < len-1 && b >= 72)
{
*cptr++ = '"';
*cptr++ = ',';
*cptr++ = '\n';
*cptr++ = ' ';
*cptr++ = '"';
b = 0;
}
}
len = (len + 3) & ~3;
for(; i < len; i++)
{
*cptr++ = '\\';
*cptr++ = 'x';
*cptr++ = '0';
*cptr++ = '0';
}
*cptr++ = '"';
*cptr = '\0';
free(tmp);
}
return str; return str;
} }
@ -462,11 +398,9 @@ static void write_rcinline(FILE *fp)
char *cptr; char *cptr;
int l = blk->msgs[j]->len; int l = blk->msgs[j]->len;
const char *comma = j == blk->nmsg-1 && i == lbp->nblk-1 ? "" : ","; const char *comma = j == blk->nmsg-1 && i == lbp->nblk-1 ? "" : ",";
cptr = make_string(blk->msgs[j]->msg, l, unicodeout ? 0 : blk->msgs[j]->cp); cptr = make_string(blk->msgs[j]->msg, l);
fprintf(fp, "\n /* Msg 0x%08x */ 0x%04x, 0x000%c,\n", fprintf(fp, "\n /* Msg 0x%08x */ 0x%04x, 0x0001,\n",
blk->idlo + j, blk->idlo + j, ((l * 2 + 3) & ~3) + 4 );
(unicodeout ? (l*2+3)&~3 : (l+3)&~3) + 4,
unicodeout ? '1' : '0');
fprintf(fp, "%s%s\n", cptr, comma); fprintf(fp, "%s%s\n", cptr, comma);
free(cptr); free(cptr);
} }