#!/bin/sh

if ! [ -f ai/regression/regression.nut ]; then
	echo "Make sure you are in the root of OpenTTD before starting this script."
	exit 1
fi

cat ai/regression/regression.nut | awk '
/^function/ {
	for (local in locals) {
		delete locals[local]
	}
	if (match($0, "function Regression::Start") || match($0, "function Regression::Stop")) next
	locals["this"] = "AIControllerSquirrel"
}

/local/ {
	gsub(".*local", "local")
	if (match($4, "^AI")) {
		sub("\\(.*", "", $4)
		locals[$2] = $4
	}
}

/\./ {
	for (local in locals) {
		if (match($0, local ".")) {
			fname = substr($0, index($0, local "."))
			sub("\\(.*", "", fname)
			sub("\\.", "::", fname)
			sub(local, locals[local], fname)
			print fname
		}
	}
}
' | sort | uniq > tmp.in_regression

grep 'DefSQ.*Method' ../src/ai/api/*.hpp | grep -v '::GetClassName' | sed 's/^[^,]*, &//g;s/,[^,]*//g' | sort > tmp.in_api

diff -u tmp.in_regression tmp.in_api | grep -v '^+++' | grep '^+' | sed 's/^+//'

rm -f tmp.in_regression tmp.in_api

