#!/bin/csh
#
# Script that will generate Cray2 C stubs that interface to Fortran
# from regular C stubs
#
# Syntax:  makefstubs	<oldstubs> <newstubs>
#
test -s f.ex || rm f.ex
test -s F.ex || rm F.ex
switch($1)
case "cray2":
case "CRAY2":
case "ymp":
case "YMP":
    awk '{if (index($1,"#") == 0) print $2 }' $2 > f.ex
    foreach i (`cat f.ex`)
	echo -n  "/$i/s/$i/"  >> F.ex
	echo $i | \
	sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'| \
	sed -e 's/$/%%%%%%/' |  \
	sed -e 's/\(......\).*/\1\//' | \
	sed -e 's/%//g'  >> F.ex 
    end
    breaksw
case "alliant":
case "ALLIANT":
case "convex":
case "CONVEX":
    awk '{if (index($1,"#") == 0) print $2 }' $2 > f.ex
    foreach i (`cat f.ex`)
	echo -n  "/$i/s/$i/"  >> F.ex
	echo $i | \
	sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'| \
	sed -e 's/$/%%%%%%/' |  \
	sed -e 's/\(......\).*/\1/' | \
	sed -e 's/%//g'  | \
	sed -e 's/^\(.*\)$/\1_\//' >> F.ex 
    end
    breaksw
default:
    breaksw
endsw
echo '1,$s/\([ 	]\)s\([	 $]\)/\\1\*s\\2/g' >> F.ex
echo '1,$s/\([ 	]\)s$/\\1\*s/' >> F.ex
echo 'g/\[\(arg[0-9]\)\(\*arg[0-9].*\)\]/s//\[\*\\1\*\\2\]/g' >> F.ex
echo 'g/\[\([0-9]\)\(\*arg.*\)\]/s//\[\\1\*\\2\]/g' >> F.ex
echo 'g/\[\(arg[0-9]\)\]/s//\[\*\\1\]/g' >> F.ex
echo "w! tmp" >> F.ex
ex $2 < F.ex > /dev/null
cat tmp
