#!/bin/sh

#
# usage: mkdef dll
#
# build dll.c file from dll.d spec file
#

base=$1

def2=${base}.c

exec >$def2

echo 
echo "#include \"if32.h\""
echo "#include \"${base}.h\""
echo

def3=${base}.h

exec >$def3
echo 
echo "#include \"bin32.h\""
echo
echo "extern MAPTABLE ModuleMapper_${base}[];"
echo

while read type args function index ext
do
	#
	# append this new entry to .def file
	#
	if [ "$type" = "stdcall" -o "$type" = "cdecl" ]
	then

		#
		# append to .c file...
		exec >>$def2
			
		if [ "$type" = "stdcall" ]
		then

		echo "void"
		echo "IT32_$function()"
		echo "{"
		echo "    if32_stdcall_$args(ModuleMapper_${base}[$index].maddr);"
		echo "}"
		echo 
		fi

		exec >>$def3
		echo "void $function$ext();"
		continue;
	fi
	
done <${base}.d

