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: Sat, 26 Jan 2013 14:49:02 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        13/01/26 14:49:01

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Common.pm Structuring.pm 
        tp/Texinfo/Convert: Converter.pm 
Added files:
        tp/Texinfo/Convert: IXIN.pm IXINSXML.pm 

Log message:
        Use TEXINFO_OUTPUT_FORMAT as a customization option to select the format
        in the same ay as the TEXINFO_OUTPUT_FORMAT environment variable.
        
        Preliminary IXIN (implement the ixin format) and IXINSXML (inherit from
        IXIN and TexinfoSXML to convert to ixin with SXML content.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.163&r2=1.164
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.174&r2=1.175
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.143&r2=1.144
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.100&r2=1.101
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/IXIN.pm?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/IXINSXML.pm?cvsroot=texinfo&rev=1.1

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -b -r1.163 -r1.164
--- texi2any.pl 24 Jan 2013 01:40:59 -0000      1.163
+++ texi2any.pl 26 Jan 2013 14:48:58 -0000      1.164
@@ -105,6 +105,7 @@
 use Texinfo::Convert::DocBook;
 use Texinfo::Convert::TextContent;
 use Texinfo::Convert::PlainTexinfo;
+use Texinfo::Convert::IXINSXML;
 use DebugTexinfo::DebugCount;
 use DebugTexinfo::DebugTree;
 
@@ -829,11 +830,13 @@
        $value = undef;
      }
      # special case, this is a pseudo format for debug
-     if ($var eq 'DEBUGCOUNT') {
-       $format = set_format('debugcount');
+     if ($var eq 'TEXINFO_OUTPUT_FORMAT') {
+       $format = set_format($value);
      } elsif ($var eq 'TEXI2HTML') {
        $format = set_format('html');
        $parser_default_options->{'values'}->{'texi2html'} = 1;
+     } elsif ($var eq 'DEBUGCOUNT') {
+       $format = set_format('debugcount');
      } elsif ($var eq 'DEBUGTREE') {
        $format = set_format('debugtree');
      } elsif ($var eq 'PLAINTEXINFO') {
@@ -942,6 +945,10 @@
              'nodes_tree' => 1,
              'converter' => sub{Texinfo::Convert::TexinfoSXML->converter(@_)},
            },
+  'ixinsxml' => {
+             'nodes_tree' => 1,
+             'converter' => sub{Texinfo::Convert::IXINSXML->converter(@_)},
+           },
   'docbook' => {
              'move_index_entries_after_items' => 1,
              'converter' => sub{Texinfo::Convert::DocBook->converter(@_)},

Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -b -r1.174 -r1.175
--- Texinfo/Common.pm   26 Jan 2013 14:16:00 -0000      1.174
+++ Texinfo/Common.pm   26 Jan 2013 14:48:59 -0000      1.175
@@ -260,6 +260,7 @@
   'TEXTCONTENT_COMMENT', 'XREF_USE_FLOAT_LABEL', 'XREF_USE_NODE_NAME_ARG',
   'MACRO_BODY_IGNORES_LEADING_SPACE', 'CHECK_HTMLXREF',
   'TEXINFO_DTD_VERSION', 'TEXINFO_COLUMN_FOR_DESCRIPTION',
+  'TEXINFO_OUTPUT_FORMAT',
 );
 # Not strings. 
 # FIXME To be documented somewhere, but where?

Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -b -r1.143 -r1.144
--- Texinfo/Structuring.pm      24 Jan 2013 01:40:59 -0000      1.143
+++ Texinfo/Structuring.pm      26 Jan 2013 14:49:00 -0000      1.144
@@ -1223,7 +1223,7 @@
     if ($element->{'extra'}->{'node_content'}) {
       unshift @{$command->{'contents'}}, 
@{$element->{'extra'}->{'node_content'}};
     }
-    return Texinfo::Convert::Texinfo::convert ($command);
+    return Texinfo::Convert::Texinfo::convert($command);
   }
   
   my $command = $element->{'extra'}->{'element_command'};

