This shell archive contains 7 tools for use with Chainsaw 3.0 empire:
These tools are heavily dependent on running the client eif in a unix
environment.  If you aren't using eif, then these tools will be of no
use to you.

1) cmvr:   move your civs from over-populated sectors to under-populated ones
2) feed:   feed your starving civs from a warehouse
3) del:    calculate net production delta of all commodities
4) post:   mail-like interface for reading telegrams--it remembers which ones
           you've read.
5) wingit: organise your planes into wings and count efficient planes by type
6) Edata:  database for storing information from satellites.  It also generates
           pretty bmaps.
7) newsparse: This script reads through the news and then figures out who
              is beside who in the world.

-Buster, ruler of children
stevens@math.utoronto.ca

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	Edata
#	README
#	bdesinfo
#	cmvr.c
#	dat
#	del
#	eif_extras
#	eifrc
#	endEdata
#	feed
#	makefile
#	mvc
#	newsparse
#	post.c
#	startEdata
#	wingit
# This archive created: Sun May  8 23:52:22 1994
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Edata'
then
	echo shar: "will not over-write existing file 'Edata'"
else
cat << \SHAR_EOF > 'Edata'
#!/usr/local/bin/perl
# eval "exec /usr/local/bin/perl -S $0 $*"
#    if $running_under_some_shell;
			# this emulates #! processing on NIH machines.
			# (remove #! line above if indigestible)

# eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
			# process any FOO=bar switches

#
#                               Edata
#
#                written by Ken Stevens for chainsaw 3.0
#
# DESCRIPTION:
# This script does two things.  First, it reads the output of your spy
# satellites and stores all of the information in an internal database.
# You can query the information in this database by sending commands to Edata.
#
# The other thing that this script does is it generates "bdes" commands based
# on a list you give it of one letter of the alphabet for each country.
# The "bdes" script it then writes (which you can run using "exec" in eif)
# will bdes enemy sectors to letters according to their owner.  If
# there are any land units in the sector, then it will use a capital letter.
#
# INSTALLATION:
# Before you run this script, make sure that you have typed:
# chmod +x Edata
# chmod +x dat
# chmod +x startEdata
# chmod +x endEdata
#
# HOW TO RUN IT:
# If you are going to use the "bdes" feature of Edata, then you should copy
# the "bdesinfo" file and change it to suit your needs.  For example, you
# may wish to change it so that "m" is for "Mirkwood" and "w" is for "Waffen".
#
# The next thing you will need to do is get the satellite info into a file.
# In eif you should do this by typing "sat * >! .sat".  You should
# also get the list of coutries by typing "relat >! .rel". Once you have done
# this, you are ready to try running this script.  Type:
# Edata
# Then it will say:
# <+ Edata started +>
# Now you can type "help" to get a list of commands.  The first command you
# should do is this:
# <+ Edata started +> load .sat
# where .sat contains the output of a "sat" command from empire.
# This will load the satellite data into the database.  Now you can start
# Querying the database.  Try typing "la" at the prompt.  It should list
# all the land units that your radars saw.  If you just type the co-ordinates
# for s sector, then it will tell you about that sector and list any units
# or ships in it.  You can also query sectors by owner or type or both, 
# and you can query ships and units by owner.
# 
# To create a power report, you should first load the country names into
# the database by typing:
# Edata +> rload .rel
# Where .rel contains the ouput of a "relat" command from empire.
# Now that Edata knows the country names, you can ask for a power report
# by typing "power" at the prompt.
#
# If you want to have a look at the world "coloured in" by country, then you
# will use the "bdes" feature.  Once the satellite data is loaded in, then
# load your personal bdesinfo file by typing something like this:
# Edata +> bload bdesinfo
# And then once it has read the file in, you can type "bdes" to create a 
# script for colouring your map.  The file it creates is called "bdes" and
# you can run it in eif by typing "exec bdes".
#
# Now if you have windows, you can just run Edata in one window and eif in
# the other, and you will not need to use the files "dat", "startEdata" and 
# "endEdata".  These are for people like me who play over a modem on a
# dumb terminal.  They allow you to run Edata and eif at the same time
# (through the use of a named pipe), and to access the Edata database from
# within eif.  If you want to try this, this is what you have to do:
# In your .eifrc file, put the lines:
# alias Edata "@startEdata ; @dat noprompt ; @dat load .sat ; @dat rload .rel"
# alias dat "@dat"
# Now in eif, just type "Edata", and the Edata programme will be started up 
# in the background, and if you want to send anything to it, just type
# "dat" in front of it in eif, and eif will send the command to Edata.
# For example, in eif I could type "dat la 7" to get a list of country #7's
# land units, or I could type "dat 15,3" to get the rundown on that sector.
# When you quit eif, make sure to run endEdata so that your Edata
# process shuts down.  You can do that by putting these lines in your
# .eifrc file:
# alias x "@endEdata; exit"
# alias q "@endEdata; quit"
# and then just typing "x" or "q" to exit or quit eif.
#
# BUG REPORTS:
# mail your bug-reports and comments to:
# stevens@math.utoronto.ca

