#!/bin/sh

pdir=`dirname $0`
pnam=`basename $0`

usage()
{
    echo "$pnam <oldconfig> [to] <newconfig>"
    exit 1
}

if [ "X$1" = "X" -o ! -f "$1" ] ; then
	usage
fi
source="$1"

if [ "X$2" = "X" ] ; then
	usage
fi
if [ "$2" = "to" ] ; then
	shift
fi
if [ ! -f "$2" ] ; then
	echo "$2:notfound"
	usage
fi

template="$2"

echo "Generating table..."
cat "$source" | awk -f $pdir/setconf.awk | tee log.in
echo "..creating CONFIG..."
cat "$template" | awk -f $pdir/genconf.awk | tee log.out
echo "done."

if [ -s log.in -o -s log.out ] ; then
	exit 1
fi
exit 0