#!/bin/bash

#  	ccide - C Language Decision Table Code Generator 
#	Copyright (C) 2002-2004,2010,2012;  Thomas W. Young, e-mail:  ccide@twyoung.com

#    	This file is part of ccide, the C Language Decision Table Code Generator.

#   	Ccide is free software: you can redistribute it and/or modify
#   	it under the terms of the GNU General Public License as published by
#    	the Free Software Foundation, either version 3 of the License, or
#   	(at your option) any later version.

#    	Ccide is distributed in the hope that it will be useful,
#    	but WITHOUT ANY WARRANTY; without even the implied warranty of
#    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    	GNU General Public License for more details.

#    	You should have received a copy of the GNU General Public License
#    	along with Ccide.  If not, see <http://www.gnu.org/licenses/> or
#    	write to the Free Software Foundation, Inc., 51 Franklin St, 
#    	Fifth Floor, Boston, MA 02110-1301 USA.
# ----------------------------------------------- end of legal stuff ---------------------- #

# scripts/ccide.d.  Generated from ccide.d.in by configure.  ccide is a wrapper script for ccidew.  

CCIDELANG=C
BINDIR="/usr/bin"
PKGDATADIR=@pkgdatadir@
LANGSX="BASH BASIC C CH CC C++ CS EX JAVA QB VB JS"

function Die() {
	echo "CCIDE_DIE/DIE: "
	exit 1
}

#CCIDE_INLINE_CODE:
#GENERATED_CODE:
#
#ccide-BASH.m4
#Copyright (C) 2002-2004,2010,2012; Thomas W. Young, e-mail:  ccide@twyoung.com
#  The code generated by ccide is covered by the same license as the source  
#  code(decision table) from which it is derived. If you created the source,  
#  you are free to do anything you like with the generated code, 
#  including incorporating it into or linking it with proprietary software.  
#
function CcideFindRule() {             # Return rule number
	CCIDE=0; nstate=$(( 4294967295 ^ ${2} ))
        while [[ $CCIDE -lt ${1} ]] 						\
		&& (    [[ $((${CCIDE_YES[$CCIDE]} & $nstate)) -ne 0 ]] 	\
		     || [[ $((${CCIDE_NO[$CCIDE]}  & ${2})) -ne 0 ]] ); do	\
 	               CCIDE=$(($CCIDE+1))
        done
}
#
function CcideFindRuleYes() {             # Return rule number
	CCIDE=0; nstate=$(( 4294967295 ^ ${2} ))
        while [[ $CCIDE -lt ${1} ]] 						\
		&& [[ $((${CCIDE_YES[$CCIDE]} & $nstate)) -ne 0 ]]; do		\
               CCIDE=$(($CCIDE+1))
        done
}
#
#END_GENERATED_CODE:
#GENERATED_CODE: 
# Substitution strings are: /:: and @@/
#END_GENERATED_CODE: 

#DECISION_TABLE:
#    Y   Y   Y   Y   Y   Y   Y | -z "$CCIDEW" 
#    Y   -   -   -   -   -   - | -x ../src/ccidew 
#    -   Y   -   -   -   -   - | -x ../src/ccidew.exe 
#    -   -   Y   -   -   -   - | -x ./ccidew.exe 
#    -   -   -   Y   -   -   - | -x ./ccidew   
#    -   -   -   -   Y   -   - | -x $BINDIR/ccidew  
#    -   -   -   -   -   Y   - | -x $BINDIR/ccidew.exe  
#___________________________________________________________
#    X   -   -   -   -   -   - | CCIDEW=`pwd`/../src/ccidew
#    -   X   -   -   -   -   - | CCIDEW=`pwd`/../src/ccidew.exe
#    -   -   X   -   -   -   - | CCIDEW=`pwd`/ccidew.exe
#    -   -   -   X   -   -   - | CCIDEW=`pwd`/ccidew
#    -   -   -   -   X   -   - | CCIDEW=$BINDIR/ccidew
#    -   -   -   -   -   X   - | CCIDEW=$BINDIR/ccidew.exe
#    -   -   -   -   -   -   X | Die Cannot find bin/ccidew
#END_TABLE:
#GENERATED_CODE: FOR TABLE_1.
#	7 Rules, 7 conditions, and 7 actions.
#	Table 1 rule order = 1 2 3 4 5 6 7 
	CCIDE_YES=(3 5 9 17 33 65 1)


	CCIDE=0
