X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=util%2Fprocess_docs.pl;h=d2fef5dedf3153f15c8cd69673597cfcc311e323;hp=eaa4964869bc8cf549ba7234c23e6d4108db21ad;hb=9059ab425aed6019a7d56ce4b9c55abeefc08d9d;hpb=2bc57c88d852d83ee31f68f5b84b36d54b4c3dc4 diff --git a/util/process_docs.pl b/util/process_docs.pl old mode 100644 new mode 100755 index eaa4964869..d2fef5dedf --- a/util/process_docs.pl +++ b/util/process_docs.pl @@ -1,7 +1,7 @@ #! /usr/bin/env perl -# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. # -# Licensed under the OpenSSL license (the "License"). You may not use +# Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy # in the file LICENSE in the source distribution or at # https://www.openssl.org/source/license.html @@ -13,51 +13,64 @@ use File::Spec::Functions; use File::Basename; use File::Copy; use File::Path; +use FindBin; +use lib "$FindBin::Bin/perl"; +use OpenSSL::Glob; use Getopt::Long; use Pod::Usage; use lib '.'; use configdata; +# We know we are in the 'util' directory and that our perl modules are +# in util/perl +use lib catdir(dirname($0), "perl"); +use OpenSSL::Util::Pod; + my %options = (); GetOptions(\%options, - 'sourcedir=s', # Source directory - 'subdir=s%', # Subdirectories to look through, + 'sourcedir=s@', # Source directories + 'section=i@', # Subdirectories to look through, # with associated section numbers 'destdir=s', # Destination directory #'in=s@', # Explicit files to process (ignores sourcedir) - #'section=i', # Default section used for --in files 'type=s', # The result type, 'man' or 'html' + 'suffix:s', # Suffix to add to the extension. + # Only used with type=man 'remove', # To remove files rather than writing them 'dry-run|n', # Only output file names on STDOUT 'debug|D+', ); -unless ($options{subdir}) { - $options{subdir} = { apps => '1', - crypto => '3', - ssl => '3' }; +unless ($options{section}) { + $options{section} = [ 1, 3, 5, 7 ]; } unless ($options{sourcedir}) { - $options{sourcedir} = catdir($config{sourcedir}, "doc"); + $options{sourcedir} = [ catdir($config{sourcedir}, "doc"), + catdir($config{builddir}, "doc") ]; } -pod2usage(1) unless ( defined $options{subdir} +pod2usage(1) unless ( defined $options{section} && defined $options{sourcedir} && defined $options{destdir} && defined $options{type} && ($options{type} eq 'man' || $options{type} eq 'html') ); +pod2usage(1) if ( $options{type} eq 'html' + && defined $options{suffix} ); if ($options{debug}) { print STDERR "DEBUG: options:\n"; - print STDERR "DEBUG: --sourcedir = $options{sourcedir}\n" - if defined $options{sourcedir}; + foreach (sort @{$options{sourcedir}}) { + print STDERR "DEBUG: --sourcedir = $_\n"; + } print STDERR "DEBUG: --destdir = $options{destdir}\n" if defined $options{destdir}; print STDERR "DEBUG: --type = $options{type}\n" if defined $options{type}; - foreach (keys %{$options{subdir}}) { - print STDERR "DEBUG: --subdir = $_=$options{subdir}->{$_}\n"; + print STDERR "DEBUG: --suffix = $options{suffix}\n" + if defined $options{suffix}; + foreach (sort @{$options{section}}) { + print STDERR "DEBUG: --section = $_\n"; } print STDERR "DEBUG: --remove = $options{remove}\n" if defined $options{remove}; @@ -69,48 +82,25 @@ if ($options{debug}) { my $symlink_exists = eval { symlink("",""); 1 }; -foreach my $subdir (keys %{$options{subdir}}) { - my $section = $options{subdir}->{$subdir}; - my $podsourcedir = catfile($options{sourcedir}, $subdir); - my $podglob = catfile($podsourcedir, "*.pod"); +foreach my $section (sort @{$options{section}}) { + my $subdir = "man$section"; + my @podsourcedirs = map { catfile($_, $subdir); } @{$options{sourcedir}}; + my @podglobs = map { catfile($_, "*.pod"); } @podsourcedirs; - foreach my $podfile (glob "$podglob") { + foreach my $podfile (map { glob $_ } @podglobs) { my $podname = basename($podfile, ".pod"); my $podpath = catfile($podfile); - my %podinfo = ( section => $section ); - - print STDERR "DEBUG: Reading $podpath\n" if $options{debug}; - open my $pod_fh, $podpath or die "Trying to read $podpath: $!\n"; - while (<$pod_fh>) { - s|\R$||; - if (m|^=for\s+comment\s+openssl_manual_section:\s*([0-9])\s*$|) { - print STDERR "Found section number $1\n" if $options{debug}; - $podinfo{section} = $1; - } - last if m|^=head1| && defined $podinfo{lastsect} eq "NAME"; - if (m|^head1=\s*(.*)|) { - $podinfo{lastsect} = $1; - $podinfo{lastsect} =~ s/\s+$//; - } - next if (m|^=| || m|^\s*$|); - $podinfo{lastsecttext} .= " "; - $podinfo{lastsecttext} .= $_; - } - close $pod_fh; - $podinfo{lastsecttext} =~ s| - .*$||; - print STDERR "DEBUG: Done reading $podpath\n" if $options{debug}; - - my @podfiles = - grep { $_ ne $podname } - map { s|\s+||g; $_ } - split(m|,|, $podinfo{lastsecttext}); + my %podinfo = extract_pod_info($podpath, + { debug => $options{debug}, + section => $section }); + my @podfiles = grep { $_ ne $podname } @{$podinfo{names}}; my $updir = updir(); my $name = uc $podname; - my $suffix = { man => ".$podinfo{section}", + my $suffix = { man => ".$podinfo{section}".($options{suffix} // ""), html => ".html" } -> {$options{type}}; my $generate = { man => "pod2man --name=$name --section=$podinfo{section} --center=OpenSSL --release=$config{version} \"$podpath\"", - html => "pod2html \"--podroot=$options{sourcedir}\" --htmldir=$updir --podpath=apps:crypto:ssl \"--infile=$podpath\" \"--title=$podname\"" + html => "pod2html \"--podroot=$options{sourcedir}\" --htmldir=$updir --podpath=man1:man3:man5:man7 \"--infile=$podpath\" \"--title=$podname\" --quiet" } -> {$options{type}}; my $output_dir = catdir($options{destdir}, "man$podinfo{section}"); my $output_file = $podname . $suffix; @@ -122,8 +112,34 @@ foreach my $subdir (keys %{$options{subdir}}) { if $options{debug}; unless ($options{"dry-run"}) { @output = `$generate`; - map { s|href="http://man\.he\.net/man|href="../man|g; } @output + map { s|href="http://man\.he\.net/(man\d/[^"]+)(?:\.html)?"|href="../$1.html"|g; } @output if $options{type} eq "html"; + if ($options{type} eq "man") { + # Because some *roff parsers are more strict than others, + # multiple lines in the NAME section must be merged into + # one. + my $in_name = 0; + my $name_line = ""; + my @newoutput = (); + foreach (@output) { + if ($in_name) { + if (/^\.SH "/) { + $in_name = 0; + push @newoutput, $name_line."\n"; + } else { + chomp (my $x = $_); + $name_line .= " " if $name_line; + $name_line .= $x; + next; + } + } + if (/^\.SH +"NAME" *$/) { + $in_name = 1; + } + push @newoutput, $_; + } + @output = @newoutput; + } } print STDERR "DEBUG: Done processing\n" if $options{debug}; @@ -194,6 +210,7 @@ B [B<--sourcedir>=I] B<--destdir>=I B<--type>=B|B +[B<--suffix>=I] [B<--remove>] [B<--dry-run>|B<-n>] [B<--debug>|B<-D>] @@ -226,6 +243,10 @@ Top directory where the resulting files should end up Type of output to produce. Currently supported are man pages and HTML files. +=item B<--suffix>=I + +A suffix added to the extension. Only valid with B<--type>=B + =item B<--remove> Instead of writing the files, remove them. @@ -242,9 +263,9 @@ Print extra debugging output. =head1 COPYRIGHT -Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2013-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html