#!/bin/sh

TEXT=0
CONTAINED=0
DYNAMIC=0
PROCESS=0

INDEX=0
NOINDEX=0

ROOT=foo

while [ x"$1" != x ]; do
  case $1 in
  -a0)
    DYNAMIC=1
    INDEX=1
    NOINDEX=1
    shift
    continue;;

  -a1)
    DYNAMIC=1
    PROCESS=1
    INDEX=1
    NOINDEX=1
    shift
    continue;;

  -a2)
    DYNAMIC=1
    PROCESS=1
    CONTAINED=1
    INDEX=1
    NOINDEX=1
    shift
    continue;;

  -a3)
    DYNAMIC=1
    PROCESS=1
    CONTAINED=1
    TEXT=1
    INDEX=1
    NOINDEX=1
    shift
    continue;;

  -b)
    INDEX=1
    NOINDEX=1
    shift
    continue;;

  -c)
    CONTAINED=1
    shift
    continue;;

  -d)
    DYNAMIC=1
    shift
    continue;;

  -i)
    INDEX=1
    shift
    continue;;

  -n)
    NOINDEX=1
    shift
    continue;;

  -p)
    PROCESS=1
    shift
    continue;;

  -t)
    TEXT=1
    shift
    continue;;

  -z)
    FILTER_PAINT=true
    export FILTER_PAINT
    shift
    continue;;

  *)
    shift
    continue;;
  esac
done

if [ $TEXT = 0 -a $CONTAINED = 0 -a $DYNAMIC = 0 -a $PROCESS = 0 ]; then
  DYNAMIC=1
  PROCESS=1
  TEXT=1
fi

if [ $INDEX = 0 -a $NOINDEX = 0 ]; then
  INDEX=1
fi

echo " "
echo "dynamic=$DYNAMIC text=$TEXT process=$PROCESS contained=$CONTAINED"
echo "index=$INDEX noindex=$NOINDEX"
if [ x$FILTER_PAINT = xtrue ]; then
  X=z
  echo "filter paint mode is on"
else
  X=""
fi
echo "testing against old funcnts: `which funcnts`"
echo "making evread ..."
make evread
echo " "

FILTER_IDX_DEBUG=0
export FILTER_IDX_DEBUG

if [ x$DYNAMIC = x1 ]; then
  echo "dynamic ..."
  FILTER_PTYPE=d
  export FILTER_PTYPE
  if [ x$INDEX = x1 ]; then
    echo "with index ..."
    date
    FILTER_IDX_ACTIVATE=1
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.id$X 2>&1
    if [ x$TEXT = x1 ]; then
      echo "... and with text ..."
      date
      ./funtexts > ${ROOT}.it$X 2>&1
    fi
  fi
  if [ x$NOINDEX = x1 ]; then
    echo "no index ..."
    date
    FILTER_IDX_ACTIVATE=0
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.nd$X 2>&1
    if [ x$TEXT = x1 ]; then
      echo "... and with text ..."
      date
      ./funtexts > ${ROOT}.nt$X 2>&1
    fi
  fi
fi

if [ x$PROCESS = x1 ]; then
  echo "process ..."
  FILTER_PTYPE=p
  export FILTER_PTYPE
  if [ x$INDEX = x1 ]; then
    echo "with index ..."
    date
    FILTER_IDX_ACTIVATE=1
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.ip$X 2>&1
  fi
  if [ x$NOINDEX = x1 ]; then
    echo "no index ..."
    date
    FILTER_IDX_ACTIVATE=0
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.np$X 2>&1
  fi
fi

if [ x$CONTAINED = x1 ]; then
  echo "contained ..."
  FILTER_PTYPE=c
  export FILTER_PTYPE
  if [ x$INDEX = x1 ]; then
    echo "with index ..."
    date
    FILTER_IDX_ACTIVATE=1
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.ic$X 2>&1
  fi
  if [ x$NOINDEX = x1 ]; then
    echo "no index ..."
    date
    FILTER_IDX_ACTIVATE=0
    export FILTER_IDX_ACTIVATE
    ./funtests $* >${ROOT}.nc$X 2>&1
  fi
fi

echo "done"
date
