#!/bin/sh

{
	echo "/* WARNING: THIS FILE IS AUTOGENERATED. DO NOT EDIT! */"
	echo "#ifndef DISPATCH_AUTOGEN_H"
	echo "#define  DISPATCH_AUTOGEN_H"
	echo
	echo "/* Definition of the DEF_TABLE macro which allows easy creation of dispatch table */"
	echo "#define DEF_TABLE(suffix) DispatchTable suffix##Dispatch = { \\"
	grep '^[[:space:]]*FPTR' dispatch.h | sed 's/^[[:space:]]*FPTR[[:space:]][[:space:]]*\([^(]*\)(\*\([^)]*\)DT)\(([^)]*)\).*/	\2##suffix, \\/' | sed '$s/,//'
	echo "};"

	echo
	echo "/* Definitions to allow acces without prepending dispatch-> to all calls. */"
	grep '^[[:space:]]*FPTR' dispatch.h | sed 's/^[[:space:]]*FPTR[[:space:]][[:space:]]*\([^(]*\)(\*\([^)]*\)DT)\(([^)]*)\).*/#define \2 (dispatch->\2DT)/'

	echo
	echo "/* Definitions of all external functions. */"
	grep '^[[:space:]]*FPTR' dispatch.h | sed 's/^[[:space:]]*FPTR[[:space:]][[:space:]]*\([^(]*\)(\*\([^)]*\)DT)\(([^)]*)\).*/\1 \2SC\3;/'
	grep '^[[:space:]]*FPTR' dispatch.h | sed 's/^[[:space:]]*FPTR[[:space:]][[:space:]]*\([^(]*\)(\*\([^)]*\)DT)\(([^)]*)\).*/\1 \2UTF8\3;/'
	echo "#endif"
} > dispatch_autogen.h
