#! /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
}

for i in 1 2; do
 patch -p1 -s < tmp/patch-0.98.3.$i
done

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

patch -p1 -s < tmp/patch-0.98.4

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