[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Parser.pm Texinfo/Convert/Te...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Parser.pm Texinfo/Convert/Te... |
Date: |
Sun, 17 Oct 2010 13:43:43 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/10/17 13:43:42
Modified files:
tp/Texinfo : Parser.pm
tp/Texinfo/Convert: Text.pm
tp/t : test_utils.pl
Added files:
tp/t : 80include.t
tp/t/include : inc_file.texi
tp/t/results/include: simple.pl
Log message:
Handle file inclusion.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.73&r2=1.74
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Text.pm?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/test_utils.pl?cvsroot=texinfo&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/80include.t?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/include/inc_file.texi?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/include/simple.pl?cvsroot=texinfo&rev=1.1
Patches:
Index: Texinfo/Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -b -r1.73 -r1.74
--- Texinfo/Parser.pm 16 Oct 2010 21:35:29 -0000 1.73
+++ Texinfo/Parser.pm 17 Oct 2010 13:43:42 -0000 1.74
@@ -23,6 +23,8 @@
use 5.00405;
use Data::Dumper;
+# to expand file names in @include
+use Texinfo::Convert::Text;
use strict;
require Exporter;
@@ -72,7 +74,8 @@
'indices' => [],
'values' => {},
'macros' => {},
- 'expanded_formats', []
+ 'expanded_formats' => [],
+ 'include_directories' => [ '.' ]
);
my %no_brace_commands; # commands never taking braces
@@ -588,13 +591,13 @@
{
my $self = shift;
my $file_name = shift;
+ my $filehandle = do { local *FH };
# FIXME error message
- local *FILE;
- open (*FILE, $file_name) or return undef;
+ open ($filehandle, $file_name) or return undef;
my $line_nr = 0;
my $line;
my @first_lines;
- while ($line = <FILE>) {
+ while ($line = <$filehandle>) {
$line_nr++;
$line =~ s/\x{7F}.*\s*//;
if ($line =~ /^ *\\input/ or $line =~ /^\s*$/) {
@@ -608,7 +611,7 @@
'file_name' => $file_name, 'macro' => '' }] ],
'name' => $file_name,
'line_nr' => $line_nr,
- 'fh' => \*FILE
+ 'fh' => $filehandle
}], address@hidden);
}
@@ -982,7 +985,8 @@
my $fh = $current->{'fh'};
my $line = <$fh>;
if (defined($line)) {
- $current->{'line_nr'} ++;
+ $line =~ s/\x{7F}.*\s*//;
+ $current->{'line_nr'}++;
return ($line, {'line_nr' => $current->{'line_nr'},
'file_name' => $current->{'name'},
'macro' => ''});
@@ -1345,9 +1349,9 @@
$current = $current->{'parent'};
my $misc_cmd = $current;
my $command = $current->{'cmdname'};
- print STDERR "MISC END address@hidden>{'cmdname'}\n" if ($self->{'debug'});
- if ($self->{'misc_commands'}->{$current->{'cmdname'}}->{'arg'}
- and $self->{'misc_commands'}->{$current->{'cmdname'}}->{'arg'} =~
/^\d$/) {
+ print STDERR "MISC END address@hidden" if ($self->{'debug'});
+ if ($self->{'misc_commands'}->{$command}->{'arg'}
+ and $self->{'misc_commands'}->{$command}->{'arg'} =~ /^\d$/) {
my $args = _parse_line_command_args ($self, $current, $line_nr);
$current->{'special'}->{'misc_args'} = $args if (defined($args));
}
@@ -1386,6 +1390,59 @@
return $current;
}
+sub _end_line_and_include_file ($$$$)
+{
+ my $self = shift;
+ my $current = shift;
+ my $line_nr = shift;
+ my $input = shift;
+
+ my $included_file = 0;
+
+ if ($current->{'type'} and $current->{'type'} eq 'misc_line_arg'
+ and $current->{'parent'}->{'cmdname'}
+ and $current->{'parent'}->{'cmdname'} eq 'include') {
+ my $filename = Texinfo::Convert::Text::convert ($current);
+ chomp($filename);
+ my $file;
+ if ($filename =~ m,^(/|\./|\.\./),) {
+ $file = $filename if (-e $file and -r $file);
+ } else {
+ foreach my $dir (@{$self->{'include_directories'}}) {
+ $file = "$dir/$filename" if (-e "$dir/$filename" and -r
"$dir/$filename");
+ last if (defined($file));
+ }
+ }
+ if (defined($file)) {
+ my $filehandle = do { local *FH };
+ if (open ($filehandle, $file)) {
+ $included_file = 1;
+ print STDERR "Included $file($filehandle)\n" if ($self->{'debug'});
+ $included_file = 1;
+ unshift @$input, {
+ 'name' => $file,
+ 'line_nr' => 1,
+ 'pending' => [],
+ 'fh' => $filehandle };
+ } else {
+ _line_error ($self, sprintf($self->__("address@hidden: Cannot open %s:
%s"),
+ 'include', $filename, $!), $line_nr);
+ }
+ } else {
+ _line_error ($self, sprintf($self->__("address@hidden: Cannot find %s"),
+ 'include', $filename), $line_nr);
+ }
+ }
+ if ($included_file) {
+ # remove completly the include file command
+ $current = $current->{'parent'}->{'parent'};
+ pop @{$current->{'contents'}};
+ } else {
+ $current = _end_line ($self, $current, $line_nr);
+ }
+ return ($current, $included_file);
+}
+
sub _start_empty_line_after_command($$) {
my $line = shift;
my $current = shift;
@@ -1593,12 +1650,16 @@
if ($self->{'debug'});
($line, $line_nr) = _next_text($text, $line_nr);
if (!defined($line)) {
- # end of the document
- $current = _end_line($self, $current, $line_nr);
+ # end of the file
+ my $included_file;
+ ($current, $included_file) =
+ _end_line_and_include_file ($self, $current, $line_nr, $text);
+ if (!$included_file) {
$current = _end_block_command($self, $current, $line_nr);
return $root;
}
}
+ }
# handle user defined macros before anything else since
# their expansion may lead to changes in the line
@@ -2266,7 +2327,9 @@
die "BUG: text remaining (@$text) and `$line'\n" if (scalar(@$text));
}
#print STDERR "END LINE AFTER MERGE END OF LINE: ".
_print_current($current)."\n";
- $current = _end_line($self, $current, $line_nr);
+ my $included_file;
+ ($current, $included_file) =
+ _end_line_and_include_file ($self, $current, $line_nr, $text);
last;
}
}
Index: Texinfo/Convert/Text.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Text.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Texinfo/Convert/Text.pm 17 Oct 2010 10:50:45 -0000 1.2
+++ Texinfo/Convert/Text.pm 17 Oct 2010 13:43:42 -0000 1.3
@@ -43,6 +43,8 @@
$VERSION = '0.01';
+# this is in fact not needed for 'footnote', 'shortcaption', 'caption'
+# since they have no brace_command_arg below.
my %ignored_brace_commands;
foreach my $ignored_brace_command ('xref','ref','pxref','inforef','anchor',
'footnote', 'shortcaption', 'caption', 'hyphenation') {
@@ -172,6 +174,10 @@
$kept_misc_commands{$command} = 1;
}
+my %ignored_types;
+foreach my $type ('empty_line_after_command', 'empty_spaces_after_command') {
+ $ignored_types{$type} = 1;
+}
sub ascii_accents($$)
{
@@ -190,11 +196,6 @@
return $text . $accent;
}
-my %ignored_types;
-foreach my $type ('empty_line_after_command', 'empty_spaces_after_command') {
- $ignored_types{$type} = 1;
-}
-
sub _normalise_space($)
{
return undef unless (defined ($_[0]));
@@ -225,6 +226,7 @@
or ($root->{'cmdname'}
and ($ignored_brace_commands{$root->{'cmdname'}}
or $ignored_block_commands{$root->{'cmdname'}}
+ # here ignore most of the misc commands
or ($root->{'args'} and $root->{'args'}->[0]
and $root->{'args'}->[0]->{'type'}
and ($root->{'args'}->[0]->{'type'} eq 'misc_line_arg'
Index: t/test_utils.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/test_utils.pl,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- t/test_utils.pl 17 Oct 2010 10:50:45 -0000 1.20
+++ t/test_utils.pl 17 Oct 2010 13:43:42 -0000 1.21
@@ -59,7 +59,9 @@
$test_name = basename($test_case, '.texi');
}
- my $parser = Texinfo::Parser->parser({'test' => 1, 'debug' =>
$self->{'debug'},
+ my $parser = Texinfo::Parser->parser({'test' => 1,
+ 'include_directories' =>
['t/include/'],
+ 'debug' => $self->{'debug'},
%$parser_options});
print STDERR " TEST $test_name\n" if ($self->{'debug'});
my $result;
Index: t/80include.t
===================================================================
RCS file: t/80include.t
diff -N t/80include.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/80include.t 17 Oct 2010 13:43:42 -0000 1.1
@@ -0,0 +1,17 @@
+use strict;
+
+use Test::More;
+
+require 't/test_utils.pl';
+
+my @test_cases = (
+[ 'simple',
+'@include inc_file.texi
+'],
+);
+
+our ($arg_test_case, $arg_generate, $arg_debug);
+
+run_all ('include', address@hidden, $arg_test_case,
+ $arg_generate, $arg_debug);
+
Index: t/include/inc_file.texi
===================================================================
RCS file: t/include/inc_file.texi
diff -N t/include/inc_file.texi
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/include/inc_file.texi 17 Oct 2010 13:43:42 -0000 1.1
@@ -0,0 +1 @@
+In included file.
Index: t/results/include/simple.pl
===================================================================
RCS file: t/results/include/simple.pl
diff -N t/results/include/simple.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/results/include/simple.pl 17 Oct 2010 13:43:42 -0000 1.1
@@ -0,0 +1,30 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors);
+
+$result_trees{'simple'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'parent' => {},
+ 'text' => 'In included file.
+'
+ }
+ ],
+ 'parent' => {},
+ 'type' => 'paragraph'
+ }
+ ]
+};
+$result_trees{'simple'}{'contents'}[0]{'contents'}[0]{'parent'} =
$result_trees{'simple'}{'contents'}[0];
+$result_trees{'simple'}{'contents'}[0]{'parent'} = $result_trees{'simple'};
+
+$result_texis{'simple'} = 'In included file.
+';
+
+
+$result_texts{'simple'} = 'In included file.
+';
+
+$result_errors{'simple'} = [];
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp Texinfo/Parser.pm Texinfo/Convert/Te...,
Patrice Dumas <=