#!/bin/sh
# Handle Bison version issues for derive_parser.y
#

b_version=`bison --version | sed -n -e '/^bison/s/.*)  *//p'`

if [ -z "$b_version" ]
then
    echo "Arrgh ... cannot get bison version from ..."
    bison --version
    exit 1
fi

if [ ! -f derive_parser.y.in ]
then
    echo "Arrgh ... cannot find derive_parser.y.in"
    exit 1
fi

rm -f derive_parser.y
cat <<End-of-File >derive_parser.y
/*
 * DO NOT EDIT THIS FILE ... CHANGES HERE WILL BE LOST
 *
 * This file created from derive_parser.y.in (make changes there!)
 * by fix_derive_parser_y on `date`.
 */

End-of-File

case "$b_version"
in
    2.[0-3]*)
	sed -e 's/^PUT-PREFIX-DECL-HERE.*/%name-prefix="derive_"/' <derive_parser.y.in >>derive_parser.y
	;;
    2.[4-7]*)
	sed -e 's/^PUT-PREFIX-DECL-HERE.*/%name-prefix "derive_"/' <derive_parser.y.in >>derive_parser.y
	;;
    2.[8-9]*|3.*)
	sed -e 's/^PUT-PREFIX-DECL-HERE.*/%define api.prefix {derive_}/' <derive_parser.y.in >>derive_parser.y
	;;
    *)
	rm -f derive_parser.y
	echo "Arrgh ... don't know what to do with bison version $b_version"
	exit 1
	;;
esac

chmod a-w derive_parser.y

exit 0
