#!/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
