Blob Blame History Raw
#!/bin/csh
# Motif
#
# Copyright (c) 1987-2012, The Open Group. All rights reserved.
#
# These libraries and programs are free software; you can
# redistribute them and/or modify them under the terms of the GNU
# Lesser General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# These libraries and programs are distributed in the hope that
# they will be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with these librararies and programs; if not, write
# to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301 USA
# 
# HISTORY
#

if ($#argv < 1) then  
Help:
	echo "usage: "$0" -DMOTIF1_1 ... -DMotif1_n <TestName>.dat ||"
	echo "usage: "$0" -DMOTIF1_1 ... -DMotif1_n <TestName>.scr"
	exit 1
endif

if ("$argv[1]" == "-help") then
	goto Help
endif

set extension = $argv[$#argv]:e

if ("$extension" == "dat") then
	set output_extension = ".Dat"
else
	if ("$extension" == "scr") then
		set output_extension = ".Scr"
	else
		echo "usage: "$0" -DMOTIF1_1 ... -DMotif1_n <TestName>.dat ||"
		echo "usage: "$0" -DMOTIF1_1 ... -DMotif1_n <TestName>.scr"
		exit 1
	endif
endif

set tmp_script = /tmp/$$.sed
set tmp_file = /tmp/$$.pp1
set tmp_file2 = /tmp/$$.pp2
set root = $argv[$#argv]:r

touch $tmp_script
chmod 777 $tmp_script

if (-e $root$output_extension) then
	rm $root$output_extension
endif

# create sed file to delete ifdef's and endif's corresponding to 
# the defines passed in from DEFINES.

foreach define ($argv[*])
	if ("$define" == "-DMOTIF1_1") then
		echo "/^#ifdef[	 ]*MOTIF1_1/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_1/d" >> $tmp_script
	endif
	if ("$define" == "-DMOTIF1_2") then
		echo "/^#ifdef[	 ]*MOTIF1_2/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_2/d" >> $tmp_script
	endif
	if ("$define" == "-DMOTIF1_3") then
		echo "/^#ifdef[	 ]*MOTIF1_3/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_3/d" >> $tmp_script
		echo "/^#ifdef[	 ]*MOTIF1_2/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_2/d" >> $tmp_script
	endif
	if ("$define" == "-DMOTIF1_4") then
		echo "/^#ifdef[	 ]*MOTIF1_4/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_4/d" >> $tmp_script
		echo "/^#ifdef[	 ]*MOTIF1_3/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_3/d" >> $tmp_script
		echo "/^#ifdef[	 ]*MOTIF1_2/d" >> $tmp_script
		echo "/^#endif[	 ]*MOTIF1_2/d" >> $tmp_script
	endif
end


if (-z $tmp_script) then
        cat $argv[$#argv] > $tmp_file
else
        sed -f $tmp_script $argv[$#argv] > $tmp_file
endif

# remove remaining #ifdef and #endif lines.

sed "/^#ifdef[	 ]*.*/,/^#endif[	 ]*.*/d" $tmp_file > $tmp_file2

# remove C Style comment lines from pp file.

sed -e "/\/\*.*\*\//d" \
    -e "/\/\*/,/\*\//d" $tmp_file2 > $root$output_extension

# clean up all temporary files.

rm -f $tmp_script $tmp_file $tmp_file2