texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...
Date: Sun, 13 Nov 2011 23:04:31 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/11/13 23:04:31

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Common.pm 
        tp/Texinfo/Convert: DocBook.pm HTML.pm Info.pm Plaintext.pm 
                            Text.pm XML.pm 
        tp/init        : book.pm chm.pm latex2html.pm tex4ht.pm 

Log message:
        Close every opened files and warn or error out when there was an error
        while closing.
        
        Add the possibility for registered handlers to abort the HTML 
conversion.
        
        Better error reporting and using.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.88&r2=1.89
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.95&r2=1.96
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/DocBook.pm?cvsroot=texinfo&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/HTML.pm?cvsroot=texinfo&r1=1.206&r2=1.207
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Info.pm?cvsroot=texinfo&r1=1.74&r2=1.75
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.189&r2=1.190
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Text.pm?cvsroot=texinfo&r1=1.81&r2=1.82
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/XML.pm?cvsroot=texinfo&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/init/book.pm?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/init/chm.pm?cvsroot=texinfo&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/init/latex2html.pm?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/init/tex4ht.pm?cvsroot=texinfo&r1=1.7&r2=1.8

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- texi2any.pl 11 Nov 2011 13:55:01 -0000      1.88
+++ texi2any.pl 13 Nov 2011 23:04:29 -0000      1.89
@@ -991,12 +991,22 @@
     my $macro_expand_file = get_conf('MACRO_EXPAND');
     my $macro_expand_fh = Texinfo::Common::open_out($parser, 
                                                     $macro_expand_file);
+
+    my $error_macro_expand_file;
     if (defined ($macro_expand_fh)) {
       print $macro_expand_fh $texinfo_text;
-      close ($macro_expand_fh);
+      if (!close ($macro_expand_fh)) {
+        warn (sprintf(__("Error on closing macro expand file %s: %s\n"), 
+                      $macro_expand_file, $!));
+        $error_macro_expand_file = 1;
+      }
     } else {
       warn (sprintf(__("Could not open %s for writing: %s\n"), 
                     $macro_expand_file, $!));
+      $error_macro_expand_file = 1;
+    }
+
+    if ($error_macro_expand_file) {
       $error_count++;
       exit (1) if ($error_count and (!get_conf('FORCE')
          or $error_count > get_conf('ERROR_LIMIT')));
@@ -1050,12 +1060,21 @@
     my $internal_links_file = get_conf('INTERNAL_LINKS');
     my $internal_links_fh = Texinfo::Common::open_out($converter, 
                                              $internal_links_file);
+    my $error_internal_links_file;
     if (defined ($internal_links_fh)) {
       print $internal_links_fh $internal_links_text;
-      close ($internal_links_fh);
+      
+      if (!close ($internal_links_fh)) {
+        warn (sprintf(__("Error on closing internal links file %s: %s\n"), 
+                      $internal_links_file, $!));
+        $error_internal_links_file = 1;
+      }
     } else {
       warn (sprintf(__("Could not open %s for writing: %s\n"), 
                     $internal_links_file, $!));
+      $error_internal_links_file = 1;
+    }
+    if ($error_internal_links_file) {
       $error_count++;
       exit (1) if ($error_count and (!get_conf('FORCE')
          or $error_count > get_conf('ERROR_LIMIT')));

Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -b -r1.95 -r1.96
--- Texinfo/Common.pm   11 Nov 2011 13:55:03 -0000      1.95
+++ Texinfo/Common.pm   13 Nov 2011 23:04:30 -0000      1.96
@@ -864,7 +864,10 @@
         push @{$verbatiminclude->{'contents'}}, 
                   {'type' => 'raw', 'text' => $_ };
       }
-      close (VERBINCLUDE);
+      if (!close (VERBINCLUDE)) {
+        $self->document_warn(sprintf($self->__("Error on closing 
address@hidden file %s: %s"),
+                             $file, $!));
+      }
     }
   } elsif ($self) {
     $self->line_error (sprintf($self->__("address@hidden: Cannot find %s"), 
@@ -1203,7 +1206,10 @@
       }
       $htmlxref->{$manual}->{$split_or_mono} = $href;
     }
-    close (HTMLXREF);
+    if (!close (HTMLXREF)) {
+      $self->document_warn(sprintf($self->__("Error on closing html refs 
config file %s: %s"),
+                             $file, $!));
+    }
   }
   return $htmlxref;
 }
