X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Fwindmc.c;h=97a43c114310255b06e45f573b06a1c72d426974;hb=b6fb30eda72b7fc3a6214ed2787f80971f66810d;hp=283c2657506d79dcf875e6046cc8b7c38e0d3977;hpb=0af1713e7cd57b52f6c81f73aa58934132198880;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/windmc.c b/binutils/windmc.c index 283c265750..97a43c1143 100644 --- a/binutils/windmc.c +++ b/binutils/windmc.c @@ -1,6 +1,5 @@ /* windmc.c -- a program to compile Windows message files. - Copyright 2007, 2008 - Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. Written by Kai Tietz, Onevision. This file is part of GNU Binutils. @@ -51,11 +50,6 @@ typedef struct mc_msg_item struct bin_messagetable_item *res; } mc_msg_item; -/* 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; - int target_is_bigendian = 0; const char *def_target_arch; @@ -175,7 +169,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); } static FILE * @@ -192,7 +186,7 @@ mc_create_path_text_file (const char *path, const char *ext) sprintf (hsz, "%s%s%s", (path != NULL ? path : ""), mcset_mc_basename, (ext != NULL ? ext : "")); if ((ret = fopen (hsz, "wb")) == NULL) - fatal (_("can't create %s file ,%s' for output.\n"), (ext ? ext : "text"), hsz); + fatal (_("can't create %s file `%s' for output.\n"), (ext ? ext : "text"), hsz); free (hsz); return ret; } @@ -210,7 +204,7 @@ usage (FILE *stream, int status) -C --codepage_in= Set codepage when reading mc text file\n\ -d --decimal_values Print values to text files decimal\n\ -e --extension= Set header extension used on export header file\n\ - -F --target Specify output target for endianess.\n\ + -F --target Specify output target for endianness.\n\ -h --headerdir= Set the export directory for headers\n\ -u --unicode_in Read input file as UTF16 file\n\ -U --unicode_out Write binary messages as UFT16\n\ @@ -236,47 +230,17 @@ usage (FILE *stream, int status) } static void -set_endianess (bfd *abfd, const char *target) +set_endianness (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 ** arches = bfd_arch_list (); - - if (arches && tname) - { - const char ** arch = arches; - - 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++; - } - } - - free (arches); - - if (! def_target_arch) - fatal ("Can't detect architecture."); - } + fatal ("Can't detect target endianness and architecture."); + if (! def_target_arch) + fatal ("Can't detect architecture."); } static int @@ -294,7 +258,7 @@ probe_codepage (rc_uint_type *cp, int *is_uni, const char *pswitch, int defmode) if (*cp != 0 && *cp != CP_UTF16) { fprintf (stderr, _("%s: warning: "), program_name); - fprintf (stderr, _("A codepage was specified switch ,%s' and UTF16.\n"), pswitch); + fprintf (stderr, _("A codepage was specified switch `%s' and UTF16.\n"), pswitch); fprintf (stderr, _("\tcodepage settings are ignored.\n")); } *cp = CP_UTF16; @@ -413,7 +377,7 @@ write_header_define (FILE *fp, const unichar *sym_name, rc_uint_type vid, const if (nl != NULL) { if (mcset_out_values_are_decimal) - fprintf (fp, "//\n// MessageId: 0x%lu\n//\n", (unsigned long) vid); + fprintf (fp, "//\n// MessageId: %lu\n//\n", (unsigned long) vid); else fprintf (fp, "//\n// MessageId: 0x%lx\n//\n", (unsigned long) vid); } @@ -428,7 +392,7 @@ write_header_define (FILE *fp, const unichar *sym_name, rc_uint_type vid, const (tdef ? "(" : ""), (tdef ? tdef : ""), (tdef ? ")" : ""), (unsigned long) vid); else - fprintf (fp, "#define %s %s%s%s 0x%lu\n\n", sym, + fprintf (fp, "#define %s %s%s%s %lu\n\n", sym, (tdef ? "(" : ""), (tdef ? tdef : ""), (tdef ? ")" : ""), (unsigned long) vid); } @@ -734,7 +698,7 @@ windmc_write_bin (const char *filename, mc_node_lang **nl, int elems) dta_off += mi[i].res_len; } sec_length = (dta_off + 3) & ~3; - if (! bfd_set_section_size (mc_bfd.abfd, mc_bfd.sec, sec_length)) + if (!bfd_set_section_size (mc_bfd.sec, sec_length)) bfd_fatal ("bfd_set_section_size"); /* Make sure we write the complete block. */ set_windmc_bfd_content ("\0", sec_length - 1, 1); @@ -857,7 +821,7 @@ write_dbg (FILE *fp) while (h != NULL) { if (h->symbol) - write_dbg_define (fp, h->symbol, mcset_msg_id_typedef); + write_dbg_define (fp, h->symbol, h->id_typecast); h = h->next; } fprintf (fp, " { ("); @@ -908,7 +872,7 @@ write_header (FILE *fp) fprintf (fp, "#define %s 0x%lx\n", convert_unicode_to_ACP (key->sval), (unsigned long) key->nval); else - fprintf (fp, "#define %s 0x%lu\n", convert_unicode_to_ACP (key->sval), + fprintf (fp, "#define %s %lu\n", convert_unicode_to_ACP (key->sval), (unsigned long) key->nval); } } @@ -928,7 +892,7 @@ write_header (FILE *fp) fprintf (fp, "#define %s 0x%lx\n", convert_unicode_to_ACP (key->sval), (unsigned long) key->nval); else - fprintf (fp, "#define %s 0x%lu\n", convert_unicode_to_ACP (key->sval), + fprintf (fp, "#define %s %lu\n", convert_unicode_to_ACP (key->sval), (unsigned long) key->nval); } } @@ -944,7 +908,7 @@ write_header (FILE *fp) fprintf (fp, "%s", s); } if (h->symbol) - write_header_define (fp, h->symbol, h->vid, mcset_msg_id_typedef, h->sub); + write_header_define (fp, h->symbol, h->vid, h->id_typecast, h->sub); h = h->next; } } @@ -960,7 +924,7 @@ mc_unify_path (const char *path) hsz = xmalloc (strlen (path) + 2); strcpy (hsz, path); end = hsz + strlen (hsz); - if (hsz[-1] != '/' && hsz[-1] != '\\') + if (end[-1] != '/' && end[-1] != '\\') strcpy (end, "/"); while ((end = strchr (hsz, '\\')) != NULL) *end = '/'; @@ -988,10 +952,12 @@ main (int argc, char **argv) program_name = argv[0]; xmalloc_set_program_name (program_name); + bfd_set_error_program_name (program_name); expandargv (&argc, &argv); - bfd_init (); + if (bfd_init () != BFD_INIT_MAGIC) + fatal (_("fatal error: libbfd ABI mismatch")); set_default_bfd_target (); target = NULL; @@ -1089,7 +1055,7 @@ main (int argc, char **argv) ++optind; } - set_endianess (NULL, target); + set_endianness (NULL, target); if (input_filename == NULL) { @@ -1144,18 +1110,19 @@ main (int argc, char **argv) unichar *u; rc_uint_type ul; char *buff; - long flen; + bfd_size_type flen; FILE *fp = fopen (input_filename, "rb"); if (!fp) - fatal (_("unable to open file ,%s' for input.\n"), input_filename); + fatal (_("unable to open file `%s' for input.\n"), input_filename); fseek (fp, 0, SEEK_END); flen = ftell (fp); fseek (fp, 0, SEEK_SET); buff = malloc (flen + 3); memset (buff, 0, flen + 3); - fread (buff, 1, flen, fp); + if (fread (buff, 1, flen, fp) < flen) + fatal (_("unable to read contents of %s"), input_filename); fclose (fp); if (mcset_text_in_is_unicode != 1) { @@ -1194,12 +1161,9 @@ main (int argc, char **argv) } write_bin (); - if (mc_nodes_lang) - free (mc_nodes_lang); - if (mc_severity_codes) - free (mc_severity_codes); - if (mc_facility_codes) - free (mc_facility_codes); + free (mc_nodes_lang); + free (mc_severity_codes); + free (mc_facility_codes); xexit (0); return 0;