#! /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.99.13.$i
done

rm -rf src/arch/NetBSD src/arch/linux/threads
rm -f src/include/lt-threads.h src/include/netbsd_*

add_last_linefeed src/commands/precompiled/autoexec.bat
patch -p1 -s < tmp/patch-0.99.13.3
delete_last_linefeed src/commands/precompiled/autoexec.bat

(cd src/doc/README; rm -f vm86plus video ibmset loglevel)
rm -f doc/Known-Bugs man/xtermdos.1
patch -p1 -s < tmp/patch-0.99.14

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