@@ -1249,9 +1255,13 @@
       warn (sprintf($self->__("%s:%d: nodes without a new name at the end of 
file\n"),
              $renamed_nodes_file, $renamed_nodes_line_nr));
     }
-    close(RENAMEDFILE);
+    if (!close(RENAMEDFILE)) {
+      $self->document_warn(sprintf($self->__("Error on closing renamed nodes 
file %s: %s"), 
+                            $renamed_nodes_file, $!));
+    }
   } else {
-    warn (sprintf($self->__("Cannot read %s: %s"), $renamed_nodes_file, $!));
+    $self->document_warn(sprintf($self->__("Cannot read %s: %s"), 
+                         $renamed_nodes_file, $!));
   }
   return ($renamed_nodes, $renamed_nodes_lines);
 }

Index: Texinfo/Convert/DocBook.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/DocBook.pm,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- Texinfo/Convert/DocBook.pm  8 Nov 2011 00:05:50 -0000       1.31
+++ Texinfo/Convert/DocBook.pm  13 Nov 2011 23:04:30 -0000      1.32
@@ -331,6 +331,10 @@
   $result .= $self->_output_text($header, $fh);
   $result .= $self->convert_document_sections($root, $fh);
   $result .= $self->_output_text("</book>\n", $fh);
+  if ($fh and !close ($fh)) {
+    $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                  $self->{'output_filename'}, $!));
+  }
   return $result;
 }
 

Index: Texinfo/Convert/HTML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/HTML.pm,v
retrieving revision 1.206
retrieving revision 1.207
diff -u -b -r1.206 -r1.207
--- Texinfo/Convert/HTML.pm     11 Nov 2011 13:55:04 -0000      1.206
+++ Texinfo/Convert/HTML.pm     13 Nov 2011 23:04:30 -0000      1.207
@@ -6076,7 +6076,7 @@
     $toc_frame_outfile = $toc_frame_file;
   }
   
