#!/bin/sh

# This script, given some commented Scott datafiles, compiles the
# datafiles in to a TRS-80 Scott adventure datafile

# Here are the datafiles this program uses
# header.dat: The header with number of rooms, etc
# actions.dat: A datafile with all of the actions we process (series of 
# numbers; see ScottDefinition for details)
# vocab.dat: A vocabulary listing
# rooms.dat: A listing of rooms in the game
# messages.dat: Messages shown to the player during the game
# objects.dat: Objects in the game

cat header.dat | sed 's/#.*//' | tr -d ' ' > game.dat
cat actions.dat | sed 's/#.*//' | egrep '[0-9]' | tr -d ' ' >> game.dat
cat vocab.dat | sed 's/#.*//' | egrep '[^\s]' | awk '$2 ~ /[A-Z0-9\.]/ {
		gsub(/\([^\)]*\)/,"");
		sub(/^\.$/,"",$2);
		sub(/^\.$/,"",$3);
		print "\""$2"\"";
		print "\""$3"\""}' >> game.dat
cat rooms.dat | sed 's/#.*//' | egrep '[^\s]' | awk '
		{sub(/ $/,"");print}' >> game.dat
cat messages.dat | sed 's/#.*//'| egrep '[^\s]' | awk '
		{sub(/ $/,"");print}' >> game.dat
cat objects.dat | sed 's/#.*//'| egrep '[^\s]' | awk '
		{sub(/ $/,"");print}' >> game.dat
cat actions.dat | sed 's/#.*//' | egrep '[0-9]' | awk '
	{a++;if(a % 8 == 0){print "\"\""}}' >> game.dat
echo 2 >> game.dat   # Version
echo 99 >> game.dat  # Adventure number
echo 1234 >> game.dat # Unknown "magic" number
