+
+
+
+#############################################################################
+### HELPER FUNCTIONS
+#############################################################################
+
+# Convert a given node name to its proper file name (normalization as explained
+# in the texinfo manual:
+# http://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html
+sub texinfo_file_name($)
+{
+ my $text = shift;
+ my $result = '';
+ # File name normalization by texinfo:
+ # 1/2: letters and numbers are left unchanged
+ # 3/4: multiple, leading and trailing whitespace is removed
+ $text = main::normalise_space($text);
+ # 5/6: all remaining spaces are converted to '-', all other 7- or 8-bit
+ # chars are replaced by _xxxx (xxxx=ascii character code)
+ while ($text ne '') {
+ if ($text =~ s/^([A-Za-z0-9]+)//o) { # number or letter stay unchanged
+ $result .= $1;
+ } elsif ($text =~ s/^ //o) { # space -> '-'
+ $result .= '-';
+ } elsif ($text =~ s/^(.)//o) { # Otherwise use _xxxx (ascii char code)
+ my $ccode = ord($1);
+ if ( $ccode <= 0xFFFF ) {
+ $result .= sprintf("_%04x", $ccode);
+ } else {
+ $result .= sprintf("__%06x", $ccode);
+ }
+ }
+ }
+ # 7: if name does not begin with a letter, prepend 't_g' (so it starts with a letter)
+ if ($result !~ /^[a-zA-Z]/) {
+ $result = 't_g' . $result;
+ }
+ # DONE
+ return $result
+}
+
+
+# Load a file containing a nodename<=>filename map (tab-sepatared, i.e.
+# NODENAME\tFILENAME\tANCHOR
+# Returns a ref to a hash "Node title" => ["FilenameWithoutExt", "Anchor"]
+sub load_map_file ($)
+{
+ my $mapfile = shift;
+ my $node_map = ();
+
+ if (open(XREFFILE, $mapfile)) {
+ my $line;
+ while ( $line = <XREFFILE> ) {
+ # parse the tab-separated entries and insert them into the map:
+ chomp($line);
+ my @entries = split(/\t/, $line);
+ if (scalar (@entries) == 3) {
+ $node_map->{$entries[0]} = [$entries[1], $entries[2]];
+ } else {
+ print STDERR "Invalid entry in the node file $mapfile: $line\n";
+ }
+ }
+ close (XREFFILE);
+ } else {
+ print STDERR "WARNING: Unable to load the map file $mapfile\n";
+ }
+ return $node_map;
+}
+
+
+# Split the given path into dir and basename (with .texi removed). Used mainly
+# to get the path/basename of the original texi input file
+sub split_texi_filename ($)
+{
+ my $docu = shift;
+ my $docu_dir, $docu_name;
+ if ($docu =~ /(.*\/)/) {
+ chop($docu_dir = $1);
+ $docu_name = $docu;
+ $docu_name =~ s/.*\///;
+ } else {
+ $docu_dir = '.';
+ $docu_name = $docu;
+ }
+ $docu_name =~ s/\.te?x(i|info)?$//;
+ return ($docu_dir, $docu_name);
+}
+
+
+
+
+
+#############################################################################
+### CSS HANDLING
+#############################################################################
+
+# Include our standard CSS file, not hard-coded CSS code directly in the HTML!
+# For IE, conditionally include the lilypond-ie-fixes.css style sheet
+sub lilypond_css_lines ($$)
+{
+ my $import_lines = shift;
+ my $rule_lines = shift;
+ return if (defined($Texi2HTML::THISDOC{'CSS_LINES'}));
+ if (@$rule_lines or @$import_lines)
+ {
+ $Texi2HTML::THISDOC{'CSS_LINES'} = "<style type=\"text/css\">\n<!--\n";
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$import_lines) . "\n" if (@$import_lines);
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= join('',@$rule_lines) . "\n" if (@$rule_lines);
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= "-->\n</style>\n";
+ }
+ foreach my $ref (@CSS_REFS)
+ {
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"stylesheet\" type=\"text/css\" title=\"$ref->{TITLE}\" href=\"$ref->{FILENAME}\">\n";
+ }
+ foreach my $ref (@ALT_CSS_REFS)
+ {
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= "<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"$ref->{FILENAME}\" title=\"$ref->{TITLE}\">\n";
+ }
+ $Texi2HTML::THISDOC{'CSS_LINES'} .= "<!--[if lte IE 7]>\n<link href=\"lilypond-ie-fixes.css\" rel=\"stylesheet\" type=\"text/css\">\n<![endif]-->\n";
+}
+
+
+
+
+
+#############################################################################
+### SPLITTING BASED ON NUMBERED SECTIONS
+#############################################################################
+
+my $lastfilename;
+my $docnr = 0;
+my $node_to_filename_map = ();
+
+