# Extract MySQL Type Code Definitions

TMP1=${TMPDIR:-/tmp/$$-1.tmp}
TMP2=${TMPDIR:-/tmp/$$-2.tmp}

trap "rm -f '$TMP1 $TMP2'" 0

INP=gen.tmp
OUT=apq-mysql.ads

# while read VALUE NAME ; do
# 	case "$NAME" in
# 	CR_MIN_ERROR | CR_MAX_ERROR | ER_ERROR_MESSAGES )
# 		;;
# 	* )	echo "$VALUE $NAME";;
# 	esac
# done >"$TMP1"

cat >$TMP1

#
# EDIT THE PRAMGA LINKER OPTIONS INTO THE INPUT
#
sed <"$INP" >"$TMP2" '/%mysql_linker_options%/,$d'
./mysql_linker_options >>"$TMP2"

case "$(uname -s)" in
CYGWIN* )	sed <"$INP" >>"$TMP2" '1,/%mysql_linker_options%/d;s|%MYSQL_ROW_NO%|64|';;
* )		
		sed <"$INP" >>"$TMP2" '1,/%mysql_linker_options%/d;s|%MYSQL_ROW_NO%|64|';;
esac;

INP="$TMP2"


LINES=$(wc -l <"$TMP1")

sed <$INP >"$OUT" -n '1,/^ *type Field_Type is/p'

i=0
while read VALUE NAME ; do
	i=$(expr $i + 1)
	if [ $i -lt $LINES ] ; then
		echo "      $NAME,"
	else
		echo "      $NAME"
	fi
done <"$TMP1" >>$OUT

sed <$INP >>$OUT '1,/%ENUM_FIELD_TYPE%/d;/%USE_FIELD_TYPE%/,$d'

i=0
while read VALUE NAME ; do
	i=$(expr $i + 1)
	if [ $i -lt $LINES ] ; then
		echo "      $NAME => $VALUE,"
	else
		echo "      $NAME => $VALUE"
	fi
done <"$TMP1" >>$OUT

sed <$INP >>$OUT '1,/%USE_FIELD_TYPE%/d'

# Now edit in the MySQL Option Values

cp $OUT $TMP1
sed <"$TMP1" >$OUT '/%MYSQL_OPTIONS%/,$d'
cat opts.tmp >>$OUT
sed <"$TMP1" >>$OUT '1,/%MYSQL_OPTIONS%/d'

# End
