3 # Copyright 2006, 2007 Lennart Borgman, http://OurComments.org/. All
6 # This file is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This file is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
24 use lib "$FindBin::Bin/PerlLib";
34 ### Script start parameters
36 my $m_param_files = 1;
38 my $m_param_single = 0;
43 my $m_param_Overwrite;
46 my $m_iAlwaysOpenedLevel = 0;
49 my $m_sTemplateFolder;
63 sub read_page_list($);
67 sub find_template_files();
68 sub find_linked_from_pages();
69 sub copy_wtoc_files();
70 sub copy_linked_files();
72 #push @pages, [$ind, $tit, $full_fil, $anc, $hrf, $trg, $tip];
81 ##########################################################
83 ##########################################################
86 if ($m_param_action eq "FIND") {
87 find_pages(\@m_param_InRoot, $m_param_InPages);
88 } elsif($m_param_action eq "MERGE") {
90 read_page_list($m_param_InPages);
91 find_template_files();
98 find_linked_from_pages();
100 } elsif($m_param_action eq "TOC") {
104 sub copy_if_newer_or_overwrite($$) {
109 my ($in_v, $in_d, $in_f) = File::Spec->splitpath( $in_file );
110 my ($out_v,$out_d,$out_f) = File::Spec->splitpath( $out, 1 );
111 $out_file = File::Spec->catpath( $out_v, $out_d, $in_f );
113 my $should_write = 1;
115 if ($m_param_Overwrite) {
116 my $in_mdt = (stat $in_file)[9];
117 my $outmdt = (stat $out_file)[9];
118 if (($outmdt > $in_mdt)) {
126 if (!File::Copy::syscopy($in_file, $out_file)) {
127 die "syscopy($in_file, $out_file): $!";
129 print " $in_file => $out_file\n";
132 } # copy_if_newer_or_overwrite
134 sub copy_wtoc_files() {
135 print "\n**** Copy html-wtoc files\n";
136 mkdir $m_param_OutRoot, 0777;
137 my $css_file = $FindBin::Bin . "/html-wtoc.css";
138 copy_if_newer_or_overwrite($css_file, $m_param_OutRoot);
139 my $js_file = $FindBin::Bin . "/html-wtoc.js";
140 copy_if_newer_or_overwrite($js_file, $m_param_OutRoot);
141 my $OutRootImg = $m_param_OutRoot . "img/";
143 my $imgsrc = $FindBin::Bin . "/img/";
144 opendir(IMGDIR, $imgsrc) or die "Can't opendir $imgsrc: $!";
145 while (my $imgfile = readdir(IMGDIR)) {
146 my $outimg = $OutRootImg . $imgfile;
147 $imgfile = $imgsrc . $imgfile;
148 #print STDERR ">>>$imgfile\n";
150 copy_if_newer_or_overwrite($imgfile, $outimg);
156 sub add_to_linked_files($$) {
157 my $from_file = shift;
159 if (exists $m_linked_files{$to_file}) {
160 my $old_from = $m_linked_files{$to_file};
161 unless ($old_from eq $from_file) {
162 die "Both $from_file and $old_from should be copied to $to_file";
165 $m_linked_files{$to_file} = $from_file;
166 } # add_to_linked_files
168 sub copy_linked_files() {
169 print "\n**** Copy linked files\n";
171 for my $pnum (0..$#pages) {
172 $pages{ full_in_name($pnum) } = 1;
174 for my $to_file (keys %m_linked_files) {
175 my $from_file = $m_linked_files{$to_file};
176 unless (exists $pages{$from_file}) {
178 mkpath4file($to_file);
179 copy_if_newer_or_overwrite($from_file, $to_file);
183 } # copy_linked_files
185 sub find_linked_files($;$) {
187 my $out_file = shift;
188 $out_file = in2out($in_file) unless ($out_file);
189 my $whole = get_file($in_file);
190 while ($whole =~ m!(?:\s|^)(?:href|src)="(.*?)"!gis) {
192 next unless $l =~ m!\.(?:css|js|jpg|jpeg|gif|png)$!;
193 if (!File::Spec->file_name_is_absolute($l)) {
194 next if $l =~ m!^javascript:!;
195 next if $l =~ m!^http://!;
196 next if $l =~ m!^ftp://!;
197 next if $l =~ m!^mailto:!;
201 if (File::Spec->file_name_is_absolute($l)) {
202 $rel_l = PathSubs::mk_relative_link($in_file, $l);
204 $full_in = PathSubs::mk_absolute_link($in_file, $l);
206 my $full_out = PathSubs::mk_absolute_link($out_file, $rel_l);
207 add_to_linked_files($full_in, $full_out);
209 } # find_linked_files
211 sub find_template_files() {
212 print "\n**** Find files referenced in template file\n";
213 my $in_file = $m_param_Template;
214 my $out_file = $m_param_OutRoot . "dummy.htm";
215 find_linked_files($in_file, $out_file);
217 sub find_linked_from_pages() {
218 for my $pnum (0..$#pages) {
219 next unless defined $pages[$pnum][FULL_FIL];
220 next unless $pages[$pnum][FULL_FIL] ne "";
221 next if defined $pages[$pnum][TRG];
222 find_linked_files( full_in_name($pnum) );
226 sub should_write_merged($$) {
228 my $out_file = shift;
229 my $should_write = 1;
231 if ($m_param_Overwrite) {
232 my $srcmdt = page_src_time($pnum);
233 my $outmdt = (stat $out_file)[9];
234 if (($outmdt > $srcmdt)
235 && ($outmdt > $m_TemplateTime)
236 && ($outmdt > $m_InPagesTime)) {
243 return $should_write;
246 #print STDERR "*** param_OutRoot=$m_param_OutRoot\n";
247 if ($m_param_single) {
248 my $out_file = $m_param_OutRoot . "single_$m_param_pnum.html";
249 if (should_write_merged($m_param_pnum, $out_file)) {
250 my $page = create_single_page($m_param_pnum);
251 $page = shrink($page);
252 create_file_and_path($out_file, $page);
256 print "\n*** Creating pages:\n";
257 for my $pnum (0..$#pages) {
258 next unless defined $pages[$pnum][FULL_FIL];
259 next unless $pages[$pnum][FULL_FIL] ne "";
260 next if defined $pages[$pnum][TRG];
262 my $out_file = full_out_name($pnum);
263 if (should_write_merged($pnum, $out_file)) {
264 my $page = create_page($pnum);
266 print " Creating page $iPages: " . full_in_name($pnum) . "\n";
267 $page = shrink($page);
268 print "\t=> $out_file\n";
269 create_file_and_path($out_file, $page);
276 my $page = ($m_param_single ?
277 create_single_page($m_param_pnum)
279 create_page($m_param_pnum) );
283 ##########################################################
285 ##########################################################
288 $sScript =~ tr!\\!/!;
289 $sScript =~ s!.*/(.*)!$1!;
291 Making preliminary file list:
292 $sScript find in="in-dir" pages="pages-file" [overwrite=1]
294 Merging pages and table of contents:
295 $sScript merge pages="pages-file" outroot="out-dir" template="template-file" [overwrite=1]
302 for my $arg (@ARGV) { print " "; print $arg; } print "\n\n";
303 die_usage() unless $#ARGV > 0;
304 $m_param_action = $ARGV[0];
305 $m_param_action =~ tr/a-z/A-Z/;
306 #push @m_param_InRoot, $FindBin::Bin . "/doc/";
307 #$m_param_OutRoot = $FindBin::Bin . "/tmp/";
308 #$m_param_Template = $FindBin::Bin . "/doc/home_template.htm";
309 #$m_param_InPages = $FindBin::Bin . "/doc/toc_pages.txt";
310 for (my $i = 1; $i <= $#ARGV; $i++) {
311 my ($k, $v) = ($ARGV[$i] =~ m!(.*?)=(.*)!);
314 $v = PathSubs::uniq_file($v);
315 $v .= "/" unless substr($v, -1) eq "/";
316 push @m_param_InRoot, $v;
317 } elsif( $k eq "outroot") {
318 $v = PathSubs::uniq_dir($v);
319 $v .= "/" unless substr($v, -1) eq "/";
320 $m_param_OutRoot = $v;
321 } elsif( $k eq "pages") {
322 $v = PathSubs::uniq_file($v);
323 $m_param_InPages = $v;
324 } elsif( $k eq "template") {
325 $v = PathSubs::uniq_file($v);
326 $m_param_Template = $v;
327 } elsif( $k eq "overwrite" ) {
328 $m_param_Overwrite = $v;
329 } elsif( $k eq "openedlevel" ) {
330 $m_iAlwaysOpenedLevel = $v * 1;
332 die "Unknown parameter: $ARGV[$i]\n";
335 if($m_param_action eq "FIND") {
336 if ($#m_param_InRoot < 0) { die_usage(); }
337 if (! defined $m_param_InPages) { die_usage(); }
338 } elsif($m_param_action eq "MERGE") {
339 if (! defined $m_param_InPages) { die_usage(); }
340 if (! defined $m_param_OutRoot) { die_usage(); }
341 if (! defined $m_param_Template) { die_usage(); }
342 $m_sTemplateFolder = $m_param_Template;
343 $m_sTemplateFolder =~ s![^/]*$!!;
348 $m_sInPagesFolder = $m_param_InPages;
349 $m_sInPagesFolder =~ s![^/]*$!!;
350 print "Parameters:\n";
351 print " " . $m_param_action . "\n";
352 print " pages=" . $m_param_InPages . "\n";
353 print " outroot=" . $m_param_OutRoot . "\n";
354 print " template=" . $m_param_Template . "\n";
355 if (defined $m_param_Overwrite) {
356 print " overwrite=" . $m_param_Overwrite . "\n";
358 #if ($#m_param_InRoot == -1) { push @m_param_InRoot,$m_sInPagesFolder; }
362 my $sTemplate = get_file($m_param_Template, 1);
363 $m_TemplateTime = (stat $m_param_Template)[9];
364 $m_InPagesTime = (stat $m_param_InPages)[9];
365 $sTemplate =~ s/<!--.*?-->//gs;
366 if ( $sTemplate =~ m!(.*?<body.*?>)(.*)</body>!si ) {
367 $m_sStartTemplate = $1;
368 $m_sBodyTemplate = $2;
369 #$m_sEndTemplate = $3;
371 die "Can't find body of template\n";
375 sub read_page_list($) {
376 my $sPagesFile = shift;
378 open(P,$sPagesFile) or die "Can't open toc list file $sPagesFile: $!\n";
379 while (my $sLine = <P>) {
381 $sLine =~ s/^\s+|\s+$//g;
382 next if $sLine eq "";
383 next if substr($sLine, 0, 1) eq ";";
384 #print STDERR "$sLine\n";
385 my ($ind, $tit, $ref, $tip, $trg, $ico)
386 = map { s/^\s+|\s+$//g; $_; } split("###", $sLine);
387 #warn "trg=$trg\n" if defined $trg;
388 my ($fil, $anc) = ("", "");
391 #$ref = "" unless defined $ref;
392 #print STDERR "ref=$ref\n";
394 if (defined $trg) { undef $trg unless $trg ne ""; }
395 if ((defined $trg) || ($ref =~ m/https?:/i)) {
398 ($fil, $anc) = split('#', $ref);
400 if (File::Spec->file_name_is_absolute($fil)) {
403 $full_fil = PathSubs::uniq_file($m_sInPagesFolder . $fil);
408 if ((!$tip) && ($full_fil ne "")) {
409 $tip = get_title($full_fil);
411 push @pages, [$ind, $tit, $full_fil, $anc, $hrf, $trg, $tip];
412 push @in_files, $full_fil if !defined $trg;
415 $m_sCommonIn = get_common_root(\@in_files). "/";
420 sub get_common_root($) {
423 for my $s (@$psRoots) {
424 my $full_s = PathSubs::uniq_file($s);
425 my @full_s = split("/", $full_s);
426 if ($#sCommon == -1) {
429 my $iMax = $#sCommon; if ($#full_s < $iMax) { $iMax = $#full_s; }
430 for (my $i = 0; $i <= $iMax; $i++) {
431 if ($sCommon[$i] ne $full_s[$i]) {
432 #print STDERR "$i: $sCommon[$i] != $full_s[$i]\n";
433 @sCommon = @sCommon[0..$i-1];
439 my $sCommon = join("/", @sCommon);
445 my $pasInRoot = shift;
446 my $sOutFile = shift;
447 if (!$m_param_Overwrite) {
448 die "Don't want to overwrite existing output file $sOutFile!\n" if -e $sOutFile;
454 return unless m/.html?/i;
456 my $fname = PathSubs::uniq_file($_);
457 die "Can't read $fname\n" unless -r $_;
458 my $title = get_title($_);
459 my $level = $fname =~ tr!/!!;
460 $level -= $root_level;
461 my $rel_fname = PathSubs::mk_relative_link($sOutFile, $fname);
462 $sList .= "$level ### $title ### $rel_fname\n";
464 for my $sInRoot (@$pasInRoot) {
465 $sInRoot = PathSubs::uniq_file($sInRoot);
466 chop($sInRoot) if (substr($sInRoot, -1) eq "/");
467 $root_level = $sInRoot =~ tr!/!!;
468 File::Find::find($handle_file, $sInRoot);
470 create_file($sOutFile, $sList);
474 ##########################################################
475 ### File - page helpers
476 ##########################################################
480 return $pages[$num][FULL_FIL];
484 return $pages[$num][ANC];
488 #die $pages[$num][HRF] if defined $pages[$num][HRF];
489 return $pages[$num][HRF];
493 return $pages[$num][TRG];
497 return $pages[$num][TIT];
501 return $pages[$num][TIP];
503 sub full_in_name($) {
505 my $name = file_name($num);
508 sub full_out_href($) {
510 my $anchor = file_anchor($num);
511 my $full_href = full_out_name($num);
512 warn "full_href is null" unless $full_href;
513 if ((defined $anchor) && ($anchor ne "")) { $full_href .= "#" . $anchor; }
516 sub full_out_name($) {
518 my $in_name = file_name($num);
519 return unless $in_name;
520 my $anchor = file_anchor($num);
521 #$m_param_OutRoot . $name;
523 my $name = substr($in_name, length($m_sCommonIn));
527 for (my $i = length($name);$i>0;$i--) {
528 if (substr($name, $i, 1) eq ".") {
529 $base = substr($name, 0, $i-1);
530 $ext = substr($name, $i);
531 $name = $base . "_sharp_" . $anchor . $ext;
536 $m_param_OutRoot . $name;
538 sub replace_name_link($) {
540 for my $k (keys %page_num) {
541 my $num = $page_num{$k};
542 my $href = ($m_param_single ? "javascript:ShowPage($num)" : file_name($num));
543 $page =~ s!%%$k%%!$href!gs;
548 ##########################################################
549 ### File name helpers
550 ##########################################################
553 die "in2out: File name is not abs: $in_name" unless File::Spec->file_name_is_absolute($in_name);
554 my $name = substr($in_name, length($m_sCommonIn));
555 $m_param_OutRoot . $name;
558 ##########################################################
559 ### File reading/writing
560 ##########################################################
566 File::Path::mkpath($path);
568 sub create_file($$) {
569 my ($out_file, $page) = @_;
570 if (!$m_param_Overwrite) {
571 if (-e $out_file) { die "Will not overwrite $out_file\n"; }
573 open(OUT, ">$out_file") or die "Can't create $out_file: $!";
576 chmod 0111|((stat $out_file)[2]&07777), $out_file
578 sub create_file_and_path($$) {
579 my ($out_file, $page) = @_;
580 mkpath4file($out_file);
581 create_file($out_file, $page);
586 my ($file, $need) = @_;
587 if (open(FL, $file)) {
594 die "Can't open $file: $err\n" if $need;
601 open(H, $file) or die "Can't open and get title from $file: $!";
602 while (my $line = <H>) {
603 if ($line =~ m!<title>(.*?)</title>!i) { close H; return $1; }
610 ##########################################################
612 ##########################################################
614 sub get_head_from_file($) {
617 my $head = get_head(get_file($fname, 1), \$err);
618 die "\n\n$fname\n\t" . $err if defined $err;
621 # BUG: These actually requires parsing of the file, but it does not
622 # seem very important:
626 return "" unless $html;
627 $html =~ s/<!--.*?-->//g;
628 if ($html =~ m!<head.*?>(.*)</head>!is) {
631 $$perr = "Can't find <head>-tag in $html\n";
635 return "" unless $html;
636 $html =~ s/<!--.*?-->//gs;
637 if ($html =~ m!<body[^>]*>(.*)</body>!is) {
640 die "Can't find <body>-tag in $html\n";
646 my @str = split("\n", $str);
649 if ($s =~ m!<pre>!i) { $in_pre = 1; }
650 if ($s =~ m!</pre>!i) { $in_pre = 0; }
651 $s =~ s!^(\s*)!! unless $in_pre;
652 $out_str .= $s . "\n";
655 $str =~ s!^(\s*)!!gm;
660 ##########################################################
661 ### Making what we see
662 ##########################################################
665 return "" if ! $m_param_single;
667 <a href="javascript:show_search()" xstyle="font-size: 8pt"
668 title="Show Search Form"
669 ><img src="img/search.gif" border="$m_bBorders" align="left"></a>
670 <a href="javascript:show_search()" xstyle="font-size: 8pt"
671 title="Show Search Form"
672 class="html-wtoc-search"
676 sub mk_main_table($$$$$) {
679 my $srch_table = shift;
683 if ($m_param_single) {
687 . td({-valign=>'bottom', }, mk_search(), ) )
691 { -border=>"$m_bBorders", -cellpadding=>0, -cellspacing=>0,
693 -id=>"html-wtoc-contents",
695 -summary=>"Table of contents",
699 td({-class=>"html-wtoc-margin"})
700 . td({-valign=>'top'}, $left) )
704 my $page = $m_sBodyTemplate;
705 $page = replace_template_links($m_sBodyTemplate, $sFile);
706 $page =~ s!%%TOC%%!$cont_table!;
707 $page =~ s!%%PAGE%%!$main!;
712 sub find_ind_level_prev($) {
714 for (my $i = $lThis - 1; $i > 0; $i--) {
715 my $ind_lev = $pages[$i][IND];
716 if ($ind_lev < 50) { return $ind_lev; }
720 sub find_ind_level_next($) {
722 #print "find_ind_level_next($lThis)";
724 #print file_title($lThis);
726 #for (my $i = $lThis; $i < $#pages; $i++) {
727 for (my $i = $lThis + 1; $i <= $#pages; $i++) {
728 my $ind_lev = $pages[$i][IND];
729 if ($ind_lev < 50) { return $ind_lev; }
741 sub mk_opener_elem($$$) {
749 if ($sHref) { $$Aattrib{href} = $sHref; }
763 -src=>"img/$sImg.gif",
775 if (!$pages[$pnum]) {
781 my $this_indent = $pages[$pnum][IND];
782 my $this_file = $pages[$pnum][FULL_FIL];
783 if ($this_indent == -2) {
786 my $this_href = full_out_name($pnum);
787 #my $anchor = file_anchor($pnum);
788 #if (defined $anchor) { $this_href .= "#" . $anchor; }
796 ### Open all main level nodes
797 my @opened; # rename to visible!!!!!
798 for my $pi (0..$#pages) {
799 my $indent = $pages[$pi][IND];
800 if ($indent <= $m_iAlwaysOpenedLevel) {
803 $opened[$pi] = 0; # more simple to handle
809 ### Open ancestors and older sisters (if not a standalone node)
810 my $pnum_indent = $pages[$pnum][IND];
811 my $high_open = $pnum_indent;
812 my $standalone_open = 10;
813 if ($high_open < $standalone_open) { ### Not a standalone node
814 for (my $pi = $pnum; $pi >= 0; $pi--) {
815 my $pi_indent = $pages[$pi][IND];
816 if ($high_open >= $pi_indent) {
818 $high_open = $pi_indent;
819 for (my $ps = $pi+1; $ps <= $#pages; $ps++) {
820 my $ps_indent = $pages[$ps][IND];
821 last if $ps_indent < $pi_indent;
822 $opened[$ps] = 1 if $ps_indent == $pi_indent;
825 last if $pi_indent == 0;
832 ### Open direct childs and younger sisters
834 my $more_sisters = 1;
835 my $max_open_indent = $pnum_indent;
836 for my $pi ($pnum+1..$#pages) {
837 my $pi_indent = $pages[$pi][IND];
838 if ($pi_indent <= $max_open_indent) { $maybe_child = 0; }
839 if ($pi_indent < $pnum_indent) { $more_sisters = 0; }
840 if ($pi_indent == $pnum_indent) {
841 if ($more_sisters) { $opened[$pi] = 1; }
843 } elsif ($pi_indent == $pnum_indent+1) {
844 if ($maybe_child) { $opened[$pi] = 1; }
852 ### Open all in the same file (necessary for non-JavaScript)
853 for my $pi (0..$#pages) {
854 my $file = $pages[$pi][FULL_FIL];
855 #printf STDERR "file - open=(%s)\n", $file;
856 #if ($file eq $this_file) {
857 if ($file eq $this_file) {
862 if ($pages[$pi][IND] < $pages[$pi+1][IND]) {
867 if ($pages[$pi][IND] > 10) {
869 #print ">>>>>>>>\$opened[$pi] = 0;\n";
871 #print STDERR "+++++++++\$opened[$pi] = $opened[$pi]\n";
877 ### Make the actual contents
880 for my $pi (0..$#pages) {
881 # if (!$pages[$pi][FULL_FIL] && !$pages[$pi][HRF]) {
882 # my $txt = file_title($pi); #$pages[$pi][TIT];
883 # $txt = qq(</p><hr width="50%" align="left" /><p style='margin-top:0'>) if $txt eq "-";
888 my $txt = file_title($pi); #$pages[$pi][TIT];
890 $txt = qq(</p><hr width="50%" align="left" /><p style='margin-top:0'>);
895 #if ($pages[$pi][TRG]) {
898 #next if ! defined $opened[$pi];
899 #next if ! $opened[$pi];
900 my $ind_lev = $pages[$pi][IND];
901 next if $ind_lev > 50;
902 my $ind_lev_next = find_ind_level_next($pi);
903 #my $ind_lev_prev = find_ind_level_prev($pi);
907 ### Child id from previous row
908 if (defined $child_id) {
911 $display = qq(style="display:none");
914 $this_entry .= "\n<div id=\"$child_id\" $display>\n";
917 my $opener_elem = ""; #qq(<img src="img/blank12.gif" width=12 height=12 alt=" ">);
918 my $childs_are_visible = ($pi == $pnum);
920 if ($pages[$pi][IND] < $pages[$pi+1][IND]) {
921 if ($opened[$pi+1]) { $childs_are_visible = 1; }
924 #if ($pages[$pi][IND] < $m_iAlwaysOpenedLevel) { $childs_are_visible = 1; }
931 my $title = file_title($pi);
932 my $file_name = file_name($pi);
934 $file_href = file_href($pi); # || "";
935 $target = file_target($pi);
939 ($m_param_single ? "JavaScript:ShowPage($pi);" :
940 ($file_href ne ""? $file_href
942 PathSubs::mk_relative_link($this_href, full_out_href($pi))))
944 ($m_param_single ? "JavaScript:ShowPage($pi)" : "?pnum=$pi")
947 (File::Spec->splitpath($this_href))[2]);
949 $href_self = $this_href;
950 if ($href_self =~ m!([^/\\]*$)!) {
954 $target_attrib = (defined $target? qq(target="$target"): "");
960 if (defined $ind_lev_next && $ind_lev_next > $ind_lev) {
961 $child_id = "toc_child_$pi";
962 #print " child_id=$child_id\n";
963 push @child_trace, $child_id;
964 $opener_elem = mk_opener_elem($pi,
965 ($href? $href : $href_self),
966 $childs_are_visible);
968 $title =~ s/_/ /go;
969 my $indent = ($ind_lev ? " " x (($ind_lev-1) * 4) : "");
970 my $size = $size[$ind_lev];
971 $title = b($title) if $ind_lev == 0;
976 onclick=>"html_wtoc_nailing(this)",
981 id=>"opener_text_$pi",
986 $$Aattrib{class} = "html-wtoc-currcont";
987 $$Aattrib{title} = "You are here";
988 $$Aattrib{href} = $href_self;
993 -class=>"html-wtoc-contline",
995 -summary=>"Formatter",
1003 $indent . $title . " "
1007 -class=>"html-wtoc-mark",
1018 ### Link to other page
1019 if (file_title($pi)) {
1020 $tooltip = $pages[$pi][TIP];
1021 if (!defined $tooltip) { $tooltip = "Go to the page $title"; }
1022 $$Aattrib{class} = "html-wtoc-contents-a";
1024 if (!defined $href) {
1025 $a_or_span = span($Aattrib, $indent . $title);
1027 $$Aattrib{title} = $tooltip;
1028 $$Aattrib{href} = $href;
1029 if (defined $target) { $$Aattrib{target} = $target; }
1030 $a_or_span = a($Aattrib, $indent . $title);
1036 -class=>"html-wtoc-contline",
1038 -summary=>"Formatter",
1047 -class=>"html-wtoc-mark",
1054 $this_entry .= $indent . " " . $title;
1058 if ((!defined $ind_lev_next) || $ind_lev_next <= $ind_lev) {
1059 my $ind_end = $ind_lev;
1060 if (defined $ind_lev_next) { $ind_end = $ind_lev_next+1; }
1061 for (my $i = $ind_end; $i <= $ind_lev; $i++) {
1062 my $end_id = pop @child_trace;
1063 if (defined $end_id) {
1064 $this_entry .= "</div><!-- end child $end_id -->"; # end childs' span
1065 #print " end $end_id\n";
1069 $cont .= $this_entry;
1070 $father[$ind_lev] = $pi;
1071 } #for my $pi (0..$#pages)
1073 $cont = div({-class=>"html-wtoc-contents"}, $cont) . p(" ");
1074 #$cont =~ s|<|\n<|gms;
1075 #$cont =~ tr!\n\r! !;
1082 if (!PathSubs::is_abs_path($src)) {
1083 my $srcabs = PathSubs::mk_absolute_link(full_out_name(0), $src);
1084 $src = PathSubs::mk_relative_link(full_out_name($pnum), $srcabs);
1091 sub mk_main_window($) {
1093 my $full_name = full_in_name($pnum);
1094 return unless defined $full_name;
1095 return get_body(get_file($full_name, 1));
1105 ##########################################################
1106 ### The JavaScripts and styles we need
1107 ##########################################################
1113 PathSubs::mk_relative_link(full_out_name($pnum), $m_param_OutRoot . "html-wtoc.css");
1114 return qq(<link rel="stylesheet" href="$rel_link" type="text/css">\n);
1118 return <<__HTML_END_JS_PNUM__;
1119 <script type="text/JavaScript">
1120 var iCurrentChild = $pnum;
1121 var iMaxChildNum = $#pages;
1123 __HTML_END_JS_PNUM__
1126 if ($m_param_single) {
1127 $single_js = qq[if (!document.all) { navigate("0.html"); }];
1128 my $page_info = "var page_name = new Array;\n";
1129 for my $i (0..$#pages) {
1130 my $page_name = file_title($i); #$pages[$i][TIT];
1131 $page_info .= qq[ page_name[$i] = "$page_name";\n];
1133 $single_js .= $page_info;
1136 PathSubs::mk_relative_link(full_out_name($pnum), $m_param_OutRoot . "search.js");
1138 PathSubs::mk_relative_link(full_out_name($pnum), $m_param_OutRoot . "html-wtoc.js");
1139 return <<__HTML_END_JS__;
1140 <script type="text/JavaScript" src="$sch_link"></script>
1141 <script type="text/JavaScript" src="$top_link"></script>
1142 <script type="text/JavaScript">
1148 ##########################################################
1150 ##########################################################
1152 sub replace_template_links($$) {
1153 my $template = shift;
1155 $template =~ s{\ssrc="(.*?)"}
1157 my $sSrc = $m_param_OutRoot . $1;
1158 my $sRelSrc = PathSubs::mk_relative_link($sFile, $sSrc);
1159 qq( src="$sRelSrc");
1161 $template =~ s{\shref="(.*?)"}
1164 if ((lc substr($sOld, 0, 11)) eq "javascript:") {
1166 } elsif (PathSubs::is_abs_netpath($sOld)) {
1169 my $sSrc = $m_param_OutRoot . $sOld;
1170 my $sRelSrc = PathSubs::mk_relative_link($sFile, $sSrc);
1171 qq( href="$sRelSrc");
1175 } # replace_template_links
1177 sub mk_start_of_page($) {
1180 my $page_style = mk_style($pnum);
1181 my $page_js = mk_js($pnum);
1182 my $sFile = full_out_name($pnum);
1185 $head .= $page_style;
1186 $head .= get_head_from_file(full_in_name($pnum));
1187 $page .= header if !$m_param_files;
1188 $page .= replace_template_links($m_sStartTemplate, $sFile);
1189 $page =~ s!<title>HEAD</title>!$head!;
1190 my $focus_pnum = $pnum;
1191 my $ind_lev = $pages[$pnum][IND];
1192 if ($ind_lev > 50) { $focus_pnum = 0; }
1193 $page =~ s!%%PNUM%%!$focus_pnum!;
1195 } # mk_start_of_page
1197 my %m_sCreatedPages;
1198 sub page_src_time($) {
1200 my $src_file = $pages[$pnum][FULL_FIL];
1201 return (stat $src_file)[9];
1203 sub create_page($) {
1205 return unless $pages[$pnum][FULL_FIL];
1207 my $out_name = full_out_name($pnum);
1208 return if exists $m_sCreatedPages{$out_name};
1209 $m_sCreatedPages{$out_name} = 1;
1211 my $page = mk_start_of_page($pnum);
1212 my $cont_win = mk_content($pnum);
1213 my $main_win = mk_main_window($pnum);
1214 $page .= mk_main_table(
1222 $page = replace_name_link($page);
1230 ##########################################################
1231 ### Unused currently
1232 ##########################################################
1234 sub build_ShowPage() {
1235 for my $num (0..$#pages) {
1236 $page_num{$pages[$num][FULL_FIL]} = $num;
1237 my $fon = full_out_name($num);
1238 if ($fon) { $js_show_page{$fon} = "ShowPage($num);"; }
1244 sub mk_meta_enter_exit() {
1245 return <<__HTML_EE__;
1246 <meta HTTP-EQUIV="Page-Enter" content="RevealTrans (Duration=0.1, Transition=31)">
1247 <meta HTTP-EQUIV="Page-Exit" content="RevealTrans (Duration=1, Transition=23)">
1251 ##########################################################
1253 ##########################################################
1256 return <<__HTML_END_NOSCRIPT__;
1258 Sorry, there is not yet any version for non-JavaScript browsers.
1259 You need to enable JavaScript to see the rest of the pages!
1260 __HTML_END_NOSCRIPT__
1263 sub create_single_page($) {
1266 my $page = mk_start_of_page($pnum);
1269 for my $pi (0..$#pages) {
1270 next unless $pages[$pi][FULL_FIL];
1271 my $display = ($pi == $pnum ? 'style="display: block"' : 'Style="display: none"');
1272 my $pi_left_col = replace_rel_link(mk_content($pi), full_out_name($pi));
1273 my $pi_main = replace_rel_link(mk_main_window($pi), full_out_name($pi));
1275 $left_col .= "\n<div id='left_col_$pi' $display>" . $pi_left_col . "</div>\n";
1276 $main .= "\n<div id='main_$pi' $display>" . $pi_main . "</div>\n";
1278 my $search_table = qq[
1279 <table border="0" width="100%" height="200"
1280 cellpadding="0" cellspacing="0"
1282 class="html-wtoc-search"
1283 id="search" style="display:none">
1285 <td> </td>
1286 <td align="left" valign="top" height="1">
1287 <form onsubmit="return do_search(input.value);"
1288 class="html-wtoc-search-form"
1290 <input id="input" size="14"
1291 ><input type="image" name="Search" value="Search"
1293 src="img/search.gif"
1300 <td> </td>
1301 <td id="hits" valign="top">
1305 <td> </td>
1306 <td valign="bottom">
1308 <a href="javascript:hide_search()" xstyle="font-size: 8pt"
1310 ><img src="img/nosearch.gif" border=0 align="left"></a>
1311 <a href="javascript:hide_search()"
1318 $page .= mk_main_table(
1322 full_out_name($pnum),
1325 $page .= mk_noscript();
1327 $page =~ s/(\d+)\.html/javascript:ShowPage($1);/gs;
1328 #$page =~ s/<body(.*?)>/<body$1 onload="ShowPage(0)">/gis;
1329 $page =~ s/<body(.*?)>/<body$1 onload="HTML_WTOC_NS.onload_actions()">/gis;
1330 $page = replace_name_link($page);
1332 } # create_single_page
1336 <table border="$m_bBorders" cellpadding=0 cellspacing=0
1337 width="100%" height=70
1353 ##########################################################
1355 ##########################################################
1357 # sub mk_index_page($) {
1359 # my $check_browser = qq[ //if (document.all) { navigate("single_0.html"); }\n];
1360 # #$page =~ s/(<script.*?>)/$1\n$check_browser/s;
1361 # mkdir $m_param_OutRoot, 0777;
1362 # my $out_file = $m_param_OutRoot . "index.htm";
1363 # create_file_and_path($out_file, $page);
1369 ##########################################################
1371 ##########################################################
1374 sub replace_rel_link($$) {
1375 my ($page, $page_file) = @_;
1383 if (!PathSubs::is_abs_path($href)) {
1384 $href = PathSubs::mk_absolute_link($page_file, $href);
1386 if (exists $js_show_page{$href}) {
1387 $href = "javascript:$js_show_page{$href}";
1390 qq($src_href="$href");