texi2html-cvs
[Top][All Lists]
Advanced

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

[Texi2html-cvs] Changes to texi2html/texi2html.pl


From: Patrice Dumas
Subject: [Texi2html-cvs] Changes to texi2html/texi2html.pl
Date: Sun, 28 Aug 2005 04:40:09 -0400

Index: texi2html/texi2html.pl
diff -u texi2html/texi2html.pl:1.149 texi2html/texi2html.pl:1.150
--- texi2html/texi2html.pl:1.149        Wed Aug 24 14:33:20 2005
+++ texi2html/texi2html.pl      Sun Aug 28 08:39:55 2005
@@ -62,7 +62,7 @@
 
#--##############################################################################
 
 # CVS version:
-# $Id: texi2html.pl,v 1.149 2005/08/24 14:33:20 pertusus Exp $
+# $Id: texi2html.pl,v 1.150 2005/08/28 08:39:55 pertusus Exp $
 
 # Homepage:
 my $T2H_HOMEPAGE = "http://www.nongnu.org/texi2html/";;
@@ -440,6 +440,10 @@
 %accent_letters
 %unicode_accents
 %special_accents
address@hidden
address@hidden
address@hidden
+%command_handler
 );
 
 $I = \&Texi2HTML::I18n::get_string;
@@ -1157,31 +1161,11 @@
 my @raw_regions = ('html', 'verbatim', 'tex', 'xml', 'docbook');
 
 # special raw formats which are expanded between second and third pass
-# and are replaced by specific commands. Currently used for tex. It takes
-# precedence over raw_regions.
-# Currently there is no integrated handling of such regions. The collecting
-# of special sections is generic, they are collected by init_special during 
-# the second phase, so calling a user function reference should be trivial.
-# then init_special would remember which @-command is associated with 
-# which user defined function and add a mangled @-command like 
-# @t2h_special_command_nr 
-# remark: this is not problematic, the only gotcha is that it shouldn't
-# intersect with user undefined @-commands (nor with texinfo commands!).
-# However the replacement is done by matching @tex_(\d+). Maybe a generic
-# interface would be to have the @-commands names set by init_special 
-# in a hash and expand them by calling the correponding function.
+# and are replaced by specific commands. It takes precedence over 
+# raw_regions.
+#FIXME it is not modifiable by the user!
 my @special_regions = ();
 
