This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch]: Fix a windres (rcparse.y) parsing bug for controls without text fields


Hello

Currently, rc files with LISTBOX, COMBOBOX, EDITTEXT and SCROLLBAR controls
defined like

501 DIALOG DISCARDABLE  0, 0, 168, 137
BEGIN
    COMBOBOX        1001,10,10,50,54, CBS_SIMPLE | WS_TABSTOP
END

fail to produce valid resource objects with windres

This failure can be traced to this change:

2003-03-31  Ian Lance Taylor <ian@airs.com>

	* rcparse.y: Replace uses of 'optstringrc' with 'optresid'.
	(optresid): Handle a resource id that can be a string or a number.

With the old 'optstringrc', the first field after the COMBOBOX keyword was
an empty string and the remaining fields were bumped so that everything was
in place. Now it is treated as an ordinal alias for a name in an res_id union,
so the fields are off-by-one unless we put in an explict empty string field,
eg.
  COMBOBOX        "",1001,10,10,50,54, CBS_SIMPLE | WS_TABSTOP


The LISTBOX, COMBOBOX, EDITTEXT and SCROLLBAR controls should not accept
a text field (nor a numerical alias stored in a res_id structure) in
syntax definition, but should expect a resource reference id (integer only) to
be the first field after the control name keyword. 
For the first three of these control types, this is documented
by MSDN which give the definition syntax as:

LISTBOX id, x, y, width, height [[, style [[, extended-style]]]]
COMBOBOX id, x, y, width, height [, style [, extended-style]]
EDITTEXT id, x, y, width, height [[, style [[, extended-style]]]]

Note, id here is not a res_id name field but a resource reference id.
There is no text field.

For SCROLLBAR, MSDN documents the syntax for definition as:

SCROLLBAR text, id, x, y, width, height [[, style [[, extended-style]]]]

But the version of rc that ships with VC++6 chokes on that syntax
eg

/* bad-scrollbar.rc */
501 DIALOGEX 0, 0, 168, 137
BEGIN
    SCROLLBAR       "anytext",1001,43,68,105,10,0,0,0x81f503e9
END

Fails with:
"error RC2116: expecting number for id."
then
"error RC2108: expecting numerical dialog constant"\

The same errors are reported by rc.exe with LISTBOX, COMBOBOX and EDITEXT
when a text field follows the controlname keyword.

The following patch fixes by defining a new <dialog_control>
control_params_no_text, like control_params, but passing a
null-text res_id as first parameter to define_control.

I'm not sure this is the best way to do this, but I'm finding it
difficult to discern what the "real" rules should be when the behaviour
of native resource compiler sometimes disagrees with documentation.

I've also noted that although MSDN documents the default-style for
COMBOBOX as CBS_SIMPLE | WS_TABSTOP, the actual behaviour of MS rc is to
define _no_ default style for this control. I've left the default_style
in rcparse.y, but modified the testcase to explicitly set the
documented default.

The testcase .rsd file are dumps from res file generated by
MS rc.exe version 5.00.1641.1.

Danny

ChangeLog

2003-06-27  Danny Smith  <dannysmith@usrs.sourceforge.net>

	* rcparse.y (null_text): New static const struct res_id object,
	with empty name field.
	(control_params_no_text): New <dialog_control> for handling
	of controls without lead text field.	 
	(control): Use control_params_no_text for COMBOBOX,
	LISTBOX, EDITTEXT and SCROLLBAR.
	* resrc.c (define_control): Make first param const.
	* windres.h (define_control): Adjust prototype.

testsuite

	* binutils-all/windres/combobox.rc: New file.
	* binutils-all/windres/combobox.rsd: New file.
	* binutils-all/windres/edittext.rc: New file.
	* binutils-all/windres/edittext.rsd: New file.
	* binutils-all/windres/listbox.rc: New file.
	* binutils-all/windres/listbox.rsd: New file.
	* binutils-all/windres/scrollbar.rc: New file.
	* binutils-all/windres/scrollbar.rsd: Newfile.


Index: rcparse.y
===================================================================
RCS file: /cvs/src/src/binutils/rcparse.y,v
retrieving revision 1.17
diff -c -3 -p -r1.17 rcparse.y
*** rcparse.y	31 Mar 2003 10:15:58 -0000	1.17
--- rcparse.y	26 Jun 2003 09:49:22 -0000
*************** static unsigned long base_style;
*** 53,58 ****
--- 53,62 ----
  static unsigned long default_style;
  static unsigned long class;
  
+ /* This is used in control_params_no_text. COMBOBOX, LISTBOX and EDITTEXT
+    do not allow resource 'text' field in control definition. */
+ static const struct res_id null_text = { 1, {{0, L""}}};
+ 
  %}
  
  %union
*************** static unsigned long class;
*** 125,131 ****
  
  %type <pacc> acc_entries
  %type <acc> acc_entry acc_event
! %type <dialog_control> control control_params
  %type <menuitem> menuitems menuitem menuexitems menuexitem
  %type <rcdata> optrcdata_data optrcdata_data_int rcdata_data
  %type <rcdata_item> opt_control_data
