--- burst.pl 2001/05/08 12:14:35 1.12 +++ burst.pl 2001/09/04 23:10:55 1.19 @@ -53,7 +53,7 @@ ## ## show debug output -my $debug=1; +my $debug=0; ## default DOCTYPE added on the slides $doctype = ''; @@ -133,45 +133,55 @@ my %page_data; my %overview_data; +my $pack = 0; +my @pack_additional; # additional files to pack (pictures, logos...) +my %nesttag = init_nesttag(); + ############################################################################## ## 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 +my @file; -# 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 = ; - @PARAM = (); +############################################################################## +sub parse_infos { + my @file=@_; do { if ($file[0] && $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"; + my ($var,$value) = split(/ *= */,$file[0],2); + $value=~s/'/\\'/g; + $cmd="\$$var = \'$value\';"; + if (defined($value)) { + eval($cmd) || warn "problem with eval of: $cmd"; + } else { + die "no value defined for $var"; + } + print STDERR "$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) { - my ($var,$value) = split(/ *= */,$_,2); - $value=~s/'/\\'/g; - $cmd="\$$var = \'$value\';"; - if ($value) { - eval($cmd) || die "problem with eval of: $cmd"; - } else { - die "no value defined for $var"; - } +parse_infos(@ARGV); # backward compatibility and for pack + +# read parameters from infos.txt and put them in @PARAM +if (open(INFOS, $infos)) { + print STDERR "--- Reading parameters file $infos ---\n"; + @file = ; + parse_infos(@file); +} + +# try to read local infos.txt for template +if (-f "$template/$infos" && open(INFOS,"$template/$infos")) { + print STDERR "--- Reading template parameters file $template/$infos ---\n"; + @file = ; + parse_infos(@file); + close(INFOS); } +## @PARAM is now a table with the user preferences for his presentation + ## use charset if ($charset) { @@ -180,6 +190,7 @@ $http_equiv=''; } + ############################################################################## ## read the raw html presentation ## @@ -197,6 +208,14 @@ ## they do not need to show up on the slides $buf =~ s///sgo; +## if $pack is set, output name of css (for inclusion in archive), but +## reset $cssStandard only to filename (without path) + +if ($pack) { + push @pack_additional,$cssStandard; + $cssStandard =~ s/^.*\/([^\/]+)$/$1/g; +} + ## 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 and as separator (ignores attributes!) @@ -216,7 +235,7 @@ ############################################################################## ## processing the slides -print STDOUT "\n--- Processing $total slides ---\n"; +print STDERR "\n--- Processing $total slides ---\n"; ## generate the header table of content of the presentation ## which is also the first page of the talk @@ -245,7 +264,7 @@ my $tmp = $table[($i*2)].$table[($i*2)+1]; while ($tmp =~ s,,,i) { $anchor_on_slide{$1}=($i+1); - print "\tslide ",($i+1)," anchor: $1\n" if ($debug); + print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug); } } @@ -324,8 +343,10 @@ ## and would not work on all platforms (ie would fail on Joe's laptop) &generateTOC; +## print additional files to pack +print STDOUT join("\n",@pack_additional) if ($pack); -print STDOUT "--- Finished ---\n"; +print STDERR "--- Finished ---\n"; exit 0; ## ## end of the slidemaker main program @@ -339,6 +360,7 @@ { ## open the file to write to open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!"; + push @pack_additional,"$_[0].html" if ($pack); ## the style sheet used in the table of content is $stylelink = ""; @@ -367,11 +389,12 @@ author => $author, authorUrl => $authorUrl, author2 => $author2, - authorUrl2 => $authorUrl2, + author2Url => $author2Url, date => $date, - toc => $loc_toc, + toc_title => $loc_toc, + template_dir => "$template/", ); } @@ -388,6 +411,7 @@ $overview_data{toc_entries} = [ @toc_entries ]; my $page= new Text::FastTemplate key => 'overview'; + $page_data{template_dir}='' if ($pack); print FOO $page->output( \%overview_data ); close(FOO); @@ -503,12 +527,14 @@ $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle; $status =~ s/<[^>]+>//g; - print STDOUT $status; + print STDERR $status; - &verify_html($content); # check the html + &verify_html($content); # check the html + &check_tags($content); # check open and closed tags ## write to the slide open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!"; + push @pack_additional,"slide$nr.html" if ($pack); my $toc_link = "$overview\.html"; @@ -563,17 +589,19 @@ toc_link => $toc_link, next_link => $next_link, prev_title => $prev_title, + toc_title => $loc_toc, next_title => $next_title, author => $author, authorUrl => $authorUrl, author2 => $author2, - authorUrl2 => $authorUrl2, + author2Url => $author2Url, date => $date, slide_html => $slide_html, + template_dir => "$template/", ); my $page; @@ -582,8 +610,9 @@ } else { $page= new Text::FastTemplate key => 'title'; } + $page_data{template_dir}='' if ($pack); print SLIDE $page->output( \%page_data ); - + extract_files($page->output( \%page_data )) if ($pack); close(SLIDE); return 0; } @@ -631,8 +660,8 @@ if ($_[0] =~ /]*)>/im) { if (!($1 =~ /ALT=/im)) { - print STDOUT "WARNING: without ALT\n"; - print STDOUT " \n" ; + print STDERR "WARNING: without ALT\n"; + print STDERR " \n" ; } } } @@ -669,7 +698,7 @@ my $pcnt_done=int($nr*100/$total); my $pcnt_left=100-$pcnt_done; - if ($progress_bar) { + if ($progress_bar && uc($progress_bar) ne "NO") { my $l=$r=" "; my $t="$nr of $total"; if ($pcnt_done > 50) { @@ -677,7 +706,14 @@ } else { $r=$t; } - $html='
'.$l.''.$r.'
'; + $html=''; + if ($pcnt_done != 0) { + $html.=''; + } + if ($pcnt_left != 0) { + $html.=''; + } + $html.='
'.$l.''.$r.'
'; } else { $html="$loc_slide $nr $loc_of $total"; } @@ -686,9 +722,131 @@ } ############################################################################## -# make slide progress bar +# remove anchors
from html (for titles) sub remove_anchor { my $tmp = $_[0]; $tmp =~ s/(.*)]*>(.*)<\/A>(.*)/$1$2$3/ig; return $tmp; } + +############################################################################## +# extract files referenced in presentation + +sub extract_files { + my $tmp = $_[0]; + while ($tmp =~ s/href="*([^"\s]+)"*//ism || + $tmp =~ s/src="*([^"\s]+)"*//ism) { + if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) { + push @pack_additional,$1; + } + } +} + +############################################################################## +# check tags in slide +# based on code from hindent 1.1.2 by Paul Balyoz + +sub init_nesttag { +# Tags that require their own end tag ... we will nest them +# properly: (WARNING, you must use lower-case here) +# All other tags (not on this list) will be ignored for indenting purposes. +return ( + 'html' => 1, + 'head' => 1, + 'body' => 1, + 'title' => 1, + + 'a' => 1, + + 'table' => 1, + 'tr' => 1, + 'th' => 1, + 'td' => 1, + + 'form' => 1, + 'select' => 1, + 'textarea' => 1, + +# 'p' => 1, Don't do this one because many people use

