die "$0: delta source defined but not target";
}
} elsif (defined $delta_target) {
- die "$0: delta target defined but not target";
+ die "$0: delta target defined but not source";
}
close MASTER;
# Find all the modules
{
my @modpods;
- find \&getpods => map {abs_from_top($_)} qw(lib/ ext/);
+ find \&getpods => abs_from_top('lib/');
sub getpods {
if (/\.p(od|m)$/) {
return if $file =~ m!XS/(?:APItest|Typemap)!;
my $pod = $file;
return if $pod =~ s/pm$/pod/ && -e $pod;
- die "$0: tut $File::Find::name" if $file =~ /TUT/;
unless (open (F, "< $_\0")) {
warn "$0: bogus <$file>: $!";
system "ls", "-l", $file;
while ($line = <F>) {
if ($line =~ /^=head1\s+NAME\b/) {
push @modpods, $file;
- #warn "GOOD $file\n";
close F;
return;
}
my %done;
for (@modpods) {
- #($name) = /(\w+)\.p(m|od)$/;
- my $name = path2modname($_);
+ my $name = $_;
+ $name =~ s/\.p(m|od)$//;
+ $name =~ s-.*?/lib/--;
+ $name =~ s-/-::-g;
+ next if $done{$name}++;
+
if ($name =~ /^[a-z]/) {
$Pragmata{$name} = $_;
} else {
- if ($done{$name}++) {
- # warn "already did $_\n";
- next;
- }
$Modules{$name} = $_;
}
}
# OK. Now a lot of ancillary function definitions follow
# Main program returns at "Do stuff"
-sub path2modname {
- local $_ = shift;
- s/\.p(m|od)$//;
- s-.*?/(lib|ext)/--;
- s-/-::-g;
- s/(\w+)::\1/$1/;
- return $_;
-}
-
-sub output ($);
+my $OUT;
sub output_perltoc {
my $filename = shift;
- open OUT, '>', $filename or die "$0: creating $filename failed: $!";
-
- local $/ = '';
- ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+ ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
# !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
# This file is autogenerated by buildtoc from all the other pods.
}
- ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+ ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
podset($_, $Pragmata{$_});
}
- ($_= <<"EOPOD2B") =~ s/^\t//gm && output($_);
+ ($_= <<"EOPOD2B") =~ s/^\t//gm and $OUT .= $_;
EOPOD2B
s/^\t//gm;
- output $_;
- output "\n"; # flush $LINE
+ $OUT .= "$_\n";
+
+ $OUT =~ s/\n\s+\n/\n\n/gs;
+ $OUT =~ s/\n{3,}/\n\n/g;
+
+ $OUT =~ s/([^\n]+)/wrap('', '', $1)/ge;
+
+ open OUT, '>', $filename or die "$0: creating $filename failed: $!";
+ print OUT $OUT;
close OUT;
}
sub podset {
my ($pod, $file) = @_;
+ local $/ = '';
+
open my $fh, '<', $file or die "Can't open file '$file' for $pod: $!";
while(<$fh>) {
tr/\015//d;
if (s/^=head1 (NAME)\s*/=head2 /) {
unhead1();
- output "\n\n=head2 ";
+ $OUT .= "\n\n=head2 ";
$_ = <$fh>;
# Remove svn keyword expansions from the Perl FAQ
s/ \(\$Revision: \d+ \$\)//g;
if ( /^\s*\Q$pod\E\b/ ) {
s/$pod\.pm/$pod/; # '.pm' in NAME !?
- output $_;
} else {
s/^/$pod, /;
- output $_;
}
- next;
}
- if (s/^=head1 (.*)/=item $1/) {
+ elsif (s/^=head1 (.*)/=item $1/) {
unhead2();
- output "=over 4\n\n" unless $inhead1;
+ $OUT .= "=over 4\n\n" unless $inhead1;
$inhead1 = 1;
- output $_; nl(); next;
+ $_ .= "\n";
}
- if (s/^=head2 (.*)/=item $1/) {
+ elsif (s/^=head2 (.*)/=item $1/) {
unitem();
- output "=over 4\n\n" unless $inhead2;
+ $OUT .= "=over 4\n\n" unless $inhead2;
$inhead2 = 1;
- output $_; nl(); next;
+ $_ .= "\n";
}
- if (s/^=item ([^=].*)/$1/) {
+ elsif (s/^=item ([^=].*)/$1/) {
next if $pod eq 'perldiag';
s/^\s*\*\s*$// && next;
s/^\s*\*\s*//;
s/\s+$//;
next if /^[\d.]+$/;
next if $pod eq 'perlmodlib' && /^ftp:/;
- ##print "=over 4\n\n" unless $initem;
- output ", " if $initem;
+ $OUT .= ", " if $initem;
$initem = 1;
s/\.$//;
s/^-X\b/-I<X>/;
- output $_; next;
}
- if (s/^=cut\s*\n//) {
- unhead1();
+ else {
+ unhead1() if /^=cut\s*\n/;
next;
}
+ $OUT .= $_;
}
}
sub unhead1 {
unhead2();
if ($inhead1) {
- output "\n\n=back\n\n";
+ $OUT .= "\n\n=back\n\n";
}
$inhead1 = 0;
}
sub unhead2 {
unitem();
if ($inhead2) {
- output "\n\n=back\n\n";
+ $OUT .= "\n\n=back\n\n";
}
$inhead2 = 0;
}
sub unitem {
if ($initem) {
- output "\n\n";
- ##print "\n\n=back\n\n";
+ $OUT .= "\n\n";
}
$initem = 0;
}
-sub nl {
- output "\n";
-}
-
-my $NEWLINE = 0; # how many newlines have we seen recently
-my $LINE; # what remains to be printed
-
-sub output ($) {
- for (split /(\n)/, shift) {
- if ($_ eq "\n") {
- if ($LINE) {
- print OUT wrap('', '', $LINE);
- $LINE = '';
- }
- if (($NEWLINE) < 2) {
- print OUT;
- $NEWLINE++;
- }
- }
- elsif (/\S/ && length) {
- $LINE .= $_;
- $NEWLINE = 0;
- }
- }
-}
-
# End of original buildtoc. From here on are routines to generate new sections
# for and inplace edit other files
# Annoyingly, unexpand doesn't consider it good form to replace a single
# space before a tab with a tab
# Annoyingly (2) it returns read only values.
- my @temp = unexpand (map {sprintf "%-32s%s\n", @$_} @_);
+ my @temp = unexpand (map {sprintf "%-32s%s", @$_} @_);
map {s/ \t/\t\t/g; $_} @temp;
}
sub generate_manifest_pod {
sort keys %Pods, keys %Readmepods;
}
-sub generate_descrip_mms_3 {
- map qq{\t- If F\$Search("[.pod]$_").nes."" Then Delete/NoConfirm/Log [.pod]$_;*},
- sort keys %Generated, keys %Copies;
-}
-
sub generate_nmake_1 {
# XXX Fix this with File::Spec
(map {sprintf "\tcopy ..\\README.%-8s ..\\pod\\perl$_.pod\n", $_}
}
sub do_manifest {
- my $name = shift;
+ my ($name, $prev) = @_;
my @manifest =
- grep {! m!^pod/[^.]+\.pod.*\n!}
- grep {! m!^README\.(\S+)! || $Ignore{$1}} @_;
- # Dictionary order - fold and handle non-word chars as nothing
- map { $_->[0] }
- sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }
- map { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] }
- @manifest,
- &generate_manifest_pod(),
- &generate_manifest_readme();
+ grep {! m!^pod/[^.]+\.pod.*!}
+ grep {! m!^README\.(\S+)! || $Ignore{$1}} split "\n", $prev;
+ join "\n", (
+ # Dictionary order - fold and handle non-word chars as nothing
+ map { $_->[0] }
+ sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }
+ map { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] }
+ @manifest,
+ &generate_manifest_pod(),
+ &generate_manifest_readme()), '';
}
sub do_nmake {
- my $name = shift;
- my $makefile = join '', @_;
- die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
+ my ($name, $makefile) = @_;
$makefile =~ s/^\tcopy \.\.\\README.*\n/\0/gm;
verify_contiguous($name, $makefile, 'README copies');
# Now remove the other copies that follow
*do_dmake = *do_dmake = \&do_nmake;
sub do_perlpod {
- my $name = shift;
- my $pod = join '', @_;
+ my ($name, $pod) = @_;
unless ($pod =~ s{(For\ ease\ of\ access,\ .*\n)
(?:\s+[a-z]{4,}.*\n # fooo
}
sub do_podmak {
- my $name = shift;
- my $body = join '', @_;
+ my ($name, $body) = @_;
foreach my $variable (qw(pod man html tex)) {
die "$0: could not find $variable in $name"
unless $body =~ s{\n\U$variable\E = (?:[^\n]*\\\n)*[^\n]*}
}
sub do_vms {
- my $name = shift;
- my $makefile = join '', @_;
- die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
+ my ($name, $makefile) = @_;
$makefile =~ s/\npod\d* =[^\n]*/\0/gs;
verify_contiguous($name, $makefile, 'pod assignments');
$makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_1/se;
die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
+# Looking for the macro defining the current perldelta:
+#PERLDELTA_CURRENT = [.pod]perl5139delta.pod
+
+ $makefile =~ s/\nPERLDELTA_CURRENT\s+=\s+\Q[.pod]perl\E\d+delta\.pod\n
+ /\0/sx;
+ verify_contiguous($name, $makefile, 'current perldelta macro');
+ $makefile =~ s/\0+/join "\n", '', "PERLDELTA_CURRENT = [.pod]$delta_target", ''/se;
+
# Looking for rules like this
# [.lib.pods]perl.pod : [.pod]perl.pod
# @ If F$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
verify_contiguous($name, $makefile, 'copy rules');
$makefile =~ s/\0+/join "\n", '', &generate_descrip_mms_2/se;
-# Looking for rules like this:
-# - If F$Search("[.pod]perldelta.pod").nes."" Then Delete/NoConfirm/Log [.pod]perldelta.pod;*
- $makefile =~ s!(?:\t- If F\$Search\("\[\.pod\]perl\d*[a-z]+\Q.pod").nes."" Then Delete/NoConfirm/Log [.pod]perl\E\d*[a-z]+\.pod;\*\n)+!\0!sg;
- verify_contiguous($name, $makefile, 'delete rules');
- $makefile =~ s/\0+/join "\n", &generate_descrip_mms_3, ''/se;
-
$makefile;
}
sub do_unix {
- my $name = shift;
- my $makefile_SH = join '', @_;
- die "$0: $name contains NUL bytes" if $makefile_SH =~ /\0/;
+ my ($name, $makefile_SH) = @_;
$makefile_SH =~ s{^(perltoc_pod_prereqs = extra.pods).*}
{join ' ', $1, map "pod/$_",
next;
}
print "Now processing $name\n" if $Verbose;
+ local $/;
open THING, $name or die "Can't open $name: $!";
binmode THING;
- my @orig = <THING>;
- my $orig = join '', @orig;
+ my $orig = <THING>;
close THING;
- my @new = do {
+ die "$0: $name contains NUL bytes" if $orig =~ /\0/;
+ my $new = do {
no strict 'refs';
- &{"do_$target"}($target, @orig);
+ &{"do_$target"}($target, $orig);
};
- my $new = join '', @new;
if ($new eq $orig) {
print "Was not modified\n" if $Verbose;
next;