Browse Source

switch many variable names in make-index; not disturbing as I'm currently the

only developper but is a bad thing to do.
improved handling of comments line during the parsing of the .sxd.
remotes/origin/translate_notes
Alexandre Dupas 16 years ago
parent
commit
3bbec669b2
  1. 53
      make-index

53
make-index

@ -4,8 +4,7 @@
# simplified version from the original C programm that parse the input.
#
# Usage: mk-idx.pl SRC
# SRC should be an .sxd file generated by latex during a first compilation
# of the file.
# SRC should be an .sxd file generated by the latex songs package
#
use warnings;
@ -60,51 +59,57 @@ open( FILE, $file ) or die("unable to open $file");
my @data = <FILE>;
close( FILE );
#process data
# Process data
my %table;
my $type = shift @data; # first line determines the type of the index (AUTHOR or TITLE)
# Get the type of the index. Not used but we have it.
my $type = shift @data;
if( $type =~ /AUTHOR/ )
{
;
}
elsif( $type =~ /TITLE/ )
{
shift @data; # ignore the second line (in my test cases, it contains "%prefix" which should probably be ignored.
}
# Parse data and create the index table
my $item;
my $index;
my $link;
my $letter;
my $ref;
while( @data )
{
my $item = shift @data;
$item = shift @data;
unless( $item =~ /^\s*%/ ) # ignore a line starting with %
{
chomp $item;
my $index = shift @data;
$index = shift @data;
chomp $index;
my $link = shift @data;
$link = shift @data;
chomp $link;
# Get the first letter or number of the current item
my $first_letter = get_first_letter $item;
$table{$first_letter} = {} unless exists $table{$first_letter};
$letter = get_first_letter $item;
my $ref = { num => $index, link => $link };
# Create empty data index if needed
$table{$letter} = {} unless exists $table{$letter};
$table{$letter}{$item} = [] unless exists $table{$letter}{$item};
$table{$first_letter}{$item} = [] unless exists $table{$first_letter}{$item};
# Create reference for the current item
$ref = { num => $index, link => $link };
push @{$table{$first_letter}{$item}}, $ref;
# Add the reference to the index
push @{$table{$letter}{$item}}, $ref;
}
}
# Create the index formated file
foreach my $letter ( sort keys %table )
my @refs;
foreach $letter ( sort keys %table )
{
print '\begin{idxblock}{'.$letter."}\n";
foreach my $item (sort keys %{$table{$letter}} )
foreach $item ( sort keys %{$table{$letter}} )
{
print '\idxentry{';
print $item;
print '}{';
my @refs = @{$table{$letter}{$item}};
@refs = @{$table{$letter}{$item}};
print join ("\\\\", map { "\\hyperlink{$_->{link}}{$_->{num}}" } @refs);
print '}'."\n";
}

Loading…
Cancel
Save