#!/bin/sh

DOMAINS=$(find -L . '(' -name '*.c' -o -name '*.cc' ')' -exec grep UL_LOG_CUST '{}' ';' | \
  sed -n -e 's/^.*UL_LOG_CUST(\([^)]*\)).*$/\1/p' | sort -u )

#echo $DOMAINS

#echo -e "#define UL_LOGL_DEF UL_LOGL_DEB\n"

echo -e "/*"
echo -e " * This is generated file, do not edit it directly."
echo -e " * Take it from standard output of \"ul_log_domains\""
echo -e " * script called in the top level project directory"
echo -e " */\n"

for i in $DOMAINS ; do
  echo -e "ul_log_domain_t $i\t= {UL_LOGL_DEF, \"$(echo -n $i | sed -n -e 's/ulogd_\(.*\)/\1/pg' )\"};"
done

echo -e "\nul_log_domain_t *ul_log_domains_array[] = {"

for i in $DOMAINS ; do
  echo -e "  &$i,"
done

echo "};"
