wrc: Store language as a simple integer.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2022-04-01 12:58:10 +02:00
parent 234710e8f7
commit 49bea92bdc
10 changed files with 120 additions and 165 deletions

View File

@ -175,7 +175,7 @@ static int parse_accel_string( const string_t *key, int flags )
* size member) * size member)
***************************************************************************** *****************************************************************************
*/ */
static void put_string(const string_t *str, int isterm, const language_t *lang) static void put_string(const string_t *str, int isterm, language_t lang)
{ {
int cnt, codepage; int cnt, codepage;
@ -183,10 +183,7 @@ static void put_string(const string_t *str, int isterm, const language_t *lang)
{ {
string_t *newstr; string_t *newstr;
if (lang) codepage = get_language_codepage( lang->id, lang->sub ); codepage = get_language_codepage( lang );
else codepage = get_language_codepage( 0, 0 );
assert( codepage != -1 );
newstr = convert_string_unicode( str, codepage ); newstr = convert_string_unicode( str, codepage );
if (str->type == str_char && check_valid_utf8( str, codepage )) if (str->type == str_char && check_valid_utf8( str, codepage ))
{ {
@ -223,7 +220,7 @@ static void put_string(const string_t *str, int isterm, const language_t *lang)
* Function : put_name_id * Function : put_name_id
***************************************************************************** *****************************************************************************
*/ */
static void put_name_id(name_id_t *nid, int upcase, const language_t *lang) static void put_name_id(name_id_t *nid, int upcase, language_t lang)
{ {
switch (nid->type) switch (nid->type)
{ {
@ -249,8 +246,8 @@ static void put_name_id(name_id_t *nid, int upcase, const language_t *lang)
*/ */
static void put_lvc(lvc_t *lvc) static void put_lvc(lvc_t *lvc)
{ {
if(lvc && lvc->language) if(lvc)
put_word(MAKELANGID(lvc->language->id, lvc->language->sub)); put_word(lvc->language);
else else
put_word(0); /* Neutral */ put_word(0); /* Neutral */
if(lvc && lvc->version) if(lvc && lvc->version)
@ -296,7 +293,7 @@ static int put_res_header(int type, name_id_t *name, unsigned int memopt, lvc_t
{ {
put_byte(0xff); /* ResType */ put_byte(0xff); /* ResType */
put_word(type); put_word(type);
put_name_id(name, TRUE, NULL); /* ResName */ put_name_id(name, TRUE, 0); /* ResName */
put_word(memopt); /* Memory options */ put_word(memopt); /* Memory options */
tag = output_buffer_pos; tag = output_buffer_pos;
put_dword(4); /* ResSize overwritten later*/ put_dword(4); /* ResSize overwritten later*/
@ -466,21 +463,21 @@ static void dialog2res(name_id_t *name, dialog_t *dlg)
put_word(dlg->width); put_word(dlg->width);
put_word(dlg->height); put_word(dlg->height);
if(dlg->menu) if(dlg->menu)
put_name_id(dlg->menu, TRUE, NULL); put_name_id(dlg->menu, TRUE, 0);
else else
put_byte(0); put_byte(0);
if(dlg->dlgclass) if(dlg->dlgclass)
put_name_id(dlg->dlgclass, TRUE, NULL); put_name_id(dlg->dlgclass, TRUE, 0);
else else
put_byte(0); put_byte(0);
if(dlg->title) if(dlg->title)
put_string(dlg->title, TRUE, NULL); put_string(dlg->title, TRUE, 0);
else else
put_byte(0); put_byte(0);
if(dlg->font) if(dlg->font)
{ {
put_word(dlg->font->size); put_word(dlg->font->size);
put_string(dlg->font->name, TRUE, NULL); put_string(dlg->font->name, TRUE, 0);
} }
for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next) for (ctrl = dlg->controls; ctrl; ctrl = ctrl->next)
@ -496,11 +493,11 @@ static void dialog2res(name_id_t *name, dialog_t *dlg)
&& ctrl->ctlclass->name.i_name <= 0x85) && ctrl->ctlclass->name.i_name <= 0x85)
put_byte(ctrl->ctlclass->name.i_name); put_byte(ctrl->ctlclass->name.i_name);
else if(ctrl->ctlclass->type == name_str) else if(ctrl->ctlclass->type == name_str)
put_name_id(ctrl->ctlclass, FALSE, NULL); put_name_id(ctrl->ctlclass, FALSE, 0);
else else
error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name); error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
if(ctrl->title) if(ctrl->title)
put_name_id(ctrl->title, FALSE, NULL); put_name_id(ctrl->title, FALSE, 0);
else else
put_byte(0); put_byte(0);
@ -517,7 +514,7 @@ static void dialog2res(name_id_t *name, dialog_t *dlg)
* Remarks : Self recursive * Remarks : Self recursive
***************************************************************************** *****************************************************************************
*/ */
static void menuitem2res(menu_item_t *menitem, const language_t *lang) static void menuitem2res(menu_item_t *menitem, language_t lang)
{ {
menu_item_t *itm = menitem; menu_item_t *itm = menitem;
@ -545,7 +542,7 @@ static void menuitem2res(menu_item_t *menitem, const language_t *lang)
* Remarks : Self recursive * Remarks : Self recursive
***************************************************************************** *****************************************************************************
*/ */
static void menuexitem2res(menu_item_t *menitem, const language_t *lang) static void menuexitem2res(menu_item_t *menitem, language_t lang)
{ {
menu_item_t *itm = menitem; menu_item_t *itm = menitem;
assert(win32 != 0); assert(win32 != 0);
@ -604,7 +601,7 @@ static void menu2res(name_id_t *name, menu_t *men)
else /* win16 */ else /* win16 */
{ {
put_dword(0); /* Menuheader: Version and HeaderSize */ put_dword(0); /* Menuheader: Version and HeaderSize */
menuitem2res(men->items, NULL); menuitem2res(men->items, 0);
} }
set_res_size(restag); set_res_size(restag);
} }
@ -952,8 +949,8 @@ static void user2res(name_id_t *name, user_t *usr)
} }
else /* win16 */ else /* win16 */
{ {
put_name_id(usr->type, TRUE, NULL); put_name_id(usr->type, TRUE, 0);
put_name_id(name, TRUE, NULL); /* ResName */ put_name_id(name, TRUE, 0); /* ResName */
put_word(usr->memopt); /* Memory options */ put_word(usr->memopt); /* Memory options */
tag = output_buffer_pos; tag = output_buffer_pos;
put_dword(4); /* ResSize overwritten later*/ put_dword(4); /* ResSize overwritten later*/
@ -971,7 +968,7 @@ static void user2res(name_id_t *name, user_t *usr)
* Remarks : Self recursive * Remarks : Self recursive
***************************************************************************** *****************************************************************************
*/ */
static void versionblock2res(ver_block_t *blk, int level, const language_t *lang) static void versionblock2res(ver_block_t *blk, int level, language_t lang)
{ {
ver_value_t *val; ver_value_t *val;
int blksizetag; int blksizetag;
@ -985,7 +982,7 @@ static void versionblock2res(ver_block_t *blk, int level, const language_t *lang
put_word(0); put_word(0);
if(win32) if(win32)
put_word(0); /* level ? */ put_word(0); /* level ? */
put_string(blk->name, TRUE, NULL); put_string(blk->name, TRUE, 0);
align_output(4); align_output(4);
for(val = blk->values; val; val = val->next) for(val = blk->values; val; val = val->next)
{ {
@ -1000,7 +997,7 @@ static void versionblock2res(ver_block_t *blk, int level, const language_t *lang
{ {
put_word(level); put_word(level);
} }
put_string(val->key, TRUE, NULL); put_string(val->key, TRUE, 0);
align_output(4); align_output(4);
tag = output_buffer_pos; tag = output_buffer_pos;
put_string(val->value.str, TRUE, lang); put_string(val->value.str, TRUE, lang);
@ -1020,7 +1017,7 @@ static void versionblock2res(ver_block_t *blk, int level, const language_t *lang
{ {
put_word(level); put_word(level);
} }
put_string(val->key, TRUE, NULL); put_string(val->key, TRUE, 0);
align_output(4); align_output(4);
tag = output_buffer_pos; tag = output_buffer_pos;
for(i = 0; i < val->value.words->nwords; i++) for(i = 0; i < val->value.words->nwords; i++)
@ -1089,7 +1086,7 @@ static void versioninfo2res(name_id_t *name, versioninfo_t *ver)
set_word(valsizetag, output_buffer_pos - tag); set_word(valsizetag, output_buffer_pos - tag);
/* Descend into the blocks */ /* Descend into the blocks */
for(blk = ver->blocks; blk; blk = blk->next) for(blk = ver->blocks; blk; blk = blk->next)
versionblock2res(blk, 0, win32 ? ver->lvc.language : NULL); versionblock2res(blk, 0, win32 ? ver->lvc.language : 0);
/* Set root block's size */ /* Set root block's size */
set_word(rootblocksizetag, output_buffer_pos - rootblocksizetag); set_word(rootblocksizetag, output_buffer_pos - rootblocksizetag);
set_res_size(restag); set_res_size(restag);

View File

@ -185,7 +185,7 @@ ani_any_t *new_ani_any(void)
return ret; return ret;
} }
resource_t *new_resource(enum res_e t, void *res, int memopt, language_t *lan) resource_t *new_resource(enum res_e t, void *res, int memopt, language_t lan)
{ {
resource_t *r = xmalloc(sizeof(resource_t)); resource_t *r = xmalloc(sizeof(resource_t));
memset( r, 0, sizeof(*r) ); memset( r, 0, sizeof(*r) );
@ -210,20 +210,6 @@ characts_t *new_characts(unsigned int c)
return cp; return cp;
} }
language_t *new_language(int id, int sub)
{
language_t *lan = xmalloc(sizeof(language_t));
lan->id = id;
lan->sub = sub;
return lan;
}
language_t *dup_language(language_t *l)
{
if(!l) return NULL;
return new_language(l->id, l->sub);
}
version_t *dup_version(version_t *v) version_t *dup_version(version_t *v)
{ {
if(!v) return NULL; if(!v) return NULL;
@ -337,10 +323,9 @@ typedef struct {
int id; int id;
} id_alloc_t; } id_alloc_t;
static int get_new_id(id_alloc_t **list, int *n, language_t *lan) static int get_new_id(id_alloc_t **list, int *n, language_t lan)
{ {
int i; int i;
assert(lan != NULL);
assert(list != NULL); assert(list != NULL);
assert(n != NULL); assert(n != NULL);
@ -348,25 +333,25 @@ static int get_new_id(id_alloc_t **list, int *n, language_t *lan)
{ {
*list = xmalloc(sizeof(id_alloc_t)); *list = xmalloc(sizeof(id_alloc_t));
*n = 1; *n = 1;
(*list)[0].lan = *lan; (*list)[0].lan = lan;
(*list)[0].id = 1; (*list)[0].id = 1;
return 1; return 1;
} }
for(i = 0; i < *n; i++) for(i = 0; i < *n; i++)
{ {
if((*list)[i].lan.id == lan->id && (*list)[i].lan.sub == lan->sub) if((*list)[i].lan == lan)
return ++((*list)[i].id); return ++((*list)[i].id);
} }
*list = xrealloc(*list, sizeof(id_alloc_t) * (*n+1)); *list = xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
(*list)[*n].lan = *lan; (*list)[*n].lan = lan;
(*list)[*n].id = 1; (*list)[*n].id = 1;
*n += 1; *n += 1;
return 1; return 1;
} }
static int alloc_icon_id(language_t *lan) static int alloc_icon_id(language_t lan)
{ {
static id_alloc_t *idlist = NULL; static id_alloc_t *idlist = NULL;
static int nid = 0; static int nid = 0;
@ -374,7 +359,7 @@ static int alloc_icon_id(language_t *lan)
return get_new_id(&idlist, &nid, lan); return get_new_id(&idlist, &nid, lan);
} }
static int alloc_cursor_id(language_t *lan) static int alloc_cursor_id(language_t lan)
{ {
static id_alloc_t *idlist = NULL; static id_alloc_t *idlist = NULL;
static int nid = 0; static int nid = 0;

View File

@ -42,11 +42,9 @@ res_count_t *new_res_count(void);
string_t *new_string(void); string_t *new_string(void);
toolbar_item_t *new_toolbar_item(void); toolbar_item_t *new_toolbar_item(void);
ani_any_t *new_ani_any(void); ani_any_t *new_ani_any(void);
resource_t *new_resource(enum res_e t, void *res, int memopt, language_t *lan); resource_t *new_resource(enum res_e t, void *res, int memopt, language_t lan);
version_t *new_version(unsigned int v); version_t *new_version(unsigned int v);
characts_t *new_characts(unsigned int c); characts_t *new_characts(unsigned int c);
language_t *new_language(int id, int sub);
language_t *dup_language(language_t *l);
version_t *dup_version(version_t *v); version_t *dup_version(version_t *v);
characts_t *dup_characts(characts_t *c); characts_t *dup_characts(characts_t *c);
html_t *new_html(raw_data_t *rd, int *memopt); html_t *new_html(raw_data_t *rd, int *memopt);

View File

@ -174,7 +174,7 @@ static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
static raw_data_t *str2raw_data(string_t *str); static raw_data_t *str2raw_data(string_t *str);
static raw_data_t *int2raw_data(int i); static raw_data_t *int2raw_data(int i);
static raw_data_t *long2raw_data(int i); static raw_data_t *long2raw_data(int i);
static raw_data_t *load_file(string_t *name, language_t *lang); static raw_data_t *load_file(string_t *name, language_t lang);
static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid); static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev); static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
static event_t *add_event(int key, int id, int flags, event_t *prev); static event_t *add_event(int key, int id, int flags, event_t *prev);
@ -182,7 +182,7 @@ static name_id_t *convert_ctlclass(name_id_t *cls);
static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev); static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
static dialog_t *dialog_version(version_t *v, dialog_t *dlg); static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg); static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
static dialog_t *dialog_language(language_t *l, dialog_t *dlg); static dialog_t *dialog_language(language_t l, dialog_t *dlg);
static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg); static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg); static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg); static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
@ -227,7 +227,7 @@ static int rsrcid_to_token(int lookahead);
control_t *ctl; control_t *ctl;
name_id_t *nid; name_id_t *nid;
font_id_t *fntid; font_id_t *fntid;
language_t *lan; language_t lan;
version_t *ver; version_t *ver;
characts_t *chars; characts_t *chars;
event_t *event; event_t *event;
@ -388,8 +388,7 @@ resources
while(rsc) while(rsc)
{ {
if(rsc->type == head->type if(rsc->type == head->type
&& rsc->lan->id == head->lan->id && rsc->lan == head->lan
&& rsc->lan->sub == head->lan->sub
&& !compare_name_id(rsc->name, head->name) && !compare_name_id(rsc->name, head->name)
&& (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type))) && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
{ {
@ -503,12 +502,11 @@ resource
if(!win32) if(!win32)
parser_warning("LANGUAGE not supported in 16-bit mode\n"); parser_warning("LANGUAGE not supported in 16-bit mode\n");
free(currentlanguage); currentlanguage = MAKELANGID($3, $5);
if (get_language_codepage($3, $5) == -1) if (get_language_codepage(currentlanguage) == -1)
yyerror( "Language %04x is not supported", ($5<<10) + $3); yyerror( "Language %04x is not supported", currentlanguage);
currentlanguage = new_language($3, $5);
$$ = NULL; $$ = NULL;
chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3); chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, currentlanguage);
} }
; ;
@ -744,8 +742,7 @@ accelerators
$$->lvc = *($3); $$->lvc = *($3);
free($3); free($3);
} }
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
$$->lvc.language = dup_language(currentlanguage);
} }
; ;
@ -807,8 +804,7 @@ dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
$$->style->or_mask &= ~($$->style->and_mask); $$->style->or_mask &= ~($$->style->and_mask);
$$->style->and_mask = 0; $$->style->and_mask = 0;
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
$$->lvc.language = dup_language(currentlanguage);
} }
; ;
@ -1023,8 +1019,7 @@ dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_att
$$->style->or_mask &= ~($$->style->and_mask); $$->style->or_mask &= ~($$->style->and_mask);
$$->style->and_mask = 0; $$->style->and_mask = 0;
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
$$->lvc.language = dup_language(currentlanguage);
} }
; ;
@ -1200,8 +1195,7 @@ menu : tMENU loadmemopts opt_lvc menu_body {
$$->lvc = *($3); $$->lvc = *($3);
free($3); free($3);
} }
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
$$->lvc.language = dup_language(currentlanguage);
} }
; ;
@ -1276,8 +1270,7 @@ menuex : tMENUEX loadmemopts opt_lvc menuex_body {
$$->lvc = *($3); $$->lvc = *($3);
free($3); free($3);
} }
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
$$->lvc.language = dup_language(currentlanguage);
} }
; ;
@ -1492,7 +1485,7 @@ versioninfo
$$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0); $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
$$->blocks = get_ver_block_head($5); $$->blocks = get_ver_block_head($5);
/* Set language; there is no version or characteristics */ /* Set language; there is no version or characteristics */
$$->lvc.language = dup_language(currentlanguage); $$->lvc.language = currentlanguage;
} }
; ;
@ -1627,10 +1620,7 @@ toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
$$->lvc = *($6); $$->lvc = *($6);
free($6); free($6);
} }
if(!$$->lvc.language) if(!$$->lvc.language) $$->lvc.language = currentlanguage;
{
$$->lvc.language = dup_language(currentlanguage);
}
} }
; ;
@ -1730,9 +1720,9 @@ opt_lvc : /* Empty */ { $$ = new_lvc(); }
* The conflict is now moved to the expression handling below. * The conflict is now moved to the expression handling below.
*/ */
opt_language opt_language
: tLANGUAGE expr ',' expr { $$ = new_language($2, $4); : tLANGUAGE expr ',' expr { $$ = MAKELANGID($2, $4);
if (get_language_codepage($2, $4) == -1) if (get_language_codepage($$) == -1)
yyerror( "Language %04x is not supported", ($4<<10) + $2); yyerror( "Language %04x is not supported", $$);
} }
; ;
@ -1753,7 +1743,7 @@ raw_data: opt_lvc tBEGIN raw_elements tEND {
} }
if(!$3->lvc.language) if(!$3->lvc.language)
$3->lvc.language = dup_language(currentlanguage); $3->lvc.language = currentlanguage;
$$ = $3; $$ = $3;
} }
@ -1775,7 +1765,7 @@ raw_elements
; ;
/* File data or raw data */ /* File data or raw data */
file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); } file_raw: filename { $$ = load_file($1,currentlanguage); }
| raw_data { $$ = $1; } | raw_data { $$ = $1; }
; ;
@ -1896,7 +1886,7 @@ static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
return dlg; return dlg;
} }
static dialog_t *dialog_language(language_t *l, dialog_t *dlg) static dialog_t *dialog_language(language_t l, dialog_t *dlg)
{ {
assert(dlg != NULL); assert(dlg != NULL);
if(dlg->lvc.language) if(dlg->lvc.language)
@ -2152,7 +2142,7 @@ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
} }
/* Raw data functions */ /* Raw data functions */
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, *name; char *path, *name;
@ -2334,12 +2324,11 @@ static stringtable_t *find_stringtable(lvc_t *lvc)
assert(lvc != NULL); assert(lvc != NULL);
if(!lvc->language) if(!lvc->language)
lvc->language = dup_language(currentlanguage); lvc->language = currentlanguage;
for(stt = sttres; stt; stt = stt->next) for(stt = sttres; stt; stt = stt->next)
{ {
if(stt->lvc.language->id == lvc->language->id if(stt->lvc.language == lvc->language)
&& stt->lvc.language->sub == lvc->language->sub)
{ {
/* Found a table with the same language */ /* Found a table with the same language */
/* The version and characteristics are now handled /* The version and characteristics are now handled
@ -2640,7 +2629,7 @@ static resource_t *build_fontdirs(resource_t *tail)
{ {
if(!fnt[j]) if(!fnt[j])
continue; continue;
if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub) if(fnt[j]->lan == fnd[i]->lan)
{ {
lanfnt[nlanfnt] = fnt[j]; lanfnt[nlanfnt] = fnt[j];
nlanfnt++; nlanfnt++;
@ -2670,7 +2659,7 @@ static resource_t *build_fontdirs(resource_t *tail)
fnt[i] = NULL; fnt[i] = NULL;
fntleft--; fntleft--;
} }
else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub) else if(fnt[i]->lan == lanfnt[0]->lan)
goto addlanfnt; goto addlanfnt;
} }
} }

View File

@ -52,38 +52,41 @@ struct mo_file
/* ... rest of file data here */ /* ... rest of file data here */
}; };
static int is_english( const language_t *lan ) static int is_english( language_t lan )
{ {
return lan->id == LANG_ENGLISH && lan->sub == SUBLANG_DEFAULT; return lan == MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );
} }
static int is_rtl_language( const language_t *lan ) static int is_rtl_language( language_t lan )
{ {
return lan->id == LANG_ARABIC || lan->id == LANG_HEBREW || lan->id == LANG_PERSIAN; return PRIMARYLANGID(lan) == LANG_ARABIC ||
PRIMARYLANGID(lan) == LANG_HEBREW ||
PRIMARYLANGID(lan) == LANG_PERSIAN;
} }
static int uses_larger_font( const language_t *lan ) static int uses_larger_font( language_t lan )
{ {
return lan->id == LANG_CHINESE || lan->id == LANG_JAPANESE || lan->id == LANG_KOREAN; return PRIMARYLANGID(lan) == LANG_CHINESE ||
PRIMARYLANGID(lan) == LANG_JAPANESE ||
PRIMARYLANGID(lan) == LANG_KOREAN;
} }
static int get_default_sublang( const language_t *lan ) static language_t get_default_sublang( language_t lan )
{ {
if (lan->sub != SUBLANG_NEUTRAL) if (SUBLANGID(lan) != SUBLANG_NEUTRAL) return lan;
return lan->sub;
switch (lan->id) switch (PRIMARYLANGID(lan))
{ {
case LANG_SPANISH: case LANG_SPANISH:
return SUBLANG_SPANISH_MODERN; return MAKELANGID( LANG_SPANISH, SUBLANG_SPANISH_MODERN );
case LANG_CHINESE: case LANG_CHINESE:
return SUBLANG_CHINESE_SIMPLIFIED; return MAKELANGID( LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED );
default: default:
return SUBLANG_DEFAULT; return MAKELANGID( PRIMARYLANGID(lan), SUBLANG_DEFAULT );
} }
} }
static version_t *get_dup_version( language_t *lang ) static version_t *get_dup_version( language_t lang )
{ {
/* English "translations" take precedence over the original rc contents */ /* English "translations" take precedence over the original rc contents */
return new_version( is_english( lang ) ? 1 : -1 ); return new_version( is_english( lang ) ? 1 : -1 );
@ -156,7 +159,7 @@ static int control_has_title( const control_t *ctrl )
return TRUE; return TRUE;
} }
static resource_t *dup_resource( resource_t *res, language_t *lang ) static resource_t *dup_resource( resource_t *res, language_t lang )
{ {
resource_t *new = xmalloc( sizeof(*new) ); resource_t *new = xmalloc( sizeof(*new) );
@ -571,8 +574,7 @@ static po_message_t find_message( po_file_t po, const char *msgid, const char *m
return msg; return msg;
} }
static void add_po_string( po_file_t po, const string_t *msgid, const string_t *msgstr, static void add_po_string( po_file_t po, const string_t *msgid, const string_t *msgstr, language_t lang )
const language_t *lang )
{ {
static const char dnt[] = "do not translate"; static const char dnt[] = "do not translate";
po_message_t msg; po_message_t msg;
@ -593,9 +595,7 @@ static void add_po_string( po_file_t po, const string_t *msgid, const string_t *
if (msgstr) if (msgstr)
{ {
if (lang) codepage = get_language_codepage( lang->id, lang->sub ); codepage = get_language_codepage( lang );
else codepage = get_language_codepage( 0, 0 );
assert( codepage != -1 );
str = str_buffer = convert_string_utf8( msgstr, codepage ); str = str_buffer = convert_string_utf8( msgstr, codepage );
if (is_english( lang )) get_message_context( &str ); if (is_english( lang )) get_message_context( &str );
} }
@ -647,35 +647,35 @@ static po_file_t create_po_file(void)
return po; return po;
} }
static po_file_t get_po_file( const language_t *lang ) static po_file_t get_po_file( language_t lang )
{ {
struct po_file_lang *po_file; struct po_file_lang *po_file;
LIST_FOR_EACH_ENTRY( po_file, &po_file_langs, struct po_file_lang, entry ) LIST_FOR_EACH_ENTRY( po_file, &po_file_langs, struct po_file_lang, entry )
if (po_file->lang.id == lang->id && po_file->lang.sub == lang->sub) return po_file->po; if (po_file->lang == lang) return po_file->po;
/* create a new one */ /* create a new one */
po_file = xmalloc( sizeof(*po_file) ); po_file = xmalloc( sizeof(*po_file) );
po_file->lang = *lang; po_file->lang = lang;
po_file->po = create_po_file(); po_file->po = create_po_file();
list_add_tail( &po_file_langs, &po_file->entry ); list_add_tail( &po_file_langs, &po_file->entry );
return po_file->po; return po_file->po;
} }
static const char *get_language_name( const language_t *lang ) static const char *get_language_name( language_t lang )
{ {
static char name[20]; static char name[20];
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(languages); i++) for (i = 0; i < ARRAY_SIZE(languages); i++)
if (languages[i].id == lang->id && languages[i].sub == lang->sub) if (MAKELANGID( languages[i].id, languages[i].sub ) == lang)
return languages[i].name; return languages[i].name;
sprintf( name, "%02x-%02x", lang->id, lang->sub ); sprintf( name, "%04x", lang );
return name; return name;
} }
static char *get_po_file_name( const language_t *lang ) static char *get_po_file_name( language_t lang )
{ {
return strmake( "%s.po", get_language_name( lang ) ); return strmake( "%s.po", get_language_name( lang ) );
} }
@ -687,7 +687,7 @@ static unsigned int flush_po_files( const char *output_name )
LIST_FOR_EACH_ENTRY_SAFE( po_file, next, &po_file_langs, struct po_file_lang, entry ) LIST_FOR_EACH_ENTRY_SAFE( po_file, next, &po_file_langs, struct po_file_lang, entry )
{ {
char *name = get_po_file_name( &po_file->lang ); char *name = get_po_file_name( po_file->lang );
if (output_name) if (output_name)
{ {
if (!strcmp( get_basename(output_name), name )) if (!strcmp( get_basename(output_name), name ))
@ -718,7 +718,7 @@ static void add_pot_stringtable( po_file_t po, const resource_t *res )
while (stt) while (stt)
{ {
for (i = 0; i < stt->nentries; i++) for (i = 0; i < stt->nentries; i++)
if (stt->entries[i].str) add_po_string( po, stt->entries[i].str, NULL, NULL ); if (stt->entries[i].str) add_po_string( po, stt->entries[i].str, NULL, 0 );
stt = stt->next; stt = stt->next;
} }
} }
@ -744,7 +744,7 @@ static void add_pot_dialog_controls( po_file_t po, const control_t *ctrl )
{ {
while (ctrl) while (ctrl)
{ {
if (control_has_title( ctrl )) add_po_string( po, ctrl->title->name.s_name, NULL, NULL ); if (control_has_title( ctrl )) add_po_string( po, ctrl->title->name.s_name, NULL, 0 );
ctrl = ctrl->next; ctrl = ctrl->next;
} }
} }
@ -753,7 +753,7 @@ static void add_pot_dialog( po_file_t po, const resource_t *res )
{ {
const dialog_t *dlg = res->res.dlg; const dialog_t *dlg = res->res.dlg;
if (dlg->title) add_po_string( po, dlg->title, NULL, NULL ); if (dlg->title) add_po_string( po, dlg->title, NULL, 0 );
add_pot_dialog_controls( po, dlg->controls ); add_pot_dialog_controls( po, dlg->controls );
} }
@ -830,7 +830,7 @@ static void compare_dialogs( const dialog_t *english_dlg, const dialog_t *dlg )
} }
static void add_po_dialog_controls( po_file_t po, const control_t *english_ctrl, static void add_po_dialog_controls( po_file_t po, const control_t *english_ctrl,
const control_t *ctrl, const language_t *lang ) const control_t *ctrl, language_t lang )
{ {
while (english_ctrl && ctrl) while (english_ctrl && ctrl)
{ {
@ -859,7 +859,7 @@ static void add_pot_menu_items( po_file_t po, const menu_item_t *item )
{ {
while (item) while (item)
{ {
if (item->name) add_po_string( po, item->name, NULL, NULL ); if (item->name) add_po_string( po, item->name, NULL, 0 );
if (item->popup) add_pot_menu_items( po, item->popup ); if (item->popup) add_pot_menu_items( po, item->popup );
item = item->next; item = item->next;
} }
@ -871,7 +871,7 @@ static void add_pot_menu( po_file_t po, const resource_t *res )
} }
static void add_po_menu_items( po_file_t po, const menu_item_t *english_item, static void add_po_menu_items( po_file_t po, const menu_item_t *english_item,
const menu_item_t *item, const language_t *lang ) const menu_item_t *item, language_t lang )
{ {
while (english_item && item) while (english_item && item)
{ {
@ -911,7 +911,7 @@ static void add_pot_accel( po_file_t po, const resource_t *res )
{ {
/* accelerators without a context don't make sense in po files */ /* accelerators without a context don't make sense in po files */
if (event->str && string_has_context( event->str )) if (event->str && string_has_context( event->str ))
add_po_string( po, event->str, NULL, NULL ); add_po_string( po, event->str, NULL, 0 );
event = event->next; event = event->next;
} }
} }
@ -1002,7 +1002,7 @@ static void add_pot_versioninfo( po_file_t po, const resource_t *res )
if (!langcharset) return; if (!langcharset) return;
for (val = langcharset->values; val; val = val->next) for (val = langcharset->values; val; val = val->next)
if (version_value_needs_translation( val )) if (version_value_needs_translation( val ))
add_po_string( po, val->value.str, NULL, NULL ); add_po_string( po, val->value.str, NULL, 0 );
} }
static void add_po_versioninfo( const resource_t *english, const resource_t *res ) static void add_po_versioninfo( const resource_t *english, const resource_t *res )
@ -1253,7 +1253,7 @@ static menu_item_t *translate_items( menu_item_t *item, int *found )
return head; return head;
} }
static stringtable_t *translate_stringtable( stringtable_t *stt, language_t *lang, int *found ) static stringtable_t *translate_stringtable( stringtable_t *stt, language_t lang, int *found )
{ {
stringtable_t *new, *head = NULL, *tail = NULL; stringtable_t *new, *head = NULL, *tail = NULL;
int i; int i;
@ -1321,7 +1321,7 @@ static event_t *translate_accel( accelerator_t *acc, accelerator_t *new, int *fo
return head; return head;
} }
static ver_value_t *translate_langcharset_values( ver_value_t *val, language_t *lang, int *found ) static ver_value_t *translate_langcharset_values( ver_value_t *val, language_t lang, int *found )
{ {
ver_value_t *new_val, *head = NULL, *tail = NULL; ver_value_t *new_val, *head = NULL, *tail = NULL;
while (val) while (val)
@ -1340,16 +1340,16 @@ static ver_value_t *translate_langcharset_values( ver_value_t *val, language_t *
return head; return head;
} }
static ver_value_t *translate_stringfileinfo( ver_value_t *val, language_t *lang, int *found ) static ver_value_t *translate_stringfileinfo( ver_value_t *val, language_t lang, int *found )
{ {
int i; int i;
ver_value_t *new_val, *head = NULL, *tail = NULL; ver_value_t *new_val, *head = NULL, *tail = NULL;
const char *english_block_name[2] = { "040904b0", "040904e4" }; const char *english_block_name[2] = { "040904b0", "040904e4" };
char *block_name[2]; char *block_name[2];
int langid = MAKELANGID( lang->id, get_default_sublang( lang ) ); language_t langid = get_default_sublang( lang );
block_name[0] = strmake( "%04x%04x", langid, 1200 ); block_name[0] = strmake( "%04x%04x", langid, 1200 );
block_name[1] = strmake( "%04x%04x", langid, get_language_codepage( lang->id, lang->sub ) ); block_name[1] = strmake( "%04x%04x", langid, get_language_codepage( lang ));
while (val) while (val)
{ {
@ -1400,7 +1400,7 @@ static ver_value_t *translate_stringfileinfo( ver_value_t *val, language_t *lang
return head; return head;
} }
static ver_value_t *translate_varfileinfo( ver_value_t *val, language_t *lang ) static ver_value_t *translate_varfileinfo( ver_value_t *val, language_t lang )
{ {
ver_value_t *new_val, *head = NULL, *tail = NULL; ver_value_t *new_val, *head = NULL, *tail = NULL;
@ -1416,13 +1416,13 @@ static ver_value_t *translate_varfileinfo( ver_value_t *val, language_t *lang )
val->value.words->words[0] == MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US )) val->value.words->words[0] == MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ))
{ {
ver_words_t *new_words; ver_words_t *new_words;
int langid, codepage; int codepage;
langid = MAKELANGID( lang->id, get_default_sublang( lang ) ); language_t langid = get_default_sublang( lang );
new_words = new_ver_words( langid ); new_words = new_ver_words( langid );
if (val->value.words->words[1] == 1200) if (val->value.words->words[1] == 1200)
codepage = 1200; codepage = 1200;
else else
codepage = get_language_codepage( lang->id, lang->sub ); codepage = get_language_codepage( lang );
new_val->value.words = add_ver_words( new_words, codepage ); new_val->value.words = add_ver_words( new_words, codepage );
} }
free( key ); free( key );
@ -1437,7 +1437,7 @@ static ver_value_t *translate_varfileinfo( ver_value_t *val, language_t *lang )
return head; return head;
} }
static ver_block_t *translate_versioninfo( ver_block_t *blk, language_t *lang, int *found ) static ver_block_t *translate_versioninfo( ver_block_t *blk, language_t lang, int *found )
{ {
ver_block_t *new_blk, *head = NULL, *tail = NULL; ver_block_t *new_blk, *head = NULL, *tail = NULL;
char *name; char *name;
@ -1462,7 +1462,7 @@ static ver_block_t *translate_versioninfo( ver_block_t *blk, language_t *lang, i
return head; return head;
} }
static void translate_resources( language_t *lang ) static void translate_resources( language_t lang )
{ {
resource_t *res; resource_t *res;
@ -1526,7 +1526,7 @@ void add_translations( const char *po_dir )
if (!po_dir) /* run through the translation process to remove msg contexts */ if (!po_dir) /* run through the translation process to remove msg contexts */
{ {
translate_resources( new_language( LANG_ENGLISH, SUBLANG_DEFAULT )); translate_resources( MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ));
goto done; goto done;
} }
@ -1552,7 +1552,7 @@ void add_translations( const char *po_dir )
name = strmake( "%s/%s.mo", po_dir, tok ); name = strmake( "%s/%s.mo", po_dir, tok );
load_mo_file( name ); load_mo_file( name );
translate_resources( new_language(languages[i].id, languages[i].sub) ); translate_resources( MAKELANGID( languages[i].id, languages[i].sub ));
free_mo_file(); free_mo_file();
free( name ); free( name );
} }

View File

@ -673,15 +673,15 @@ static const struct lang2cp lang2cps[] =
{ LANG_ZULU, SUBLANG_NEUTRAL, 1252 } { LANG_ZULU, SUBLANG_NEUTRAL, 1252 }
}; };
int get_language_codepage( unsigned short lang, unsigned short sublang ) int get_language_codepage( language_t lang )
{ {
unsigned int i; unsigned int i;
int cp = -1, defcp = -1; int cp = -1, defcp = -1;
for (i = 0; i < ARRAY_SIZE(lang2cps); i++) for (i = 0; i < ARRAY_SIZE(lang2cps); i++)
{ {
if (lang2cps[i].lang != lang) continue; if (lang2cps[i].lang != PRIMARYLANGID(lang)) continue;
if (lang2cps[i].sublang == sublang) if (lang2cps[i].sublang == SUBLANGID(lang))
{ {
cp = lang2cps[i].cp; cp = lang2cps[i].cp;
break; break;

View File

@ -38,7 +38,7 @@ string_t *convert_string_unicode( const string_t *str, int codepage );
char *convert_string_utf8( const string_t *str, 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 get_language_codepage( unsigned short lang, unsigned short sublang ); int get_language_codepage( language_t lang );
int is_valid_codepage(int cp); int is_valid_codepage(int cp);
#endif #endif

View File

@ -109,8 +109,8 @@ int extensions = 1;
/* /*
* Language setting for resources (-l option) * Language setting for resources (-l option)
*/ */
static language_t *defaultlanguage; static language_t defaultlanguage;
language_t *currentlanguage = NULL; language_t currentlanguage = 0;
/* /*
* Set when extra warnings should be generated (-W option) * Set when extra warnings should be generated (-W option)
@ -271,7 +271,7 @@ static int load_file( const char *input_name, const char *output_name )
} }
/* Reset the language */ /* Reset the language */
currentlanguage = dup_language( defaultlanguage ); currentlanguage = defaultlanguage;
check_utf8 = 1; check_utf8 = 1;
/* Go from .rc to .res */ /* Go from .rc to .res */
@ -288,7 +288,6 @@ static int load_file( const char *input_name, const char *output_name )
unlink( temp_name ); unlink( temp_name );
temp_name = NULL; temp_name = NULL;
} }
free( currentlanguage );
return ret; return ret;
} }
@ -376,14 +375,10 @@ static void option_callback( int optc, char *optarg )
else if (strcmp(optarg, "rc")) error("Output format %s not supported.\n", optarg); else if (strcmp(optarg, "rc")) error("Output format %s not supported.\n", optarg);
break; break;
case 'l': case 'l':
{ defaultlanguage = strtol(optarg, NULL, 0);
int lan; if (get_language_codepage( defaultlanguage ) == -1)
lan = strtol(optarg, NULL, 0); error("Language %04x is not supported\n", defaultlanguage);
if (get_language_codepage(PRIMARYLANGID(lan), SUBLANGID(lan)) == -1) break;
error("Language %04x is not supported\n", lan);
defaultlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
}
break;
case 'm': case 'm':
if (!strcmp( optarg, "16" )) win32 = 0; if (!strcmp( optarg, "16" )) win32 = 0;
else win32 = 1; else win32 = 1;
@ -474,10 +469,6 @@ int main(int argc,char *argv[])
(debuglevel & DEBUGLEVEL_PPTRACE) != 0, (debuglevel & DEBUGLEVEL_PPTRACE) != 0,
(debuglevel & DEBUGLEVEL_PPMSG) != 0 ); (debuglevel & DEBUGLEVEL_PPMSG) != 0 );
/* Check if the user set a language, else set default */
if(!defaultlanguage)
defaultlanguage = new_language(0, 0);
atexit(cleanup_files); atexit(cleanup_files);
for (i = 0; i < input_files.count; i++) for (i = 0; i < input_files.count; i++)

View File

@ -48,7 +48,7 @@ extern int line_number;
extern int char_number; extern int char_number;
extern resource_t *resource_top; extern resource_t *resource_top;
extern language_t *currentlanguage; extern language_t currentlanguage;
void write_pot_file( const char *outname ); void write_pot_file( const char *outname );
void write_po_files( const char *outname ); void write_po_files( const char *outname );

View File

@ -102,17 +102,12 @@ typedef struct name_id {
enum name_e type; enum name_e type;
} name_id_t; } name_id_t;
/* Language definitions */ typedef unsigned int language_t;
typedef struct language {
int id;
int sub;
} language_t;
typedef unsigned int characts_t; typedef unsigned int characts_t;
typedef unsigned int version_t; typedef unsigned int version_t;
typedef struct lvc { typedef struct lvc {
language_t *language; language_t language;
version_t *version; version_t *version;
characts_t *characts; characts_t *characts;
} lvc_t; } lvc_t;
@ -555,7 +550,7 @@ typedef struct resource {
struct resource *prev; struct resource *prev;
enum res_e type; enum res_e type;
name_id_t *name; /* resource's name */ name_id_t *name; /* resource's name */
language_t *lan; /* Only used as a sorting key and c-name creation*/ language_t lan; /* Only used as a sorting key and c-name creation*/
union { union {
accelerator_t *acc; accelerator_t *acc;
ani_curico_t *ani; ani_curico_t *ani;