From 556d6e605e6838f5a8bd872c21a10b974783bb75 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Mon, 26 Jul 2004 03:21:41 +0000 Subject: [PATCH] Add a --version option to bsdtar that prints the versions of both bsdtar and libarchive. Of course, this requires that bsdtar have a version number. Let's call this 1.00, shall we? ;-) --- usr.bin/tar/Makefile | 2 ++ usr.bin/tar/bsdtar.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile index 6b7758f2dcb1..c4917be3b6de 100644 --- a/usr.bin/tar/Makefile +++ b/usr.bin/tar/Makefile @@ -1,10 +1,12 @@ # $FreeBSD$ PROG= bsdtar +VERSION= 1.00 SRCS= bsdtar.c matching.c read.c util.c write.c WARNS?= 6 DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ} LDADD= -larchive -lbz2 -lz +CFLAGS+= -DPACKAGE_VERSION=\"${VERSION}\" .if !defined(WITH_GTAR) SYMLINKS= ${BINDIR}/bsdtar ${BINDIR}/tar diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index 89dc5ad17443..da99da69dc41 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -67,6 +67,7 @@ static void only_mode(struct bsdtar *, char mode, const char *opt, static char ** rewrite_argv(struct bsdtar *, int *argc, char ** src_argv, const char *optstring); +static void version(void); /* * The leading '+' here forces the GNU version of getopt() (as well as @@ -99,6 +100,7 @@ static const char *tar_opts = "+Bb:C:cF:f:HhjkLlmnOoPprtT:UuvW:wX:xyZz"; #define OPTION_NO_SAME_PERMISSIONS 6 #define OPTION_NULL 7 #define OPTION_ONE_FILE_SYSTEM 8 +#define OPTION_VERSION 9 static const struct option tar_longopts[] = { { "absolute-paths", no_argument, NULL, 'P' }, @@ -141,6 +143,7 @@ static const struct option tar_longopts[] = { { "unlink-first", no_argument, NULL, 'U' }, { "update", no_argument, NULL, 'u' }, { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, OPTION_VERSION }, { NULL, 0, NULL, 0 } }; @@ -355,6 +358,9 @@ main(int argc, char **argv) case 'v': /* SUSv2 */ bsdtar->verbose++; break; + case OPTION_VERSION: + version(); + break; case 'w': /* SUSv2 */ bsdtar->option_interactive = 1; break; @@ -573,6 +579,15 @@ usage(struct bsdtar *bsdtar) exit(1); } +static void +version(void) +{ + printf("bsdtar %s, ", PACKAGE_VERSION); + printf("%s\n", archive_version()); + printf("Copyright (C) 2003-2004 Tim Kientzle\n"); + exit(1); +} + static const char *long_help_msg = "First option must be a mode specifier:\n" " -c Create -r Add/Replace -t List -u Update -x Extract\n" @@ -622,8 +637,8 @@ long_help(struct bsdtar *bsdtar) fflush(stderr); - p = (strcmp(prog,"bsdtar")!=0) ? "(bsdtar)" : ""; - fprintf(stdout, "%s%s: manipulate archive files\n", prog, p); + p = (strcmp(prog,"bsdtar") != 0) ? "(bsdtar)" : ""; + printf("%s%s: manipulate archive files\n", prog, p); for (p = long_help_msg; *p != '\0'; p++) { if (*p == '%') { @@ -635,8 +650,8 @@ long_help(struct bsdtar *bsdtar) } else putchar(*p); } - fprintf(stdout, "\n%s\n", archive_version()); - fflush(stderr); + printf("\n"); + version(); } static int