2004-08-04 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / binutils / rcparse.y
index fcd34cc231523df4df371c14749e344de49c4ba9..7aacaaa067326d2bd720527b8141922c8def2b54 100644 (file)
@@ -1,5 +1,5 @@
 %{ /* rcparse.y -- parser for Windows rc files
-   Copyright 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of GNU Binutils.
@@ -52,6 +52,11 @@ static unsigned long style;
 static unsigned long base_style;
 static unsigned long default_style;
 static unsigned long class;
+static struct res_id res_text_field;
+
+/* This is used for COMBOBOX, LISTBOX and EDITTEXT which
+   do not allow resource 'text' field in control definition. */
+static const struct res_id res_null_text = { 1, {{0, L""}}};
 
 %}
 
@@ -135,11 +140,11 @@ static unsigned long class;
 %type <vervar> vertrans
 %type <res_info> suboptions memflags_move_discard memflags_move
 %type <memflags> memflag
-%type <id> id resref
+%type <id> id optresidc resref
 %type <il> exstyle parennumber
 %type <il> numexpr posnumexpr cnumexpr optcnumexpr cposnumexpr
 %type <is> acc_options acc_option menuitem_flags menuitem_flag
-%type <s> optstringc file_name resname
+%type <s> file_name resname
 %type <i> sizednumexpr sizedposnumexpr
 
 %left '|'
@@ -153,28 +158,21 @@ static unsigned long class;
 
 input:
          /* empty */
-       | input newcmd accelerator
-       | input newcmd bitmap
-       | input newcmd cursor
-       | input newcmd dialog
-       | input newcmd font
-       | input newcmd icon
-       | input newcmd language
-       | input newcmd menu
-       | input newcmd menuex
-       | input newcmd messagetable
-       | input newcmd rcdata
-       | input newcmd stringtable
-       | input newcmd user
-       | input newcmd versioninfo
-       | input newcmd IGNORED_TOKEN
-       ;
-
-newcmd:
-         /* empty */
-         {
-           rcparse_discard_strings ();
-         }
+       | input accelerator
+       | input bitmap
+       | input cursor
+       | input dialog
+       | input font
+       | input icon
+       | input language
+       | input menu
+       | input menuex
+       | input messagetable
+       | input rcdata
+       | input stringtable
+       | input user
+       | input versioninfo
+       | input IGNORED_TOKEN
        ;
 
 /* Accelerator resources.  */
@@ -183,6 +181,9 @@ accelerator:
          id ACCELERATORS suboptions BEG acc_entries END
          {
            define_accelerator ($1, &$3, $5);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -223,7 +224,7 @@ acc_entry:
            $$.id = $2;
            $$.flags |= $4;
            if (($$.flags & ACC_VIRTKEY) == 0
-               && ($$.flags & (ACC_SHIFT | ACC_CONTROL | ACC_ALT)) != 0)
+               && ($$.flags & (ACC_SHIFT | ACC_CONTROL)) != 0)
              rcparse_warning (_("inappropriate modifiers for non-VIRTKEY"));
          }
        ;
