#!/usr/local/bin/perl5
#
# distturn <turnfile>
#
# Update master.html to recognize a new turn
#
require '/home/alansz/rw/rw-lib.ph';

$turn = $ARGV[0];
$turn =~ s/turn//;
$master = "/home/alansz/www/rw-pbem/master.html";
$tmp = "/tmp/distturn.$$";

print "Enter the title (Turn N: blah): ";
chop($title = <STDIN>);

open(IN,"$master") || die "Couldn't open $master\n";
open(OUT,">$tmp") || die "Couldn't open $tmp\n";

while (<IN>) {
  if (/\<!-- (\w+) --\>/) {
	$name = $1;
	$lcname = "\L$name";
	if ($players{$lcname}) {
	  # An active player. Add a reference
		  print OUT <<EOP;
 <li><a href="/cgi-alansz/spewturn?$turn+\u$lcname">$title</a>
EOP
        }
  }
  print OUT;
}
close(IN);
close(OUT);

print "Producing new master.html\n";
system("/bin/cp $master $master.bak");
system("/bin/mv $tmp $master");
chmod(0644,$master);
print "Updating index.html from master.html\n";
exec("/home/alansz/rw/updatebase");
