5 kx #!/usr/bin/perl
5 kx
5 kx use FindBin;
5 kx use lib $FindBin::Bin;
5 kx
5 kx use strict;
5 kx use warnings FATAL => 'all';
5 kx use _kxLab;
5 kx
5 kx my $filename = shift or die "Error: Need a patch file";
5 kx my $arg2 = shift;
5 kx my $depmode = 0;
5 kx my $dir = ".";
5 kx if( defined( $arg2 ) )
5 kx {
5 kx if( $arg2 eq "-dep-" )
5 kx {
5 kx $depmode = 1;
5 kx }
5 kx else
5 kx {
5 kx $dir = $arg2;
5 kx }
5 kx }
5 kx
5 kx open( PATCH, "<$filename" ) or die "Error: Could not open patch file: $filename: $!";
5 kx while( <PATCH> )
5 kx {
5 kx next if /^#/;
5 kx if (/(\S+)\s*(.*)/)
5 kx {
5 kx if( $depmode )
5 kx {
5 kx print "$1 ";
5 kx }
5 kx else
5 kx {
5 kx my $arg = $2 || "-p0";
5 kx print "=== Applying $1 ===\n";
5 kx _kxLab::system( "patch -d $dir $arg < $1" );
5 kx }
5 kx }
5 kx }
5 kx close PATCH;
5 kx if( $depmode )
5 kx {
5 kx print "$filename\n";
5 kx }
5 kx