From d2b2318176fc81d6a1f69ea4c9710a3b1776de73 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 9 Dec 1996 12:02:16 +0000 Subject: [PATCH] support pax '-s replstr' option in tar mode too. this can be used to deal with cleaning up absolute paths --- bin/pax/options.c | 21 +++++++++++++++----- bin/pax/tar.1 | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/bin/pax/options.c b/bin/pax/options.c index 4bdffe20d88..8d84828272f 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.11 1996/12/09 12:00:15 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.12 1996/12/09 12:02:16 deraadt Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.11 1996/12/09 12:00:15 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.12 1996/12/09 12:02:16 deraadt Exp $"; #endif #endif /* not lint */ @@ -605,7 +605,8 @@ tar_options(argc, argv) /* * process option flags */ - while ((c = getoldopt(argc, argv, "b:cef:hmoprutvwxzBC:HLPXZ014578")) + while ((c = getoldopt(argc, argv, + "b:cef:hmopruts:vwxzBC:HLPXZ014578")) != EOF) { switch(c) { case 'b': @@ -677,6 +678,15 @@ tar_options(argc, argv) */ act = APPND; break; + case 's': + /* + * file name substitution name pattern + */ + if (rep_add(optarg) < 0) { + tar_usage(); + break; + } + break; case 't': /* * list contents of the tape @@ -1178,9 +1188,10 @@ void tar_usage() #endif { - (void)fputs("usage: tar -{txru}[cevfbmopwzBHLPXZ014578] [tapefile] ", + (void)fputs("usage: tar -{txru}[cevfbmopswzBHLPXZ014578] [tapefile] ", stderr); - (void)fputs("[blocksize] [-C directory] file1 file2...\n", stderr); + (void)fputs("[blocksize] [replstr] [-C directory] file1 file2...\n", + stderr); exit(1); } diff --git a/bin/pax/tar.1 b/bin/pax/tar.1 index b6d4d9f1dc9..ef213e4a091 100644 --- a/bin/pax/tar.1 +++ b/bin/pax/tar.1 @@ -27,7 +27,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: tar.1,v 1.3 1996/10/27 06:45:14 downsj Exp $ +.\" $OpenBSD: tar.1,v 1.4 1996/12/09 12:02:17 deraadt Exp $ .\" .Dd June 11, 1996 .Dt TAR 1 @@ -44,6 +44,9 @@ .No [-C .Ar directory .No ] +.No [-s +.Ar replstr +.No ] .Ar file1 .Op Ar file2... .Sh DESCRIPTION @@ -98,6 +101,51 @@ Do not create directories. .It Fl p Preserve user id, group id, file mode, access and modification times. +.It Fl s Ar replstr +Modify the file or archive member names specified by the +.Ar pattern +or +.Ar file +operands according to the substitution expression +.Ar replstr , +using the syntax of the +.Xr ed 1 +utility regular expressions. +The format of these regular expressions are: +.Dl /old/new/[gp] +As in +.Xr ed 1 , +.Cm old +is a basic regular expression and +.Cm new +can contain an ampersand (&), \\n (where n is a digit) back-references, +or subexpression matching. +The +.Cm old +string may also contain +.Dv +characters. +Any non-null character can be used as a delimiter (/ is shown here). +Multiple +.Fl s +expressions can be specified. +The expressions are applied in the order they are specified on the +command line, terminating with the first successful substitution. +The optional trailing +.Cm g +continues to apply the substitution expression to the pathname substring +which starts with the first character following the end of the last successful +substitution. The first unsuccessful substitution stops the operation of the +.Cm g +option. +The optional trailing +.Cm p +will cause the final result of a successful substitution to be written to +.Dv standard error +in the following format: +.Dl >> +File or archive member names that substitute to the empty string +are not selected and will be skipped. .It Fl v Verbose operation mode. .It Fl w -- 2.20.1