/[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

Annotation of /burst.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Sat May 5 18:23:39 2001 UTC (18 years, 4 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +0 -4 lines
File MIME type: text/plain
removed debug output

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

  ViewVC Help
Powered by ViewVC 1.1.26