windres borland compatibility patch
Ryan Underwood
nemesis-lists@icequake.net
Wed Sep 8 21:24:00 GMT 2004
> It's probably better to use mkstemps for a temporary file name anyhow.
How's this one?
--
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 8 Sep 2004 21:23:08 -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 8 Sep 2004 21:23:08 -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,36 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id BITMAP memflags_move BEG binary_blob END
+ {
+ char fname[] = "windres_bitmap_XXXXXX";
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_bitmap ($1, &$3, fname);
+ free($5.s);
+ unlink(fname);
+ }
+ ;
+
+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 +362,17 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id CURSOR memflags_move_discard BEG binary_blob END
+ {
+ char fname[] = "windres_cur_XXXXXX";
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_cursor ($1, &$3, fname);
+ free($5.s);
+ unlink(fname);
+ }
;
/* Dialog resources. */
@@ -959,6 +1006,17 @@
YYERROR;
rcparse_discard_strings ();
}
+ | id ICON memflags_move_discard BEG binary_blob END
+ {
+ char fname[] = "windres_icon_XXXXXX";
+
+ if (!blob2file(&$5, fname))
+ YYERROR;
+
+ define_icon ($1, &$3, fname);
+ free($5.s);
+ unlink(fname);
+ }
;
/* Language command. This changes the static variable language, which
@@ -1766,3 +1824,35 @@
{
language = lang;
}
+
+/* Turn a Borland-style resource binary blob into a temporary file. */
+
+int blob2file(struct bstring *blob, char *fname) {
+
+ int tmpfd;
+ int ret;
+
+ if ((tmpfd = mkstemp(fname)) == -1)
+ {
+ printf("Creating temporary file %s failed\n", fname);
+ return 0;
+ }
+
+ ret = write(tmpfd, blob->s, blob->len);
+
+ if ((ret < 0) || ((unsigned long)ret < blob->len))
+ {
+ printf("Couldn't write resource to file %s: %s\n", fname, strerror(errno));
+ return 0;
+ }
+
+ if (close(tmpfd) == -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 8 Sep 2004 21:23:08 -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/20040908/9b63d987/attachment.sig>
More information about the Binutils
mailing list