Changeset 618 for trunk/src/binutils/binutils/bucomm.c
- Timestamp:
- Aug 16, 2003, 11:33:53 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/binutils/binutils/bucomm.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 1 1 /* 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 3 3 Free Software Foundation, Inc. 4 4 … … 25 25 26 26 #include "bfd.h" 27 #include "bfdver.h" 27 28 #include "libiberty.h" 28 29 #include "bucomm.h" 29 30 #include "filenames.h" 31 #include "libbfd.h" 30 32 31 33 #include <sys/stat.h> … … 38 40 #endif 39 41 40 41 /* Error reporting */ 42 static const char * endian_string PARAMS ((enum bfd_endian)); 43 static int display_target_list PARAMS ((void)); 44 static int display_info_table PARAMS ((int, int)); 45 static int display_target_tables PARAMS ((void)); 46 47 48 /* Error reporting. */ 42 49 43 50 char *program_name; … … 45 52 void 46 53 bfd_nonfatal (string) 47 CONSTchar *string;48 { 49 CONSTchar *errmsg = bfd_errmsg (bfd_get_error ());54 const char *string; 55 { 56 const char *errmsg = bfd_errmsg (bfd_get_error ()); 50 57 51 58 if (string) … … 57 64 void 58 65 bfd_fatal (string) 59 CONSTchar *string;66 const char *string; 60 67 { 61 68 bfd_nonfatal (string); … … 73 80 } 74 81 75 #ifdef ANSI_PROTOTYPES 76 void 77 fatal (const char *format, ...) 78 { 79 va_list args; 80 81 va_start (args, format); 82 void 83 fatal VPARAMS ((const char *format, ...)) 84 { 85 VA_OPEN (args, format); 86 VA_FIXEDARG (args, const char *, format); 87 82 88 report (format, args); 83 va_end(args);89 VA_CLOSE (args); 84 90 xexit (1); 85 91 } 86 92 87 93 void 88 non_fatal (const char *format, ...)89 { 90 va_list args;91 92 va_start (args, format); 94 non_fatal VPARAMS ((const char *format, ...)) 95 { 96 VA_OPEN (args, format); 97 VA_FIXEDARG (args, const char *, format); 98 93 99 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 } 124 102 125 103 /* Set the default BFD target based on the configured target. Doing … … 139 117 } 140 118 141 /* After a falsereturn from bfd_check_format_matches with119 /* After a FALSE return from bfd_check_format_matches with 142 120 bfd_get_error () == bfd_error_file_ambiguously_recognized, print 143 121 the possible matching targets. */ … … 160 138 FILE *f; 161 139 { 162 extern const bfd_target *const *bfd_target_vector;163 140 int t; 141 const char **targ_names = bfd_target_list (); 164 142 165 143 if (name == NULL) … … 167 145 else 168 146 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]); 171 150 fprintf (f, "\n"); 151 free (targ_names); 152 } 153 154 /* List the supported architectures. */ 155 156 void 157 list_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 177 static const char * 178 endian_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 192 static int 193 display_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 244 static int 245 display_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 321 static int 322 display_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 360 int 361 display_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; 172 368 } 173 369 … … 181 377 FILE *file; 182 378 bfd *abfd; 183 b oolean verbose;379 bfd_boolean verbose; 184 380 { 185 381 struct stat buf; … … 192 388 char timebuf[40]; 193 389 time_t when = buf.st_mtime; 194 CONST char *ctime_result = (CONSTchar *) ctime (&when);390 const char *ctime_result = (const char *) ctime (&when); 195 391 196 392 /* POSIX format: skip weekday and seconds from ctime output. */ … … 219 415 #if defined (__EMX__) 220 416 char *slash = _getname (filename); 221 if (slash == filename) 222 slash = NULL; 223 else 224 slash -= 1; 417 slash = (slash == filename) ? NULL : slash - 1; 225 418 #else /* not __EMX__ */ 226 419 char *slash = strrchr (filename, '/'); … … 279 472 280 473 ret = bfd_scan_vma (s, &end, 0); 281 474 282 475 if (*end != '\0') 283 476 fatal (_("%s: bad number: %s"), arg, s); -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.