#!/bin/sh

function confirm ()
{ while true; do
    echo -n "$1 "
    read answer
    case "$answer" in
          y*)   return 0
                ;;
          n*)   return 1
                ;;
          *)
                echo "Please answer yes or no"
                ;;
    esac
  done
}

version=`cat VERSION`
versiondate=`date +"%B %Y"`
major=`echo $version | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1/'`
minor=`echo $version | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\2/'`
patch=`echo $version | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\3/'`

tmp=.tmp$$

f=src/Makefile.in
sed "s/^PCEVERSIONDATE=.*/PCEVERSIONDATE=$versiondate/" $f > $tmp
if cmp $f $tmp; then
    rm -f $tmp
else
    cp $tmp $f
    echo "Updated PCEVERSIONDATE in $f"
fi

f=src/h/interface.h
sed "s/^#define PCE_VERSION.*/#define PCE_VERSION "\""$version, $versiondate"\"/ $f > $tmp
if cmp $f $tmp; then
    rm -f $tmp
else
    cp $tmp $f
    echo "Updated #define PCE_VERSION in $f"
fi

rm -f $tmp
