#!/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);
  }   
}

