#!/usr/bin/env bash


set -o pipefail     # Disable output buffering

if [ $# -ne 3 ]; then
    echo "This script must be invoked with three parameters!"
    exit
fi

MAXINT=$1
MAX_NESTING_LEVEL=$2
OUTPUT_PREDICATES=$3

SCRIPTDIR=`dirname $0`
BIN=$SCRIPTDIR/dlv



if [ $MAXINT -eq 0 ]; then
	# Execution with preprocessing and postprocessing:
	$SCRIPTDIR/dlv_preprocess.pl | $BIN -pfilter=$OUTPUT_PREDICATES -n=1 -silent --  | $SCRIPTDIR/dlv_postprocess.pl 
fi
if [ $MAXINT -ne 0 ]; then
        # Execution with preprocessing and postprocessing:
        $SCRIPTDIR/dlv_preprocess.pl | $BIN -pfilter=$OUTPUT_PREDICATES -n=1 -N=$MAXINT -silent -- | $SCRIPTDIR/dlv_postprocess.pl 
fi

ECODE=$?
if [ $ECODE -ne 0 ]; then
    echo UNKNOWN;
fi
exit $ECODE

