Re: patch preventing creation of empty top file (was Re: doc patch

Peter Moulder <[email protected]> Wed, 19 Sep 2001 08:39:15 +1000
Newsgroups gmane.comp.tex.texi2html.devel
Message-ID <[email protected]>
On Tue, Sep 18, 2001 at 02:24:48PM -0400, Derek Robert Price wrote:
> > Attached is a short context diff as per subject line.  (See also
> > <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=101265&repeatmerged=yes>.)
> 
> At face value, this looks good to me, but what cases created an empty top file
> previously?

In the old code shown in the patch, the file is opened unconditionally
but only written to if either !$T2H_SPLIT or $has_top; it's created as a
zero-length file if $T2H_SPLIT && !$has_top.

> Even with your patch, running texi2html on an empty file (touch
> test.texinfo; ./texi2html test.texinfo) creates a top file (test.html) containing
> the HTML header, footer, and the "This document was generated by ... on ... using
> texi2html" text.

The patch ensured that no zero-length file would be created, though I
didn't consider the "zero-content" case.

I've now looked at it some more, but I think it is doing the right thing
(except that perhaps it ought to warn) for contentless input.

The attached patch is [believed to be] logically identical to the
previous patch, but is arranged to be easier to understand: the
monolithic case is now in a separate block of code.  (Also used
$docu_doc_file instead of $docu_top_file, though these currently have
the same value in the monolithic case.)

pjm.
toppatch2 (text/plain, 2.2 KB)
Index: texi2html.pl
===================================================================
RCS file: /usr/local/tigris/data/helm/cvs/repository/texi2html/texi2html.pl,v
retrieving revision 1.3
diff -d -c -w -t -r1.3 texi2html.pl
*** texi2html.pl	2001/05/01 21:33:44	1.3
--- texi2html.pl	2001/09/18 22:32:53
***************
*** 3675,3696 ****
  
  
      #############################################################################
      # print Top
      #
      open(FILE, "> $docu_top_file")
          || die "$ERROR: Can't open $docu_top_file for writing: $!\n";
!     &$T2H_print_page_head(\*FILE) unless ($T2H_SPLIT);
  
-     if ($has_top)
-     {
          print "# Creating Top in $docu_top_file ...\n" if $T2H_VERBOSE;
          $T2H_THIS_SECTION = $T2H_TOP;
          $T2H_HREF{This} = $T2H_HREF{Top};
          $T2H_NAME{This} = $T2H_NAME{Top};
          &$T2H_print_Top(\*FILE);
      }
  
-     close(FILE) if $T2H_SPLIT;
  
      #############################################################################
      # Print sections
--- 3675,3714 ----
  
  
      #############################################################################
+     # Monolithic beginning.
+     #
+     unless ($T2H_SPLIT)
+     {
+         open(FILE, "> $docu_doc_file")
+             || die "$ERROR: Can't open $docu_doc_file for writing: $!\n";
+         &$T2H_print_page_head(\*FILE);
+     }
+ 
+ 
+     #############################################################################
      # print Top
      #
+     if ($has_top)
+     {
+         if ($T2H_SPLIT)
+         {
              open(FILE, "> $docu_top_file")
                  || die "$ERROR: Can't open $docu_top_file for writing: $!\n";
!         }
  
          print "# Creating Top in $docu_top_file ...\n" if $T2H_VERBOSE;
          $T2H_THIS_SECTION = $T2H_TOP;
          $T2H_HREF{This} = $T2H_HREF{Top};
          $T2H_NAME{This} = $T2H_NAME{Top};
          &$T2H_print_Top(\*FILE);
+ 
+         if ($T2H_SPLIT)
+         {
+             close(FILE)
+                 || die "$ERROR: Error occurred when closing $docu_top_file: $!\n";
+         }
      }
  
  
      #############################################################################
      # Print sections