#!/nix/store/226mxicx2n7hgdf2424vz5y526nlyly8-bash-5.2-p15/bin/sh
#
#
AWK=gawk
DIR=/nix/store/73607zrlqz12j17jvqfy5gc3ircffq3x-libkrb5-1.20.2/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"
