#!/bin/sh
#
# $NetBSD: pkgdiff,v 1.4 2000/08/26 04:40:28 hubertf Exp $
#
# Usage: pkgdiff newfile
#        pkgdiff oldfile newfile
#
# Will output a patch ready for the NetBSD Pkgs Collection (unified
# diff, plus no RCS IDs if possible). If only newfile is given,
# oldfile is assumed as newfile.orig.
#
# Copyright (c) 2000 by Hubert Feyrer <hubertf@netbsd.org>
# All Rights Reserved.  Absolutely no warranty.  
#

if [ $# -le 1 ]
then
	if [ -f "$1.orig" ]; then 
		old="$1.orig"
		new="$1"
	else
		echo $0: need at least one arguments >&2
		exit 1;
	fi
else
	old="$1"
	new="$2"
fi

lines=3
while [ `diff -u -$lines "$old" "$new" | egrep -c '\\$(NetBSD|Author|Date|Header|Id|Locker|Log|Name|RCSfile|Revision|Source|State)'`  !=  0 ]
do
	lines=`expr $lines - 1`
	if [ $lines = 0 ]; then
		echo "Cannot strip away RCS IDs, please handle manually!"
		exit 1
	fi
done

if ! diff -qu -$lines "$old" "$new" > /dev/null
then
    echo '$'NetBSD'$'
    echo ''
    # Strip out the date on the +++ line to reduce needless
    # differences in regenerated patches
    diff -u -$lines "$old" "$new" | sed -e 's:^\(+++ [^	]*\)	.*:\1:'
fi
