/[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.1.1.1 - (show annotations) (vendor branch)
Tue Apr 17 08:35:10 2001 UTC (22 years, 11 months ago) by dpavlin
Branch: DbP
CVS Tags: pre
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
initial import into cvs

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

  ViewVC Help
Powered by ViewVC 1.1.26