#!/bin/sh
#
#  SetupComponent - Add or delete components from the source tree.
#
#  SetupComponent,v 1.2 1995/03/17 00:37:50 hardy Exp
#
if test $# -ne 3; then
	echo "Usage: ./SetupComponent add subsystem component";
	echo "       ./SetupComponent delete subsystem component";
	echo "";
	echo "Please refer to the Harvest User Manual for further help.";
	exit 1;
fi
cmd="$1";
subsys="$2";
component="$3";

if test "$cmd" != "add" -a "$cmd" != "delete"; then
	echo "Usage: ./SetupComponent add subsystem component";
	echo "       ./SetupComponent delete subsystem component";
	echo "";
	echo "Please refer to the Harvest User Manual for further help.";
	exit 1;
fi

if test ! -d "./components/$subsys"; then
	echo "$subsys is not a valid subsystem name."
	exit 1;
fi

if test ! -d "./components/$subsys/$component"; then
	echo "$component is not a valid component for $subsys."
	exit 1;
fi

if test "$cmd" = "add"; then
	echo "Adding $component to $subsys."
	echo "$component" >> ./components/$subsys/BUILD
	exit 0
fi

# delete
tfile="/tmp/sc.$$"
echo "Deleting $component to $subsys."
grep -v "$component" ./components/$subsys/BUILD > $tfile
cp $tfile ./components/$subsys/BUILD
rm -f $tfile

exit 0
