#! /bin/sh
# Copied from apply/kernel-feat-i2c
# Called with:
#   $1 = %patches
#   $2 = %name of patch package
#   $3 = %kversion

name="kernel-feat-swsusp"
version="2003.10.16"

exit_handler()
{
	local rc=$?
	trap - EXIT
	exit $rc
}
trap exit_handler EXIT HUP INT QUIT PIPE TERM

function apply_recursive()
{
    for i in `ls -1 $1` ; do
	if [ ! -s "$1/$i" ] ; then continue ; fi
	if [ -f "$1/dont_apply_to_${3}_$i" ] ; then
	    echo "Denied for the kernel version $3 ..."
	    continue
	fi
	if [ -d "$1/$i" ] ; then
	    if [ -f patches/APPLIED_`echo $i | sed -e 's/^.._\\(.*\\)/\\1/'` ] ; then
		apply_recursive "$1/$i/is" "$2" "$3" || return 1
	    else
		apply_recursive "$1/$i/is_not" "$2" "$3" || return 1
	    fi
	    continue
	fi
	echo "Applying patch $i ..."
	patch -p1 -b < "$1/$i" || return 1
    done
}

apply_recursive "$1/$2" "$1" "$3"