[[ -z "$CCIDEW" ]]  && CCIDE=1
[[ -x ../src/ccidew ]] && CCIDE=$((CCIDE+=2)) 
[[ -x ../src/ccidew.exe ]] && CCIDE=$((CCIDE+=4)) 
[[ -x ./ccidew.exe ]] && CCIDE=$((CCIDE+=8)) 
[[ -x ./ccidew ]] && CCIDE=$((CCIDE+=16)) 
[[ -x $BINDIR/ccidew ]] && CCIDE=$((CCIDE+=32)) 
[[ -x $BINDIR/ccidew.exe ]] && CCIDE=$((CCIDE+=64)) 
		  
	CcideFindRuleYes 7 $CCIDE;	case $CCIDE in

	(6) #	Rule 7
	    Die Cannot find bin/ccidew;
	    ;;
	(5) #	Rule 6
	    CCIDEW=$BINDIR/ccidew.exe;
	    ;;
	(4) #	Rule 5
	    CCIDEW=$BINDIR/ccidew;
	    ;;
	(3) #	Rule 4
	    CCIDEW=`pwd`/ccidew;
	    ;;
	(2) #	Rule 3
	    CCIDEW=`pwd`/ccidew.exe;
	    ;;
	(1) #	Rule 2
	    CCIDEW=`pwd`/../src/ccidew.exe;
	    ;;
	(0) #	Rule 1
	    CCIDEW=`pwd`/../src/ccidew;
	    ;;
	esac
#END_GENERATED_CODE: FOR TABLE_1, by ccide-0.6.6-1 Sun Oct  7 21:06:36 2012 


#   Set m4 directory...  	
CWD=`pwd`
[ -f ../m4/ccide-CC.m4 ] && M4DIR=$CWD/../m4
[ -f m4/ccide-CC.m4 ] && M4DIR=$CWD/m4
[ -f /usr/share/ccide/ccide-CC.m4 ] && M4DIR=/usr/share/ccide
[ -z $CCIDE_M4DIR ] || M4DIR=$CCIDE_M4DIR;   # CCIDE_M4DIR overrides if specified:

