#!/bin/bash

rm -f register_all_functions.cpp

cat <<EOF >> register_all_functions.cpp
/* AUTO GENERATED FILE.  DO NOT EDIT */

/* Should be updated by update_register_all_functions script when new functions are added */

#include "libfunction_precompiled.h"

#include "register_all_functions.h"

#include "function_boilerplate.h"
EOF

HEADERS=`grep -l FUNCTION_BEGIN *.h | sed 's/function_boilerplate.h//'`

for f in $HEADERS ; do
    sed -f stripcomments.sed "$f" \
	| grep FUNCTION_BEGIN \
	| sed 's/FUNCTION_BEGIN(//' \
	| sed 's/,.*//' \
	| awk '{printf("REGISTER_DCL(%s);\n",$0);}' \
	>> register_all_functions.cpp
done

cat <<EOF >> register_all_functions.cpp

void register_all_functions(FunctionRegistry& r)
{
EOF

for f in $HEADERS ; do
    sed -f stripcomments.sed "$f" \
	| grep FUNCTION_BEGIN \
	| sed 's/FUNCTION_BEGIN(//' \
	| sed 's/,.*//' \
	| awk '{printf("  register_%s(r);\n",$0);}' \
	>> register_all_functions.cpp
done

cat <<EOF >> register_all_functions.cpp
}
EOF