$[ = 1;			# set array base to 1
$, = ' ';		# set output field separator
$\ = "\n";		# set output record separator

print $QWE;
$prompt = 'Edata +> ';
printf "\n<+ Edata started +> ";

{
  while (<>) {
    chop;
    @Cmd = split(' ', $_);
    if ($Cmd[1] eq 'noprompt') {
      $prompt = '';
    }
    elsif ($Cmd[1] eq 'help' || $Cmd[1] eq 'h' || $Cmd[1] eq '?') {
      print 'List of commands for the Edata program:';
      print 'load <filename>   Load satellite information from the file <filename>.';
      print '                  This file should contain the output of a "sat" command';

      print 'se                List all the sectors in the database.';
      print 'se <n>            List the sectors owned by country number <n>.';
      print 'sd <des>          List sectors designated as <des>.';
      print 'sd <des> <n>      List sectors designated <des> owned by <n>.';
      print 'sh                List all the ships in the database.';
      print 'sh <n>            List the ships owned by country <n>.';
      print 'la                List all the land units in the database.';
      print 'la <n>            List the land units owned by country <n>.';
      print 'power             Print a power report.';
      print '<x>,<y>           Print the info on sector <x>,<y>.';
      print 'quit              Quit this program';
      print 'bload <filename>  Load bdes info from <filename>.  This file should';
      print '                  have on each line a country number, followed by a';
      print '                  space, followed by a letter of the alphabet.';
      print 'bdes              Using the information from the bload command,';
      print '                  write a list of bdes commands to a file called "bdes".';
      print '                  These will make your bmap show who owns what sectors.';
      print 'rload <filename>  Load a file containing the output of the "relat" command';
      print '                  (This is used by the "power" command)';
      print 'noprompt          Turn off the prompt.';
    }
    elsif ($Cmd[1] eq 'quit' || $Cmd[1] eq 'q' || $Cmd[1] eq 'x') {
      exit;
    }
    elsif ($Cmd[1] eq 'load') {
      &load_data($Cmd[2]);
    }
    elsif ($Cmd[1] eq 'rload') {
      &rload_data($Cmd[2]);
    }
    elsif ($Cmd[1] eq 'bload') {
      &bload_data($Cmd[2]);
    }    
    elsif (!%st) {
      print "You must first use the \"load\" command to load data into the database.";
      printf "\n%s", $prompt;
      next;
    }
    elsif ($Cmd[1] eq 'bdes') {
      if (!%bdata) {
	print "You must first use the \"bload\" command to load the bdes data into the database.";
	printf "\n%s", $prompt;
	next;
      }
      &create_bdes();
    }
    elsif ($Cmd[1] eq 'power') {
      &print_power();
    }
    elsif ($Cmd[1] eq 'se') {
      if ($Cmd[2]) {
	@sects = sort sectsort grep($so{$_} == $Cmd[2], keys %so);
      }
      else {
	@sects = sort sectsort (keys %st);
      }
      &print_sectors();
    }
    elsif ($Cmd[1] eq 'sd') {
      if (!$Cmd[2]) {
	print "Syntax: sd <des> <n>";
      }
      elsif ($Cmd[3]) {
	@sects = sort sectsort 
	  grep($st{$_} eq $Cmd[2] && $so{$_} == $Cmd[3], keys %so);
      }
      else {
	@sects = sort sectsort grep($st{$_} eq $Cmd[2], keys %so);
      }
      &print_sectors();
    }
    elsif ($Cmd[1] eq 'sh') {
      if ($Cmd[2]) {
	@n = sort shipsort grep($ho{$_} eq $Cmd[2], keys %ho);
      }
      else {
	@n = sort shipsort (keys %ho);
      }
      &print_ships();
    }
    elsif ($Cmd[1] eq 'la') {
      if ($Cmd[2]) {
	@n = sort landsort grep($lo{$_} == $Cmd[2], keys %lo);
      }
      else {
	@n = sort landsort (keys %lo);
      }
      &print_units();
    }
    else {
      &print_sector('h');
      &print_sector($Cmd[1]);
      @n = sort shipsort grep($hs{$_} eq $Cmd[1], keys %hs);
      if ($#n) {
	&print_ships();
      }
      @n = sort landsort grep($ls{$_} eq $Cmd[1], keys %ls);
      if ($#n) {
	&print_units();
      }
    }
    if ($prompt) {
      printf "\n%s", $prompt;
    }
  }

  sub load_data {
    if (!open(_DATA, "<@_")) {
      print "Cannot open file @_.";
      return 0;
    }
    while (<_DATA>) {
      chop;
      @F = split(' ', $_);
      if (/Satellite sector report/) {
	$mode = 'sec';
      }
      if (/Satellite ship report/) {
	$mode = 'shi';
      }
      if (/Satellite unit report/) {
	$mode = 'uni';
      }
      if (/Satellite radar report/) {
	$mode = 'none';
      }

      if ($F[5] == 1994 || $F[1] eq 'sect' || $F[2] eq 'sectors' ||
	  $F[1] eq 'own' || $F[2] eq 'ships' || $F[2] eq 'units' ||
	  $F[1] eq 'Satellite' || $F[2] eq 'spysat') {
	next;
      }
      if ($mode eq 'sec' && $F[1]) {
	$st{$F[1]} = $F[2];
	$so{$F[1]} = $F[3];
	$se{$F[1]} = $F[4];
	$sc{$F[1]} = $F[5];
	$sm{$F[1]} = $F[6];
	$ss{$F[1]} = $F[7];
	$sg{$F[1]} = $F[8];
	$si{$F[1]} = $F[9];
	$sp{$F[1]} = $F[10];
	$sf{$F[1]} = $F[11];
      }
      elsif ($mode eq 'shi' && $F[1]) {
	$ho{$F[2]} = $F[1];
	$ht{$F[2]} = substr($_, 11, 38);
	@a = split(' ', substr($_, 55, 7));
	$hs{$F[2]} = $a[1];
	$he{$F[2]} = substr($_, 64, 3);
      }
      elsif ($mode eq 'uni' && $F[1]) {
	$lo{$F[2]} = $F[1];
	$Lt{$F[2]} = substr($_, 11, 18);
	@a = split(' ', substr($_, 30, 7));
	$ls{$F[2]} = $a[1];
	$Le{$F[2]} = substr($_, 38, 3);
      }
    }
    print "loaded $. lines from @_.";
    close(_DATA);
  }

  sub rload_data {
    if (!open(_RDATA, "<@_")) {
      print "Cannot open file \"@_\".";
      return 0;
    }
    while (<_RDATA>) {
      chop;
      @F = split(' ', $_);
      if (!$F[4] || $F[1] eq 'Formal' || $F[2] eq 'Diplomatic') {
	next;
      }
      chop($F[1]);
      $name{$F[1]} = substr($F[2], 1, 9);
    }
    print "loaded $. lines from \"@_\".";
    close(_RDATA);
  }

  sub bload_data {
    if (!open(_BDATA, "<@_")) {
      print "Cannot open file \"@_\".";
      return 0;
    }
    while (<_BDATA>) {
      chop;
      @F = split(' ', $_);
      foreach $b (values %bdata) {
	if ($b eq $F[2]) {
	  print "Warning:  The symbol \"$F[2]\" is multiply defined in the file \"@_\".";
	}
      }
      $bdata{$F[1]} = $F[2];
    }
    print "loaded $. lines from \"@_\".";
    close(_BDATA);
  }

  sub print_sector {
    local($S) = @_;
    if ($S eq 'h') {
      printf "%7s %4s %4s %3s %4s %4s %4s %4s %4s %4s %4s\n", 'sect',

      'type', 'own', 'eff', 'civ', 'mil', 'shl', 'gun', 'iron', 'pet',

      'food';
    }
    elsif ($st{$S}) {
      printf "%7s %4s %4d %3d %4d %4d %4d %4d %4d %4d %4d\n", $S, $st{$S},

      $so{$S}, $se{$S}, $sc{$S}, $sm{$S}, $ss{$S}, $sg{$S}, $si{$S},

      $sp{$S}, $sf{$S};
    }
    else {
      printf "sector %s not in database\n";
    }
  }

  sub print_ship {
    local($n) = @_;
    if ($n eq 'h') {
      printf "%4s %4s %-40s %7s %3s\n", 'own', 'shp#', 'ship type',

      'sector', 'eff';
    }
    elsif ($ho{$n}) {
      printf "%4s %4d %40s %7s %3d%%\n", $ho{$n}, $n, $ht{$n}, $hs{$n},

      $he{$n};
    }
    else {
      printf "ship %s not in database\n", $n;
    }
  }

  sub print_land {
    local($n) = @_;
    if ($n eq 'h') {
      printf " %4s %4s %-20s %-7s %3s\n", 'own', 'lnd#', 'unit type',

      'sector', 'eff';
    }
    elsif ($lo{$n}) {
      printf "%4d %4d %20s %7s %3d%%\n", $lo{$n}, $n, $Lt{$n}, $ls{$n},

      $Le{$n};
    }
    else {
      printf "land unit %s not in database\n", $n;
    }
  }

  sub create_bdes {
    if (!open(_BDES, ">bdes")) {
      print "Cannot create file \"bdes\".";
      return 0;
    }
    local($i) = 0;

    print "Creating file \"bdes\".";
    foreach $S (keys %so) {
      if ($bdata{$so{$S}}) {
	$bdes = $bdata{$so{$S}};
	foreach $n (keys %ls) {
	  if ($ls{$n} eq $S) {
	    $bdes = "\u$bdata{$so{$S}}";
	    last;
	  }
	}
	++$i;
	printf _BDES "bdes %s %s\n", $S, $bdes;
      }
    }
    print "$i lines written to the file \"bdes\".";
    close(_BDES);
  }

  sub print_power {
    print '         - = [   Edata Power Report   ] = -';
    print '';
    printf "%9s %4s %3s %4s %4s %5s %4s %4s %4s %4s %4s %4s %4s\n", '',
    'sects', 'eff', 'civ', 'mil', 'shell', 'gun', 'pet', 'iron', 'food',
    'oil', 'ship', 'unit';

    foreach $n (values %so) {
      $Ps{$n} = 0;
      $Pe{$n} = 0;
      $Pc{$n} = 0;
      $Pm{$n} = 0;
      $Pb{$n} = 0;
      $Pg{$n} = 0;
      $Pp{$n} = 0;
      $Pi{$n} = 0;
      $Pf{$n} = 0;
      $Po{$n} = 0;
      $Ph{$n} = 0;
      $Pl{$n} = 0;
    }
    foreach $S (keys %so) {
      $n = $so{$S};
      ++$Ps{$n};
      $Pe{$n} += $se{$S};
      $Pc{$n} += $sc{$S};
      $Pm{$n} += $sm{$S};
      $Pb{$n} += $ss{$S};
      $Pg{$n} += $sg{$S};
      $Pp{$n} += $sp{$S};
      $Pi{$n} += $si{$S};
      $Pf{$n} += $sf{$S};
      $Po{$n} += $so{$S};
    }
    foreach $x (keys %ho) {
      ++$Ph{$ho{$x}};
    }
    foreach $x (keys %lo) {
      ++$Pl{$lo{$x}};
    }
    for $n (sort {$Ps{$b} <=> $Ps{$a}} (keys %Ps)) {
      printf "%9s %4s %3s%% %4s %4s %5s %4s %4s %4s %4s %4s %4s %4s\n",
      $name{$n}?$name{$n}:$n,
      $Ps{$n}, int($Pe{$n}/$Ps{$n}), &con($Pc{$n}), &con($Pm{$n}),
      &con($Pb{$n}), &con($Pg{$n}), &con($Pp{$n}), &con($Pi{$n}),
      &con($Pf{$n}), &con($Po{$n}), &con($Ph{$n}), &con($Pl{$n});
    }
  }

  sub con {
    local($n) = @_;
    if ($n <= 999) {
      return $n;
    }
    if ($n <= 9999) {
      return sprintf("%d.%dK", int($n/1000), int($n%1000/100));
    } 
    if ($n <= 999999) {
      return sprintf("%dK", int($n/1000));
    }
    if ($n <= 9999999) {
      return sprintf("%d.%dM", int($n/1000000), int($n%1000000/100000));
    }
    if ($n <= 999999999) {
      return sprintf("%dM", int($n/1000000));
    }
    return 'huge';
  } 

  sub sectsort {
    if (@_) {
      @aa = split(',',@_[1]);
      @bb = split(',',@_[2]);
    }
    else {
      @aa = split(',',$a);
      @bb = split(',',$b);
    }
    if ($aa[2] == $bb[2]) {
      return $aa[1] <=> $bb[1];
    }
    return $aa[2] <=> $bb[2];
  }

  sub shipsort {
    if ($ho{$a} == $ho{$b}) {
      if ($hs{$a} eq $hs{$b}) {
	if ($ht{$a} eq $ht{b}) {
	  return $he{$a} <=> $he{$b};
	}
	return $ht{$a} cmp $ht{b};
      }
      return &sectsort($hs{$a},$hs{b});
    }
    return $ho{$a} <=> $ho{$b};
  }
  sub landsort {
    if ($lo{$a} == $lo{$b}) {
      if ($ls{$a} eq $ls{$b}) {
	if ($Lt{$a} eq $Lt{b}) {
	  return $Le{$a} <=> $Le{$b};
	}
	return $Lt{$a} cmp $Lt{b};
      }
      return &sectsort($ls{$a},$ls{$b});
    }
    return $lo{$a} <=> $lo{$b};
  }

  sub print_sectors {
    &print_sector('h');
    for (@sects) {
      &print_sector($_);
    }
    printf "%d sectors\n", $#sects;
  }

  sub print_units {
    &print_land('h');
    for (@n) {
      &print_land($_);
    }
    printf "%d units\n", $#n;
  }

  sub print_ships {
    &print_ship('h');
    for (@n) {
      &print_ship($_);
    }
    printf "%d ships\n", $#n;
  }
}
SHAR_EOF
chmod +x 'Edata'
fi
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
This shell archive contains 7 tools for use with Chainsaw 3.0 empire:
These tools are heavily dependent on running the client eif in a unix
environment.  If you aren't using eif, then these tools will be of no
use to you.

1) cmvr:   move your civs from over-populated sectors to under-populated ones
2) feed:   feed your starving civs from a warehouse
3) del:    calculate net production delta of all commodities
4) post:   mail-like interface for reading telegrams--it remembers which ones
           you've read.