while [[ $# > 0 ]]; do
	#DECISION_TABLE:
	#    Y   -   -   -   - | "$1" == "-L"
	#    -   Y   -   -   - | "$1" == "-m4"
	#    -   -   Y   -   - | "$1" == "--help"
	#    -   -   -   Y   - | ("$1" == "-V") || ("$1" == "--version")
	#________________________________________________________
	#    X   -   -   -   - | CCIDELANG=`echo $2|tr [:lower:] [:upper:]`; shift
	#    -   X   -   -   - | CCIDE_M4="yes"
	#    -   -   X   -   - | $CCIDEW --help
	#    -   -   X   -   - | exit 0
	#    -   -   -   X   - | echo "	ccide-0.6.6-1"
	#    -   -   -   X   - | WC="$WC -V"
	#    -   -   -   -   X | WC="$WC $1"
	#END_TABLE:
	#GENERATED_CODE: FOR TABLE_2.
	#	5 Rules, 4 conditions, and 7 actions.
	#	Table 2 rule order = 1 2 3 4 5 
		CCIDE_YES=(1 2 4 8 0)


		CCIDE=0
	[[ "$1" == "-L" ]]  && CCIDE=1
	[[ "$1" == "-m4" ]] && CCIDE=$((CCIDE+=2)) 
	[[ "$1" == "--help" ]] && CCIDE=$((CCIDE+=4)) 
	[[ ("$1" == "-V") || ("$1" == "--version") ]] && CCIDE=$((CCIDE+=8)) 
			  
	CcideFindRuleYes 5 $CCIDE;	case $CCIDE in

		(4) #	Rule 5
		    WC="$WC $1";
		    ;;
		(3) #	Rule 4
		    echo "	ccide-0.6.6-1";
		    WC="$WC -V";
		    ;;
		(2) #	Rule 3
		    $CCIDEW --help;
		    exit 0;
		    ;;
		(1) #	Rule 2
		    CCIDE_M4="yes";
		    ;;
		(0) #	Rule 1
		    CCIDELANG=`echo $2|tr [:lower:] [:upper:]`; shift;
		    ;;
		esac
	#END_GENERATED_CODE: FOR TABLE_2, by ccide-0.6.6-1 Sun Oct  7 21:06:36 2012 
	shift
done

#DECISION_TABLE:
#    Y   -   -   - | "$CCIDE_M4" == "yes"
#    -   Y   -   - | "$CCIDELANG" == "C" 
#    -   -   Y   - | "$CCIDELANG" == "?"
#    -   -   -   Y | "$CCIDELANG" == "CH"
#________________________________________________________
#    X   -   -   - | $CCIDEW -m4 $WC
#    -   X   -   X | $CCIDEW $WC
#    -   -   X   - | echo "Ccide supported languages are: $LANGSX"
#    X   X   -   X | exit $?
#    -   -   X   - | exit 2
#END_TABLE:
#GENERATED_CODE: FOR TABLE_3.
#	4 Rules, 4 conditions, and 5 actions.
#	Table 3 rule order = 1 2 3 4 
	CCIDE_YES=(1 2 4 8)


	CCIDE=0
[[ "$CCIDE_M4" == "yes" ]]  && CCIDE=1
[[ "$CCIDELANG" == "C" ]] && CCIDE=$((CCIDE+=2)) 
[[ "$CCIDELANG" == "?" ]] && CCIDE=$((CCIDE+=4)) 
[[ "$CCIDELANG" == "CH" ]] && CCIDE=$((CCIDE+=8)) 
		  
	CcideFindRuleYes 4 $CCIDE;	case $CCIDE in

	(2) #	Rule 3
	    echo "Ccide supported languages are: $LANGSX";
	    exit 2;
	    ;;
	(1) #	Rule 2
	    $CCIDEW $WC;
	    exit $?;
	    ;;
	(3) #	Rule 4
	    $CCIDEW $WC;
	    exit $?;
	    ;;
	(0) #	Rule 1
	    $CCIDEW -m4 $WC;
	    exit $?;
	    ;;
	esac
#END_GENERATED_CODE: FOR TABLE_3, by ccide-0.6.6-1 Sun Oct  7 21:06:36 2012 


[ -f $M4DIR/ccide-${CCIDELANG}.m4 ] || Die Cannot find $M4DIR/ccide-${CCIDELANG}.m4

#DECISION_TABLE:
#    Y   -   N | "$CCIDELANG" == "BASH"
#    -   Y   - | "$CCIDELANG" == "EX"
#__________________________________________
#    X   -   - | DELIM="-d '[[' ']]'" 
#    -   X   X | $CCIDEW            -L $CCIDELANG $WC | /usr/bin/m4 -P "$M4DIR/ccide-$CCIDELANG.m4" "-"
#    X   -   - | $CCIDEW -m4 $DELIM -L $CCIDELANG $WC | /usr/bin/m4 -P "$M4DIR/ccide-$CCIDELANG.m4" "-"
#END_TABLE:
#GENERATED_CODE: FOR TABLE_4.
#	3 Rules, 2 conditions, and 3 actions.
#	Table 4 rule order = 1 3 2 
	CCIDE_YES=(1 0 2)
CCIDE_NO=(0 1 0)


	
CCIDE=0
[[ "$CCIDELANG" == "BASH" ]]  && CCIDE=1
[[ "$CCIDELANG" == "EX" ]] && CCIDE=$((CCIDE+=2)) 
		  
	CcideFindRule 3 $CCIDE;	case $CCIDE in
	(0) #	Rule 1
	    DELIM="-d '[[' ']]'";
	    $CCIDEW -m4 $DELIM -L $CCIDELANG $WC | /usr/bin/m4 -P "$M4DIR/ccide-$CCIDELANG.m4" "-";
	    ;;
	(1) #	Rule 3
	    $CCIDEW            -L $CCIDELANG $WC | /usr/bin/m4 -P "$M4DIR/ccide-$CCIDELANG.m4" "-";
	    ;;
	(2) #	Rule 2
	    $CCIDEW            -L $CCIDELANG $WC | /usr/bin/m4 -P "$M4DIR/ccide-$CCIDELANG.m4" "-";
	    ;;
	esac
#END_GENERATED_CODE: FOR TABLE_4, by ccide-0.6.6-1 Sun Oct  7 21:06:36 2012 

 
exit $?