-  my $frame_fh = $self->Texinfo::Common::open_out ($frame_outfile);
+  my $frame_fh = $self->Texinfo::Common::open_out($frame_outfile);
   if (defined($frame_fh)) {
     my $doctype = $self->get_conf('FRAMESET_DOCTYPE');
     my $top_file = '';
@@ -6096,9 +6096,18 @@
 </html>
 EOT
 
+    if (!close ($frame_fh)) {
+      $self->document_error(sprintf($self->__("Error on closing frame file %s: 
%s"),
+                                    $frame_outfile, $!));
+      return 0;
+    }
+  } else {
+    $self->document_error(sprintf($self->__("Could not open %s for writing: 
%s"),
+                                  $frame_outfile, $!));
+    return 0;
   }
 
-  my $toc_frame_fh = $self->Texinfo::Common::open_out ($toc_frame_outfile);
+  my $toc_frame_fh = $self->Texinfo::Common::open_out($toc_frame_outfile);
   if (defined($toc_frame_fh)) {
 
     my $header = &{$self->{'format_begin_file'}}($self, $toc_frame_file, 
undef);
@@ -6110,7 +6119,17 @@
     print $toc_frame_fh $shortcontents;
     print $toc_frame_fh "</body></html>\n";
 
+    if (!close ($toc_frame_fh)) {
+      $self->document_error(sprintf($self->__("Error on closing TOC frame file 
%s: %s"),
+                                    $toc_frame_outfile, $!));
+      return 0;
   }
+  } else {
+    $self->document_error(sprintf($self->__("Could not open %s for writing: 
%s"),
+                                  $toc_frame_outfile, $!));
+    return 0;
+  }
+  return 1;
 }
 
 sub convert($$)
@@ -6202,7 +6221,7 @@
   my $stage = shift;
   die if (!$possible_stages{$stage});
 
-  return if 
(!defined($Texinfo::Config::texinfo_default_stage_handlers{$stage}));
+  return 1 if 
(!defined($Texinfo::Config::texinfo_default_stage_handlers{$stage}));
 
   my @sorted_priorities = sort 
keys(%{$Texinfo::Config::texinfo_default_stage_handlers{$stage}});
   foreach my $priority (@sorted_priorities) {
@@ -6210,9 +6229,16 @@
       if ($converter->get_conf('DEBUG')) {
         print STDERR "HANDLER($stage) , priority $priority: $handler\n";
       }
-      &{$handler}($converter, $stage);
+      my $status = &{$handler}($converter, $stage);
+      if (!$status) {
+        if ($converter->get_conf('VERBOSE')) {
+          print STDERR "Handler $handler of $stage($priority) failed\n";
+        }
+        return $status;
     }
   }
+  }
+  return 1;
 }
 
 my $default_priority = 'default';
@@ -6292,7 +6318,8 @@
   }
   $self->set_conf('EXTERNAL_CROSSREF_SPLIT', $self->get_conf('SPLIT'));
 
-  $self->run_stage_handlers('setup');
+  my $setup_status = $self->run_stage_handlers('setup');
+  return undef unless($setup_status);
 
   $self->_prepare_css();
 
@@ -6346,7 +6373,8 @@
   $self->_prepare_index_entries();
   $self->_prepare_footnotes();
 
-  $self->run_stage_handlers('structure');
+  my $structure_status = $self->run_stage_handlers('structure');
+  return undef unless($structure_status);
 
   &{$self->{'format_css_lines'}}($self);
 
@@ -6432,10 +6460,12 @@
     pop @{$self->{'document_context'}};
   }
 
-  $self->run_stage_handlers('init');
+  my $init_status = $self->run_stage_handlers('init');
+  return undef unless($init_status);
 
   if ($self->get_conf('FRAMES')) {
-    &{$self->{'format_frame_files'}}($self);
+    my $status = &{$self->{'format_frame_files'}}($self);
+    return undef if (!$status);
   }
 
   # Now do the output
@@ -6443,8 +6473,8 @@
   my $output = '';
   if (!$elements or !defined($elements->[0]->{'filename'})) {
     # no page
-    if ($self->{'output_file'} ne '') {
       my $outfile;
+    if ($self->{'output_file'} ne '') {
       if ($self->get_conf('SPLIT')) {
         $outfile = $self->_top_node_filename();
         if (defined($self->{'destination_directory'})) {
@@ -6455,7 +6485,7 @@
       }
       print STDERR "DO No pages, output in $outfile\n"
         if ($self->get_conf('DEBUG'));
-      $fh = $self->Texinfo::Common::open_out ($outfile);
+      $fh = $self->Texinfo::Common::open_out($outfile);
       if (!$fh) {
         $self->document_error(sprintf($self->__("Could not open %s for 
writing: %s"),
                                       $outfile, $!));
@@ -6478,6 +6508,10 @@
       $output .= $self->_output_text($self->_convert($root), $fh);
     }
     $output .= $self->_output_text(&{$self->{'format_end_file'}}($self), $fh);
+    if ($fh and !close($fh)) {
+      $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                    $outfile, $!));
+    }
     return $output if ($self->{'output_file'} eq '');
   } else {
     # output with pages
@@ -6504,7 +6538,7 @@
       }
       # Then open the file and output the elements or the special_page_content
       if (!$files{$element->{'filename'}}->{'fh'}) {
-        $file_fh = $self->Texinfo::Common::open_out 
($element->{'out_filename'});
+        $file_fh = 
$self->Texinfo::Common::open_out($element->{'out_filename'});
         if (!$file_fh) {
           $self->document_error(sprintf($self->__("Could not open %s for 
writing: %s"),
                                     $element->{'out_filename'}, $!));
@@ -6528,11 +6562,17 @@
       if ($self->{'file_counters'}->{$element->{'filename'}} == 0) {
         # end file
         print $file_fh "". &{$self->{'format_end_file'}}($self);
+        if (!close($file_fh)) {
+          $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                $element->{'out_filename'}, $!));
+          # FIXME(Karl) return at that point?
+        }
       }
     }
   }
 
-  $self->run_stage_handlers('finish');
+  my $finish_status = $self->run_stage_handlers('finish');
+  return undef unless($finish_status);
 
   # do node redirection pages
   $self->{'current_filename'} = undef;
@@ -6570,13 +6610,17 @@
         } else {
           $out_filename = $node_filename;
         }
