#!/bin/sh
#set -e
LC_ALL=C
export LC_ALL
echo
echo Generating suffix tables.
for file in suffix suffix_x; do
	echo -n $file" "
	if [ $file = suffix ]; then
		filter="grep -v !"
	else
		filter="sed -n s/^[!]//p"
	fi
	(
	echo '/* Automatically generated by gen-suffix */'
	echo
	echo "static_const const_char_ptr domain_$file[] = {"
	cat public_suffix_list.dat | sed 's/[ 	][ 	]*$//' | grep -v '\/\/' | grep -v '^$' | $filter | grep '^[0-9a-z\*\.-]*$' | sort | sed 's/^\(.*\)$/	"\1",/'
	echo "};"
	) >../$file.inc
	if grep -q '[^"/ ]\*' ../$file.inc; then
		echo
		echo Wildcard can be only on the beginning. Fix the code.
		exit 1
	fi
done
echo
echo Done.
echo
