windres borland compatibility patch
Ryan Underwood
nemesis-lists@icequake.net
Tue Sep 7 00:42:00 GMT 2004
> I hacked up a little patch that parses the byte-blob format that Borland
> resource files use. With it, I was able to compile the resource file of
> an application I am porting. The form is like this:
>
> ICON1 ICON
> {
> 'AE 09 08 64 ...
>
> basically a string of hexadecimal bytes. I saw it used in the icon,
> cursor, and bitmap types, but it's possible that it is used in other
> types.
>
> All the patch does is parse this into an internal structure, and then
> write out a temp file which is then passed to the other windres
> functions like a normal filename was included. This works fine for me,
> but if anyone has a more elegant approach, I'm all ears.
>
> applies against cvs.
Here's the patch for real this time.
--
Ryan Underwood, <nemesis@icequake.net>
-------------- next part --------------
Index: rclex.l
===================================================================
RCS file: /cvs/src/src/binutils/rclex.l,v
retrieving revision 1.10
diff -u -r1.10 rclex.l
--- rclex.l 14 Sep 2003 12:20:16 -0000 1.10
+++ rclex.l 7 Sep 2004 00:19:32 -0000
@@ -72,12 +72,16 @@
%}
+%x QUOTE_STATE
+
%%
"BEGIN" { MAYBE_RETURN (BEG); }
"{" { MAYBE_RETURN (BEG); }
"END" { MAYBE_RETURN (END); }
"}" { MAYBE_RETURN (END); }
+<QUOTE_STATE>"'" { BEGIN INITIAL; }
+"'" { BEGIN QUOTE_STATE; }
"ACCELERATORS" { MAYBE_RETURN (ACCELERATORS); }
"VIRTKEY" { MAYBE_RETURN (VIRTKEY); }
"ASCII" { MAYBE_RETURN (ASCII); }
@@ -184,6 +188,12 @@
cpp_line (yytext);
}
+<QUOTE_STATE>[0-9A-Fa-f]{2}/[[:space:]'] {
+ yylval.i.val = strtoul (yytext, 0, 16);
+ yylval.i.dword = 0;
+ MAYBE_RETURN (BYTE);
+ }
+
[0-9][x0-9A-Fa-f]*L {
yylval.i.val = strtoul (yytext, 0, 0);
yylval.i.dword = 1;
@@ -229,8 +239,8 @@
MAYBE_RETURN (STRING);
}
-[\n] { ++rc_lineno; }
-[ \t\r]+ { /* ignore whitespace */ }
+<*>[\n] { ++rc_lineno; }
+<*>[ \t\r]+ { /* ignore whitespace */ }
. { MAYBE_RETURN (*yytext); }
%%
Index: rcparse.y
===================================================================
RCS file: /cvs/src/src/binutils/rcparse.y,v
retrieving revision 1.19
diff -u -r1.19 rcparse.y
--- rcparse.y 14 Sep 2003 12:20:16 -0000 1.19
+++ rcparse.y 7 Sep 2004 00:19:33 -0000
@@ -58,6 +58,8 @@
do not allow resource 'text' field in control definition. */
static const struct res_id res_null_text = { 1, {{0, L""}}};
+int blob2file(struct bstring *blob, char *fname);
+
%}
%union
@@ -98,9 +100,11 @@
unsigned long length;
const char *s;
} ss;
+ struct bstring bs;
+ unsigned char uc;
};
-%token BEG END
+%token BEG END QUOTE
%token ACCELERATORS VIRTKEY ASCII NOINVERT SHIFT CONTROL ALT
%token BITMAP
%token CURSOR
@@ -127,6 +131,7 @@
%token <i> NUMBER
%token <ss> SIZEDSTRING
%token IGNORED_TOKEN
+%token <uc> BYTE
%type <pacc> acc_entries
%type <acc> acc_entry acc_event
@@ -146,6 +151,7 @@
%type <is> acc_options acc_option menuitem_flags menuitem_flag
%type <s> file_name resname
%type <i> sizednumexpr sizedposnumexpr
+%type <bs> binary_blob
%left '|'
%left '^'
@@ -314,6 +320,38 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id BITMAP memflags_move BEG binary_blob END
+ {
+ char *fname;
+ asprintf(&fname, ".temp.bmp");
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_bitmap ($1, &$3, fname);
+ free($5.s);
+ free(fname);
+ unlink(".temp.bmp");
+ }
+ ;
+
+binary_blob:
+ binary_blob BYTE
+ {
+ if ($$.len == $$.alloc_len)
+ {
+ $$.s = xrealloc($$.s, $$.alloc_len + 256);
+ $$.alloc_len += 256;
+ }
+ $$.s[$$.len++] = $2;
+ }
+ | BYTE
+ {
+ $$.s = (unsigned char *)xmalloc(256);
+ $$.alloc_len = 256;
+ $$.len = 0;
+ $$.s[$$.len++] = $1;
+ }
;
/* Cursor resources. */
@@ -326,6 +364,19 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id CURSOR memflags_move_discard BEG binary_blob END
+ {
+ char *fname;
+ asprintf(&fname, ".temp.cur");
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_cursor ($1, &$3, fname);
+ free($5.s);
+ free(fname);
+ unlink(".temp.cur");
+ }
;
/* Dialog resources. */
@@ -959,6 +1010,19 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id ICON memflags_move_discard BEG binary_blob END
+ {
+ char *fname;
+ asprintf(&fname, ".temp.ico");
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_icon ($1, &$3, fname);
+ free($5.s);
+ free(fname);
+ unlink(".temp.ico");
+ }
;
/* Language command. This changes the static variable language, which
@@ -1766,3 +1830,29 @@
{
language = lang;
}
+
+int blob2file(struct bstring *blob, char *fname) {
+
+ FILE *newfile;
+ newfile = fopen(fname, "w+");
+
+ if (newfile == NULL)
+ {
+ printf("Couldn't create file %s for resource\n", fname);
+ return 0;
+ }
+ if (fwrite(blob->s, 1, blob->len, newfile) < blob->len)
+ {
+ printf("Couldn't write resource to file %s\n", fname);
+ return 0;
+ }
+ if (fclose(newfile) == -1)
+ {
+ printf("Couldn't close %s: %s\n", fname, strerror(errno));
+ return 0;
+ }
+
+ return 1;
+}
+
+
Index: windres.h
===================================================================
RCS file: /cvs/src/src/binutils/windres.h,v
retrieving revision 1.11
diff -u -r1.11 windres.h
--- windres.h 14 Sep 2003 12:20:17 -0000 1.11
+++ windres.h 7 Sep 2004 00:19:33 -0000
@@ -746,6 +746,16 @@
unsigned char *data;
};
+/* A structure to hold a binary blob as it is being parsed from the
+ * rc file. */
+
+struct bstring
+{
+ unsigned long len;
+ unsigned long alloc_len;
+ unsigned char *s;
+};
+
extern int verbose;
/* Function declarations. */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://sourceware.org/pipermail/binutils/attachments/20040907/89b37892/attachment.sig>
More information about the Binutils
mailing list