#!/opt/gnu/bin/gawk -f -
BEGIN\
{
	start = 0
	opening_braces = 0
	closing_braces = 0
	new_section = 0
}
/class[ 	]*AmberFF/\
{
	start = 1
	new_section = 0
}
/@name/\
{
	match($0, /@name/)
	if (RSTART > 0)
	{
		section = substr($0,RSTART + RLENGTH)
		gsub(/^[ 	]*/, "", section)
		gsub(/[ 	]*\*\/[ 	]*$/, "", section)
		new_section = 1
	}
}
/public:/\
{
	if (start == 1)
	{
		start = 2
	}
}
/protected:/\
{
	if (start == 2)
	{
		start = 1
	}
}
/private:/\
{
	if (start == 2)
	{
		start = 1
	}
}

{
	if (start > 0)
	{
		line = $0
		for (i = 0 ; i < length($0); i++)
		{
			if (substr(line, i, 1) == "{")
			{
				opening_braces++;
			}
			if (substr(line, i,1) == "{")
			{
				closing_braces++;
			}
		}
		if ((closing_braces == opening_braces) && (opening_braces > 0))
		{
			start = 0
		}
	}
	if (start == 2)
	{
		if ((t = index($0, "//")) != 0) {
			$0 = substr($0, 1, t-1)
		}
		if ((t = index($0, "/*")) != 0) {
				 # value will be "" if t is 1
				 tmp = substr($0, 1, t - 1)
				 u = index(substr($0, t + 2), "*/")
				 while (u == 0) {
							if (getline <= 0) {
									 m = "unexpected EOF or error"
									 m = (m ": " ERRNO)
									 print m > "/dev/stderr"
									 exit
							}
							t = -1
							u = index($0, "*/")
				 }
				 # substr expression will be "" if */
				 # occurred at end of line
				 $0 = tmp substr($0, t + u + 3)
		}
		if (new_section == 1)
		{
			print ""
			print "// SECTION: " section
			new_section = 0
		}
		if (!($0 ~ /^[ 	]*$/) && !($0 ~/public:/))
		{
			gsub(/^[ 	]*/, "  ")
			print $0
		}
	}
}
