#!/usr/local/bin/perl # # patch.pl # # This file, along with the patches, should be placed in and run from ns-allinone/patches # # Usage: ./patch.pl patch_dir # # Example: ./patch.pl 01Jun15-BL-UNC $top_patches_dir = `pwd`; chop $top_patches_dir; $top_dir = $top_patches_dir; substr ($top_dir, -8) = ""; $ns_dir = "$top_dir/ns-2.1b8"; $patch_dir = "$top_patches_dir/$ARGV[0]"; print "Patching $patch_dir to $ns_dir\n\n"; @files = `ls $patch_dir/*.patch`; foreach $full_filename (@files) { chop $full_filename; # remove \n $filename = `basename $full_filename`; # remove path from full_filename chop $filename; # remove \n $patch = $filename; # save patch filename substr ($patch, -6) = ""; # remove .patch from filename if ($patch eq "ns2.1b8") { print "patching $patch...\n"; $cmd = "cd $ns_dir; patch < $full_filename 2>$full_filename.out"; print "$cmd\n\n"; system ("$cmd"); } else { @subdirs = split ('-', $patch); if ($#subdirs == 1) { print "patching ns-2.1b8/$subdirs[1]...\n"; $cmd = "mkdir -p $ns_dir/$subdirs[1]"; print "$cmd\n"; system ("$cmd"); $cmd = "cd $ns_dir/$subdirs[1]; patch < $full_filename 2>$full_filename.out"; print "$cmd\n\n"; system ("$cmd"); } elsif ($#subdirs == 2){ print "patching ns-2.1b8/$subdirs[1]/$subdirs[2]...\n"; $cmd = "mkdir -p $ns_dir/$subdirs[1]/$subdirs[2]"; print "$cmd\n"; system ("$cmd"); $cmd = "cd $ns_dir/$subdirs[1]/$subdirs[2]; patch < $full_filename 2>$full_filename.out"; print "$cmd\n\n"; system ("$cmd"); } } } print "DONE -- Checking for failures...\n"; system ("grep fail $patch_dir/*.out");