case $CONFIG in
'')
	if test -f config.sh; then TOP=.;
	elif test -f ../config.sh; then TOP=..;
	elif test -f ../../config.sh; then TOP=../..;
	elif test -f ../../../config.sh; then TOP=../../..;
	elif test -f ../../../../config.sh; then TOP=../../../..;
	else
		echo "Can't find config.sh."; exit 1
	fi
	. $TOP/config.sh
	;;
esac
: This forces SH files to create target in same directory as SH file.
: This is so that make depend always knows where to find SH derivatives.
case "$0" in
*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
esac
echo "Extracting fixturn (with variable substitutions)"
: This section of the file will have variable substitutions done on it.
: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
: Protect any dollar signs and backticks that you do not want interpreted
: by putting a backslash in front.  You may delete these comments.
$spitshell >fixturn <<!GROK!THIS!
#!$perlpath
#
# fixturn: Fix up a turn file, replacing group and language lists
#   with the names of the appropriate players who are in those
#   groups or speak those languages during that turn.
#
# Usage: fixturn <pbem-shortname> <turn>
# Example:
#        fixturn mage mage-3
#        fixturn mage 3
# will both fix up the turn file 'mage-3'.
#
# # Copyright 1998 Alan Schwartz
# # 
# # This file is part of pbemtools.
# # 
# # pbemtools is free software; you can redistribute it and/or modify
# # it under the terms of the GNU General Public License as published by
# # the Free Software Foundation; either version 2, or (at your option)
# # any later version.
# # 
# # pbemtools is distributed in the hope that it will be useful,
# # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# # GNU General Public License for more details.
# # 
# # You should have received a copy of the GNU General Public License
# # along with pbemtools; see the file COPYING.
# # If not, write to the Free Software Foundation,
# # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# # 
# # Report problems and direct all questions to:
# # 
# #     alansz@pennmush.org
# # 
use lib qw($installperllib .);
require 'pbemtools.pl';
use Getopt::Std;

my \$mv = "$mv";
!GROK!THIS!

: In the following dollars and backticks do not need the extra backslash.
$spitshell >>fixturn <<'!NO!SUBS!'

die "Usage: fixturn <pbemname> <turn>\n" unless $#ARGV == 1;
my $pbem = shift(@ARGV);
&parseconfig("$pbem.config") or die "No config file $pbem.config\n";
my $turn = shift(@ARGV); 
$turn = "$pbem-$turn" unless -r "$Turndir/$turn";
die "I can't find $Turndir/$turn\n" unless -r "$Turndir/$turn";

open(IN,"$Turndir/$turn") or die "Unable to open $turn\n";
my $tmp = "/tmp/fixturn.$$";
open(OUT,">$tmp") or die "Unable to open $tmp\n";

while (<IN>) {
  if (/^\<(.*)\>/) {
    print OUT "<",&expand($1),">\n";
    next;
  } 
  print OUT;
}

close OUT;
close IN;
system("$mv $tmp $Turndir/$turn");
unlink $tmp;
exit 0;

sub expand {
  my $what = shift;
  my @l = ();
  my $player;
  foreach $player (@Players) {
    next if $player eq "gm";
    push(@l,$player) if speaks($player,$what,$speaker);
  }
  return join(",",sort @l);
}

!NO!SUBS!
chmod 755 fixturn
$eunicefix fixturn
