#!/bin/bash
#
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: scripts/Create-DescPatch
# Copyright (C) 2006 - 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if [ "$1" = "-repository" ] ; then
	shift ; for y ; do
		for x in package/$y/[a-z0-9]* ; do $0 ${x##*/} ; done
	done
	exit 0
fi

if [ "$1" != "${1#-}" -o $# -eq 0 ] ; then
	echo "Usage: $0 <package-names>"
	echo "or     $0 -repository <repository-names>"
	exit 1
fi

for package ; do
	lastpdir=
	for pdir in package/*/$package ; do
		[ "$lastpdir" ] && echo "$package: Found dup: $pdir $lastpdir"
		lastpdir="$pdir"
	done

	if [ -f $pdir/$package.desc ] ; then
		tempfn=`mktemp`
		{ echo ; nl=0
		while read line ; do
			if [ "$line" = "--" -a "$nl" = 0 ] ; then
				echo ; nl=1
			fi
			if [ "${line#\[}" != "$line" ] ; then
			    for x in $line ; do
				x="`echo $x | tr -d '[]'`"
				grep "^\[$x\]" $pdir/$package.desc && nl=0
			    done
			fi
		done < etc/desc_format
		if [ "$nl" = 0 ] ; then echo ; fi
		grep "^\[X" $pdir/$package.desc && echo
		} > $tempfn
		diff -u ./$pdir/$package.desc $tempfn
		rm -f $tempfn
	fi
done