#! /bin/csh -f 

set usage = "$0 DIR ICONSIZE"

# Replaces all symbolic links named "p-icon.gif" under directory DIR by
# symbolic links to "p-SIZE.gif".  Checks whether the latter exists.

set dir = "$1"; shift;
set size = "$1"; shift;

set tmp = "/tmp/$$"

if ( $#argv != 0 ) then
  echo "usage: $usage"; exit 1
endif

cd ${dir} || ( echo "can't cd to ${dir}"; exit 1 ) || exit 1

find ./ -type l -name 'p-icon.gif' -print > ${tmp}

foreach f ( `cat ${tmp}` )
  echo $f
  set g = "${f:h}/p-${size}.gif"
  if ( -r $g ) then
    /bin/rm $f && ln -s $g $f
  else
    echo "** $g not found" 
  endif
end

find ./ \( \! -type l \) -name 'p-icon.gif' -print > ${tmp}.nl

if ( ! ( -z ${tmp}.nl ) ) then
  echo "non-link icons (not touched):"
  cat ${tmp}.nl
endif

/bin/rm -f ${tmp} ${tmp}.nl