-# the handling of @math is ad-hoc, it should be more generic. More
-# precisely this is a special command. The special commands should be
-# collect by init_special and handled like special regions.  
-
-# there should be more hooks for user defined functions, at least
-# one after the first pass with all the possible information (file
-# names), between the pass 2 and 3, that mark that all the special 
-# regions have been collected, and one after the pass 3 for cleaning.
-# This is currently what is done with Latex2HTML.
-
 # regions expanded or not depending on the value of this hash
 my %text_macros = (
      'iftex' => 0, 
@@ -2310,6 +2294,10 @@
 $T2H_DEBUG = $Texi2HTML::Config::DEBUG;
 $T2H_VERBOSE = $Texi2HTML::Config::VERBOSE;
 
+$Texi2HTML::LaTeX2HTML::debug = 0;
+$Texi2HTML::LaTeX2HTML::debug = 1 if ($T2H_DEBUG & $DEBUG_L2H);
+
+
 
#+++############################################################################
 #                                                                              
#
 # evaluation of cmd line options
@@ -2672,6 +2660,10 @@
 $Texi2HTML::THISDOC{'filename'}->{'about'} = $docu_about;
 $Texi2HTML::THISDOC{'filename'}->{'top'} = $docu_top;
 $Texi2HTML::THISDOC{'filename'}->{'toc'} = $docu_toc;
+# FIXME document that
+$Texi2HTML::THISDOC{'out_dir'} = $docu_rdir;
+$Texi2HTML::THISDOC{'file_base_name'} = $docu_name;
+
 
 my $docu_doc_file = "$docu_rdir$docu_doc"; 
 my $docu_toc_file  = "$docu_rdir$docu_toc";
@@ -2985,15 +2977,17 @@
 # holds the status of latex2html operations. If 0 it means that there was 
 # an error
 my $status = 0;
+
 my $debug;
 my $docu_rdir;
+my $docu_name;
 
 #if ($Texi2HTML::Config::L2H)
-sub init($$$)
+sub init
 {
-    my $docu_name = shift;
-    $docu_rdir = shift;
-    $debug = shift;
+#    $debug = shift;
+    $docu_name = $Texi2HTML::THISDOC{'file_base_name'};
+    $docu_rdir = $Texi2HTML::THISDOC{'out_dir'};
     $l2h_name =  "${docu_name}_l2h";
     $l2h_latex_file = "$docu_rdir${l2h_name}.tex";
     $l2h_cache_file = "${docu_rdir}l2h_cache.pm";
@@ -3030,6 +3024,8 @@
 my $l2h_to_latex_count = 0;  # total number of latex texts processed
 my $l2h_cached_count = 0;    # number of cached latex text
 my %l2h_cache = ();          
+
+my %global_count = ();
 #$Texi2HTML::Config::L2H = l2h_InitToLatex() if ($Texi2HTML::Config::L2H);
 
 # return used latex 1, if l2h could be initalized properly, 0 otherwise
@@ -3059,8 +3055,17 @@
 #sub l2h_ToLatex
 sub to_latex
 {
-    my($text) = @_;
-    my($count);
+    my $command = shift;
+    my $text = shift;
+    my $counter = shift;
+    if ($command eq 'tex')
+    {
+        $text .= ' ';
+    }
+    elsif ($command eq 'math') 
+    {
+        $text = "\$".$text."\$";
+    }
     $l2h_to_latex_count++;
     $text =~ s/(\s*)$//;
     # try whether we can cache it
@@ -3072,7 +3077,8 @@
         return $cached_text;
     }
     # try whether we have text already on things to do
-    unless ($count = $l2h_to_latex{$text})
+    my $count = $l2h_to_latex{$text};
+    unless ($count)
     {
         $count = $l2h_latex_count;
         $l2h_latex_count++;
@@ -3091,7 +3097,9 @@
             print L2H_LATEX "\\end{rawhtml}\n";
         }
     }
-    return "address@hidden ";
+    $global_count{"${command}_$counter"} = $count; 
+    #return "address@hidden ";
+    return 1;
 }
 
 # print closing into latex file and close it
@@ -3282,9 +3290,11 @@
     return $to_do.$done;
 }
 
-sub do_tex($)
+sub do_tex($$$$)
 {
-    my $count = shift;
+    my $style = shift;
+    my $counter = shift;
+    my $count = $global_count{"${style}_$counter"}; 
     my $result = '';
     $result = "<!-- l2h_begin $l2h_name $count -->"
             #if ($T2H_DEBUG & $DEBUG_L2H);
@@ -3646,7 +3656,7 @@
         $text .= $1;
     }
     $line = '' if (!defined($line));
-    return ($line, "address@hidden" . $text, $args);
+    return ($line, $text, $args);
 }
 
 #+++###########################################################################
@@ -3672,7 +3682,7 @@
                                     # to be used
     $state->{'menu'} = 0;           # number of opened menus
     $state->{'detailmenu'} = 0;     # number of opened detailed menus      
-    $state->{'level'} = 0;          # current sectionning level
+    $state->{'sectionning_base'} = 0;         # current base sectionning level
     $state->{'table_stack'} = [ "no table" ]; # a stack of opened tables/lists
     delete ($state->{'region_lines'}) unless 
(defined($state->{'region_lines'}));
 }
@@ -3699,6 +3709,8 @@
 my $element_chapter_index;  # chapter with first index
 my $element_first;          # first element
 my $element_last;           # last element
+my %special_commands;       # hash for the commands specially handled 
+                            # by the user 
 
 # This is a virtual element used to have the right hrefs for index entries
 # and anchors in footnotes
