diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2011-10-10 14:57:48 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2011-10-10 14:57:48 +0000 |
commit | 92b499acff8a35d64ec0f9b27b5df06209656ca9 (patch) | |
tree | 028b13e0eb9c8522daa2a868f0593a76d32e5adb /winsup/utils/ldd.cc | |
parent | 4fc8a5c90acb2501178613b04bca32492953884a (diff) | |
download | cygnal-92b499acff8a35d64ec0f9b27b5df06209656ca9.tar.gz cygnal-92b499acff8a35d64ec0f9b27b5df06209656ca9.tar.bz2 cygnal-92b499acff8a35d64ec0f9b27b5df06209656ca9.zip |
* Align usage output, version output, as well as usage and version
option handling to use the same style throughout all Cygwin utils.
Throughout use program_invocation_short_name to refer to current
process name in Cygwin executables.
* utils.sgml: Align documentation to above change. Add missing
sections for getconf, ldd, and setmetamode.
* strace.cc (proc_child): Avoid compiler warning.
Diffstat (limited to 'winsup/utils/ldd.cc')
-rw-r--r-- | winsup/utils/ldd.cc | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/winsup/utils/ldd.cc b/winsup/utils/ldd.cc index 073c40bcb..29d5a8b12 100644 --- a/winsup/utils/ldd.cc +++ b/winsup/utils/ldd.cc @@ -33,6 +33,7 @@ #include <wchar.h> #include <locale.h> #include <sys/cygwin.h> +#include <cygwin/version.h> #include <unistd.h> #include <libgen.h> @@ -49,18 +50,20 @@ struct option longopts[] = { - {"help", no_argument, NULL, 0}, - {"version", no_argument, NULL, 0}, + {"help", no_argument, NULL, 'h'}, + {"verbose", no_argument, NULL, 'v'}, + {"version", no_argument, NULL, 'V'}, {"data-relocs", no_argument, NULL, 'd'}, {"function-relocs", no_argument, NULL, 'r'}, {"unused", no_argument, NULL, 'u'}, {0, no_argument, NULL, 0} }; +const char *opts = "dhruvV"; static int process_file (const wchar_t *); static int -usage (const char *fmt, ...) +error (const char *fmt, ...) { va_list ap; va_start (ap, fmt); @@ -70,6 +73,38 @@ usage (const char *fmt, ...) exit (1); } +static void +usage () +{ + printf ("Usage: %s [OPTION]... FILE...\n\ +\n\ +Print shared library dependencies\n\ +\n\ + -h, --help print this help and exit\n\ + -V, --version print version information and exit\n\ + -r, --function-relocs process data and function relocations\n\ + (currently unimplemented)\n\ + -u, --unused print unused direct dependencies\n\ + (currently unimplemented)\n\ + -v, --verbose print all information\n\ + (currently unimplemented)\n", + program_invocation_short_name); +} + +static void +print_version () +{ + printf ("ldd (cygwin) %d.%d.%d\n" + "Print shared library dependencies\n" + "Copyright (C) 2009 - %s Chris Faylor\n" + "This is free software; see the source for copying conditions. There is NO\n" + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", + CYGWIN_VERSION_DLL_MAJOR / 1000, + CYGWIN_VERSION_DLL_MAJOR % 1000, + CYGWIN_VERSION_DLL_MINOR, + strrchr (__DATE__, ' ') + 1); +} + #define print_errno_error_and_return(__fn) \ do {\ fprintf (stderr, "ldd: %s: %s\n", (__fn), strerror (errno));\ @@ -338,51 +373,37 @@ report (const char *in_fn, bool multiple) return 0; } - int main (int argc, char **argv) { int optch; - int index; /* Use locale from environment. If not set or set to "C", use UTF-8. */ setlocale (LC_CTYPE, ""); if (!strcmp (setlocale (LC_CTYPE, NULL), "C")) setlocale (LC_CTYPE, "en_US.UTF-8"); - while ((optch = getopt_long (argc, argv, "dru", longopts, &index)) != -1) + while ((optch = getopt_long (argc, argv, opts, longopts, NULL)) != -1) switch (optch) { case 'd': case 'r': case 'u': - usage ("option not implemented `-%c'", optch); + error ("option not implemented `-%c'", optch); exit (1); - case 0: - if (index == 1) - { - printf ("ldd (Cygwin) %s\nCopyright (C) 2009 Chris Faylor\n" - "This is free software; see the source for copying conditions. There is NO\n" - "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", - VERSION); - exit (0); - } - else - { - puts ("Usage: ldd [OPTION]... FILE...\n\ - --help print this help and exit\n\ - --version print version information and exit\n\ - -r, --function-relocs process data and function relocations\n\ - (currently unimplemented)\n\ - -u, --unused print unused direct dependencies\n\ - (currently unimplemented)\n\ - -v, --verbose print all information\n\ - (currently unimplemented)"); - exit (0); - } + case 'h': + usage (); + exit (0); + case 'V': + print_version (); + return 0; + default: + fprintf (stderr, "Try `%s --help' for more information.\n", + program_invocation_short_name); + return 1; } argv += optind; if (!*argv) - usage("missing file arguments"); + error ("missing file arguments"); int ret = 0; bool multiple = !!argv[1]; |