[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6712] load paragraph module as Texinfo::Convert::Paragraph
From: |
Gavin D. Smith |
Subject: |
[6712] load paragraph module as Texinfo::Convert::Paragraph |
Date: |
Mon, 19 Oct 2015 18:52:33 +0000 |
Revision: 6712
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6712
Author: gavin
Date: 2015-10-19 18:52:32 +0000 (Mon, 19 Oct 2015)
Log Message:
-----------
load paragraph module as Texinfo::Convert::Paragraph
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/MANIFEST
trunk/tp/Makefile.am
trunk/tp/Texinfo/Convert/Info.pm
trunk/tp/Texinfo/Convert/Plaintext.pm
trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am
trunk/tp/t/paragraph.t
trunk/tp/texi2any.pl
Added Paths:
-----------
trunk/tp/Texinfo/Convert/Paragraph.pm
trunk/tp/Texinfo/Convert/ParagraphNonXS.pm
Removed Paths:
-------------
trunk/tp/Texinfo/Convert/Paragraph.pm
trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/ChangeLog 2015-10-19 18:52:32 UTC (rev 6712)
@@ -1,5 +1,14 @@
2015-10-19 Gavin Smith <address@hidden>
+ * tp/Texinfo/Convert/Paragraph.pm,
+ tp/Texinfo/Convert/ParagraphNonXS.pm: Rename.
+ * tp/Texinfo/Convert/XSParagraph/XSParagraph.pm,
+ tp/Texinfo/Convert/Paragraph.pm: Move and rename. This allows
+ code to refer to the Texinfo::Convert::Paragraph module, as it
+ did before (instead of Texinfo::Convert::XSParagraph::XSParagraph).
+
+2015-10-19 Gavin Smith <address@hidden>
+
* info/info-utils.c (parse_top_node_line): Adjust
output_bytes_difference and node_offset according to how much of
the nodeline was printed.
Modified: trunk/tp/MANIFEST
===================================================================
--- trunk/tp/MANIFEST 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/tp/MANIFEST 2015-10-19 18:52:32 UTC (rev 6712)
@@ -56,6 +56,7 @@
Texinfo/Convert/Line.pm
Texinfo/Convert/NodeNameNormalization.pm
Texinfo/Convert/Paragraph.pm
+Texinfo/Convert/ParagraphNonXS.pm
Texinfo/Convert/PlainTexinfo.pm
Texinfo/Convert/Plaintext.pm
Texinfo/Convert/Texinfo.pm
Modified: trunk/tp/Makefile.am
===================================================================
--- trunk/tp/Makefile.am 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/tp/Makefile.am 2015-10-19 18:52:32 UTC (rev 6712)
@@ -90,6 +90,7 @@
Texinfo/Convert/Line.pm \
Texinfo/Convert/NodeNameNormalization.pm \
Texinfo/Convert/Paragraph.pm \
+ Texinfo/Convert/ParagraphNonXS.pm \
Texinfo/Convert/PlainTexinfo.pm \
Texinfo/Convert/Plaintext.pm \
Texinfo/Convert/Texinfo.pm \
Modified: trunk/tp/Texinfo/Convert/Info.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Info.pm 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/tp/Texinfo/Convert/Info.pm 2015-10-19 18:52:32 UTC (rev 6712)
@@ -1,6 +1,6 @@
# Info.pm: output tree as Info.
#
-# Copyright 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+# Copyright 2010, 2011, 2012, 2013, 2014, 2015 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
@@ -304,7 +304,7 @@
my $self = shift;
$self->_set_global_multiple_commands();
- my $paragraph = Texinfo::Convert::XSParagraph::XSParagraph->new();
+ my $paragraph = Texinfo::Convert::Paragraph->new();
my $result = $paragraph->add_text("This is ");
# This ensures that spaces in file are kept.
$result .= $paragraph->add_next($self->{'output_filename'});
Deleted: trunk/tp/Texinfo/Convert/Paragraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Paragraph.pm 2015-10-19 18:17:21 UTC (rev
6711)
+++ trunk/tp/Texinfo/Convert/Paragraph.pm 2015-10-19 18:52:32 UTC (rev
6712)
@@ -1,478 +0,0 @@
-# Paragraph.pm: handle paragraph text.
-#
-# Copyright 2010, 2011, 2012, 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 has nothing Texinfo specific. In contrast with existing
-# modules Text::Wrap, Text::Format, it keeps a state of the paragraph
-# and waits for text to be fed into it.
-
-package Texinfo::Convert::Paragraph;
-
-use 5.006;
-use strict;
-
-use Unicode::EastAsianWidth;
-use Carp qw(cluck);
-
-# initialize a paragraph object.
-sub new($;$)
-{
- my $class = shift;
- my $conf = shift;
- my $self = {'max' => 72, 'indent_length' => 0, 'counter' => 0,
- 'word_counter' => 0, 'space' => '', 'frenchspacing' => 0,
- 'lines_counter' => 0, 'end_line_count' => 0};
- if (defined($conf)) {
- foreach my $key (keys(%$conf)) {
- $self->{$key} = $conf->{$key};
- }
- }
- bless $self, $class;
-}
-
-# for debugging
-sub dump($)
-{
- my $self = shift;
- my $word = 'UNDEF';
- if (defined($self->{'word'})) {
- $word = $self->{'word'};
- }
- my $end_sentence = 'UNDEF';
- $end_sentence = $self->{'end_sentence'} if
(defined($self->{'end_sentence'}));
- print STDERR "para ($self->{'counter'}+$self->{'word_counter'}) word: $word,
space `$self->{'space'}' end_sentence: $end_sentence\n";
-}
-
-sub _cut_line($)
-{
- my $paragraph = shift;
- return '' if ($paragraph->{'ignore_columns'});
- return _end_line($paragraph);
-}
-
-sub end_line_count($)
-{
- my $paragraph = shift;
- return $paragraph->{'end_line_count'};
-}
-
-sub end_line($)
-{
- my $paragraph = shift;
- $paragraph->{'end_line_count'} = 0;
- return _end_line($paragraph);
-}
-
-# end a line.
-sub _end_line($)
-{
- my $paragraph = shift;
- $paragraph->{'counter'} = 0;
- $paragraph->{'space'} = '';
- if (defined($paragraph->{'indent_length_next'})) {
- $paragraph->{'indent_length'} = $paragraph->{'indent_length_next'};
- delete $paragraph->{'indent_length_next'};
- }
- $paragraph->{'lines_counter'}++;
- $paragraph->{'end_line_count'}++;
- print STDERR "END_LINE\n" if ($paragraph->{'DEBUG'});
- return "\n";
-}
-
-sub get_pending($)
-{
- my $paragraph = shift;
- my $result = '';
- if ($paragraph->{'space'}) {
- $result .= $paragraph->{'space'};
- }
- if (defined($paragraph->{'word'})) {
- $result .= $paragraph->{'word'};
- }
- return $result;
-}
-
-sub add_pending_word($;$)
-{
- my $paragraph = shift;
- my $add_spaces = shift;
- $paragraph->{'end_line_count'} = 0;
- return _add_pending_word($paragraph, $add_spaces);
-}
-
-# put a pending word and spaces in the result string.
-sub _add_pending_word($;$)
-{
- my $paragraph = shift;
- my $add_spaces = shift;
- my $result = '';
-
- if (defined($paragraph->{'word'}) or $add_spaces) {
- if ($paragraph->{'indent_length'} > $paragraph->{'counter'}) {
- $result .= ' ' x ($paragraph->{'indent_length'} -
$paragraph->{'counter'});
- $paragraph->{'counter'} = $paragraph->{'indent_length'};
- print STDERR
"INDENT($paragraph->{'counter'}+$paragraph->{'word_counter'})\n"
- if ($paragraph->{'DEBUG'});
- } elsif ($paragraph->{'space'}) {
- $result .= $paragraph->{'space'};
- $paragraph->{'counter'} += length($paragraph->{'space'});
- print STDERR
"ADD_SPACES($paragraph->{'counter'}+$paragraph->{'word_counter'})\n"
- if ($paragraph->{'DEBUG'});
-
- }
- if (defined($paragraph->{'word'})) {
- $result .= $paragraph->{'word'};
- $paragraph->{'counter'} += $paragraph->{'word_counter'};
- print STDERR
"ADD_WORD[$paragraph->{'word'}]+$paragraph->{'word_counter'}
($paragraph->{'counter'})\n"
- if ($paragraph->{'DEBUG'});
- $paragraph->{'word'} = undef;
- $paragraph->{'last_char'} = undef;
- $paragraph->{'word_counter'} = 0;
- }
- $paragraph->{'space'} = '';
- }
- return $result;
-}
-
-# end a paragraph
-sub end($)
-{
- my $paragraph = shift;
- $paragraph->{'end_line_count'} = 0;
- print STDERR "PARA END\n" if ($paragraph->{'DEBUG'});
- my $result = _add_pending_word($paragraph);
- if ($paragraph->{'counter'} != 0) {
- $result .= "\n";
- $paragraph->{'lines_counter'}++;
- $paragraph->{'end_line_count'}++;
- }
- return $result;
-}
-
-my $end_sentence_character = quotemeta('.?!');
-my $after_punctuation_characters = quotemeta('"\')]');
-
-# Add $WORD to paragraph, returning the text to be added to the paragraph.
-# Any end of sentence punctuation in $WORD that should be allowed to end a
-# sentence but which would otherwise be preceded by an upper-case letter
should
-# instead by preceded by a backspace character.
-sub add_next($;$$)
-{
- my $paragraph = shift;
- my $word = shift;
- my $transparent = shift;
- $paragraph->{'end_line_count'} = 0;
- return _add_next($paragraph, $word, $transparent);
-}
-
-# add a word and/or end of sentence.
-sub _add_next($;$$$)
-{
- my $paragraph = shift;
- my $word = shift;
- my $transparent = shift;
- my $newlines_impossible = shift;
- my $result = '';
-
- if (defined($word)) {
- my $disinhibit = 0;
- # Reverse the insertion of the control character in Plaintext.pm.
- if ($word =~ s/\x08$//) {
- $disinhibit = 1;
- }
- if (!defined($paragraph->{'word'})) {
- $paragraph->{'word'} = '';
- $paragraph->{'last_char'} = '';
- if ($paragraph->{'end_sentence'}
- and $paragraph->{'end_sentence'} > 0
- and !$paragraph->{'frenchspacing'}
- and $paragraph->{'counter'} != 0 and $paragraph->{'space'}) {
- # do not to double space if there are leading spaces in word
- if ($word !~ /^\s/) {
- #$paragraph->{'space'} = ' ';
- $paragraph->{'space'} .= ' ' x (2 - length($paragraph->{'space'}));
- }
- delete $paragraph->{'end_sentence'};
- }
- }
-
- $paragraph->{'word'} .= $word;
-
- if (!$transparent) {
- if ($disinhibit) {
- $paragraph->{'last_char'} = 'a';
- } elsif ($word =~
- /([^$end_sentence_character$after_punctuation_characters])
- [$end_sentence_character$after_punctuation_characters]*$/x) {
- # Save the last character in $word before punctuation
- $paragraph->{'last_char'} = $1;
- }
- }
-
- if (!$newlines_impossible and $word =~ /\n/) {
- $result .= $paragraph->{'space'};
- $paragraph->{'space'} = '';
- $result .= $paragraph->{'word'};
- _end_line($paragraph);
- $paragraph->{'word_counter'} = 0;
- $paragraph->{'word'} = undef;
- $paragraph->{'last_char'} = undef;
- } else {
- $paragraph->{'word_counter'} += length($word);
- }
- if ($paragraph->{'DEBUG'}) {
- my $para_word = 'UNDEF';;
- if (defined($paragraph->{'word'})) {
- $para_word = $paragraph->{'word'};
- }
- print STDERR "WORD+ $word -> $para_word\n";
- }
- # The $paragraph->{'counter'} != 0 is here to avoid having an
- # additional line output when the text is longer than the max.
- if ($paragraph->{'counter'} != 0 and
- $paragraph->{'counter'} + $paragraph->{'word_counter'} +
- length($paragraph->{'space'}) > $paragraph->{'max'}) {
- $result .= _cut_line($paragraph);
- }
- }
- return $result;
-}
-
-sub remove_end_sentence($)
-{
- my $paragraph = shift;
- $paragraph->{'end_sentence'} = 0;
-}
-
-sub add_end_sentence($;$) {
- my $paragraph = shift;
- my $value = shift;
- $paragraph->{'end_sentence'} = $value;
-}
-
-sub allow_end_sentence($)
-{
- my $paragraph = shift;
- printf STDERR "ALLOW END SENTENCE\n" if $paragraph->{'DEBUG'};
- $paragraph->{'last_char'} = 'a'; # lower-case
-}
-
-sub set_space_protection($$;$$$)
-{
- my $paragraph = shift;
- my $space_protection = shift;
- my $ignore_columns = shift;
- my $keep_end_lines = shift;
- my $frenchspacing = shift;
- $paragraph->{'protect_spaces'} = $space_protection
- if defined($space_protection);
- $paragraph->{'ignore_columns'} = $ignore_columns
- if defined($ignore_columns);
- $paragraph->{'keep_end_lines'} = $keep_end_lines
- if defined($keep_end_lines);
- if (!$paragraph->{'frenchspacing'} and $frenchspacing
- and $paragraph->{'end_sentence'} and $paragraph->{'counter'} != 0
- and $paragraph->{'space'} and !defined($paragraph->{'word'})) {
- $paragraph->{'space'} .= ' ' x (2 - length($paragraph->{'space'}));
- print STDERR "SWITCH frenchspacing end sentence space\n"
- if ($paragraph->{'DEBUG'});
- delete $paragraph->{'end_sentence'};
- }
- $paragraph->{'frenchspacing'} = $frenchspacing
- if defined($frenchspacing);
- # begin a word, to have something even if empty
- if ($space_protection) {
- _add_next($paragraph, '');
- }
- return '';
-}
-
-# Wrap $TEXT, returning the wrapped text, taking into account the current
state
-# of $PARAGRAPH. Any end of sentence punctuation in $TEXT that should be
-# allowed to end a sentence but which would otherwise be preceded by an
-# upper-case letter should instead by preceded by a backspace character.
-sub add_text($$)
-{
- my $paragraph = shift;
- my $text = shift;
- $paragraph->{'end_line_count'} = 0;
- my $result = '';
-
- my $protect_spaces_flag = $paragraph->{'protect_spaces'};
-
- my @segments = split
-/([^\S\x{202f}\x{00a0}]+)|(\p{InFullwidth})|((?:[^\s\p{InFullwidth}]|[\x{202f}\x{00a0}])+)/,
- $text;
-
- # Check now if a newline exists anywhere in the string to
- # try to eliminate regex checks later.
- my $newline_possible_flag = ($text =~ /\n/);
-
- my $debug_flag = $paragraph->{'DEBUG'};
- while (@segments) {
- # $empty_segment should be an empty string; the other variables
- # here were recognized as field separators by splice.
- my ($empty_segment, $spaces, $fullwidth_segment, $added_word)
- = splice (@segments, 0, 4);
-
- if ($debug_flag) {
- my $word = 'UNDEF';
- $word = $paragraph->{'word'} if (defined($paragraph->{'word'}));
- print STDERR "p ($paragraph->{'counter'}+$paragraph->{'word_counter'}) s
`"._print_escaped_spaces($paragraph->{'space'})."', w `$word'\n";
- #print STDERR "TEXT: "._print_escaped_spaces($text)."|\n"
- }
- # \x{202f}\x{00a0} are non breaking spaces
- if (defined $spaces) {
- print STDERR "SPACES($paragraph->{'counter'})
`"._print_escaped_spaces($spaces)."'\n" if $debug_flag;
- if ($protect_spaces_flag) {
- $paragraph->{'word'} .= $spaces;
- $paragraph->{'last_char'} = substr($spaces, -1);
- $paragraph->{'word_counter'} += length($spaces);
- $paragraph->{'word'} =~ s/\n/ /g;
-
- # The $paragraph->{'counter'} != 0 is here to avoid having an
- # additional line output when the text is longer than the max.
- if ($paragraph->{'counter'} != 0 and
- $paragraph->{'counter'} + $paragraph->{'word_counter'} +
- length($paragraph->{'space'}) > $paragraph->{'max'}) {
- $result .= _cut_line($paragraph);
- }
- } else {
- $result .= _add_pending_word($paragraph);
- if ($paragraph->{'counter'} != 0) {
- if ($paragraph->{'end_sentence'}
- and $paragraph->{'end_sentence'} > 0
- and !$paragraph->{'frenchspacing'}) {
- if (length($paragraph->{'space'}) >= 1 or length($spaces) > 1) {
- # more than one space, we can make sure tht there are only
- # 2 spaces
- my $all_spaces = substr($paragraph->{'space'} . $spaces, 0, 2);
- $all_spaces =~ s/[\n\r]/ /g;
- $all_spaces .= ' ' x (2 - length($all_spaces));
- $paragraph->{'space'} = $all_spaces;
- delete $paragraph->{'end_sentence'};
- } else {
- # if there is only one space, we let it accumulate
- my $new_space = $spaces;
- $new_space =~ s/^[\n\r]/ /;
- $paragraph->{'space'} = $new_space;
- }
- } else {
- $paragraph->{'space'} = substr($spaces, 0, 1);
- if ($paragraph->{'space'} eq "\n"
- or $paragraph->{'space'} eq "\r") {
- $paragraph->{'space'} = " ";
- }
- }
- }
- }
- #print STDERR "delete END_SENTENCE($paragraph->{'end_sentence'}):
spaces\n"
- # if (defined($paragraph->{'end_sentence'}) and $paragraph->{'DEBUG'});
- #delete $paragraph->{'end_sentence'};
- if ($paragraph->{'counter'} + length($paragraph->{'space'})
- > $paragraph->{'max'}) {
- $result .= _cut_line($paragraph);
- }
- if ($newline_possible_flag
- and $paragraph->{'keep_end_lines'} and $spaces =~ /\n/) {
- $result .= _end_line($paragraph);
- }
- } elsif (defined $added_word) {
- # Whether a sentence end is permitted in spite of a preceding
- # upper case letter.
- my $disinhibit = 0;
-
- # Reverse the insertion of the control character in Plaintext.pm.
- if ($added_word =~ s/\x08(?=[$end_sentence_character]
- [$after_punctuation_characters]*$)//x) {
- $disinhibit = 1;
- }
-
- $result .= _add_next($paragraph, $added_word, undef,
- !$newline_possible_flag);
-
- # Check if it is considered as an end of sentence. There are two things
- # to check: one, that we have a ., ! or ?; and second, that it is not
- # preceded by an upper-case letter (ignoring some punctuation)
- if (defined($paragraph->{'end_sentence'})
- and $added_word =~ /^[$after_punctuation_characters]*$/o) {
- # do nothing in the case of a continuation of
after_punctuation_characters
- } elsif (($disinhibit
- or !$paragraph->{'last_char'}
- or $paragraph->{'last_char'} !~ /[[:upper:]]/)
- and $added_word =~ /[$end_sentence_character]
- [$after_punctuation_characters]*$/x) {
- if ($paragraph->{'frenchspacing'}) {
- $paragraph->{'end_sentence'} = -1;
- } else {
- $paragraph->{'end_sentence'} = 1;
- }
- print STDERR "END_SENTENCE\n" if ($paragraph->{'DEBUG'});
- } else {
- delete $paragraph->{'end_sentence'};
- print STDERR "delete END_SENTENCE($paragraph->{'end_sentence'}):
text\n"
- if (defined($paragraph->{'end_sentence'}) and $paragraph->{'DEBUG'});
- }
- } elsif (defined $fullwidth_segment) {
- print STDERR "EAST_ASIAN\n" if ($paragraph->{'DEBUG'});
- if (!defined($paragraph->{'word'})) {
- $paragraph->{'word'} = '';
- }
- $paragraph->{'word'} .= $fullwidth_segment;
- $paragraph->{'last_char'} = $fullwidth_segment;
- $paragraph->{'word_counter'} += 2;
- if ($paragraph->{'counter'} != 0 and
- $paragraph->{'counter'} + $paragraph->{'word_counter'}
- > $paragraph->{'max'}) {
- $result .= _cut_line($paragraph);
- }
- $result .= _add_pending_word($paragraph);
- delete $paragraph->{'end_sentence'};
- $paragraph->{'space'} = '';
- }
- }
- return $result;
-}
-
-# for debug
-sub _print_escaped_spaces($)
-{
- my $spaces = shift;
- my $result = '';
- foreach my $pos (0 .. length($spaces)-1) {
- my $char = substr($spaces, $pos, 1);
- if ($char eq ' ') {
- $result .= $char;
- } elsif ($char =~ /[\f\n]/) {
- $char =~ s/\f/\\f/;
- $char =~ s/\n/\\n/;
- $result .= $char;
- } elsif ($char =~ /\s/) {
- if (ord($char) <= hex(0xFFFF)) {
- $result .= '\x'.sprintf("%04x",ord($char));
- } else {
- $result .= '\x'.sprintf("%06x",ord($char));
- }
- } else {
- $result .= $char;
- }
- }
- return $result;
-}
-
-1;
Copied: trunk/tp/Texinfo/Convert/Paragraph.pm (from rev 6580,
trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm)
===================================================================
--- trunk/tp/Texinfo/Convert/Paragraph.pm (rev 0)
+++ trunk/tp/Texinfo/Convert/Paragraph.pm 2015-10-19 18:52:32 UTC (rev
6712)
@@ -0,0 +1,254 @@
+# Copyright 2014, 2015 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/>.
+
+package Texinfo::Convert::Paragraph;
+
+use DynaLoader;
+
+# same as texi2any.pl, although I don't know what the real requirement
+# is for this module.
+use 5.00405;
+use strict;
+use warnings;
+
+require Exporter;
+
+our @ISA = qw(Exporter DynaLoader);
+
+# 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 XSParagraph ':all';
+# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
+# will save memory.
+our %EXPORT_TAGS = ( 'all' => [ qw(
+ add_next
+ add_text
+
+) ] );
+
+our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
+
+our @EXPORT = qw(
+
+);
+
+BEGIN {
+
+my $module = "Texinfo::Convert::XSParagraph::XSParagraph::";
+our $VERSION = '6.0dev';
+# Module interface number, to be changed when the XS interface changes.
+# The value used for the .xs file compilation is set in configure.ac.
+# Both should correspond, but it should be manually changed here to make
+# sure that a changed interface has not been missed.
+my $XSPARAGRAPH_INTERFACE_VERSION = "1";
+
+# Possible values for TEXINFO_XS environmental variable:
+#
+# TEXINFO_XS=omit # don't try loading xs at all
+# TEXINFO_XS=default # try xs, libtool and then perl paths, silent
fallback
+# TEXINFO_XS=libtool # try xs, libtool only, silent fallback
+# TEXINFO_XS=standalone # try xs, perl paths only, silent fallback
+# TEXINFO_XS=warn # try xs, libtool and then perl paths, warn on
failure
+# TEXINFO_XS=required # abort if not loadable, no fallback
+# TEXINFO_XS=debug # voluminuous debugging
+#
+# Other values are treated at the moment as 'default'.
+
+my $TEXINFO_XS = $ENV{'TEXINFO_XS'};
+if (!defined($TEXINFO_XS)) {
+ $TEXINFO_XS = '';
+}
+
+if ($TEXINFO_XS eq 'omit') {
+ # Don't try to use the XS module
+ goto FALLBACK;
+}
+
+# For verbose information about what's being done
+sub _debug($) {
+ if ($TEXINFO_XS eq 'debug') {
+ my $msg = shift;
+ warn $msg . "\n";
+ }
+}
+
+# For messages to say that XS module couldn't be loaded
+sub _fatal($) {
+ if ($TEXINFO_XS eq 'debug'
+ or $TEXINFO_XS eq 'required'
+ or $TEXINFO_XS eq 'warn') {
+ my $msg = shift;
+ warn $msg . "\n";
+ }
+}
+
+# We look for the .la and .so files in @INC because this allows us to override
+# which modules are used using -I flags to "perl".
+sub _find_file($) {
+ my $file = shift;
+ for my $dir (@INC) {
+ _debug "checking $dir/$file";
+ if (-f "$dir/$file") {
+ _debug "found $dir/$file";
+ return ($dir, "$dir/$file");
+ }
+ }
+ return undef;
+}
+
+our $disable_XS;
+if ($disable_XS) {
+ _fatal "use of XS modules was disabled when Texinfo was built";
+ goto FALLBACK;
+}
+
+my ($libtool_dir, $libtool_archive);
+if ($TEXINFO_XS ne 'stand-alone') {
+ ($libtool_dir, $libtool_archive) = _find_file("XSParagraph.la");
+ if (!$libtool_archive) {
+ if ($TEXINFO_XS eq 'libtool') {
+ _fatal "XSParagraph: couldn't find Libtool archive file";
+ goto FALLBACK;
+ }
+ _debug "XSParagraph: couldn't find Libtool archive file";
+ }
+}
+
+my $dlname = undef;
+my $dlpath = undef;
+
+# Try perl paths
+if (!$libtool_archive) {
+ my @modparts = split(/::/,$module);
+ my $dlname = $modparts[-1];
+ my $modpname = join('/',@modparts);
+ # the directories with -L prepended setup directories to
+ # be in the search path. Then $dlname is prepended as it is
+ # the name really searched for.
+ $dlpath = DynaLoader::dl_findfile(map("-L$_/auto/$modpname", @INC), $dlname);
+ if (!$dlpath) {
+ _fatal "XSParagraph: couldn't find $module";
+ goto FALLBACK;
+ }
+ goto LOAD;
+}
+
+my $fh;
+open $fh, $libtool_archive;
+if (!$fh) {
+ _fatal "XSParagraph: couldn't open Libtool archive file";
+ goto FALLBACK;
+}
+
+# Look for the line in XSParagraph.la giving the name of the loadable object.
+while (my $line = <$fh>) {
+ if ($line =~ /^\s*dlname\s*=\s*'([^']+)'\s$/) {
+ $dlname = $1;
+ last;
+ }
+}
+if (!$dlname) {
+ _fatal "XSParagraph: couldn't find name of shared object";
+ goto FALLBACK;
+}
+
+# The *.so file is under .libs in the source directory.
+push @DynaLoader::dl_library_path, $libtool_dir;
+push @DynaLoader::dl_library_path, "$libtool_dir/.libs";
+
+$dlpath = DynaLoader::dl_findfile($dlname);
+if (!$dlpath) {
+ _fatal "XSParagraph: couldn't find $dlname";
+ goto FALLBACK;
+}
+
+LOAD:
+
+#print STDERR "loadable object is at $dlpath\n";
+
+# Following steps under "bootstrap" in "man DynaLoader".
+#bootstrap XSParagraph $VERSION;
+
+# TODO: Execute blib/arch/auto/XSParagraph/XSParagraph.bs ?
+# That file is empty.
+
+#my $flags = dl_load_flags $module; # This is 0 in DynaLoader
+my $flags = 0;
+my $libref = DynaLoader::dl_load_file($dlpath, $flags);
+if (!$libref) {
+ _fatal "XSParagraph: couldn't load file $dlpath";
+ goto FALLBACK;
+}
+my @undefined_symbols = DynaLoader::dl_undef_symbols();
+if ($#undefined_symbols+1 != 0) {
+ _fatal "XSParagraph: still have undefined symbols after dl_load_file";
+}
+my $bootname = "boot_$module";
+$bootname =~ s/:/_/g;
+my $symref = DynaLoader::dl_find_symbol($libref, $bootname);
+if (!$symref) {
+ _fatal "XSParagraph: couldn't find boot_$module symbol";
+ goto FALLBACK;
+}
+my $boot_fn = DynaLoader::dl_install_xsub("${module}::bootstrap",
+ $symref, $dlname);
+
+if (!$boot_fn) {
+ _fatal "XSParagraph: couldn't bootstrap";
+ goto FALLBACK;
+}
+
+push @DynaLoader::dl_shared_objects, $dlpath; # record files loaded
+
+# This is the module bootstrap function, which causes all the other
+# functions (XSUB's) provided by the module to become available to
+# be called from Perl code.
+&$boot_fn($module, $XSPARAGRAPH_INTERFACE_VERSION);
+
+*Texinfo::Convert::Paragraph = *Texinfo::Convert::XSParagraph::XSParagraph::;
+if (!Texinfo::Convert::Paragraph::init ()) {
+ _fatal "XSParagraph: error initializing";
+ goto FALLBACK;
+}
+goto DONTFALLBACK;
+
+FALLBACK:
+ if ($TEXINFO_XS eq 'required') {
+ die "unset the TEXINFO_XS environmental variable to use the "
+ ."pure Perl modules\n";
+ } elsif ($TEXINFO_XS eq 'warn' or $TEXINFO_XS eq 'debug') {
+ warn "falling back to pure Perl modules\n";
+ }
+ # Fall back to using the Perl code.
+ require Texinfo::Convert::ParagraphNonXS;
+ *Texinfo::Convert::Paragraph:: = *Texinfo::Convert::ParagraphNonXS::;
+DONTFALLBACK: ;
+} # end BEGIN
+
+
+# Preloaded methods go here.
+
+#########################################################################
+
+# Used for debugging. Not implemented.
+sub dump($)
+{
+ return "\n";
+}
+
+1;
+__END__
Copied: trunk/tp/Texinfo/Convert/ParagraphNonXS.pm (from rev 6578,
trunk/tp/Texinfo/Convert/Paragraph.pm)
===================================================================
--- trunk/tp/Texinfo/Convert/ParagraphNonXS.pm (rev 0)
+++ trunk/tp/Texinfo/Convert/ParagraphNonXS.pm 2015-10-19 18:52:32 UTC (rev
6712)
@@ -0,0 +1,478 @@
+# Paragraph.pm: handle paragraph text.
+#
+# Copyright 2010, 2011, 2012, 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 has nothing Texinfo specific. In contrast with existing
+# modules Text::Wrap, Text::Format, it keeps a state of the paragraph
+# and waits for text to be fed into it.
+
+package Texinfo::Convert::ParagraphNonXS;
+
+use 5.006;
+use strict;
+
+use Unicode::EastAsianWidth;
+use Carp qw(cluck);
+
+# initialize a paragraph object.
+sub new($;$)
+{
+ my $class = shift;
+ my $conf = shift;
+ my $self = {'max' => 72, 'indent_length' => 0, 'counter' => 0,
+ 'word_counter' => 0, 'space' => '', 'frenchspacing' => 0,
+ 'lines_counter' => 0, 'end_line_count' => 0};
+ if (defined($conf)) {
+ foreach my $key (keys(%$conf)) {
+ $self->{$key} = $conf->{$key};
+ }
+ }
+ bless $self, $class;
+}
+
+# for debugging
+sub dump($)
+{
+ my $self = shift;
+ my $word = 'UNDEF';
+ if (defined($self->{'word'})) {
+ $word = $self->{'word'};
+ }
+ my $end_sentence = 'UNDEF';
+ $end_sentence = $self->{'end_sentence'} if
(defined($self->{'end_sentence'}));
+ print STDERR "para ($self->{'counter'}+$self->{'word_counter'}) word: $word,
space `$self->{'space'}' end_sentence: $end_sentence\n";
+}
+
+sub _cut_line($)
+{
+ my $paragraph = shift;
+ return '' if ($paragraph->{'ignore_columns'});
+ return _end_line($paragraph);
+}
+
+sub end_line_count($)
+{
+ my $paragraph = shift;
+ return $paragraph->{'end_line_count'};
+}
+
+sub end_line($)
+{
+ my $paragraph = shift;
+ $paragraph->{'end_line_count'} = 0;
+ return _end_line($paragraph);
+}
+
+# end a line.
+sub _end_line($)
+{
+ my $paragraph = shift;
+ $paragraph->{'counter'} = 0;
+ $paragraph->{'space'} = '';
+ if (defined($paragraph->{'indent_length_next'})) {
+ $paragraph->{'indent_length'} = $paragraph->{'indent_length_next'};
+ delete $paragraph->{'indent_length_next'};
+ }
+ $paragraph->{'lines_counter'}++;
+ $paragraph->{'end_line_count'}++;
+ print STDERR "END_LINE\n" if ($paragraph->{'DEBUG'});
+ return "\n";
+}
+
+sub get_pending($)
+{
+ my $paragraph = shift;
+ my $result = '';
+ if ($paragraph->{'space'}) {
+ $result .= $paragraph->{'space'};
+ }
+ if (defined($paragraph->{'word'})) {
+ $result .= $paragraph->{'word'};
+ }
+ return $result;
+}
+
+sub add_pending_word($;$)
+{
+ my $paragraph = shift;
+ my $add_spaces = shift;
+ $paragraph->{'end_line_count'} = 0;
+ return _add_pending_word($paragraph, $add_spaces);
+}
+
+# put a pending word and spaces in the result string.
+sub _add_pending_word($;$)
+{
+ my $paragraph = shift;
+ my $add_spaces = shift;
+ my $result = '';
+
+ if (defined($paragraph->{'word'}) or $add_spaces) {
+ if ($paragraph->{'indent_length'} > $paragraph->{'counter'}) {
+ $result .= ' ' x ($paragraph->{'indent_length'} -
$paragraph->{'counter'});
+ $paragraph->{'counter'} = $paragraph->{'indent_length'};
+ print STDERR
"INDENT($paragraph->{'counter'}+$paragraph->{'word_counter'})\n"
+ if ($paragraph->{'DEBUG'});
+ } elsif ($paragraph->{'space'}) {
+ $result .= $paragraph->{'space'};
+ $paragraph->{'counter'} += length($paragraph->{'space'});
+ print STDERR
"ADD_SPACES($paragraph->{'counter'}+$paragraph->{'word_counter'})\n"
+ if ($paragraph->{'DEBUG'});
+
+ }
+ if (defined($paragraph->{'word'})) {
+ $result .= $paragraph->{'word'};
+ $paragraph->{'counter'} += $paragraph->{'word_counter'};
+ print STDERR
"ADD_WORD[$paragraph->{'word'}]+$paragraph->{'word_counter'}
($paragraph->{'counter'})\n"
+ if ($paragraph->{'DEBUG'});
+ $paragraph->{'word'} = undef;
+ $paragraph->{'last_char'} = undef;
+ $paragraph->{'word_counter'} = 0;
+ }
+ $paragraph->{'space'} = '';
+ }
+ return $result;
+}
+
+# end a paragraph
+sub end($)
+{
+ my $paragraph = shift;
+ $paragraph->{'end_line_count'} = 0;
+ print STDERR "PARA END\n" if ($paragraph->{'DEBUG'});
+ my $result = _add_pending_word($paragraph);
+ if ($paragraph->{'counter'} != 0) {
+ $result .= "\n";
+ $paragraph->{'lines_counter'}++;
+ $paragraph->{'end_line_count'}++;
+ }
+ return $result;
+}
+
+my $end_sentence_character = quotemeta('.?!');
+my $after_punctuation_characters = quotemeta('"\')]');
+
+# Add $WORD to paragraph, returning the text to be added to the paragraph.
+# Any end of sentence punctuation in $WORD that should be allowed to end a
+# sentence but which would otherwise be preceded by an upper-case letter
should
+# instead by preceded by a backspace character.
+sub add_next($;$$)
+{
+ my $paragraph = shift;
+ my $word = shift;
+ my $transparent = shift;
+ $paragraph->{'end_line_count'} = 0;
+ return _add_next($paragraph, $word, $transparent);
+}
+
+# add a word and/or end of sentence.
+sub _add_next($;$$$)
+{
+ my $paragraph = shift;
+ my $word = shift;
+ my $transparent = shift;
+ my $newlines_impossible = shift;
+ my $result = '';
+
+ if (defined($word)) {
+ my $disinhibit = 0;
+ # Reverse the insertion of the control character in Plaintext.pm.
+ if ($word =~ s/\x08$//) {
+ $disinhibit = 1;
+ }
+ if (!defined($paragraph->{'word'})) {
+ $paragraph->{'word'} = '';
+ $paragraph->{'last_char'} = '';
+ if ($paragraph->{'end_sentence'}
+ and $paragraph->{'end_sentence'} > 0
+ and !$paragraph->{'frenchspacing'}
+ and $paragraph->{'counter'} != 0 and $paragraph->{'space'}) {
+ # do not to double space if there are leading spaces in word
+ if ($word !~ /^\s/) {
+ #$paragraph->{'space'} = ' ';
+ $paragraph->{'space'} .= ' ' x (2 - length($paragraph->{'space'}));
+ }
+ delete $paragraph->{'end_sentence'};
+ }
+ }
+
+ $paragraph->{'word'} .= $word;
+
+ if (!$transparent) {
+ if ($disinhibit) {
+ $paragraph->{'last_char'} = 'a';
+ } elsif ($word =~
+ /([^$end_sentence_character$after_punctuation_characters])
+ [$end_sentence_character$after_punctuation_characters]*$/x) {
+ # Save the last character in $word before punctuation
+ $paragraph->{'last_char'} = $1;
+ }
+ }
+
+ if (!$newlines_impossible and $word =~ /\n/) {
+ $result .= $paragraph->{'space'};
+ $paragraph->{'space'} = '';
+ $result .= $paragraph->{'word'};
+ _end_line($paragraph);
+ $paragraph->{'word_counter'} = 0;
+ $paragraph->{'word'} = undef;
+ $paragraph->{'last_char'} = undef;
+ } else {
+ $paragraph->{'word_counter'} += length($word);
+ }
+ if ($paragraph->{'DEBUG'}) {
+ my $para_word = 'UNDEF';;
+ if (defined($paragraph->{'word'})) {
+ $para_word = $paragraph->{'word'};
+ }
+ print STDERR "WORD+ $word -> $para_word\n";
+ }
+ # The $paragraph->{'counter'} != 0 is here to avoid having an
+ # additional line output when the text is longer than the max.
+ if ($paragraph->{'counter'} != 0 and
+ $paragraph->{'counter'} + $paragraph->{'word_counter'} +
+ length($paragraph->{'space'}) > $paragraph->{'max'}) {
+ $result .= _cut_line($paragraph);
+ }
+ }
+ return $result;
+}
+
+sub remove_end_sentence($)
+{
+ my $paragraph = shift;
+ $paragraph->{'end_sentence'} = 0;
+}
+
+sub add_end_sentence($;$) {
+ my $paragraph = shift;
+ my $value = shift;
+ $paragraph->{'end_sentence'} = $value;
+}
+
+sub allow_end_sentence($)
+{
+ my $paragraph = shift;
+ printf STDERR "ALLOW END SENTENCE\n" if $paragraph->{'DEBUG'};
+ $paragraph->{'last_char'} = 'a'; # lower-case
+}
+
+sub set_space_protection($$;$$$)
+{
+ my $paragraph = shift;
+ my $space_protection = shift;
+ my $ignore_columns = shift;
+ my $keep_end_lines = shift;
+ my $frenchspacing = shift;
+ $paragraph->{'protect_spaces'} = $space_protection
+ if defined($space_protection);
+ $paragraph->{'ignore_columns'} = $ignore_columns
+ if defined($ignore_columns);
+ $paragraph->{'keep_end_lines'} = $keep_end_lines
+ if defined($keep_end_lines);
+ if (!$paragraph->{'frenchspacing'} and $frenchspacing
+ and $paragraph->{'end_sentence'} and $paragraph->{'counter'} != 0
+ and $paragraph->{'space'} and !defined($paragraph->{'word'})) {
+ $paragraph->{'space'} .= ' ' x (2 - length($paragraph->{'space'}));
+ print STDERR "SWITCH frenchspacing end sentence space\n"
+ if ($paragraph->{'DEBUG'});
+ delete $paragraph->{'end_sentence'};
+ }
+ $paragraph->{'frenchspacing'} = $frenchspacing
+ if defined($frenchspacing);
+ # begin a word, to have something even if empty
+ if ($space_protection) {
+ _add_next($paragraph, '');
+ }
+ return '';
+}
+
+# Wrap $TEXT, returning the wrapped text, taking into account the current
state
+# of $PARAGRAPH. Any end of sentence punctuation in $TEXT that should be
+# allowed to end a sentence but which would otherwise be preceded by an
+# upper-case letter should instead by preceded by a backspace character.
+sub add_text($$)
+{
+ my $paragraph = shift;
+ my $text = shift;
+ $paragraph->{'end_line_count'} = 0;
+ my $result = '';
+
+ my $protect_spaces_flag = $paragraph->{'protect_spaces'};
+
+ my @segments = split
+/([^\S\x{202f}\x{00a0}]+)|(\p{InFullwidth})|((?:[^\s\p{InFullwidth}]|[\x{202f}\x{00a0}])+)/,
+ $text;
+
+ # Check now if a newline exists anywhere in the string to
+ # try to eliminate regex checks later.
+ my $newline_possible_flag = ($text =~ /\n/);
+
+ my $debug_flag = $paragraph->{'DEBUG'};
+ while (@segments) {
+ # $empty_segment should be an empty string; the other variables
+ # here were recognized as field separators by splice.
+ my ($empty_segment, $spaces, $fullwidth_segment, $added_word)
+ = splice (@segments, 0, 4);
+
+ if ($debug_flag) {
+ my $word = 'UNDEF';
+ $word = $paragraph->{'word'} if (defined($paragraph->{'word'}));
+ print STDERR "p ($paragraph->{'counter'}+$paragraph->{'word_counter'}) s
`"._print_escaped_spaces($paragraph->{'space'})."', w `$word'\n";
+ #print STDERR "TEXT: "._print_escaped_spaces($text)."|\n"
+ }
+ # \x{202f}\x{00a0} are non breaking spaces
+ if (defined $spaces) {
+ print STDERR "SPACES($paragraph->{'counter'})
`"._print_escaped_spaces($spaces)."'\n" if $debug_flag;
+ if ($protect_spaces_flag) {
+ $paragraph->{'word'} .= $spaces;
+ $paragraph->{'last_char'} = substr($spaces, -1);
+ $paragraph->{'word_counter'} += length($spaces);
+ $paragraph->{'word'} =~ s/\n/ /g;
+
+ # The $paragraph->{'counter'} != 0 is here to avoid having an
+ # additional line output when the text is longer than the max.
+ if ($paragraph->{'counter'} != 0 and
+ $paragraph->{'counter'} + $paragraph->{'word_counter'} +
+ length($paragraph->{'space'}) > $paragraph->{'max'}) {
+ $result .= _cut_line($paragraph);
+ }
+ } else {
+ $result .= _add_pending_word($paragraph);
+ if ($paragraph->{'counter'} != 0) {
+ if ($paragraph->{'end_sentence'}
+ and $paragraph->{'end_sentence'} > 0
+ and !$paragraph->{'frenchspacing'}) {
+ if (length($paragraph->{'space'}) >= 1 or length($spaces) > 1) {
+ # more than one space, we can make sure tht there are only
+ # 2 spaces
+ my $all_spaces = substr($paragraph->{'space'} . $spaces, 0, 2);
+ $all_spaces =~ s/[\n\r]/ /g;
+ $all_spaces .= ' ' x (2 - length($all_spaces));
+ $paragraph->{'space'} = $all_spaces;
+ delete $paragraph->{'end_sentence'};
+ } else {
+ # if there is only one space, we let it accumulate
+ my $new_space = $spaces;
+ $new_space =~ s/^[\n\r]/ /;
+ $paragraph->{'space'} = $new_space;
+ }
+ } else {
+ $paragraph->{'space'} = substr($spaces, 0, 1);
+ if ($paragraph->{'space'} eq "\n"
+ or $paragraph->{'space'} eq "\r") {
+ $paragraph->{'space'} = " ";
+ }
+ }
+ }
+ }
+ #print STDERR "delete END_SENTENCE($paragraph->{'end_sentence'}):
spaces\n"
+ # if (defined($paragraph->{'end_sentence'}) and $paragraph->{'DEBUG'});
+ #delete $paragraph->{'end_sentence'};
+ if ($paragraph->{'counter'} + length($paragraph->{'space'})
+ > $paragraph->{'max'}) {
+ $result .= _cut_line($paragraph);
+ }
+ if ($newline_possible_flag
+ and $paragraph->{'keep_end_lines'} and $spaces =~ /\n/) {
+ $result .= _end_line($paragraph);
+ }
+ } elsif (defined $added_word) {
+ # Whether a sentence end is permitted in spite of a preceding
+ # upper case letter.
+ my $disinhibit = 0;
+
+ # Reverse the insertion of the control character in Plaintext.pm.
+ if ($added_word =~ s/\x08(?=[$end_sentence_character]
+ [$after_punctuation_characters]*$)//x) {
+ $disinhibit = 1;
+ }
+
+ $result .= _add_next($paragraph, $added_word, undef,
+ !$newline_possible_flag);
+
+ # Check if it is considered as an end of sentence. There are two things
+ # to check: one, that we have a ., ! or ?; and second, that it is not
+ # preceded by an upper-case letter (ignoring some punctuation)
+ if (defined($paragraph->{'end_sentence'})
+ and $added_word =~ /^[$after_punctuation_characters]*$/o) {
+ # do nothing in the case of a continuation of
after_punctuation_characters
+ } elsif (($disinhibit
+ or !$paragraph->{'last_char'}
+ or $paragraph->{'last_char'} !~ /[[:upper:]]/)
+ and $added_word =~ /[$end_sentence_character]
+ [$after_punctuation_characters]*$/x) {
+ if ($paragraph->{'frenchspacing'}) {
+ $paragraph->{'end_sentence'} = -1;
+ } else {
+ $paragraph->{'end_sentence'} = 1;
+ }
+ print STDERR "END_SENTENCE\n" if ($paragraph->{'DEBUG'});
+ } else {
+ delete $paragraph->{'end_sentence'};
+ print STDERR "delete END_SENTENCE($paragraph->{'end_sentence'}):
text\n"
+ if (defined($paragraph->{'end_sentence'}) and $paragraph->{'DEBUG'});
+ }
+ } elsif (defined $fullwidth_segment) {
+ print STDERR "EAST_ASIAN\n" if ($paragraph->{'DEBUG'});
+ if (!defined($paragraph->{'word'})) {
+ $paragraph->{'word'} = '';
+ }
+ $paragraph->{'word'} .= $fullwidth_segment;
+ $paragraph->{'last_char'} = $fullwidth_segment;
+ $paragraph->{'word_counter'} += 2;
+ if ($paragraph->{'counter'} != 0 and
+ $paragraph->{'counter'} + $paragraph->{'word_counter'}
+ > $paragraph->{'max'}) {
+ $result .= _cut_line($paragraph);
+ }
+ $result .= _add_pending_word($paragraph);
+ delete $paragraph->{'end_sentence'};
+ $paragraph->{'space'} = '';
+ }
+ }
+ return $result;
+}
+
+# for debug
+sub _print_escaped_spaces($)
+{
+ my $spaces = shift;
+ my $result = '';
+ foreach my $pos (0 .. length($spaces)-1) {
+ my $char = substr($spaces, $pos, 1);
+ if ($char eq ' ') {
+ $result .= $char;
+ } elsif ($char =~ /[\f\n]/) {
+ $char =~ s/\f/\\f/;
+ $char =~ s/\n/\\n/;
+ $result .= $char;
+ } elsif ($char =~ /\s/) {
+ if (ord($char) <= hex(0xFFFF)) {
+ $result .= '\x'.sprintf("%04x",ord($char));
+ } else {
+ $result .= '\x'.sprintf("%06x",ord($char));
+ }
+ } else {
+ $result .= $char;
+ }
+ }
+ return $result;
+}
+
+1;
Modified: trunk/tp/Texinfo/Convert/Plaintext.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Plaintext.pm 2015-10-19 18:17:21 UTC (rev
6711)
+++ trunk/tp/Texinfo/Convert/Plaintext.pm 2015-10-19 18:52:32 UTC (rev
6712)
@@ -26,7 +26,7 @@
use Texinfo::Convert::Converter;
use Texinfo::Common;
use Texinfo::Convert::Texinfo;
-use Texinfo::Convert::XSParagraph::XSParagraph;
+use Texinfo::Convert::Paragraph;
use Texinfo::Convert::Text;
use Texinfo::Convert::Line;
use Texinfo::Convert::UnFilled;
@@ -660,9 +660,7 @@
if ($type eq 'line') {
$container = Texinfo::Convert::Line->new($container_conf);
} elsif ($type eq 'paragraph') {
- #$container = Texinfo::Convert::Paragraph->new($container_conf);
- $container =
- Texinfo::Convert::XSParagraph::XSParagraph->new($container_conf);
+ $container = Texinfo::Convert::Paragraph->new($container_conf);
} elsif ($type eq 'unfilled') {
$container = Texinfo::Convert::UnFilled->new($container_conf);
} else {
Modified: trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am 2015-10-19 18:17:21 UTC
(rev 6711)
+++ trunk/tp/Texinfo/Convert/XSParagraph/Makefile.am 2015-10-19 18:52:32 UTC
(rev 6712)
@@ -39,8 +39,6 @@
modulesdir = $(pkgdatadir)/Texinfo/Convert/XSParagraph
xsdir = $(pkglibexecdir)
-dist_modules_DATA = XSParagraph.pm
-
PERL_INC = $(PERL_CONF_archlibexp)/CORE
XSUBPPARGS = -typemap $(PERL_CONF_privlibexp)/ExtUtils/typemap
Deleted: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-10-19 18:17:21 UTC
(rev 6711)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-10-19 18:52:32 UTC
(rev 6712)
@@ -1,254 +0,0 @@
-# Copyright 2014, 2015 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/>.
-
-package Texinfo::Convert::XSParagraph::XSParagraph;
-
-use DynaLoader;
-
-# same as texi2any.pl, although I don't know what the real requirement
-# is for this module.
-use 5.00405;
-use strict;
-use warnings;
-
-require Exporter;
-
-our @ISA = qw(Exporter DynaLoader);
-
-# 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 XSParagraph ':all';
-# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
-# will save memory.
-our %EXPORT_TAGS = ( 'all' => [ qw(
- add_next
- add_text
-
-) ] );
-
-our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
-
-our @EXPORT = qw(
-
-);
-
-BEGIN {
-
-my $module = "Texinfo::Convert::XSParagraph::XSParagraph";
-our $VERSION = '6.0dev';
-# Module interface number, to be changed when the XS interface changes.
-# The value used for the .xs file compilation is set in configure.ac.
-# Both should correspond, but it should be manually changed here to make
-# sure that a changed interface has not been missed.
-my $XSPARAGRAPH_INTERFACE_VERSION = "1";
-
-# Possible values for TEXINFO_XS environmental variable:
-#
-# TEXINFO_XS=omit # don't try loading xs at all
-# TEXINFO_XS=default # try xs, libtool and then perl paths, silent
fallback
-# TEXINFO_XS=libtool # try xs, libtool only, silent fallback
-# TEXINFO_XS=standalone # try xs, perl paths only, silent fallback
-# TEXINFO_XS=warn # try xs, libtool and then perl paths, warn on
failure
-# TEXINFO_XS=required # abort if not loadable, no fallback
-# TEXINFO_XS=debug # voluminuous debugging
-#
-# Other values are treated at the moment as 'default'.
-
-my $TEXINFO_XS = $ENV{'TEXINFO_XS'};
-if (!defined($TEXINFO_XS)) {
- $TEXINFO_XS = '';
-}
-
-if ($TEXINFO_XS eq 'omit') {
- # Don't try to use the XS module
- goto FALLBACK;
-}
-
-# For verbose information about what's being done
-sub _debug($) {
- if ($TEXINFO_XS eq 'debug') {
- my $msg = shift;
- warn $msg . "\n";
- }
-}
-
-# For messages to say that XS module couldn't be loaded
-sub _fatal($) {
- if ($TEXINFO_XS eq 'debug'
- or $TEXINFO_XS eq 'required'
- or $TEXINFO_XS eq 'warn') {
- my $msg = shift;
- warn $msg . "\n";
- }
-}
-
-# We look for the .la and .so files in @INC because this allows us to override
-# which modules are used using -I flags to "perl".
-sub _find_file($) {
- my $file = shift;
- for my $dir (@INC) {
- _debug "checking $dir/$file";
- if (-f "$dir/$file") {
- _debug "found $dir/$file";
- return ($dir, "$dir/$file");
- }
- }
- return undef;
-}
-
-our $disable_XS;
-if ($disable_XS) {
- _fatal "use of XS modules was disabled when Texinfo was built";
- goto FALLBACK;
-}
-
-my ($libtool_dir, $libtool_archive);
-if ($TEXINFO_XS ne 'stand-alone') {
- ($libtool_dir, $libtool_archive) = _find_file("XSParagraph.la");
- if (!$libtool_archive) {
- if ($TEXINFO_XS eq 'libtool') {
- _fatal "XSParagraph: couldn't find Libtool archive file";
- goto FALLBACK;
- }
- _debug "XSParagraph: couldn't find Libtool archive file";
- }
-}
-
-my $dlname = undef;
-my $dlpath = undef;
-
-# Try perl paths
-if (!$libtool_archive) {
- my @modparts = split(/::/,$module);
- my $dlname = $modparts[-1];
- my $modpname = join('/',@modparts);
- # the directories with -L prepended setup directories to
- # be in the search path. Then $dlname is prepended as it is
- # the name really searched for.
- $dlpath = DynaLoader::dl_findfile(map("-L$_/auto/$modpname", @INC), $dlname);
- if (!$dlpath) {
- _fatal "XSParagraph: couldn't find $module";
- goto FALLBACK;
- }
- goto LOAD;
-}
-
-my $fh;
-open $fh, $libtool_archive;
-if (!$fh) {
- _fatal "XSParagraph: couldn't open Libtool archive file";
- goto FALLBACK;
-}
-
-# Look for the line in XSParagraph.la giving the name of the loadable object.
-while (my $line = <$fh>) {
- if ($line =~ /^\s*dlname\s*=\s*'([^']+)'\s$/) {
- $dlname = $1;
- last;
- }
-}
-if (!$dlname) {
- _fatal "XSParagraph: couldn't find name of shared object";
- goto FALLBACK;
-}
-
-# The *.so file is under .libs in the source directory.
-push @DynaLoader::dl_library_path, $libtool_dir;
-push @DynaLoader::dl_library_path, "$libtool_dir/.libs";
-
-$dlpath = DynaLoader::dl_findfile($dlname);
-if (!$dlpath) {
- _fatal "XSParagraph: couldn't find $dlname";
- goto FALLBACK;
-}
-
-LOAD:
-
-#print STDERR "loadable object is at $dlpath\n";
-
-# Following steps under "bootstrap" in "man DynaLoader".
-#bootstrap XSParagraph $VERSION;
-
-# TODO: Execute blib/arch/auto/XSParagraph/XSParagraph.bs ?
-# That file is empty.
-
-#my $flags = dl_load_flags $module; # This is 0 in DynaLoader
-my $flags = 0;
-my $libref = DynaLoader::dl_load_file($dlpath, $flags);
-if (!$libref) {
- _fatal "XSParagraph: couldn't load file $dlpath";
- goto FALLBACK;
-}
-my @undefined_symbols = DynaLoader::dl_undef_symbols();
-if ($#undefined_symbols+1 != 0) {
- _fatal "XSParagraph: still have undefined symbols after dl_load_file";
-}
-my $bootname = "boot_$module";
-$bootname =~ s/:/_/g;
-my $symref = DynaLoader::dl_find_symbol($libref, $bootname);
-if (!$symref) {
- _fatal "XSParagraph: couldn't find boot_$module symbol";
- goto FALLBACK;
-}
-my $boot_fn = DynaLoader::dl_install_xsub("${module}::bootstrap",
- $symref, $dlname);
-
-if (!$boot_fn) {
- _fatal "XSParagraph: couldn't bootstrap";
- goto FALLBACK;
-}
-
-push @DynaLoader::dl_shared_objects, $dlpath; # record files loaded
-
-# This is the module bootstrap function, which causes all the other
-# functions (XSUB's) provided by the module to become available to
-# be called from Perl code.
-&$boot_fn($module, $XSPARAGRAPH_INTERFACE_VERSION);
-
-if (!Texinfo::Convert::XSParagraph::XSParagraph::init ()) {
- _fatal "XSParagraph: error initializing";
- goto FALLBACK;
-}
-goto DONTFALLBACK;
-
-FALLBACK:
- if ($TEXINFO_XS eq 'required') {
- die "unset the TEXINFO_XS environmental variable to use the "
- ."pure Perl modules\n";
- } elsif ($TEXINFO_XS eq 'warn' or $TEXINFO_XS eq 'debug') {
- warn "falling back to pure Perl modules\n";
- }
- # Fall back to using the Perl code.
- require Texinfo::Convert::Paragraph;
- *Texinfo::Convert::XSParagraph::XSParagraph::
- = *Texinfo::Convert::Paragraph::;
-DONTFALLBACK: ;
-} # end BEGIN
-
-
-# Preloaded methods go here.
-
-#########################################################################
-
-# Used for debugging. Not implemented.
-sub dump($)
-{
- return "\n";
-}
-
-1;
-__END__
Modified: trunk/tp/t/paragraph.t
===================================================================
--- trunk/tp/t/paragraph.t 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/tp/t/paragraph.t 2015-10-19 18:52:32 UTC (rev 6712)
@@ -21,14 +21,15 @@
}; # end BEGIN
-use Texinfo::Convert::Paragraph;
-use Texinfo::Convert::XSParagraph::XSParagraph;
+use Texinfo::Convert::ParagraphNonXS;
use Texinfo::Convert::Line;
use Texinfo::Convert::UnFilled;
# We do the test for Texinfo::Convert::Paragraph tests twice, once with
# Texinfo::Convert::Paragraph, once with XSParagraph. A few them are only
done
# once, though.
+local *xsmodule = *Texinfo::Convert::Paragraph::;
+*Texinfo::Convert::Paragraph:: = *Texinfo::Convert::ParagraphNonXS::;
my $testing_XSParagraph;
DOITAGAIN:
ok(1, "modules loading"); # If we made it this far, we're ok.
@@ -509,8 +510,8 @@
$result .= $para->end();
is ($para->{'lines_counter'}, 2, 'count lines end paragraph');
- *Texinfo::Convert::Paragraph::
- = *Texinfo::Convert::XSParagraph::XSParagraph::;
+ use Texinfo::Convert::Paragraph;
+ *Texinfo::Convert::Paragraph:: = *xsmodule;
$testing_XSParagraph = 1;
goto DOITAGAIN;
}
Modified: trunk/tp/texi2any.pl
===================================================================
--- trunk/tp/texi2any.pl 2015-10-19 18:17:21 UTC (rev 6711)
+++ trunk/tp/texi2any.pl 2015-10-19 18:52:32 UTC (rev 6712)
@@ -94,7 +94,7 @@
BEGIN {
my $enable_xs = '@enable_xs@';
if ($enable_xs eq 'no') {
- package Texinfo::Convert::XSParagraph::XSParagraph;
+ package Texinfo::Convert::Paragraph;
our $disable_XS;
$disable_XS = 1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6712] load paragraph module as Texinfo::Convert::Paragraph,
Gavin D. Smith <=