-        my $file_fh = $self->Texinfo::Common::open_out ($out_filename);
+        my $file_fh = $self->Texinfo::Common::open_out($out_filename);
         if (!$file_fh) {
          $self->document_error(sprintf($self->__("Could not open %s for 
writing: %s"),
                                     $out_filename, $!));
         } else {
           print $file_fh $redirection_page;
-          close ($file_fh);
+          if (!close ($file_fh)) {
+            $self->document_error(sprintf($self->__("Error on closing 
redirection node file %s: %s"),
+                                    $out_filename, $!));
+            # FIXME(Karl) return at that point?
+          }
         }
       }
     }
@@ -6632,13 +6676,17 @@
         } else {
           $out_filename = $filename;
         }
-        my $file_fh = $self->Texinfo::Common::open_out ($out_filename);
+        my $file_fh = $self->Texinfo::Common::open_out($out_filename);
         if (!$file_fh) {
          $self->document_error(sprintf($self->__("Could not open %s for 
writing: %s"),
                                     $out_filename, $!));
         } else {
           print $file_fh $redirection_page;
-          close ($file_fh);
+          if (!close ($file_fh)) {
+            $self->document_error(sprintf($self->__("Error on closing renamed 
node file %s: %s"),
+                                    $out_filename, $!));
+            # FIXME(Karl) return at that point?
+          }
         }
       }
     }

Index: Texinfo/Convert/Info.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Info.pm,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -b -r1.74 -r1.75
--- Texinfo/Convert/Info.pm     11 Nov 2011 13:55:04 -0000      1.74
+++ Texinfo/Convert/Info.pm     13 Nov 2011 23:04:30 -0000      1.75
@@ -83,6 +83,7 @@
                                     $self->{'output_file'}, $!));
       return undef;
     }
+    push @{$self->{'opened_files'}}, $self->{'output_file'};
   }
   print STDERR "DOCUMENT\n" if ($self->get_conf('DEBUG'));
   my $out_file_nr = 0;
@@ -123,18 +124,40 @@
           and $self->{'count_context'}->[-1]->{'bytes'} > 
                   $out_file_nr * $self->get_conf('SPLIT_SIZE') 
           and @nodes and $fh) {
-        close ($fh);
+        my $close_error;
+        if (!close ($fh)) {
+          $close_error = $!;
+        }
         if ($out_file_nr == 1) {
+          if (defined($close_error)) {
+            $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                  $self->{'output_file'}, $close_error));
+            return undef;
+          }
           unless (rename ($self->{'output_file'}, 
                           $self->{'output_file'}.'-'.$out_file_nr)) {
             $self->document_error(sprintf($self->__("Rename %s failed: %s"), 
                                          $self->{'output_file'}, $!));
+            return undef;
+          }
+          # remove the main file from opened files since it was renamed
+          my $outfile = pop @{$self->{'opened_files'}};
+          if ($outfile ne $self->{'output_file'}) {
+            die "BUG: on top of opened_files $outfile and not 
$self->{'output_file'}\n";
           }
           push @{$self->{'opened_files'}}, 
                    $self->{'output_file'}.'-'.$out_file_nr;
           push @indirect_files, [$self->{'output_filename'}.'-'.$out_file_nr,
                                  $first_node_bytes_count];
           #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
