diff options
author | kientzle <kientzle@FreeBSD.org> | 2004-06-02 21:01:27 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2004-06-02 21:01:27 +0000 |
commit | 44e8bf5a4175f7d632bab6747b9c7ee110ff5b58 (patch) | |
tree | 3093538aadc2a981f5ff52fdf23a0ad0b00d4df6 /usr.bin/tar | |
parent | 47c3b636254c8cb55dea1272f8be52ddc6561b8f (diff) | |
download | FreeBSD-src-44e8bf5a4175f7d632bab6747b9c7ee110ff5b58.zip FreeBSD-src-44e8bf5a4175f7d632bab6747b9c7ee110ff5b58.tar.gz |
Improve help handling:
* --help produces long help message on systems with getopt_long
* -h with no other options also produces long help message
(If a mode is specified, -h has its usual meaning.)
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/bsdtar.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index 4d3639d..73f0854 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -122,6 +122,7 @@ main(int argc, char **argv) int opt; char mode; char buff[16]; + char possible_help_request; /* * Use a pointer for consistency, but stack-allocated storage @@ -134,6 +135,7 @@ main(int argc, char **argv) if (setlocale(LC_ALL, "") == NULL) bsdtar_warnc(bsdtar, 0, "Failed to set default locale"); mode = '\0'; + possible_help_request = 0; /* Look up uid/uname of current user for future reference */ bsdtar->user_uid = geteuid(); @@ -220,6 +222,8 @@ main(int argc, char **argv) break; case 'h': /* Linux Standards Base, gtar; synonym for -L */ bsdtar->symlink_mode = 'L'; + /* Hack: -h by itself is the "help" command. */ + possible_help_request = 1; break; #ifdef HAVE_GETOPT_LONG case OPTION_HELP: @@ -351,6 +355,11 @@ main(int argc, char **argv) /* * Sanity-check options. */ + if (mode == '\0' && possible_help_request) { + long_help(bsdtar); + exit(1); + } + if (mode == '\0') bsdtar_errc(bsdtar, 1, 0, "Must specify one of -c, -r, -t, -u, -x"); @@ -509,7 +518,11 @@ usage(struct bsdtar *bsdtar) printf(" List: %s -tf [archive-filename]\n", p); printf(" Extract: %s -xf [archive-filename]\n", p); printf(" Create: %s -cf [archive-filename] [filenames...]\n", p); +#ifdef HAVE_GETOPT_LONG + printf(" Help: %s --help\n", p); +#else printf(" Help: %s -h\n", p); +#endif exit(1); } |