#!/usr/local/bin/perl # # vv - a Perl script for producing "Virtual Viewgraphs", a chain of linked # frames of HTML pages for talks, presented directly off the web, or from # a laptop cache of web pages. # # Released into the public domain by Aake Nordlund, NBIfAFG & TAC, Copenhagen, # 18-sep-98. # # NO support is provided, this is "use as is" software, provided as a service to # those, who in principle could have written this piece of perl code themselves, # and / or are smart enough to adjust it to their own needs and preferences. # # Syntax: vv [ -f ] [ -p pp] [ -c sz ] [ -t sz ] [ 1.sld 2.sld 3.sld ... ] # # -f : "fold" section headers (just try it) # -pr : printout format, with vertical centering and larger text size # -p pp : percentage width of the contents fram # -c sz : relative size of contents text (default: -1) # -t sz : relative size of talks text (default:+2 of web, +3 for printout) # 1.sld : input file (default: all *.sld files) # # The files 1.sld etc contain plain text (and embedded HTML) in the form # (see also http://www.tac.dk/~padoan/talks/dust/[0123].sld): # # title: Protogalaxies at high z [ only one per talk ] # section: Introduction [ one per file ] # head: Acknowledgements [ one per slide # o Collaborators: # + James Dunlop # + Jose Franco # [ blank line separates slides ] # head: Galaxies at High Redshift # o When are galaxies formed? # - Observing distant galaxies is the only direct method to ... # ##################################################################### $windir = "c:\\WINNT\\PROFILES\\aake\\Desktop\\Talks\\"; $macdir = "Macintosh HD:Desktop Folder:Talks:"; $unxdir = "/b/aake/talks/"; ##################################################################### # Default values $talk = "Lund01"; # Talk subdir $filepat = "[0-3].sld\$"; # file pattern of source files $icons = "../../Icons"; # Path of icons dir (relative to subdirs) $psize = "18"; # Percent contents frame $csize = "-1"; # Contents text size delta $verbose = 3; # noisy execution? $printout = 0; # printout(1) or web(0) $eqcol = "blue"; # equation color ##################################################################### sub setDefaults { $menubgcolor = "#779999"; $menufgcolor = "#eeeeee"; $headfgcolor = "#bbbbff"; if ($printout) { ############################################################# # Default values for printing $tsize = 2 if $tsize eq ""; # Main text size delta $folded = 0 if $folded eq ""; # Folded table of contents? $bold = 0; # Boldface text? $vheight = 660; # vertical centering height $bgcolor = "#ffffff"; # page bgcolor $fgcolor = "#ffffbb"; # figure bgcolor } else { ############################################################# # Default values for web presentation $tsize = 2 if $tsize eq ""; # Main text size delta $folded = 0 if $folded eq ""; # Folded table of contents? $bold = 0; # Boldface text? $vheight = 0; # no vertical centering $bgcolor = "#ffffff"; # page bgcolor $fgcolor = "#ffffcc"; # figure bgcolor } if ($verbose) {print "tsize=$tsize folded=$folded\n";} } ##################################################################### sub beginHTML { $page = "$sep1$s$sep2"."page"."$pg.html"; $html = ""; $id = " ($s.$pg)"; } ##################################################################### sub endHTML { $pg++; if ($vheight == 0) {$height="";} else {$height="HEIGHT=60";} open (PGE,">$page"); $lsize = $tsize-1; print PGE " $title
$title $section$id