+        } else {
+          if (defined($close_error)) {
+            $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                  $self->{'output_file'}.'-'.$out_file_nr, 
+                                  $close_error));
+            # FIXME return undef, interrupting processing?
+            # return undef;
+          }
         }
         $out_file_nr++;
         $fh = $self->Texinfo::Common::open_out (
@@ -145,6 +168,8 @@
                   $self->{'output_file'}.'-'.$out_file_nr, $!));
            return undef;
         }
+        push @{$self->{'opened_files'}}, 
+                $self->{'output_file'}.'-'.$out_file_nr;
         print $fh $header;
         $self->{'count_context'}->[-1]->{'bytes'} += $header_bytes;
         push @indirect_files, [$self->{'output_filename'}.'-'.$out_file_nr,
@@ -155,7 +180,12 @@
   }
   my $tag_text = '';
   if ($out_file_nr > 1) {
-    close ($fh);
+    if (!close ($fh)) {
+      $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                            $self->{'output_file'}.'-'.$out_file_nr, $!));
+      # FIXME return undef, interrupting processing?
+      # return undef;
+    }
     $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
     if (!$fh) {
       $self->document_error(sprintf(
@@ -163,6 +193,7 @@
             $self->{'output_file'}, $!));
       return undef;
     }
+    push @{$self->{'opened_files'}}, $self->{'output_file'};
     $tag_text = $header;
     $tag_text .= "\x{1F}\nIndirect:";
     foreach my $indirect (@indirect_files) {
@@ -208,10 +239,15 @@
   }
   if ($fh) {
     print $fh $tag_text;
-    # NOTE it should be possible to close STDOUT.  However this leads to
+    # FIXME it should be possible to close STDOUT.  However this leads to
     # 'Filehandle STDOUT reopened as FH only for input' if there are files
     # reopened after closing STDOUT.
-    close ($fh) unless ($self->{'output_file'} eq '-');
+    unless ($self->{'output_file'} eq '-') {
+      if (!close ($fh)) {
+        $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                              $self->{'output_file'}, $!));
+      }
+    }
   } else {
     $result .= $tag_text;
   }

Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -b -r1.189 -r1.190
--- Texinfo/Convert/Plaintext.pm        7 Nov 2011 22:59:50 -0000       1.189
+++ Texinfo/Convert/Plaintext.pm        13 Nov 2011 23:04:30 -0000      1.190
@@ -969,7 +969,10 @@
       }
       # remove last end of line
       chomp ($result);
