# # Converts and xcopy command line into the appropriate binplace # command line(s) # use strict; # GLOBALS my $gExcludes=""; my @all_files=(); # Never exit if a single file failed my $gFlags ="-e"; MAIN: { foreach ("_NTTREE","_NTROOT","_NTDRIVE") { if (! defined $ENV{$_} ) { die("# $0 : Must be run from a Razzle window!\n"); } } my($src, $dst) = ParseArgs(\@ARGV); if ($gExcludes ne "") { $gExcludes = "($gExcludes)"; } my $cwd = `cd`; chomp $cwd; my $nttree = $ENV{'_NTTREE'}; my $ntdrive = $ENV{'_NTDRIVE'}; my $ntroot = $ENV{'_NTROOT'}; # Make placeroot and tempdst my $placeroot = $dst; my $rootdst; $placeroot =~ s/^\Q$nttree\E//; $placeroot =~ /.*[^:](\\[^\\]*)/; $rootdst = $1; $rootdst = "" if (!defined $rootdst); $placeroot =~ s/\Q$rootdst\E$//; $placeroot =~ s/^\\//; $rootdst =~ s/^\\//; $rootdst =~ s/\\$//; $placeroot = "\%_NTTREE\%\\$placeroot"; if ($gExcludes eq "") { # No need to do file by file listings, just # copy entire directories if (-d $src) { push(@all_files, "$src\\*"); RecurseDirectoryTree($src, \&IsDir); } else { push(@all_files, $src); } } else { # Need to go file by file so we can exclude # files. UseExcludes($src); if (-d $src) { RecurseDirectoryTree($src, \&UseExcludes); } } if ($#all_files < 0) { die("# $0 : No files to copy found.\n"); } my $file; foreach $file (@all_files) { my $temp = $file; # Translate the src $file =~ s/^\Q$ntdrive\E//i; $file =~ s/\Q$ntroot\E\\//i; # Translate the dest $temp =~ /^\Q$src\E(.*)/; $temp = $1; $temp =~ s/\\[^\\]*$//; $temp =~ s/^\\//; my $dest = ($rootdst eq "") ? (($temp eq "") ? "." : $temp) : "$rootdst\\$temp"; $dest = ".\\" if $dest eq ""; ##HERE## system "binplace $gFlags -R $placeroot -:DEST $dest $file\n"; } } # Add excludes to the global regexp sub AddExcludesToGlobals { my $exclude_file = shift; my $line; if (! open(hFILE, "$exclude_file") ) { print("BUILDMSG: $0: Can't open exclude file \"$exclude_file\". Skipping.\n"); return; } while ($line = ) { chomp $line; if ($line =~ /^\*$/) { print("BUILDMSG: $0: Skipping global mask (*) in file $exclude_file.\n"); next; } $line =~ s/\\/\\\\/g; # \ to \\ $line =~ s/\./\\\./g; # . to \. $line =~ s/\?/\./g; # ? to . $line =~ s/\*/\.\*/g; # * to .* $line =~ s/\{/\\\{/g; # { to \{ $line =~ s/\}/\\\}/g; # } to \} $line =~ s/\(/\\\(/g; # ( to \( $line =~ s/\)/\\\)/g; # ) to \) if ($gExcludes ne "") { $gExcludes .= "|$line"; } else { $gExcludes = "$line"; } } } # Sub to process files not using excludes sub IsDir { my $file = shift; if (-d $file) { push(@all_files, "$file\\*"); } } # Parse the command line sub ParseArgs { my @OPTS_ARRAY = @{$_[0]}; my $OPT; my $source = ""; my $dest = ""; my %options; foreach $OPT (@OPTS_ARRAY) { my $switch = uc(substr($OPT,0,1)); my $value; my $i; # generic loop var my $c; # to hold a char # Convert XCopy Flags if ( $switch =~ /[-\/]/) { $value = substr($OPT, 1); if ( uc(substr($value,0,8)) eq "EXCLUDE:") { # HANDLE EXCLUDES; $value = substr($value, 8); my @ExcludeFiles = split(/\+/, $value); foreach (@ExcludeFiles) { AddExcludesToGlobals($_); } } else { for ($i=0;$i