#!/bin/sh

# This script generates a configuration that will ignore the aspects of
# GObject-based programs that ought to be ignored. This is ugly, but it has
# worked so far. What would be better would be to actually parse the C code
# rather than to rely on awk and sed.

for i in $(grep -l G_DEFINE_INTERFACE $*); do
	# awk prints all of the lines including and after G_DEFINE_INTERFACE...
	# sed grabs the text of the second argument.
	j=$(cat $i | awk '/^G_DEFINE_INTERFACE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^,]*, \([^,]*\),.*/\1/g')
	echo -n ${j}_default_init\;
	echo -n ${j}_get_type\;
done

for i in $(grep -l G_DEFINE_TYPE $*); do
	j=$(cat $i | awk '/^G_DEFINE_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^,]*, \([^,]*\),.*/\1/g')
	echo -n ${j}_class_init\;
	echo -n ${j}_class_intern_init\;
	echo -n ${j}_get_instance_private\;
	echo -n ${j}_get_type\;
	echo -n ${j}_get_type_once\;
	echo -n ${j}_init\;
	echo -n ${j}_parent_class\;
done

for i in $(grep -l G_DEFINE_TYPE $*); do \
	j=$(cat $i | awk '/^G_DEFINE_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^(]*(\([^,]*\),.*/\1/g')
	echo -n ${j}_private_offset\;
done

for i in $(grep -l G_DEFINE_DYNAMIC_TYPE $*); do \
	j=$(cat $i | awk '/^G_DEFINE_DYNAMIC_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^,]*, \([^,]*\),.*/\1/g')
	echo -n ${j}_class_init\;
	echo -n ${j}_class_finalize\;
	echo -n ${j}_init\;
	echo -n ${j}_parent_class\;
	echo -n ${j}_type_id\;
	echo -n ${j}_register_type\;
	echo -n ${j}_class_intern_init\;
	echo -n ${j}_get_instance_private\;
	echo -n ${j}_register_type\;
done

for i in $(grep -l G_DEFINE_DYNAMIC_TYPE $*); do \
	j=$(cat $i | awk '/^G_DEFINE_DYNAMIC_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^(]*(\([^,]*\),.*/\1/g')
	echo -n ${j}_private_offset\;
done

for i in $(grep -l G_DEFINE_DYNAMIC_TYPE_EXTENDED $*); do \
	j=$(cat $i | awk '/^G_DEFINE_DYNAMIC_TYPE_EXTENDED/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^,]*, \([^,]*\),.*/\1/g')
	echo -n ${j}_class_finalize\;
	echo -n ${j}_register_type\;
	echo -n ${j}_init\;
	echo -n ${j}_parent_class\;
	echo -n ${j}_type_id\;
	echo -n ${j}_intern_init\;
	echo -n ${j}_get_instance_private\;
	echo -n ${j}_register_type\;
	echo -n ${j}_class_intern_init\;
done

for i in $(grep -l G_DEFINE_DYNAMIC_TYPE_EXTENDED $*); do \
	j=$(cat $i | awk '/^G_DEFINE_DYNAMIC_TYPE_EXTENDED/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^(]*(\([^,]*\),.*/\1/g')
	echo -n ${j}_private_offset\;
done

for i in $(grep -l G_DEFINE_ABSTRACT_TYPE $*); do \
	j=$(cat $i | awk '/^G_DEFINE_ABSTRACT_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^,]*, \([^,]*\),.*/\1/g')
	echo -n ${j}_init\;
	echo -n ${j}_class_init\;
	echo -n ${j}_get_type_once\;
	echo -n ${j}_parent_class\;
	echo -n ${j}_get_instance_private\;
	echo -n ${j}_class_intern_init\;
done

for i in $(grep -l G_DEFINE_ABSTRACT_TYPE $*); do \
	j=$(cat $i | awk '/^G_DEFINE_ABSTRACT_TYPE/ { x = 1 } { if (x == 1) printf("%s ", $0) }' | sed 's/[^(]*(\([^,]*\),.*/\1/g')
	echo -n ${j}_private_offset\;
done