5) wingit: organise your planes into wings and count efficient planes by type
6) Edata:  database for storing information from satellites.  It also generates
           pretty bmaps.
7) newsparse: This script reads through the news and then figures out who
              is beside who in the world.

The files for these tools are as follows:
cmvr:      cmvr.c mvc
feed:      feed
del:       del
post:      post.c
wingit:    wingit
Edata:     Edata, dat, startEdata, endEdata, bdesinfo
newsparse: newsparse

Explanations of how to use these tools can be found at the top of the files.

Other files included in this package are:
eifrc:      Commands you should include in your .eifrc file to run the tools
eif_extras: Some interesting eif aliases that you might want to try

-Buster, ruler of children
stevens@math.utoronto.ca

SHAR_EOF
fi
if test -f 'bdesinfo'
then
	echo shar: "will not over-write existing file 'bdesinfo'"
else
cat << \SHAR_EOF > 'bdesinfo'
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j
11 k
12 l
13 m
14 n
15 o
16 p
17 q
18 r
19 s
20 t
21 u
22 v
23 w
24 x
25 y
26 z
SHAR_EOF
fi
if test -f 'cmvr.c'
then
	echo shar: "will not over-write existing file 'cmvr.c'"
else
cat << \SHAR_EOF > 'cmvr.c'
#define DISTANCE 6       /* The maximum distance we will move the civs (this
			    value can be over-ridden on the command line*/
#define FACTOR 100
#define NUMTOMOVE 100    /* The number of civs we move (it will be multiplied
			    by minmob/FACTOR where minmob is either specified
			    as the second argument to this program or if
			    there is no second argument, then minmob = 
			    MINMOBTOMOVE) */
#define MINMOBTOMOVE 100 /* only move civs from sectors with this much mob 
			    Note this is only a default--minmob can be passed
			    as a parameter. */

/*
                             cmvr

              written by Ken Stevens for chainsaw 3.0

DESCRIPTION:
This very simple program moves your civs from over-populated sectors into
under-populated sectors.  It works with the output of the census command
(i.e. not dump) so it should work for any version of empire which supports
moving by destination-sector.

INSTALLATION:
This file should be called "cmvr.c".
If you want, change the #defines for DISTANCE, FACTOR, NUMTOMOVE, and
MINMOBTOMOVE below.  (Note: the default values should be fine.)
Then in unix, type:
  chmod +x mvc
  make cmvr

SYNTAX:
    cmvr <safeciv> [<minmob>] [<distance>]
  where <safeciv> is the number of civs you would like to have per
  sector, and the optional argument <minmob> is the minimum
  mobility that a sector must have in order to move civs from it.
  If the optional argument <minmob> is not specified, then the value of
  the #define MINMOBTOMOVE is used.  The third optional argument <distance>
  is how many sectors your civs can move--note that the distance function
  used in this program is very primitive (it uses the box metric).

HOW TO RUN IT:
novice:
  In empire, type:
    cen # >! .cen
  Use the "nation" command to find out your max safe population.  Suppose that
  your max safe population is 666, then in unix you would type:
    cmvr 666 <.cen >! move_script
  Lastly, you would run the move_script in empire to move the civs.

expert:
  In your .eifrc file, put the lines:
    alias cmvr "cen # >! .cen; runfeed cmvr $1 ${2:+} ${3:+}"
    alias cmvr1 "cen * ?ter=1 >! .cen; runfeed cmvr $1 ${2:+} ${3:+}"
    alias cmvr2 "cen * ?ter=2 >! .cen; runfeed cmvr $1 ${2:+} ${3:+}"
    etc...
  Then in eif, you can just type:
    cmvr 666
  or if you want to allow moving from sectors with less mob, you could type
  something like:
    cmvr 666 71

lazy-hacker:
  In my .eifrc file, I have the lines:
alias cmvr "cen # >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr1 "cen * ?ter=1 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr2 "cen * ?ter=2 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
etc...
  The mvc script reads my .nation file, figures out my max safe civs, and then
  runs cmvr for me.  So I can just type:
    cmvr
  Or sometimes, to populate a newly conquered island:
    cmvr 200 40 20

BUG REPORTS:
mail your bug-reports and comments to:
stevens@math.utoronto.ca
*/

#include <stdio.h>
#define MAXSECTS 800   /* Our number of sectors must be smaller than this */
#define ABORTIFSAFECIV 50 /* if this program is called with safeciv less than
			      this number, abort the program */

char cor[MAXSECTS][10];
int mob[MAXSECTS];
int civ[MAXSECTS];
char des[MAXSECTS][3];
int eff[MAXSECTS];
int owned[MAXSECTS];
int start, safeciv, minmob;
int n, numtomove, distance;

/* near(a,b) calculates the distance between two sectors in the box metric */

near(a,b)
{
  int x1, y1, x2, y2, d;
  sscanf(a, "%d,%d", &x1,&y1);
  sscanf(b, "%d,%d", &x2,&y2);
  return (abs(x2-x1) < distance && abs(y2-y1) < distance);
}

main(argc,argv)
char **argv;
{
  char s[800], dum[800];
  int i,j,k;
  char d[MAXSECTS];
  
/* parse the command line arguments */

  if (argc < 2 || argc > 4) {
    printf("*#* CMVR ERROR: WRONG NUMBER OF ARGUMENTS *#*\n");
    printf("syntax: cmvr <safeciv> [<minmob>] [<distance>]\n");
    printf("where <safeciv> is the number of civs you would like to have per\n");
    printf("sector, and the optional argument <minmob> is the minimum\n");
    printf("mobility that a sector must have in order to move civs from it.\n");
    exit(1);
  }
  safeciv=atoi(argv[1]);
  if (safeciv < ABORTIFSAFECIV) {
    printf("*#* CMVR ERROR: <safeciv> argument was %d, it must be greater than %d *#*\n", safeciv, ABORTIFSAFECIV);
    exit(1);
  }
  minmob = (argc >= 3)?atoi(argv[2]):MINMOBTOMOVE;
  numtomove = (NUMTOMOVE*minmob)/FACTOR;
  distance = (argc == 4)?atoi(argv[3]):DISTANCE;
  
/* read the output from the census command */

  gets(s);
  while (!feof(stdin) && n < MAXSECTS) {
    sscanf(s, "%s %s %d%s %d %s", cor[n], des[n], &eff[n], d, &mob[n], d);
    if (!strcmp(des[n],"sectors"))
      break;
    sscanf(s + 33, " %d %s", &civ[n], dum);
    if (s[32] == '*')
      owned[n] = 0;
    else
      owned[n] = 1;
    gets(s);
    if (!strcmp(cor[n], "sect"))
      start = 1;
    if (start)
      ++n;
  }

  /* move the civs */

  for (k = 1; k <= 5; ++k)
    for (i = 1; i < n; ++i)
      if (from(i,k))
	if ((i+k)%2) {
	  for (j = 1; j < n; ++j)
	    if (to(j,k) && near(cor[i], cor[j])) {
	      mob[i] -= numtomove;
	      civ[i] -= numtomove;
	      civ[j] += numtomove;
	      printf("move c %s %d %s; &h\n", cor[i], numtomove, cor[j]);
	      break;
	    }	
	}
	else {
	  for (j = n - 1; j >= 1; --j)
	    if (to(j,k) && near(cor[i], cor[j])) {
	      mob[i] -= numtomove;
	      civ[i] -= numtomove;
	      civ[j] += numtomove;
	      printf("move c %s %d %s; &h\n", cor[i], numtomove, cor[j]);
	      break;
	    }	
	}
}

from(i,pass)
int i, pass;
{
  switch (pass) {
  case 3:
  case 4:
    /* If a sector has enough civs, is owned, mobile, not a warehouse, and
       either a 100% road or 100% radar station, move civs from there */
    if (civ[i]>numtomove && owned[i] && mob[i]>=minmob && strcmp(des[i],"w")
	&& eff[i]==100 && (!strcmp(des[i],"+") || !strcmp(des[i],")")))
      return 1;
  case 1:
  case 2:
  case 5:
/*  If a sector is overpopulated, owned, mobile, and not a warehouse,
    move civs from there */
    if (civ[i]>safeciv && owned[i] && mob[i]>=minmob && strcmp(des[i],"w"))
      return 1;
  }
  return 0;
}