-      close ($filehandle);
+      if (!close ($filehandle)) {
+        $self->document_warn(sprintf($self->__("Error on closing image text 
file %s: %s"),
+                                     $txt_file, $!));
+      }
       return $result;
     } else {
       $self->line_warn(sprintf($self->__("address@hidden file `%s' unreadable: 
%s"), 

Index: Texinfo/Convert/Text.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Text.pm,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -b -r1.81 -r1.82
--- Texinfo/Convert/Text.pm     8 Nov 2011 00:05:50 -0000       1.81
+++ Texinfo/Convert/Text.pm     13 Nov 2011 23:04:30 -0000      1.82
@@ -629,6 +629,7 @@
   my $result = _convert($tree, \%options);
   if ($fh) {
     print $fh $result;
+    return undef if (!close($fh));
     $result = '';
   }
   return $result;

Index: Texinfo/Convert/XML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/XML.pm,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- Texinfo/Convert/XML.pm      6 Nov 2011 00:55:28 -0000       1.53
+++ Texinfo/Convert/XML.pm      13 Nov 2011 23:04:30 -0000      1.54
@@ -279,6 +279,10 @@
   $result .= $self->_output_text($header, $fh);
   $result .= $self->convert_document_sections($root, $fh);
   $result .= $self->_output_text("</texinfo>\n", $fh);
+  if ($fh and !close ($fh)) {
+    $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                  $self->{'output_filename'}, $!));
+  }
 
   return $result;
 }

Index: init/book.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/init/book.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- init/book.pm        31 Oct 2011 18:04:30 -0000      1.6
+++ init/book.pm        13 Nov 2011 23:04:30 -0000      1.7
@@ -47,6 +47,7 @@
   $book_previous_default_filename = undef;
   $book_previous_file_name = undef;
   $book_unumbered_nr = 0;
+  return 1;
 }
 
 texinfo_register_handler('init', \&book_init);

Index: init/chm.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/init/chm.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- init/chm.pm 2 Nov 2011 00:40:33 -0000       1.8
+++ init/chm.pm 13 Nov 2011 23:04:30 -0000      1.9
@@ -208,14 +208,15 @@
   return if (defined($self->get_conf('OUTFILE'))
         and $Texinfo::Common::null_device_file{$self->get_conf('OUTFILE')});
   my $document_name = $self->{'document_name'};
+
   my $hhk_filename = $document_name . ".hhk";
   my $hhk_file = $self->{'destination_directory'} . $hhk_filename;
-
   my $hhk_fh = Texinfo::Common::open_out($self, $hhk_file);
   # Not sure $! is still valid
   if (!defined($hhk_fh)) {
-    die sprintf($self->__("Can't open %s for writing: %s\n"), 
-                  $hhk_file, $!);
+    $self->document_error(sprintf($self->__("Can't open %s for writing: 
%s\n"), 
+                  $hhk_file, $!));
+    return 0;
   }
   print STDERR "# writing HTML Help index in $hhk_file...\n" 
      if ($self->get_conf('VERBOSE'));
@@ -229,71 +230,6 @@
   }
   print $hhk_fh "</OBJECT>\n";
 
-  my $hhp_filename = $document_name . ".hhp";
-  my $hhp_file = $self->{'destination_directory'} . $hhp_filename;
-  my $hhp_fh = Texinfo::Common::open_out($self, $hhp_file);
-  # Not sure $! is still valid
-  if (!defined($hhp_fh)) {
-    die sprintf($self->__("Can't open %s for writing: %s\n"), 
-                  $hhp_file, $!);
-  }
-  print STDERR "# writing HTML Help project in $hhp_file...\n" 
-     if ($self->get_conf('VERBOSE'));
-  my $language = $chm_languages{'en'};
-  my $documentlanguage = $self->get_conf('documentlanguage');
-  $documentlanguage =~ s/_.*//;
-  if (exists ($chm_languages{$documentlanguage})) {
-    $language = $chm_languages{$documentlanguage};
-  }
-  my $title = convert_tree($self, $self->{'title_tree'});
-  my $top_file = '';
-  my $top_element = $self->global_element('Top');
-  if ($top_element and $top_element->{'extra'}->{'element_command'}) {
-    $top_file 
-     = $self->command_filename($top_element->{'extra'}->{'element_command'});
-  }
-
-  print $hhp_fh <<EOT;
-[OPTIONS]
-Compatibility=1.1 or later
-Compiled file=$document_name.chm
-Contents file=$document_name.hhc
-Default Window=Default
-Default topic=$top_file
-Display compile progress=No
-Full-text search=Yes
-Index file=$hhk_filename
-Language=$language
-Title=$title
-
-[WINDOWS]
-Default=,"$document_name.hhc","$hhk_filename","$top_file","$top_file",,,,,0x22520,,0x384e,,,,,,,,0
-
-[FILES]
-EOT
-
-  my %chm_files;
-  if ($self->{'elements'}) {
-    foreach my $element (@{$self->{'elements'}}) {
-      if (!$chm_files{$element->{'filename'}}) {
-        print $hhp_fh "$element->{'filename'}\n";
-        $chm_files{$element->{'filename'}} = 1;
-      }
-    }
-  }
-  close ($hhp_fh);
-
-  my $hhc_filename = $document_name . ".hhc";
-  my $hhc_file = $self->{'destination_directory'} . $hhc_filename;
-  my $hhc_fh = Texinfo::Common::open_out($self, $hhc_file);
-  # Not sure $! is still valid
-  if (!defined($hhc_fh)) {
-    die sprintf($self->__("Can't open %s for writing: %s\n"), 
-                  $hhc_file, $!);
-  }
-  print STDERR "# writing HTML Help project in $hhc_file...\n" 
-     if ($self->get_conf('VERBOSE'));
-  
   my $index_entries = Texinfo::Structuring::sort_indices($self, 
                                           $self->{'index_entries'},
                                           $self->{'index_names'});