but not

+ 'ul' => 1, + 'ol' => 1, + 'dl' => 1, + 'blockquote' => 1, + 'center' => 1, + 'div' => 1, + + 'font' => 1, + 'pre' => 1, + 'tt' => 1, + 'i' => 1, + 'b' => 1, + 'u' => 1, + 'strike' => 1, + 'big' => 1, + 'small' => 1, + 'sub' => 1, + 'sup' => 1, + 'em' => 1, + 'strong' => 1, + 'dfn' => 1, + 'code' => 1, + 'samp' => 1, + 'kbd' => 1, + 'var' => 1, + 'cite' => 1, + + 'h1' => 1, + 'h2' => 1, + 'h3' => 1, + 'h4' => 1, + 'h5' => 1, + 'h6' => 1, + + 'applet' => 1, + + 'map' => 1, + + 'frameset' => 1, + 'noframes' => 1, +); +} + +sub check_tags { + my $tmp = $_[0]; + my @tagstack; + my $level=0; + + while ($tmp =~ /<(.*?)>/gsm) { + my $tag=$1; $tag=~s/\s.+//g; + # if regular tag, push it on stack; if end-tag, pop it off stack. + # but don't do any of this if it's not a special "nesting" tag! + if ($tag !~ m,^/,) { + if ($nesttag{lc($tag)}) { + push @tagstack,$tag; + $level++; # remember how much for later + } + } else { + $tag =~ s,^/,,; # convert this end-tag to a begin-tag + $tag = lc($tag); + if ($nesttag{lc($tag)}) { + # throw away tags until we find a match + if ($#tagstack > -1) { + while ($tag ne lc(pop @tagstack)) { + $level--; # we threw away extra tags + last if $#tagstack <= 0; + } + $level--; # we threw away extra tags + if ($level < 0) { + print STDERR "WARNING: more end than begin tags around !\n"; + } + } + } + } + } + + if ($level > 0) { + print STDERR "WARNING: level=$level, ", $#tagstack+1," tags left on stack after done parsing! Specifically:\n<",join("> <",@tagstack),">\n"; + } + +} +