#!/bin/bash
## This file is part of the aMule Project
##
## Copyright (c) 2006-2009      Angel Vidal (Kry) ( kry@amule.org )
## Copyright (c) 2006-2009      aMule Project     ( http://www.amule-project.net )
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA

# Wikifies lastest changelog entry. No sanity checking. Must be run from sources root folder.
if test x"`ls docs/Changelog`" = x""; then
  echo "This script must be run on aMule base directory."
else
  CHANGELOG="Changelog-`grep -h -E 'Version [0-9]\.[0-9]+\.[0-9]+.*' docs/Changelog | head -n 1 | cut -d ' ' -f 2`"
  head -n `grep -hn -E '(\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-)+' docs/Changelog | cut -d ':' -f 1 | head -1` docs/Changelog > $CHANGELOG 
  sed -i -r "s/\t([A-Z,a-z].+):$/'''\1:'''/g" $CHANGELOG
  sed -i -r "s/^(Version .+)$/=== \1 ===/g" $CHANGELOG
  sed -i -r "s/^----------$//g" $CHANGELOG
  sed -i -r "s/^([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)$/''\1''/g" $CHANGELOG
  sed -i -r "s/\t+(\*? .+)$/\1/g" $CHANGELOG
  while test x"`grep -E '^\s+.+$' $CHANGELOG`" != x""; do 
    sed -i -r "N 
		s/^(\*?.*)\n\s+([^\*]+)$/\1 \2/g " $CHANGELOG;
  done
  echo "$CHANGELOG created."
fi

