[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp/Texinfo/Convert Info.pm Plaintext.pm
From: |
Patrice Dumas |
Subject: |
texinfo/tp/Texinfo/Convert Info.pm Plaintext.pm |
Date: |
Tue, 21 Dec 2010 01:27:31 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 10/12/21 01:27:31
Modified files:
tp/Texinfo/Convert: Info.pm Plaintext.pm
Log message:
Format @printindex in Info.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Info.pm?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.38&r2=1.39
Patches:
Index: Info.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Info.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Info.pm 19 Dec 2010 17:25:06 -0000 1.2
+++ Info.pm 21 Dec 2010 01:27:31 -0000 1.3
@@ -136,14 +136,132 @@
return '';
}
+
+my $index_length_to_node = 41;
+
sub _printindex($$)
{
my $self = shift;
my $printindex = shift;
+ my $index_name;
+ if ($printindex->{'extra'} and $printindex->{'extra'}->{'misc_args'}
+ and defined($printindex->{'extra'}->{'misc_args'}->[0])) {
+ $index_name = $printindex->{'extra'}->{'misc_args'}->[0];
+ } else {
+ return '';
+ }
+ #Â this is not redone for each index, only once
+ if (!defined($self->{'index_entries'}) and $self->{'parser'}) {
+ my ($index_names, $merged_indices, $index_entries)
+ = $self->{'parser'}->indices_information();
+ $self->{'index_entries'} =
$self->Texinfo::Structuring::sort_indices($index_entries);
+ $self->{'index_names'} = $index_names;
+ $self->{'merged_indices'} = $merged_indices;
+ }
+ if (!$self->{'index_entries'} or !$self->{'index_entries'}->{$index_name}
+ or ! @{$self->{'index_entries'}->{$index_name}}) {
return '';
+ }
+
+ my $result = "\x{00}\x{08}[index\x{00}\x{08}]\n* Menu:\n\n";
+
+ my $lines_count = 3;
+ my $bytes_count = $self->count_bytes($result);
+
+ #Â first determine the line numbers for the spacing of their formatting
+ my %line_nrs;
+ my $max_index_line_nr_string_length = 0;
+ foreach my $entry (@{$self->{'index_entries'}->{$index_name}}) {
+ my $line_nr;
+ if (defined ($self->{'index_entries_line_location'}->{$entry})) {
+ $line_nr =
$self->{'index_entries_line_location'}->{$entry}->{'lines_count'};
+ }
+ if (!defined($entry->{'node'})) {
+ $line_nr = 0;
+ } else {
+ $line_nr = 3 if (defined($line_nr) and $line_nr < 3);
+ $line_nr = 4 if (!defined($line_nr));
+ }
+ my $index_line_nr_string_length =
+ Texinfo::Convert::Unicode::string_width($line_nr);
+ $max_index_line_nr_string_length = $index_line_nr_string_length
+ if ($max_index_line_nr_string_length < $index_line_nr_string_length);
+ $line_nrs{$entry} = $line_nr;
+ }
+
+ #Â this is used to count entries that are the same
+ my %entry_counts = ();
+
+ #Â FIXME second maybe should be index_prefix of eeach entry?
+ my $in_code = $self->{'index_names'}->{$index_name}->{$index_name};
+
+ foreach my $entry (@{$self->{'index_entries'}->{$index_name}}) {
+ #my @keys = keys(%$entry);
+ #print STDERR "$index_name $entry: @keys\n";
+ my $entry_tree = {'contents' => $entry->{'content'}};
+ $entry_tree->{'type'} = 'code' if ($in_code);
+ my $entry_text = '';
+ $self->advance_count_text(\$entry_text, \$bytes_count, undef,
+ undef, 0, $self->convert_line($entry_tree, {'indent' => 0}));
+
+ my $entry_nr = '';
+ if (!defined($entry_counts{$entry_text})) {
+ $entry_counts{$entry_text} = 0;
+ } else {
+ $entry_counts{$entry_text}++;
+ $entry_nr = ' <'.$entry_counts{$entry_text}.'>';
+ }
+ my $entry_line = "* $entry_text${entry_nr}: ";
+ $bytes_count += $self->count_bytes("* ${entry_nr}: ");
+
+ my $line_width = Texinfo::Convert::Unicode::string_width($entry_line);
+ if ($line_width < $index_length_to_node) {
+ my $spaces = ' ' x ($index_length_to_node - $line_width);
+ $entry_line .= $spaces;
+ $bytes_count += $self->count_bytes($spaces);
+ }
+ my $node_text;
+ if (!defined($entry->{'node'})) {
+ $node_text = $self->gdt('(outside of any node)');
+ $bytes_count += $self->count_bytes($node_text);
+ $entry_line .= $node_text;
+ } else {
+ $self->advance_count_text(\$entry_line, \$bytes_count, undef,
+ undef, 0, $self->convert_line({'type' => 'code',
+ 'contents' => $entry->{'node'}->{'extra'}->{'node_content'}}));
+ }
+ $entry_line .= '.';
+ $bytes_count += $self->count_bytes('.');
+
+ $result .= $entry_line;
+
+ my $line_nr = $line_nrs{$entry};
+ my $line_nr_spaces = sprintf("%${max_index_line_nr_string_length}d",
$line_nr);
+ my $line_part = "(line ${line_nr_spaces})";
+ $line_width = Texinfo::Convert::Unicode::string_width($entry_line);
+ my $line_part_width = Texinfo::Convert::Unicode::string_width($line_part);
+ if ($line_width + $line_part_width +1 > $self->{'fillcolumn'}) {
+ $line_part = "\n" . ' ' x ($self->{'fillcolumn'} - $line_part_width)
+ . "$line_part\n";
+ $lines_count++;
+ } else {
+ $line_part
+ = ' ' x ($self->{'fillcolumn'} - $line_part_width - $line_width)
+ . "$line_part\n";
+ }
+ $lines_count++;
+ $result .= $line_part;
+ $bytes_count += $self->count_bytes($line_part);
+ }
+
+ $result .= "\n";
+ $lines_count++;
+ $bytes_count += $self->count_bytes("\n");
+
+ return ($result, {'lines' => $lines_count, 'bytes' => $bytes_count});
}
my @directions = ('Next', 'Prev', 'Up');
@@ -169,9 +287,9 @@
if ($node_direction->{'extra'}->{'manual_content'}) {
$self->advance_count_text(\$result, \$bytes_count, undef,
undef, 0, $self->convert_line({'type' => 'code',
- 'contents' => ['text' => '(',
+ 'contents' => [{'text' => '('},
@{$node_direction->{'extra'}->{'manual_content'}},
- 'text' => ')']}));
+ {'text' => ')'}]}));
}
if ($node_direction->{'extra'}->{'node_content'}) {
$self->advance_count_text(\$result, \$bytes_count, undef,
Index: Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- Plaintext.pm 19 Dec 2010 17:25:06 -0000 1.38
+++ Plaintext.pm 21 Dec 2010 01:27:31 -0000 1.39
@@ -68,8 +68,6 @@
$informative_commands{$informative_command} = 1;
}
-# printindex not handled in plain text output.
-#'printindex',
foreach my $kept_command(keys (%informative_commands),
'verbatiminclude', 'insertcopying',
'listoffloats', 'printindex',
@@ -375,7 +373,7 @@
}
foreach my $location (@{$locations->{'lines'}}) {
if ($location->{'index_entry'}) {
- $self->{'index_entries'}->{$location->{'index_entry'}} = $location;
+ $self->{'index_entries_line_location'}->{$location->{'index_entry'}} =
$location;
}
}
$self->{'file_bytes_count'} += $bytes_count;
@@ -583,7 +581,7 @@
sub _footnotes($$)
{
my $self = shift;
- my $node = shift;
+ my $element = shift;
my $bytes_count = 0;
my $lines_count = 0;
@@ -594,14 +592,16 @@
$result .= "\n";
$lines_count++;
}
- if ($self->{'footnotestyle'} eq 'end' or !defined($node)) {
+ if ($self->{'footnotestyle'} eq 'end' or !defined($element)) {
$result .= " ---------- Footnotes ----------\n\n";
$lines_count += 2;
} else {
+
my $footnotes_node = {
- 'node_up' => $node->{'node'},
- 'extra' => {'node_content' =>
address@hidden>{'node'}->{'extra'}->{'node_content'}},
- 'text' => '-Footnotes']}
+ 'node_up' => $element->{'extra'}->{'node'},
+ 'extra' => {'node_content' =>
+ address@hidden>{'extra'}->{'node'}->{'extra'}->{'node_content'}},
+ {'text' => '-Footnotes'}]}
};
$self->advance_count_text(\$result, \$bytes_count, \$lines_count,
$locations, 0, $self->_node($footnotes_node));
@@ -1334,7 +1334,7 @@
return '';
} elsif ($root->{'cmdname'} eq 'printindex') {
$self->advance_count_text(\$result, \$bytes_count, \$lines_count,
- $locations, 0, $self->_convert($root->{'args'}->[0]));
+ $locations, 0, $self->_printindex($root));
return ($result, {'bytes' => $bytes_count, 'lines' => $lines_count},
$locations);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- texinfo/tp/Texinfo/Convert Info.pm Plaintext.pm,
Patrice Dumas <=