[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo Parser.pm
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo Parser.pm |
Date: |
Tue, 19 Oct 2010 11:15:54 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/10/19 11:15:54
Modified files:
tp/Texinfo : Parser.pm
Log message:
Simplify handling of included file
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.85&r2=1.86
Patches:
Index: Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -b -r1.85 -r1.86
--- Parser.pm 19 Oct 2010 10:50:39 -0000 1.85
+++ Parser.pm 19 Oct 2010 11:15:54 -0000 1.86
@@ -1197,6 +1197,8 @@
my $current = shift;
my $line_nr = shift;
+ my $included_file = 0;
+
# a line consisting only of spaces.
if ($current->{'contents'} and @{$current->{'contents'}}
and $current->{'contents'}->[-1]->{'type'}
@@ -1366,6 +1368,7 @@
} elsif ($current->{'type'}
and $current->{'type'} eq 'misc_line_arg') {
$self->_isolate_last_space($current);
+
# first parent is the @command, second is the parent
$current = $current->{'parent'};
my $misc_cmd = $current;
@@ -1375,8 +1378,50 @@
and $self->{'misc_commands'}->{$command} =~ /^\d$/) {
my $args = _parse_line_command_args ($self, $current, $line_nr);
$current->{'special'}->{'misc_args'} = $args if (defined($args));
+ } elsif ($self->{'misc_commands'}->{$command}
+ and $self->{'misc_commands'}->{$command} eq 'text') {
+ if (!$current->{'args'} or address@hidden>{'args'}}) {
+ _line_warn ($self, sprintf($self->__("address@hidden missing
argument"),
+ $command), $line_nr);
+ } else {
+ my $text = Texinfo::Convert::Text::convert($current->{'args'}->[0]);
+ if ($command eq 'include') {
+ my $file;
+ if ($text =~ m,^(/|\./|\.\./),) {
+ $file = $text if (-e $text and -r $text);
+ } else {
+ foreach my $dir (@{$self->{'include_directories'}}) {
+ $file = "$dir/$text" if (-e "$dir/$text" and -r "$dir/$text");
+ 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 @{$self->{'input'}}, {
+ 'name' => $file,
+ 'line_nr' => 1,
+ 'pending' => [],
+ 'fh' => $filehandle };
+ } else {
+ _line_error ($self, sprintf($self->__("address@hidden: Cannot
open %s: %s"),
+ $command, $text, $!), $line_nr);
+ }
+ } else {
+ _line_error ($self, sprintf($self->__("address@hidden: Cannot find
%s"),
+ $command, $text), $line_nr);
+ }
+ }
+ }
}
$current = $current->{'parent'};
+ if ($included_file) {
+ # remove completly the include file command
+ pop @{$current->{'contents'}};
+ }
# columnfractions
if ($command eq 'columnfractions') {
# in a multitable, we are in a block_line_arg
@@ -1409,59 +1454,6 @@
unshift @{$current->{'parent'}->{'contents'}}, $empty_line;
}
}
- return $current;
-}
-
-sub _end_line_and_include_file ($$$)
-{
- my $self = shift;
- my $current = shift;
- my $line_nr = 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') {
- $self->_isolate_last_space($current);
- my $filename = Texinfo::Convert::Text::convert ($current);
- chomp($filename);
- my $file;
- if ($filename =~ m,^(/|\./|\.\./),) {
- $file = $filename if (-e $filename and -r $filename);
- } 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 @{$self->{'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);
}
@@ -1674,7 +1666,7 @@
# end of the file
my $included_file;
($current, $included_file) =
- _end_line_and_include_file ($self, $current, $line_nr);
+ _end_line ($self, $current, $line_nr);
if (!$included_file) {
$current = _end_block_command($self, $current, $line_nr);
return $root;
@@ -2019,7 +2011,7 @@
}
my $included_file;
($current, $included_file) =
- _end_line_and_include_file ($self, $current, $line_nr);
+ _end_line ($self, $current, $line_nr);
last NEXT_LINE if ($command eq 'bye');
last;
} else {
@@ -2246,7 +2238,7 @@
if ($command eq "\n") {
my $included_file;
($current, $included_file) =
- _end_line_and_include_file ($self, $current, $line_nr);
+ _end_line ($self, $current, $line_nr);
last;
}
} else {
@@ -2386,7 +2378,7 @@
#print STDERR "END LINE AFTER MERGE END OF LINE: ".
_print_current($current)."\n";
my $included_file;
($current, $included_file) =
- _end_line_and_include_file ($self, $current, $line_nr);
+ _end_line ($self, $current, $line_nr);
last;
}
}
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/04
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/04
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/09
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/14
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/14
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/16
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/18
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/19
- texinfo/tp/Texinfo Parser.pm,
Patrice Dumas <=
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/24
- texinfo/tp/Texinfo Parser.pm, Patrice Dumas, 2010/10/24