#!/bin/sh

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.


ARGS=""
FILES=""

trap 'rm -f temp.$$; exit 1' 1 2 15

case $# in
0)	echo 'Usage: ptxunif [-n] -Usymbol [files] '
	exit 1
	;;
esac

for i
do
	case $i in
	-n)	LIST=1;;
	-U*)	if [ "$ARGS" ]
		then
			echo "Specify only one symbol"
			exit 1
		else
			ARGS="$i"
		fi
		;;
	-*)	echo "Unknown option(s)"
		exit 1;;
	*)	FILES="$FILES $i";;
	esac
done

if [ ! "$ARGS" ]
then
	echo "A symbol must be specified"
	exit 1
fi

for j in $ARGS
do
	case $j in
	-U*) undefine=`echo $j | sed -e "s/-U//"`
	esac
done

if [ ! "$FILES" ]
then
	FILES=`find . -type f -print | xargs egrep -l "^#if.*$undefine"`
fi

if [  "$LIST" ]
then
	echo $FILES
	exit 0
fi

for j in $FILES
do
	unifdef -U$undefine $j > temp.$$
	mv temp.$$ $j
done
exit 0
