develooper Front page | perl.perl5.porters | Postings from March 2003

[PATCH 5.8.0 UTIL] Fix installhtml for splitting and PM/POD conflicts

Thread Next
From:
Steve Hay
Date:
March 20, 2003 04:33
Subject:
[PATCH 5.8.0 UTIL] Fix installhtml for splitting and PM/POD conflicts
Message ID:
3E79B547.6030201@uk.radan.com
The patch below fixes four bugs in the installhtml utility:

1. The create_index() function does not correctly match the "NAME" 
section of the converted HTML files.  This is addressed by the change to 
the block of four lines in the section marked "@@ -329,14 +330,14 @@" in 
the patch.  Running the installhtml utility with arguments such as the 
following:

perl .\installhtml --podroot=C:/Temp/perl-5.8.0 --podpath=pod --recurse 
--libpods=perlfunc,perlguts,perlvar,perlrun,perlop 
--splititem=pod/perlfunc --splitpod=pod --htmldir=C:/Temp/perldocs 
--htmlroot=/

highlights this problem.  Without this change, the perlfunc.html index 
page created for the split perlfunc manpage contains entries like:

<A HREF="C:/Temp/perldocs/pod/perlfunc/abs.html">

[sic]!, i.e. no text is actually linked - there is nothing to click on.  
With this change, the "NAME" section is correctly matched and linked, 
and we get entries like:

<A 
HREF="C:/Temp/perldocs/pod/perlfunc/abs.html"><DT><p>abs</A><DD>absolute 
value function</p>

2. The above link itself, however, is still "wrong" in that it is 
absolute.  I believe it would be better if it were relative, thus 
allowing the document set created to be moved around from one location 
to another.  In the patch, the new line in the section marked "@@ -303,6 
+303,7 @@" creates a new $pod variable in the create_index() function, 
which is then used by the two one-line changes in the section marked "@@ 
-329,14 +330,14 @@".  Applying this change as well, the above entry 
would now become:

<A HREF="perlfunc/abs.html"><DT><p>abs</A><DD>absolute value function</p>

3. The split_on_item() function contains a pattern-match that is not 
"greedy" when it should be.  The section marked "@@ -393,7 +394,7 @@" in 
the patch fixes this.  Without this change, the above installhtml 
command-line works fine when all the POD files are in their original 
locations in the Perl source tree (the $pod being pattern-matched is 
"pod/perlfunc.pod", which just happens to by correctly split into 
$dirname and $filename "pod" and "perlfunc.pod" respectively), but when 
Perl is installed and the pod/* files are relocated into lib/pod/* then 
$pod becomes "lib/pod/perlfunc.pod" which is erroneously split into 
$dirname and $filename "lib" and "pod/perlfunc.pod" respectively.  Thus, 
the installhtml program does not work on an "installed" Perl source 
tree.  This change corrects the non-greedy pattern-match, so that 
$dirname and $filename become "lib/pod" and "perlfunc.pod" respectively, 
as must have been intended anyway.

4. Finally, the installdir() function is supposed to "prefer" a POD file 
to a PM file if both exist with the same basename, but it doesn't 
function as intended.  The section marked "@@ -550,7 +551,7 @@" in the 
patch fixes this.  Without this change, running the installhtml utility 
with the same arguments as above but with "--podpath=ext" rather than 
"--podpath=pod" we find that the file 
"C:\Temp\perldocs\ext\POSIX\POSIX.html" is all but empty because the 
POSIX.pm (which contains no POD) was accidentally used instead of the 
POSIX.pod file.  With this change, we get a 100kB POSIX.html file 
containing all the converted POD, as intended.

Please copy any discussion on this patch to me -- I'm not subscribed to 
the perl5-porters list.

Cheers

Steve

--- START PATCH ---
diff -ru perl-5.8.0.orig/installhtml perl-5.8.0/installhtml
--- perl-5.8.0.orig/installhtml    2002-06-01 19:03:14.000000000 +0100
+++ perl-5.8.0/installhtml    2003-03-20 11:13:39.000000000 +0000
@@ -303,6 +303,7 @@
 
 sub create_index {
     my($html, $dir) = @_;
+    (my $pod = $dir) =~ s,^.*/,,;
     my(@files, @filedata, @index, $file);
     my($lcp1,$lcp2);
 
@@ -329,14 +330,14 @@
 
     # pull out the NAME section
   my $name;
-    ($name) = grep(/NAME=/, @filedata);
-    ($lcp1,$lcp2) = ($name =~ m,/H1>\s(\S+)\s[\s-]*(.*?)\s*$,sm);
-    if (defined $lcp1 and $lcp1 eq '<P>') { # Uninteresting.  Try again.
-       ($lcp1,$lcp2) = ($name =~ m,/H1>\s<P>\s(\S+)\s[\s-]*(.*?)\s*$,sm);
+    ($name) = grep(/name="name"/i, @filedata);
+    ($lcp1,$lcp2) = ($name =~ m,/H1>\s(\S+)\s[\s-]*(.*?)\s*$,smi);
+    if (defined $lcp1 and $lcp1 =~ m,^<P>$,i) { # Uninteresting.  Try 
again.
+        ($lcp1,$lcp2) = ($name =~ 
m,/H1>\s<P>\s*(\S+)\s[\s-]*(.*?)\s*$,smi);
     }
-    my $url= "$dir/$file" ;
+    my $url= "$pod/$file" ;
     if ( ! defined $Options{htmlroot} || $Options{htmlroot} eq '' ) {
-        $url = Pod::Html::relativize_url( "$dir/$file", $html ) ;
+        $url = Pod::Html::relativize_url( "$pod/$file", $html ) ;
     }
 
     print HTML qq(<A HREF="$url">);
@@ -393,7 +394,7 @@
     foreach my $pod (@splititem) {
     # figure out the directory to split into
     $pod      =~ s,^([^/]*)$,/$1,;
-    $pod      =~ m,(.*?)/(.*?)(\.pod)?$,;
+    $pod      =~ m,(.*)/(.*?)(\.pod)?$,;
     $dirname  = "$1/$2";
     $filename = "$2.pod";
 
@@ -550,7 +551,7 @@
     next if grep($_ eq "$podroot/$pod.pod", @$ignore);
 
     # check if a .pm files exists too
-    if (grep($_ eq "$pod.pm", @pmlist)) {
+    if (grep($_ eq $pod, @pmlist)) {
         print  "$0: Warning both `$podroot/$pod.pod' and "
         . "`$podroot/$pod.pm' exist, using pod\n";
         push(@ignore, "$pod.pm");
--- END PATCH ---



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About