diff --git a/make-index b/make-index index b74b909e..78ef3846 100755 --- a/make-index +++ b/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 = ; 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; - chomp $item; - my $index = shift @data; - chomp $index; - my $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}; - - my $ref = { num => $index, link => $link }; + $item = shift @data; + unless( $item =~ /^\s*%/ ) # ignore a line starting with % + { + chomp $item; + $index = shift @data; + chomp $index; + $link = shift @data; + chomp $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 -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"; }