/[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.3 - (show annotations)
Tue Apr 17 13:40:36 2001 UTC (23 years ago) by dpavlin
Branch: MAIN
Changes since 1.2: +3 -4 lines
File MIME type: text/plain
cosmetic changes

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

  ViewVC Help
Powered by ViewVC 1.1.26