Index: Texinfo/Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -b -r1.100 -r1.101
--- Texinfo/Convert/Converter.pm        24 Jan 2013 01:40:59 -0000      1.100
+++ Texinfo/Convert/Converter.pm        26 Jan 2013 14:49:00 -0000      1.101
@@ -129,6 +129,23 @@
   return undef;
 }
 
+sub _informative_command_value($$)
+{
+  my $self = shift;
+  my $root = shift;
+
+  my $cmdname = $root->{'cmdname'};
+
+  if ($Texinfo::Common::misc_commands{$cmdname} eq 'skipline') {
+    return 1;
+  } elsif (exists($root->{'extra'}->{'text_arg'})) {
+    return $root->{'extra'}->{'text_arg'};
+  } elsif ($root->{'extra'} and $root->{'extra'}->{'misc_args'}
+           and exists($root->{'extra'}->{'misc_args'}->[0])) {
+    return $root->{'extra'}->{'misc_args'}->[0];
+  }
+}
+
 # FIXME documentencoding handling is not reverted by resetting
 # a value with set_conf, so _unset_global_multiple_commands won't
 # reverse what _set_global_multiple_commands did through 
@@ -143,33 +160,8 @@
 
   return if ($self->{'set'}->{$cmdname});
 
-  if ($Texinfo::Common::misc_commands{$cmdname} eq 'skipline') {
-    $self->set_conf($cmdname, 1);
-  } elsif (exists($root->{'extra'}->{'text_arg'})) {
-    $self->set_conf($cmdname, $root->{'extra'}->{'text_arg'});
-    #if ($cmdname eq 'documentencoding'
-    #    and defined($root->{'extra'})
-    #    and defined($root->{'extra'}->{'perl_encoding'})
-    #   ){
-      # the following does not work with shifijs.  The encoding
-      # has to be set only once by open_out. 
-      #if (defined($self->{'fh'})) {
-      #  my $encoding = $self->{'perl_encoding'};
-      #  my $filehandle = $self->{'fh'};
-      #  if ($encoding eq 'utf8' or $encoding eq 'utf-8-strict') {
-      #    binmode($filehandle, ':utf8');
-      #  } else { # also right for shiftijs or similar encodings?
-      #    binmode($filehandle, ':bytes');
-      #  }
-      #  binmode($filehandle, ":encoding($encoding)");
-      #}
-    #  $self->{'encoding_name'} = $root->{'extra'}->{'encoding_name'};
-    #  $self->{'perl_encoding'} = $root->{'extra'}->{'perl_encoding'};
-    #}
-  } elsif ($root->{'extra'} and $root->{'extra'}->{'misc_args'}
-           and exists($root->{'extra'}->{'misc_args'}->[0])) {
-    $self->set_conf($cmdname, $root->{'extra'}->{'misc_args'}->[0]);
-  }
+  my $value = $self->_informative_command_value($root);
+  $self->set_conf($cmdname, $value);
 }
 
 sub register_close_file($$)
