# Configures KScope parameters

# echo -n Looking for cscope...

if [ -z $CSCOPE_PATH ]
then
	CSCOPE_PATH=`which cscope`
fi

if [ \( $CSCOPE_PATH \) -a \( -x $CSCOPE_PATH \) ]
then
	echo $CSCOPE_PATH
	
	# echo -n Checking Cscope version...
	
	CSCOPE_VER_MAJOR=`$CSCOPE_PATH -V 2>&1 | grep cscope | sed -e "s/.*\([0-9][0-9]\)\.\([0-9]\).*/\1/"`
	CSCOPE_VER_MINOR=`$CSCOPE_PATH -V 2>&1 | grep cscope | sed -e "s/.*\([0-9][0-9]\)\.\([0-9]\).*/\2/"`
	if [ \( "$CSCOPE_VER_MAJOR" \) -a \( "$CSCOPE_VER_MINOR" \) ]
	then
		echo $CSCOPE_VER_MAJOR.$CSCOPE_VER_MINOR
		
		# echo -n Cscope support for line mode verbose output...
		
		if [ "`$CSCOPE_PATH -h 2>&1 | grep "\-v"`" ]
		then
			CSCOPE_VERBOSE=Yes
		else
			CSCOPE_VERBOSE=No
		fi
		echo $CSCOPE_VERBOSE
	else
		echo ERROR
		# echo -e "\n *** ERROR *** The \"cscope\" executable does not appear to be a Cscope compatible programme"
	fi
else
	echo ERROR
	# echo -e "\n *** ERROR *** No Cscope executable found"
fi

# echo -n Looking for Ctags...

if [ -z $CTAGS_PATH ]
then
	for CTAGS_NAME in exctags ctags-exuberant exuberant-ctags ctags
	do
		CTAGS_PATH=`which $CTAGS_NAME`
		if [ \( "$CTAGS_PATH" \) -a \( -x "$CTAGS_PATH" \) ]
		then
			break
		fi
	done
fi

if [ $CTAGS_PATH ]
then	
	echo $CTAGS_PATH
	
	# echo -n Checking for Exuberant-Ctags compatibility...
	
	CTAGS_EXUB=`$CTAGS_PATH --help | grep -c "\-\-excmd=number"`
	if [ $CTAGS_EXUB -gt 0 ]
	then
		CTAGS_EXUB_PATH=$CTAGS_PATH
		echo Yes
	else
		echo ERROR
		# echo -e "\n *** ERROR *** The \"ctags\" executable does not appear to be compatible with Exuberant Ctags"
	fi
	
else
	echo ERROR
	# echo -e "\n *** ERROR *** No Ctags executable found"
fi

# echo -n Looking for Dot...

if [ -z $DOT_PATH ]
then
	DOT_PATH=`which dot`
fi

if [ \( $DOT_PATH \) -a \( -x $DOT_PATH \) ]
then	
	echo $DOT_PATH
	
	# echo -n Checking if dot handles the -Tplain option...
	
	echo "digraph G {Hello->World}" | $DOT_PATH -Tplain >& /dev/null
	if [ $? -eq 0 ]
	then
		echo Yes
	else
		echo ERROR
		# echo -e "\n *** ERROR *** The \"dot\" executable does not support -Tplain"
	fi
	
else
	echo ERROR
	# echo -e "\n *** ERROR *** No Dot executable found"
fi
