psed A Perl implementation of sed
ptar A Perl implementation of tar
ptardiff A diff for tar archives
+ ptargrep A grep for tar archives
s2p sed-to-perl translator
shasum A tool to print or check SHA checksums
splain Describe Perl warnings and errors
cpan/Archive-Extract/t/src/y.zip Archive::Extract tests
cpan/Archive-Tar/bin/ptar the ptar utility
cpan/Archive-Tar/bin/ptardiff the ptardiff utility
+cpan/Archive-Tar/bin/ptargrep the ptardiff utility
cpan/Archive-Tar/lib/Archive/Tar/Constant.pm Archive::Tar
cpan/Archive-Tar/lib/Archive/Tar/File.pm Archive::Tar
cpan/Archive-Tar/lib/Archive/Tar.pm Archive::Tar
utils/pl2pm.PL A pl to pm translator
utils/prove.PL The prove harness utility
utils/ptardiff.PL The ptardiff utility
+utils/ptargrep.PL The ptargrep utility
utils/ptar.PL The ptar utility
utils/shasum.PL filter for computing SHA digests (analogous to md5sum)
utils/splain.PL Stand-alone version of diagnostics.pm
'Archive::Tar' =>
{
'MAINTAINER' => 'kane',
- 'DISTRIBUTION' => 'BINGOS/Archive-Tar-1.68.tar.gz',
+ 'DISTRIBUTION' => 'BINGOS/Archive-Tar-1.70.tar.gz',
'FILES' => q[cpan/Archive-Tar],
'EXCLUDED' => [ qw(Makefile.PL) ],
'UPSTREAM' => 'cpan',
$ WRITE CONFIG "$ s2p == """ + perl_setup_perl + " ''vms_prefix':[utils]s2p.com"""
$ WRITE CONFIG "$ ptar == """ + perl_setup_perl + " ''vms_prefix':[utils]ptar.com"""
$ WRITE CONFIG "$ ptardiff == """ + perl_setup_perl + " ''vms_prefix':[utils]ptardiff.com"""
+$ WRITE CONFIG "$ ptargrep == """ + perl_setup_perl + " ''vms_prefix':[utils]ptargrep.com"""
$ WRITE CONFIG "$ shasum == """ + perl_setup_perl + " ''vms_prefix':[utils]shasum.com"""
$ WRITE CONFIG "$ splain == """ + perl_setup_perl + " ''vms_prefix':[utils]splain.com"""
$ WRITE CONFIG "$ xsubpp == """ + perl_setup_perl + " ''vms_prefix':[utils]xsubpp.com"""
--- /dev/null
+#!/usr/bin/perl
+##############################################################################
+# Tool for using regular expressions against the contents of files in a tar
+# archive. See 'targrep --help' for more documentation.
+#
+
+use strict;
+use warnings;
+
+use Pod::Usage qw(pod2usage);
+use Getopt::Long qw(GetOptions);
+use Archive::Tar qw();
+use File::Path qw(mkpath);
+
+my(%opt, $pattern);
+
+if(!GetOptions(\%opt,
+ 'basename|b',
+ 'ignore-case|i',
+ 'list-only|l',
+ 'verbose|v',
+ 'help|?',
+)) {
+ pod2usage(-exitval => 1, -verbose => 0);
+}
+
+
+pod2usage(-exitstatus => 0, -verbose => 2) if $opt{help};
+
+pod2usage(-exitval => 1, -verbose => 0,
+ -message => "No pattern specified",
+) unless @ARGV;
+make_pattern( shift(@ARGV) );
+
+pod2usage(-exitval => 1, -verbose => 0,
+ -message => "No tar files specified",
+) unless @ARGV;
+
+process_archive($_) foreach @ARGV;
+
+exit 0;
+
+
+sub make_pattern {
+ my($pat) = @_;
+
+ if($opt{'ignore-case'}) {
+ $pattern = qr{(?im)$pat};
+ }
+ else {
+ $pattern = qr{(?m)$pat};
+ }
+}
+
+
+sub process_archive {
+ my($filename) = @_;
+
+ _log("Processing archive: $filename");
+ my $next = Archive::Tar->iter($filename);
+ while( my $f = $next->() ) {
+ next unless $f->is_file;
+ match_file($f) if $f->size > 0;
+ }
+}
+
+
+sub match_file {
+ my($f) = @_;
+ my $path = $f->name;
+
+ _log("filename: %s (%d bytes)", $path, $f->size);
+
+ my $body = $f->get_content();
+ if($body !~ $pattern) {
+ _log(" no match");
+ return;
+ }
+
+ if($opt{'list-only'}) {
+ print $path, "\n";
+ return;
+ }
+
+ save_file($path, $body);
+}
+
+
+sub save_file {
+ my($path, $body) = @_;
+
+ _log(" found match - extracting");
+ my($fh);
+ my($dir, $file) = $path =~ m{\A(?:(.*)/)?([^/]+)\z};
+ if($dir and not $opt{basename}) {
+ _log(" writing to $dir/$file");
+ $dir =~ s{\A/}{./};
+ mkpath($dir) unless -d $dir;
+ open $fh, '>', "$dir/$file" or die "open($dir/$file): $!";
+ }
+ else {
+ _log(" writing to ./$file");
+ open $fh, '>', $file or die "open($file): $!";
+ }
+ print $fh $body;
+ close($fh);
+}
+
+
+sub _log {
+ return unless $opt{verbose};
+ my($format, @args) = @_;
+ warn sprintf($format, @args) . "\n";
+}
+
+
+__END__
+
+=head1 NAME
+
+targrep - Apply pattern matching to the contents of files in a tar archive
+
+=head1 SYNOPSIS
+
+ targrep [options] <pattern> <tar file> ...
+
+ Options:
+
+ --basename|-b ignore directory paths from archive
+ --ignore-case|-i do case-insensitive pattern matching
+ --list-only|-l list matching filenames rather than extracting matches
+ --verbose|-v write debugging message to STDERR
+ --help|-? detailed help message
+
+=head1 DESCRIPTION
+
+This utility allows you to apply pattern matching to B<the contents> of files
+contained in a tar archive. You might use this to identify all files in an
+archive which contain lines matching the specified pattern and either print out
+the pathnames or extract the files.
+
+The pattern will be used as a Perl regular expression (as opposed to a simple
+grep regex).
+
+Multiple tar archive filenames can be specified - they will each be processed
+in turn.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--basename> (alias -b)
+
+When matching files are extracted, ignore the directory path from the archive
+and write to the current directory using the basename of the file from the
+archive. Beware: if two matching files in the archive have the same basename,
+the second file extracted will overwrite the first.
+
+=item B<--ignore-case> (alias -i)
+
+Make pattern matching case-insensitive.
+
+=item B<--list-only> (alias -l)
+
+Print the pathname of each matching file from the archive to STDOUT. Without
+this option, the default behaviour is to extract each matching file.
+
+=item B<--verbose> (alias -v)
+
+Log debugging info to STDERR.
+
+=item B<--help> (alias -?)
+
+Display this documentation.
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright 2010 Grant McLean E<lt>grantm@cpan.orgE<gt>
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+
+
$DEBUG = 0;
$WARN = 1;
$FOLLOW_SYMLINK = 0;
-$VERSION = "1.68";
+$VERSION = "1.70";
$CHOWN = 1;
$CHMOD = 1;
$SAME_PERMISSIONS = $> == 0 ? 1 : 0;
BEGIN {
require Exporter;
- $VERSION = '1.68';
+ $VERSION = '1.70';
@ISA = qw[Exporter];
require Time::Local if $^O eq "MacOS";
use vars qw[@ISA $VERSION];
#@ISA = qw[Archive::Tar];
-$VERSION = '1.68';
+$VERSION = '1.70';
### set value to 1 to oct() it during the unpack ###
my $tmpl = [
# the corelist script from lib/Module/CoreList/bin and ptar* in
# lib/Archive/Tar/bin, the config_data script in lib/Module/Build/scripts
# (they're installed later with other utils)
- return if $name =~ /^(?:cpan|instmodsh|prove|corelist|ptar|cpan2dist|cpanp|cpanp-run-perl|ptardiff|config_data)\z/;
+ return if $name =~ /^(?:cpan|instmodsh|prove|corelist|ptar|cpan2dist|cpanp|cpanp-run-perl|ptardiff|ptargrep|config_data)\z/;
# ignore the Makefiles
return if $name =~ /^makefile$/i;
# ignore the test extensions
=item *
+C<Archive::Tar> has been upgraded from 1.68 to 1.70
+
+This adds the ptargrep utility for using regular expressions against
+the contents of files in a tar archive.
+
+=item *
+
C<B> has been upgraded from 1.24 to 1.26.
It no longer crashes when taking apart a C<y///> containing characters
entries for each change
Use L<XXX> with program names to get proper documentation linking. ]
-=head3 L<XXX>
+=head3 L<ptargrep>
=over 4
=item *
-XXX
+L<ptargrep> is a utility to apply pattern matching to the contents of files
+in a tar archive. It comes with C<Archive::Tar>.
=back
C<Text::Diff> module to function properly; this module isn't distributed
with perl, but is available from the CPAN.)
+=item L<ptargrep>
+
+F<ptargrep> is a utility to apply pattern matching to the contents of files
+in a tar archive.
+
=item L<shasum>
This utility, that comes with the C<Digest::SHA> module, is used to print
utils/prove
utils/ptar
utils/ptardiff
+utils/ptargrep
utils/cpanp-run-perl
utils/cpanp
utils/cpan2dist
# Files to be built with variable substitution after miniperl is
# available. Dependencies handled manually below (for now).
-pl = c2ph.PL config_data.PL corelist.PL cpan.PL h2ph.PL h2xs.PL instmodsh.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL prove.PL ptar.PL ptardiff.PL cpanp-run-perl.PL cpanp.PL cpan2dist.PL shasum.PL splain.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL xsubpp.PL
-plextract = c2ph config_data corelist cpan h2ph h2xs instmodsh perlbug perldoc perlivp pl2pm prove ptar ptardiff cpanp-run-perl cpanp cpan2dist shasum splain dprofpp libnetcfg piconv enc2xs xsubpp
-plextractexe = ./c2ph ./config_data ./corelist ./cpan ./h2ph ./h2xs ./instmodsh ./perlbug ./perldoc ./perlivp ./pl2pm ./prove ./ptar ./ptardiff ./cpanp-run-perl ./cpanp ./cpan2dist ./shasum ./splain ./dprofpp ./libnetcfg ./piconv ./enc2xs ./xsubpp
+pl = c2ph.PL config_data.PL corelist.PL cpan.PL h2ph.PL h2xs.PL instmodsh.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL prove.PL ptar.PL ptardiff.PL ptargrep.PL cpanp-run-perl.PL cpanp.PL cpan2dist.PL shasum.PL splain.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL xsubpp.PL
+plextract = c2ph config_data corelist cpan h2ph h2xs instmodsh perlbug perldoc perlivp pl2pm prove ptar ptardiff ptargrep cpanp-run-perl cpanp cpan2dist shasum splain dprofpp libnetcfg piconv enc2xs xsubpp
+plextractexe = ./c2ph ./config_data ./corelist ./cpan ./h2ph ./h2xs ./instmodsh ./perlbug ./perldoc ./perlivp ./pl2pm ./prove ./ptar ./ptardiff ./ptargrep ./cpanp-run-perl ./cpanp ./cpan2dist ./shasum ./splain ./dprofpp ./libnetcfg ./piconv ./enc2xs ./xsubpp
all: $(plextract)
ptardiff: ptardiff.PL ../config.sh
+ptargrep: ptargrep.PL ../config.sh
+
cpanp-run-perl: cpanp-run-perl.PL ../config.sh
cpanp: cpanp.PL ../config.sh
# Files to be built with variable substitution after miniperl is
# available. Dependencies handled manually below (for now).
-pl = c2ph.PL config_data.PL corelist.PL cpan.PL h2ph.PL h2xs.PL instmodsh.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL prove.PL ptar.PL ptardiff.PL cpanp-run-perl.PL cpanp.PL cpan2dist.PL shasum.PL splain.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL xsubpp.PL
-plextract = c2ph config_data corelist cpan h2ph h2xs instmodsh perlbug perldoc perlivp pl2pm prove ptar ptardiff cpanp-run-perl cpanp cpan2dist shasum splain dprofpp libnetcfg piconv enc2xs xsubpp
-plextractexe = ./c2ph ./config_data ./corelist ./cpan ./h2ph ./h2xs ./instmodsh ./perlbug ./perldoc ./perlivp ./pl2pm ./prove ./ptar ./ptardiff ./cpanp-run-perl ./cpanp ./cpan2dist ./shasum ./splain ./dprofpp ./libnetcfg ./piconv ./enc2xs ./xsubpp
+pl = c2ph.PL config_data.PL corelist.PL cpan.PL h2ph.PL h2xs.PL instmodsh.PL perlbug.PL perldoc.PL perlivp.PL pl2pm.PL prove.PL ptar.PL ptardiff.PL ptargrep.PL cpanp-run-perl.PL cpanp.PL cpan2dist.PL shasum.PL splain.PL dprofpp.PL libnetcfg.PL piconv.PL enc2xs.PL xsubpp.PL
+plextract = c2ph config_data corelist cpan h2ph h2xs instmodsh perlbug perldoc perlivp pl2pm prove ptar ptardiff ptargrep cpanp-run-perl cpanp cpan2dist shasum splain dprofpp libnetcfg piconv enc2xs xsubpp
+plextractexe = ./c2ph ./config_data ./corelist ./cpan ./h2ph ./h2xs ./instmodsh ./perlbug ./perldoc ./perlivp ./pl2pm ./prove ./ptar ./ptardiff ./ptargrep ./cpanp-run-perl ./cpanp ./cpan2dist ./shasum ./splain ./dprofpp ./libnetcfg ./piconv ./enc2xs ./xsubpp
all: $(plextract)
ptardiff: ptardiff.PL ../config.sh
+ptargrep: ptargrep.PL ../config.sh
+
cpanp-run-perl: cpanp-run-perl.PL ../config.sh
cpanp: cpanp.PL ../config.sh
--- /dev/null
+#!/usr/local/bin/perl
+
+use Config;
+use File::Basename qw(&basename &dirname);
+use Cwd;
+
+# List explicitly here the variables you want Configure to
+# generate. Metaconfig only looks for shell variables, so you
+# have to mention them as if they were shell variables, not
+# %Config entries. Thus you write
+# $startperl
+# to ensure Configure will look for $Config{startperl}.
+
+# This forces PL files to create target in same directory as PL file.
+# This is so that make depend always knows where to find PL derivatives.
+my $origdir = cwd;
+chdir dirname($0);
+my $file = basename($0, '.PL');
+$file .= '.com' if $^O eq 'VMS';
+
+open OUT,">$file" or die "Can't create $file: $!";
+
+print "Extracting $file (with variable substitutions)\n";
+
+# In this section, perl variables will be expanded during extraction.
+# You can use $Config{...} to use Configure variables.
+
+print OUT <<"!GROK!THIS!";
+$Config{startperl}
+ eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
+ if \$running_under_some_shell;
+!GROK!THIS!
+
+use File::Spec;
+
+my $script = File::Spec->catfile(
+ File::Spec->catdir(
+ File::Spec->updir, qw[cpan Archive-Tar bin]
+ ), "ptargrep");
+
+if (open(IN, $script)) {
+ print OUT <IN>;
+ close IN;
+} else {
+ die "$0: cannot find '$script'\n";
+}
+
+close OUT or die "Can't close $file: $!";
+chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
+exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
+chdir $origdir;
utils2 = [.utils]h2xs.com [.utils]libnetcfg.com [.lib]perlbug.com [.utils]dprofpp.com
utils3 = [.utils]perlivp.com [.lib]splain.com [.utils]pl2pm.com [.utils]xsubpp.com [.utils]instmodsh.com
utils4 = [.utils]enc2xs.com [.utils]piconv.com [.utils]cpan.com [.utils]prove.com [.utils]ptar.com [.utils]ptardiff.com [.utils]shasum.com
-utils5 = [.utils]corelist.com [.utils]config_data.com [.utils]cpanp.com [.utils]cpan2dist.com [.utils]cpanp-run-perl.com
+utils5 = [.utils]corelist.com [.utils]config_data.com [.utils]cpanp.com [.utils]cpan2dist.com [.utils]cpanp-run-perl.com [.utils]ptargrep.com
.ifdef NOX2P
all : base extras archcorefiles preplibrary [.pod]perltoc.pod
[.utils]ptardiff.com : [.utils]ptardiff.PL $(ARCHDIR)Config.pm
$(MINIPERL) -"I[-.lib]" $(MMS$SOURCE)
+[.utils]ptargrep.com : [.utils]ptargrep.PL $(ARCHDIR)Config.pm
+ $(MINIPERL) -"I[-.lib]" $(MMS$SOURCE)
+
[.utils]shasum.com : [.utils]shasum.PL $(ARCHDIR)Config.pm
$(MINIPERL) -"I[-.lib]" $(MMS$SOURCE)
..\utils\prove \
..\utils\ptar \
..\utils\ptardiff \
+ ..\utils\ptargrep \
..\utils\cpanp-run-perl \
..\utils\cpanp \
..\utils\cpan2dist \
perlvos.pod perlwin32.pod
-cd ..\utils && del /f h2ph splain perlbug pl2pm c2ph pstruct h2xs \
perldoc perlivp dprofpp libnetcfg enc2xs piconv cpan *.bat \
- xsubpp instmodsh prove ptar ptardiff cpanp-run-perl cpanp cpan2dist shasum corelist config_data
+ xsubpp instmodsh prove ptar ptardiff ptargrep cpanp-run-perl cpanp cpan2dist shasum corelist config_data
-cd ..\x2p && del /f find2perl s2p psed *.bat
-del /f ..\config.sh perlmain.c dlutils.c config.h.new \
perlmainst.c
..\utils\prove \
..\utils\ptar \
..\utils\ptardiff \
+ ..\utils\ptargrep \
..\utils\cpanp-run-perl \
..\utils\cpanp \
..\utils\cpan2dist \
perlvos.pod perlwin32.pod
-cd ..\utils && del /f h2ph splain perlbug pl2pm c2ph pstruct h2xs \
perldoc perlivp dprofpp libnetcfg enc2xs piconv cpan *.bat \
- xsubpp instmodsh prove ptar ptardiff cpanp-run-perl cpanp cpan2dist shasum corelist config_data
+ xsubpp instmodsh prove ptar ptardiff ptargrep cpanp-run-perl cpanp cpan2dist shasum corelist config_data
-cd ..\x2p && del /f find2perl s2p psed *.bat
-del /f ..\config.sh perlmain.c dlutils.c config.h.new \
perlmainst.c