gas: run the hwcaps-bump tests with 64-bit sparc objects only.
[deliverable/binutils-gdb.git] / binutils / windmc.c
index 5465b351cd77dd1ae6bb8a47a24e3e4a86424228..e4356531a5d75255b7be4e6f15344f8a53a71c33 100644 (file)
@@ -1,13 +1,12 @@
 /* windmc.c -- a program to compile Windows message files.
 /* windmc.c -- a program to compile Windows message files.
-   Copyright 2007
-   Free Software Foundation, Inc.
+   Copyright (C) 2007-2016 Free Software Foundation, Inc.
    Written by Kai Tietz, Onevision.
 
    This file is part of GNU Binutils.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    Written by Kai Tietz, Onevision.
 
    This file is part of GNU Binutils.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -20,6 +19,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
+
 /* This program can read and comile Windows message format.
 
    It is based on information taken from the following sources:
 /* This program can read and comile Windows message format.
 
    It is based on information taken from the following sources:
@@ -50,11 +50,6 @@ typedef struct mc_msg_item
   struct bin_messagetable_item *res;
 } 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;
 
 int target_is_bigendian = 0;
 const char *def_target_arch;
 
@@ -174,7 +169,7 @@ res_init (void)
 void *
 res_alloc (rc_uint_type bytes)
 {
 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 *
 }
 
 static FILE *
@@ -191,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)
   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;
 }
   free (hsz);
   return ret;
 }
@@ -209,7 +204,7 @@ usage (FILE *stream, int status)
   -C --codepage_in=<val>       Set codepage when reading mc text file\n\
   -d --decimal_values          Print values to text files decimal\n\
   -e --extension=<extension>   Set header extension used on export header file\n\
   -C --codepage_in=<val>       Set codepage when reading mc text file\n\
   -d --decimal_values          Print values to text files decimal\n\
   -e --extension=<extension>   Set header extension used on export header file\n\
-  -F --target <target>         Specify output target for endianess.\n\
+  -F --target <target>         Specify output target for endianness.\n\
   -h --headerdir=<directory>   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\
   -h --headerdir=<directory>   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\
@@ -235,39 +230,17 @@ usage (FILE *stream, int status)
 }
 
 static void
 }
 
 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;
 {
   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)
   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.");
-  }
+    fatal ("Can't detect target endianness and architecture.");
+  if (! def_target_arch)
+    fatal ("Can't detect architecture.");
 }
 
 static int
 }
 
 static int
@@ -285,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);
       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;
          fprintf (stderr, _("\tcodepage settings are ignored.\n"));
        }
       *cp = CP_UTF16;
@@ -372,7 +345,8 @@ convert_unicode_to_ACP (const unichar *usz)
     return NULL;
   codepage_from_unicode (&l, usz, &s, mcset_codepage_out);
   if (! s)
     return NULL;
   codepage_from_unicode (&l, usz, &s, mcset_codepage_out);
   if (! s)
-    fatal ("unicode string not mappable to ASCII codepage 0x%lx.\n", (long) mcset_codepage_out);
+    fatal ("unicode string not mappable to ASCII codepage 0x%lx.\n",
+          (unsigned long) mcset_codepage_out);
   return s;
 }
 
   return s;
 }
 
@@ -698,13 +672,11 @@ windmc_write_bin (const char *filename, mc_node_lang **nl, int elems)
   if (elems <= 0)
     return;
   mc_bfd.abfd = windmc_open_as_binary (filename);
   if (elems <= 0)
     return;
   mc_bfd.abfd = windmc_open_as_binary (filename);
-  mc_bfd.sec = bfd_make_section (mc_bfd.abfd, ".data");
+  mc_bfd.sec = bfd_make_section_with_flags (mc_bfd.abfd, ".data",
+                                           (SEC_HAS_CONTENTS | SEC_ALLOC
+                                            | SEC_LOAD | SEC_DATA));
   if (mc_bfd.sec == NULL)
     bfd_fatal ("bfd_make_section");
   if (mc_bfd.sec == NULL)
     bfd_fatal ("bfd_make_section");
-  if (! bfd_set_section_flags (mc_bfd.abfd, mc_bfd.sec,
-                              (SEC_HAS_CONTENTS | SEC_ALLOC
-                               | SEC_LOAD | SEC_DATA)))
-    bfd_fatal ("bfd_set_section_flags");
   /* Requiring this is probably a bug in BFD.  */
   mc_bfd.sec->output_section = mc_bfd.sec;
 
   /* Requiring this is probably a bug in BFD.  */
   mc_bfd.sec->output_section = mc_bfd.sec;
 
