#!/bin/sh
#
#  dosbox-genconf  --  generate config/lang files for DOSBox
#

: ${DOSBOX:=./dosbox}
: ${CONF:=dosbox.conf}
: ${CONF_SAMPLE:=${CONF}.sample}
: ${CONF_HEADER:=${CONF_SAMPLE}-header}
:   ${CONF_BODY:=${CONF_SAMPLE}-body}
:   ${CONF_LANG:=dosbox.lang.en}

function main()
{
    if [ -z "$DISPLAY" ]; then
	echo "Error: DISPLAY variable is empty, X Window is not started?"
	return 1
    fi

    if [ ! -x "$DOSBOX" ]; then
	echo "Error: cannot find $DOSBOX, check DOSBOX variable!"
	return 1
    fi

    cd `dirname $0`

    $DOSBOX -conf /dev/null . \
	-c "config -writeconf ${CONF_BODY}" \
        -c "config -writelang ${CONF_LANG}" \
	-c exit

    if [ -r ${CONF_HEADER} ]; then
	cat ${CONF_HEADER} ${CONF_BODY} > ${CONF_SAMPLE}
        rm -f ${CONF_BODY}
    else
	mv -f ${CONF_BODY} ${CONF_SAMPLE}
    fi

    cd -
}

main "$@"

## EOF ##
