3 # Philippe Chauvat - Bacula Systems
5 # 25-octobre-2013: Creation
7 # Context: This script is designed to handle external references in HTML
11 # This is a two step process.
12 # -a) Each HTML file produced by the latex2html converter is analyzed and
13 # every <a name="whatever_but_beginning_with_SECTION"> expression is
14 # kept into a global file in a tab form: manual anchor_name file_name
15 # -b) This (handle-xr-references.pl) script is called once, after the
16 # translate.pl post-process.
17 # It takes a list of manuals and the filename from (a) (list of anchors)
18 # and analyze each HTML file to find the external reference pattern:
20 # Then it replaces the pattern build like __XRANCHOR_TEXT_ANCHOR_MANUAL_LEVEL_
21 # by a <a href="path/to/manual/file_name#anchor_name>text level</a>
25 # -i: list of anchors file name
26 # -m: list of manuals to manage
27 # -l: lang of the manuals. en by default.
34 print "handle-xr-references.pl -m | --manuals-list manual's list
35 -i | --input anchors-input-file-name
36 [ -l | --lang language ]
42 # Send message to output in case of debug only
43 # ======================
45 my ($what,$msg) = @_ ;
47 print "\n===============================\nBegin of $msg\n" ;
49 print "\n===============================\nEnd of $msg\n\n" ;
54 my $referencefile = $_[0] ;
57 open FH, "< $referencefile" or die "Unable to open $referencefile\n" ;
59 our($manual,$filename,$anchor) = split /\t/,$_ ;
61 if ($anchor !~ /^SECTION/ and $anchor !~ /^tex2html/ and $anchor !~ /^\d+/ ) {
62 # print "Manual: $manual\nAnchor: $anchor\nFilename: $filename\n\n" ;
63 $references{$manual}{$anchor} = $filename ;
71 our($anchorfile,$manuallist,$help,$debug,$language) ;
73 # Usage in case of missing arguments
74 usage() unless($#ARGV > -1) ;
76 # Input file / Output file
77 GetOptions("input|i=s" => \$anchorfile,
78 "manual-list|m=s" => \$manuallist,
79 "lang|l=s" => \$language,
81 "help|?" => \$help) or usage() ;
86 # Anchor file is mandatory
87 usage() unless (defined $anchorfile) ;
88 # ... and file must exist
89 die "$anchorfile does not exists.\n" unless -e $anchorfile ;
91 # Manual list is mandatory too
92 usage() unless (defined $manuallist) ;
94 # Read the anchor file
95 my %references = read_references($anchorfile) ;
97 # Read all HTML files and replace the need references
98 my @manuals = split / /, $manuallist ;
100 foreach $m (@manuals) {
101 print "HTML files for manual $m\n" ;
102 @htmls = glob($m . "/*html") ;
103 foreach my $f (@htmls) {
104 print "HTML file: $f\n" ;
106 open FH, "< $f" or die "Unable to open $f\n" ;
109 open FH, "> $f" or die "Unable to write to $f\n" ;
110 foreach my $l (@content) {
112 # __XRANCHOR_Tape Testing_FreeBSDTapes_problems_chapter__
113 while ($l =~ /(__XRANCHOR_[^_]*_[^_]*_[^_]*_[^_]*__)/) {
116 my ($text,$anchor,$manual,$level) = /__XRANCHOR_([^_]*)_([^_]*)_([^_]*)_([^_]*)__/ ;
117 # print "\t\tText: $text\n\t\tAnchor: $anchor\n\t\tManual: $manual\n\t\tLevel: $level\n" ;
118 my $filename = $references{$manual}{$anchor} ;
119 my $theanchor = "<a class=\"borg_xrlinkclass\" href=\"../../$manual/$manual/$filename#$anchor\">$text $level</a>" ;
126 while ($l =~ /(__HREF_[^_]*_[^_]*__)/) {
128 my ($link,$text) = /__HREF_([^_]*)_([^_]*)__/ ;
129 my $theanchor = "<a class=\"borg_linkclass\" href=\"$link\">$text</a>" ;