to(i,pass)
int i, pass;
{
  switch (pass) {
  case 1:
  case 3:
/* if a sector is owned and underpopulated and that sector is:
     1. not a mountain
     2. not a road
     3. not a bridge
     4. not a radar station
     5. not a capitol
   then move civs there.
*/
    if (civ[i] + numtomove < safeciv && owned[i] &&
	(
	 strcmp(des[i],"^") &&
	 strcmp(des[i],"+") &&
	 strcmp(des[i],"=") &&
	 strcmp(des[i],")") &&
	 strcmp(des[i],"c")
	 )
	)
      return 1;
    break;

  case 2:
  case 4:
/* if a sector is owned and underpopulated and that sector is:
     1. not a mountain
     2. not a 80% road
     3. not a 80% bridge
     4. not a 80% radar station
     5. not a 80% capitol
   then move civs there.
*/
    if (civ[i] + numtomove < safeciv && owned[i] &&
	(
	 strcmp(des[i],"^") &&
	 (
	  (
	   strcmp(des[i],"+") &&
	   strcmp(des[i],"=") &&
	   strcmp(des[i],")") &&
	   strcmp(des[i],"c")
	   ) ||
	  eff[i]<80)
	 )
	)
      return 1;
    break;

  case 5:
/* if a sector is owned and underpopulated and that sector is not a mountain,
   then move civs there.
*/
    if (civ[i] + numtomove < safeciv && owned[i] && strcmp(des[i],"^"))
      return 1;
    break;
  }
  return 0;
}
SHAR_EOF
fi
if test -f 'dat'
then
	echo shar: "will not over-write existing file 'dat'"
else
cat << \SHAR_EOF > 'dat'
#!/bin/csh
#
# This is a script for Ken Stevens' Edata program.
#
echo $* > pipe
SHAR_EOF
chmod +x 'dat'
fi
if test -f 'del'
then
	echo shar: "will not over-write existing file 'del'"
else
cat << \SHAR_EOF > 'del'
#!/usr/local/bin/perl
eval "exec /usr/local/bin/perl -S $0 $*"
    if $running_under_some_shell;
			# this emulates #! processing on NIH machines.
			# (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
			# process any FOO=bar switches

#
#                               delta
#
#                written by Ken Stevens for chainsaw 3.0
#
# DESCRIPTION:
# This script reads through your production info and tells you whether you
# have a positive or negative delta on iron, dust, lcm, etc...  If you
# have a negative delta, then the "supply" columb will tell you in how
# many updates you will run out of stock.
# The output looks something like this:
#
#      ----PRODUCTION DELTA REPORT----
#   com    start        +        -    delta      net   supply
# ------------------------------------------------------------
#  food    12304     3996     2572     1423    13727         
#  iron    13398     2997     1795     1202    14600         
#   oil      500        0      207     -207      293        2
#  dust      325        0      134     -134      191        2
#   lcm     4974      586      925     -339     4635       14
#   hcm    10591      586      570       16    10607         
# ------------------------------------------------------------
#  bars      980       20                       1000
#   pet       98        0                         98
# shell     2756      195                       2951
#  guns      304       36                        340
#   civ    36652    10995                      47647
#    uw     2997      449                       3446
#   mil      929      240                       1169
#
# INSTALLATION:
# Before you run this script, make sure that you have typed:
# chmod +x delta
# where delta is the name of this file.
#
# HOW TO RUN IT:
# Set the variable MAX_CIV_PER_SECTOR to what the "nation" command tells you
# your max civs per sector is.  (This variable is set at the top of
# the script, just a few lines below here.)
# Also, set the ETU_PER_UPDATE to what it should be.
#
# If you use eif, then you should just put the following two lines in
# your .eifrc file:
#
# alias del "cen # >!.delta ; com # >>.delta ; prod # >>.delta ; @delta .delta"
# alias cdel "cen # >!.cdelta ; prod # >>.cdelta ; @delta .cdelta"
#
# Then in eif you can type "del" to get your production delta.  The extra
# feature "cdel" tells you approximately how many updates until your civs
# max out.
#
# If you don't use eif, then all I have to say is "you should".  But I
# may be biased, because my cousin wrote it.
#
# BUG REPORTS:
# mail your bug-reports and comments to:
# stevens@math.utoronto.ca

$[ = 1;			# set array base to 1
$, = ' ';		# set output field separator
$\ = "\n";		# set output record separator

$MAX_CIV_PER_SECTOR = 999;
$ETU_PER_UPDATE = 60;

while (<>) {
    chop;	# strip record separator
    @Fld = split(' ', $_, 9999);

    {
	if ($Fld[5] ne '1994' && $Fld[1] ne 'sect') {
	    if ($com) {
		{
		    $ss += substr($_, 34, 4);

		    if (substr($_, 34, 1) ne ' ') {
			$sg += $Fld[5];
			$sp += $Fld[6];
			$si += $Fld[7];
			$sd += $Fld[8];
			$sb += $Fld[9];
			$so += $Fld[10];
			$sl += $Fld[11];
			$sh += $Fld[12];
			$sr += $Fld[13];
		    }
		    else {
			$sg += $Fld[6];
			$sp += $Fld[7];
			$si += $Fld[8];
			$sd += $Fld[9];
			$sb += $Fld[10];
			$so += $Fld[11];
			$sl += $Fld[12];
			$sh += $Fld[13];
			$sr += $Fld[14];
		    }
		}
	    }
	    elsif ($prod) {
		if ($Fld[2] eq 'm') {
		    $i += $Fld[5];
		}
		if ($Fld[2] eq 'g') {
		    $d += $Fld[5];
		}
		if ($Fld[2] eq 'o') {
		    $o += $Fld[5];
		}
		if ($Fld[2] eq '%') {
		    $p += $Fld[5];
		    $oc += &num($Fld[9]);
		}
		if ($Fld[2] eq 'j') {
		    $l += $Fld[5];
		    $ic += &num($Fld[9]);
		}
		if ($Fld[2] eq 'k') {
		    $h += $Fld[5];
		    $ic += &num($Fld[9]);
		}
		if ($Fld[2] eq 'l') {
		    $lc += &num($Fld[9]);
		}
		if ($Fld[2] eq 'b') {
		    $b += $Fld[5];
		    $dc += &num($Fld[9]);
		}
		if ($Fld[2] eq 'i') {
		    $S += $Fld[5];
		    $lc += &num($Fld[9]);
		    $hc += &num($Fld[10]);
		}
		if ($Fld[2] eq 'd') {
		    $g += $Fld[5];
		    $oc += &num($Fld[9]);
		    $lc += &num($Fld[10]);
		    $hc += &num($Fld[11]);
		}
		if ($Fld[2] eq 't') {
		    $dc += &num($Fld[9]);
		    $oc += &num($Fld[10]);
		    $lc += &num($Fld[11]);
		}
		if ($Fld[2] eq 'r') {
		    $dc += &num($Fld[9]);
		    $oc += &num($Fld[10]);
		    $lc += &num($Fld[11]);
		}
		if ($Fld[2] eq 'e') {
		    $M += $Fld[5];
		}
		if ($Fld[2] eq 'a') {
		    $f += &min($Fld[5], 999);
		}
		if ($Fld[2] eq '^') {
		    $mountain += 1;
		}
	    }
	    elsif ($cen) {
		if ($Fld[7] eq '*') {
		    $sc += $Fld[8];
		    $sm += $Fld[9];
		    $su += $Fld[10];
		    if ($Fld[10]) {
			++$uwsectors;
		    }
		    $sf += $Fld[11];
		}
		else {
		    $sc += $Fld[7];
		    $sm += $Fld[8];
		    $su += $Fld[9];
		    if ($Fld[9]) {
			++$uwsectors;
		    }
		    $sf += $Fld[10];
		}
	    }
	}
    }

    if (/CENSUS/) {
	$cen = 1;
	$com = 0;
	$prod = 0;
    }
    if (/COMMODITIES/) {
	$com = 1;
	$cen = 0;
	$prod = 0;
	$do_delta = 1;
    }
    if (/PRODUCTION/) {
	$prod = 1;
	$cen = 0;
	$com = 0;
    }
    if (/sectors/) {
	if ($cen) {
	    $sectors = $Fld[1];
	}
    }
}

if ($do_delta) {
    $c = $sc * 5 * $ETU_PER_UPDATE / 1000;
    $u = $su * 5 * $ETU_PER_UPDATE / 2000;
    $fc += (($sc + $sm + $su) * $ETU_PER_UPDATE / 1000) + (($c + $u) *

      $ETU_PER_UPDATE / 5000);
    print '     ----PRODUCTION DELTA REPORT----';
    printf "%5s %8s %8s %8s %8s %8s %8s\n", 'com', 'start', '+', '-', 'delta',

      'net', 'supply';
    print '------------------------------------------------------------';
    if ($f || $fc) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'food', $sf, $f, $fc,

	  $f - $fc, $sf + $f - $fc, &warn($sf, $f - $fc);
    }
    if ($i || $si) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'iron', $si, $i, $ic,

	  $i - $ic, $si + $i - $ic, &warn($si, $i - $ic);
    }
    if ($o || $so) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'oil', $so, $o, $oc, $o - $oc,

	  $so + $o - $oc, &warn($so, $o - $oc);
    }
    if ($d || $sd) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'dust', $sd, $d, $dc,

	  $d - $dc, $sd + $d - $dc, &warn($sd, $d - $dc);
    }
    if ($l || $sl) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'lcm', $sl, $l, $lc, $l - $lc,

	  $sl + $l - $lc, &warn($sl, $l - $lc);
    }
    if ($h || $sh) {
	printf "%5s %8d %8d %8d %8d %8d %8s\n", 'hcm', $sh, $h, $hc, $h - $hc,

	  $sh + $h - $hc, &warn($sh, $h - $hc);
    }
    print '------------------------------------------------------------';
    if ($b || $sb) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'bars', $sb, $b, '', '', $sb + $b;
    }
    if ($p || $sp) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'pet', $sp, $p, '', '', $sp + $p;
    }
    if ($S || $ss) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'shell', $ss, $S, '', '',

	  $ss + $S;
    }
    if ($g || $sg) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'guns', $sg, $g, '', '', $sg + $g;
    }
    if ($c || $sc) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'civ', $sc, $c, '', '', $sc + $c;
    }
    if ($u || $su) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'uw', $su, $u, '', '', $su + $u;
    }
    if ($M || $sm) {
	printf "%5s %8d %8d %8s %8s %8d\n", 'mil', $sm, $M, '', '', $sm + $M;
    }
}
else {
    $sectors -= $mountains;
    $civmax = $sectors * $MAX_CIV_PER_SECTOR;
    $uwmax = $uwsectors * $MAX_CIV_PER_SECTOR;
    $civ = $sc + $sm;
    $uw = $su;
    $foo = $sf;
    $fprod = $f;
    print '        ----FOOD DELTA REPORT----';
    print '	 start			  food	  food	  food';
    print 'update	  food	   civ	    uw	 eaten	  prod	 delta';
    print '-------------------------------------------------------';
    for ($i = 1; $i <= 20; ++$i) {
	$cbaby = $civ * 5 * $ETU_PER_UPDATE / 1000;
	$ubaby = $uw * 5 * $ETU_PER_UPDATE / 2000;
	$eaten = (($civ + $uw) * $ETU_PER_UPDATE / 1000) + (($cbaby + $ubaby)

	  * $ETU_PER_UPDATE / 5000);
	$delta = $fprod - $eaten;
	printf " %2d:\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\n", $i, $foo, $civ, $uw,

	  $eaten, $fprod, $delta;
	$foo += $delta;
	$civ += $cbaby;
	if ($civ > $civmax) {	#???
	    $civ = $civmax;
	}
	$uw += $ubaby;
	if ($uw > $uwmax) {	#???
	    $uw = $uwmax;
	}
    }
    printf "Maximum civs for %d sectors: %d\n", $sectors, $civmax;
    printf "Maximum uws for %d sectors: %d\n", $uwsectors, $uwmax;
}