@@ -3751,7 +3763,7 @@
             #
             if ($tag and $tag eq 'node' or defined($sec2level{$tag}) or $tag 
eq 'printindex' or $tag eq 'float')
             {
-                $_ = substitute_texi_line($_); #usefull if there is an anchor 
???
+                $_ = substitute_texi_line($_); 
                 if (@stack and $tag eq 'node' or defined($sec2level{$tag}) or
 $tag eq 'float')
                 {# in pass structure node and float shouldn't appear in formats
@@ -4072,7 +4084,7 @@
         {
             $sec2level{$sec} = $level + 1;
         }
-        $state->{'level'}--;
+        $state->{'sectionning_base'}--;
     }
     elsif ($macro eq 'raisesections')
     {
@@ -4081,7 +4093,7 @@
         {
             $sec2level{$sec} = $level - 1;
         }
-        $state->{'level'}++;
+        $state->{'sectionning_base'}++;
     }
     elsif ($macro eq 'contents')
     {
@@ -4098,6 +4110,7 @@
     elsif ($macro eq 'novalidate')
     {
         $novalidate = 1;
+        $Texi2HTML::THISDOC{$macro} = 1; 
     }
     elsif (grep {$_ eq $macro} 
('settitle','setfilename','shortitle','shorttitlepage') 
              and ($line =~ /^\s+(.*)$/))
@@ -4132,6 +4145,7 @@
                 {
                     $index_properties->{$prefix_to}->{'from'}->{$prefix_from} 
= 1;
                 }
+                push @{$Texi2HTML::THISDOC{$macro}}, 
[$prefix_from,$prefix_to]; 
             }
         }
         else
@@ -4146,6 +4160,7 @@
             my $name = $1;
             $index_properties->{$name}->{'name'} = $name;
             $index_properties->{$name}->{'code'} = 1 if $macro eq 
'defcodeindex';
+            push @{$Texi2HTML::THISDOC{$macro}}, $name; 
         }
         else
         {# FIXME makeinfo don't warn and even accepts index with empty name
@@ -4158,6 +4173,9 @@
         {
             my $lang = $1;
             set_document_language($lang, 0, $line_nr) if (!$cmd_line_lang && 
$lang);
+            # warning, this is not the language of te document but the one that
+            # appear in the texinfo...
+            $Texi2HTML::THISDOC{$macro} = $lang; 
         }
     }
     elsif ($macro eq 'kbdinputstyle')
@@ -4302,6 +4320,8 @@
     my $text = shift;
     my $line_nr = shift;
     my ($skipped, $remaining, $args);
+    # if it is true the command args are kept so the user can modify how
+    # they are skipped and handle them as unknown @-commands
     my $keep = $Texi2HTML::Config::misc_command{$macro}->{'keep'};
 
     if ($macro eq 'detailmenu')
@@ -4361,17 +4381,14 @@
     }
     elsif ($macro eq 'need')
     {
-        unless (($line =~ /\s+([0-9]+(\.[0-9]*)?)[^\w\-]/) or 
-                 ($line =~ /\s+(\.[0-9]+)[^\w\-]/))
+        unless (($line =~ /^\s+([0-9]+(\.[0-9]*)?)[^\w\-]/) or 
+                 ($line =~ /^\s+(\.[0-9]+)[^\w\-]/))
         {
             echo_warn ("Bad address@hidden", $line_nr);
         }
     }
     ($remaining, $skipped, $args) = preserve_command($line, $macro);
-    if ($keep)
-    {
-        $remaining = $args . $remaining;
-    }
+    return ($skipped) if ($keep);
     return $remaining if ($remaining ne '');
     return undef;
 }
@@ -6195,7 +6212,6 @@
     $Texi2HTML::THISDOC{'copying'} = $copying_comment;
     $Texi2HTML::THISDOC{'toc_file'} = ''; 
     $Texi2HTML::THISDOC{'toc_file'} = $docu_toc if 
($Texi2HTML::Config::SPLIT); 
-    $Texi2HTML::THISDOC{'file_base_name'} = $docu_name;
     $Texi2HTML::THISDOC{'destination_directory'} = $docu_rdir;
     $Texi2HTML::THISDOC{'authors'} = [] if 
(!defined($Texi2HTML::THISDOC{'authors'}));
     $Texi2HTML::THISDOC{'subtitles'} = [] if 
