[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Convert/Plaintext.pm Texinfo...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Convert/Plaintext.pm Texinfo... |
Date: |
Thu, 24 Mar 2011 00:51:57 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 11/03/24 00:51:56
Modified files:
tp/Texinfo/Convert: Plaintext.pm Text.pm
tp/t : test_utils.pl
Added files:
tp/Texinfo/Convert: Converter.pm
Log message:
Add a generic converter class for code that could be useful to all the
converters.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.125&r2=1.126
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Text.pm?cvsroot=texinfo&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.76&r2=1.77
Patches:
Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -b -r1.125 -r1.126
--- Texinfo/Convert/Plaintext.pm 22 Mar 2011 00:37:04 -0000 1.125
+++ Texinfo/Convert/Plaintext.pm 24 Mar 2011 00:51:56 -0000 1.126
@@ -22,8 +22,8 @@
use 5.00405;
use strict;
+use Texinfo::Convert::Converter;
use Texinfo::Common;
-use Texinfo::Report;
use Texinfo::Convert::Texinfo;
use Texinfo::Convert::Text;
use Texinfo::Convert::Paragraph;
@@ -35,7 +35,7 @@
require Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
address@hidden = qw(Exporter Texinfo::Report);
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.
@@ -331,138 +331,42 @@
}
}
-sub _unset_global_multiple_commands($)
+sub _defaults($)
{
- my $converter = shift;
-
- foreach my $global_command (@informative_global_commands) {
- if (defined($converter->{'extra'}->{$global_command})
- and ref($converter->{'extra'}->{$global_command}) eq 'ARRAY') {
- my $root = $converter->{'extra'}->{$global_command}->[0];
- next if ($converter->{'set'}->{$root->{'cmdname'}}
- or !exists($defaults{$root->{'cmdname'}}));
- $converter->{$root->{'cmdname'}} = $defaults{$root->{'cmdname'}};
- }
- }
+ return %defaults;
}
-sub converter(;$)
+sub _global_commands($)
{
- my $class = shift;
- my $converter = { 'set' => {} };
-
- my $conf;
- my $name = 'converter';
+ return @informative_global_commands;
+}
- if (ref($class) eq 'HASH') {
- $conf = $class;
- bless $converter;
- } elsif (defined($class)) {
- bless $converter, $class;
- $name = ref($class);
- $conf = shift;
- } else {
- bless $converter;
- $conf = shift;
- $name = ref($converter);
- }
- foreach my $key (keys(%defaults)) {
- $converter->{$key} = $defaults{$key};
- }
- if (defined($conf)) {
- if ($conf->{'parser'}) {
- $converter->{'parser'} = $conf->{'parser'};
- $converter->{'extra'}
- = $converter->{'parser'}->global_commands_information();
- $converter->{'info'} = $converter->{'parser'}->global_informations();
- if ($converter->{'info'} and $converter->{'info'}->{'perl_encoding'}) {
- $converter->{'perl_encoding'} =
$converter->{'info'}->{'perl_encoding'};
- $converter->{'encoding_name'} =
$converter->{'info'}->{'encoding_name'};
- }
- my $floats = $converter->{'parser'}->floats_information();
- my $labels = $converter->{'parser'}->labels_information();
- $converter->{'structuring'} = $converter->{'parser'}->{'structuring'};
-
- $converter->{'floats'} = $floats if ($floats);
- $converter->{'labels'} = $labels if ($labels);
- $converter->{'setcontentsaftertitlepage'} = 1
- if ($converter->{'extra'}->{'contents'}
- and $converter->{'extra'}->{'setcontentsaftertitlepage'}
- and $converter->{'structuring'}
- and $converter->{'structuring'}->{'sectioning_root'});
- $converter->{'setshortcontentsaftertitlepage'} = 1
- if (($converter->{'extra'}->{'shortcontents'}
- or $converter->{'extra'}->{'summarycontents'})
- and $converter->{'extra'}->{'setshortcontentsaftertitlepage'}
- and $converter->{'structuring'}
- and $converter->{'structuring'}->{'sectioning_root'});
- $converter->{'gettext'} = $converter->{'parser'}->{'gettext'};
- foreach my $global_command (@informative_global_commands) {
- if (defined($converter->{'extra'}->{$global_command})) {
- my $root = $converter->{'extra'}->{$global_command};
- #if (ref($root) eq 'ARRAY') {
- # $root = $converter->{'extra'}->{$global_command}->[0];
- #}
- if (ref($root) ne 'ARRAY') {
- $converter->_informative_command($root);
- }
- }
- }
- delete $conf->{'parser'};
- }
- foreach my $key (keys(%$conf)) {
- if (!exists($defaults{$key})) {
- # many things may be passed down
- #warn "$key not a possible configuration in $name\n";
- } else {
- $converter->{$key} = $conf->{$key};
- $converter->{'set'}->{$key} = 1;
- }
- }
- }
- if (!defined($converter->{'expanded_formats'})) {
- if ($converter->{'parser'}) {
- $converter->{'expanded_formats'} =
$converter->{'parser'}->{'expanded_formats'};
- } else {
- $converter->{'expanded_formats'} = [];
- }
- }
- if (!defined($converter->{'include_directories'})) {
- if ($converter->{'parser'}) {
- $converter->{'include_directories'} =
$converter->{'parser'}->{'include_directories'};
- } else {
- $converter->{'include_directories'} = [ '.' ];
- }
- }
+sub _initialize($)
+{
+ my $self = shift;
- $converter->{'context'} = [];
- $converter->{'format_context'} = [];
- $converter->push_top_formatter('_Root_context');
- push @{$converter->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
+ $self->{'context'} = [];
+ $self->{'format_context'} = [];
+ $self->push_top_formatter('_Root_context');
+ push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
'locations' => []};
- %{$converter->{'ignored_types'}} = %ignored_types;
- %{$converter->{'ignored_commands'}} = %ignored_commands;
+ %{$self->{'ignored_types'}} = %ignored_types;
+ %{$self->{'ignored_commands'}} = %ignored_commands;
# this is dynamic because raw formats may either be full commands if
# isolated, or simple text if in a paragraph
- %{$converter->{'format_context_commands'}} =
%default_format_context_commands;
- %{$converter->{'preformatted_context_commands'}}
+ %{$self->{'format_context_commands'}} = %default_format_context_commands;
+ %{$self->{'preformatted_context_commands'}}
= %default_preformatted_context_commands;
- $converter->{'footnote_index'} = 0;
- $converter->{'pending_footnotes'} = [];
+ $self->{'footnote_index'} = 0;
+ $self->{'pending_footnotes'} = [];
- # turn the array to a hash for speed. Not sure it really matters for such
- # a small array.
- foreach my $expanded_format(@{$converter->{'expanded_formats'}}) {
- $converter->{'expanded_formats_hash'}->{$expanded_format} = 1;
- }
foreach my $format (@out_formats) {
- $converter->{'ignored_commands'}->{$format} = 1
- unless ($converter->{'expanded_formats_hash'}->{$format});
+ $self->{'ignored_commands'}->{$format} = 1
+ unless ($self->{'expanded_formats_hash'}->{$format});
}
- $converter->Texinfo::Report::new();
- return $converter;
+ return $self;
}
sub _convert_node($$)
Index: Texinfo/Convert/Text.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Text.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- Texinfo/Convert/Text.pm 22 Mar 2011 19:34:55 -0000 1.33
+++ Texinfo/Convert/Text.pm 24 Mar 2011 00:51:56 -0000 1.34
@@ -526,6 +526,8 @@
},
);
+#Â verbatiminclude would be nice to have too, however it requires a Report
+# object and a list of directories, which is too much for this converter
our %formatting_misc_commands;
foreach my $command ('sp', 'center', 'exdent',
'item', 'itemx', 'tab', 'headitem',
Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -b -r1.76 -r1.77
--- t/test_utils.pl 22 Mar 2011 00:37:04 -0000 1.76
+++ t/test_utils.pl 24 Mar 2011 00:51:56 -0000 1.77
@@ -193,7 +193,7 @@
my $converter_options = shift;
$converter_options = {} if (!defined($converter_options));
my $converter =
- Texinfo::Convert::Plaintext::converter({'DEBUG' => $self->{'DEBUG'},
+ Texinfo::Convert::Plaintext->converter({'DEBUG' => $self->{'DEBUG'},
'parser' => $parser,
'output_format' => 'plaintext',
%$converter_options });
Index: Texinfo/Convert/Converter.pm
===================================================================
RCS file: Texinfo/Convert/Converter.pm
diff -N Texinfo/Convert/Converter.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Texinfo/Convert/Converter.pm 24 Mar 2011 00:51:56 -0000 1.1
@@ -0,0 +1,184 @@
+# Converter.pm: Common code for Converters.
+#
+# Copyright 2011 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>
+
+package Texinfo::Convert::Converter;
+
+use 5.00405;
+use strict;
+
+use Texinfo::Report;
+
+use vars qw(@ISA);
address@hidden = qw(Texinfo::Report);
+
+my %defaults = (
+ 'frenchspacing' => 'off',
+ 'paragraphindent' => 3,
+ 'firstparagraphindent' => 'none',
+ 'ENABLE_ENCODING' => 1,
+ 'footnotestyle' => 'end',
+ 'fillcolumn' => 72,
+# 'perl_encoding' => 'ascii',
+# 'encoding_name' => 'us-ascii',
+ 'OUTFILE' => undef,
+ 'SUBDIR' => undef,
+ 'documentlanguage' => undef,
+ 'NUMBER_FOOTNOTES' => 1,
+ 'SPLIT_SIZE' => 300000,
+ 'expanded_formats' => undef,
+ 'include_directories' => undef,
+ 'NUMBER_SECTIONS' => 1,
+
+ 'DEBUG' => 0,
+ 'TEST' => 0,
+);
+
+sub _defaults($)
+{
+ return %defaults;
+}
+
+sub _initialize($)
+{
+}
+
+sub _global_commands($)
+{
+ return ();
+}
+
+sub converter(;$)
+{
+ my $class = shift;
+ my $converter = { 'set' => {} };
+
+ my $conf;
+ my $name = 'converter';
+
+ if (ref($class) eq 'HASH') {
+ $conf = $class;
+ bless $converter;
+ } elsif (defined($class)) {
+ bless $converter, $class;
+ $name = ref($class);
+ $conf = shift;
+ } else {
+ bless $converter;
+ $conf = shift;
+ $name = ref($converter);
+ }
+ my %defaults = $converter->_defaults();
+ foreach my $key (keys(%defaults)) {
+ $converter->{$key} = $defaults{$key};
+ }
+ if (defined($conf)) {
+ if ($conf->{'parser'}) {
+ $converter->{'parser'} = $conf->{'parser'};
+ $converter->{'extra'}
+ = $converter->{'parser'}->global_commands_information();
+ $converter->{'info'} = $converter->{'parser'}->global_informations();
+ if ($converter->{'info'} and $converter->{'info'}->{'perl_encoding'}) {
+ $converter->{'perl_encoding'} =
$converter->{'info'}->{'perl_encoding'};
+ $converter->{'encoding_name'} =
$converter->{'info'}->{'encoding_name'};
+ }
+ my $floats = $converter->{'parser'}->floats_information();
+ my $labels = $converter->{'parser'}->labels_information();
+ $converter->{'structuring'} = $converter->{'parser'}->{'structuring'};
+
+ $converter->{'floats'} = $floats if ($floats);
+ $converter->{'labels'} = $labels if ($labels);
+ $converter->{'setcontentsaftertitlepage'} = 1
+ if ($converter->{'extra'}->{'contents'}
+ and $converter->{'extra'}->{'setcontentsaftertitlepage'}
+ and $converter->{'structuring'}
+ and $converter->{'structuring'}->{'sectioning_root'});
+ $converter->{'setshortcontentsaftertitlepage'} = 1
+ if (($converter->{'extra'}->{'shortcontents'}
+ or $converter->{'extra'}->{'summarycontents'})
+ and $converter->{'extra'}->{'setshortcontentsaftertitlepage'}
+ and $converter->{'structuring'}
+ and $converter->{'structuring'}->{'sectioning_root'});
+ $converter->{'gettext'} = $converter->{'parser'}->{'gettext'};
+ foreach my $global_command ($converter->_global_commands()) {
+ if (defined($converter->{'extra'}->{$global_command})) {
+ my $root = $converter->{'extra'}->{$global_command};
+ #if (ref($root) eq 'ARRAY') {
+ # $root = $converter->{'extra'}->{$global_command}->[0];
+ #}
+ if (ref($root) ne 'ARRAY') {
+ $converter->_informative_command($root);
+ }
+ }
+ }
+ delete $conf->{'parser'};
+ }
+ foreach my $key (keys(%$conf)) {
+ if (!exists($defaults{$key})) {
+ # many things may be passed down
+ #warn "$key not a possible configuration in $name\n";
+ } else {
+ $converter->{$key} = $conf->{$key};
+ $converter->{'set'}->{$key} = 1;
+ }
+ }
+ }
+ if (!defined($converter->{'expanded_formats'})) {
+ if ($converter->{'parser'}) {
+ $converter->{'expanded_formats'} =
$converter->{'parser'}->{'expanded_formats'};
+ } else {
+ $converter->{'expanded_formats'} = [];
+ }
+ }
+ if (!defined($converter->{'include_directories'})) {
+ if ($converter->{'parser'}) {
+ $converter->{'include_directories'} =
$converter->{'parser'}->{'include_directories'};
+ } else {
+ $converter->{'include_directories'} = [ '.' ];
+ }
+ }
+
+ # turn the array to a hash for speed. Not sure it really matters for such
+ # a small array.
+ foreach my $expanded_format(@{$converter->{'expanded_formats'}}) {
+ $converter->{'expanded_formats_hash'}->{$expanded_format} = 1;
+ }
+
+ $converter->_initialize();
+
+ $converter->Texinfo::Report::new();
+
+ return $converter;
+}
+
+sub _unset_global_multiple_commands($)
+{
+ my $converter = shift;
+
+ foreach my $global_command ($converter->_global_commands()) {
+ if (defined($converter->{'extra'}->{$global_command})
+ and ref($converter->{'extra'}->{$global_command}) eq 'ARRAY') {
+ my $root = $converter->{'extra'}->{$global_command}->[0];
+ next if ($converter->{'set'}->{$root->{'cmdname'}}
+ or !exists($defaults{$root->{'cmdname'}}));
+ $converter->{$root->{'cmdname'}} = $defaults{$root->{'cmdname'}};
+ }
+ }
+}
+
+1;