summaryrefslogtreecommitdiff
path: root/binutils/windres.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>1999-05-11 21:06:16 +0000
committerDJ Delorie <dj@delorie.com>1999-05-11 21:06:16 +0000
commita32a6d24adae19034a728286cab67ec5d61cc6f0 (patch)
tree955a47f0b13be4b7c5b1f2fbb02a1a7d0af830dc /binutils/windres.c
parent72542c1f88daf3c249aebc927670a54ce9da43be (diff)
downloadbinutils-redhat-a32a6d24adae19034a728286cab67ec5d61cc6f0.tar.gz
1999-05-10 DJ Delorie <dj@cygnus.com>
* windres.c (quot): Quote shell metacharacters in a string (main): quote parameters to cpp that might have metacharacters in them. Allow -D as an alias for --define to allow for sharing make macros with gcc. * objdump.c (dump_reloc_set): don't core if howto->name is NULL * Makefile.am: Give rescoff.c a cpu-specific -D so it can set the correct BFD. * Makefile.in: ditto * rescoff.c (write_coff_file): Set the correct BFD
Diffstat (limited to 'binutils/windres.c')
-rw-r--r--binutils/windres.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/binutils/windres.c b/binutils/windres.c
index 7de28c259e..885cd51fc0 100644
--- a/binutils/windres.c
+++ b/binutils/windres.c
@@ -724,6 +724,34 @@ No input-file is stdin, default rc. No output-file is stdout, default rc.\n"));
exit (status);
}
+/* Quote characters that will confuse the shell when we run the preprocessor */
+static const char *quot (string)
+ const char *string;
+{
+ static char *buf = 0;
+ static int buflen = 0;
+ int slen = strlen (string);
+ const char *src;
+ char *dest;
+
+ if ((buflen < slen * 2 + 2) || !buf)
+ {
+ buflen = slen * 2 + 2;
+ if (buf)
+ free (buf);
+ buf = (char *) xmalloc (buflen);
+ }
+
+ for (src=string, dest=buf; *src; src++, dest++)
+ {
+ if (*src == '(' || *src == ')' || *src == ' ')
+ *dest++ = '\\';
+ *dest = *src;
+ }
+ *dest = 0;
+ return buf;
+}
+
/* The main function. */
int
@@ -739,6 +767,7 @@ main (argc, argv)
char *target;
char *preprocessor;
char *preprocargs;
+ const char *quotedarg;
int language;
struct res_directory *resources;
@@ -765,7 +794,7 @@ main (argc, argv)
preprocargs = NULL;
language = -1;
- while ((c = getopt_long (argc, argv, "i:o:I:O:F:", long_options,
+ while ((c = getopt_long (argc, argv, "i:o:I:O:F:D:", long_options,
(int *) 0)) != EOF)
{
switch (c)
@@ -794,18 +823,21 @@ main (argc, argv)
preprocessor = optarg;
break;
+ case 'D':
case OPTION_DEFINE:
if (preprocargs == NULL)
{
- preprocargs = xmalloc (strlen (optarg) + 3);
- sprintf (preprocargs, "-D%s", optarg);
+ quotedarg = quot (optarg);
+ preprocargs = xmalloc (strlen (quotedarg) + 3);
+ sprintf (preprocargs, "-D%s", quotedarg);
}
else
{
char *n;
- n = xmalloc (strlen (preprocargs) + strlen (optarg) + 4);
- sprintf (n, "%s -D%s", preprocargs, optarg);
+ quotedarg = quot (optarg);
+ n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 4);
+ sprintf (n, "%s -D%s", preprocargs, quotedarg);
free (preprocargs);
preprocargs = n;
}
@@ -814,15 +846,17 @@ main (argc, argv)
case OPTION_INCLUDE_DIR:
if (preprocargs == NULL)
{
- preprocargs = xmalloc (strlen (optarg) + 3);
- sprintf (preprocargs, "-I%s", optarg);
+ quotedarg = quot (optarg);
+ preprocargs = xmalloc (strlen (quotedarg) + 3);
+ sprintf (preprocargs, "-I%s", quotedarg);
}
else
{
char *n;
- n = xmalloc (strlen (preprocargs) + strlen (optarg) + 4);
- sprintf (n, "%s -I%s", preprocargs, optarg);
+ quotedarg = quot (optarg);
+ n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 4);
+ sprintf (n, "%s -I%s", preprocargs, quotedarg);
free (preprocargs);
preprocargs = n;
}