(!defined($Texi2HTML::THISDOC{'subtitles'}));
@@ -7134,8 +7150,8 @@
 
 sub do_math($;$)
 {
-    #return l2h_ToLatex("\$".$_[0]."\$");
-    return Texi2HTML::LaTeX2HTML::to_latex("\$".$_[0]."\$");
+    #return Texi2HTML::LaTeX2HTML::to_latex("\$".$_[0]."\$");
+    return Texi2HTML::LaTeX2HTML::to_latex('math',$_[0]);
 }
 
 sub do_anchor_label($$$$)
@@ -7393,17 +7409,30 @@
     return ($line, $text);
 }
 
-# do regions handled specially, currently only tex, going throug latex2html
+# do regions handled specially, currently only tex, going through latex2html
 sub init_special($$)
 {
     my $style = shift;
     my $text = shift;
-    if ($style eq 'tex')
+    if (defined($Texi2HTML::Config::command_handler{$style}) and
+       defined($Texi2HTML::Config::command_handler{$style}->{'init'}))
     {
+        $special_commands{$style}->{'count'} = 0 if 
(!defined($special_commands{$style}));
+        if ($Texi2HTML::Config::command_handler{$style}->{'init'}($style,$text,
+               $special_commands{$style}->{'count'} +1))
+        {
+            $special_commands{$style}->{'count'}++;  
+            return "address@hidden".$special_commands{$style}->{'count'}."{}";
+        }
+        return '';
+    }
+#    if ($style eq 'tex')
+#    {
         # add space to the end -- tex(i2dvi) does this, as well
         #return (l2h_ToLatex($text . " "));
-        return (Texi2HTML::LaTeX2HTML::to_latex($text . " "));
-    }
+#        return (Texi2HTML::LaTeX2HTML::to_latex($style,$text));
+#    }
+    
 }
 
 sub do_insertcopying($)
@@ -8937,7 +8966,7 @@
             {# ARG_EXPANSION
                  my ($line, $args);
                  ($_, $line, $args) = preserve_command($_, $macro);
-                 add_prev ($text, $stack, $line) unless $state->{'ignored'}; 
+                 add_prev ($text, $stack, "address@hidden" . $line) unless 
$state->{'ignored'}; 
             }
             # pertusus: it seems that value substitution are performed after
             # macro argument expansions: if we have 
@@ -9508,7 +9537,7 @@
                  my $line;
                  ($_, $line) = misc_command_structure($_, $macro, $state, 
                        $line_nr);
-                 add_prev ($text, $stack, $line); 
+                 add_prev ($text, $stack, "address@hidden".$line); 
                  next;
             }
 
@@ -9689,11 +9718,11 @@
                             $state->{'place'} = $state->{'footnote_place'};
                         }
                     }
-                    elsif ($style->{'style'} eq 'math' and 
$Texi2HTML::Config::L2H)
-                    {
-                        add_prev ($text, $stack, do_math($style->{'text'}));
-                        next;
-                    }
+                    #elsif ($style->{'style'} eq 'math' and 
$Texi2HTML::Config::L2H)
+                    #{
+                    #    add_prev ($text, $stack, do_math($style->{'text'}));
+                    #    next;
+                    #}
                     elsif ($style->{'style'} eq 'caption' or $style->{'style'}
 eq 'shortcaption' and $state->{'float'})
                     {
@@ -9704,7 +9733,11 @@
                     {
                         $state->{'element'}->{'titlefont'} = $style->{'text'} 
unless ((exists($state->{'region_lines'}) and 
($state->{'region_lines'}->{'format'} eq 'titlepage')) or 
defined($state->{'element'}->{'titlefont'})) ;
                     }
-                    if ($style->{'style'})
+                    if 
(defined($Texi2HTML::Config::command_handler{$style->{'style'}}))
+                    {
+                         $result = 
init_special($style->{'style'},$style->{'text'});
+                    }
+                    elsif ($style->{'style'})
                     {
                          $result = '@' . $style->{'style'} . '{' . 
$style->{'text'} . '}';
                     }
@@ -10126,6 +10159,7 @@
             add_prev($text, $stack, do_text($1, $state));
             my $macro = $2;
            #print STDERR "MACRO $macro\n";
+           #print STDERR "LINE $_";
            #dump_stack ($text, $stack, $state);
             # This is a macro added by close_stack to mark paragraph end
             if ($macro eq 'end_paragraph')
@@ -10174,7 +10208,7 @@
                     ($_, $line, $args) = preserve_command($_, $macro);
                     if ($state->{'keep_texi'})
                     {
-                        add_prev($text, $stack, $line);
+                        add_prev($text, $stack, "address@hidden". $line);
                     }
                     next;
                 }
