#! /bin/ksh
USAGE='USAGE: search_cd cd_links
   cd_links is a file with file_path 2 tabs and a link value.
   listing all the link files on the CD and the link value.

   Find out how we can get to
   /mnt/system_cd/usr/packages/interviews/bin
   through a link.  Look for a link to a file below bin or to 
   bin itself.
'
# (C) Copyright 1995 by Michael Coulter.  All rights reserved.

# SEARCH_DIR='/mnt/system_cd/usr/packages'
#SEARCH_DIR='/mnt/system_cd/usr/lib/smail'
#SEARCH_DIR='/mnt/system_cd/usr/X11R6/lib/X11'
SEARCH_DIR='/system_cd/usr/lib/emacs'

# Process parameters

   CD_LINK="$1" ; shift

# Do it

  set -P # print absolut hw path
  cat "$CD_LINK" | while read FILE LINK REST
  do
     # echo "search_cd: $FILE $LINK"
     if [ -d "$FILE" ]
     then
        cd "$FILE"
     else
        cd $(dirname "$FILE")
        cd $(dirname "$LINK") 2> /dev/null
     fi
     # echo "search_cd: dir is $PWD"
     if [ "$PWD" != "${PWD#$SEARCH_DIR}" ]
     then
	echo "$FILE with link $LINK is a problem"
     fi
  done
  exit 0
