Commit 49bea92b authored by Alexandre Julliard's avatar Alexandre Julliard

wrc: Store language as a simple integer.

parent 234710e8
......@@ -175,7 +175,7 @@ static int parse_accel_string( const string_t *key, int flags )
* 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;
......@@ -183,10 +183,7 @@ static void put_string(const string_t *str, int isterm, const language_t *lang)
{
string_t *newstr;
if (lang) codepage = get_language_codepage( lang->id, lang->sub );
else codepage = get_language_codepage( 0, 0 );
assert( codepage != -1 );
codepage = get_language_codepage( lang );
newstr = convert_string_unicode( 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
*****************************************************************************
*/
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)
{
......@@ -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)
{
if(lvc && lvc->language)
put_word(MAKELANGID(lvc->language->id, lvc->language->sub));
if(lvc)
put_word(lvc->language);
else
put_word(0); /* Neutral */
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_word(type);
put_name_id(name, TRUE, NULL); /* ResName */
put_name_id(name, TRUE, 0); /* ResName */
put_word(memopt); /* Memory options */
tag = output_buffer_pos;
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->height);
if(dlg->menu)
put_name_id(dlg->menu, TRUE, NULL);
put_name_id(dlg->menu, TRUE, 0);
else
put_byte(0);
if(dlg->dlgclass)
put_name_id(dlg->dlgclass, TRUE, NULL);
put_name_id(dlg->dlgclass, TRUE, 0);
else
put_byte(0);
if(dlg->title)
put_string(dlg->title, TRUE, NULL);
put_string(dlg->title, TRUE, 0);
else
put_byte(0);
if(dlg->font)
{
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)
......@@ -496,11 +493,11 @@ static void dialog2res(name_id_t *name, dialog_t *dlg)
&& ctrl->ctlclass->name.i_name <= 0x85)
put_byte(ctrl->ctlclass->name.i_name);
else if(ctrl->ctlclass->type == name_str)
put_name_id(ctrl->ctlclass, FALSE, NULL);
put_name_id(ctrl->ctlclass, FALSE, 0);
else
error("Unknown control-class %04x\n", ctrl->ctlclass->name.i_name);
if(ctrl->title)
put_name_id(ctrl->title, FALSE, NULL);
put_name_id(ctrl->title, FALSE, 0);
else
put_byte(0);
......@@ -517,7 +514,7 @@ static void dialog2res(name_id_t *name, dialog_t *dlg)
* 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;
......@@ -545,7 +542,7 @@ static void menuitem2res(menu_item_t *menitem, const language_t *lang)
* 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;
assert(win32 != 0);
......@@ -604,7 +601,7 @@ static void menu2res(name_id_t *name, menu_t *men)
else /* win16 */
{
put_dword(0); /* Menuheader: Version and HeaderSize */
menuitem2res(men->items, NULL);
menuitem2res(men->items, 0);
}
set_res_size(restag);
}
......@@ -952,8 +949,8 @@ static void user2res(name_id_t *name, user_t *usr)
}
else /* win16 */
{
put_name_id(usr->type, TRUE, NULL);
put_name_id(name, TRUE, NULL); /* ResName */
put_name_id(usr->type, TRUE, 0);
put_name_id(name, TRUE, 0); /* ResName */
put_word(usr->memopt); /* Memory options */
tag = output_buffer_pos;
put_dword(4); /* ResSize overwritten later*/
......@@ -971,7 +968,7 @@ static void user2res(name_id_t *name, user_t *usr)
* 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;
int blksizetag;
......@@ -985,7 +982,7 @@ static void versionblock2res(ver_block_t *blk, int level, const language_t *lang
put_word(0);
if(win32)
put_word(0); /* level ? */
put_string(blk->name, TRUE, NULL);
put_string(blk->name, TRUE, 0);
align_output(4);
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_string(val->key, TRUE, NULL);
put_string(val->key, TRUE, 0);
align_output(4);
tag = output_buffer_pos;
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_string(val->key, TRUE, NULL);
put_string(val->key, TRUE, 0);
align_output(4);
tag = output_buffer_pos;
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);
/* Descend into the blocks */
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_word(rootblocksizetag, output_buffer_pos - rootblocksizetag);
set_res_size(restag);
......
......@@ -185,7 +185,7 @@ ani_any_t *new_ani_any(void)
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));
memset( r, 0, sizeof(*r) );
......@@ -210,20 +210,6 @@ characts_t *new_characts(unsigned int c)
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)
{
if(!v) return NULL;
......@@ -337,10 +323,9 @@ typedef struct {
int id;
} 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;
assert(lan != NULL);
assert(list != 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));
*n = 1;
(*list)[0].lan = *lan;
(*list)[0].lan = lan;
(*list)[0].id = 1;
return 1;
}
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);
}
*list = xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
(*list)[*n].lan = *lan;
(*list)[*n].lan = lan;
(*list)[*n].id = 1;
*n += 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 int nid = 0;
......@@ -374,7 +359,7 @@ static int alloc_icon_id(language_t *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 int nid = 0;
......
......@@ -42,11 +42,9 @@ res_count_t *new_res_count(void);
string_t *new_string(void);
toolbar_item_t *new_toolbar_item(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);
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);
characts_t *dup_characts(characts_t *c);
html_t *new_html(raw_data_t *rd, int *memopt);
......
......@@ -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 *int2raw_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 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);
......@@ -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 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_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_class(name_id_t *n, 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;
name_id_t *nid;
font_id_t *fntid;
language_t *lan;
language_t lan;
version_t *ver;
characts_t *chars;
event_t *event;
......@@ -388,8 +388,7 @@ resources
while(rsc)
{
if(rsc->type == head->type
&& rsc->lan->id == head->lan->id
&& rsc->lan->sub == head->lan->sub
&& rsc->lan == head->lan
&& !compare_name_id(rsc->name, head->name)
&& (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
{
......@@ -503,12 +502,11 @@ resource
if(!win32)
parser_warning("LANGUAGE not supported in 16-bit mode\n");
free(currentlanguage);
if (get_language_codepage($3, $5) == -1)
yyerror( "Language %04x is not supported", ($5<<10) + $3);
currentlanguage = new_language($3, $5);
currentlanguage = MAKELANGID($3, $5);
if (get_language_codepage(currentlanguage) == -1)
yyerror( "Language %04x is not supported", currentlanguage);
$$ = 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);
free($3);
}
if(!$$->lvc.language)
$$->lvc.language = dup_language(currentlanguage);
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -807,8 +804,7 @@ dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
$$->style->or_mask &= ~($$->style->and_mask);
$$->style->and_mask = 0;
if(!$$->lvc.language)
$$->lvc.language = dup_language(currentlanguage);
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -1023,8 +1019,7 @@ dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_att
$$->style->or_mask &= ~($$->style->and_mask);
$$->style->and_mask = 0;
if(!$$->lvc.language)
$$->lvc.language = dup_language(currentlanguage);
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -1200,8 +1195,7 @@ menu : tMENU loadmemopts opt_lvc menu_body {
$$->lvc = *($3);
free($3);
}
if(!$$->lvc.language)
$$->lvc.language = dup_language(currentlanguage);
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -1276,8 +1270,7 @@ menuex : tMENUEX loadmemopts opt_lvc menuex_body {
$$->lvc = *($3);
free($3);
}
if(!$$->lvc.language)
$$->lvc.language = dup_language(currentlanguage);
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -1492,7 +1485,7 @@ versioninfo
$$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
$$->blocks = get_ver_block_head($5);
/* 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);
free($6);
}
if(!$$->lvc.language)
{
$$->lvc.language = dup_language(currentlanguage);
}
if(!$$->lvc.language) $$->lvc.language = currentlanguage;
}
;
......@@ -1730,9 +1720,9 @@ opt_lvc : /* Empty */ { $$ = new_lvc(); }
* The conflict is now moved to the expression handling below.
*/
opt_language
: tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
if (get_language_codepage($2, $4) == -1)
yyerror( "Language %04x is not supported", ($4<<10) + $2);
: tLANGUAGE expr ',' expr { $$ = MAKELANGID($2, $4);
if (get_language_codepage($$) == -1)
yyerror( "Language %04x is not supported", $$);
}
;
......@@ -1753,7 +1743,7 @@ raw_data: opt_lvc tBEGIN raw_elements tEND {
}
if(!$3->lvc.language)
$3->lvc.language = dup_language(currentlanguage);
$3->lvc.language = currentlanguage;
$$ = $3;
}
......@@ -1775,7 +1765,7 @@ raw_elements
;
/* File data or raw data */
file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
file_raw: filename { $$ = load_file($1,currentlanguage); }
| raw_data { $$ = $1; }
;
......@@ -1896,7 +1886,7 @@ static dialog_t *dialog_menu(name_id_t *m, dialog_t *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);
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 */
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;
char *path, *name;
......@@ -2334,12 +2324,11 @@ static stringtable_t *find_stringtable(lvc_t *lvc)
assert(lvc != NULL);
if(!lvc->language)
lvc->language = dup_language(currentlanguage);
lvc->language = currentlanguage;
for(stt = sttres; stt; stt = stt->next)
{
if(stt->lvc.language->id == lvc->language->id
&& stt->lvc.language->sub == lvc->language->sub)
if(stt->lvc.language == lvc->language)
{
/* Found a table with the same language */
/* The version and characteristics are now handled
......@@ -2640,7 +2629,7 @@ static resource_t *build_fontdirs(resource_t *tail)
{
if(!fnt[j])
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];
nlanfnt++;
......@@ -2670,7 +2659,7 @@ static resource_t *build_fontdirs(resource_t *tail)
fnt[i] = NULL;
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;
}
}
......
......@@ -673,15 +673,15 @@ static const struct lang2cp lang2cps[] =
{ 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;
int cp = -1, defcp = -1;
for (i = 0; i < ARRAY_SIZE(lang2cps); i++)
{
if (lang2cps[i].lang != lang) continue;
if (lang2cps[i].sublang == sublang)
if (lang2cps[i].lang != PRIMARYLANGID(lang)) continue;
if (lang2cps[i].sublang == SUBLANGID(lang))
{
cp = lang2cps[i].cp;
break;
......
......@@ -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 );
void free_string( string_t *str );
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);
#endif
......@@ -109,8 +109,8 @@ int extensions = 1;
/*
* Language setting for resources (-l option)
*/
static language_t *defaultlanguage;
language_t *currentlanguage = NULL;
static language_t defaultlanguage;
language_t currentlanguage = 0;
/*
* 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 */
currentlanguage = dup_language( defaultlanguage );
currentlanguage = defaultlanguage;
check_utf8 = 1;
/* Go from .rc to .res */
......@@ -288,7 +288,6 @@ static int load_file( const char *input_name, const char *output_name )
unlink( temp_name );
temp_name = NULL;
}
free( currentlanguage );
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);
break;
case 'l':
{
int lan;
lan = strtol(optarg, NULL, 0);
if (get_language_codepage(PRIMARYLANGID(lan), SUBLANGID(lan)) == -1)
error("Language %04x is not supported\n", lan);
defaultlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
}
break;
defaultlanguage = strtol(optarg, NULL, 0);
if (get_language_codepage( defaultlanguage ) == -1)
error("Language %04x is not supported\n", defaultlanguage);
break;
case 'm':
if (!strcmp( optarg, "16" )) win32 = 0;
else win32 = 1;
......@@ -474,10 +469,6 @@ int main(int argc,char *argv[])
(debuglevel & DEBUGLEVEL_PPTRACE) != 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);
for (i = 0; i < input_files.count; i++)
......
......@@ -48,7 +48,7 @@ extern int line_number;
extern int char_number;
extern resource_t *resource_top;
extern language_t *currentlanguage;
extern language_t currentlanguage;
void write_pot_file( const char *outname );
void write_po_files( const char *outname );
......
......@@ -102,17 +102,12 @@ typedef struct name_id {
enum name_e type;
} name_id_t;
/* Language definitions */
typedef struct language {
int id;
int sub;
} language_t;
typedef unsigned int language_t;
typedef unsigned int characts_t;
typedef unsigned int version_t;
typedef struct lvc {
language_t *language;
language_t language;
version_t *version;
characts_t *characts;
} lvc_t;
......@@ -555,7 +550,7 @@ typedef struct resource {
struct resource *prev;
enum res_e type;
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 {
accelerator_t *acc;
ani_curico_t *ani;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment