#!/usr/local/bin/perl
#
# $Id: w3cburst.pl,v 1.1 2001/02/06 11:59:49 ivan Exp $
# $Log: w3cburst.pl,v $
# Revision 1.1  2001/02/06 11:59:49  ivan
# *** empty log message ***
#
# Revision 1.1  2001/02/01 15:17:00  ivan
# *** empty log message ***
#
# Revision 1.1  2000/12/23 10:56:26  ivan
# Initial revision
#
#
# Copyright 1999 World Wide Web Consortium,
# (Massachusetts Institute of Technology, Institut
# National de Recherche en Informatique et en
# Automatique, Keio University). All Rights Reserved.
# This program is distributed under the W3C's
# Intellectual Property License. This program is
# distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See W3C License
# http://www.w3.org/Consortium/Legal/ for more details.
#
##############################################################################
#
# slidemaker tool
# split a all.htm into slide*.htm
#
# Stephan Montigaud - stephan@w3.org
# created 970601
# modified by Pierre Fillault
# check the documentation at http://www.w3.org/Talks/YYMMsub/
#
# modified 19990505 Bert Bos: ALT text of prev/next arrows is now
# "prev"/"next" rather than the title of the prev/next slide; looks better
# in lynx.
#
# version: 4.14 - 19990719
# $Id: w3cburst.pl,v 1.1 2001/02/06 11:59:49 ivan Exp $
#
# modified 20001028 Ivan Herman: took out the alternative style button if only
# one style file is used
#
# modified 20001104 Ivan Herman: added the filter feature. The class properties are also
# searched for in <h1>-s and:
#    - if none, the slide is generated
#    - else if exists and is one of values of the 'accept' property in info.txt, the slide
#      is accepted
#    - otherwise the slide is not generated
#
# modified 20001112 Ivan Herman: there was a bug in the previous version...
#
# modified 20010123 Ivan Herman: allows severl 'accept' statements in the info.txt file
# and accumulate the contents
#
#
# NOTE: all the anchors in this tool contain the extension
# indeed this package has to work outside the environment of a web server
# Users need to be able to display their presentation using file:\\
# which requires link to 'real' files

##############################################################################
## default values of variables
##

## default DOCTYPE added on the slides
$doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';

## name of raw HTML file containing the slides
$all = 'all.html';

## name of the slide classes which are to be accepted
$accept = '';

## table of content built from all.htm - also first page of the presentation
## this is only the basename as we need to generate one toc for each style sheets
## the main toc will not bear any more so the server can understand a request for '/'
## the next ones will bear a number corresponding to the slide index
$overview = 'overview';

## name of the file containing the parameters of the presentation
$infos = 'infos.txt';

## link to the logo printed on all the slides
$logoLink = 'http://www.w3.org/';

## default location of the logo - works when slidemaker is used as a package
$logoFile = '../Icons/w3c_home.gif';

## if slidemaker is used online, then the location of the logo is likely to be different
## than the default
if (! -f $logoFile) {
	# if the logo is not found, then we're likely to find it
	# at /Talks/Icons/ for W3C AFS users
	$logoFile = '/Talks/Icons/w3c_home.gif';
}

## alternate representation of the logo
$logoAlt = 'W3C ';

## default values set to none
$logoLink2 = '';     # link to a potential second reference
$logoFile2 = '';     # location of a second logo
$logoAlt2  = '';     # alternate representation of the second logo

## navigation icons used in the slides
$left   = '../icons/left.gif';
$right  = '../icons/right.gif';
$top    = '../icons/up.gif';
$toc    = '../icons/toc.png';
$bar    = '../icons/bar.gif';
$barl   = '../icons/barl.gif';
$change = '../icons/change.png';

## for online use on the W3C site
if (! -d '../Icons') {
	## the icons will be present at this default location
	$left   = '/Talks/icons/left.gif';
	$right  = '/Talks/icons/right.gif';
	$top    = '/Talks/icons/up.gif';
	$toc    = '/Talks/icons/toc.png';
	$bar    = '/Talks/icons/bar.gif';
	$barl   = '/Talks/icons/barl.gif';
	$change = '/Talks/Icons/change.png';
}