@@ -309,6 +310,9 @@ bitmap:
          id BITMAP memflags_move file_name
          {
            define_bitmap ($1, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -318,6 +322,9 @@ cursor:
          id CURSOR memflags_move_discard file_name
          {
            define_cursor ($1, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -345,6 +352,9 @@ dialog:
            styles BEG controls END
          {
            define_dialog ($1, &sub_res_info, &dialog);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr
            cnumexpr
@@ -369,6 +379,9 @@ dialog:
            styles BEG controls END
          {
            define_dialog ($1, &sub_res_info, &dialog);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr
            cnumexpr cnumexpr
@@ -394,6 +407,9 @@ dialog:
            styles BEG controls END
          {
            define_dialog ($1, &sub_res_info, &dialog);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -412,6 +428,8 @@ styles:
          /* empty */
        | styles CAPTION QUOTEDSTRING
          {
+           dialog.style |= WS_CAPTION;
+           style |= WS_CAPTION;
            unicode_from_ascii ((int *) NULL, &dialog.caption, $3);
          }
        | styles CLASS id
@@ -437,6 +455,27 @@ styles:
            style |= DS_SETFONT;
            dialog.pointsize = $3;
            unicode_from_ascii ((int *) NULL, &dialog.font, $5);
+           if (dialog.ex != NULL)
+             {
+               dialog.ex->weight = 0;
+               dialog.ex->italic = 0;
+               dialog.ex->charset = 1;
+             }
+         }
+       | styles FONT numexpr ',' QUOTEDSTRING cnumexpr
+         {
+           dialog.style |= DS_SETFONT;
+           style |= DS_SETFONT;
+           dialog.pointsize = $3;
+           unicode_from_ascii ((int *) NULL, &dialog.font, $5);
+           if (dialog.ex == NULL)
+             rcparse_warning (_("extended FONT requires DIALOGEX"));
+           else
+             {
+               dialog.ex->weight = $6;
+               dialog.ex->italic = 0;
+               dialog.ex->charset = 1;
+             }
          }
        | styles FONT numexpr ',' QUOTEDSTRING cnumexpr cnumexpr
          {
@@ -450,6 +489,22 @@ styles:
              {
                dialog.ex->weight = $6;
                dialog.ex->italic = $7;
+               dialog.ex->charset = 1;
+             }
+         }
+       | styles FONT numexpr ',' QUOTEDSTRING cnumexpr cnumexpr cnumexpr
+         {
+           dialog.style |= DS_SETFONT;
+           style |= DS_SETFONT;
+           dialog.pointsize = $3;
+           unicode_from_ascii ((int *) NULL, &dialog.font, $5);
+           if (dialog.ex == NULL)
+             rcparse_warning (_("extended FONT requires DIALOGEX"));
+           else
+             {
+               dialog.ex->weight = $6;
+               dialog.ex->italic = $7;
+               dialog.ex->charset = $8;
              }
          }
        | styles MENU id
@@ -483,70 +538,78 @@ controls:
        ;
 
 control:
-         AUTO3STATE
+         AUTO3STATE optresidc
            {
              default_style = BS_AUTO3STATE | WS_TABSTOP;
              base_style = BS_AUTO3STATE;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | AUTOCHECKBOX
+       | AUTOCHECKBOX optresidc
            {
              default_style = BS_AUTOCHECKBOX | WS_TABSTOP;
              base_style = BS_AUTOCHECKBOX;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | AUTORADIOBUTTON
+       | AUTORADIOBUTTON optresidc
            {
              default_style = BS_AUTORADIOBUTTON | WS_TABSTOP;
              base_style = BS_AUTORADIOBUTTON;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | BEDIT
+       | BEDIT optresidc
            {
              default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              class = CTL_EDIT;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
            if (dialog.ex == NULL)
              rcparse_warning (_("BEDIT requires DIALOGEX"));
            res_string_to_id (&$$->class, "BEDIT");
          }
-       | CHECKBOX
+       | CHECKBOX optresidc
            {
              default_style = BS_CHECKBOX | WS_TABSTOP;
              base_style = BS_CHECKBOX | WS_TABSTOP;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
        | COMBOBOX
            {
+             /* This is as per MSDN documentation.  With some (???)
+                versions of MS rc.exe their is no default style.  */
              default_style = CBS_SIMPLE | WS_TABSTOP;
              base_style = 0;
              class = CTL_COMBOBOX;
+             res_text_field = res_null_text;   
            }
            control_params
          {
            $$ = $3;
          }
-       | CONTROL optstringc numexpr cnumexpr control_styleexpr cnumexpr
+       | CONTROL optresidc numexpr cnumexpr control_styleexpr cnumexpr
            cnumexpr cnumexpr cnumexpr optcnumexpr opt_control_data
          {
            $$ = define_control ($2, $3, $6, $7, $8, $9, $4, style, $10);
@@ -557,7 +620,7 @@ control:
                $$->data = $11;
              }
          }
-       | CONTROL optstringc numexpr cnumexpr control_styleexpr cnumexpr
+       | CONTROL optresidc numexpr cnumexpr control_styleexpr cnumexpr
            cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
          {
            $$ = define_control ($2, $3, $6, $7, $8, $9, $4, style, $10);
@@ -566,7 +629,7 @@ control:
            $$->help = $11;
            $$->data = $12;
          }
-       | CONTROL optstringc numexpr ',' QUOTEDSTRING control_styleexpr
+       | CONTROL optresidc numexpr ',' QUOTEDSTRING control_styleexpr
            cnumexpr cnumexpr cnumexpr cnumexpr optcnumexpr opt_control_data
          {
            $$ = define_control ($2, $3, $7, $8, $9, $10, 0, style, $11);
@@ -579,7 +642,7 @@ control:
            $$->class.named = 1;
            unicode_from_ascii (&$$->class.u.n.length, &$$->class.u.n.name, $5);
          }
-       | CONTROL optstringc numexpr ',' QUOTEDSTRING control_styleexpr
+       | CONTROL optresidc numexpr ',' QUOTEDSTRING control_styleexpr
            cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
          {
            $$ = define_control ($2, $3, $7, $8, $9, $10, 0, style, $11);
@@ -590,55 +653,60 @@ control:
            $$->class.named = 1;
            unicode_from_ascii (&$$->class.u.n.length, &$$->class.u.n.name, $5);
          }
-       | CTEXT
+       | CTEXT optresidc
            {
              default_style = SS_CENTER | WS_GROUP;
              base_style = SS_CENTER;
              class = CTL_STATIC;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | DEFPUSHBUTTON
+       | DEFPUSHBUTTON optresidc
            {
              default_style = BS_DEFPUSHBUTTON | WS_TABSTOP;
              base_style = BS_DEFPUSHBUTTON | WS_TABSTOP;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
        | EDITTEXT
            {
              default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              class = CTL_EDIT;
+             res_text_field = res_null_text;   
            }
            control_params
          {
            $$ = $3;
          }
-       | GROUPBOX
+       | GROUPBOX optresidc
            {
              default_style = BS_GROUPBOX;
              base_style = BS_GROUPBOX;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | HEDIT
+       | HEDIT optresidc
            {
              default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              class = CTL_EDIT;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
            if (dialog.ex == NULL)
              rcparse_warning (_("IEDIT requires DIALOGEX"));
            res_string_to_id (&$$->class, "HEDIT");
@@ -666,15 +734,16 @@ control:
            $$ = define_icon_control ($2, $3, $4, $5, style, $9, $10, $11,
                                      dialog.ex);
           }
-       | IEDIT
+       | IEDIT optresidc
            {
              default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
              class = CTL_EDIT;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
            if (dialog.ex == NULL)
              rcparse_warning (_("IEDIT requires DIALOGEX"));
            res_string_to_id (&$$->class, "IEDIT");
@@ -684,22 +753,24 @@ control:
              default_style = LBS_NOTIFY | WS_BORDER;
              base_style = LBS_NOTIFY | WS_BORDER;
              class = CTL_LISTBOX;
+             res_text_field = res_null_text;   
            }
            control_params
          {
            $$ = $3;
          }
-       | LTEXT
+       | LTEXT optresidc
            {
              default_style = SS_LEFT | WS_GROUP;
              base_style = SS_LEFT;
              class = CTL_STATIC;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | PUSHBOX
+       | PUSHBOX optresidc
            {
              default_style = BS_PUSHBOX | WS_TABSTOP;
              base_style = BS_PUSHBOX;
@@ -707,65 +778,70 @@ control:
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | PUSHBUTTON
+       | PUSHBUTTON optresidc
            {
              default_style = BS_PUSHBUTTON | WS_TABSTOP;
              base_style = BS_PUSHBUTTON | WS_TABSTOP;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | RADIOBUTTON
+       | RADIOBUTTON optresidc
            {
              default_style = BS_RADIOBUTTON | WS_TABSTOP;
              base_style = BS_RADIOBUTTON;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | RTEXT
+       | RTEXT optresidc
            {
              default_style = SS_RIGHT | WS_GROUP;
              base_style = SS_RIGHT;
              class = CTL_STATIC;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
        | SCROLLBAR
            {
              default_style = SBS_HORZ;
              base_style = 0;
              class = CTL_SCROLLBAR;
+             res_text_field = res_null_text;   
            }
            control_params
          {
            $$ = $3;
          }
-       | STATE3
+       | STATE3 optresidc
            {
              default_style = BS_3STATE | WS_TABSTOP;
              base_style = BS_3STATE;
              class = CTL_BUTTON;
+             res_text_field = $2;      
            }
            control_params
          {
-           $$ = $3;
+           $$ = $4;
          }
-       | USERBUTTON QUOTEDSTRING ',' numexpr ',' numexpr ',' numexpr ','
+       | USERBUTTON resref numexpr ',' numexpr ',' numexpr ','
            numexpr ',' numexpr ',' 
            { style = WS_CHILD | WS_VISIBLE; }
            styleexpr optcnumexpr
          {
-           $$ = define_control ($2, $4, $6, $8, $10, $12, CTL_BUTTON,
-                                style, $16);
+           $$ = define_control ($2, $3, $5, $7, $9, $11, CTL_BUTTON,
+                                style, $15);
          }
        ;
 
@@ -777,52 +853,56 @@ control:
    style.  CLASS is the class of the control.  */
 
 control_params:
-         optstringc numexpr cnumexpr cnumexpr cnumexpr cnumexpr
-           opt_control_data
+         numexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
          {
-           $$ = define_control ($1, $2, $3, $4, $5, $6, class,
+           $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class,
                                 default_style | WS_CHILD | WS_VISIBLE, 0);
-           if ($7 != NULL)
+           if ($6 != NULL)
              {
                if (dialog.ex == NULL)
                  rcparse_warning (_("control data requires DIALOGEX"));
-               $$->data = $7;
+               $$->data = $6;
              }
          }
-       | optstringc numexpr cnumexpr cnumexpr cnumexpr cnumexpr
+       | numexpr cnumexpr cnumexpr cnumexpr cnumexpr
            control_params_styleexpr optcnumexpr opt_control_data
          {
-           $$ = define_control ($1, $2, $3, $4, $5, $6, class, style, $8);
-           if ($9 != NULL)
+           $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class, style, $7);
+           if ($8 != NULL)
              {
                if (dialog.ex == NULL)
                  rcparse_warning (_("control data requires DIALOGEX"));
-               $$->data = $9;
+               $$->data = $8;
              }
          }
-       | optstringc numexpr cnumexpr cnumexpr cnumexpr cnumexpr
+       | numexpr cnumexpr cnumexpr cnumexpr cnumexpr
            control_params_styleexpr cnumexpr cnumexpr opt_control_data
          {
-           $$ = define_control ($1, $2, $3, $4, $5, $6, class, style, $8);
+           $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class, style, $7);
            if (dialog.ex == NULL)
              rcparse_warning (_("help ID requires DIALOGEX"));
-           $$->help = $9;
-           $$->data = $10;
+           $$->help = $8;
+           $$->data = $9;
          }
        ;
 
-optstringc:
+optresidc:
          /* empty */
          {
-           $$ = NULL;
+           res_string_to_id (&$$, "");
+         }
+       | posnumexpr ','
+         {
+           $$.named = 0;
+           $$.u.id = $1;
          }
        | QUOTEDSTRING
          {
-           $$ = $1;
+           res_string_to_id (&$$, $1);
          }
        | QUOTEDSTRING ','
          {
-           $$ = $1;
+           res_string_to_id (&$$, $1);
          }
        ;
 
@@ -863,6 +943,9 @@ font:
          id FONT memflags_move_discard file_name
          {
            define_font ($1, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -872,6 +955,9 @@ icon:
          id ICON memflags_move_discard file_name
          {
            define_icon ($1, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -891,6 +977,9 @@ menu:
          id MENU suboptions BEG menuitems END
          {
            define_menu ($1, &$3, $5);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -978,6 +1067,9 @@ menuex:
          id MENUEX suboptions BEG menuexitems END
          {
            define_menu ($1, &$3, $5);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1044,6 +1136,9 @@ messagetable:
          id MESSAGETABLE memflags_move file_name
          {
            define_messagetable ($1, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1053,6 +1148,9 @@ rcdata:
          id RCDATA suboptions BEG optrcdata_data END
          {
            define_rcdata ($1, &$3, $5.first);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1132,10 +1230,16 @@ string_data:
        | string_data numexpr QUOTEDSTRING
          {
            define_stringtable (&sub_res_info, $2, $3);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        | string_data numexpr ',' QUOTEDSTRING
          {
            define_stringtable (&sub_res_info, $2, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1146,10 +1250,16 @@ user:
          id id suboptions BEG optrcdata_data END
          {
            define_user_data ($1, $2, &$3, $5.first);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        | id id suboptions file_name
          {
            define_user_file ($1, $2, &$3, $4);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1159,6 +1269,9 @@ versioninfo:
          id VERSIONINFO fixedverinfo BEG verblocks END
          {
            define_versioninfo ($1, language, $3, $5);
+           if (yychar != YYEMPTY)
+             YYERROR;
+           rcparse_discard_strings ();
          }
        ;
 
@@ -1318,7 +1431,7 @@ suboptions:
            memset (&$$, 0, sizeof (struct res_res_info));
            $$.language = language;
            /* FIXME: Is this the right default?  */
-           $$.memflags = MEMFLAG_MOVEABLE;
+           $$.memflags = MEMFLAG_MOVEABLE | MEMFLAG_PURE | MEMFLAG_DISCARDABLE;
          }
        | suboptions memflag
          {
@@ -1367,7 +1480,7 @@ memflags_move:
          {
            memset (&$$, 0, sizeof (struct res_res_info));
            $$.language = language;
-           $$.memflags = MEMFLAG_MOVEABLE;
+           $$.memflags = MEMFLAG_MOVEABLE | MEMFLAG_PURE | MEMFLAG_DISCARDABLE;
          }
        | memflags_move memflag
          {
@@ -1649,8 +1762,7 @@ sizedposnumexpr:
 /* Set the language from the command line.  */
 
 void
-rcparse_set_language (lang)
-     int lang;
+rcparse_set_language (int lang)
 {
   language = lang;
 }
This page took 0.055752 seconds and 4 git commands to generate.