#!/bin/gawk -f

BEGIN {
    forwarders = 0;
}

#C style comments detection
/(^|[[:space:]]+)\/\*([[:space:]]+|$)/ {
    comment = 1;
}

/(^|[[:space:]]+)\*\/([[:space:]]+|$)/ {
    comment = 0;
}

#join forwarders option into one string
/(^|[[:space:]]+)(forwarders|allow-query|allow-recursion)([[:space:]]+|$)/ {
    if (!comment)
    {
	line=$0;
	forwarders=1;
	foundat=FNR;
    }
}

/{/ { 
    if (forwarders && FNR != foundat)
    {
	line = line $0;
	foundat=FNR;
    }
}

/}/ {
    if (forwarders)
    {
	if (FNR != foundat) line = line $0;
	print line;
	forwarders = 0;
	next;
    }
}

#default action
{
    if (forwarders)
    {
	if (FNR != foundat) line = line $0;
	foundat = FNR;
    }
    else
	print $0;
}