@@ -796,8 +768,8 @@ write_rc (FILE *fp)
   int i, l;
 
   fprintf (fp,
   int i, l;
 
   fprintf (fp,
-    "/* Do not edit this file manually.\n"
-    "   This file is autogenerated by windmc.  */\n\n");
+          "/* Do not edit this file manually.\n"
+          "   This file is autogenerated by windmc.  */\n\n");
   if (! mc_nodes_lang_count)
     return;
   n = NULL;
   if (! mc_nodes_lang_count)
     return;
   n = NULL;
@@ -809,10 +781,11 @@ write_rc (FILE *fp)
       ++i;
       n = mc_nodes_lang[l];
       fprintf (fp, "\n// Country: %s\n// Language: %s\n#pragma code_page(%u)\n",
       ++i;
       n = mc_nodes_lang[l];
       fprintf (fp, "\n// Country: %s\n// Language: %s\n#pragma code_page(%u)\n",
-       n->lang->lang_info.country, n->lang->lang_info.name,
-       (unsigned) n->lang->lang_info.wincp);
-      fprintf (fp, "LANGUAGE 0x%lx, 0x%lx\n", (long) (n->lang->nval & 0x3ff),
-       (long) ((n->lang->nval & 0xffff) >> 10));
+              n->lang->lang_info.country, n->lang->lang_info.name,
+              (unsigned) n->lang->lang_info.wincp);
+      fprintf (fp, "LANGUAGE 0x%lx, 0x%lx\n",
+              (unsigned long) (n->lang->nval & 0x3ff),
+              (unsigned long) ((n->lang->nval & 0xffff) >> 10));
       fprintf (fp, "1 MESSAGETABLE \"");
       if (mcset_prefix_bin)
        fprintf (fp, "%s_", mcset_mc_basename);
       fprintf (fp, "1 MESSAGETABLE \"");
       if (mcset_prefix_bin)
        fprintf (fp, "%s_", mcset_mc_basename);
@@ -979,6 +952,7 @@ main (int argc, char **argv)
 
   program_name = argv[0];
   xmalloc_set_program_name (program_name);
 
   program_name = argv[0];
   xmalloc_set_program_name (program_name);
+  bfd_set_error_program_name (program_name);
 
   expandargv (&argc, &argv);
 
 
   expandargv (&argc, &argv);
 
@@ -1080,7 +1054,7 @@ main (int argc, char **argv)
       ++optind;
     }
 
       ++optind;
     }
 
-  set_endianess (NULL, target);
+  set_endianness (NULL, target);
 
   if (input_filename == NULL)
     {
 
   if (input_filename == NULL)
     {
@@ -1135,18 +1109,19 @@ main (int argc, char **argv)
     unichar *u;
     rc_uint_type ul;
     char *buff;
     unichar *u;
     rc_uint_type ul;
     char *buff;
-    long flen;
+    bfd_size_type flen;
     FILE *fp = fopen (input_filename, "rb");
 
     if (!fp)
     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);
 
     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)
       {
     fclose (fp);
     if (mcset_text_in_is_unicode != 1)
       {
This page took 0.025601 seconds and 4 git commands to generate.