X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=binutils%2Frcparse.y;h=3d5cb6049986147dfc26b5bd235ae9d34c7aab75;hb=e6c7cdec063514bb9ffe2a62fb280e5ec676cac0;hp=989fac8d0427e52d30028595c939c63494f724c1;hpb=4a594fce16683232bbb2e239d3e3ebcfcde16d1a;p=binutils-gdb.git diff --git a/binutils/rcparse.y b/binutils/rcparse.y index 989fac8d042..3d5cb604998 100644 --- a/binutils/rcparse.y +++ b/binutils/rcparse.y @@ -1,6 +1,5 @@ %{ /* rcparse.y -- parser for Windows rc files - Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007 - Free Software Foundation, Inc. + Copyright (C) 1997-2016 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. Extended by Kai Tietz, Onevision. @@ -8,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -21,6 +20,7 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + /* This is a parser for Windows rc files. It is based on the parser by Gunther Ebert . */ @@ -78,6 +78,7 @@ static const rc_res_id res_null_text = { 1, {{0, &null_unichar}}}; rc_rcdata_item *rcdata_item; rc_fixed_versioninfo *fixver; rc_ver_info *verinfo; + rc_ver_stringtable *verstringtable; rc_ver_stringinfo *verstring; rc_ver_varinfo *vervar; rc_toolbar_item *toobar_item; @@ -149,6 +150,7 @@ static const rc_res_id res_null_text = { 1, {{0, &null_unichar}}}; %type opt_control_data %type fixedverinfo %type verblocks +%type verstringtables %type vervals %type vertrans %type toolbar_data @@ -159,9 +161,9 @@ static const rc_res_id res_null_text = { 1, {{0, &null_unichar}}}; %type numexpr posnumexpr cnumexpr optcnumexpr cposnumexpr %type acc_options acc_option menuitem_flags menuitem_flag %type file_name -%type res_unicode_string resname +%type res_unicode_string resname res_unicode_string_concat %type sizedstring -%type sizedunistring +%type sizedunistring res_unicode_sizedstring res_unicode_sizedstring_concat %type sizednumexpr sizedposnumexpr %left '|' @@ -442,7 +444,7 @@ exstyle: styles: /* empty */ - | styles CAPTION res_unicode_string + | styles CAPTION res_unicode_string_concat { dialog.style |= WS_CAPTION; style |= WS_CAPTION; @@ -461,11 +463,11 @@ styles: { dialog.exstyle = $3; } - | styles CLASS res_unicode_string + | styles CLASS res_unicode_string_concat { res_unistring_to_id (& dialog.class, $3); } - | styles FONT numexpr ',' res_unicode_string + | styles FONT numexpr ',' res_unicode_string_concat { dialog.style |= DS_SETFONT; style |= DS_SETFONT; @@ -478,7 +480,7 @@ styles: dialog.ex->charset = 1; } } - | styles FONT numexpr ',' res_unicode_string cnumexpr + | styles FONT numexpr ',' res_unicode_string_concat cnumexpr { dialog.style |= DS_SETFONT; style |= DS_SETFONT; @@ -493,7 +495,7 @@ styles: dialog.ex->charset = 1; } } - | styles FONT numexpr ',' res_unicode_string cnumexpr cnumexpr + | styles FONT numexpr ',' res_unicode_string_concat cnumexpr cnumexpr { dialog.style |= DS_SETFONT; style |= DS_SETFONT; @@ -508,7 +510,7 @@ styles: dialog.ex->charset = 1; } } - | styles FONT numexpr ',' res_unicode_string cnumexpr cnumexpr cnumexpr + | styles FONT numexpr ',' res_unicode_string_concat cnumexpr cnumexpr cnumexpr { dialog.style |= DS_SETFONT; style |= DS_SETFONT; @@ -560,7 +562,7 @@ control: base_style = BS_AUTO3STATE; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -572,7 +574,7 @@ control: base_style = BS_AUTOCHECKBOX; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -584,7 +586,7 @@ control: base_style = BS_AUTORADIOBUTTON; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -596,7 +598,7 @@ control: base_style = ES_LEFT | WS_BORDER | WS_TABSTOP; class.named = 0; class.u.id = CTL_EDIT; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -611,7 +613,7 @@ control: base_style = BS_CHECKBOX | WS_TABSTOP; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -625,7 +627,7 @@ control: base_style = 0; class.named = 0; class.u.id = CTL_COMBOBOX; - res_text_field = res_null_text; + res_text_field = res_null_text; } control_params { @@ -657,7 +659,7 @@ control: base_style = SS_CENTER; class.named = 0; class.u.id = CTL_STATIC; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -669,7 +671,7 @@ control: base_style = BS_DEFPUSHBUTTON | WS_TABSTOP; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -681,7 +683,7 @@ control: base_style = ES_LEFT | WS_BORDER | WS_TABSTOP; class.named = 0; class.u.id = CTL_EDIT; - res_text_field = res_null_text; + res_text_field = res_null_text; } control_params { @@ -693,7 +695,7 @@ control: base_style = BS_GROUPBOX; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -705,7 +707,7 @@ control: base_style = ES_LEFT | WS_BORDER | WS_TABSTOP; class.named = 0; class.u.id = CTL_EDIT; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -743,7 +745,7 @@ control: base_style = ES_LEFT | WS_BORDER | WS_TABSTOP; class.named = 0; class.u.id = CTL_EDIT; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -758,7 +760,7 @@ control: base_style = LBS_NOTIFY | WS_BORDER; class.named = 0; class.u.id = CTL_LISTBOX; - res_text_field = res_null_text; + res_text_field = res_null_text; } control_params { @@ -770,7 +772,7 @@ control: base_style = SS_LEFT; class.named = 0; class.u.id = CTL_STATIC; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -793,7 +795,7 @@ control: base_style = BS_PUSHBUTTON | WS_TABSTOP; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -805,7 +807,7 @@ control: base_style = BS_RADIOBUTTON; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -817,7 +819,7 @@ control: base_style = SS_RIGHT; class.named = 0; class.u.id = CTL_STATIC; - res_text_field = $2; + res_text_field = $2; } control_params { @@ -829,7 +831,7 @@ control: base_style = 0; class.named = 0; class.u.id = CTL_SCROLLBAR; - res_text_field = res_null_text; + res_text_field = res_null_text; } control_params { @@ -841,14 +843,14 @@ control: base_style = BS_3STATE; class.named = 0; class.u.id = CTL_BUTTON; - res_text_field = $2; + res_text_field = $2; } control_params { $$ = $4; } | USERBUTTON resref numexpr ',' numexpr ',' numexpr ',' - numexpr ',' numexpr ',' + numexpr ',' numexpr ',' { style = WS_CHILD | WS_VISIBLE; } styleexpr optcnumexpr { @@ -925,7 +927,7 @@ resid: $$.named = 0; $$.u.id = $1; } - | res_unicode_string + | res_unicode_string_concat { $$.named = 1; $$.u.n.name = $1; @@ -1032,7 +1034,7 @@ menuitems: ; menuitem: - MENUITEM res_unicode_string cnumexpr menuitem_flags + MENUITEM res_unicode_string_concat cnumexpr menuitem_flags { $$ = define_menuitem ($2, $3, $4, 0, 0, NULL); } @@ -1040,7 +1042,7 @@ menuitem: { $$ = define_menuitem (NULL, 0, 0, 0, 0, NULL); } - | POPUP res_unicode_string menuitem_flags BEG menuitems END + | POPUP res_unicode_string_concat menuitem_flags BEG menuitems END { $$ = define_menuitem ($2, 0, $3, 0, 0, $5); } @@ -1122,15 +1124,15 @@ menuexitems: ; menuexitem: - MENUITEM res_unicode_string + MENUITEM res_unicode_string_concat { $$ = define_menuitem ($2, 0, 0, 0, 0, NULL); } - | MENUITEM res_unicode_string cnumexpr + | MENUITEM res_unicode_string_concat cnumexpr { $$ = define_menuitem ($2, $3, 0, 0, 0, NULL); } - | MENUITEM res_unicode_string cnumexpr cnumexpr optcnumexpr + | MENUITEM res_unicode_string_concat cnumexpr cnumexpr optcnumexpr { $$ = define_menuitem ($2, $3, $4, $5, 0, NULL); } @@ -1138,19 +1140,19 @@ menuexitem: { $$ = define_menuitem (NULL, 0, 0, 0, 0, NULL); } - | POPUP res_unicode_string BEG menuexitems END + | POPUP res_unicode_string_concat BEG menuexitems END { $$ = define_menuitem ($2, 0, 0, 0, 0, $4); } - | POPUP res_unicode_string cnumexpr BEG menuexitems END + | POPUP res_unicode_string_concat cnumexpr BEG menuexitems END { $$ = define_menuitem ($2, $3, 0, 0, 0, $5); } - | POPUP res_unicode_string cnumexpr cnumexpr BEG menuexitems END + | POPUP res_unicode_string_concat cnumexpr cnumexpr BEG menuexitems END { $$ = define_menuitem ($2, $3, $4, 0, 0, $6); } - | POPUP res_unicode_string cnumexpr cnumexpr cnumexpr optcnumexpr + | POPUP res_unicode_string_concat cnumexpr cnumexpr cnumexpr optcnumexpr BEG menuexitems END { $$ = define_menuitem ($2, $3, $4, $5, $6, $8); @@ -1247,32 +1249,37 @@ rcdata_data: $1.last->next = ri; $$.last = ri; } + | rcdata_data ',' + { + $$=$1; + } ; /* Stringtable resources. */ stringtable: - STRINGTABLE suboptions BEG - { sub_res_info = $2; } - string_data END + STRINGTABLE suboptions BEG + { sub_res_info = $2; rcparse_rcdata (); } + string_data END { rcparse_normal (); } ; string_data: /* empty */ - | string_data numexpr res_unicode_string + | string_data numexpr res_unicode_sizedstring_concat { - define_stringtable (&sub_res_info, $2, $3); - if (yychar != YYEMPTY) - YYERROR; + define_stringtable (&sub_res_info, $2, $3.s, $3.length); rcparse_discard_strings (); } - | string_data numexpr ',' res_unicode_string + | string_data numexpr ',' res_unicode_sizedstring_concat { - define_stringtable (&sub_res_info, $2, $4); - if (yychar != YYEMPTY) - YYERROR; + define_stringtable (&sub_res_info, $2, $4.s, $4.length); rcparse_discard_strings (); } + | string_data error + { + rcparse_warning (_("invalid stringtable resource.")); + abort (); + } ; rcdata_id: @@ -1415,16 +1422,18 @@ fixedverinfo: res_alloc (sizeof (rc_fixed_versioninfo))); memset ($$, 0, sizeof (rc_fixed_versioninfo)); } - | fixedverinfo FILEVERSION numexpr cnumexpr cnumexpr cnumexpr + | fixedverinfo FILEVERSION numexpr optcnumexpr optcnumexpr + optcnumexpr { - $1->file_version_ms = ($3 << 16) | $4; - $1->file_version_ls = ($5 << 16) | $6; + $1->file_version_ms = ($3 << 16) | ($4 & 0xffff); + $1->file_version_ls = ($5 << 16) | ($6 & 0xffff); $$ = $1; } - | fixedverinfo PRODUCTVERSION numexpr cnumexpr cnumexpr cnumexpr + | fixedverinfo PRODUCTVERSION numexpr optcnumexpr optcnumexpr + optcnumexpr { - $1->product_version_ms = ($3 << 16) | $4; - $1->product_version_ls = ($5 << 16) | $6; + $1->product_version_ms = ($3 << 16) | ($4 & 0xffff); + $1->product_version_ls = ($5 << 16) | ($6 & 0xffff); $$ = $1; } | fixedverinfo FILEFLAGSMASK numexpr @@ -1465,22 +1474,33 @@ verblocks: { $$ = NULL; } - | verblocks BLOCKSTRINGFILEINFO BEG BLOCK BEG vervals END END + | verblocks BLOCKSTRINGFILEINFO BEG verstringtables END { - $$ = append_ver_stringfileinfo ($1, $4, $6); + $$ = append_ver_stringfileinfo ($1, $4); } - | verblocks BLOCKVARFILEINFO BEG VALUE res_unicode_string vertrans END + | verblocks BLOCKVARFILEINFO BEG VALUE res_unicode_string_concat vertrans END { $$ = append_ver_varfileinfo ($1, $5, $6); } ; +verstringtables: + /* empty */ + { + $$ = NULL; + } + | verstringtables BLOCK BEG vervals END + { + $$ = append_ver_stringtable ($1, $2, $4); + } + ; + vervals: /* empty */ { $$ = NULL; } - | vervals VALUE res_unicode_string ',' res_unicode_string + | vervals VALUE res_unicode_string_concat ',' res_unicode_string_concat { $$ = append_verval ($1, $3, $5); } @@ -1505,7 +1525,6 @@ id: $$.named = 0; $$.u.id = $1; } - | resname { res_unistring_to_id (&$$, $1); @@ -1666,6 +1685,27 @@ file_name: } ; +/* Concat string */ +res_unicode_string_concat: + res_unicode_string + { + $$ = $1; + } + | + res_unicode_string_concat res_unicode_string + { + rc_uint_type l1 = unichar_len ($1); + rc_uint_type l2 = unichar_len ($2); + unichar *h = (unichar *) res_alloc ((l1 + l2 + 1) * sizeof (unichar)); + if (l1 != 0) + memcpy (h, $1, l1 * sizeof (unichar)); + if (l2 != 0) + memcpy (h + l1, $2, l2 * sizeof (unichar)); + h[l1 + l2] = 0; + $$ = h; + } + ; + res_unicode_string: QUOTEDUNISTRING { @@ -1679,6 +1719,43 @@ res_unicode_string: } ; +res_unicode_sizedstring: + sizedunistring + { + $$ = $1; + } + | sizedstring + { + unichar *h = NULL; + rc_uint_type l = 0; + unicode_from_ascii_len (&l, &h, $1.s, $1.length); + $$.s = h; + $$.length = l; + } + ; + +/* Concat string */ +res_unicode_sizedstring_concat: + res_unicode_sizedstring + { + $$ = $1; + } + | + res_unicode_sizedstring_concat res_unicode_sizedstring + { + rc_uint_type l1 = $1.length; + rc_uint_type l2 = $2.length; + unichar *h = (unichar *) res_alloc ((l1 + l2 + 1) * sizeof (unichar)); + if (l1 != 0) + memcpy (h, $1.s, l1 * sizeof (unichar)); + if (l2 != 0) + memcpy (h + l1, $2.s, l2 * sizeof (unichar)); + h[l1 + l2] = 0; + $$.length = l1 + l2; + $$.s = h; + } + ; + sizedstring: SIZEDSTRING { @@ -1810,12 +1887,12 @@ sizednumexpr: } | sizednumexpr '/' sizednumexpr { - $$.val = $1.val / $3.val; + $$.val = $1.val / ($3.val ? $3.val : 1); $$.dword = $1.dword || $3.dword; } | sizednumexpr '%' sizednumexpr { - $$.val = $1.val % $3.val; + $$.val = $1.val % ($3.val ? $3.val : 1); $$.dword = $1.dword || $3.dword; } | sizednumexpr '+' sizednumexpr @@ -1889,12 +1966,13 @@ sizedposnumexpr: } | sizedposnumexpr '/' sizednumexpr { - $$.val = $1.val / $3.val; + $$.val = $1.val / ($3.val ? $3.val : 1); $$.dword = $1.dword || $3.dword; } | sizedposnumexpr '%' sizednumexpr { - $$.val = $1.val % $3.val; + /* PR 17512: file: 89105a25. */ + $$.val = $1.val % ($3.val ? $3.val : 1); $$.dword = $1.dword || $3.dword; } | sizedposnumexpr '+' sizednumexpr