#!/bin/sh
if test "$1" = "-help"
then
    echo "purpose: make aliases file 'ugaliases' for  easy changing ";
	echo "         into ug's directories,e.g. instead of typing on ";
	echo "         your shell command line: ";
    echo "             cd \$UGROOT/gm/gg3             ";
    echo "         you can use:                      ";
    echo "             cdgg3                         ";
	echo "         (remark that no space is used)    ";
	echo "         To activate the 'ugaliases' file in your shell ";
	echo "         type on your shell command line:  ";
	echo "             source \$UGROOT/bin/ugaliases  ";
	echo "         you can also put this line into your shell ";
	echo "         resource file (e.g. ~/.tcshrc) to use the  ";
	echo "         shortcutting permanently.";
    exit 1;
fi

if test "x$UGROOT" = "x"
then
    echo "$0: to use $0 set shell environment variable UGROOT!";
    exit 1;
fi

UGALIASESFILE=$UGROOT/bin/ugaliases

cd $UGROOT;
rm -f $UGALIASESFILE;

echo " creating aliases for ug...";

# create aliases for applications
cd ..;
for i in *
do
	if test "$i" != "ug"
	then
		if test -d $i -a ! -h $i
		then
			if test "`basename $i`" != "CVS"
			then
				echo "alias cd`basename $i` 'cd \$UGROOT/../$i'" >> $UGALIASESFILE;
			fi
			for j in $i/*
			do
				if test -d $j -a ! -h $j
				then
					if test "`basename $j`" != "CVS"
					then
						echo "alias cd`basename $i``basename $j` 'cd \$UGROOT/../$j'" >> $UGALIASESFILE;
					fi
				fi
			done
		fi
	fi
done

cd $UGROOT;

# create aliases for ug directory
echo "alias cdug 'cd \$UGROOT'" >> $UGALIASESFILE;
for i in  `find . -type d \
			\( -name man -o -name doc -o -name ddd -o -name CVS \) -prune -o \
			-type d \
			-print`
do
	echo $i
	echo "alias cd`basename $i` 'cd \$UGROOT/$i'" >> $UGALIASESFILE;
done

chmod 755 $UGALIASESFILE;


# create aliases for application and problem part

# final message
echo " new 'ugaliases' file ($UGALIASESFILE) created!";
