#!/bin/sh

#
# mkbin xxx
#
# build xxxBin.c, and xxxBin.h
#

n=0
base=$1

def1=${base}.d
def2=${base}Bin.c
def3=${base}Bin.h

exec >$def2
echo
echo "#include \"bin32.h\""
echo "#include \"$def3\""
echo
echo "unsigned long Win32Trap();"
echo
echo "MAPTABLE ModuleMapper_${base}[] = {"
echo

exec >$def3
echo 

#stdcall 1 DestroyIcon 137 32
#cdecl   0 wsprintfA   613
#stdcall 4 WinHelpA  607  

grep -v "^stub" $def1 |while read spec args api index ext
do 	
	if [ "$spec" = "cdecl" ]
	then prefix=
	else prefix=IT32_
	fi
	echo $index $prefix$api $api$ext $api
done | sort -n >$base.api

while read arg ifapi api apiname
do
	exec >>$def2
	while [ "$n" != "$arg" ]
	do	
		echo "   { /* $n */ Win32Trap, 0, \"\" }," 
		n=`expr $n + 1`
	done

	echo "   { /* $n */  $ifapi, $api, \"$apiname\"},"
	
	exec >>$def3
	if [ "$ifapi" != "$api" ]
	then
		echo "unsigned long $ifapi();"
	fi
	echo "unsigned long $api();"

	n=`expr $n + 1`
done  <$base.api

exec >>$def2
echo "   { /* $n */ 0,0} "
echo "};"
