michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: sub recursive_copy { michael@0: local($fromdir); michael@0: local($todir); michael@0: local(@dirlist); michael@0: $fromdir = shift; michael@0: $todir = shift; michael@0: michael@0: print STDERR "recursive copy called with $fromdir, $todir\n"; michael@0: michael@0: #remove any trailing slashes. michael@0: $fromdir =~ s/\/$//; michael@0: $todir =~ s/\/$//; michael@0: michael@0: opendir(DIR, $fromdir); michael@0: @dirlist = readdir DIR; michael@0: close DIR; michael@0: michael@0: michael@0: foreach $file (@dirlist) { michael@0: if (! (($file eq "." ) || ($file eq "..") )) { michael@0: michael@0: if (-d "$fromdir/$file") { michael@0: print STDERR "handling directory $todir/$file\n"; michael@0: &rec_mkdir("$todir/$file"); michael@0: &recursive_copy("$fromdir/$file","$todir/$file"); michael@0: } michael@0: else { michael@0: print STDERR "handling file $fromdir/$file\n"; michael@0: &my_copy("$fromdir/$file","$todir/$file"); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: sub parse_argv { michael@0: michael@0: # print STDERR "Parsing Variables\n"; michael@0: michael@0: foreach $q ( @ARGV ) { michael@0: if (! ($q =~ /=/)) { michael@0: $var{$lastassigned} .= " $q"; michael@0: } michael@0: else { michael@0: $q =~ /^([^=]*)=(.*)/; michael@0: $left = $1; michael@0: $right = $2; michael@0: michael@0: $right =~ s/ *$//; michael@0: $var{$left} = $right; michael@0: michael@0: $lastassigned = $left; michael@0: michael@0: } michael@0: print STDERR "Assigned $lastassigned = $var{$lastassigned}\n"; michael@0: } michael@0: } michael@0: michael@0: michael@0: # usage: &my_copy("dir/fromfile","dir2/tofile"); michael@0: # do a 'copy' - files only, 'to' MUST be a filename, not a directory. michael@0: michael@0: # fix this to be able to use copy on win nt. michael@0: michael@0: sub my_copy { michael@0: local($from); michael@0: local($to); michael@0: local($cpcmd); michael@0: michael@0: $from = shift; michael@0: $to = shift; michael@0: michael@0: if ( ! defined $var{OS_ARCH}) { michael@0: die "OS_ARCH not defined!"; michael@0: } michael@0: else { michael@0: if ($var{OS_ARCH} eq 'WINNT') { michael@0: $cpcmd = 'cp'; michael@0: } michael@0: else { michael@0: $cpcmd = 'cp'; michael@0: } michael@0: print STDERR "COPYING: $cpcmd $from $to\n"; michael@0: system("$cpcmd $from $to"); michael@0: } michael@0: } michael@0: michael@0: michael@0: sub old_my_copy { michael@0: local($from); michael@0: local($to); michael@0: michael@0: $from = shift; michael@0: $to = shift; michael@0: open(FIN, "<$from") || die("Can't read from file $from\n"); michael@0: if ( ! open(FOUT,">$to")) { michael@0: close FIN; michael@0: die "Can't write to file $to\n"; michael@0: } michael@0: while (read(FIN, $buf, 100000)) { michael@0: print FOUT $buf; michael@0: } michael@0: close (FIN); michael@0: close (FOUT); michael@0: } michael@0: michael@0: sub rec_mkdir { michael@0: local($arg); michael@0: local($t); michael@0: local($q); michael@0: michael@0: $arg = shift; michael@0: $t = ""; michael@0: foreach $q (split(/\//,$arg)) { michael@0: $t .= $q; michael@0: if (! ($t =~ /\.\.$/)) { michael@0: if ($t =~ /./) { michael@0: mkdir($t,0775); michael@0: } michael@0: } michael@0: $t.= '/'; michael@0: } michael@0: } michael@0: michael@0: 1;