#!/usr/bin/perl use strict; my($slidename, $slidetitle, $incmode, $suppress, $LIST, $SLIDE, $tablerowcount, @titleelem, $currsect, $newsect); $incmode = 0; $suppress = 0; $currsect = -1; $newsect = 0; open LIST, "> slides-list"; # Eat the input and turn it into slides for a presentation while(){ # Be keen to turn include mode off, and slow to turn it on... if(/(.*)<\/slideinclude>/ || /(.*)<\/slidetext>/){ if($slidename ne ""){ $_ = makeslidetext($1); print SLIDE "$_\n"; } $incmode = 0; print STDERR "Turning include mode off\n"; } if(($incmode == 1) && ($slidename ne "")){ $_ = makeslidetext($_); print SLIDE "$_"; } elsif($incmode == 1){ print STDERR "Included text skipped for lack of a slide: $_"; } # Found a chapter if(/.*/i){ $slidename = ""; $currsect = 0; $newsect = 0; } if(/.*/i){ print STDERR "New section number $1\n"; $newsect = $1; } # Found a slide name (a title) if((/(.*)(.*)<\/title>.*/i) && ($suppress == 0)){ if($1 eq "<figure>"){ print STDERR "Figure title skipped\n"; } # Did we go down or up in sect levels? elsif($currsect == -1){ print STDERR "First title element\n"; $titleelem[0] = $2; openslide(); } elsif($newsect > $currsect){ print STDERR "Appending a title element\n"; $titleelem[$newsect] = $2; openslide(); } else{ print STDERR "Rolling back a title element\n"; $#titleelem = $newsect; $titleelem[$newsect] = $2; openslide(); } } if(/.*<slideinclude>/ || /.*<slidetext>/){ $incmode = 1; print STDERR "Turning include mode on\n"; } # Forcing a page break in a side if(/.*<slidebreak>/){ print STDERR "Slide page break\n"; # Is the last element of the title already a cont? $_ = $titleelem[$#titleelem]; if(/Continued (.*)/){ $titleelem[$#titleelem] = "Continued " . ($1 + 1); } else{ $titleelem[$#titleelem + 1] = "Continued 1"; } openslide(); } # We can also suppress titles from being included if(/.*<noslide>/){ $suppress = 1; print STDERR "Suppressing contents of sgml\n"; } if(/.*<\/noslide>/){ $suppress = 0; print STDERR "Suppression disabled\n"; } } exit; sub openslide(){ print STDERR "[Old $currsect, New $newsect] Title elements: " . join(", ", @titleelem) . "\n"; $currsect = $newsect; # Generate a filename for this slide $slidetitle = join(": ", @titleelem); $slidename = "content/" . join("-", @titleelem); $slidename = makefile($slidename); close SLIDE; open SLIDE, "> $slidename"; print SLIDE "TITLE: $slidetitle\n"; print LIST "$slidename\n"; } sub makefile(){ my($temp) = @_; $temp = lc($temp); $temp =~ s/[ \t]/-/g; $temp =~ s/://g; $temp =~ s/the-//g; $temp =~ s/\?//g; $temp =~ s/'//g; return $temp; } sub makeslidetext(){ my($temp) = @_; my($linelen); # Convert tables to HTML $linelen = -42; $_ = $temp; if(/.*<row>/){ if($tablerowcount == 1){ $temp =~ s/<row>/<tr bgcolor=BBBBBB>/; $tablerowcount = 0; } else{ $temp =~ s/<row>/<tr>/; $tablerowcount = 1; } } $temp =~ s/<\/row>/<\/tr>/g; $temp =~ s/<entry>/<td>/g; $temp =~ s/<\/entry>/<\/td>/g; $temp =~ s/<thead>//g; $temp =~ s/<\/thead>//g; $temp =~ s/<tbody>//g; $temp =~ s/<\/tbody>//g; $temp =~ s/<tgroup[^>]*>//g; $temp =~ s/<\/tgroup>//g; # $temp =~ s/<table[^>]*><title>(.*)<\/title>/<title>$1<\/title><br><table>/g; $_ = $temp; if(/.*<table>/){ $tablerowcount = 1; } $temp =~ s/<table[^>]*><title>(.*)<\/title>/<table>/g; # Deal with quotes $temp =~ s/<quote>/<i>/g; $temp =~ s/<\/quote>/<\/i>/g; # Deal with images $temp =~ s/<figure>/<br><br><div align=\"center\">/g; $temp =~ s/<title>/<b>/g; $temp =~ s/<\/title>/<\/b>/g; $temp =~ s/<graphic format.*fileref=\"/<br><img src=\"\/notes\/presentations\/content\//g; $temp =~ s/<\/figure>/<\/div><BR><BR>/g; # Footnotes $temp =~ s/<footnote><para>/<i>(/g; $temp =~ s/<\/para><\/footnote>/)<\/i>/g; # Listitems $temp =~ s/<orderedlist>//g; $temp =~ s/<\/orderedlist>//g; $temp =~ s/<itemizedlist>//g; $temp =~ s/<\/itemizedlist>//g; $temp =~ s/<listitem><para>/<li>/g; $temp =~ s/<\/para><\/listitem>//g; # Source code $temp =~ s/<programlisting>/<pre>/g; $temp =~ s/<\/programlisting>/<\/pre>/g; # Emphasis / command $temp =~ s/<emphasis>/<i>/g; $temp =~ s/<\/emphasis>/<\/i>/g; $temp =~ s/<command>/<i><b>/g; $temp =~ s/<\/command>/<\/b><\/i>/g; # Sections $temp =~ s/<sect[^>]*>/<BR><BR>/g; $temp =~ s/<\/sect[^>]*>//g; # Other stuff $temp =~ s/<slidetext>//g; $temp =~ s/<\/slidetext>//g; $temp =~ s/<para>/<BR><BR>/g; $temp =~ s/<\/para>//g; return $temp; }