texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp texi2any.pl


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl
Date: Tue, 11 Jan 2011 00:49:17 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/01/11 00:49:17

Modified files:
        tp             : texi2any.pl 

Log message:
        Do the actual conversion with a hash setting the defaults for the output
        format.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- texi2any.pl 10 Jan 2011 01:08:57 -0000      1.1
+++ texi2any.pl 11 Jan 2011 00:49:16 -0000      1.2
@@ -124,6 +124,8 @@
 
 # This is done at runtime because the modules are also found at runtime.
 require Texinfo::Parser;
+require Texinfo::Structuring;
+require Texinfo::Convert::Info;
 
 # determine configuration directories.
 
@@ -159,6 +161,8 @@
 my $option_force = 0;
 my $option_error_limit = 100;
 my $option_no_warn = 0;
+my $format = 'info';
+my $converter_default_options = {};
 
 
 my $result_options = Getopt::Long::GetOptions (
@@ -167,6 +171,13 @@
  'no-warn' => \$option_no_warn,
 );
 
+my %formats_table = (
+ 'info' => { 'nodes_tree' => 1,
+             'floats' => 1,
+             'converter' => sub{Texinfo::Convert::Info->converter(@_)},
+           },
+);
+
 # Main processing, process all the files given on the command line
 
 my $failure_text =  sprintf(__("Try `%s --help' for more information.\n"), 
@@ -177,6 +188,21 @@
 die sprintf(__("%s: missing file argument.\n"), $real_command_name) 
    .$failure_text unless (scalar(@input_files) >= 1);
 
+sub handle_errors($$) {
+  my $self = shift;
+  my $error_count = shift;
+  my ($errors, $new_error_count) = $self->errors();
+  $error_count += $new_error_count if ($new_error_count);
+  foreach my $error_message (@$errors) {
+    warn $error_message->{'error_line'} if ($error_message->{'type'} eq 'error'
+                                           or !$option_no_warn);
+  }
+  
+  exit (1) if ($error_count and (!$option_force
+     or $error_count > $option_error_limit));
+  return $error_count;
+}
+
 my $file_number = 0;
 # main processing
 while(@input_files)
@@ -200,15 +226,12 @@
 
   my $parser = Texinfo::Parser::parser({'gettext' => \&__});
   my $tree = $parser->parse_texi_file($input_file_name);
-  my ($errors, $error_count) = $parser->errors();
-  foreach my $error_message (@$errors) {
-    warn $error_message->{'error_line'} if ($error_message->{'type'} eq 'error'
-                                           or !$option_no_warn);
-  }
-  exit (1) if ($error_count and (!$option_force
-     or $error_count > $option_error_limit));
 
-  next if (!defined($tree));
+  my $error_count = 0;
+  if (!defined($tree)) {
+    handle_errors($parser, $error_count);
+    next;
+  }
   if (defined($macro_expand)) {
     my $texinfo_text = Texinfo::Convert::Texinfo::convert ($tree);
     #print STDERR "$texinfo_text\n";
@@ -226,4 +249,24 @@
     }
   }
   $file_number++;
+  # every format needs the sectioning structure
+  my $structure = Texinfo::Structuring::sectioning_structure($parser, $tree);
+  # this can be done for every format, since information is already gathered
+  my $floats = $parser->floats_information();
+
+  my $top_node;
+  if ($formats_table{$format}->{'nodes_tree'}) {
+    $top_node = Texinfo::Structuring::nodes_tree($parser);
+  }
+  if ($formats_table{$format}->{'floats'}) {
+    Texinfo::Structuring::number_floats($floats);
+  }
+  $error_count = handle_errors($parser, $error_count);
+
+  my $converter_options = { %$converter_default_options };
+  $converter_options->{'parser'} = $parser;
+  my $converter = 
&{$formats_table{$format}->{'converter'}}($converter_options);
+  $converter->convert($tree);
+  handle_errors($converter, $error_count);
 }
+



reply via email to

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