@@ -322,7 +258,24 @@
     }
   }
   print $hhk_fh "</BODY>\n</HTML>\n";
-  close ($hhk_fh);
+  if (!close ($hhk_fh)) {
+    $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                          $hhk_file, $!));
+    return 0;                  
+  }
+
+  my $hhc_filename = $document_name . ".hhc";
+  my $hhc_file = $self->{'destination_directory'} . $hhc_filename;
+  my $hhc_fh = Texinfo::Common::open_out($self, $hhc_file);
+  # Not sure $! is still valid
+  if (!defined($hhc_fh)) {
+    $self->document_error(sprintf($self->__("Can't open %s for writing: 
%s\n"), 
+                  $hhc_file, $!));
+    return 0;
+  }
+
+  print STDERR "# writing HTML Help project in $hhc_file...\n" 
+     if ($self->get_conf('VERBOSE'));
 
   print $hhc_fh "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n<HTML>\n";
   print $hhc_fh "<HEAD>\n<meta name=\"GENERATOR\" content=\""
@@ -375,6 +328,73 @@
     }
   }
   print $hhc_fh "</HTML>\n</BODY>\n";
+  if (!close ($hhc_fh)) {
+    $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                          $hhc_file, $!));
+    return 0;                  
+  }
+
+  my $hhp_filename = $document_name . ".hhp";
+  my $hhp_file = $self->{'destination_directory'} . $hhp_filename;
+  my $hhp_fh = Texinfo::Common::open_out($self, $hhp_file);
+  # Not sure $! is still valid
+  if (!defined($hhp_fh)) {
+    $self->document_error(sprintf($self->__("Can't open %s for writing: 
%s\n"), 
+                  $hhp_file, $!));
+    return 0;
+  }
+  print STDERR "# writing HTML Help project in $hhp_file...\n" 
+     if ($self->get_conf('VERBOSE'));
+  my $language = $chm_languages{'en'};
+  my $documentlanguage = $self->get_conf('documentlanguage');
+  $documentlanguage =~ s/_.*//;
+  if (exists ($chm_languages{$documentlanguage})) {
+    $language = $chm_languages{$documentlanguage};
+  }
+  my $title = convert_tree($self, $self->{'title_tree'});
+  my $top_file = '';
+  my $top_element = $self->global_element('Top');
+  if ($top_element and $top_element->{'extra'}->{'element_command'}) {
+    $top_file 
+     = $self->command_filename($top_element->{'extra'}->{'element_command'});
+  }
+
+  print $hhp_fh <<EOT;
+[OPTIONS]
+Compatibility=1.1 or later
+Compiled file=$document_name.chm
+Contents file=$hhc_filename
+Default Window=Default
+Default topic=$top_file
+Display compile progress=No
+Full-text search=Yes
+Index file=$hhk_filename
+Language=$language
+Title=$title
+
+[WINDOWS]
+Default=,"$hhc_filename","$hhk_filename","$top_file","$top_file",,,,,0x22520,,0x384e,,,,,,,,0
+
+[FILES]
+EOT
+
+  my %chm_files;
+  if ($self->{'elements'}) {
+    foreach my $element (@{$self->{'elements'}}) {
+      if (!$chm_files{$element->{'filename'}}) {
+        print $hhp_fh "$element->{'filename'}\n";
+        $chm_files{$element->{'filename'}} = 1;
+      }
+    }
+  }
+
+  if (!close ($hhp_fh)) {
+    $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                          $hhp_file, $!));
+    return 0;                  
+  }
+
+  return 1;
 }
 texinfo_register_handler('init', \&chm_init);
 

