#!/bin/sh
#   LinkMy file...
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Try to find a version of each named file for this machine, and link it into #
# the current working directory.  We use the environment variables  $HOSTNAME #
# and  $SYSTYPE,  and  call  hostype  and .hostype to set them if they aren't #
# already defined.  Suppose we have                                           #
#   $HOSTNAME = foo                                                           #
#   $SYSTYPE  = bar                                                           #
# and the command is                                                          #
#   LinkMy xyz                                                                #
# We will look for xyz in the following order:                                #
#   Lc foo_xyz xyz                                                            #
#   Lc bar_xyz xyz                                                            #
#   Lc foo/xyz xyz                                                            #
#   Lc bar/xyz xyz                                                            #
#   Lc ../foo_xyz xyz                                                         #
#   Lc ../bar_xyz xyz                                                         #
#   Lc src/foo_xyz xyz                                                        #
#   Lc src/bar_xyz xyz                                                        #
#   Lc src/hdr/foo_xyz xyz                                                    #
#   Lc src/hdr/bar_xyz xyz                                                    #
# where "src" is the environment variable $SRC if it is defined, and  /src #
# otherwise.   The first of these files that is found is the one that will be #
# linked into the current directory.  The "Lc" command does a ln if possible, #
# and a cp if the ln fails.                                                   #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
if [ ! -n "$SYSTYPE" -a -f  hostype ];then eval  `hostype -she`;fi
if [ ! -n "$SYSTYPE" -a -f .hostype ];then eval `.hostype -she`;fi
if [ ! -n "$SYSTYPE" ];then echo "### Can't figure out the SYSTYPE"; exit 1;fi
#
for f
do
	if  [ -f    $HOSTNAME'_'$f ];then
		Lc      $HOSTNAME'_'$f $f
		echo ln $HOSTNAME'_'$f $f
	elif [ -f   $SYSTYPE'_'$f ];then
		Lc      $SYSTYPE'_'$f $f
		echo ln $SYSTYPE'_'$f $f
	elif [ -f   $HOSTNAME'/'$f ];then
		Lc      $HOSTNAME'/'$f $f
		echo ln $HOSTNAME'/'$f $f
	elif [ -f   $SYSTYPE'/'$f ];then
		Lc      $SYSTYPE'/'$f $f
		echo ln $SYSTYPE'/'$f $f
	elif [ -f   ../$HOSTNAME'_'$f ];then
		Lc      ../$HOSTNAME'_'$f $f
		echo ln ../$HOSTNAME'_'$f $f
	elif [ -f   ../$SYSTYPE'_'$f ];then
		Lc      ../$SYSTYPE'_'$f $f
		echo ln ../$SYSTYPE'_'$f $f
	elif [ -f   ${SRC-/src}/$HOSTNAME'_'$f ];then
		Lc      ${SRC-/src}/$HOSTNAME'_'$f $f
		echo Lc ${SRC-/src}/$HOSTNAME'_'$f $f
	elif [ -f   ${SRC-/src}/$SYSTYPE'_'$f ];then
		Lc      ${SRC-/src}/$SYSTYPE'_'$f $f
		echo Lc ${SRC-/src}/$SYSTYPE'_'$f $f
	elif [ -f   ${SRC-/src}/hdr/$HOSTNAME'_'$f ];then
		Lc      ${SRC-/src}/hdr/$HOSTNAME'_'$f $f
		echo Lc ${SRC-/src}/hdr/$HOSTNAME'_'$f $f
	elif [ -f   ${SRC-/src}/hdr/$SYSTYPE'_'$f ];then
		Lc      ${SRC-/src}/hdr/$SYSTYPE'_'$f $f
		echo Lc ${SRC-/src}/hdr/$SYSTYPE'_'$f $f
	else
		echo "###Can't find $SYSTYPE $f"
	fi
done
exit
