diff options
Diffstat (limited to 'binutils/windres.c')
-rw-r--r-- | binutils/windres.c | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/binutils/windres.c b/binutils/windres.c index 7de28c259e6..0ccd909404c 100644 --- a/binutils/windres.c +++ b/binutils/windres.c @@ -46,6 +46,10 @@ #include <ctype.h> #include <time.h> +/* used by resrc.c at least */ + +int verbose = 0; + /* An enumeration of format types. */ enum res_format @@ -122,6 +126,7 @@ static const struct option long_options[] = {"output-format", required_argument, 0, 'O'}, {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR}, {"target", required_argument, 0, 'F'}, + {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, OPTION_VERSION}, {"yydebug", no_argument, 0, OPTION_YYDEBUG}, {0, no_argument, 0, 0} @@ -705,7 +710,9 @@ Options:\n\ -F TARGET, --target TARGET Specify COFF target\n\ --preprocessor PROGRAM Program to use to preprocess rc file\n\ --include-dir DIR Include directory when preprocessing rc file\n\ - --define SYM[=VAL] Define SYM when preprocessing rc file\n\ + -DSYM[=VAL], --define SYM[=VAL]\n\ + Define SYM when preprocessing rc file\n\ + -v Verbose - tells you what it's doing\n\ --language VAL Set language when reading rc file\n")); #ifdef YYDEBUG fprintf (stream, _("\ @@ -724,6 +731,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 +774,7 @@ main (argc, argv) char *target; char *preprocessor; char *preprocargs; + const char *quotedarg; int language; struct res_directory *resources; @@ -765,7 +801,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:v", long_options, (int *) 0)) != EOF) { switch (c) @@ -794,35 +830,44 @@ 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; } break; + case 'v': + verbose ++; + break; + 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; } |