Add program name to some error messages.
than the corresponding files.
*/
int newer_only = 0;
-/* write a __.SYMDEF member into the modified archive. */
-boolean write_armap = false;
-/*
- Nonzero means don't update __.SYMDEF unless command line explicitly
- requested it
-*/
-int ignore_symdef = 0;
+
+/* Controls the writing of an archive symbol table (in BSD: a __.SYMDEF
+ member). -1 means we've been explicitly asked to not write a symbol table;
+ +1 means we've been explictly asked to write it;
+ 0 is the default.
+ Traditionally, the default in BSD has been to not write the table.
+ However, for Posix.2 compliance the default is now to write a symbol table
+ if any of the members are object files. */
+int write_armap = 0;
+
/*
Nonzero means it's the name of an existing member; position new or moved
files with respect to this one.
boolean operation_alters_arch = false;
+extern char *program_version;
+
void
do_show_version ()
{
- extern char *program_version;
printf ("%s version %s\n", program_name, program_version);
}
+void
+usage ()
+{
+ fprintf(stderr, "ar %s\n\
+Usage: %s [-]{dmpqrtx}[abcilosuv] [membername] archive-file file...\n\
+ %s -M [<mri-script]\n",
+ program_version, program_name, program_name);
+ exit(1);
+}
+
/*
The option parsing should be in its own function. It will be when I have
getopt working.
++temp;
if (is_ranlib > 0 || (is_ranlib < 0 && strcmp(temp, "ranlib") == 0)) {
if (argc < 2)
- fatal("Too few command arguments.");
+ usage ();
arg_ptr = argv[1];
if (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "-v") == 0) {
do_show_version();
}
if (argc < 2)
- fatal("Too few command arguments.");
+ usage ();
arg_ptr = argv[1];
show_version = true;
break;
case 's':
- write_armap = true;
+ write_armap = 1;
break;
case 'u':
newer_only = 1;
if (show_version)
exit(0);
else
- fatal("Too few command arguments.");
+ usage ();
if (mri_mode) {
mri_emul();
}
else {
if ((operation == none || operation == print_table)
- && write_armap == true)
+ && write_armap == 1)
ranlib_only(argv[2]);
if (operation == none)
inarch_filename = argv[arg_index++];
- if (arg_index < argc) {
- files = argv + arg_index;
- while (arg_index < argc)
- if (!strcmp(argv[arg_index++], "__.SYMDEF")) {
- ignore_symdef = 1;
- break;
- }
- }
- else
- files = NULL;
+ files = arg_index < argc ? argv + arg_index : NULL;
if (operation == quick_append) {
if (files != NULL)
break;
case replace:
- if (files != NULL || write_armap)
+ if (files != NULL || write_armap > 0)
replace_members(files);
break;
#endif
if (inarch == NULL) {
bloser:
+ fprintf (stderr, "%s: ", program_name);
bfd_perror(archive_filename);
exit(1);
}
struct utimbuf tb;
tb.actime = buf.st_mtime;
tb.modtime = buf.st_mtime;
- utime(abfd->filename, tb); /* FIXME check result */
+ utime(abfd->filename, &tb); /* FIXME check result */
#else /* ! POSIX_UTIME */
#ifdef USE_UTIME
long tb[2];
temp = bfd_openr(archive_filename, NULL);
#endif
if (temp == NULL) {
+ fprintf (stderr, "%s: ", program_name);
bfd_perror(archive_filename);
exit(1);
}
for (; files_to_append && *files_to_append; ++files_to_append) {
struct ar_hdr *hdr = bfd_special_undocumented_glue(temp, *files_to_append);
if (hdr == NULL) {
+ fprintf (stderr, "%s: ", program_name);
bfd_perror(*files_to_append);
exit(1);
}
ifile = fopen(*files_to_append, FOPEN_RB);
if (ifile == NULL)
+ {
bfd_perror(program_name);
+ }
if (stat(*files_to_append, &sbuf) != 0)
+ {
+ fprintf (stderr, "%s: ", program_name);
bfd_perror(*files_to_append);
+ }
tocopy = sbuf.st_size;
bfd_fatal(inarch->filename);
bfd_set_format(obfd, bfd_archive);
- obfd->has_armap = write_armap;
+
+ /* Request writing the archive symbol table unless we've
+ been explicitly requested not to. */
+ obfd->has_armap = write_armap >= 0;
if (bfd_set_archive_head(obfd, contents_head) != true)
bfd_fatal(inarch->filename);
/*
In a.out systems, the armap is optional. It's also called
__.SYMDEF. So if the user asked to delete it, we should remember
- that fact. The name is NULL in COFF archives, so using this as a
- key is as good as anything I suppose
- */
+ that fact. This isn't quite right for COFF systems (where
+ __.SYMDEF might be regular member), but it's very unlikely
+ to be a problem. FIXME */
+
if (!strcmp(*files_to_delete, "__.SYMDEF")) {
inarch->has_armap = false;
- write_armap = false;
+ write_armap = -1;
continue;
}
bfd *current;
bfd **current_ptr;
bfd *temp;
- /*
- If the first item in the archive is an __.SYMDEF then remove it
- */
- if (inarch->next &&
- strcmp(inarch->next->filename, "__.SYMDEF") == 0) {
- inarch->next = inarch->next->next;
- }
-
-
while (files_to_move && *files_to_move) {
current_ptr = &inarch->next;
ranlib_only(archname)
char *archname;
{
- write_armap = true;
+ write_armap = 1;
open_inarch(archname);
write_archive();
exit(0);
void
copy_usage()
{
- fprintf(stderr,
- "Usage %s [-vVSgxX] [-I informat] [-O outformat] infile [outfile]\n",
- program_name);
+ fprintf(stderr, "copy %s\n\
+Usage: %s [-vVSgxX] [-I format] [-O format] [-F format]\n\
+ [--format=format] [--target=format] [--input-format=format]\n\
+ [--output-format=format] [--strip-all] [--strip-debug]\n\
+ [--discard-all] [--discard-locals] [--verbose] [--version]\n\
+ infile [outfile]\n",
+ program_version, program_name);
exit(1);
}
void
strip_usage()
{
- fprintf(stderr, "Usage %s [-vVsSgxX] [-I informat] [-O outformat] filename ...\n", program_name);
+ fprintf(stderr, "strip %s\n\
+Usage: %s [-vVsSgxX] [-I format] [-O format] [-F format]\n\
+ [--format=format] [--target=format] [--input-format=format]\n\
+ [--output-format=format] [--strip-all] [--strip-debug]\n\
+ [--discard-all] [--discard-locals] [--verbose] [--version] file...\n",
+ program_version, program_name);
exit(1);
}
{
int i;
int c; /* sez which option char */
- int option_index = 0; /* used by getopt and ignored by us */
program_name = argv[0];
if (is_strip) {
while ((c = getopt_long(argc, argv, "I:O:F:sSgxXVv",
- strip_options, &option_index))
+ strip_options, (int *) 0))
!= EOF) {
switch (c) {
case 'I':
/* Invoked as "copy", not "strip" */
while ((c = getopt_long(argc, argv, "I:s:O:d:F:b:SgxXVv",
- strip_options, &option_index))
+ strip_options, (int *) 0))
!= EOF) {
switch (c) {
case 'I':
display_file PARAMS ((char *filename));
static void
-do_one_rel_file PARAMS ((bfd *file));
+do_one_rel_file PARAMS ((bfd* file, bfd *archive));
static unsigned int
filter_symbols PARAMS ((bfd *file, asymbol **syms, unsigned long symcount));
static void
-print_symbols PARAMS ((bfd *file, asymbol **syms, unsigned long symcount));
+print_symbols PARAMS ((bfd *file, asymbol **syms, unsigned long symcount,
+ bfd *archive));
static void
print_symdef_entry PARAMS ((bfd * abfd));
struct option long_options[] = {
{"debug-syms", no_argument, &print_debug_syms, 1},
{"extern-only", no_argument, &external_only, 1},
- {"no-sort", no_argument, &no_sort, 1},
+ {"no-sort", no_argument, &no_sort, 1},
{"numeric-sort", no_argument, &sort_numerically, 1},
{"print-armap", no_argument, &print_armap, 1},
{"print-file-name", no_argument, &file_on_each_line, 1},
{"reverse-sort", no_argument, &reverse_sort, 1},
- {"target", optional_argument, (int *)NULL, 0},
+ {"target", optional_argument, 0, 200},
{"undefined-only", no_argument, &undefined_only, 1},
- {"version", no_argument, &show_version, 1},
+ {"version", no_argument, &show_version, 1},
{0, no_argument, 0, 0}
};
void
usage ()
{
- fprintf(stderr, "nm %s\nUsage: %s [-agnoprsuV] filename...\n",
+ fprintf(stderr, "nm %s\n\
+Usage: %s [-agnoprsuV] [--debug-syms] [--extern-only] [--print-armap]\n\
+ [--print-file-name] [--numeric-sort] [--no-sort] [--reverse-sort]\n\
+ [--undefined-only] [--target=bfdname] [file...]\n",
program_version, program_name);
- exit(0);
+ exit(1);
}
int
char **argv;
{
int c; /* sez which option char */
- int option_index = 0; /* used by getopt and ignored by us */
int retval;
program_name = *argv;
bfd_init();
- while ((c = getopt_long(argc, argv, "agnoprsuV", long_options, &option_index)) != EOF) {
+ while ((c = getopt_long(argc, argv, "agnoprsuvABV", long_options, (int *) 0)) != EOF) {
switch (c) {
case 'a': print_debug_syms = 1; break;
case 'g': external_only = 1; break;
case 'r': reverse_sort = 1; break;
case 's': print_armap = 1; break;
case 'u': undefined_only = 1; break;
+ case 'v':
case 'V': show_version = 1; break;
- case 0:
- if (!strcmp("target",(long_options[option_index]).name)) {
- target = optarg;
- }
+ /* For MIPS compatibility, -A selects System V style output, -B
+ selects BSD style output. These are not implemented. When
+ they are, they should be added to usage (). */
+ case 'A': break;
+ case 'B': break;
- break; /* we've been given a long option */
+ case 200: /* --target */
+ target = optarg;
+ break;
default:
usage ();
on sucess -- the inverse of the C sense. */
/* OK, all options now parsed. If no filename specified, do a.out. */
- if (option_index == argc) return !display_file ("a.out");
+ if (optind == argc) return !display_file ("a.out");
retval = 0;
show_names = (argc -optind)>1;
file = bfd_openr(filename, target);
if (file == NULL) {
- fprintf (stderr, "\n%s: can't open '%s'.\n", program_name, filename);
+ fprintf (stderr, "%s: ", program_name);
+ bfd_perror (filename);
return false;
}
if (show_names) {
printf ("\n%s:\n",filename);
}
- do_one_rel_file (file);
+ do_one_rel_file (file, NULL);
}
else if (bfd_check_format (file, bfd_archive)) {
if (!bfd_check_format (file, bfd_archive)) {
- fprintf (stderr, "%s: %s: unknown format.\n", program_name, filename);
+ fprintf (stderr, "%s: %s: unknown format\n", program_name, filename);
retval = false;
goto closer;
}
- printf("\n%s:\n", filename);
+ if (!file_on_each_line)
+ printf("\n%s:\n", filename);
if (print_armap) print_symdef_entry (file);
for (;;) {
arfile = bfd_openr_next_archived_file (file, arfile);
if (!bfd_check_format(arfile, bfd_object))
printf("%s: not an object file\n", arfile->filename);
else {
- printf ("\n%s:\n", arfile->filename);
- do_one_rel_file (arfile) ;
+ if (!file_on_each_line)
+ printf ("\n%s:\n", arfile->filename);
+ do_one_rel_file (arfile, file) ;
}
}
}
else {
- fprintf (stderr, "\n%s: %s: unknown format.\n", program_name, filename);
+ fprintf (stderr, "\n%s: %s: unknown format\n", program_name, filename);
retval = false;
}
};
\f
static void
-do_one_rel_file (abfd)
+do_one_rel_file (abfd, archive_bfd)
bfd *abfd;
+ bfd *archive_bfd; /* If non-NULL: archive containing abfd. */
{
unsigned int storage;
asymbol **syms;
nosymz:
fprintf (stderr, "%s: Symflags set but there are none?\n",
bfd_get_filename (abfd));
- exit (1);
+ return;
}
syms = (asymbol **) xmalloc (storage);
if (print_each_filename && !file_on_each_line)
printf("\n%s:\n", bfd_get_filename(abfd));
- print_symbols (abfd, syms, symcount);
+ print_symbols (abfd, syms, symcount, archive_bfd);
free (syms);
}
\f
} else if (external_only) {
keep = ((flags & BSF_GLOBAL)
|| (sym->section == &bfd_und_section)
- || (sym->section == &bfd_com_section));
+ || (bfd_is_com_section (sym->section)));
} else {
keep = 1;
}
}
\f
static void
-print_symbols (abfd, syms, symcount)
+print_symbols (abfd, syms, symcount, archive_bfd)
bfd *abfd;
asymbol **syms;
unsigned long symcount;
+ bfd *archive_bfd;
{
asymbol **sym = syms, **end = syms + symcount;
for (; sym < end; ++sym) {
- if (file_on_each_line) printf("%s:", bfd_get_filename(abfd));
+ if (file_on_each_line) {
+ if (archive_bfd)
+ printf("%s:", bfd_get_filename(archive_bfd));
+ printf("%s:", bfd_get_filename(abfd));
+ }
if (undefined_only) {
if ((*sym)->section == &bfd_und_section)
void
usage ()
{
- fprintf (stderr, "\
-usage: %s [-ahifdrtxsl] [-m machine] [-j section_name]\n\
- [--syms] [--reloc] [--header] [--version] obj ...\n",
- program_name);
+ fprintf (stderr, "objdump %s\n\
+Usage: %s [-ahifdrtxsl] [-m machine] [-j section_name] [-b bfdname]\n\
+ [--syms] [--reloc] [--header] [--version] objfile...\n",
+ program_version, program_name);
exit (1);
}
#ifdef ELF_STAB_DISPLAY
{"stabs", no_argument, &dump_stab_section_info, 1},
#endif
- {0, no_argument, 0, 0}};
+ {0, no_argument, 0, 0}
+};
static void
file = bfd_openr (filename, target);
if (file == NULL)
{
+ fprintf (stderr, "%s: ", program_name);
bfd_perror (filename);
return;
}
if (arfile == NULL)
{
if (bfd_error != no_more_archived_files)
- bfd_perror (bfd_get_filename (file));
+ {
+ fprintf (stderr, "%s: ", program_name);
+ bfd_perror (bfd_get_filename (file));
+ }
return;
}
extern char *optarg;
char *target = default_target;
boolean seenflag = false;
- int ind = 0;
bfd_init ();
program_name = *argv;
- while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options, &ind))
+ while ((c = getopt_long (argc, argv, "ib:m:Vdlfahrtxsj:", long_options,
+ (int *) 0))
!= EOF)
{
seenflag = true;
o - We also handle core files.
o - We also handle archives.
If you write shell scripts which manipulate this info then you may be
- out of luck; there's no +predantic switch.
+ out of luck; there's no --predantic option.
*/
#include "bfd.h"
void
usage ()
{
- fprintf (stderr, "size %s\nUsage: %s -{dox}{AB}V files ...\n",
- program_version, program_name);
- fputs("\t+radix={8|10|16} -- select appropriate output radix.\n\
-\t-d -- output in decimal\n\
-\t-o -- output in octal\n\
-\t-x -- output in hex", stderr);
- fputs("\t+format={Berkeley|SysV} -- select display format.\n\
-\t-A -- SysV(AT&T) format\n\
-\t-B -- BSD format", stderr);
+ fprintf (stderr, "size %s\n\
+Usage: %s [-ABdoxV] [--format=berkeley|sysv] [--radix=8|10|16]\n\
+ [--target=bfdname] [--version] [--help] [file...]\n",
+ program_version, program_name);
#if BSD_DEFAULT
- fputs("\t (Default is +format=Berkeley)", stderr);
+ fputs (" (default is --format=berkeley)\n", stderr);
#else
- fputs("\t (Default is +format=SysV)", stderr);
+ fputs (" (default is --format=sysv)\n", stderr);
#endif
- fputs("\t-V, +version -- display program version, etc.\n\
-\t+help -- this message\n", stderr);
- exit(1);
+ exit (1);
}
-struct option long_options[] = {{"radix", no_argument, 0, 0},
- {"format", required_argument, 0, 0},
- {"version", no_argument, &show_version, 1},
- {"target", optional_argument, NULL, 0},
- {"help", no_argument, &show_help, 1},
- {0, no_argument, 0, 0}};
+struct option long_options[] = {
+ {"format", required_argument, 0, 200},
+ {"radix", required_argument, 0, 201},
+ {"target", required_argument, 0, 202},
+ {"version", no_argument, &show_version, 1},
+ {"help", no_argument, &show_help, 1},
+ {0, no_argument, 0, 0}
+};
int
main (argc, argv)
{
int temp;
int c; /* sez which option char */
- int option_index = 0;
extern int optind; /* steps thru options */
+
program_name = *argv;
bfd_init();
while ((c = getopt_long(argc, argv, "ABVdox", long_options,
- &option_index)) != EOF)
+ (int *) 0)) != EOF)
switch(c) {
- case 0:
- if (!strcmp("format",(long_options[option_index]).name)) {
+ case 200: /* --format */
switch(*optarg) {
case 'B': case 'b': berkeley_format = 1; break;
case 'S': case 's': berkeley_format = 0; break;
- default: printf("Unknown option to +format: %s\n", optarg);
+ default: fprintf(stderr, "invalid argument to --format: %s\n", optarg);
usage();
}
break;
- }
- if (!strcmp("target",(long_options[option_index]).name)) {
+ case 202: /* --target */
target = optarg;
break;
- }
- if (!strcmp("radix",(long_options[option_index]).name)) {
+ case 201: /* --radix */
#ifdef ANSI_LIBRARIES
temp = strtol(optarg, NULL, 10);
#else
default: printf("Unknown radix: %s\n", optarg);
usage();
}
- }
- break;
+ break;
+
case 'A': berkeley_format = 0; break;
case 'B': berkeley_format = 1; break;
case 'V': show_version = 1; break;
file = bfd_openr (filename, target);
if (file == NULL) {
+ fprintf (stderr, "%s: ", program_name);
bfd_perror (filename);
return_code = 1;
return;
arfile = bfd_openr_next_archived_file (file, arfile);
if (arfile == NULL) {
if (bfd_error != no_more_archived_files) {
+ fprintf (stderr, "%s: ", program_name);
bfd_perror (bfd_get_filename (file));
return_code = 2;
}
int width;
bfd_size_type num;
{
- printf ((radix == decimal ? "%-*ld\t" :
- ((radix == octal) ? "%-*lo\t" : "%-*lx\t")), width, (long)num);
+ printf ((radix == decimal ? "%-*lu\t" :
+ ((radix == octal) ? "%-*lo\t" : "%-*lx\t")),
+ width, (unsigned long)num);
}
void
int width;
bfd_size_type num;
{
- printf ((radix == decimal ? "%*ld\t" :
- ((radix == octal) ? "%*lo\t" : "%*lx\t")), width, (long)num);
+ printf ((radix == decimal ? "%*lu\t" :
+ ((radix == octal) ? "%*lo\t" : "%*lx\t")),
+ width, (unsigned long)num);
}
static char *bss_section_name = ".bss";
lprint_number (7, textsize);
lprint_number (7, datasize);
lprint_number (7, bsssize);
- printf (((radix == octal) ? "%-7lo\t%-7lx\t" : "%-7ld\t%-7lx\t"),
- (long)total, (long)total);
+ printf (((radix == octal) ? "%-7lo\t%-7lx\t" : "%-7lu\t%-7lx\t"),
+ (unsigned long)total, (unsigned long)total);
fputs(bfd_get_filename(abfd), stdout);
if (abfd->my_archive) printf (" (ex %s)", abfd->my_archive->filename);
{
bfd_size_type size = bfd_section_size (file, sec);
if (sec!= &bfd_abs_section
- && sec!= &bfd_com_section
+ && ! bfd_is_com_section (sec)
&& sec!=&bfd_und_section)
{