--- 129,135 ----
  
  %type <pacc> acc_entries
  %type <acc> acc_entry acc_event
! %type <dialog_control> control control_params control_params_no_text
  %type <menuitem> menuitems menuitem menuexitems menuexitem
  %type <rcdata> optrcdata_data optrcdata_data_int rcdata_data
  %type <rcdata_item> opt_control_data
*************** control:
*** 588,598 ****
  	  }
  	| COMBOBOX
  	    {
  	      default_style = CBS_SIMPLE | WS_TABSTOP;
  	      base_style = 0;
  	      class = CTL_COMBOBOX;
  	    }
! 	    control_params
  	  {
  	    $$ = $3;
  	  }
--- 592,604 ----
  	  }
  	| 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;
  	    }
! 	    control_params_no_text
  	  {
  	    $$ = $3;
  	  }
*************** control:
*** 666,672 ****
  	      base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
  	      class = CTL_EDIT;
  	    }
! 	    control_params
  	  {
  	    $$ = $3;
  	  }
--- 672,678 ----
  	      base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
  	      class = CTL_EDIT;
  	    }
! 	    control_params_no_text
  	  {
  	    $$ = $3;
  	  }
*************** control:
*** 735,741 ****
  	      base_style = LBS_NOTIFY | WS_BORDER;
  	      class = CTL_LISTBOX;
  	    }
! 	    control_params
  	  {
  	    $$ = $3;
  	  }
--- 741,747 ----
  	      base_style = LBS_NOTIFY | WS_BORDER;
  	      class = CTL_LISTBOX;
  	    }
! 	    control_params_no_text
  	  {
  	    $$ = $3;
  	  }
*************** control:
*** 795,801 ****
  	      base_style = 0;
  	      class = CTL_SCROLLBAR;
  	    }
! 	    control_params
  	  {
  	    $$ = $3;
  	  }
--- 801,807 ----
  	      base_style = 0;
  	      class = CTL_SCROLLBAR;
  	    }
! 	    control_params_no_text
  	  {
  	    $$ = $3;
  	  }
*************** control_params:
*** 858,863 ****
--- 864,904 ----
  	      rcparse_warning (_("help ID requires DIALOGEX"));
  	    $$->help = $9;
  	    $$->data = $10;
+ 	  }
+ 	;
+ 
+ /* Like control_params, but no text field allowed in definition.  */
+ control_params_no_text:
+ 	  numexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
+ 	  {
+ 	    $$ = define_control (null_text, $1, $2, $3, $4, $5, class,
+ 				 default_style | WS_CHILD | WS_VISIBLE, 0);
+ 	    if ($6 != NULL)
+ 	      {
+ 		if (dialog.ex == NULL)
+ 		  rcparse_warning (_("control data requires DIALOGEX"));
+ 		$$->data = $6;
+ 	      }
+ 	  }
+ 	| numexpr cnumexpr cnumexpr cnumexpr cnumexpr
+ 	    control_params_styleexpr optcnumexpr opt_control_data
+ 	  {
+ 	    $$ = define_control (null_text, $1, $2, $3, $4, $5, class, style, $7);
+ 	    if ($8 != NULL)
+ 	      {
+ 		if (dialog.ex == NULL)
+ 		  rcparse_warning (_("control data requires DIALOGEX"));
+ 		$$->data = $8;
+ 	      }
+ 	  }
+ 	| numexpr cnumexpr cnumexpr cnumexpr cnumexpr
+ 	    control_params_styleexpr cnumexpr cnumexpr opt_control_data
+ 	  {
+ 	    $$ = define_control (null_text, $1, $2, $3, $4, $5, class, style, $7);
+ 	    if (dialog.ex == NULL)
+ 	      rcparse_warning (_("help ID requires DIALOGEX"));
+ 	    $$->help = $8;
+ 	    $$->data = $9;
  	  }
  	;
  
Index: resrc.c
===================================================================
RCS file: /cvs/src/src/binutils/resrc.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 resrc.c
*** resrc.c	31 Mar 2003 10:15:58 -0000	1.21
--- resrc.c	26 Jun 2003 09:49:25 -0000
*************** define_dialog (id, resinfo, dialog)
*** 819,825 ****
  
  struct dialog_control *
  define_control (iid, id, x, y, width, height, class, style, exstyle)
!      struct res_id iid;
       unsigned long id;
       unsigned long x;
       unsigned long y;
--- 819,825 ----
  
  struct dialog_control *
  define_control (iid, id, x, y, width, height, class, style, exstyle)
!      const struct res_id iid;
       unsigned long id;
       unsigned long x;
       unsigned long y;
Index: windres.h
===================================================================
RCS file: /cvs/src/src/binutils/windres.h,v
retrieving revision 1.9
diff -c -3 -p -r1.9 windres.h
*** windres.h	31 Mar 2003 10:15:58 -0000	1.9
--- windres.h	26 Jun 2003 09:49:26 -0000
*************** extern void define_cursor
*** 814,820 ****
  extern void define_dialog
    PARAMS ((struct res_id, const struct res_res_info *, const struct dialog *));
  extern struct dialog_control *define_control