## default accesskeys for navigation icons used in the slides
$prevKey  = 'P';	# accesskey for previous slide
$nextKey  = 'N';	# accesskey for next slide
$tocKey   = 'C';	# accesskey for table of contents
$styleKey = 'S';	# accesskey for changing style sheets

## default author name
$author = '';

## default presentation title
$talkTitle = 'W3C Talk';

## standard style sheets 
$cssStandardFiles = '../tools/w3ctalk-640w.css,../tools/w3ctalk-800w.css,../tools/w3ctalk-1024w.css';
if (! -d '../Tools') {
	## online location for W3C use
	$cssStandardFiles = '/Talks/Tools/w3ctalk-640w.css,/Talks/Tools/w3ctalk-800w.css,/Talks/Tools/w3ctalk-1024w.css';
}

## default charset use in meta tag http-equiv
$charset = 'ISO-8859-1';

## default language setting is English 
$baselang = 'en-US';

## HTML page color characteristics (background, text, link, visited link, active link)
#$body = '<body bgcolor="#000060" text="#ffffff" link="#ffffe8" vlink="#eeffee" alink="#ff0000">';
$body = '<body>';

## end of default values for the presentation
##############################################################################

##############################################################################
## reading user input from $infos
##
@PARAM = @ARGV; # we keep this for backward compatibility with an old version
                # of the slidemaker tool
                #when the parameters were in Makefile or make.bat

