#!/bin/bash
###
 #  Main authors:
 #     Fabio Rossi <rossi@dmi.unipg.it>
 #
 #  Contributing authors:
 #     Stefano Bistarelli <bista@dmi.unipg.it>
 #     Francesco Santini <francesco.santini@dmi.unipg.it>
 #
 #  Copyright:
 #     Fabio Rossi, 2017
 #     Stefano Bistarelli, 2017
 #     Francesco Santini, 2017
 #
 #  This file is part of ConArg Project, a software for Argumentation Framework:
 #     http://www.dmi.unipg.it/conarg
 #
 #  Permission is hereby granted, free of charge, to any person obtaining
 #  a copy of this software and associated documentation files (the
 #  "Software"), to deal in the Software without restriction, including
 #  without limitation the rights to use, copy, modify, merge, publish,
 #  distribute, sublicense, and/or sell copies of the Software, and to
 #  permit persons to whom the Software is furnished to do so, subject to
 #  the following conditions:
 #
 #  The above copyright notice and this permission notice shall be
 #  included in all copies or substantial portions of the Software.
 #
 #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 #  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 #  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 #  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 #  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 #  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 #  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #
 ###

function usage() {
	echo "Usage:"
	echo -e "\t"`basename $0`
	echo -e "\t\tprint solver and authors information"

	echo -e "\t"`basename $0`" --formats"
	echo -e "\t\tprint supported formats (currently 'apx' for Aspartix format only)"

	echo -e "\t"`basename $0`" --problems"
	echo -e "\t\tprint supported problems"

	echo -e "\t"`basename $0`" -p <problem> -f <inputfile> -fo <inputfileformat> [-a argument]"
	echo -e "\t\tsolve the specified problem for the specified semantic."
	echo -e "\t\tThe optional -a parameter specifies the argument to check for credulous/sceptical (DC and DS problems only)\n"
	echo -e "\tSee (see https://www.dbai.tuwien.ac.at/iccma17/participation.html) for more info"
}

CONARG="`dirname $0`/conarg2"
INPUTFILE=""
PROBLEM=""
FORMAT=""
ARGUMENT=""

if test $# -lt 1
then
	echo "Conarg - ICCMA17 version"
	echo "Bistarelli Stefano <bista@dmi.unipg.it>, Santini Francesco <francesco.santini@dmi.unipg.it>, Rossi Fabio <rossi@dmi.unipg.it>"
	exit 0
else
	SAVEIFS=$IFS
	IFS=$(echo -en "\n\b")

	while (( "$#" ))
	do
		case $1 in
			"--formats")
				echo '[apx]'
				exit 0
			;;
			"--problems")
				echo '[EE-CO,SE-CO,DC-CO,DS-CO,EE-PR,SE-PR,DC-PR,DS-PR,EE-ST,SE-ST,DC-ST,DS-ST,EE-SST,SE-SST,DC-SST,DS-SST,EE-STG,SE-STG,DC-STG,DS-STG,EE-GR,SE-GR,DC-GR,DS-GR,EE-ID,SE-ID,DC-ID,DS-ID]'
				exit 0
			;;
			"-p")
				shift
				PROBLEM=$1
			;;
			"-f")
				shift
				INPUTFILE=$1
			;;
			"-fo")
				shift
				FORMAT=$1
			;;
			"-a")
				shift
				ARGUMENT=$1
			;;
			"--help")
				usage
				exit 0
			;;
			*)
				usage
				exit -1
			;;
		esac
	shift
	done
	IFS=$SAVEIFS
fi

if test -z $FORMAT 
then
	echo "Missing format"
	exit -1
else
	if test $FORMAT != "apx"
	then
		echo "Format '$FORMAT' not supported (currently Aspartix format only is supported)"
		exit -1
	else
		if test -z $INPUTFILE
		then
			echo "Missing input file name"
			exit -1
		fi
	fi
fi

case $PROBLEM in
	"DC-CO")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e complete -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-PR")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e preferred -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-ST")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e stable -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-SST")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e semistable -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-STG")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e stage -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-GR")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e grounded -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DC-ID")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e ideal -c $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-CO")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e complete -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-PR")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e preferred -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-ST")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e stable -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-GR")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e grounded -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-ID")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e ideal -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-SST")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e semistable -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"DS-STG")
		if test ! -z $ARGUMENT
		then
			$CONARG -q -p -e stage -s $ARGUMENT $INPUTFILE
		else
			echo "Missing argument to check"
			exit -1
		fi
	;;
	"EE-CO")
		$CONARG -q -p -e complete $INPUTFILE
	;;
	"EE-PR")
		$CONARG -q -p -e preferred $INPUTFILE
	;;
	"EE-ST")
		$CONARG -q -p -e stable $INPUTFILE
	;;
	"EE-SST")
		$CONARG -q -p -e semistable $INPUTFILE
	;;
	"EE-STG")
		$CONARG -q -p -e stage $INPUTFILE
	;;
	"EE-GR")
		$CONARG -q -p -e grounded $INPUTFILE
	;;
	"EE-ID")
		$CONARG -q -p -e ideal $INPUTFILE
	;;
	"SE-CO")
		$CONARG -q -p -e complete -n 1 $INPUTFILE
	;;
	"SE-PR")
		$CONARG -q -p -e preferred -n 1 $INPUTFILE
	;;
	"SE-ST")
		$CONARG -q -p -e stable -n 1 $INPUTFILE
	;;
	"SE-SST")
		$CONARG -q -p -e semistable -n 1 $INPUTFILE
	;;
	"SE-STG")
		$CONARG -q -p -e stage -n 1 $INPUTFILE
	;;
	"SE-GR")
		$CONARG -q -p -e grounded -n 1 $INPUTFILE
	;;
	"SE-ID")
		$CONARG -q -p -e ideal -n 1 $INPUTFILE
	;;
	*)
		echo "Problem $PROBLEM not supported"
		exit -1
	;;
esac



















