#!/bin/sh
#
# duplicate_oids
#
# finds oids that are duplicated in the system tables.
#

# no multibytes files
FILES=`ls pg_*.h |grep -v '_mb.h'`

#
# The previous version did not use the -d option on uniq
# so check here that it is supported.
# Otherwise, use the old algorithm
#

if [ `uniq -d < /dev/null > /dev/null 2>&1` ]; then
  echo "uniq -d is not supported on your platform."
  echo "Please report this to pgsql-hackers@postgresql.org"

egrep '^DATA' $FILES | \
	sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
	sort -n >/tmp/alloids.$$
uniq /tmp/alloids.$$ >/tmp/uniqoids.$$

diff -u /tmp/alloids.$$ /tmp/uniqoids.$$ | \
	grep -v '/tmp/' | \
	grep '^-' | \
	sed -e 's/^-//' | \
	grep -v '^0$' | \
	uniq
rm /tmp/alloids.$$
rm /tmp/uniqoids.$$

else

#  echo "uniq -d is supported on this platform."
#  echo "Will omit the use of temporary files."

egrep '^DATA' $FILES | \
	sed -e 's/^.*OID[^=]*=[^0-9]*//' -e 's/[^0-9].*$//' | \
	sort -n | uniq -d | \
	egrep -v '^[0]*$'

fi

exit
