? .htaccess ? README ? line-endings.diff ? test ? test.txt ? useFileSpec08.diff Index: preprocessor.pl =================================================================== RCS file: /cvsroot/mozilla/config/preprocessor.pl,v retrieving revision 3.24 diff --unified=8 -d -p -r3.24 preprocessor.pl --- preprocessor.pl 21 Jan 2004 15:34:10 -0000 3.24 +++ preprocessor.pl 25 Jan 2004 16:07:03 -0000 @@ -80,31 +80,26 @@ unshift(@ARGV, @includes); # do the work foreach (@ARGV) { include($stack, $_); } exit(0); ######################################################################## package main; -use File::Spec; +use File::Spec 0.8; use File::Spec::Unix; # on all platforms, because the #include syntax is unix-based -# Note: Ideally we would use File::Spec 0.8. When this becomes -# possible, add "0.8" to the first "use" line above, then replace -# occurances of "::_0_8::" with "->" below. And remove the code for -# File::Spec 0.8 much lower down the file. - sub include { my($stack, $filename) = @_; my $directory = $stack->{'variables'}->{'DIRECTORY'}; if ($filename ne '-') { - $filename = File::Spec::_0_8::rel2abs($filename, $directory); - my($volume, $path) = File::Spec::_0_8::splitpath($filename); - $directory = File::Spec::_0_8::catpath($volume, $path, ''); + $filename = File::Spec->rel2abs($filename, $directory); + my($volume, $path) = File::Spec->splitpath($filename); + $directory = File::Spec->catpath($volume, $path, ''); } local $stack->{'variables'}->{'DIRECTORY'} = $directory; local $stack->{'variables'}->{'FILE'} = $filename; local $stack->{'variables'}->{'LINE'} = 0; local *FILE; open(FILE, $filename) or die "Couldn't open $filename: $!\n"; while () { # on cygwin, line endings are screwed up, so normalise them. @@ -273,17 +268,17 @@ sub print { } } } sub visit { my $self = shift; my($filename) = @_; my $directory = $stack->{'variables'}->{'DIRECTORY'}; - $filename = File::Spec::_0_8::abs2rel(File::Spec::_0_8::rel2abs($filename, $directory)); + $filename = File::Spec->abs2rel(File::Spec->rel2abs($filename, $directory)); CORE::print("$filename\n"); } ######################################################################## package preprocessor; sub define { @@ -411,17 +406,17 @@ sub literal { my $line = shift; $stack->print("$line\n"); } sub include { my $stack = shift; return if $stack->disabled; die "argument expected\n" unless @_; - my $filename = File::Spec::_0_8::catpath(File::Spec::_0_8::splitpath(@_)); + my $filename = File::Spec->catpath(File::Spec->splitpath(@_)); if ($stack->{'dependencies'}) { $stack->visit($filename); } else { main::include($stack, $filename); } } sub filter { @@ -468,124 +463,9 @@ sub substitution { } sub attemptSubstitution { my($stack, $text) = @_; $text =~ s/@(\w+)@/$stack->get($1, 0)/gose; return $text; } -######################################################################## - -######################################################################## -# This code is from File::Spec::Unix 0.8. -# It is not considered a part of the preprocessor.pl source file -# This code is licensed under the same license as File::Spec itself. - -package File::Spec::_0_8; - -use Cwd; - -sub rel2abs { - my ($path, $base) = @_; - if ( ! File::Spec->file_name_is_absolute( $path ) ) { - if ( !defined( $base ) || $base eq '' ) { - $base = cwd() ; - } elsif ( ! File::Spec->file_name_is_absolute( $base ) ) { - $base = rel2abs( $base ); - } else { - $base = File::Spec->canonpath( $base ); - } - $path = File::Spec->catdir( $base, $path ); - } - return File::Spec->canonpath( $path ); -} - -sub splitdir { - return split m|/|, $_[1], -1; # Preserve trailing fields -} - -sub splitpath { - my ($path, $nofile) = @_; - - my ($volume,$directory,$file) = ('','',''); - - if ( $nofile ) { - $directory = $path; - } - else { - $path =~ m|^ ( (?: .* / (?: \.\.?\Z(?!\n) )? )? ) ([^/]*) |xs; - $directory = $1; - $file = $2; - } - - return ($volume,$directory,$file); -} - -sub catpath { - my ($volume,$directory,$file) = @_; - - if ( $directory ne '' && - $file ne '' && - substr( $directory, -1 ) ne '/' && - substr( $file, 0, 1 ) ne '/' - ) { - $directory .= "/$file" ; - } - else { - $directory .= $file ; - } - - return $directory ; -} - -sub abs2rel { - my($path,$base) = @_; - - # Clean up $path - if ( ! File::Spec->file_name_is_absolute( $path ) ) { - $path = rel2abs( $path ) ; - } - else { - $path = File::Spec->canonpath( $path ) ; - } - - # Figure out the effective $base and clean it up. - if ( !defined( $base ) || $base eq '' ) { - $base = cwd(); - } - elsif ( ! File::Spec->file_name_is_absolute( $base ) ) { - $base = rel2abs( $base ) ; - } - else { - $base = File::Spec->canonpath( $base ) ; - } - - # Now, remove all leading components that are the same - my @pathchunks = File::Spec::_0_8::splitdir( $path); - my @basechunks = File::Spec::_0_8::splitdir( $base); - - while (@pathchunks && @basechunks && $pathchunks[0] eq $basechunks[0]) { - shift @pathchunks ; - shift @basechunks ; - } - - $path = CORE::join( '/', @pathchunks ); - $base = CORE::join( '/', @basechunks ); - - # $base now contains the directories the resulting relative path - # must ascend out of before it can descend to $path_directory. So, - # replace all names with $parentDir - $base =~ s|[^/]+|..|g ; - - # Glue the two together, using a separator if necessary, and preventing an - # empty result. - if ( $path ne '' && $base ne '' ) { - $path = "$base/$path" ; - } else { - $path = "$base$path" ; - } - - return File::Spec->canonpath( $path ) ; -} - -# End code from File::Spec::Unix 0.8. ########################################################################