#!/usr/bin/perl -w use strict; use IO::File; use CGI; use CGI::Carp 'fatalsToBrowser'; #use URI::URL; #use HTML::Entities 'encode_entities'; sub construct_url { my $url = shift; return $url."?".$_[0]."=".$_[1]; # my ($url, %param) = @_; # my $url = URI::URL->new($url); # $url->query_form(%param); # return $url->as_string; } sub encode_entities { my $crap = shift; $crap =~ s/([&<>"])/ {"&" => "&", '"' => """, "<" => "<", ">" => ">"}->{$1}/ge; return $crap; } sub excorcise { my $fn = shift; $fn =~ s/\D//g; return $fn; } my $q = CGI->new; my $self_url = $q->url; my $content = "stuff"; opendir DIR, $content or die "tie '$content' as IO::Dir: $!"; my $menu; my @reg_files = sort grep { !/^\./ && -f "$content/$_" } readdir DIR; { my $idx = 0; foreach my $f (@reg_files) { $idx += 1; push @$menu, {url => construct_url($self_url, pg => $idx), text => $f}; } } my $pg = excorcise($q->param("pg") || 0) || 0; my $pgs; if ($pg) { $pgs = "$content/$reg_files[$pg-1]"; } else { $pgs = "main.htf"; } my $fh = IO::File->new($pgs, "r"); print $q->header; print <ZetaTalk commentary: $pg END { print ""; print "
"; print ""; print ""; my $idx = 0; foreach (@$menu) { $idx += 1; print qq|\n"; } print "
Menu
 
|; if ($idx == $pg) { print "$_->{text}"; } else { print qq|$_->{text}|; } print "
"; } { my @colors = ('#000000', '#800080', '#004898', '#984800'); my $mode = "text"; while (<$fh>) { chomp; if (//) { die "transition from '$mode' to email?" unless $mode eq 'text'; $mode = "emailhead"; print "\n"; next; } if ($mode eq 'emailhead') { if (/^\w+: (.*)/) { print qq||.encode_entities($_)."\n"; next; } $mode = 'email'; } if ($mode eq 'email') { if (//) { print qq|

\n|; $mode = "comment"; next; } my ($resp_level) = /^(>+)/; my $color = $colors[length($resp_level)]; print qq||.encode_entities($_)."\n"; next; } if ($mode eq 'comment') { if (/<\/comment>/) { print qq|

\n|;
	    $mode = "email";
	    next;
	}
	print "$_\n";
	next;
    }
    print "$_\n";
}
}
print "

Back to top.

"; print "";