sub num {
    local($str) = @_;
    substr($str, 1, length($str) - 1);
}

sub min {
    local($a, $b) = @_;
    if ($a < $b) {	#???
	return $a;
    }
    $b;
}

sub warn {
    local($start, $delta) = @_;
    if ($delta >= 0) {
	return '';
    }
    int(-$start / $delta) . '';
}
SHAR_EOF
chmod +x 'del'
fi
if test -f 'eif_extras'
then
	echo shar: "will not over-write existing file 'eif_extras'"
else
cat << \SHAR_EOF > 'eif_extras'
# Here are some commands from my .eifrc file.  Maybe you'll find
# something you like in here!

# Build a bridge
alias bb "build b $1 ; &$2 ; expl c $1 1 ${2}h"

# Check oil and dust
alias cod "res * ?des=o&ocon<10; res * ?des=g&gold<10"

# firing
alias fi "fire sect $1 $2"
alias fl "fire land $1 $2"
alias fs "fire ship $1 $2"
alias mfi "fi $1 $2 ; fi $1 $2 ; fi $1 $2 ; fi $1 $2 ; fi $1 $2 ; fi $1 $2 ; fi $1 $2 ; fi $1 $2 "
alias mfl "fl $1 $2 ; fl $1 $2 ; fl $1 $2 ; fl $1 $2 ; fl $1 $2 ; fl $1 $2 ; fl $1 $2 ; fl $1 $2 "
alias mfs "fs $1 $2 ; fs $1 $2 ; fs $1 $2 ; fs $1 $2 ; fs $1 $2 ; fs $1 $2 ; fs $1 $2 ; fs $1 $2 "

# typo's

alias udpate update
alias reda read
alias mvoe move
alias mvo move
alias shiip ship
alias cdn cen
alias elnist enlist

# Expansion aliases
alias cc expl c 0,0 1
alias cd expl c 2,0 1
alias d- "desi * ?des=- +"
alias m "map #"

# Populated sectors
alias cp "cen * ?civ>20"
alias mp "com * ?civ>20"
alias lp "lev * ?civ>20"
alias rp "res * ?civ>20"
alias cnm "cen # ?des#^"

# Economics
alias pr "prod # ?newd#m&newd#g&newd#o&newd#a&newd#+"
alias ceno "cen * ?civ>423"
alias cenu "cen * ?civ<423"
alias ns "cen * ?des=+&civ>60&eff<100"
alias rs "res * ?des=+&civ>60&eff<100"
alias ne "neweff * ?civ>20&des#newd;neweff * ?civ>20&eff<100"
alias ne1 "neweff * ?civ>20&des#newd&ter=1;neweff * ?civ>20&eff<100&ter=1"
alias rd "cen * ?des=+&civ>20&eff>90"
alias thom "th o * ?newd=o 1; th i * ?newd=m 1; th d * ?newd=g 1; th l * ?newd=j 1; th h * ?newd=k 1; th s * ?newd=i 1; th g * ?newd=d 1; th p * ?newd=% 1; th r * ?newd=u 1"

# Check for stranded commodities

alias cks com * ?she>1&newd#f&newd#h&newd#!&newd#*&newd#w&s_di<1
alias ckg com * ?gun>1&newd#f&newd#h&newd#!&newd#w&g_di<1
alias ckp com * ?pet>1&newd#h&newd#*&newd#w&p_di<1
alias cki com * ?iron>1&newd#j&newd#k&newd#w&i_di<1
alias cko com * ?oil>1&newd#%&newd#d&newd#t&newd#r&newd#w&o_di<1
alias ckd com * ?dust>1&newd#b&newd#t&newd#r&newd#w&d_di<1
alias ckl com * ?lcm>1&newd#h&newd#*&newd#!&newd#t&newd#r&newd#i&newd#d&newd#l&newd#p&newd#w&l_di<1
alias ckh com * ?hcm>1&newd#h&newd#*&newd#!&newd#i&newd#d&newd#w&h_di<1
alias ckb com * ?bar>1&newd#b&newd#w&b_di<1
alias cksf th s * ?she>1&newd#f&newd#h&newd#!&newd#*&newd#w&s_di<1 1
alias ckgf th g * ?gun>1&newd#f&newd#h&newd#!&newd#w&g_di<1 1
alias ckpf th p * ?pet>1&newd#h&newd#*&newd#w&p_di<1 1
alias ckif th i * ?iron>1&newd#j&newd#k&newd#w&i_di<1 1
alias ckof th o * ?oil>1&newd#%&newd#d&newd#t&newd#r&newd#w&o_di<1 1
alias ckdf th d * ?dust>1&newd#b&newd#t&newd#r&newd#w&d_di<1 1
alias cklf th l * ?lcm>1&newd#h&newd#*&newd#!&newd#t&newd#r&newd#i&newd#d&newd#l&newd#p&newd#w&l_di<1 1
alias ckhf th h * ?hcm>1&newd#h&newd#*&newd#!&newd#i&newd#d&newd#w&h_di<1 1
alias ckbf th b * ?bar>1&newd#b&newd#w&b_di<1 1
alias star "starv * ?old=own"

# Converting civs
alias convv "conv * ?own#oldown&uw<999 999; shoot * ?own#oldown&uw>998 c 999;"
alias cm "cen * ?own#oldown&mob>0"
alias cr "cen * ?own#oldown&civ>500&mil<50; cen * ?own#oldown&civ>500&mil<100"

# abbreviations
alias h history
alias mv move
alias inf info
alias info "info $1 | more"
alias fus "fuel s * 999"
alias bs "bmap # s"
alias cw "com # ?des=w"

# census by realm:

alias c1 "cen #1"
alias c2 "cen #2"
alias c3 "cen #3"
alias c4 "cen #4"
alias c5 "cen #5"
alias c6 "cen #6"

alias v1 "cen #1 ?civ>20"
alias v2 "cen #2 ?civ>20"
alias v3 "cen #3 ?civ>20"
alias v4 "cen #4 ?civ>20"
alias v5 "cen #5 ?civ>20"
alias v6 "cen #6 ?civ>20"

# census by territory

alias t1 "cen * ?ter=1"
alias t2 "cen * ?ter=2"
alias t3 "cen * ?ter=3"
alias t4 "cen * ?ter=4"
alias t5 "cen * ?ter=5"
alias t6 "cen * ?ter=6"

# levels by territory

alias l1 "lev * ?ter=1"
alias l2 "lev * ?ter=2"
alias l3 "lev * ?ter=3"
alias l4 "lev * ?ter=4"
alias l5 "lev * ?ter=5"
alias l6 "lev * ?ter=6"

# commodities by territory