Index: init/latex2html.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/init/latex2html.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- init/latex2html.pm  6 Nov 2011 17:48:54 -0000       1.1
+++ init/latex2html.pm  13 Nov 2011 23:04:30 -0000      1.2
@@ -227,6 +227,9 @@
   if ($status) {
     $status = l2h_init_from_html($self);
   }
+  # FIXME use $status?  That is abort when something goes wrong on the
+  # latex2html front?
+  return 1;
 }
 
 
@@ -539,7 +542,8 @@
 sub l2h_finish($)
 {
   my $self = shift;
-  return unless($status);
+  return 1 unless($status);
+
   if ($verbose) {
     if ($extract_error_count + $invalid_counter_count) {
       warn "# l2h: finished from html ($extract_error_count extract and 
$invalid_counter_count invalid counter errors)\n";

Index: init/tex4ht.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/init/tex4ht.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- init/tex4ht.pm      6 Nov 2011 00:55:28 -0000       1.7
+++ init/tex4ht.pm      13 Nov 2011 23:04:30 -0000      1.8
@@ -82,11 +82,12 @@
 my $tex4ht_initial_dir;
 my $tex4ht_out_dir;
 
-sub tex4ht_prepare($) {
+sub tex4ht_prepare($)
+{
   # set file names
   my $self = shift;
 
-  return if (defined($self->get_conf('OUTFILE'))
+  return 1 if (defined($self->get_conf('OUTFILE'))
         and $Texinfo::Common::null_device_file{$self->get_conf('OUTFILE')});
 
   $tex4ht_initial_dir = Cwd::abs_path;
@@ -119,7 +120,7 @@
       unless (open (*TEX4HT_TEXFILE, ">$rfile")) {
         $self->document_warn (sprintf($self->__("tex4ht error opening %s: 
%s"), 
                                       $rfile, $!));
-        return;
+        return 1;
       }
       $commands{$command}->{'handle'} = *TEX4HT_TEXFILE;
 
@@ -202,6 +203,7 @@
          "address@hidden \"$commands{$command}->{'basename'}.css\";\n";
     }
   }
+  return 1;
 }
 
 sub tex4ht_convert($)
@@ -210,7 +212,7 @@
   unless (chdir $tex4ht_out_dir) {
     $self->document_warn(sprintf($self->__("chdir to %s failed"),
                          $tex4ht_out_dir));
-    return;
+    return 1;
   }
   print STDERR "cwd($tex4ht_out_dir): " . Cwd::cwd() ."\n" 
     if ($self->get_conf('VERBOSE'));
@@ -220,8 +222,10 @@
     $errors += tex4ht_process_command($self, $command);
   }
   unless (chdir $tex4ht_initial_dir) {
-    die "tex4ht unable to return to the initial dir\n";
+    warn "tex4ht unable to return to the initial dir\n";
+    return 0;
   }
+  return 1;
 }
 
 sub tex4ht_process_command($$) {
@@ -317,6 +321,7 @@
       }
     }
   }
+  return 1;
 }
 
 1;  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]