-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
-
-sub generate_perlpod {
- my @output;
- my $maxlength = 0;
- foreach (@Master) {
- my $flags = $_->[0];
- next if $flags->{aux};
- next if $flags->{perlpod_omit};
-
- if (@$_ == 2) {
- # Heading
- push @output, "=head2 $_->[1]\n";
- } elsif (@$_ == 3) {
- # Section
- my $start = " " x (4 + $flags->{indent}) . $_->[1];
- $maxlength = length $start if length ($start) > $maxlength;
- push @output, [$start, $_->[2]];
- } elsif (@$_ == 0) {
- # blank line
- push @output, "\n";
- } else {
- die "$0: Illegal length " . scalar @$_;
- }
- }
- # want at least 2 spaces padding
- $maxlength += 2;
- $maxlength = ($maxlength + 3) & ~3;
- # sprintf gives $1.....$2 where ... are spaces:
- return unexpand (map {ref $_ ? sprintf "%-${maxlength}s%s\n", @$_ : $_}
- @output);
-}
-
-
-sub generate_manifest {
- # Annyoingly 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", @$_} @_);
- map {s/ \t/\t\t/g; $_} @temp;
-}
-sub generate_manifest_pod {
- generate_manifest map {["pod/$_.pod", $Pods{$_}]}
- sort grep {!$Copies{"$_.pod"}} grep {!$Generated{"$_.pod"}} keys %Pods;
-}
-sub generate_manifest_readme {
- generate_manifest sort {$a->[0] cmp $b->[0]}
- ["README.vms", "Notes about installing the VMS port"],
- map {["README.$_", $Readmes{$_}]} keys %Readmes;
-}
-
-sub generate_roffitall {
- (map ({"\t\$maindir/$_.1\t\\"}sort keys %Pods),
- "\t\t\\",
- map ({"\t\$maindir/$_.1\t\\"}sort keys %Aux),
- "\t\t\\",
- map ({"\t\$libdir/$_.3\t\\"}sort keys %Pragmata),
- "\t\t\\",
- map ({"\t\$libdir/$_.3\t\\"}sort keys %Modules),
- )
-}
-
-sub generate_descrip_mms_1 {
- local $Text::Wrap::columns = 150;
- my $count = 0;
- my @lines = map {"pod" . $count++ . " = $_"}
- split /\n/, wrap('', '', join " ", map "[.lib.pods]$_.pod",
- sort keys %Pods, keys %Readmepods);
- @lines, "pod = " . join ' ', map {"\$(pod$_)"} 0 .. $count - 1;
-}
-
-sub generate_descrip_mms_2 {
- map {<<"SNIP"}
-[.lib.pods]$_.pod : [.pod]$_.pod
- \@ If F\$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
- Copy/NoConfirm/Log \$(MMS\$SOURCE) [.lib.pods]
-SNIP
- 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", $_}
- sort keys %Readmes),
- (map {"\tcopy ..\\pod\\$Copies{$_} ..\\pod\\$_\n"} sort keys %Copies);
-}
-
-# This doesn't have a trailing newline
-sub generate_nmake_2 {
- # Spot the special case
- local $Text::Wrap::columns = 76;
- my $line = wrap ("\t ", "\t ",
- join " ", sort keys %Copies, keys %Generated,
- map {"perl$_.pod"} keys %Readmes);
- $line =~ s/$/ \\/mg;
- $line;
-}
-
-sub generate_pod_mak {
- my $variable = shift;
- my @lines;
- my $line = join "\\\n", "\U$variable = ",
- map {"\t$_.$variable\t"} sort keys %Pods;
- # Special case
- $line =~ s/.*perltoc.html.*\n//m;
- $line;
-}
-
-sub verify_contiguous {
- my ($name, $content, $what) = @_;
- my $sections = () = $content =~ m/\0+/g;
- croak("$0: $name contains no $what") if $sections < 1;
- croak("$0: $name contains discontiguous $what") if $sections > 1;
-}
-
-sub do_manifest {
- my $name = shift;
- 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();
-}
-
-sub do_nmake {
- my $name = shift;
- my $makefile = join '', @_;
- die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
- $makefile =~ s/^\tcopy \.\.\\README.*\n/\0/gm;
- verify_contiguous($name, $makefile, 'README copies');
- # Now remove the other copies that follow
- 1 while $makefile =~ s/\0\tcopy .*\n/\0/gm;
- $makefile =~ s/\0+/join ("", &generate_nmake_1)/se;
-
- $makefile =~ s{(del /f [^\n]+podchecker[^\n]+).*?(pod2html)}
- {"$1\n" . &generate_nmake_2."\n\t $2"}se;
- $makefile;
-}
-
-# shut up used only once warning
-*do_dmake = *do_dmake = \&do_nmake;
-
-sub do_perlpod {
- my $name = shift;
- my $pod = join '', @_;
-
- unless ($pod =~ s{(For\ ease\ of\ access,\ .*\n)
- (?:\s+[a-z]{4,}.*\n # fooo
- |=head.*\n # =head foo
- |\s*\n # blank line
- )+
- }
- {$1 . join "", &generate_perlpod}mxe) {
- die "$0: Failed to insert amendments in do_perlpod";
- }
- $pod;
-}
-
-sub do_podmak {
- my $name = shift;
- my $body = join '', @_;
- 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]*}
- {"\n" . generate_pod_mak ($variable)}se;
- }
- $body;
-}
-
-sub do_vms {
- my $name = shift;
- my $makefile = join '', @_;
- die "$0: $name contains NUL bytes" if $makefile =~ /\0/;
- $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 rules like this
-# [.lib.pods]perl.pod : [.pod]perl.pod
-# @ If F$Search("[.lib]pods.dir").eqs."" Then Create/Directory [.lib.pods]
-# Copy/NoConfirm/Log $(MMS$SOURCE) [.lib.pods]
-
- $makefile =~ s/\n\Q[.lib.pods]\Eperl[^\n\.]*\.pod[^\n]+\n
- [^\n]+\n # Another line
- [^\n]+\Q[.lib.pods]\E\n # ends [.lib.pods]
- /\0/gsx;
- 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[a-z]+\Q.pod").nes."" Then Delete/NoConfirm/Log [.pod]perl\E[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/;
-
- $makefile_SH =~ s{^(perltoc_pod_prereqs = extra.pods).*}
- {join ' ', $1, map "pod/$_",
- sort keys %Copies, grep {!/perltoc/} keys %Generated
- }mge;
-
-# pod/perldelta.pod: pod/perl511delta.pod
-# cd pod && $(LNS) perl511delta.pod perldelta.pod
-
- $makefile_SH =~ s!(
-pod/perl[a-z0-9_]+\.pod: pod/perl[a-z0-9_]+\.pod
- \$\(LNS\) perl[a-z0-9_]+\.pod pod/perl[a-z0-9_]+\.pod
-)+!\0!gm;
-
- verify_contiguous($name, $makefile_SH, 'copy rules');
-
- my @copy_rules = map "
-pod/$_: pod/$Copies{$_}
- \$(LNS) $Copies{$_} pod/$_
-", keys %Copies;
-
- $makefile_SH =~ s/\0+/join '', @copy_rules/se;
- $makefile_SH;
-
-}
-
-# Do stuff
-
-my $built;
-while (my ($target, $name) = each %Targets) {
- next unless $Build{$target};
- $built++;
- if ($target eq "toc") {
- print "Now processing $name\n" if $Verbose;
- &output_perltoc;
- print "Finished\n" if $Verbose;
- next;
- }
- print "Now processing $name\n" if $Verbose;
- open THING, $name or die "Can't open $name: $!";
- my @orig = <THING>;
- my $orig = join '', @orig;
- close THING;
- my @new = do {
- no strict 'refs';
- &{"do_$target"}($target, @orig);
- };
- my $new = join '', @new;
- if ($new eq $orig) {
- print "Was not modified\n" if $Verbose;
- next;
- }
- rename $name, "$name.old" or die "$0: Can't rename $name to $name.old: $!";
- open THING, ">$name" or die "$0: Can't open $name for writing: $!";
- print THING $new or die "$0: print to $name failed: $!";
- close THING or die die "$0: close $name failed: $!";
-}
-
-warn "$0: was not instructed to build anything\n" unless $built;