alias m1 "com * ?ter=1"
alias m2 "com * ?ter=2"
alias m3 "com * ?ter=3"
alias m4 "com * ?ter=4"
alias m5 "com * ?ter=5"
alias m6 "com * ?ter=6"

# dirs

setvar SANTADIR /usr/ydisk/stevens/edir/santa

# hosts

setvar PURDUE  128.46.159.151
setvar NOVI    129.142.49.230
setvar TECH    129.67.15.75
setvar SANTAFE empire.santafe.edu
setvar FAA     bolero.rahul.net
setvar OPUS    opus.chem.psu.edu
setvar ALDERAAN alderaan.lanl.gov

# games

addgame santa4 $SANTAFE 6789 4 4 ${SANTADIR} v2.0
alias santa4 "connect santa4"
addgame santa5 $SANTAFE 6789 5 5 ${SANTADIR} v2.0
alias santa5 "connect santa4"
addgame santa6 $SANTAFE 6789 6 6 ${SANTADIR} v2.0
alias santa6 "connect santa6"
SHAR_EOF
fi
if test -f 'eifrc'
then
	echo shar: "will not over-write existing file 'eifrc'"
else
cat << \SHAR_EOF > 'eifrc'
# These are the lines you need in your .eifrc file to run the tools:

# wingit
alias wingit "plane * >!.planes ; runfeed wingit .planes ; @cat .af"

# post
alias mail "read >> teles; &y; @post"

# feed
alias feed "echo from_sect ${1:-2,10} >!.starv ; starv * >>.starv ; runfeed feed .starv"

# cmvr
alias cmvr "cen # >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr1 "cen * ?ter=1 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr2 "cen * ?ter=2 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr3 "cen * ?ter=3 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr4 "cen * ?ter=4 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"
alias cmvr5 "cen * ?ter=5 >! .cen; nation >! .nation; runfeed mvc ${1:+} ${2:+} ${3:+}"

# Edata (previous to this I did a "sat * >! .sat" to make the ".sat" file)
alias Edata "@startEdata ; @dat noprompt ; @dat load .sat"
# In empire I can send commands to Edata by typing "dat" before them:
alias dat "@dat"

# When you exit or quit, you will need to end Edata
alias x "@endEdata; exit"
alias q "@endEdata; quit"

# del and fdel
alias del "cen * >!.delta ; com * >>.delta ; prod * >>.delta ; @del .delta"
alias del1 "cen * ?ter=1 >!.delta ; com * ?ter=1 >>.delta ; prod * ?ter=1 >>.delta ; @del .delta"
alias del2 "cen * ?ter=2 >!.delta ; com * ?ter=2 >>.delta ; prod * ?ter=2 >>.delta ; @del .delta"
alias del3 "cen * ?ter=3 >!.delta ; com * ?ter=3 >>.delta ; prod * ?ter=3 >>.delta ; @del .delta"
alias del4 "cen * ?ter=4 >!.delta ; com * ?ter=4 >>.delta ; prod * ?ter=4 >>.delta ; @del .delta"
alias del5 "cen * ?ter=5 >!.delta ; com * ?ter=5 >>.delta ; prod * ?ter=5 >>.delta ; @del .delta"
alias del6 "cen * ?ter=6 >!.delta ; com * ?ter=6 >>.delta ; prod * ?ter=6 >>.delta ; @del .delta"
alias del7 "cen * ?ter=7 >!.delta ; com * ?ter=7 >>.delta ; prod * ?ter=7 >>.delta ; @del .delta"
alias del8 "cen * ?ter=8 >!.delta ; com * ?ter=8 >>.delta ; prod * ?ter=8 >>.delta ; @del .delta"
alias del9 "cen * ?ter=9 >!.delta ; com * ?ter=9 >>.delta ; prod * ?ter=9 >>.delta ; @del .delta"
alias del10 "cen * ?ter=10 >!.delta ; com * ?ter=10 >>.delta ; prod * ?ter=10 >>.delta ; @del .delta"
alias del11 "cen * ?ter=11 >!.delta ; com * ?ter=11 >>.delta ; prod * ?ter=11 >>.delta ; @del .delta"
alias del12 "cen * ?ter=12 >!.delta ; com * ?ter=12 >>.delta ; prod * ?ter=12 >>.delta ; @del .delta"
alias del13 "cen * ?ter=13 >!.delta ; com * ?ter=13 >>.delta ; prod * ?ter=13 >>.delta ; @del .delta"
alias fdel "cen * >!.fdelta ; prod * >>.fdelta ; @del .fdelta"
alias fdel1 "cen * ?ter=1 >!.fdelta ; prod * ?ter=1 >>.fdelta ; @del .fdelta"
alias fdel2 "cen * ?ter=2 >!.fdelta ; prod * ?ter=2 >>.fdelta ; @del .fdelta"
alias fdel3 "cen * ?ter=3 >!.fdelta ; prod * ?ter=3 >>.fdelta ; @del .fdelta"
alias fdel4 "cen * ?ter=4 >!.fdelta ; prod * ?ter=4 >>.fdelta ; @del .fdelta"
alias fdel5 "cen * ?ter=5 >!.fdelta ; prod * ?ter=5 >>.fdelta ; @del .fdelta"
alias fdel6 "cen * ?ter=6 >!.fdelta ; prod * ?ter=6 >>.fdelta ; @del .fdelta"
alias fdel7 "cen * ?ter=7 >!.fdelta ; prod * ?ter=7 >>.fdelta ; @del .fdelta"
alias fdel8 "cen * ?ter=8 >!.fdelta ; prod * ?ter=8 >>.fdelta ; @del .fdelta"
alias fdel9 "cen * ?ter=9 >!.fdelta ; prod * ?ter=9 >>.fdelta ; @del .fdelta"
alias fdel10 "cen * ?ter=10 >!.fdelta ; prod * ?ter=10 >>.fdelta ; @del .fdelta"
alias fdel11 "cen * ?ter=11 >!.fdelta ; prod * ?ter=11 >>.fdelta ; @del .fdelta"
alias fdel12 "cen * ?ter=12 >!.fdelta ; prod * ?ter=12 >>.fdelta ; @del .fdelta"
alias fdel13 "cen * ?ter=13 >!.fdelta ; prod * ?ter=13 >>.fdelta ; @del .fdelta"
alias dela "@del .delta"

SHAR_EOF
fi
if test -f 'endEdata'
then
	echo shar: "will not over-write existing file 'endEdata'"
else
cat << \SHAR_EOF > 'endEdata'
#!/bin/sh
#
# This is a script for Ken Stevens' Edata program.
#

if (test -r .Edata_pid) then
  kill -9 `cat .Edata_pid`
  \rm -fr pipe .Edata_pid
fi
SHAR_EOF
chmod +x 'endEdata'
fi
if test -f 'feed'
then
	echo shar: "will not over-write existing file 'feed'"
else
cat << \SHAR_EOF > 'feed'
#!/bin/awk -f
#
#                               feed
#
#                written by Ken Stevens for chainsaw 3.0
#
# DESCRIPTION:
# This script reads the output of the "starv" command and moves the
# necessary food to the starving sectors from a specified sector.
#
# INSTALLATION:
# Before you run this script, make sure that you have typed:
# chmod +x feed
# where feed is the name of this file.
#
# HOW TO RUN IT:
# Then in your .eifrc file, put the following line:
# alias feed "echo from_sect ${1:-X,Y} >!.starv ; starv * >>.starv ; runfeed feed .starv"
# where X,Y is the co-ordinates of the default sector you want to feed from.
# Then in eif you can just type "feed" to feed from the default co-ordinates,
# or you can type something like "feed 4,-8" to feed from another place.
#
# BUG REPORTS:
# mail your bug-reports and comments to:
# stevens@math.utoronto.ca

{
  if ($1 == "from_sect")
    from_sect = $2;
  else if ($1 != "Starvation" && $2 != "sectors" && $1 != "sect" && $1 != "starv" && $5 != 1994) {
    if (substr($0, 13, 1) != "*") {
      if ($8 + 0 > 0)
        food[$1] = $8;	
      else
        food[$1] = $9;
    }
  }
}

END {
   if (!from_sect)
      exit;
   for (sect in food) {
      printf("move f %s %d %s;&h\n", from_sect, food[sect] + 5, sect);
  }   
}

SHAR_EOF
chmod +x 'feed'
fi
if test -f 'makefile'
then
	echo shar: "will not over-write existing file 'makefile'"
else
cat << \SHAR_EOF > 'makefile'
all: post cmvr
SHAR_EOF
fi
if test -f 'mvc'
then
	echo shar: "will not over-write existing file 'mvc'"
else
cat << \SHAR_EOF > 'mvc'
#!/bin/csh
#
# This is a little script for use with Ken Stevens' cmvr program.
#
if ($1) then
  set safeciv = $1
else
  set safeciv = `awk '/safe populat/ {split($6, A, "/"); print A[1]}' <.nation`
endif
cmvr $safeciv $2 $3 <.cen
SHAR_EOF
chmod +x 'mvc'
fi
if test -f 'newsparse'
then
	echo shar: "will not over-write existing file 'newsparse'"
