? .htaccess ? README ? line-endings.diff ? test ? test.txt Index: preprocessor.pl =================================================================== RCS file: /cvsroot/mozilla/config/preprocessor.pl,v retrieving revision 3.23 diff --unified=8 -d -p -r3.23 preprocessor.pl --- preprocessor.pl 9 Jan 2004 00:12:16 -0000 3.23 +++ preprocessor.pl 21 Jan 2004 15:24:13 -0000 @@ -58,16 +58,24 @@ while ($_ = $ARGV[0], defined($_) && /^- push(@includes, $1); } elsif (/^-E$/os) { foreach (keys %ENV) { # define all variables that have valid names $stack->define($_, $ENV{$_}) unless m/\W/; } } elsif (/^-d$/os) { $stack->{'dependencies'} = 1; + } elsif (/^--line-endings=crlf$/os) { + $stack->{'lineEndings'} = "\x0D\x0A"; + } elsif (/^--line-endings=cr$/os) { + $stack->{'lineEndings'} = "\x0D"; + } elsif (/^--line-endings=lf$/os) { + $stack->{'lineEndings'} = "\x0A"; + } elsif (/^--line-endings=(.+)$/os) { + die "$0: unrecognised line ending: $1\n"; } else { die "$0: invalid argument: $_\n"; } } unshift(@ARGV, '-') unless @ARGV; unshift(@ARGV, @includes); # do the work @@ -101,17 +109,17 @@ sub include { while () { # on cygwin, line endings are screwed up, so normalise them. s/[\x0D\x0A]+$/\n/os if $^O eq 'cygwin'; $stack->newline; if (/^\#([a-z]+)\n?$/os) { # argumentless processing instruction process($stack, $1); } elsif (/^\#([a-z]+)\s(.*?)\n?$/os) { # processing instruction with arguments process($stack, $1, $2); - } elsif (/^\#\n?/os) { # comment + } elsif (/^\#/os) { # comment # ignore it } elsif ($stack->enabled) { # print it, including any newlines $stack->print(filtered($stack, $_)); } } close(FILE); } @@ -168,16 +176,17 @@ sub new { }, 'filters' => { # filters }, 'values' => [], # the value of the last condition evaluated at the nth lewel 'lastPrinting' => [], # whether we were printing at the n-1th level 'printing' => 1, # whether we are currently printing at the Nth level 'dependencies' => 0, # whether we are showing dependencies + 'lineEndings' => "\n", # default to platform conventions }; } sub newline { my $self = shift; $self->{'variables'}->{'LINE'}++; } @@ -251,17 +260,23 @@ sub expand { my($line) = @_; $line =~ s/__(\w+)__/$self->get($1)/gose; return $line; } sub print { my $self = shift; return if $self->{'dependencies'}; - CORE::print(@_); + foreach my $line (@_) { + if (chomp $line) { + CORE::print("$line$self->{'lineEndings'}"); + } else { + CORE::print($line); + } + } } 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)); CORE::print("$filename\n");