#!/bin/sh
# Snap symbolic links, i.e. replace links with copies of the files they
# point to.
if test $# -eq 0 ; then
   echo "Usage: 'snap filespec [filespec filespec ...]'."
   echo "  For each filespec which is a symbolic link, 'snap' replaces"
   echo "  it with a copy of the file to which it points.  Files which"
   echo "  are not symbolic links are unaffected."
   echo "  This means you can say 'snap *' to snap all the symbolic links"
   echo "  in a given directory at once, leaving the real files alone."
   exit 1
fi
tmpname=snap.$$
if test -e $tmpname; then \
   echo "Temp file already exists." ; exit 1; \
fi
files=`/bin/ls -F $* | /bin/grep @ | sed 's/@//'`
echo "File list: $files"
for f in $files; do \
    if test -d $f; then \
       echo "$f is a directory." ; \
    elif test -r $f; then \
#         echo "Copying $f to $tmpname." ; \
       cp $f $tmpname ; \
#         echo "Moving $tmpname to $f." ; \
       mv -f $tmpname $f ; \
    else
       echo "I can't read the file $f." ; \
    fi;
done
echo "Removing temp file."
rm -f $tmpname
