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. 65
      make-index

65
make-index

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

Loading…
Cancel
Save