/[PLies]/burst.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations)
Tue May 8 23:03:03 2001 UTC (22 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.13: +1 -1 lines
File MIME type: text/plain
recreate original presentation (after pack)

1 #!/usr/bin/perl
2 #
3 # PLies Copyright 2001 Dobrica Pavlinusic <dpavlin@rot13.org>
4 #
5 # this tool is based on SlideMaker and XLSies tool
6 # split a all.htm into slide*.htm
7 #
8 # For more information please see presentation about this tool on
9 # http://www.rot13.org/~dpavlin/presentations/XLSies_to_PLies/
10 #
11 # Copyright 1999 World Wide Web Consortium,
12 # (Massachusetts Institute of Technology, Institut
13 # National de Recherche en Informatique et en
14 # Automatique, Keio University). All Rights Reserved.
15 # This program is distributed under the W3C's
16 # Intellectual Property License. This program is
17 # distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied
19 # warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See W3C License
21 # http://www.w3.org/Consortium/Legal/ for more details.
22 #
23 #
24 ##############################################################################
25 #
26 # slidemaker credits:
27 #
28 # Stephan Montigaud - stephan@w3.org
29 # created 970601
30 # modified by Pierre Fillault
31 # check the documentation at http://www.w3.org/Talks/YYMMsub/
32 #
33 # modified 19990505 Bert Bos: ALT text of prev/next arrows is now
34 # "prev"/"next" rather than the title of the prev/next slide; looks better
35 # in lynx.
36 #
37 # version: 4.14 - 19990719
38 # $Id: w3cburst.pl,v 1.41 1999/11/02 17:25:50 charles Exp $
39 #
40 #
41 # XLSies credits:
42 #
43 # Sami Lempinen - lempinen@iki.fi
44 # http://www.snowman.sgic.fi/ssl/xslies/
45 #
46 # Text::FastTemplate:
47 # Robert Lehr - bozzio@the-lehrs.com
48
49 use Text::FastTemplate;
50
51 ##############################################################################
52 ## default values of variables
53 ##
54
55 ## show debug output
56 my $debug=0;
57
58 ## default DOCTYPE added on the slides
59 $doctype = '<html xmlns="http://www.w3.org/TR/REC-html40">';
60
61 ## name of raw HTML file containing the slides
62 $all = 'all.htm';
63
64 ## table of content built from all.htm - also first page of the presentation
65 ## this is only the basename as we need to generate one toc for each style sheets
66 ## the main toc will not bear any more so the server can understand a request for '/'
67 ## the next ones will bear a number corresponding to the slide index
68 #$overview = 'Overview';
69 $overview = 'index';
70
71 ## name of the file containing the parameters of the presentation
72 $infos = 'infos.txt';
73
74 ## link to the logo printed on all the slides
75 $logoLink = '';
76
77 ## default location of the logo - works when slidemaker is used as a package
78 $logoFile = '';
79
80 ### localization
81 $loc_toc = "Table of contents";
82 $loc_by = "by";
83 $loc_amp = "&amp;"; # author separator
84 $loc_slide = "Slide";
85 $loc_of = "of"; # $loc_slide nr $loc_of total
86
87 ## alternate representation of the logo
88 $logoAlt = '';
89
90 ## default values set to none
91 $logoLink2 = ''; # link to a potential second reference
92 $logoFile2 = ''; # location of a second logo
93 $logoAlt2 = ''; # alternate representation of the second logo
94
95 ## default accesskeys for navigation icons used in the slides
96 $prevKey = 'P'; # accesskey for previous slide
97 $nextKey = 'N'; # accesskey for next slide
98 $tocKey = 'C'; # accesskey for table of contents
99 $styleKey = 'S'; # accesskey for changing style sheets
100
101 ## default author name
102 $author = 'Staff';
103
104 ## default presentation title
105 $talkTitle = 'Talk';
106
107 ## standard style sheets
108 $cssStandard = '../PLies/css/default.css';
109
110 ## template name
111 $template = '../PLies/default';
112
113 ## default charset use in meta tag http-equiv (undef to skip)
114 #$charset = 'ISO-8859-1';
115
116 ## default <body> tag
117 $body = '<body>';
118
119 ## number of entries on each TOC page
120 $toc_on_page = 10;
121
122 ## use progress bar
123 $progress_bar = 1;
124
125 ## content hight for each slide
126 $content_hight = "70%";
127
128 ## end of default values for the presentation
129 ##############################################################################
130
131 ## globals
132 my $last_toc_title;
133 my %page_data;
134 my %overview_data;
135
136 my $pack = 0;
137 my @pack_additional; # additional files to pack (pictures, logos...)
138
139 ##############################################################################
140 ## reading user input from $infos
141 ##
142 @PARAM = @ARGV; # we keep this for backward compatibility with an old version
143 # of the slidemaker tool
144 #when the parameters were in Makefile or make.bat
145
146 # read parameters from infos.txt and put them in @PARAM
147 if (open(INFOS, $infos)) {
148 print STDERR "--- Reading parameters file $infos ---\n";
149 local(@file);
150 @file = <INFOS>;
151 # @PARAM = (); # don't reset param, use @ARGV
152 do {
153 if ($file[0] && $file[0] =~ /^[^#\n\r]/) {
154 $file[0] =~ s/\n//; # remove UNIX \n
155 $file[0] =~ s/\r//; # remove WINDOWS \r
156 $file[0] =~ s/ *= */=/;
157 push @PARAM,$file[0];
158 print STDERR "$file[0]\n";
159 }
160 } while (shift(@file));
161 }
162 ## @PARAM is now a table with the user preferences for his presentation
163
164 ## process arguments
165 ## each preset variable is now re-attributed using the user preferences
166 foreach (@PARAM) {
167 my ($var,$value) = split(/ *= */,$_,2);
168 $value=~s/'/\\'/g;
169 $cmd="\$$var = \'$value\';";
170 if ($value) {
171 eval($cmd) || die "problem with eval of: $cmd";
172 } else {
173 die "no value defined for $var";
174 }
175 }
176
177 ## use charset
178
179 if ($charset) {
180 $http_equiv='<meta http-equiv="Content-type" content="text/html; charset='.$charset.'">';
181 } else {
182 $http_equiv='';
183 }
184
185
186 ##############################################################################
187 ## read the raw html presentation
188 ##
189
190 ## copy file in memory
191 my $sep = $/;
192 $/ = undef;
193 open(ALL, $all) || die "Error: Cannot open file: $all";
194 my $buf = <ALL>;
195 $buf =~ s/\r//g; # remove WINDOWS \r
196 close(ALL);
197 $/ = $sep;
198
199 ## Remove comments from the raw presentation
200 ## they do not need to show up on the slides
201 $buf =~ s/<!--.*?-->//sgo;
202
203 ## if $pack is set, output name of css (for inclusion in archive), but
204 ## reset $cssStandard only to filename (without path)
205
206 if ($pack) {
207 push @pack_additional,$cssStandard;
208 $cssStandard =~ s/^.*\/([^\/]+)$/$1/g;
209 }
210
211 ## the slidemaker tool assumes that each slide is self contained between 2 sets of h1 tags
212 ## if not it will generate a rather weird output
213 ## split using <h1...> and </h1...> as separator (ignores attributes!)
214 ## h1 or H1 can be used
215 @table = split(/<\/?[hH]1[^>]*>/, $buf);
216
217 ## compute the total number of slides
218 $total = $#table / 2;
219 if ($#table % 2 != 0) {
220 $total = ($#table +1)/2;
221 }
222
223 ##
224 ## raw presentation has been read successfully
225 ##############################################################################
226
227 ##############################################################################
228 ## processing the slides
229
230 print STDERR "\n--- Processing $total slides ---\n";
231
232 ## generate the header table of content of the presentation
233 ## which is also the first page of the talk
234 &openOverview($overview);
235
236 ## start the slide count so we can number them
237 $slideCount = 1;
238
239 ## pre-load template slides using $template dir
240 Text::FastTemplate->defaults(
241 path => [ $template ]
242 );
243
244 Text::FastTemplate->preload( [
245 { file => 'slide.html', key => 'slide' },
246 { file => 'overview.html', key => 'overview' },
247 { file => 'title.html', key => 'title' },
248 ]);
249
250 ## unroll relative anchors (#something) into links with slides
251
252 my %anchor_on_slide;
253
254 ## step 1: record anchors
255 for($i=0; $i<$total; $i++) {
256 my $tmp = $table[($i*2)].$table[($i*2)+1];
257 while ($tmp =~ s,<a +name="*([^>"]+)"*>,,i) {
258 $anchor_on_slide{$1}=($i+1);
259 print STDERR "\tslide ",($i+1)," anchor: $1\n" if ($debug);
260 }
261 }
262
263 ## step 2: fix links
264 for($i=0; $i<$total; $i++) {
265 foreach (keys %anchor_on_slide) {
266 $table[($i*2)] =~ s,href="*#$_"*>,href="slide$anchor_on_slide{$_}\.html#$_">,gi;
267 }
268 }
269
270 ## @table is the array containing each slide with its title
271 ## for each slide to be generated
272 ## we delete each slide and its title when generated
273 ## so that the current slide and its title are always at $table[0] (for the title)
274 ## and $table[1] (for the slide content)
275
276 undef $prev_title;
277 undef $next_title;
278
279 do {
280
281 ## get rid of the first element contained by the raw presentation array
282 shift(@table);
283 ## then $table[0] is the title of the slide to be generated
284 $table[0] =~ s/\n+/ /g; ## replace return character by a white space
285 $table[0] =~ s/\r+/ /g; ## replace lf character by a white space
286 $table[0] =~ s/ +/ /g; ## concatenate several white spaces to only one
287 $table[0] =~ s/^ //; ## remove all the starting white spaces in the title
288 $table[0] =~ s/ $//; ## remove all trailing white spaces in the title
289 ## $slideTitle preserves link(s) in the title
290 $slideTitle = $table[0];
291 ## need to check if the title contains any anchor
292 ## if so it needs to be removed
293 ## because the title is being used in the table of content to link to the corresponding slide
294 $table[0] = remove_anchor($table[0]);
295
296 ## grab next slide title $table[2] (if there's a next slide)
297 ## to be able to use in the 'next' navigation button
298 ## keep in mind that $table[1] contains the slide corresponding to the title $table[0]
299 if ($table[2]) {
300 $next_title= remove_anchor($table[2]);
301 }
302
303 ## the current slide content is stored $table[1]
304 ## there is an attempt to make sure it's clean HTML
305 ## Pierre Fillault's note: use same piece of as used in http://www.w3.org/Web/Tools/CvsCommitScripting
306 ## to make use of the validation service
307 $slideContent = &clean_html($table[1]) ;
308
309 ## extract slide Sub Title <h2>
310 undef $slideSubTitle;
311 if ($slideContent =~ s/<[hH]2[^>]*>(.+)<\/[hH]2[^>]*>//sm) {
312 $slideSubTitle=remove_anchor($1);
313 }
314
315 ## add the title of the current slide to the table of content
316 &addTitle($slideTitle,$slideSubTitle,$slideCount);
317
318 ## generate the current slide
319 ## parameters are:
320 ## title of the slide, its content, the slide number, the title of the previous slide and the title of the next slide
321 &createSlide($slideTitle,$slideSubTitle,$slideContent ,$slideCount++,$prev_title,$next_title);
322
323 ## save the title of the previous slide to be displayed in the 'previous' navigation button
324 $prev_title=remove_anchor($table[0]);
325 }
326 ## process the next slide
327 while (shift(@table));
328
329 ## close the table of content
330 &closeOverview;
331
332 ## generate more toc with the all the style sheets
333 ## as there's no way of loading a style sheet
334 ## except dynamically, but that would be slow
335 ## and would not work on all platforms (ie would fail on Joe's laptop)
336 &generateTOC;
337
338 ## print additional files to pack
339 print STDOUT join("\n",@pack_additional) if ($pack);
340
341 print STDERR "--- Finished ---\n";
342 exit 0;
343 ##
344 ## end of the slidemaker main program
345 ##############################################################################
346
347
348 ##############################################################################
349 ## generate the header of the table of content
350
351 sub openOverview
352 {
353 ## open the file to write to
354 open(FOO, ">$_[0].html") || die "can't open $_[0].html: $!";
355 push @pack_additional,"$_[0].html" if ($pack);
356
357 ## the style sheet used in the table of content is
358 $stylelink = "";
359 ## here is the standard style sheet
360 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\" media=\"screen\">";
361
362 %overview_data = (
363 doctype => $doctype,
364 title => $title,
365 http_equiv => $http_equiv,
366 stylelink => $stylelink,
367 body => $body,
368
369 logoLink => $logoLink,
370 logoFile => $logoFile,
371 logoAlt => $logoAlt,
372 logoLink2 => $logoLink2,
373 logoFile2 => $logoFile2,
374 logoAlt2 => $logoAlt2,
375
376 talkTitle => $talkTitle,
377 talkSubTitle => $talkSubTitle,
378
379 content_hight => $content_hight,
380
381 author => $author,
382 authorUrl => $authorUrl,
383 author2 => $author2,
384 authorUrl2 => $authorUrl2,
385
386 date => $date,
387
388 toc => $loc_toc,
389 );
390
391 }
392 ##
393 ## the beginning of the table of content has been generated and saved
394 ##############################################################################
395
396 ##############################################################################
397 ## generate the footer of the table of content
398
399 sub closeOverview
400 {
401 $overview_data{slide_html} = make_progress_bar(0,$total);
402 $overview_data{toc_entries} = [ @toc_entries ];
403
404 my $page= new Text::FastTemplate key => 'overview';
405 print FOO $page->output( \%overview_data );
406
407 close(FOO);
408 }
409 ##
410 ## the toc has been completed and saved
411 ##############################################################################
412
413 ##############################################################################
414 ## add an item in the toc
415
416 sub addTitle
417 {
418 my ($title,$subtitle,$nr) = @_;
419 $title =~ s/\r//ig; # remove the windows CR+LF
420 $title =~ s/<[^>]+>//g;
421
422 if (! $title) {
423 return 1;
424 }
425
426 # split TOC entries to multiple pages
427
428 if ($nr % $toc_on_page == 0) {
429 my $toc_nr=int($nr/$toc_on_page);
430
431 $item = {
432 pre_html => $pre_ul,
433 accesskey => " ", # space
434 href => "index-toc$toc_nr.html",
435 title => "...",
436 post_html => $post_ul,
437 more => 1, # use style for more pages link (...)
438 };
439 push @toc_entries, $item;
440
441 &closeOverview;
442 undef @toc_entries;
443 &openOverview("$overview-toc$toc_nr");
444 $last_toc_title='';
445 }
446
447 $pre_ul=$post_ul='';
448 if ($last_toc_title eq $title && $subtitle) {
449 $title = $subtitle;
450 $pre_ul='<ul>';
451 $post_ul='</ul>';
452 } else {
453 $last_toc_title=$title;
454 }
455
456 # add accesskey for first 9 slides (`1' - `9') or just for first
457 # TOC page, and tabindex for all slides
458 if ($nr < 10 && $nr < $toc_on_page) {
459 $item = {
460 pre_html => $pre_ul,
461 accesskey => "$nr",
462 tabindex => "$nr",
463 href => "slide$nr.html",
464 title => $title,
465 post_html => $post_ul,
466 more => 0,
467 };
468 push @toc_entries,$item;
469 } else {
470 $item = {
471 pre_html => $pre_ul,
472 tabindex => "$nr",
473 href => "slide$nr.html",
474 title => $title,
475 post_html => $post_ul,
476 };
477 push @toc_entries,$item;
478 }
479 }
480 ##
481 ##############################################################################
482
483 ##############################################################################
484 ## generate the current slide
485
486 sub createSlide
487 {
488
489 # parameters are respectively the slide title, its content,
490 # its number, the next slide title and the previous slide title
491
492 my ($title,$subtitle,$content,$nr,$prev_title,$next_title) = @_;
493
494 if (! $title) {
495 return 1;
496 }
497
498 # work the slide title, the previous and next titles
499 chomp $title;
500 $title =~ s/\r//ig; # remove the windows CR+LF
501 $next_title =~ s/\r//ig;
502 $prev_title =~ s/\r//ig;
503
504 # Remove any tags from the prev & next titles
505 $next_title =~ s/<[^>]+>//g;
506 $prev_title =~ s/<[^>]+>//g;
507 $title =~ s/<[^>]+>//g;
508
509 # Replace double quotes
510 # $title =~ s/"/&#34;/g;
511 $next_title =~ s/"/&#34;/g;
512 $prev_title =~ s/"/&#34;/g;
513
514 # work the slide content
515 $content =~ s/<\/body>//i; # remove if any
516 $content =~ s/<\/html>//i; # remove if any
517
518 $status = sprintf "Slide %2d: %s %s\n", $nr, $title, $subtitle;
519 $status =~ s/<[^>]+>//g;
520 print STDERR $status;
521
522 &verify_html($content); # check the html
523
524 ## write to the slide
525 open(SLIDE, ">slide$nr.html") || die "can't save slide$nr.html: $!";
526 push @pack_additional,"slide$nr.html" if ($pack);
527
528 my $toc_link = "$overview\.html";
529
530 ## initialization of the navigation links
531 my $next_link = "";
532 my $prev_link = "";
533
534 if ($nr>1) {
535 $prev_link = "slide".($nr-1).".html";
536 # } else {
537 # ## add a link back to the toc for the first slide --CMN 19991102
538 # $prev_link = "$overview\.html";
539 }
540
541 if ($nr != $total) {
542 $next_link = "slide".($nr+1).".html";
543 }
544
545 $stylelink = "";
546 # here is the standard style sheet
547 $stylelink .= "<link href=\"$cssStandard\" rel=\"stylesheet\" type=\"text/css\" title=\"Talk\">";
548
549 my $slide_html=make_progress_bar($nr,$total);
550
551 # undefine body if no content is found (so that template can show
552 # only title and sub-title
553 if ($content !~ m/\S/g) {
554 undef $content;
555 }
556
557 %page_data = (
558 doctype => $doctype,
559 talkTitle => $talkTitle,
560 title => $title,
561 subtitle => $subtitle,
562 http_equiv => $http_equiv,
563 stylelink => $stylelink,
564 body => $body,
565
566 logoLink => $logoLink,
567 logoFile => $logoFile,
568 logoAlt => $logoAlt,
569 logoLink2 => $logoLink2,
570 logoFile2 => $logoFile2,
571 logoAlt2 => $logoAlt2,
572
573
574 content_hight => $content_hight,
575 content => $content,
576
577 prev_link => $prev_link,
578 toc_link => $toc_link,
579 next_link => $next_link,
580 prev_title => $prev_title,
581 next_title => $next_title,
582
583 author => $author,
584 authorUrl => $authorUrl,
585 author2 => $author2,
586 authorUrl2 => $authorUrl2,
587
588 date => $date,
589
590 slide_html => $slide_html,
591
592 );
593
594 my $page;
595 if ($content) {
596 $page= new Text::FastTemplate key => 'slide';
597 } else {
598 $page= new Text::FastTemplate key => 'title';
599 }
600 print SLIDE $page->output( \%page_data );
601 extract_files($page->output( \%page_data )) if ($pack);
602 close(SLIDE);
603 return 0;
604 }
605
606 ##############################################################################
607 ## generate all the toc of contents needed for each css choosen by the user
608 ## the default toc is not numbered so it can be served by a request to '/'
609 ## (ie it remains Overview.html whereas the other toc are called Overview_#.html)
610
611 sub generateTOC {
612
613 ## read the general toc
614 open(FOO, "<$overview.html");
615 @TOC = <FOO>;
616 close(FOO);
617 $toc = "@TOC";
618
619 ## for each user CSS file
620 ## starting after the default css
621 for ($css=1;$css<$nbCssStandard;$css++) {
622
623 ## create new TOC
624 $newTOC = $toc;
625
626 ## the links on the toc need also to be modified
627 ## to link to the correct slides
628 $newTOC =~ s/<a accesskey=\"(\d)\" tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a accesskey=\"$1\" tabindex=\"$2\" href=\"slide$3-$css\.html">/ig;
629 $newTOC =~ s/<a tabindex=\"(\d+)\" href=\"slide(\d+)-\d+\.html\">/<a tabindex=\"$1\" href=\"slide$2-$css\.html">/ig;
630
631 ## write to new TOC
632 $outfile = $overview."-".$css.".html";
633 open(OUT, ">$outfile");
634 print OUT $newTOC;
635 close(OUT)
636 }
637
638
639 }
640
641 ##############################################################################
642 # check that the html of the slide
643 # is correct (ALT tags, ...)
644 # This procedure produces only warning
645 sub verify_html {
646
647 if ($_[0] =~ /<img([^>]*)>/im) {
648 if (!($1 =~ /ALT=/im)) {
649 print STDERR "WARNING: <IMG> without ALT\n";
650 print STDERR " <IMG$1>\n" ;
651 }
652 }
653 }
654
655 ##############################################################################
656 # clean the html of the slide
657 # remove all <div class="comment">blabla</div>
658 sub clean_html {
659 my $tmp=$_[0];
660 $tmp =~ s/<div\s+class\s*=\s*(?:comment[\s>]|\"comment\").*?<\/div>//igs;
661 $tmp =~ s,</*font[^>]+>,,ig;
662 return $tmp;
663 }
664
665 ##############################################################################
666 # make transparent 1x1 gif (for layout tricks)
667 sub make_dotgif {
668 @dot_gif=(71,73,70,56,57,97,1,0,1,0,128,0,0,192,192,192,0,0,0,33,
669 249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
670 open(GIF,"> $_[0]") || die "can't write gif $_[0]: $!";
671 my $dotgif;
672 foreach (@dot_gif) {
673 $dotgif.=chr($_);
674 }
675 print GIF $dotgif;
676 close(GIF);
677 }
678
679 ##############################################################################
680 # make slide progress bar
681 sub make_progress_bar {
682 my ($nr,$total) = @_;
683
684 my $pcnt_done=int($nr*100/$total);
685 my $pcnt_left=100-$pcnt_done;
686
687 if ($progress_bar) {
688 my $l=$r="&nbsp;";
689 my $t="$nr of $total";
690 if ($pcnt_done > 50) {
691 $l=$t;
692 } else {
693 $r=$t;
694 }
695 $html='<table border="0" width="50%" cellpadding="0" cellspacing="0" align="right"><tr><td width="'.$pcnt_done.'%" class="pcnt-done">'.$l.'</td><td width="'.$pcnt_left.'%" class="pcnt-left">'.$r.'</td></tr></table>';
696 } else {
697 $html="$loc_slide $nr $loc_of $total";
698 }
699
700 return $html;
701 }
702
703 ##############################################################################
704 # remove anchors <a href...> from html (for titles)
705 sub remove_anchor {
706 my $tmp = $_[0];
707 $tmp =~ s/(.*)<A[^>]*>(.*)<\/A>(.*)/$1$2$3/ig;
708 return $tmp;
709 }
710
711 ##############################################################################
712 # extract files referenced in presentation
713
714 sub extract_files {
715 my $tmp = $_[0];
716 while ($tmp =~ s/<a\s+href="*([^"\s]+)"*//ism ||
717 $tmp =~ s/<img\s+src="*([^"\s]+)"*//ism) {
718 if ("$1" !~ m/[hf]t?tp:/ && -f "$1" && !grep(/$1/,@pack_additional)) {
719 push @pack_additional,$1;
720 }
721 }
722 }

  ViewVC Help
Powered by ViewVC 1.1.26