X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=binutils%2Fwindres.c;h=05b7559f7447a4fc8fa36b277bd32391c87007b0;hb=7603b4ae74ed1762665b19cebac5d254d1154383;hp=ac643ad59a01eeed8633951c3a7ee0ae6fbf0e9f;hpb=32866df75ece22ec1fd88e99e3c5effe9238e072;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/windres.c b/binutils/windres.c index ac643ad59a..05b7559f74 100644 --- a/binutils/windres.c +++ b/binutils/windres.c @@ -1,6 +1,6 @@ /* windres.c -- a program to manipulate Windows resources - Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 - Free Software Foundation, Inc. + Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, + 2009 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. Rewritten by Kai Tietz, Onevision. @@ -45,11 +45,7 @@ #include "safe-ctype.h" #include "obstack.h" #include "windres.h" - -/* Defined in bfd/binary.c. Used to set architecture and machine of input - binary files. */ -extern enum bfd_architecture bfd_external_binary_architecture; -extern unsigned long bfd_external_machine; +#include /* Used by resrc.c at least. */ @@ -157,7 +153,7 @@ res_init (void) void * res_alloc (rc_uint_type bytes) { - return (void *) obstack_alloc (&res_obstack, (size_t) bytes); + return obstack_alloc (&res_obstack, (size_t) bytes); } /* We also use an obstack to save memory used while writing out a set @@ -178,7 +174,7 @@ reswr_init (void) void * reswr_alloc (rc_uint_type bytes) { - return (void *) obstack_alloc (&reswr_obstack, (size_t) bytes); + return obstack_alloc (&reswr_obstack, (size_t) bytes); } /* Open a file using the include directory search list. */ @@ -731,12 +727,15 @@ quot (const char *string) /* Long options. */ -/* 150 isn't special; it's just an arbitrary non-ASCII char value. */ - -#define OPTION_PREPROCESSOR 150 -#define OPTION_USE_TEMP_FILE (OPTION_PREPROCESSOR + 1) -#define OPTION_NO_USE_TEMP_FILE (OPTION_USE_TEMP_FILE + 1) -#define OPTION_YYDEBUG (OPTION_NO_USE_TEMP_FILE + 1) +enum option_values +{ + /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ + OPTION_PREPROCESSOR = 150, + OPTION_USE_TEMP_FILE, + OPTION_NO_USE_TEMP_FILE, + OPTION_YYDEBUG, + OPTION_INCLUDE_DIR +}; static const struct option long_options[] = { @@ -746,7 +745,7 @@ static const struct option long_options[] = {"output-format", required_argument, 0, 'O'}, {"target", required_argument, 0, 'F'}, {"preprocessor", required_argument, 0, OPTION_PREPROCESSOR}, - {"include-dir", required_argument, 0, 'I'}, + {"include-dir", required_argument, 0, OPTION_INCLUDE_DIR}, {"define", required_argument, 0, 'D'}, {"undefine", required_argument, 0, 'U'}, {"verbose", no_argument, 0, 'v'}, @@ -765,6 +764,12 @@ windres_add_include_dir (const char *p) { struct include_dir *n, **pp; + /* Computing paths is often complicated and error prone. + The easiest way to check for mistakes is at the time + we add them to include_dirs. */ + assert (p != NULL); + assert (*p != '\0'); + n = xmalloc (sizeof *n); n->next = NULL; n->dir = (char * ) p; @@ -917,12 +922,27 @@ main (int argc, char **argv) input_format_tmp = format_from_name (optarg, 0); if (input_format_tmp != RES_FORMAT_UNKNOWN) { - fprintf (stderr, - _("Option -I is deprecated for setting the input format, please use -J instead.\n")); - input_format = input_format_tmp; - break; + struct stat statbuf; + char modebuf[11]; + + if (stat (optarg, & statbuf) == 0 + /* Coded this way to avoid importing knowledge of S_ISDIR into this file. */ + && (mode_string (statbuf.st_mode, modebuf), modebuf[0] == 'd')) + /* We have a -I option with a directory name that just happens + to match a format name as well. eg: -I res Assume that the + user knows what they are doing and do not complain. */ + ; + else + { + fprintf (stderr, + _("Option -I is deprecated for setting the input format, please use -J instead.\n")); + input_format = input_format_tmp; + break; + } } + /* Fall through. */ + case OPTION_INCLUDE_DIR: if (preprocargs == NULL) { quotedarg = quot (optarg); @@ -1056,38 +1076,18 @@ main (int argc, char **argv) return 0; } -static void set_endianess (bfd *abfd, const char *target) +static void +set_endianess (bfd *abfd, const char *target) { const bfd_target *target_vec; def_target_arch = NULL; - target_vec = bfd_find_target (target, abfd); + target_vec = bfd_get_target_info (target, abfd, &target_is_bigendian, NULL, + &def_target_arch); if (! target_vec) fatal ("Can't detect target endianess and architecture."); - target_is_bigendian = ((target_vec->byteorder == BFD_ENDIAN_BIG) ? 1 : 0); - { - const char *tname = target_vec->name; - const char **arch = bfd_arch_list(); - if (arch && tname) - { - if (strchr (tname, '-') != NULL) - tname = strchr (tname, '-') + 1; - while (*arch != NULL) - { - const char *in_a = strstr (*arch, tname); - char end_ch = (in_a ? in_a[strlen(tname)] : 0); - if (in_a && (in_a == *arch || in_a[-1] == ':') - && end_ch == 0) - { - def_target_arch = *arch; - break; - } - arch++; - } - } - if (! def_target_arch) - fatal ("Can't detect architecture."); - } + if (! def_target_arch) + fatal ("Can't detect architecture."); } bfd * @@ -1150,8 +1150,8 @@ set_windres_bfd (windres_bfd *wrbfd, bfd *abfd, asection *sec, rc_uint_type kind } void -set_windres_bfd_content(windres_bfd *wrbfd, const void *data, rc_uint_type off, - rc_uint_type length) +set_windres_bfd_content (windres_bfd *wrbfd, const void *data, rc_uint_type off, + rc_uint_type length) { if (WR_KIND(wrbfd) != WR_KIND_TARGET) { @@ -1163,8 +1163,8 @@ set_windres_bfd_content(windres_bfd *wrbfd, const void *data, rc_uint_type off, } void -get_windres_bfd_content(windres_bfd *wrbfd, void *data, rc_uint_type off, - rc_uint_type length) +get_windres_bfd_content (windres_bfd *wrbfd, void *data, rc_uint_type off, + rc_uint_type length) { if (WR_KIND(wrbfd) != WR_KIND_TARGET) {