@@ -10347,11 +10381,11 @@
             }
             # the following macros are not modified but just ignored 
             # if we are removing texi
-            if ($macro =~ /^tex_(\d+)$/o)
-            {
-                add_prev($text, $stack, Texi2HTML::LaTeX2HTML::do_tex($1));
-                next;
-            }
+#            if ($macro =~ /^tex_(\d+)$/o)
+#            {
+#                add_prev($text, $stack, Texi2HTML::LaTeX2HTML::do_tex($1));
+#                next;
+#            }
             if ($state->{'remove_texi'})
             {
                  if ((($macro =~ /^(\w+?)index$/) and ($1 ne 'print')) or 
@@ -11219,7 +11253,6 @@
     my $line_nr = shift;
     my $no_open = shift;
     my $no_close = shift;
-    my $result;
     
     my $arg_nr = 0;
     $arg_nr = @$args - 1 if (defined($args));
@@ -11253,6 +11286,7 @@
     }
     if (defined($things_map_ref->{$macro}))
     {
+        my $result;
         if ($state->{'keep_texi'})
         {
              $result = "address@hidden" . '{}';
@@ -11276,11 +11310,12 @@
     {
         if ($state->{'keep_texi'})
         {
-             $result = "address@hidden" . '{' . $text . '}';
+             return "address@hidden" . '{' . $text . '}';
         }
         else 
         {
              my $style;
+             my $result;
              if ($state->{'remove_texi'})
              {
 #print STDERR "REMOVE $macro, $style_map_texi_ref->{$macro}, fun 
$style_map_texi_ref->{$macro}->{'function'} remove cmd " . 
\&Texi2HTML::Config::t2h_remove_command . " ascii acc " . 
\&t2h_default_ascii_accent;
@@ -11302,12 +11337,38 @@
              { 
                   close_arg($macro,$arg_nr, $state);
              }
+             return $result;
+        }
+    }
+    elsif ($macro =~ /^special_(\w+)_(\d+)$/o)
+    {
+        my $style = $1;
+        my $count = $2;
+        print STDERR "Bug? text in address@hidden not empty.\n" if ($text ne 
'');  
+        if ($state->{'keep_texi'})
+        {# text should be empty
+             return "address@hidden" . '{' . $text . '}';
+        }
+        if (defined($Texi2HTML::Config::command_handler{$style}) and
+          defined($Texi2HTML::Config::command_handler{$style}->{'expand'}))
+        {
+             if ($count != $special_commands{$style}->{'count'})
+             {
+                  print STDERR "Bug? count in address@hidden and structure 
differ\n";
+             }
+             else
+             {
+                  $special_commands{$style}->{'count'}--;  
+             }
         }
+        my $result = $Texi2HTML::Config::command_handler{$style}->{'expand'}
+              ($style,$count,$state,$text);
+        $result = '' if (!defined($result));
         return $result;
     }
     # Unknown macro
-    $result = '';
-    my ($done, $result_text, $message) = 
&$Texi2HTML::Config::unknown_style($macro, $text);
+    my $result = '';
+    my ($done, $result_text, $message) = 
&$Texi2HTML::Config::unknown_style($macro, $text,$state);
     if ($done)
     {
          echo_warn($message, $line_nr) if (defined($message));
@@ -11338,7 +11399,8 @@
     my $stack = shift;
     my $state = shift;
     my $line_nr = shift;
-    my ($result_line, $result, $result_text, $message) = 
&$Texi2HTML::Config::unknown($macro, $line);
+    #print STDERR "do_unknown: $macro ::: $line"; 
+    my ($result_line, $result, $result_text, $message) = 
&$Texi2HTML::Config::unknown($macro, $line,$stack,$state);
     if ($result)
     {
          add_prev ($text, $stack, $result_text) if (defined($result_text));
@@ -11883,6 +11945,8 @@
     return $result . $text;
 }
 
+# this function does the second pass formatting. It is not obvious that 
+# it is usefull as in that pass the collected things 
 sub substitute_texi_line($)
 {
     my $text = shift;  
@@ -11985,8 +12049,25 @@
 }
     
 open_file($docu, $texi_line_number);
-Texi2HTML::LaTeX2HTML::init($docu_name, $docu_rdir, $T2H_DEBUG & $DEBUG_L2H)
- if ($Texi2HTML::Config::L2H);
+#Texi2HTML::LaTeX2HTML::init() if ($Texi2HTML::Config::L2H);
+if ($Texi2HTML::Config::L2H)
+{
+   push @Texi2HTML::Config::command_handler_init, 
\&Texi2HTML::LaTeX2HTML::init;
+   push @Texi2HTML::Config::command_handler_process, 
\&Texi2HTML::LaTeX2HTML::latex2html;
+   push @Texi2HTML::Config::command_handler_finish, 
\&Texi2HTML::LaTeX2HTML::finish;
+   $Texi2HTML::Config::command_handler{'math'} = 
+     { 'init' => \&Texi2HTML::LaTeX2HTML::to_latex, 
+       'expand' => \&Texi2HTML::LaTeX2HTML::do_tex
+     };
+   $Texi2HTML::Config::command_handler{'tex'} = 
+     { 'init' => \&Texi2HTML::LaTeX2HTML::to_latex, 
+       'expand' => \&Texi2HTML::LaTeX2HTML::do_tex
+     };
+}
+foreach my $handler(@Texi2HTML::Config::command_handler_init)
+{
+    &$handler;
+}
 pass_texi();
 dump_texi(address@hidden, 'texi', address@hidden) if ($T2H_DEBUG & 
$DEBUG_TEXI);
 if (defined($Texi2HTML::Config::MACRO_EXPAND))
@@ -12024,19 +12105,25 @@
 if (@{$region_lines{'copying'}})
 {
     $copying_comment = 
&$Texi2HTML::Config::copying_comment($region_lines{'copying'});
-    #$copying_comment = remove_texi(@{$region_lines{'copying'}});
-    #$copying_comment = &$Texi2HTML::Config::comment($copying_comment);
 }
 &$Texi2HTML::Config::toc_body(address@hidden);
-#&$Texi2HTML::Config::toc_body(address@hidden, $do_contents, $do_scontents);
 &$Texi2HTML::Config::css_lines(address@hidden, address@hidden);
 $sec_num = 0;
-#$Texi2HTML::Config::L2H = l2h_FinishToLatex() if ($Texi2HTML::Config::L2H);
-#$Texi2HTML::Config::L2H = l2h_ToHtml()        if ($Texi2HTML::Config::L2H);
-#$Texi2HTML::Config::L2H = l2h_InitFromHtml()  if ($Texi2HTML::Config::L2H);
-Texi2HTML::LaTeX2HTML::latex2html();
+
+#Texi2HTML::LaTeX2HTML::latex2html();
+foreach my $handler(@Texi2HTML::Config::command_handler_process)
+{
+    &$handler;
+}
 pass_text();
-#do_node_files() if ($Texi2HTML::Config::SPLIT ne 'node' and 
$Texi2HTML::Config::NODE_FILES);
+foreach my $special (keys(%special_commands))
+{
+    my $count = $special_commands{$special}->{'count'};
+    if ($count != 0)
+    {
+         echo_warn ("Still $count special address@hidden not processed\n");
+    }
+}
 if ($Texi2HTML::Config::IDX_SUMMARY)
 {
     foreach my $entry (keys(%$index_properties))
@@ -12049,7 +12136,11 @@
 do_node_files() if ($Texi2HTML::Config::NODE_FILES);
 #l2h_FinishFromHtml() if ($Texi2HTML::Config::L2H);
 #l2h_Finish() if($Texi2HTML::Config::L2H);
-Texi2HTML::LaTeX2HTML::finish();
+#Texi2HTML::LaTeX2HTML::finish();
+foreach my $handler(@Texi2HTML::Config::command_handler_finish)
+{
+    &$handler;
+}
 &$Texi2HTML::Config::finish_out();
 print STDERR "# that's all folks\n" if $T2H_VERBOSE;
 




reply via email to

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