#! /bin/csh -f
#
#  usage:     add-jpg -a ../*JPG
#     or:     add-jpg ../DSC_1234.JPG    This is a funny annotation for gallery.dat
#
# $Id: add-jpg,v 1.3 2007/03/26 23:22:07 teuben Exp $


#
if ($#argv == 0) then
  echo Examples:
  echo "$0 -a ../*JPG"
  echo "$0 ../DSC_1234.JPG    This is a funny annotation for gallery.dat"
  exit 0
endif


if (! -e gallery.dat) then
  echo File gallery.dat does not exist yet. Please create it with jigl first:
  echo "e.g."
  echo jigl -cg
  exit 0
endif


#                                figure out single or all (-a) mode
set all=0
if (! -e $1) then
  if (X$1 == X-a) then
    set all=1
  else
    echo File $1 must exist
    exit 1
  endif
endif


if ($all) then
  shift
  foreach file ($*)
    if (! -e $file) then
      echo skipping $file, it does not exist
      continue
    endif
    set filet=$file:t
    if (-e $filet) then
      echo skipping $filet, already existed
      continue
    endif
    ln -s $file
    echo "$filet ---- " >> gallery.dat
  end
else
  set file=$1
  set filet=$file:t
  if (-e $filet) then
    echo skipping $filet, already existed
  else
    shift
    ln -s $file
    echo "$filet ---- $*" >> gallery.dat
  endif
endif
