Ignore:
Timestamp:
Aug 16, 2003, 11:33:53 PM (22 years ago)
Author:
bird
Message:

Joined the port of 2.11.2 with 2.14.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/binutils/binutils/bucomm.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r617 r618  
    11/* bucomm.c -- Bin Utils COMmon code.
    2    Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001
     2   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 1998, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
     
    2525
    2626#include "bfd.h"
     27#include "bfdver.h"
    2728#include "libiberty.h"
    2829#include "bucomm.h"
    2930#include "filenames.h"
     31#include "libbfd.h"
    3032
    3133#include <sys/stat.h>
     
    3840#endif
    3941
    40 
    41 /* Error reporting */
     42static const char * endian_string PARAMS ((enum bfd_endian));
     43static int display_target_list PARAMS ((void));
     44static int display_info_table PARAMS ((int, int));
     45static int display_target_tables PARAMS ((void));
     46
     47
     48/* Error reporting.  */
    4249
    4350char *program_name;
     
    4552void
    4653bfd_nonfatal (string)
    47      CONST char *string;
    48 {
    49   CONST char *errmsg = bfd_errmsg (bfd_get_error ());
     54     const char *string;
     55{
     56  const char *errmsg = bfd_errmsg (bfd_get_error ());
    5057
    5158  if (string)
     
    5764void
    5865bfd_fatal (string)
    59      CONST char *string;
     66     const char *string;
    6067{
    6168  bfd_nonfatal (string);
     
    7380}
    7481
    75 #ifdef ANSI_PROTOTYPES
    76 void
    77 fatal (const char *format, ...)
    78 {
    79   va_list args;
    80 
    81   va_start (args, format);
     82void
     83fatal VPARAMS ((const char *format, ...))
     84{
     85  VA_OPEN (args, format);
     86  VA_FIXEDARG (args, const char *, format);
     87
    8288  report (format, args);
    83   va_end (args);
     89  VA_CLOSE (args);
    8490  xexit (1);
    8591}
    8692
    8793void
    88 non_fatal (const char *format, ...)
    89 {
    90   va_list args;
    91 
    92   va_start (args, format);
     94non_fatal VPARAMS ((const char *format, ...))
     95{
     96  VA_OPEN (args, format);
     97  VA_FIXEDARG (args, const char *, format);
     98
    9399  report (format, args);
    94   va_end (args);
    95 }
    96 #else
    97 void
    98 fatal (va_alist)
    99      va_dcl
    100 {
    101   char *Format;
    102   va_list args;
    103 
    104   va_start (args);
    105   Format = va_arg (args, char *);
    106   report (Format, args);
    107   va_end (args);
    108   xexit (1);
    109 }
    110 
    111 void
    112 non_fatal (va_alist)
    113      va_dcl
    114 {
    115   char *Format;
    116   va_list args;
    117 
    118   va_start (args);
    119   Format = va_arg (args, char *);
    120   report (Format, args);
    121   va_end (args);
    122 }
    123 #endif
     100  VA_CLOSE (args);
     101}
    124102
    125103/* Set the default BFD target based on the configured target.  Doing
     
    139117}
    140118
    141 /* After a false return from bfd_check_format_matches with
     119/* After a FALSE return from bfd_check_format_matches with
    142120   bfd_get_error () == bfd_error_file_ambiguously_recognized, print
    143121   the possible matching targets.  */
     
    160138     FILE *f;
    161139{
    162   extern const bfd_target *const *bfd_target_vector;
    163140  int t;
     141  const char **targ_names = bfd_target_list ();
    164142
    165143  if (name == NULL)
     
    167145  else
    168146    fprintf (f, _("%s: supported targets:"), name);
    169   for (t = 0; bfd_target_vector[t] != NULL; t++)
    170     fprintf (f, " %s", bfd_target_vector[t]->name);
     147
     148  for (t = 0; targ_names[t] != NULL; t++)
     149    fprintf (f, " %s", targ_names[t]);
    171150  fprintf (f, "\n");
     151  free (targ_names);
     152}
     153
     154/* List the supported architectures.  */
     155
     156void
     157list_supported_architectures (name, f)
     158     const char *name;
     159     FILE *f;
     160{
     161  const char **arch;
     162
     163  if (name == NULL)
     164    fprintf (f, _("Supported architectures:"));
     165  else
     166    fprintf (f, _("%s: supported architectures:"), name);
     167
     168  for (arch = bfd_arch_list (); *arch; arch++)
     169    fprintf (f, " %s", *arch);
     170  fprintf (f, "\n");
     171}
     172
     173
     174/* The length of the longest architecture name + 1.  */
     175#define LONGEST_ARCH sizeof ("powerpc:common")
     176
     177static const char *
     178endian_string (endian)
     179     enum bfd_endian endian;
     180{
     181  switch (endian)
     182    {
     183    case BFD_ENDIAN_BIG: return "big endian";
     184    case BFD_ENDIAN_LITTLE: return "little endian";
     185    default: return "endianness unknown";
     186    }
     187}
     188
     189/* List the targets that BFD is configured to support, each followed
     190   by its endianness and the architectures it supports.  */
     191
     192static int
     193display_target_list ()
     194{
     195  char *dummy_name;
     196  int t;
     197  int ret = 1;
     198
     199  dummy_name = make_temp_file (NULL);
     200  for (t = 0; bfd_target_vector[t]; t++)
     201    {
     202      const bfd_target *p = bfd_target_vector[t];
     203      bfd *abfd = bfd_openw (dummy_name, p->name);
     204      int a;
     205
     206      printf ("%s\n (header %s, data %s)\n", p->name,
     207              endian_string (p->header_byteorder),
     208              endian_string (p->byteorder));
     209
     210      if (abfd == NULL)
     211        {
     212          bfd_nonfatal (dummy_name);
     213          ret = 0;
     214          continue;
     215        }
     216
     217      if (! bfd_set_format (abfd, bfd_object))
     218        {
     219          if (bfd_get_error () != bfd_error_invalid_operation)
     220            {
     221              bfd_nonfatal (p->name);
     222              ret = 0;
     223            }
     224          bfd_close_all_done (abfd);
     225          continue;
     226        }
     227
     228      for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
     229        if (bfd_set_arch_mach (abfd, (enum bfd_architecture) a, 0))
     230          printf ("  %s\n",
     231                  bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
     232      bfd_close_all_done (abfd);
     233    }
     234  unlink (dummy_name);
     235  free (dummy_name);
     236
     237  return ret;
     238}
     239
     240/* Print a table showing which architectures are supported for entries
     241   FIRST through LAST-1 of bfd_target_vector (targets across,
     242   architectures down).  */
     243
     244static int
     245display_info_table (first, last)
     246     int first;
     247     int last;
     248{
     249  int t;
     250  int a;
     251  int ret = 1;
     252  char *dummy_name;
     253
     254  /* Print heading of target names.  */
     255  printf ("\n%*s", (int) LONGEST_ARCH, " ");
     256  for (t = first; t < last && bfd_target_vector[t]; t++)
     257    printf ("%s ", bfd_target_vector[t]->name);
     258  putchar ('\n');
     259
     260  dummy_name = make_temp_file (NULL);
     261  for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
     262    if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
     263      {
     264        printf ("%*s ", (int) LONGEST_ARCH - 1,
     265                bfd_printable_arch_mach (a, 0));
     266        for (t = first; t < last && bfd_target_vector[t]; t++)
     267          {
     268            const bfd_target *p = bfd_target_vector[t];
     269            bfd_boolean ok = TRUE;
     270            bfd *abfd = bfd_openw (dummy_name, p->name);
     271
     272            if (abfd == NULL)
     273              {
     274                bfd_nonfatal (p->name);
     275                ret = 0;
     276                ok = FALSE;
     277              }
     278
     279            if (ok)
     280              {
     281                if (! bfd_set_format (abfd, bfd_object))
     282                  {
     283                    if (bfd_get_error () != bfd_error_invalid_operation)
     284                      {
     285                        bfd_nonfatal (p->name);
     286                        ret = 0;
     287                      }
     288                    ok = FALSE;
     289                  }
     290              }
     291
     292            if (ok)
     293              {
     294                if (! bfd_set_arch_mach (abfd, a, 0))
     295                  ok = FALSE;
     296              }
     297
     298            if (ok)
     299              printf ("%s ", p->name);
     300            else
     301              {
     302                int l = strlen (p->name);
     303                while (l--)
     304                  putchar ('-');
     305                putchar (' ');
     306              }
     307            if (abfd != NULL)
     308              bfd_close_all_done (abfd);
     309          }
     310        putchar ('\n');
     311      }
     312  unlink (dummy_name);
     313  free (dummy_name);
     314
     315  return ret;
     316}
     317
     318/* Print tables of all the target-architecture combinations that
     319   BFD has been configured to support.  */
     320
     321static int
     322display_target_tables ()
     323{
     324  int t;
     325  int columns;
     326  int ret = 1;
     327  char *colum;
     328
     329  columns = 0;
     330  colum = getenv ("COLUMNS");
     331  if (colum != NULL)
     332    columns = atoi (colum);
     333  if (columns == 0)
     334    columns = 80;
     335
     336  t = 0;
     337  while (bfd_target_vector[t] != NULL)
     338    {
     339      int oldt = t, wid;
     340
     341      wid = LONGEST_ARCH + strlen (bfd_target_vector[t]->name) + 1;
     342      ++t;
     343      while (wid < columns && bfd_target_vector[t] != NULL)
     344        {
     345          int newwid;
     346
     347          newwid = wid + strlen (bfd_target_vector[t]->name) + 1;
     348          if (newwid >= columns)
     349            break;
     350          wid = newwid;
     351          ++t;
     352        }
     353      if (! display_info_table (oldt, t))
     354        ret = 0;
     355    }
     356
     357  return ret;
     358}
     359
     360int
     361display_info ()
     362{
     363  printf (_("BFD header file version %s\n"), BFD_VERSION_STRING);
     364  if (! display_target_list () || ! display_target_tables ())
     365    return 1;
     366  else
     367    return 0;
    172368}
    173369
     
    181377     FILE *file;
    182378     bfd *abfd;
    183      boolean verbose;
     379     bfd_boolean verbose;
    184380{
    185381  struct stat buf;
     
    192388          char timebuf[40];
    193389          time_t when = buf.st_mtime;
    194           CONST char *ctime_result = (CONST char *) ctime (&when);
     390          const char *ctime_result = (const char *) ctime (&when);
    195391
    196392          /* POSIX format:  skip weekday and seconds from ctime output.  */
     
    219415#if defined (__EMX__)
    220416  char *slash = _getname (filename);
    221   if (slash == filename)
    222     slash = NULL;
    223   else
    224     slash -= 1;
     417  slash = (slash == filename) ? NULL : slash - 1;
    225418#else /* not __EMX__ */
    226419  char *slash = strrchr (filename, '/');
     
    279472
    280473  ret = bfd_scan_vma (s, &end, 0);
    281  
     474
    282475  if (*end != '\0')
    283476    fatal (_("%s: bad number: %s"), arg, s);
Note: See TracChangeset for help on using the changeset viewer.