!   PARAMS ((struct res_id, unsigned long, unsigned long, unsigned long,
  	   unsigned long, unsigned long, unsigned long, unsigned long,
  	   unsigned long));
  extern struct dialog_control *define_icon_control
--- 814,820 ----
  extern void define_dialog
    PARAMS ((struct res_id, const struct res_res_info *, const struct dialog *));
  extern struct dialog_control *define_control
!   PARAMS ((const struct res_id, unsigned long, unsigned long, unsigned long,
  	   unsigned long, unsigned long, unsigned long, unsigned long,
  	   unsigned long));
  extern struct dialog_control *define_icon_control
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/combobox.rc	Sat Jun 21 11:32:53 2003
***************
*** 0 ****
--- 1,8 ----
+ #define CBS_SIMPLE 0x1
+ #define WS_TABSTOP 0x10000
+ 
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+     COMBOBOX        1001,10,10,50,54, CBS_SIMPLE | WS_TABSTOP
+ END
+ 
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/combobox.rsd	Tue Jun 24 23:21:20 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 01000150 00000000  ...........P....
+  0060 0a000a00 32003600 e903ffff 85000000  ....2.6.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/edittext.rc	Sat Jun 21 08:30:53 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+   EDITTEXT      1001, 28, 63, 137, 52
+ END
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/edittext.rsd	Tue Jun 24 23:21:30 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 00008150 00000000  ...........P....
+  0060 1c003f00 89003400 e903ffff 81000000  ..?...4.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/listbox.rc	Sat Jun 21 08:35:18 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+   LISTBOX     1001, 28, 63, 137, 52
+ END
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/listbox.rsd	Tue Jun 24 23:21:38 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 01008050 00000000  ...........P....
+  0060 1c003f00 89003400 e903ffff 83000000  ..?...4.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/scrollbar.rc	Thu Jun 26 08:52:54 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOGEX 0, 0, 168, 137
+ BEGIN
+     SCROLLBAR       1001,43,68,105,10,0,0,0x81f503e9
+ END
*** /dev/null	Thu Jun 26 10:41:50 2003
--- testsuite/binutils-all/windres/scrollbar.rsd	Tue Jun 24 23:21:43 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 40000000 20000000 ffff0500 fffff501  @... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 0100ffff 00000000 00000000 00008880  ................
+  0050 01000000 0000a800 89000000 00000000  ................
+  0060 e903f581 00000000 00000050 19002300  ...........P..#.
+  0070 0a006400 e9030000 ffff8400 00000000  ..d.............
*** /dev/null	Thu Jun 26 10:50:22 2003
--- testsuite/binutils-all/windres/combobox.rc	Sat Jun 21 11:32:53 2003
***************
*** 0 ****
--- 1,8 ----
+ #define CBS_SIMPLE 0x1
+ #define WS_TABSTOP 0x10000
+ 
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+     COMBOBOX        1001,10,10,50,54, CBS_SIMPLE | WS_TABSTOP
+ END
+ 
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/combobox.rsd	Tue Jun 24 23:21:20 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 01000150 00000000  ...........P....
+  0060 0a000a00 32003600 e903ffff 85000000  ....2.6.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/edittext.rc	Sat Jun 21 08:30:53 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+   EDITTEXT      1001, 28, 63, 137, 52
+ END
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/edittext.rsd	Tue Jun 24 23:21:30 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 00008150 00000000  ...........P....
+  0060 1c003f00 89003400 e903ffff 81000000  ..?...4.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/listbox.rc	Sat Jun 21 08:35:18 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOG DISCARDABLE  0, 0, 168, 137
+ BEGIN
+   LISTBOX     1001, 28, 63, 137, 52
+ END
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/listbox.rsd	Tue Jun 24 23:21:38 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 32000000 20000000 ffff0500 fffff501  2... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 00008880 00000000 01000000 0000a800  ................
+  0050 89000000 00000000 01008050 00000000  ...........P....
+  0060 1c003f00 89003400 e903ffff 83000000  ..?...4.........
+  0070 00000000                             ....            
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/scrollbar.rc	Thu Jun 26 08:52:54 2003
***************
*** 0 ****
--- 1,4 ----
+ 501 DIALOGEX 0, 0, 168, 137
+ BEGIN
+     SCROLLBAR       1001,43,68,105,10,0,0,0x81f503e9
+ END
*** /dev/null	Thu Jun 26 10:50:23 2003
--- testsuite/binutils-all/windres/scrollbar.rsd	Tue Jun 24 23:21:43 2003
***************
*** 0 ****
--- 1,8 ----
+  0000 00000000 20000000 ffff0000 ffff0000  .... ...........
+  0010 00000000 00000000 00000000 00000000  ................
+  0020 40000000 20000000 ffff0500 fffff501  @... ...........
+  0030 00000000 30100904 00000000 00000000  ....0...........
+  0040 0100ffff 00000000 00000000 00008880  ................
+  0050 01000000 0000a800 89000000 00000000  ................
+  0060 e903f581 00000000 00000050 19002300  ...........P..#.
+  0070 0a006400 e9030000 ffff8400 00000000  ..d.............


http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]