#!/usr/local/bin/perl5
#
# maketurn
# This program accepts turn source, and creates customized
# versions of the turn for each player to reflect language knowledge.
# It mails these out to the players
#
# Format for turn source is plain text, except that we escape
# paragraphs linguistically:
# <french>
# French-speaker version of the paragraph
# <!french>
# Non-french speaker version of the paragraph
# <all>
# Any language
# <player name>
# Private to that player
#
# We also translate *word* to bold if we're in archive mode, and
# /word/ to italic.

use Getopts;
require "/home/alansz/rw/rw-lib.ph";

&Getopts('td') if ($#ARGV > 0);

# Parse the file name 
$infile = $ARGV[0];

$archive = 1 if ($opt_t || $opt_d);
unless ($archive) {
  print "Enter subject line: ";
  $subject = <STDIN>;
  chop($subject);
}

@turn = <>;	# Slurp!

foreach (@players) {
  if ($archive) {
  # Use for debugging or archiving
  open($_,">$infile.$_");
  select($_);
  } else {
  open($_,"|/usr/lib/sendmail $emails{$_}");
  select($_);
  print "To: $mailing_list\n";
  print "Subject: $subject\n";
  }
  print join("",&turnify($_,$archive,@turn));
  close($_);
  chmod(0644,"$infile.$_") if $archive;
}

chmod(0644,$infile);
exit 0;

