use File::Basename; use File::Find; use File::Copy; use File::Path; use File::Spec; $S = "\001"; #$S = ";"; # @ # % * escapes... # sub p4_esc { my ($path) = (@_); $path =~ s/%/%25/g; $path =~ s/^\@/\001/; $path =~ s/\@$/\001/; $path =~ s/\@\@/%40/g; $path =~ s/^\001/\@/; $path =~ s/\001$/\@/; $path =~ s/#/%23/g; $path =~ s/\*/%2a/g; return $path; } sub rmfiles { my @files = @_; for $file (@files) { if (-d $file) { rmtree($file) || die("unable to rmtree $file: $!") } elsif (-e $file) { unlink($file) || die("unable to remove $file: $!"); } } } sub atq { my ($s) = @_; $s =~ s/\@/\@\@/g; return "\@$s\@"; } sub traverse { local($dir, $lev, $onfile, $ondir, $onsymlink) = @_; local($dirent); local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks); local($dirhandle) = "dh$lev"; opendir($dirhandle, $dir); while (($dirent = readdir($dirhandle))) { if ($dirent eq "." || $dirent eq "..") { next; } ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = lstat("$dir/$dirent"); typsw: { -f _ && do { if (defined(&$onfile)) { &$onfile("$dir", "$dirent"); } last typsw; } ; -d _ && do { if (defined(&$ondir)) { &$ondir("$dir", "$dirent"); } do traverse("$dir/$dirent", $lev+1, $onfile, $ondir, $onsymlink); last typsw; } ; -l "$dir/$dirent" && do { if (defined(&$onsymlink)) { &$onsymlink("$dir", "$dirent"); } if ($SYM_SPECIAL && $lev == 0) { do traverse("$dir/$dirent", $lev+1, $onfile, $ondir, $onsymlink); } last typsw; } ; } } closedir($dirhandle); } sub oscall { my ($cmd, $doit) = @_; my ($sts); if (! defined($doit)) { $doit = 1; } if (! $doit) { print "$Myname; $cmd\n"; return; } print "$Myname> $cmd\n"; if (($sts = system($cmd)) != 0) { my $sig = $sts & 0x0f; $sts = $sts >> 8; print ("$Myname: *** \"$cmd\" exited with signal $sig status $sts\n"); return $sts; } return 0; } sub p4d_vers { my ($P4D) = @_; my $v = `$P4D -V`; my ($y, $r) = ($v =~ m/\nRev. P4D\/[^\/]+\/(\d+)\.(\d+).*\//); if (! $v || ! $r) { print "$Myname: cannot recognize p4d version in:\n$v\n"; exit 1; } return ($y, $r); } my $cpfrom_base; my $cpto_base; sub cpfiles { my $from_path = $_; $from_path =~ s@\\@/@g; next if $from_path eq $cpfrom_base; $from_path =~ s/^$cpfrom_base//; $to_path = "$cpto_base/$from_path"; if (-d $_) { mkdir($to_path) || die("unable to mkdir $to_path: $!\n"); } else { copy($_, $to_path) || die("unable to copy $_: $!\n"); } } sub cptree { my ($from, $to) = @_; $cpfrom_base = File::Spec->rel2abs($from); $cpfrom_base =~ s@\\@/@g; $cpto_base = File::Spec->rel2abs($to); $cpto_base =~ s@\\@/@g; mkdir($cpto_base) || die("unable to mkdir $cpto_base: $!\n"); find({wanted =>\&cpfiles, no_chdir => 1 }, $cpfrom_base); } sub fixrcsfile { return if (-d $_); print "Fixing $File::Find::name\n"; open(FILE, $_) || die("unable to open $_ for reading: $!\n"); @lines = ; close(FILE); $updated = 0; @newlines = (); for $line (@lines) { if ($line =~ /^date.+author %USERNAME%;/) { $line =~ s/%USERNAME%/$ENV{USERNAME}/; } if ($line !~ /^(deltatype|permissions|commitid|kopt|filename|owner|group)/) { push(@newlines, $line); } } if ($MSWIN) { oscall("attrib -R -H \"$_\""); } else { chmod 0700; } open(FILE, ">$_") || die("unable to open $_ for writing: $!\n"); for $line (@newlines) { print FILE $line; } close(FILE); if ($MSWIN) { oscall("attrib +R \"$_\""); } else { chmod 0500; } } sub fixrcstree { find(\&fixrcsfile, $_[0]); } 1;