"; # Center vertically, for printing $hsize = $tsize+1; if ($vheight > 0) {print PGE "
$head
$html
";} # or keep tight with the
for the web else {print PGE "

$head

$html ";} close (PGE); } ##################################################################### sub doIndex { open(IDX,">$_[0]"); $psize1 = 100-$psize; print IDX " $text{$i,$j}, $title "; close(IDX); } ##################################################################### sub setLevel { # print "\nsetLevel: level=$level olevel=$olevel\n"; while ($level > $olevel) { $olevel++; if ($olevel == 0) { &beginHTML; } elsif ($olevel == 1) { } elsif ($olevel == 2) { $html=$html."

\n"; } else { $html=$html.' ' x ($olevel-1); $html=$html."
\n"; } else { $html=$html.' ' x ($olevel-1); $html=$html."\n"; } $olevel--; } } ##################################################################### sub doText{ $html=$html."

$_

"; } ##################################################################### sub doBullet{ $html=$html."

 $_\n"; } ##################################################################### sub doList{ $html=$html.' ' x $level; $color="black"; $color="blue" if $level == 3; $color="green" if $level == 4; $color="red" if $level == 5; if ($bold) {$html=$html."
  • $_\n";} else {$html=$html."
  • $_\n";} } ##################################################################### sub doLaTeX{ local($tex) = $_[0]; local($sec) = $_[1]; local($eqnnum) = $_[2]; # print $tex; $tmpfile = "tthtmp.tex"; $LaTeXpre = "preamble.tex"; $latex2html = "tth -t -r -L"; open (TMPTEX,">$tmpfile"); print TMPTEX "\\begin{document}\n"; print TMPTEX $tex; print TMPTEX "\\end{document}\n"; close TMPTEX; $html = $html.`cat $LaTeXpre $tmpfile | $latex2html`; unlink($tmpfile); } ##################################################################### sub doLaTeXinline{ local($tex) = $_[0]; local($sec) = $_[1]; local($eqnnum) = $_[2]; # print $tex; $tmpfile = "tthtmp.tex"; $LaTeXpre = "preamble.tex"; $latex2html = "tth -r -L"; open (TMPTEX,">$tmpfile"); print TMPTEX "\\begin{document}\n"; print TMPTEX $tex; print TMPTEX "\\end{document}\n"; close TMPTEX; $tex = `cat $LaTeXpre $tmpfile | $latex2html`; $tex =~ s/

    //; $html = $html.$tex } ##################################################################### # MAIN code # Necessary to explicitly set path when running under Alpha print "A\n"; if (chdir($windir)) { $sep1=""; $sep2="\\"; $dir=$windir; $win=1; # Win } elsif (chdir($macdir)) { $sep1=":"; $sep2=":"; $dir=$macdir; $mac=1; # Mac } else { $sep1=""; $sep2="/"; $dir=$unxdir; $unix=1; # UNIX } print "B\n"; chdir($talk.$sep2); print "C\n"; # $d = `pwd`; print "D\n"; print "dirs=|$dir|\n"; $d = "$sep1$dir$talk$sep2"; chdir($d); open (STDO,">stdout.txt"); select STDO; print "$d:$dir:$sep1:$sep2:\n"; $sec=-1; $s0=-1; @files = (); # argument list? if ($verbose > 0) {print "ARGC=$#ARGV ARGV=@ARGV\n";} if ($#ARGV >= 0) { arg: while ($#ARGV >= 0) { $_ = $ARGV[0]; if (/-f/) { $folded=1; shift(@ARGV); print "folded " if ($verbose); next arg; } elsif (/-c/) { $csize=$ARGV[1]; shift(@ARGV); print "csize: $csize " if ($verbose); shift(@ARGV); next arg; } elsif (/-pr/) { $vheight=$ARGV[1]; shift(@ARGV); $printout=1; print "printout " if ($verbose); next arg; } elsif (/-p/) { $psize=$ARGV[1]; shift(@ARGV); print "psize: $csize " if ($verbose); shift(@ARGV); next arg; } elsif (/-v/) { $verbose=$ARGV[1]; shift(@ARGV); print "verbose: $verbose " if ($verbose); shift(@ARGV); next arg; } elsif (/-t/) { $tsize=$ARGV[1]; shift(@ARGV); print "tsize: $tsize " if ($verbose); shift(@ARGV); next arg; } else { print "$_ " if ($verbose); @files = (@files, $ARGV[0]); } shift(@ARGV); } print "\n" if ($verbose); } &setDefaults; # if no input files from arg list if ($#files < 0) { opendir(DIR,$d); @allfiles = sort(readdir(DIR)); file: foreach (@allfiles) { if ($verbose > 2) {print "file: $_\n";} next file unless /$filepat/; @files = (@files, $_); } } if ($verbose > 1) {print "files: @files\n";} open (SRC, ">images.txt"); foreach (@files) { if ($verbose > 2) {print "file: $_\n";} @s = split(/\./); $s = $s[0]; if ($s0 == -1) {$s0=$s;} $section = ''; stat($s) || mkdir($s,0755); open (IN,"$_") || die("cannot open $s_"); $pg = 1; $olevel = -1; $r = ""; line: while () { chop; $n = split; $org = $_; s/ \& / & /g; s/:fgcolor:/$fgcolor/g; s/{\\em \(.*\)}/\1<\/B>/; if (/[wW][rR][lL]/) { # check .wrl files $file = $_; $file =~ s/[wW][rR][lL].*/wrl/; $file =~ s/.*=//; if (-e $f) {print SRC "$f\n";} else {print "$file: missing: $f\n"}; } if (/[mM][pP][gG]/) { # check .mpg files $file = $_; $file =~ s/[mM][pP][gG].*/mpg/; $file =~ s/.*=//; if (-e $f) {print SRC "$f\n";} else {print "$file: missing: $f\n"}; } if (/[sS][rR][cC]/) { # Check src=file split(/[sS][rR][cC]/); shift(@_); src: foreach (@_) { next src if (/http/); next src if (/HTTP/); #s/[^"]*"//; s/>.*//; # delete trailing stuff s/ *=//; # delete ' =' s/"//; # delete leading " s/".*//; # delete trailing ".... #s/[^']*'//; s/'//; # try single apostrophe too s/'.*//; s/ .*//; # extra parameters s/file:\/\///; if ($mac) { s/\.\.\//:/; s/\.\.\//:/g; s/\//:/g; if (/^[0-z]/) {s/^/:/;}; s/://; } s/\.\.\///; s/\#.*//; s/\n//; if (-e $_) {print SRC "$_\n";} else {print "$file: missing: $_\n"}; } } if ($_[0] eq "section:") { s/section: //; $section = $_; #$sec++; if ($sec == -1) {$sec0=$s;} $sec=$s; if ($verbose > 0) {$org =~ s/section: //; print "$s. $org\n";} $nsub{$sec}=0; $text{$sec,0}=$section; $dir{$sec}=$s; $level=-1; next line; } elsif ($n == 0) { $level=-1; } elsif ($_[0] eq "title:") { s/title: //; $title = $_; } elsif ($_[0] eq "col1:") { $html = $html."
    \n"; next line; } elsif ($_[0] eq "col2:") { s/col2: //; $img = $_[1]; $xsz = $_[2]; $ysz = $_[3]; $html = $html."
    "; next line; } elsif ($_[0] eq "emb2:") { s/emb2: //; $img = $_[1]; $xsz = $_[2]; $ysz = $_[3]; $html = $html." "; next line; } elsif ($_[0] eq "label:") { s/label: //; $label = $_; $text{$sec,$pg}=$label; } elsif ($_[0] eq "head:") { $level=0; s/head: //; s/head://; $head=$_; $label = $head; $text{$sec,$pg}=$head; if ($verbose > 1) {$org =~ s/head: //; print " $sec.$pg $org\n";} $nsub{$sec}++; } elsif ($_[0] eq "fig:") { s/fig: //; $html = $html."

    "; next line; } elsif ($_[0] eq "qt:") { s/qt: //; $html = $html."

    "; next line; } elsif ($_[0] eq "text:") { s/text: //; $html = $html."

    $_ "; while ($line ne "end:\n") { $html = $html."$line"; $line=; } $line = ""; $html = $html.""; next line; } elsif ($_[0] eq "box:") { s/box: //; $html = $html."

    $_ "; while ($line ne "end:\n") { $html = $html."$line"; $line=; } $html = $html."
    "; $line = ""; next line; } elsif ($_[0] eq "link:") { $level=0; s/link: //; $head=$_; $label = $head; $text{$sec,$pg}=$head; $_=; chop; $link{$sec,$pg}=$_; $nsub{$sec}++; } elsif ($dotex = (@_[0] eq "begintex")) { $tex = $_; $tex =~ s/begintex//; while ($dotex) { $line = ; chop $line; $ntex = split(' ',$line); $dotex = ($ntex>0 ? (@_[$ntex-1] ne "endtex") : 1); $line =~ s/endtex//; $tex = $tex.$line."\n" } # $sec = section number, $pg = page number within section $eqnnum = ++$eqncnt{$sec}; &doLaTeX($tex,$sec+1,$eqnnum); next line; } elsif ($dotex = (@_[0] eq "{")) { # single line latex # if (/\$/) {print STDERR "dollar\n"}; $html = $html.""; $tex = $_; &doLaTeXinline($tex,$sec+1,$eqnnum); $html = $html.""; next line; } elsif (/^ [o\+-] /) { $level=5; s/^ *[o\+-] //; } elsif (/^ *[<]/) { s/<>//; $html=$html."$_"; next line; } elsif (/^ /) { $level=5; } elsif (/^ [o\+-] /) { $level=4; s/^ *[o\+-] //; } elsif (/^ /) { $level=4; } elsif (/^ [o\+-] /) { $level=3; s/^ *[o\+-] //; } elsif (/^ /) { $level=3; } elsif (/^ [o\+-] /) { $level=2; s/^ *[o\+-] //; } elsif (/^ ,/) { $level=1; $_ = ''; } elsif (/^ /) { $level=2; } elsif (/^ *\\vskip/) { next line; } else { $level=1; } &setLevel; if ($level == 1) {&doText;} elsif ($level == 2) {&doBullet;} elsif ($level >= 3) {&doList;} } close (IN); $s++; $r = "../$s/"; $pg=0; &endHTML; } close (SRC); &doIndex("index.html", "$sec0$sep2"."contents0.html", "front.html"); open (CONTENT, ">contents.txt"); for ($i=$sec0; $i<=$sec; $i++) { # print "$text{$i,0} $nsub{$i}\n"; print CONTENT "$i. $text{$i,0}\n"; if ($i == $sec0) {$j0=0;} else {$j0=1;} for ($j=$j0; $j<=$nsub{$i}; $j++) { $idx="index$j.html"; $cnt="contents$j.html"; $right="page$j.html#head"; if ($link{$i,$j} ne "") {$right="$link{$i,$j}"} #print "$idx $cnt $right\n"; if ($j == 0) {$right="../front.html";} &doIndex ("$sep1$dir{$i}$sep2$idx", "$cnt", "$right"); $im = $i-1; $jm = $j-1; $prv = "index$jm.html"; if ($jm < $j0) {$prv = "../$im/index$nsub{$im}.html";} # if ($j == $j0) {$prv ="../$sec/index$nsub{$sec}.html";} if ($i == $sec0 && $j == $j0) {$prv ="../index.html";} $ip = $i+1; $jp = $j+1; $nxt = "index$jp.html"; if ($jp > $nsub{$i}) {$nxt = "../$ip/index1.html";} if ($i == $sec && $j == $nsub{$sec}) {$nxt = "../index.html";} open(CNT,">$sep1$dir{$i}$sep2$cnt"); print CNT " $text{$i,$j}

     

    \n"; for ($ii=$sec0; $ii<=$sec; $ii++) { if ($ii == $i) { print CNT "$text{$ii,0}
    \n"; for ($jj=1; $jj<=$nsub{$ii}; $jj++) { if ($jj == $j) { print CNT "  $text{$ii,$jj}
    \n"; } else { print CNT "  $text{$ii,$jj}
    \n"; } } } else { if ($folded) { print CNT "$text{$ii,0}
    \n"; } else { print CNT "$text{$ii,0}
    \n"; for ($jj=1; $jj<=$nsub{$ii}; $jj++) { print CNT "  $text{$ii,$jj}
    \n"; } } } } print CNT "
    \n"; close(CNT); if ($verbose > 2) {print " $text{$i,$j}\n";} print CONTENT " $i.$j: $text{$i,$j}\n"; } } close (CONTENT); # sleep(5); exit;