#! /bin/bash

function add_last_linefeed {
# $1 = file
  if [ "`tail -c 1 $1`" != "" ]; then
    echo "" >> $1
  fi
}

function delete_last_linefeed {
# $1 = file
  if [ "`tail -c 1 $1`" = "" ]; then
    xxx=$1;
    set yyyy `/bin/ls -l $xxx`
    head -c $(( $6 - 1 )) $xxx >$xxx.___
    mv -f $xxx.___ $xxx
  fi
}

add_last_linefeed src/commands/precompiled/autoexec.bat
add_last_linefeed contrib/dosC/readme.txt
patch -p1 -s < tmp/patch-0.99.5.1
delete_last_linefeed src/commands/precompiled/autoexec.bat
delete_last_linefeed contrib/dosC/readme.txt


for i in 2 3 4 5 6 ; do
  patch -p1 -s < tmp/patch-0.99.5.$i
done

patch -p1 -s < tmp/patch-0.99.6

rm -f core `find . -name '*.orig'`
rm -f core `find . -size 0`
sh set-permissions
rm -rf tmp
