# ifnest.awk, 18 Apr 03
#
# Count #if/#ifdef/#ifndef nesting levels
#

BEGIN {
	nesting=0
	max_nesting=0
	}

$1 == "#IF" ||
$1 == "#IFDEF" ||
$1 == "#IFNDEF" {
	going_up=1
	nesting++
	if (nesting > max_nesting)
	   max_nesting=nesting
	next
	}

$1 == "#ELIF" ||
$1 == "#ELSE" {
	next
	}

$1 == "#ENDIF" {
	if (going_up == 1)
	   max_level[nesting]++
	nesting--
	going_up=0
	next
	}

$1 == "__E__O__F__"  {
	nesting=0
	going_up=0
	next
	}

	{
	next
	}

END {
    print "File: ppidnest.d"
    for (i=1; i <= max_nesting; i++)
       print i " " 0+max_level[i]
    print "End File"
    }

