#!/bin/sh -
# $Id: flushmaps,v 1.1.1.1 1993/03/07 08:30:51 frankj Exp $
#
# If you run this file from time to time, it will clean up old maps
# that are currently not in use (ie, not present in the mapindex file)
# The way a map can become "unused" is by changing the file-name of a
# map and save.

LIBDIR=xxxx
MAPDIR=$LIBDIR/maps
OLDMAPDIR=$LIBDIR/adm/oldmaps
MAPINDEX=/tmp/foo.$$
trap "rm -f $MAPINDEX;exit" 0 1 2 3 4 5 6 7 8 10 12 13 14 15
cut -f2- -d' ' <$LIBDIR/mapindex >$MAPINDEX

LOGFILE=$LIBDIR/adm/maps.log
touch $LOGFILE
test -d $OLDMAPDIR || mkdir $OLDMAPDIR

cd $MAPDIR
files=*.om
if test x"$files" = x; then
  exit
fi
echo Flushing maps `date` >>$LOGFILE

cd $MAPDIR
for i in $files; do
  length=`expr length $i`
  length=`expr $length - 3`
  name=`expr substr $i 1 $length`
  if fgrep -x $name $MAPINDEX >/dev/null; then
    :
  else
    ls -l $name.o[om] >>$LOGFILE
    mv $name.o[om] $OLDMAPDIR
  fi
done
rm -f $MAPINDEX
