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

patch -p1 -s < tmp/patch-1.0.1.1

mv src/include/linux src/include/Linux
patch -p1 -s < tmp/patch-1.0.1.2
rm -f src/include/Linux/vm86.h

patch -p1 -s < tmp/patch-1.0.1.3
rm -f etc/config.dist
patch -p1 -s < tmp/patch-1.0.1.4

rm -rf dexe
rm -f etc/{config.test,hddummy}
rm -f setup-bootdir setup-hdimage
rm -f src/doc/README/dexe
rm -f src/tools/mkbindist
rm -f src/tools/Mkbindist
rm -f first-test
rm -f src/tools/QuickStart.bindist
rm -f src/doc/README/oldboot
rm -f dosemu.spec
rm -rf contrib/dosC
rm -f src/commands/precompiled/*.{com,exe,sys,doc}

for i in 5 6 ; do
  patch -p1 -s < tmp/patch-1.0.1.$i
done

rm -f src/plugin/commands/*.bat
patch -p1 -s < tmp/patch-1.0.1.7

(cd man; mv dos.1 dosemu.bin.1)
patch -p1 -s < tmp/patch-1.0.1.8

#patch -p1 -s < tmp/patch-1.0.2

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