#!/usr/local/bin/perl5
#
# rwnews turn24
# Make turn24.news
#
$newsdir = '.';
$newsext = ".news";
$master = '/home/alansz/www/rw-pbem/index.html';

die "Usage: $0 turnxx\n" unless @ARGV;
$turn = $ARGV[0];
$news = "$newsdir/$turn$newsext";
$turn =~ s/turn//;

open(IN,"/usr/local/etc/httpd/cgi-alansz/spewturn $turn alan|") or 
  die "Can't open turnfile\n";

# Find the name of this turn from the index file
die "Can't open $master\n" unless open(MASTER,$master);
while (<MASTER>) {
  $title = $1, last if /Turn $turn: (.*?)</;
}
close(MASTER);

die "Can't open $news\n" unless open(OUT,">$news");
print OUT <<EOP;
Newsgroups: rec.games.frp.archives
Subject: STORY: Riverworld, Chapter $turn: $title
Summary: http://mellers1.psych.berkeley.edu/~alansz/rw-pbem/
Followup-To: rec.games.frp.misc
Distribution: 
Organization: 
Keywords: riverworld story
Cc: 

For more information, see:
	http://mellers1.psych.berkeley.edu/~alansz/rw-pbem/

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Riverworld Turn #$turn: $title

EOP

while (<IN>) {
  # Strip out html stuff 
  next if /^</;
  next if /^Content-type:/;
  s#</?i>#/#g;
  s#</?b>#*#g;
  print OUT;
}
close(IN);
close(OUT);


