: Use /bin/sh
#
# $Id: Makepatch,v 1.4 91/07/27 20:48:10 geoff Exp $
#
# Copyright 1991, by Geoff Kuenning, Manhattan Beach, CA
# Permission for non-profit use is hereby granted.
# All other rights reserved.
# See "version.h" for a more complete copyright notice.
#
# $Log:	Makepatch,v $
# Revision 1.4  91/07/27  20:48:10  geoff
# Add special code so that dictionary patches are distributed as regular
# diffs, rather than context diffs.
# 
# Revision 1.3  91/07/05  17:05:31  geoff
# Quote still less on destdir;  sh is sure dumb!
# 
# Revision 1.2  91/07/05  17:01:28  geoff
# Fix some overeager quoting
# 
# Revision 1.1  91/06/23  22:20:18  geoff
# Initial revision
# 
#
#	Make an ispell patch kit.  This is not a clever script,
#	just a handy one.
#
#	Usage:
#
#	Makepatch [-d destdir] [new-files]
#
#	destdir is the directory in which the kits and patches are kept.
#
#	new-files are any new files to be added to the distribution.
#
destdir=kits
USAGE="Usage:  Makepatch [-d destdir] [new-files]"

while [ $# -gt 0 ]
do
    case "$1" in
	-d)
	    destdir="$2"
	    shift; shift
	    ;;
	-*)
	    echo "$USAGE" 1>&2
	    exit 1
	    ;;
	*)
	    break
	    ;;
    esac
done

[ -d "$destdir" ]  ||  mkdir "$destdir"

if [ -r "$destdir/Patch1" ]
then
    if [ -r "$destdir/Patch9" ]
    then
	lastpatch=`ls $destdir/Patch?? | tail -1 | sed "s;$destdir/Patch;;"`
    else
	lastpatch=`ls $destdir/Patch? | tail -1 | sed "s;$destdir/Patch;;"`
    fi
else
    lastpatch=0
fi

patchno=`expr $lastpatch + 1`
patchfile="$destdir/Patch$patchno"

echo 'Index: version.h' > "$patchfile"
prereq=`co -rpatch$lastpatch -p RCS/version.h \
  | sed -n -e 's/ (beta).*$//' -e 's/^.*International Ispell Version //p'`
echo "Prereq: $prereq" >> "$patchfile"
echo "" >> "$patchfile"
lastrev=`rlog -h version.h | sed -n 's/head:[	 ]*//p'`
rcs -Npatch$patchno:$lastrev version.h
rcsdiff -rpatch$lastpatch -rpatch$patchno version.h >> "$patchfile"

for i in RCS/*,v
do
    lastrev=`rlog -h $i | sed -n 's/head:[	 ]*//p'`
    rcs -Npatch$patchno:$lastrev $i
    case "$i" in
	RCS/version.h,v)
	    ;;
	*)
	    changes=`rcsdiff -rpatch$lastpatch -rpatch$patchno $i 2>Makepatch \
	      | sed 1q`
	    case "$changes" in
		'')
		    ;;
		*)
		    case "$i" in
			RCS/english.[012],v|RCS/american.[012],v)
			    context=
			    ;;
			RCS/altamer.[012],v|RCS/british.[012],v)
			    context=
			    ;;
			*)
			    context=-c
			    ;;
		    esac
		    echo "" >> "$patchfile"
		    basefile=`expr $i : 'RCS/\(.*\),v'`
		    echo "Index: $basefile" >> "$patchfile"
		    echo "" >> "$patchfile"
		    rcsdiff $context -rpatch$lastpatch -rpatch$patchno $i \
		      >> "$patchfile"
		    ;;
	    esac
    esac
done

#
# Do new files
#
for i
do
    echo "" >> "$patchfile"
    echo "Index: $i" >> "$patchfile"
    echo "" >> "$patchfile"
    diff -c Makepatch $i | sed "s;/dev/null;$i;" >> "$patchfile"
done
