diff options
author | obrien <obrien@FreeBSD.org> | 2000-12-24 10:52:23 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2000-12-24 10:52:23 +0000 |
commit | f57db1fdc0f7f85d46f2d4044f81ba307bd16a5d (patch) | |
tree | ef539d6575af7825e196b276d2e80a167ed04f06 /gnu/usr.bin | |
parent | 8857c9af4a9669e5bbd37bff56d1b2f7baac054c (diff) | |
download | FreeBSD-src-f57db1fdc0f7f85d46f2d4044f81ba307bd16a5d.zip FreeBSD-src-f57db1fdc0f7f85d46f2d4044f81ba307bd16a5d.tar.gz |
Clean up the -j/-y/--bzip entry in usage().
Add the -U and --unlink-first options which are the offical verions of our
--unlink localism.
Add support for the "TAR_OPTIONS" environmental variable.
Obtained from: GNU tar 1.13.18
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r-- | gnu/usr.bin/tar/Makefile | 4 | ||||
-rw-r--r-- | gnu/usr.bin/tar/prepend_args.c | 86 | ||||
-rw-r--r-- | gnu/usr.bin/tar/prepend_args.h | 26 | ||||
-rw-r--r-- | gnu/usr.bin/tar/tar.1 | 13 | ||||
-rw-r--r-- | gnu/usr.bin/tar/tar.c | 18 |
5 files changed, 140 insertions, 7 deletions
diff --git a/gnu/usr.bin/tar/Makefile b/gnu/usr.bin/tar/Makefile index 33323b3..0da24e3 100644 --- a/gnu/usr.bin/tar/Makefile +++ b/gnu/usr.bin/tar/Makefile @@ -1,7 +1,9 @@ +# $FreeBSD$ + PROG= tar SRCS= buffer.c create.c diffarch.c extract.c getdate.y \ getoldopt.c getopt.c getopt1.c gnu.c list.c mangle.c names.c port.c \ - rtapelib.c tar.c update.c version.c + prepend_args.c rtapelib.c tar.c update.c version.c CFLAGS+= -DRETSIGTYPE=void -DDIRENT=1 -DHAVE_SYS_MTIO_H=1 -DHAVE_UNISTD_H=1 CFLAGS+= -DHAVE_GETGRGID=1 -DHAVE_GETPWUID=1 -DHAVE_STRING_H=1 CFLAGS+= -DHAVE_LIMITS_H=1 -DHAVE_STRSTR=1 -DHAVE_VALLOC=1 -DHAVE_MKDIR=1 diff --git a/gnu/usr.bin/tar/prepend_args.c b/gnu/usr.bin/tar/prepend_args.c new file mode 100644 index 0000000..a4991f2 --- /dev/null +++ b/gnu/usr.bin/tar/prepend_args.c @@ -0,0 +1,86 @@ +/* prepend_args.c - utilility programs for manpiulating argv[] + Copyright (C) 1999 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +/* $FreeBSD$ */ + + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <sys/param.h> +#include "prepend_args.h" + + +/* Find the white-space-separated options specified by OPTIONS, and + using BUF to store copies of these options, set ARGV[0], ARGV[1], + etc. to the option copies. Return the number N of options found. + Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0] + etc. Backslash can be used to escape whitespace (and backslashes). */ +static int +prepend_args (options, buf, argv) + char const *options; + char *buf; + char **argv; +{ + char const *o = options; + char *b = buf; + int n = 0; + + for (;;) + { + while (isspace ((unsigned char) *o)) + o++; + if (!*o) + return n; + if (argv) + argv[n] = b; + n++; + + do + if ((*b++ = *o++) == '\\' && *o) + b[-1] = *o++; + while (*o && ! isspace ((unsigned char) *o)); + + *b++ = '\0'; + } +} + +/* Prepend the whitespace-separated options in OPTIONS to the argument + vector of a main program with argument count *PARGC and argument + vector *PARGV. */ +void +prepend_default_options (options, pargc, pargv) + char const *options; + int *pargc; + char ***pargv; +{ + if (options) + { + char *buf = xmalloc (strlen (options) + 1); + int prepended = prepend_args (options, buf, (char **) NULL); + int argc = *pargc; + char * const *argv = *pargv; + char **pp = (char **) xmalloc ((prepended + argc + 1) * sizeof *pp); + *pargc = prepended + argc; + *pargv = pp; + *pp++ = *argv++; + pp += prepend_args (options, buf, pp); + while ((*pp++ = *argv++)) + continue; + } +} diff --git a/gnu/usr.bin/tar/prepend_args.h b/gnu/usr.bin/tar/prepend_args.h new file mode 100644 index 0000000..7aad21c --- /dev/null +++ b/gnu/usr.bin/tar/prepend_args.h @@ -0,0 +1,26 @@ +/* prepend_args.h - utilility programs for manpiulating argv[] + Copyright (C) 1999 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +/* $FreeBSD$ */ + +/* This code, taken from GNU Grep, originally used the "PARAM" macro, as the + current GNU coding standards requires. Older GNU code used the "PROTO" + macro, before the GNU coding standards replaced it. We use the older + form here to keep from having to include another file in cvs/src/main.c. */ + +void prepend_default_options __P((char const *, int *, char ***)); diff --git a/gnu/usr.bin/tar/tar.1 b/gnu/usr.bin/tar/tar.1 index ce6a8df..60fd20a 100644 --- a/gnu/usr.bin/tar/tar.1 +++ b/gnu/usr.bin/tar/tar.1 @@ -267,6 +267,10 @@ to expect null-terminated names; disables .It Fl -totals Prints total bytes written with .Fl -create. +.It Fl U +.It Fl -unlink +.It Fl -unlink-first +Unlink files before creating them. .It Fl v .It Fl -verbose Lists files written to archive with @@ -319,9 +323,14 @@ Block the output of compression program for tapes or floppies (otherwise writes will be of odd length, which device drivers may reject). .It Fl [0-7][lmh] Specify tape drive and density. -.It Fl -unlink -Unlink files before creating them. .El +.Sh ENVIRONMENT +The environment variable +.Ev TAR_OPTIONS +can hold a set of default options for +.Nm . +These options are interpreted first and can be overwritten by explicit command +line parameters. .Sh EXAMPLES To create an archive on tape drive /dev/rsa0 with a block size of 20 blocks, containing files named "bert" and "ernie", you can enter diff --git a/gnu/usr.bin/tar/tar.c b/gnu/usr.bin/tar/tar.c index 81add3f..5ea5d1f 100644 --- a/gnu/usr.bin/tar/tar.c +++ b/gnu/usr.bin/tar/tar.c @@ -38,6 +38,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ */ #define TAR_EXTERN /**/ #include "tar.h" +#include "prepend_args.h" #include "port.h" #include "gnuregex.h" @@ -191,7 +192,8 @@ struct option long_options[] = {"force-local", 0, &f_force_local, 1}, {"atime-preserve", 0, &f_atime_preserve, 1}, - {"unlink", 0, &f_unlink, 1}, + {"unlink", 0, 0, 'U'}, + {"unlink-first", 0 , 0, 'U'}, {"fast-read", 0, &f_fast_read, 1}, {"norecurse", 0, 0, 'n'}, @@ -318,9 +320,11 @@ options (argc, argv) n_ar_files = 0; cur_ar_file = 0; + prepend_default_options (getenv ("TAR_OPTIONS"), &argc, &argv); + /* Parse options */ while ((c = getoldopt (argc, argv, - "-01234567Ab:BcC:df:F:g:GhiIjkK:lL:mMnN:oOpPrRsStT:uvV:wWxX:yzZ", + "-01234567Ab:BcC:df:F:g:GhiIjkK:lL:mMnN:oOpPrRsStT:uUvV:wWxX:yzZ", long_options, &ind)) != EOF) { switch (c) @@ -626,6 +630,10 @@ options (argc, argv) cmd_mode = CMD_UPDATE; break; + case 'U': + f_unlink = 1; + break; + case 'v': f_verbose++; break; @@ -747,6 +755,8 @@ Other options:\n\ -h, --dereference don't dump symlinks; dump the files they point to\n\ -i, --ignore-zeros ignore blocks of zeros in archive (normally mean EOF)\n\ --ignore-failed-read don't exit with non-zero status on unreadable files\n\ +-j, -y, --bzip,\n\ + --bzip2, --bunzip2 filter the archive through bzip2\n\ -k, --keep-old-files keep existing files; don't overwrite them from archive\n\ -K, --starting-file F begin at file F in the archive\n\ -l, --one-file-system stay in local file system when creating an archive\n\ @@ -780,6 +790,8 @@ Other options:\n\ --null -T reads null-terminated names, disable -C\n\ --totals print total bytes written with --create\n\ -v, --verbose verbosely list files processed\n\ +-U, --unlink,\n\ + --unlink-first unlink files before creating them\n\ -V, --label NAME create archive with volume name NAME\n\ --version print tar program version number\n\ -w, --interactive,\n\ @@ -789,7 +801,6 @@ Other options:\n\ -W, --verify attempt to verify the archive after writing it\n\ --exclude PATTERN exclude files, given as a globbing PATTERN\n\ -X, --exclude-from FILE exclude files listed in FILE\n\ --j, -y, --bzip, --bzip2, --bunzip2 filter the archive through bzip2\n\ -Z, --compress,\n\ --uncompress filter the archive through compress\n\ -z, --gzip,\n\ @@ -798,7 +809,6 @@ Other options:\n\ filter the archive through PROG (which must accept -d)\n\ --block-compress block the output of compression program for tapes\n\ -[0-7][lmh] specify drive and density\n\ ---unlink unlink files before creating them\n\ --fast-read stop after desired names in archive have been found\n\ ", stdout); } |