#!/usr/bin/env perl # ds # Created Fri Oct 22 2004 by dwm@austin.ibm.com # $Id: ds,v 1.11 2004/11/05 23:24:06 dwm Exp $ require 5.6.1; use Getopt::Long 2.33; use Pod::Usage; use Data::Dumper; use Config; ### variables and subroutines ## $opt_debug = 0; $opt_help = 0; $opt_man = 0; $stat_flags = ""; $diff_flags = "-Nwupa"; @dirs = (); @tops = (); sub infer_orig ( $ ) { my $suf = "$_[0]\$"; my $x = $ENV{PWD}; my $basedir; ($basedir = $x) =~ s,.*/,,; if ($basedir =~ m{$suf}) { ($tops[0] = $basedir) =~ s{$suf}{}; $tops[1] = $basedir; return 1; } return 0; } ############# main #################### GetOptions ( 'debug' => \$opt_debug, 'diffflags=s' => \$diff_flags, 'dirs=s' => \@dirs, 'help|?' => \$opt_help, 'man' => \$opt_man, 'statflags=s' => \$stat_flags, 'tops=s' => \@tops, 'verbose+' => \$verbose, ) or pod2usage(2); pod2usage (1) if $opt_help; pod2usage (-verbose => 2) if $opt_man; ( $prog = $0 ) =~ s{.*/}{}o; ## If no arguments were given, then allow STDIN to be used only ## if it's not connected to a terminal (otherwise print usage) pod2usage ("$prog: No files given.") if ((@ARGV == 0) && (-t STDIN)); # setbuf on STDERR. $ofh = select (STDERR); $| = 1; select ($ofh); @diffout = (); $kill_errs = ($verbose) ? "" : "2>/dev/null"; # # if tops is not set, infer the older directory. Long Term - find out if cvs file. # if (not scalar @tops) { my @os = ( "\.edit" ); while ($od = shift @os) { last if (infer_orig $od); } } if (not scalar @tops) { pod2usage ("$prog: could not infer, need to define tops."); } if (not -d $tops[0]) { if (-d "../$tops[0]") { chdir '..'; print STDERR qx{pwd} if $verbose; } else { die "could not find $tops[0]\n"; } } while ($path = shift @ARGV) { my $recurse = (-d "$tops[0]/$path") ? 'r' : ''; $cmd = "diff $diff_flags${recurse} $tops[0]/$path $tops[1]/$path $kill_errs"; print "tops={@tops}\n$cmd\n" if $opt_debug; open DIFFIN, "$cmd |" or die "open {$cmd}\n"; while () { next if (m{^Common}); push @diffout, $_; } } open DSI, "|diffstat $stat_flags" or die "open stat pipe\n"; print DSI @diffout; print while (); close DSI; print "\n", @diffout; __END__ =head1 NAME B - diffstat + diff from one command =head1 SYNOPSIS B [options] ... =head1 OPTIONS =over 4 =item B<--debug> run without action, printing debug messages. =item B<--diffflags> flags to pass to diff. default -Nwupa. =item B<--help> print the synopsis only. see B<--man>. =item B<--man> print the complete manpage. =item B<--statflags> flags to pass to diffstat. default is {$stat_flags}. =item B<--tops> Top level directories to diff with the appended paths. If not specified, infer from current directory if possible. =item B<--verbose> whistle while we work. multiple calls increase the verbosity level. =back =head1 DESCRIPTION Runs diff over the list of files, collecting the output. When complete, outputs the stats followed by the diffs to stdout. =head1 EXAMPLES examples =head1 NOTE note =head1 BUGS Undoubtedly. Contact the author with the particulars if this is stopping your progress. =head1 FILES B - perl script =head1 AUTHOR Doug Maxey =cut