From 1154c3efa17b5488a3f2931eeebf19c44fb1b8a1 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 8 Dec 2010 04:58:23 +0000 Subject: [PATCH] * ar.c (main): Split ranlib path. (ranlib_usage): New (ranlib_main): New --- binutils/ChangeLog | 6 ++ binutils/ar.c | 197 +++++++++++++++++++++++++-------------------- 2 files changed, 117 insertions(+), 86 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 5e71463c11c..adc9ab62d85 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2010-12-08 Arnaud Lacombe + + * ar.c (main): Split ranlib path. + (ranlib_usage): New + (ranlib_main): New + 2010-12-03 Doug Evans * dwarf.c: #include "bfd_stdint.h". diff --git a/binutils/ar.c b/binutils/ar.c index a08a991290a..29dcb4a24ef 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -225,67 +225,78 @@ usage (int help) s = help ? stdout : stderr; - if (! is_ranlib) - { - /* xgettext:c-format */ - const char * command_line = + /* xgettext:c-format */ + const char * command_line = #if BFD_SUPPORTS_PLUGINS _("Usage: %s [emulation options] [--plugin ] [-]{dmpqrstx}[abcfilNoPsSuvV] [member-name] [count] archive-file file...\n"); #else _("Usage: %s [emulation options] [-]{dmpqrstx}[abcfilNoPsSuvV] [member-name] [count] archive-file file...\n"); #endif - fprintf (s, command_line, program_name); - - /* xgettext:c-format */ - fprintf (s, _(" %s -M [ - read options from \n")); + fprintf (s, command_line, program_name); + + /* xgettext:c-format */ + fprintf (s, _(" %s -M [ - read options from \n")); #if BFD_SUPPORTS_PLUGINS - fprintf (s, _(" optional:\n")); - fprintf (s, _(" --plugin

- load the specified plugin\n")); + fprintf (s, _(" optional:\n")); + fprintf (s, _(" --plugin

- load the specified plugin\n")); #endif - ar_emul_usage (s); - } - else - { - /* xgettext:c-format */ - fprintf (s, _("Usage: %s [options] archive\n"), program_name); - fprintf (s, _(" Generate an index to speed access to archives\n")); - fprintf (s, _(" The options are:\n\ + + ar_emul_usage (s); + + list_supported_targets (program_name, s); + + if (REPORT_BUGS_TO[0] && help) + fprintf (s, _("Report bugs to %s\n"), REPORT_BUGS_TO); + + xexit (help ? 0 : 1); +} + +static void +ranlib_usage(int help) +{ + FILE *s; + + s = help ? stdout : stderr; + + /* xgettext:c-format */ + fprintf (s, _("Usage: %s [options] archive\n"), program_name); + fprintf (s, _(" Generate an index to speed access to archives\n")); + fprintf (s, _(" The options are:\n\ @ Read options from \n")); #if BFD_SUPPORTS_PLUGINS - fprintf (s, _("\ + fprintf (s, _("\ --plugin Load the specified plugin\n")); #endif - fprintf (s, _("\ + fprintf (s, _("\ -t Update the archive's symbol map timestamp\n\ -h --help Print this help message\n\ -v --version Print version information\n")); - } list_supported_targets (program_name, s); @@ -343,6 +354,52 @@ remove_output (void) } } +static void +ranlib_main(int argc, char **argv) +{ + int arg_index, status = 0; + bfd_boolean touch = FALSE; + + if (argc > 1 && argv[1][0] == '-') + { + if (strcmp (argv[1], "--help") == 0) + ranlib_usage (1); + else if (strcmp (argv[1], "--version") == 0) + { + print_version ("ranlib"); + } + } + + if (argc < 2 + || strcmp (argv[1], "--help") == 0 + || strcmp (argv[1], "-h") == 0 + || strcmp (argv[1], "-H") == 0) + ranlib_usage (0); + + if (strcmp (argv[1], "-V") == 0 + || strcmp (argv[1], "-v") == 0 + || CONST_STRNEQ (argv[1], "--v")) + print_version ("ranlib"); + arg_index = 1; + + if (strcmp (argv[1], "-t") == 0) + { + ++arg_index; + touch = TRUE; + } + + while (arg_index < argc) + { + if (! touch) + status |= ranlib_only (argv[arg_index]); + else + status |= ranlib_touch (argv[arg_index]); + ++arg_index; + } + + xexit (status); +} + /* The option parsing should be in its own function. It will be when I have getopt working. */ @@ -394,18 +451,6 @@ main (int argc, char **argv) is_ranlib = 0; } - if (argc > 1 && argv[1][0] == '-') - { - if (strcmp (argv[1], "--help") == 0) - usage (1); - else if (strcmp (argv[1], "--version") == 0) - { - if (is_ranlib) - print_version ("ranlib"); - else - print_version ("ar"); - } - } START_PROGRESS (program_name, 0); @@ -423,34 +468,14 @@ main (int argc, char **argv) argc -= (i - 1); if (is_ranlib) + ranlib_main(argc, argv); + + if (argc > 1 && argv[1][0] == '-') { - int status = 0; - bfd_boolean touch = FALSE; - - if (argc < 2 - || strcmp (argv[1], "--help") == 0 - || strcmp (argv[1], "-h") == 0 - || strcmp (argv[1], "-H") == 0) - usage (0); - if (strcmp (argv[1], "-V") == 0 - || strcmp (argv[1], "-v") == 0 - || CONST_STRNEQ (argv[1], "--v")) - print_version ("ranlib"); - arg_index = 1; - if (strcmp (argv[1], "-t") == 0) - { - ++arg_index; - touch = TRUE; - } - while (arg_index < argc) - { - if (! touch) - status |= ranlib_only (argv[arg_index]); - else - status |= ranlib_touch (argv[arg_index]); - ++arg_index; - } - xexit (status); + if (strcmp (argv[1], "--help") == 0) + usage (1); + else if (strcmp (argv[1], "--version") == 0) + print_version ("ar"); } if (argc == 2 && strcmp (argv[1], "-M") == 0) -- 2.30.2