#!/gnu/store/29jhbbg1hf557x8j53f9sxd9imlmf02a-bash-minimal-5.0.7/bin/sh
#
#
AWK=gawk
DIR=/gnu/store/4rs159kgsa0l1svi5vbvn86in7z28bpl-mit-krb5-1.17/share/et

usage="usage: $0 [ -d scriptDir ] [ --textdomain domain [ --localedir dir ] ]"
usage="$usage inputfile.et"

TEXTDOMAIN=
LOCALEDIR=

while [ $# -ge 2 ]; do
    if [ "$1" = "-d" ]; then
	DIR=$2; shift; shift
    elif [ "$1" = "--textdomain" ]; then
	TEXTDOMAIN=$2; shift; shift
    elif [ "$1" = "--localedir" ]; then
	LOCALEDIR=$2; shift; shift
    else
	echo $usage 1>&2 ; exit 1
    fi
done

# --localedir requires --textdomain.
if [ $# -ne 1 -o \( -n "$LOCALEDIR" -a -z "$TEXTDOMAIN" \) ]; then
    echo $usage 1>&2 ; exit 1
fi

ROOT=`echo $1 | sed -e s/.et$//`
BASE=`echo "$ROOT" | sed -e 's;.*/;;'`

set -ex
$AWK -f ${DIR}/et_h.awk "outfile=${BASE}.h" "$ROOT.et"
$AWK -f ${DIR}/et_c.awk "outfile=${BASE}.c" "textdomain=$TEXTDOMAIN" \
    "localedir=$LOCALEDIR" "$ROOT.et"
