#!/bin/csh -f
#
# It is not clear this script is ready for general consumption.
# Removing everything under CACHDIR is a fine option if this 
# does not work - remember that it is only a cache.
#
# Flags:
#     r  -  print out readmes
#     q  -  quick - do not check consistency (currently does not work with r)
#     h  -  print histograms
#

unlimit datasize
unlimit stacksize

set DEFS = BINDIR/defs
set CACHEDIR=`$DEFS cachedir`
echo "The cache directory is $CACHEDIR"

# /usr/bin/sort only takes up to 21 chars in path so this could be too long
# depending on what all is in CACHEDIR
set   T = `$DEFS tmpdir`

if (! -e $T) then
    echo "Making tmp directory"
    mkdir $T
endif

echo "The tmpdir is $T"
cd $T

date
find $CACHEDIR -name .alex.info -print  | sed s-/.alex.info-- | sort -T $T > alex.info.dirs
date

cat alex.info.dirs | BINDIR/alexfsck $1 >& results.fsck
date


grep "was new in" results.fsck | awk '{print $7}' >  no.dot
grep "did not point" results.fsck | awk '{print $11}' | sed s-/.alex.info-- > no.dotdot


cat no.dot no.dotdot | sed s.$CACHEDIR./alex. | sort -u > need.update

wc need.update

mkdir .split
/bin/rm .split/*

split -100 need.update .split/
foreach SET ( `ls .split` )
   date
    foreach PATH (`cat .split/$SET`)
        echo $PATH
        cat $PATH/.alex.update
    end
end