# read parameters from infos.txt and put them in @PARAM
if (open(INFOS, $infos)) {
    print STDOUT "--- Reading parameters file $infos ---\n";
    local(@file,$counter);
    $counter = 0;
    @file = <INFOS>;
    @PARAM = ();
    do {
    	if ($file[0] =~ /^[^#\n\r]/) {
    	   $file[0] =~ s/\n//;    # remove UNIX \n 
    	   $file[0] =~ s/\r//;    # remove WINDOWS \r    
    	   $file[0] =~ s/ *= */=/;
    	   $PARAM[$counter++] = $file[0];
    	   print "$file[0]\n";
    	}
    } while (shift(@file));
}
## @PARAM is now a table with the user preferences for his presentation

## process arguments
## each preset variable is now re-attributed using the user preferences
foreach (@PARAM) {
    @_ = split(/ *= */);
		# The 'accept' value has to be treated separately: the values should be accumulated
    if( $_[0] eq "accept" ) {
    	$cmd="\$$_[0] = \$$_[0].\",\".\'$_[1]\';";
    } else {
    	$cmd="\$$_[0] = \'$_[1]\';";
    }
    if (length $_[1] != 0) { 
	    eval($cmd);
    }
}

## save the style sheet file locations into tables 
@cssStandard = split(',',$cssStandardFiles);
$nbCssStandard = $#{@cssStandard} +1;
@cssUser = split(',',$cssUserFiles);
$nbCssUser = $#{@cssUser} +1;

## build an html string for the author variable
## containing the presentation author name linked to
## a location of his choice
if ($authorUrl) {
    $author = "<a href=\"$authorUrl\">$author</a>";
}

## same string is built if there is a second author for the presentation 
if ($author2 && $author2Url) {
    $author2 = "<a href=\"$author2Url\">$author2</a>";
}

## put both authors together
if ($author2) {
    $author = $author." &amp; ".$author2;
}

##############################################################################
## read the raw html presentation
##

## copy file in memory
my $sep = $/;
$/ = undef;
if (!open(ALL, $all)) {
    print "Error: Cannot open file: $all\n";
    exit 0;
}
my $buf = <ALL>;
close(ALL);
$/ = $sep;

## Remove comments from the raw presentation
## they do not need to show up on the slides
$buf =~ s/<!--.*?-->//sgo;

## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
## if not it will generate a rather weird output
## split using <h1...> and </h1...> as separator (ignores attributes!)
## h1 or H1 can be used
## The result is a table containing, alternatively, the content of the <h1> tags and
## the rest of the slide.
##
## Ivan Herman: I have modified the expression, so that the attributes are kept, with the
## ugly consequence that the ending '>' is also left in the table element. This has to
## be cleaned later.
@table = split(/<\/?[hH]1[ ]*/, $buf);

## This is the array of accept filters
@accept = split(/,/,$accept);

## Accepted headers are stored separately to be used as tooltips for the
## next slide
@tooltips = ();

## Clean up the filters:
foreach(@accept) {
    $_ =~ s/\n+/ /g;    ## replace return character by a white space 
    $_ =~ s/ +/ /g;     ## concatenate several white spaces to only one
    $_ =~ s/^ //;       ## remove starting whitespace
    $_ =~ s/ $//;       ## get ending whitespace out
}

## compute the total number of slides

## Ivan Herman:
## The simple calculation for total had to be changed to take into account
## the possible accept filter. The titles have to be checked against a (possible)
## class attribute
$total = 0;
## Some slides have to be skipped; for the accepted ones, the
## starting class and the ending '>' have to be removed
$header=0;
NUM_SLIDES: foreach(@table) {
    if( $header == 1 ) {
        $header = 0;
        $accepted = 0;
        if( /^>.*/ || /^[ ]*id=".*"[ ]*>.*/ ) { ## this is a simple title, to be accepted:
            $accepted = 1;
        } else {
            if( $accept ) { ## The possible class property has to be checked:
                $tempAccept = $_;
                $tempAccept =~ s/^class="([a-zA-Z0-9_]*)".*>.*/\1/;
                foreach(@accept) {
                    if( $tempAccept eq $_ ) {
                        $accepted = 1;
                    }
                }
            } else {
                $accepted = 1;  ## Everything has to be accepted!
            }
        }
								#print ; print "; accepted: ".$accepted."\n";

        if( $accepted == 1 ) {
            $tooltip = $_;
            $tooltip =~ s/.*>//;
            $total++;
            $tooltips[++$#tooltips] = $tooltip;
        }
    } else {
        $header = 1;
    }
}

## The first element in the tooltips does not count, we can disregard it:
shift(@tooltips);


##
## raw presentation has been read successfully
##############################################################################

##############################################################################
## processing the slides
 
print STDOUT "\n--- Processing $total slides ---\n"; 

## generate the header table of content of the presentation
## which is also the first page of the talk
&openOverview($overview);

## start the slide count so we can number them
$slideCount = 1;


## @table is the array containing each slide with its title
## for each slide to be generated
## we delete each slide and its title when generated
## so that the current slide and its title are always at $table[0] (for the title)
## and $table[1] (for the slide content)
##
## Ivan Herman: I had to change the the original do {..} while structure into
## a for(;..;..){..} structure, because that is the only way in Perl to break the
## loop
## do {
NEXT_SLIDE: for(;$#table != 0;shift(@table)) {
    ## get rid of the first element contained by the raw presentation array
    shift(@table);

    
    ## Some slides have to be skipped; for the accepted ones, the
    ## starting class and the ending '>' have to be removed
    if( $table[0] =~ /^>.*/ ||
        $table[0] =~ /^[ ]*id=".*"[ ]*>.*/ ) { ## this is a simple title, to be accepted:
        $table[0] =~ s/.*>//;
    } else {
        $tempAccept = $table[0];
        $tempAccept =~ s/^class="(.*)">.*/\1/;
        $table[0]   =~ s/^class.*>//;  ## just cut the class property
        if( $accept ) { ## The possible class property has to be checked:
            $accepted   = 0;
            foreach(@accept) {
                if( $tempAccept =~ $_ ) {                    
                    $accepted = 1;
                }
            }
            if( $accepted == 0 ) {
                next NEXT_SLIDE;
            }
        }
    }
    

    ## then $table[0] is the title of the slide to be generated
    $table[0] =~ s/\n+/ /g;    ## replace return character by a white space 
    $table[0] =~ s/ +/ /g;     ## concatenate several white spaces to only one
    $table[0] =~ s/^ //;       ## remove all the starting white spaces in the title
    $table[0] =~ s/ $//;       ## remove all trailing white spaces in the title
    ## $slideTitle preserves link(s) in the title
    $slideTitle = $table[0];
    
    ## need to check if the title contains any anchor
    ## if so it needs to be removed
    ## because the title is being used in the table of content to link to the corresponding slide
    $table[0] =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;

    ## grab next slide title $table[2] (if there's a next slide)
    ## to be able to use in the 'next' navigation button
    ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]

    ## Ivan Herman: the possible class and/or id part of the title should be taken out
    ## so I changed the original assignment
    $next_slide_title = shift(@tooltips);
    
    ## remove any anchor from the next slide title
    $next_slide_title =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/i;

    ## add the title of the current slide to the table of content
    &addTitle("$table[0]",$slideCount);

    ## the current slide content is stored $table[1]
    
    ## Ivan Herman: the first character is a ">", a leftover of the split,
    ## this has to be removed first:
    $table[1] =~ s/^.*>//;
    
    ## there is an attempt to make sure it's clean HTML
    ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
    ## to make use of the validation service
    $slideContent = &clean_html($table[1]) ;

    ## generate the current slide
    ## parameters are:
    ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
    &createSlide("$slideTitle",$slideContent ,$slideCount++,$previous_slide_title,$next_slide_title);

    ## save the title of the previous slide to be displayed in the 'previous' navigation button
    $previous_slide_title="$table[0]";
}
## process the next slide 
##while (shift(@table));

## close the table of content
&closeOverview;

## generate more toc with the all the style sheets
## as there's no way of loading a style sheet
## except dynamically, but that would be slow
## and would not work on all platforms (ie would fail on Joe's laptop)
&generateTOC;


print STDOUT "--- Finished ---\n";
exit 0;
##
## end of the slidemaker main program
##############################################################################


##############################################################################
## generate the header of the table of content

sub openOverview 
{
    ## open the file to write to
    open(FOO, ">$_[0].html");

    ## the style sheet used in the table of content is
    $stylelink = "";
    ## here is the standard style sheet
    $stylelink .= "<link href=\"$cssStandard[$0]\" rel=\"stylesheet\" type=\"text/css\" title=\"W3C Talk\" />";
    ## we overload with the user css if it exists
    if ($cssUser[$0]) {
	$stylelink .= "\n<link href=\"$cssUser[$0]\" rel=\"stylesheet\" type=\"text/css\" title=\"W3C Talk\" />";
    }

    print FOO <<END;
$doctype
<html lang="$baselang" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-type" content="text/html; charset=$charset" />
<title>$talkTitle - Slide list</title>
$stylelink
</head>
$body
END

    ## if there's only one logo to put on the toc
    if (length $logoFile2 == 0) {
        print FOO <<END;
<div class="headerSection">
      <div class="headerLogo">
<a href="$logoLink"><img src="$logoFile" align="bottom"  alt="$logoAlt" /></a>
</div>
</div>

END
    } else {
     ## the user chose a second logo
        print FOO <<END;
<div class="headerSection">
      <div class="headerLogo">
<p><a href="$logoLink"><img src="$logoFile" align="bottom"  alt="$logoAlt" /></a>&nbsp;
<a href="$logoLink2"><img src="$logoFile2" align="bottom"  alt="$logoAlt2" /></a></p>
</div>
</div>

END
	}
print FOO <<END;

<h1 align="center" class="slideList">$talkTitle
</h1>

<h2>Table of contents</h2>

<ul>
END
}
##
## the beginning of the table of content has been generated and saved
##############################################################################

##############################################################################
## generate the footer of the table of content

sub closeOverview
{
	print FOO <<END;
</ul>

</body>
</html>
END
    close(FOO); 
}
##
## the toc has been completed and saved
##############################################################################

##############################################################################
## add an item in the toc

sub addTitle 
{
    $_[0] =~ s/\r//ig;      # remove the windows CR+LF 
    $_[0] =~ s/<[^>]+>//g;
    if (length $_[0] == 0) {
	return 1;
    }
    # add accesskey for first 9 slides (`1' - `9'), and tabindex for all slides
    if ($_[1] < 10) {
    print FOO <<END;
<li class="toc"><a accesskey="$_[1]" tabindex="$_[1]" href="slide$_[1]-0.html">$_[0]</a></li>
END
    } else {
    print FOO <<END;
<li class="toc"><a tabindex="$_[1]" href="slide$_[1]-0.html">$_[0]</a></li>
END
    }
}
##
##############################################################################

##############################################################################
## generate the current slide

sub createSlide 
{

    # parameters are respectively the slide title, its content,
    # its number, the next slide title and the previous slide title
    if (length $_[0] == 0) {
        return 1;
    }

    # work the slide title, the previous and next titles
    $_[0] =~ s/\r//ig;      # remove the windows CR+LF 
    $_[3] =~ s/\r//ig; 
    $_[4] =~ s/\r//ig;
    $title = $_[0];

    # Remove any tags from the prev & next titles
    $_[3] =~ s/<[^>]+>//g;
    $_[4] =~ s/<[^>]+>//g;
    $title =~ s/<[^>]+>//g;

    # Replace double quotes
#   $_[0] =~ s/"/&#34;/g;
    $_[3] =~ s/"/&#34;/g;
    $_[4] =~ s/"/&#34;/g;

    # work the slide content
    $_[1] =~ s/<\/body>//i; # remove if any
    $_[1] =~ s/<\/html>//i; # remove if any

    $status = sprintf "Slide %2d: %s\n", $_[2], $_[0];
    $status =~ s/<[^>]+>//g;
    print STDOUT $status;

    &verify_html($_[1]);    # check the html

    ## we create as many slides as there are css files
    ## Pierre note: it'd be much nicer to have only one slide
    ## which could dynamically load the css file, but ...
    my $cNumber = 0;
    for ($i=0;$i<$nbCssStandard;$i++) {
    $cNumber = $i+1;
    $cNumber = 0  if ($i == $nbCssStandard-1);

    ## write to the slide
    open(SLIDE, ">slide$_[2]-$i.html");

    local($navBar);
    local($MiniNavBar);
    local($toclink);
    local($prevlink);
    local($nextlink);

    ## navigation bar with icons to previous slide, toc and next slide
    $navBar = "\n\n";

    ## at the same time, build a mini-navbar for the bottom. --CMN 19991102
##    $MiniNavBar = "<td valign=\"top\" nowrap>\n<div align=\"right\">\n";
			$MiniNavBar = "\n\n";
    ## the toc link needs to match the slide index
    ## so that the style sheets match between the slides and the toc
    $toclink = "<link rel=\"contents\" href=\"$overview\.html\" title=\"Contents\" />";

    ## initialization of the navigation links
    $nextlink = "";
    $prevlink = "";

    if ($_[2]>1) {
    	$prevlink = "<link rel=\"previous\" href=\"slide".eval($_[2]-1)."-$i.html\" title=\"Previous\" />";
    	$navBar .= "<a rel=\"previous\" href=\"slide".eval($_[2]-1)."-$i.html\" accesskey=\"$prevKey\"><img src=\"$left\"  width=\"32\" height=\"32\" alt=\" previous\" title=\"Back to &#34;$_[3]&#34;\" /></a>";
    	$MiniNavBar .= "<a rel=\"previous\" href=\"slide".eval($_[2]-1)."-$i.html\" accesskey=\"$prevKey\"><img src=\"$left\"  width=\"32\" height=\"32\" alt=\" previous\" title=\"Back to &#34;$_[3]&#34;\" /></a>";
    } else {
        ## add a link back to the toc for the first slide --CMN 19991102
    	$prevlink = "<link rel=\"previous\" href=\"$overview\.html\" title=\"Previous\" />";
    	$navBar .= "<a rel=\"previous\" href=\"$overview\.html\" accesskey=\"$prevKey\"><img src=\"$left\"  width=\"32\" height=\"32\" alt=\" previous\" title=\"Back to &#34;$_[3]&#34;\" /></a>";
    	$MiniNavBar .= "<a rel=\"previous\" href=\"slide".eval($_[2]-1)."-$i.html\" accesskey=\"$prevKey\"><img src=\"$left\"  width=\"32\" height=\"32\" alt=\" previous\" title=\"Back to &#34;$_[3]&#34;\" /></a>";
    }


    if ($i == 0) {
   	    ## we're using the first css file, so no need to number the toc
        $navBar = $navBar."<a rel=\"contents\" href=\"$overview\.html\" accesskey=\"$tocKey\"><img src=\"$toc\"  width=\"32\" height=\"32\" alt=\" contents\" title=\"Table of Contents\" /></a>";
    } else {
        ## change $toclink
        $toclink = "<link rel=\"contents\" href=\"$overview-$i\.html\" title=\"Contents\" />";
        ## we're using another css, the toc needs to match
	    $navBar = $navBar."<a rel=\"contents\" href=\"$overview-$i\.html\" accesskey=\"$tocKey\"><img src=\"$toc\"  width=\"32\" height=\"32\" alt=\" contents\" title=\"Table of Contents\" /></a>";
    }
    ## add style change before the "next" button --CMN 19991102
    ## However, this is necessary only if there are several style files! --IH 20001028
    if ($i != 0 ) {
	    $navBar .= "<a href=\"slide".eval($_[2])."-$cNumber.html\" accesskey=\"$styleKey\"><img src=\"$change\"  width=\"32\" height=\"32\" alt=\" change-style\" title=\"change style\" /></a>";
    }
    
    if ($_[2] != $total) {
    	$nextlink = "<link rel=\"next\" href=\"slide".eval($_[2]+1)."-$i.html\" title=\"Next\" />";
    	$navBar .= "<a rel=\"next\" href=\"slide".eval($_[2]+1)."-$i.html\" accesskey=\"$nextKey\"><img src=\"$right\"  width=\"32\" height=\"32\" alt=\" next\" title=\"On to &#34;$_[4]&#34;\" /></a>";
    	$MiniNavBar .= "<a rel=\"next\" href=\"slide".eval($_[2]+1)."-$i.html\" accesskey=\"$nextKey\"><img src=\"$right\"  width=\"32\" height=\"32\" alt=\" next\" title=\"On to &#34;$_[4]&#34;\" /></a>";
    } else {
        $navBar .= "<img src=\"$right\"  width=\"32\" height=\"32\" alt=\"no more \" title=\"The end.\" />";
        $MiniNavBar .= "<img src=\"$right\"  width=\"32\" height=\"32\" alt=\"no more \" title=\"The end.\" />";
    }

    $stylelink = "";
    # here is the standard style sheet
    $stylelink .= "<link href=\"$cssStandard[$i]\" rel=\"stylesheet\" type=\"text/css\" title=\"W3C Talk\" />";
    # we overload with the user css if it exists
    if ($cssUser[$i]) {
    	$stylelink .= "\n<link href=\"$cssUser[$i]\" rel=\"stylesheet\" type=\"text/css\" title=\"W3C Talk\" />";
    }

    print SLIDE <<END;
$doctype
<html lang="$baselang" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=$charset" />
<title>$talkTitle - slide "$title"</title>
$nextlink
$prevlink
$toclink
$stylelink
</head>
$body
<div class="headerSection">
      
END

    if (length $logoFile2 == 0) {
        print SLIDE <<END;
				<div class="headerLogo">
<p><a href="$logoLink"><img src="$logoFile"  alt="$logoAlt " /></a></p>
</div>
END

    } else {
        print SLIDE <<END;
				<div class="headerLogo">
				
<p><a href="$logoLink"><img src="$logoFile" alt="$logoAlt" /></a>&nbsp;
<a href="$logoLink2"><img src="$logoFile2"  alt="$logoAlt2" /></a></p>
</div>
END

    }

print SLIDE <<END;

      <div class="headerNavBar">
<p>$navBar</p>
 </div>
    </div>
<div class="headerTitle">
<h1 class="slide">$_[0]</h1>

<hr class="top" />
</div>
<div class="slidebody">
$_[1]
</div>

<div class="footerSection">
<hr /> 
<!-- 
<div class="footerAuthor">
<p>$author</p>
</div>
 -->
 <div class="footerLogo">
          <!--===valid XHTML=== -->
          <p>
            <a href="http://validator.w3.org/check/referer"><img
            src="../logos/valid-xhtml10.png"
            alt="Valid XHTML 1.0!" height="31" width="88" /></a> 
            <!--===valid CSS ====-->
             <a href="http://jigsaw.w3.org/css-validator/"><img
            src="../logos/valid-CSS.png" alt="Valid CSS!"
            height="31" width="88" /></a> <!-- WAI - A -->
            <!--  <a href="http://www.w3.org/WAI/WCAG1A-Conformance"
            title="Explanation of Level A Conformance"><img height="32"
            width="88" src="../logos/wcag1A.gif"
            alt="Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0" />
            </a> -->
          </p>
        </div>
<div class="footerNumSlides"><p>$_[2]/$total</p></div>
<div class="footerNavBar"><p>$MiniNavBar</p></div>
</div>
</body>
</html>
END

    close(SLIDE);
  }
  return 0;
}

##############################################################################
## generate all the toc of contents needed for each css choosen by the user
## the default toc is not numbered so it can be served by a request to '/'
## (ie it remains Overview.htm whereas the other toc are called Overview_#.htm)

sub generateTOC {

	## read the general toc
	open(FOO, "<$overview.html"); 
	@TOC = <FOO>;
	close(FOO);
	$toc = "@TOC";

	## for each user CSS file
	## starting after the default css
    	for ($css=1;$css<$nbCssStandard;$css++) {

		## create new TOC
		$newTOC = $toc;

		## replace the style link with a new one	
		## <link href="/Talks/Tools/w3ctalk-640.css" rel="stylesheet" type="text/css" title="W3C Talk">
		## we eventually choose the user css file if any
		if (! $cssUser[$css]) {
			$newTOC =~ s/<link href=\"[^\"]*\" rel=\"stylesheet\" type=\"text\/css\" title=\"([^\"]*)\">/<link href=\"$cssStandard[$css]\" rel=\"stylesheet\" type=\"text\/css\" title=\"$1\">/ig;
		} else {
			$newTOC =~ s/<link href=\"[^\"]*\" rel=\"stylesheet\" type=\"text\/css\" title=\"([^\"]*)\">/<link href=\"$cssUser[$css]\" rel=\"stylesheet\" type=\"text\/css\" title=\"$1\">/ig;
		}

		## the links on the toc need also to be modified
		## to link to the correct slides
		$newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
		$newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;

		## write to new TOC
		$outfile = $overview."-".$css.".html";
		open(OUT, ">$outfile");
		print OUT $newTOC;
		close(OUT)
	}


}

##############################################################################
# check that the html of the slide 
# is correct (ALT tags, ...)
# This procedure produces only warning
sub verify_html {
    if ($_[0] =~ /<img([^>]*)>/im) {
    	if (!($1 =~ /alt=/im)) {
    	    print STDOUT "WARNING: <img> without alt\n";
    	    print STDOUT "         <img$1>\n" ;
    	}
    }
}

##############################################################################
# clean the html of the slide
# remove all <div class="comment">blabla</div>
sub clean_html {
    $_[0] =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
    return $_[0];
}


