#!/bin/sh
#ident	"@(#)sc:publik/bin/publik	3.5"
###############################################################################
#
# C++ Standard Components, Release 3.0.
#
# Copyright (c) 1991, 1992 AT&T and Unix System Laboratories, Inc.
# Copyright (c) 1988, 1989, 1990 AT&T.  All Rights Reserved.
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and Unix System
# Laboratories, Inc.  The copyright notice above does not evidence
# any actual or intended publication of such source code.
#
###############################################################################

# Set this to your C++ translator.
CC=${CC-CC}

# Set this to where you installed the library files.
PUBLIK2=${PUBLIK2-`dirname $0`/../lib/publik2}

###############################################################
# You shouldn't have to change anything below this line.
###############################################################
pubopts=
badargs=0
set -- `getopt clmpvD:U:I:R $*`
if test $? -ne 0
then
	badargs=1
fi

# parse the options
#
for i in $*
do
	case $i in
	-[clmpv]) pubopts="$pubopts $1"; shift;;
	-I)	CPPOPTS="$CPPOPTS -I$2"; shift; shift;;
	-D)	CPPOPTS="$CPPOPTS -D$2"; shift; shift;;
	-U)	CPPOPTS="$CPPOPTS -U$2"; shift; shift;;
	-R)	CPPOPTS="$CPPOPTS -R"; shift;;
	--)	shift; break;;
	-*)	#echo "publik: illegal option $i (ignored)"; 
		shift;;
	esac
done

if test $badargs -eq 1
then
	echo "usage: publik [-cmp] [cpp options] file ..."
	exit 2
fi
	
# Check to see whether we have the basic tools.
 
if [ ! -x $CC ]
then    if [ -z "`type CC`" ]
	then    echo "publik: Cannot find CC."
		exit 2
	fi
fi
if [ ! -x $PUBLIK2 ]
then    echo "publik: Cannot find publik2 executable."
	exit 2
fi
 
#
# analyze all the input files
#
if test -z "$*" 
then
	$PUBLIK2 $pubopts
else
	for file in $*
	do
		case $file in 
		*.[cCh]|*.cpp|*.CPP|*.cxx|*.CXX|*.cc|*.CC|*.c++|*.C++)	$CC -C -E $CPPOPTS $file | $PUBLIK2 $pubopts;;
		*.i)	$PUBLIK2 $pubopts $file;;
		*) echo "publik: file with unrecognized suffix: $file (ignored)";;
		esac
	done
fi