else
cat << \SHAR_EOF > 'newsparse'
#!/bin/csh
#
#                             newsparse
#
#                written by Ken Stevens for chainsaw 3.0
#
# DESCRIPTION:
# This script is used for figuring out which nations are on which
# continents.  It is meant to be run before ships have
# become a big part of the game (i.e. after the 7th update or so, this
# program will not tell you anything useful.)  The principle it uses is
# very straightforward: if one nation has attacked or spied on another
# nation, then they are assumed to be on the same continent.
#
# INSTALLATION:
# Before you run this script, make sure that you have typed:
# chmod +x newsparse
# where newsparse is the name of this file.
#
# HOW TO RUN IT:
# To use this script, logon to empire and type the following:
#	news 999 ?action=1 >news
#	news 999 ?action=2 >>news
#	news 999 ?action=3 >>news
#	relations >relations
#
# Then make sure that this script is in the same directory as the files
# "relations" and "news" and run it.
#
# BUG REPORTS:
# mail your bug-reports and comments to:
# stevens@math.utoronto.ca
#
rm -f _in _list _done _master _outcon continent_list
echo -n cleaning news file
egrep '^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)' news | grep -v 1994 |\
cut -f2- -d':' | cut -f2- -d' ' >_in
echo -n .
foreach w (attack beaten " one" two three four five six seven eight \
nine " ten" eleven twelve teen thirteen fifteen shock troops " of" \
infantry overrun sectors times territory captures captured spy " and" \
shot " by" back annihilated capture failed " in" " on" \'s)
echo -n .
sed "s/$w//" <_in >_out; mv _out _in
end
echo done
echo -n creating master lists
awk '{if ($2) \
{if ($2 > $1) printf "%s %s\n", $1, $2; \
 if ($1 > $2) printf "%s %s\n", $2, $1}}' _in | sort -u >_list
echo -n .
awk '{print $1; print $2}' <_list | sort -u >_master
echo .done
echo -n cleaning relations file
set myname = `grep Diplomatic relations | awk '{print $1}'`
echo -n .
grep '\)' relations | cut -f2- -d')' | awk '{print $1}' > _in
echo -n .
echo $myname >>_in
echo .done
echo -n parsing master lists
echo Peaceful Nations\: > continent_list
sort _in _master | uniq -u >> continent_list
echo > _done
set i = 0
set c = `sort _master _done | uniq -u | line`
echo -n .
while ($c != "")
	echo -n .
	@ i++
	echo "\nContinent ${i}:" >> continent_list
	grep $c _list | awk '{print $1; print$2}' | sort -u > _outcon
	cmp -s _list _outcon
	set stat = $status
	while ($stat)
		mv _outcon _incon
		rm _in
		foreach d (`cat _incon`)
			grep $d _list | awk '{print $1; print$2}' >> _in
		end
		sort -u _in >_outcon
		cmp -s _incon _outcon
		set stat = $status
	end
	rm _incon
	cat _outcon >> continent_list
	cat _outcon >> _done
	set c = `sort _master _done | uniq -u | line`
end
echo done
rm -f _in _list _done _master _outcon
echo You can now look at the continent_list file by typing:
echo more continent_list
SHAR_EOF
chmod +x 'newsparse'
fi
if test -f 'post.c'
then
	echo shar: "will not over-write existing file 'post.c'"
else
cat << \SHAR_EOF > 'post.c'
/*
				post.c

	       written by Ken Stevens for chainsaw 3.0

DESCRIPTION:
This program gives you a mail-like interface for reading your telegrams.

INSTALLATION:
This file should be called "post.c" and should be placed in your empire
directory (the directory you specified on the "addgame" line in your
.eifrc file)

In unix, type:
  make post

HOW TO RUN IT:
In your .eifrc file, add the line:
alias mail "read >> teles; &y; @post"

Then in eif, when you want to use this interface for reading your telegrams,
just type "mail".

BUG REPORTS:
mail your bug-reports and comments to:
stevens@math.utoronto.ca
*/

#include <stdio.h>
#define MAX_LINE_LENGTH   100
#define MAX_COMMAND_LENGTH   800
#define MAX_TELEGRAM_LENGTH (1024 + 2*MAX_LINE_LENGTH)
#define MAX_NUM_TELEGRAMS   50

char telhead[MAX_NUM_TELEGRAMS][MAX_LINE_LENGTH];
#define UNKNOWN  0
#define PROD     1
#define BULL     2
#define TELE     3

typedef struct mail_header {
  int type;
  char status;
  char *type_mark[5];
  char from[13];
  char date[20];
  char subj[30];
} Mail_header;
  
Mail_header head[MAX_NUM_TELEGRAMS];
char *body[MAX_NUM_TELEGRAMS][MAX_TELEGRAM_LENGTH][MAX_LINE_LENGTH];
int numlines[MAX_NUM_TELEGRAMS];
int start_message = 0;
int new_message = 0;

main()
{
  FILE *telfile;
  char filename[8];    
  int n;

  telfile = fopen("teles", "r");
  if (!telfile) {
    puts("No telegram file.\n");
    exit(-1);
  }
  n = read_telegrams(telfile);
  fclose(telfile);
  print_headers(n,start_message);
  if (prompt(n)) {
    printf("Saving changes to telegrams...\n");
    telfile = fopen("teles", "w");
    if (!telfile) {
      puts("No write to telegram file.\n");
      exit(-1);
    }
    write_telegrams(telfile, n);
    fclose(telfile);
  }
}

char *clean_head(s)
     char *s;
{
  int i;

  if (strlen(s))
    for (i = strlen(s) - 1; i && s[i] == ' ' || s[i] == '\n'; s[i--] = '\0');
  return s;
}

read_telegrams(telfile)
     FILE *telfile;
{
  int n = 0;
  char s[MAX_LINE_LENGTH];
  char from[MAX_LINE_LENGTH];
  int  cnum;
  char weekday[MAX_LINE_LENGTH];
  char month[MAX_LINE_LENGTH];
  int date;
  char time[MAX_LINE_LENGTH];
  int year, money;
  char dummy[MAX_LINE_LENGTH];
  
  fgets(s, MAX_LINE_LENGTH, telfile);
  while (!feof(telfile) && n < MAX_NUM_TELEGRAMS) {
    if (!strcmp(s, "read \n") ||
	!strcmp(s, "y\n") ||
	!strcmp(s, "You have a new telegram waiting ...\n") ||
	!strcmp(s, "Into the shredder, boss? y\n") ||
	!strcmp(s, "No telegrams for you at the moment...\n"));
    else if (*s == '>') {
      ++n;
      head[n].status = 'N';
      head[n].subj[0] = '\0';
      head[n].type = UNKNOWN;
      numlines[n] = 0;
      if (sscanf(s, "> Production Report %s %s %s %d %s %d",
		 dummy,weekday,month,&date,time,&year)==6) {
	head[n].type = PROD;
	strcpy(head[n].type_mark,"----");
	strcpy(head[n].from, "Production");
	sprintf(head[n].date, "%3s %3s %2d %8s", weekday, month, date, time);
      }
      else if (sscanf(s, "> BULLETIN from %s (#0) %s %s %s %d %s %d",
		      dummy,dummy,weekday,month,&date,time,&year)==7) {
	head[n].type = BULL;
	strcpy(head[n].type_mark,"*");
	strcpy(head[n].from, "BULLETIN");
	sprintf(head[n].date, "%3s %3s %2d %8s", weekday, month, date, time);
      }
      else if (sscanf(s, "> Telegram from %s (#%d) %s %s %s %d %s %d",
		      from,&cnum,dummy,weekday,month,&date,time,&year)==8) {
	from[strlen(from)-1] = '\0';
	head[n].type = TELE;
	sprintf(head[n].type_mark,"#%d", cnum);
	strncpy(head[n].from, from, 12);
	sprintf(head[n].date, "%3s %3s %2d %8s", weekday, month, date, time);
      }
      if (s[strlen(s) - 2] == ' ')
	if (s[strlen(s) - 3] == ' ') {
	  head[n].status = 'U';
	  if (!start_message && !new_message)
	    start_message = n;
	}
	else
	  head[n].status = 'R';
      else if (!new_message) {
	start_message = n;
	new_message = 1;
      }
      strncpy(telhead[n], clean_head(s), MAX_LINE_LENGTH);
    }
    else if (n) {
      strncpy(body[n][numlines[n]++], s, MAX_LINE_LENGTH);      
      if (head[n].type == PROD) {
	if (sscanf(s, "money delta was $%d for this update", &money) == 1)
	  sprintf(head[n].subj, "money delta:  $%d", money);
      }
      else if (head[n].type == BULL) {
	if (!*head[n].subj)
	  if (index(s, '(')) {
	    strncpy(head[n].subj, s, 30);
	    head[n].subj[strlen(head[n].subj) - 1] = '\0';
	  }
      }
      else if (!*head[n].subj)
	if (*s && strcmp(s, "\n")) {
	  strncpy(head[n].subj, s, 30);
	  head[n].subj[strlen(head[n].subj) - 1] = '\0';
	}
    }
    fgets(s, MAX_LINE_LENGTH, telfile);
  }
  if (!start_message)
    start_message = 1;
  return n;
}

print_headers(n,cm)
     int n,cm;
{
  int m;
  
  for (m = 1; m <= n; ++m)
    printf("%3d %c%c %4s %-12s %19s %-30s\n",
	   m,
	   m == cm?'>':' ',
	   head[m].status,
	   head[m].type_mark,
	   head[m].from,
	   head[m].date,
	   head[m].subj);
}

write_telegrams(telfile, n)
     FILE *telfile;
     int n;
{
  int m, i;

  for (m = 1; m <= n; ++m) {
    if (head[m].status != 'D') {
      if (head[m].status == 'R' || head[m].status == ' ')
	fprintf(telfile, "%s \n", telhead[m]);
      else
	fprintf(telfile, "%s  \n", telhead[m]);
      for (i = 0; i < numlines[m]; ++i)
	fprintf(telfile, "%s", body[m][i]);
    }
  }
}

prompt(n)
     int n;
{
  char s[MAX_COMMAND_LENGTH];
  int newm;
  int m = start_message;

  if (m > n)
    m = n;
  printf("(%d/%d): ", m, n);
  fgets(s, MAX_LINE_LENGTH, stdin);
  clean_head(s);
  while(!feof(stdin) &&
	strcmp(s, "q") &&
	strcmp(s, "x")) {
    if (!strcmp(s, "h"))
      print_headers(n,m);
    else if (!strcmp(s, "d")) {
      head[m].status = 'D';
      ++m;
    }
    else if (*s == 'd')
      process_delete(s + 1, n,0);
    else if (*s == 'u')
      process_delete(s + 1, n,1);
    else if (sscanf(s, "%d", &newm) == 1)
      if (newm < 1 || newm > n)
	printf("Bad message number: %d\n", newm);
      else
	print_message(m = newm);
    else if (!strcmp(s, ""))
      if (m == n)
	puts("No more messages.");
      else {
	if (head[m].status == ' ')
	  ++m;
	print_message(m);
      }
    else
      mail_help();
    
    printf("(%d/%d): ", m, n);
    fgets(s, MAX_LINE_LENGTH, stdin);
    clean_head(s);
  }
  if (!strcmp(s, "q"))
    return 1;
  return 0;
}

print_message(m)
     int m;
{
  int i;
  printf("Message #%d (%d lines)\n", m, numlines[m]);
  printf("%s\n", telhead[m]);
  for (i = 0; i < numlines[m]; ++i)
    printf("%s", body[m][i]);
  head[m].status = ' ';
}

#define NEW_STATUS undelete?((head[m].status == 'D')?'U':head[m].status):'D'

process_delete(s,n,undelete)
     char *s;
     int n;
     int undelete;
{
  char *sp = s;
  int m, p, q;
 
  if (!sp || !*sp)
    return;
  while (*sp && *sp == ' ') ++sp;
  s = sp;
  while(*sp && *sp != ' ') ++sp;
  if (*sp)
    process_delete(sp,n,undelete);
  *sp = '\0';
  if (sscanf(s, "%d-%d", &p, &q) == 2)
    if (p > q || p < 1 || q > n)
      printf("Bad range: %d-%d\n", p, q);
    else
      for (m = p; m <= q; ++m)
	head[m].status = NEW_STATUS;
  else if (sscanf(s, "%d", &m) == 1)
    if (m < 1 || m > n)
      printf("Bad message number: %d\n", m);
    else
      head[m].status = NEW_STATUS;
  else if (!strcmp(s, "b")) {
    for (m = 0; m <= n; ++m)
      if (head[m].type == BULL)
	head[m].status = NEW_STATUS;
  }
  else if (!strcmp(s, "p")) {
    for (m = 0; m <= n; ++m)
      if (head[m].type == PROD)
	head[m].status = NEW_STATUS;
  }
  else if (!strcmp(s, "*")) {
    for (m = 0; m <= n; ++m)
      head[m].status = NEW_STATUS;
  }
}

mail_help()
{
  puts("Commands are:");
  puts("h                     print the list of headers");
  puts("<n>                   print message number <n>");
  puts("d <message list>      delete message list");
  puts("u <message list>      undelete message list");
  puts("q                     quit and save changes");
  puts("x                     quit without saving changes");
  puts("");
  puts("For delete and undelete, if no <message list> is specified, then the");
  puts("current message is used.  Other choices for <message list> are:");
  puts("  <n>                 message number <n>");
  puts("  <n>-<m>             messages <n> through <m>");
  puts("  <n1> <n2> ... <nm>  messages <n1>, <n2>, ..., and <nm>");
  puts("  p                   all Production Reports");
  puts("  b                   all BULLETINS");
  puts("  *                   all messages");
  puts("");
  puts("The meanings of the message markers are:");
  puts("  N                   new");
  puts("  U                   unread");
  puts("  R                   read");
  puts("  D                   deleted");
}

SHAR_EOF
fi
if test -f 'startEdata'
then
	echo shar: "will not over-write existing file 'startEdata'"
else
cat << \SHAR_EOF > 'startEdata'
#!/bin/sh
#
# This is a script for Ken Stevens' Edata program.
#

\rm -fr pipe
mknod pipe p
sleep 9999999 > pipe &
echo $! > .Edata_pid
Edata < pipe &
SHAR_EOF
chmod +x 'startEdata'
fi
if test -f 'wingit'
then
	echo shar: "will not over-write existing file 'wingit'"
else
cat << \SHAR_EOF > 'wingit'
#!/bin/awk -f
#
#                               wingit
#
#                written by Ken Stevens for chainsaw 3.0
#
# DESCRIPTION:
# This script reads the output of the "plane" command and organises your
# planes into wings according to plane type.
#
# INSTALLATION:
# Before you run this script, make sure that you have typed:
# chmod +x wingit
# where wingit is the name of this file.
#
# HOW TO RUN IT:
# Change the values of the "wing" and "name" array to your favourite wing names
# for different types of planes.  Note that this script only uses the
# first two letters of the plane type when assigning wings, and it
# only includes planes which are more than 70% efficient in the wings.
# This script also writes a file called ".af" which lists some info about
# your planes.
#
# In your .eifrc file, put the following line:
# alias wingit "plane * >!.plane ; runfeed wingit .plane ; @cat .af"
# Then in eif you can type "wingit" to sort your planes into wings.
#
# BUG REPORTS:
# mail your bug-reports and comments to:
# stevens@math.utoronto.ca

BEGIN {
  wing["Ze"] = "Z";
  wing["f1"] = "f";
  wing["f2"] = "f";
  wing["f3"] = "f";
  wing["f4"] = "f";
  wing["lb"] = "l";
  wing["nf"] = "n";
  wing["hb"] = "h";
  wing["as"] = "u";
  wing["es"] = "e";
  wing["mb"] = "b";
  wing["tr"] = "t";
  wing["jf"] = "F";
  wing["sr"] = "i";
  wing["jl"] = "L";
  wing["np"] = "N";
  wing["nc"] = "C";
  wing["ir"] = "i";
  wing["mi"] = "M";
  wing["sl"] = "m";
  wing["jm"] = "B";
  wing["jh"] = "H";
  wing["tc"] = "t";
  wing["ac"] = "c";
  wing["jt"] = "T";
  wing["sm"] = "s";
  wing["sp"] = "p";
  wing["la"] = "d";
  wing["ab"] = "a";
  wing["ss"] = "D";
  wing["a-"] = "A";
  wing["ic"] = "I";
  wing["sf"] = "x";
  wing["sb"] = "y";
  name["Z"] = "Zepplins";
  name["f"] = "low tech fighters";
  name["lb"] = "low tech precision bombers";
  name["n"] = "low tech naval fighters";
  name["h"] = "low tech heavy bombers";
  name["u"] = "anti-sub planes";
  name["e"] = "escort planes";
  name["m"] = "medium bombers";
  name["t"] = "low tech transport planes & choppers";
  name["F"] = "jet fighters";
  name["i"] = "low tech land missiles";
  name["L"] = "jet precision bombers";
  name["N"] = "jet naval fighters";
  name["C"] = "naval choppers";
  name["M"] = "anti-ship missiles";
  name["B"] = "jet medium bombers";
  name["H"] = "jet heavy bombers";
  name["c"] = "attack choppers";
  name["T"] = "jet transports";
  name["s"] = "sams";
  name["p"] = "spy planes";
  name["d"] = "land satellites";
  name["a"] = "abm's";
  name["D"] = "spy satellites";
  name["A"] = "anti-satellites";
  name["I"] = "icbm's";
  name["x"] = "stealth fighters";
  name["y"] = "stealth bombers";
  name["z"] = "undefined";
}

{
  if (substr($0,1,1) == " " && $1 != "#" && $2 != "planes")
  {
    t = substr($2,1,2);
    w = wing[t];
    if (!w)
    {
      ++baf["z"];
      printf "Warning: undefined plane %s\n", $2 > ".af";
    }
    else
    {
      ++baf[w];
      if (substr($0, 38, 3) + 0 > 70)
      {
        ++af[w];
        if (flock[w] == "")
          flock[w] = $1;
        else if (length(flock[w]) > 80)
        {
          printf "wing %s %s\n", w, flock[w];
          flock[w] = $1;
        }
        else
          flock[w] = flock[w] "/" $1;
      }
    }
  }
}

END {
  for (w in flock)
    printf "wing %s %s\n", w, flock[w];
  printf "%4s %4s/%-4s %s\n", "wing", "eff", "tot", "type" > ".af";
  printf "-------------------------------------\n" > ".af";
  for (w in baf)
    printf "%4s %4d/%-4d %s\n", w, af[w], baf[w], name[w] > ".af";
}
SHAR_EOF
chmod +x 'wingit'
fi
exit 0
#	End of shell archive