@@ -821,7 +813,7 @@
   
   my $fh;
   if (! $self->{'output_file'} eq '') {
-    $fh = $self->Texinfo::Common::open_out ($self->{'output_file'});
+    $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
     if (!$fh) {
       $self->document_error(sprintf($self->__("Could not open %s for writing: 
%s"),
                                     $self->{'output_file'}, $!));

Index: Texinfo/Convert/IXIN.pm
===================================================================
RCS file: Texinfo/Convert/IXIN.pm
diff -N Texinfo/Convert/IXIN.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Texinfo/Convert/IXIN.pm     26 Jan 2013 14:49:00 -0000      1.1
@@ -0,0 +1,306 @@
+# IXIN.pm: output tree as IXIN.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# 
+# Original author: Patrice Dumas <address@hidden>
+#
+# This module implements abstract functions that output the IXIN format
+# using lower level formatting funtions, here adapted to lisp like 
+# output.  For other output, the output specific functions should be
+# redefined.  This module is not enough to output IXIN format, a module
+# inheriting both from a converter module and this module is required.
+
+package Texinfo::Convert::IXIN;
+
+use 5.00405;
+use strict;
+
+use Texinfo::Convert::TexinfoSXML;
+use Texinfo::Common;
+
+use Carp qw(cluck);
+
+require Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
address@hidden = qw(Exporter Texinfo::Convert::Converter);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration       use Texinfo::Convert::IXIN ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+%EXPORT_TAGS = ( 'all' => [ qw(
+  output_ixin
+) ] );
+
address@hidden = ( @{ $EXPORT_TAGS{'all'} } );
+
address@hidden = qw(
+);
+
+$VERSION = '5.0';
+
+my $ixin_version = 1;
+
+sub _ixin_version($)
+{
+  my $self = shift;
+  return $ixin_version;
+}
+
+my %additional_setting_commands;
+# FIXME pagesizes is line
+foreach my $command ('pagesizes', 'everyheading', 'everyfooting', 
+                     'evenheading', 'evenfooting', 'oddheading', 'oddfooting',
+                     'documentencoding', 'documentlanguage', 'clickstyle') {
+  $additional_setting_commands{$command} = 1;
+}
+  
+
+# output specific
+sub ixin_header($)
+{
+  my $self = shift;
+  my $header = 'ixin '.$self->_ixin_version().';';
+  if ($self->get_conf('OUTPUT_ENCODING_NAME')) {
+    $header .= ' -*- coding: '. $self->get_conf('OUTPUT_ENCODING_NAME') 
.'-*-;';
+  }
+  $header .= "\n";
+}
+
+sub ixin_empty($$)
+{
+  my $self = shift;
+  my $name = shift;
+  return '-';
+}
+
+sub ixin_open_element($$)
+{
+  my $self = shift;
+  my $name = shift;
+  return '(';
+}
+
+sub ixin_close_element($$)
+{
+  my $self = shift;
+  my $name = shift;
+  return ')';
+}
+
+sub ixin_string_element($$$)
+{
+  my $self = shift;
+  my $name = shift;
+  my $string = shift;
+  return '"'.Texinfo::Convert::TexinfoSXML->protect_text($string).'"';
+}
+
+sub ixin_symbol_element($$$)
+{
+  my $self = shift;
+  my $name = shift;
+  my $string = shift;
+  return $string;
+}
+
+# end output specific subs
+
+# FIXME this is rather non specific. Move to Converter?
+sub _get_element($$);
+sub _get_element($$)
+{
+  my $self = shift;
+  my $current = shift;
+
+  my ($element, $root_command);
+  while (1) {
+    #print STDERR Texinfo::Common::_print_current($current);
+    if ($current->{'type'}) {
+      if ($current->{'type'} eq 'element') {
+        return ($current, $root_command);
+      }
+    }
+    if ($current->{'cmdname'}) {
+      if ($Texinfo::Common::root_commands{$current->{'cmdname'}}) {
+        $root_command = $current;
+        return ($element, $root_command) if defined($element);
+      }
+    }
+    if ($current->{'parent'}) {
+      $current = $current->{'parent'};
+    } else {
+      return ($element, $root_command);
+    }
+  }
+}
+
+sub output_ixin($$)
+{
+  my $self = shift;
+  my $root = shift;
+
+  $self->_set_outfile();
+  return undef unless $self->_create_destination_directory();
+
+  my $fh;
+  if (! $self->{'output_file'} eq '') {
+    $fh = $self->Texinfo::Common::open_out($self->{'output_file'});
+    if (!$fh) {
+      $self->document_error(sprintf($self->__("Could not open %s for writing: 
%s"),
+                                    $self->{'output_file'}, $!));
+      return undef;
+    }
+  }
+
+  $self->_set_global_multiple_commands(-1);
+
+  my $header = $self->ixin_header();
+  my $result = $self->ixin_open_element('meta');
+  $result .= $self->ixin_open_element('xid');
+
+  my $output_file = $self->ixin_empty('filename');
+  if ($self->{'output_file'} ne '') {
+    $result .= $self->ixin_string_element('filename', $self->{'output_file'});
+  }
+  my $lang = $self->get_conf('documentlanguage');
+  #my $lang_code = $lang;
+  #my $region_code;
+  #if ($lang =~ /^([a-z]+)_([A-Z]+)/) {
+  #  $lang_code = $1;
+  #  $region_code = $2;
+  #}
+  $result .= ' ';
+  $result .= $self->ixin_string_element('lang', $lang);
+  # FIXME title: use simpletitle or fulltitle
+  
+  if ($self->{'info'}->{'dircategory_direntry'}) {
+    my $current_category;
+    foreach my $dircategory_direntry 
(@{$self->{'info'}->{'dircategory_direntry'}}) {
+      if ($dircategory_direntry->{'cmdname'} and 
$dircategory_direntry->{'cmdname'} eq 'dircategory') {
+        if ($current_category) {
+          $result .= $self->ixin_close_element('category');
+        }
+        $current_category = $dircategory_direntry;
+        $result .= $self->ixin_open_element('category');
+        # FIXME wait for Thien-Thi input on renderable or string.
+      } elsif ($dircategory_direntry->{'cmdname'} 
+               and $dircategory_direntry->{'cmdname'} eq 'direntry') {
+        # FIXME wait for Thien-Thi input on renderable or string and node
+        # rendering
+      }
+    }
+    if ($current_category) {
+      $result .= $self->ixin_close_element('category');
+    }
+  }
+  $result .= $self->ixin_close_element('xid');
+
+  # FIXME vars: wait for Thien-Thi answer.
+
+  my $elements = Texinfo::Structuring::split_by_node($root);
+
+  # setting_commands is for @-commands appearing before the first node,
+  # while end_of_nodes_setting_commands holds, for @-commands names, the 
+  # last @-command element.
+  my %setting_commands;
+  my %end_of_nodes_setting_commands;
+  foreach my $global_command (keys(%{$self->{'extra'}})) {
+    if (($Texinfo::Common::misc_commands{$global_command}
+         and $Texinfo::Common::misc_commands{$global_command} =~ /^\d/)
+        or $additional_setting_commands{$global_command}) {
+      if (ref($self->{'extra'}->{$global_command}) eq 'ARRAY') {
+        foreach my $command (@{$self->{'extra'}->{$global_command}}) {
+          my ($element, $root_command) = _get_element($self, $command);
+          # before first node
+          if (!defined($root_command->{'extra'}) 
+              and !defined($root_command->{'extra'}->{'normalized'})) {
+            $setting_commands{$global_command} = $command;
+          } else {
+            # register the setting value at the end of the node
+            
$end_of_nodes_setting_commands{$root_command->{'extra'}->{'normalized'}}->{$global_command}
+              = $command;
+          }
+          #print STDERR "$element $root_command->{'extra'} $global_command\n";
+        }
+      } else {
+        $setting_commands{$global_command} = 
$self->{'extra'}->{$global_command};
+      }
+    }
+  }
+  my %settings;
+  foreach my $setting_command_name (keys(%setting_commands)) {
+    my $setting_command = $setting_commands{$setting_command_name};
+    $setting_command_name = 'shortcontents' 
+        if ($setting_command_name eq 'summarycontents');
+    my $value = $self->_informative_command_value($setting_command);
+    #print STDERR "$setting_command_name $value\n";
+    if (defined($value)) {
+      $settings{$setting_command_name} = $value;
+    }
+  }
+
+  $result .= ' ';
+  $result .= $self->ixin_open_element('settings');
+  if (scalar(keys(%settings))) {
+    foreach my $command_name (sort(keys(%settings))) {
+      $result .= $self->ixin_open_element('setting');
+      $result .= $self->ixin_symbol_element('settingname', $command_name);
+      $result .= ' ';
+      if ($Texinfo::Common::misc_commands{$command_name} eq 'lineraw') {
+        $result .= $self->ixin_string_element('settingvalue', 
$settings{$command_name});
+      } else {
+        $result .= $self->ixin_symbol_element('settingvalue', 
$settings{$command_name});
+      }
+      $result .= $self->ixin_close_element('setting');
+    }
+  }
+  $result .= $self->ixin_close_element('settings');
+  $result .= $self->ixin_close_element('meta');
+  $result .= "\n";
+
+  my $document_output = '';
+  if ($elements) {
+    foreach my $node_element (@$elements) {
+      my $node_result = $self->convert_tree($node_element);
+      if ($node_element->{'extra'}->{'no_node'}) {
+        print STDERR "FIXME No node.  What to do?\n";
+      }
+      # get node length.
+      $document_output .= $node_result;
+    }
+  } else {
+    # not a full document.
+    return $self->_output_text($self->convert_tree($root), $fh);
+  }
+
+  my $output = $self->_output_text($result, $fh);
+
+  if ($fh and $self->{'output_file'} ne '-') {
+    $self->register_close_file($self->{'output_file'});
+    if (!close ($fh)) {
+      $self->document_error(sprintf($self->__("Error on closing %s: %s"),
+                                    $self->{'output_file'}, $!));
+    }
+  }
+  return $output;
+}
+
+1;
+

Index: Texinfo/Convert/IXINSXML.pm
===================================================================
RCS file: Texinfo/Convert/IXINSXML.pm
diff -N Texinfo/Convert/IXINSXML.pm
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Texinfo/Convert/IXINSXML.pm 26 Jan 2013 14:49:00 -0000      1.1
@@ -0,0 +1,85 @@
+# IXIN.pm: output tree as IXIN with SXML converter.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# 
+# Original author: Patrice Dumas <address@hidden>
+#
+# This module implements abstract functions that output the IXIN format
+# using lower level formatting funtions, here adapted to lisp like 
+# output.  For other output, the output specific functions should be
+# redefined.  This module is not enough to output IXIN format, a module
+# inheriting both from a converter module and this module is required.
+
+package Texinfo::Convert::IXINSXML;
+
+use 5.00405;
+use strict;
+
+use Texinfo::Convert::TexinfoSXML;
+use Texinfo::Convert::IXIN;
+
+use Carp qw(cluck);
+
+require Exporter;
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
address@hidden = qw(Exporter Texinfo::Convert::TexinfoSXML 
Texinfo::Convert::IXIN);
+
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+
+# This allows declaration       use Texinfo::Convert::IXIN ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+%EXPORT_TAGS = ( 'all' => [ qw(
+  output
+) ] );
+
address@hidden = ( @{ $EXPORT_TAGS{'all'} } );
+
address@hidden = qw(
+);
+
+$VERSION = '5.0';
+
+my %defaults = (
+  'ENABLE_ENCODING'      => 0,
+  'SHOW_MENU'            => 1,
+  'EXTENSION'            => 'ixin',
+  #'output_perl_encoding' => 'utf8',
+  'OUTPUT_ENCODING_NAME' => 'utf-8',
+  # useful?
+  'TEXINFO_DTD_VERSION'  => '5.0',
+  'OUTFILE'              => undef,
+  'SUBDIR'               => undef,
+  'output_format'        => 'ixinsxml',
+  'SPLIT'                => 0,
+  'documentlanguage'     => 'en',
+  'USE_NODES'            => 1,
+);
+
+sub converter_defaults($$)
+{
+  return %defaults;
+}
+
+sub output($)
+{
+  my $self = shift;
+  my $root = shift;
+
+  return $self->output_ixin($root);
+}



reply via email to

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