#! /bin/sh

# Find a good awk.
if test -z "$AWK" ; then
  for AWK in gawk nawk awk ; do
    if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
      :
    else
      break
    fi
  done
fi

$AWK '
BEGIN {
    num = 0;
    num_ok = 0;
    num_wrong = 0;
    doit = 0;
    name = "";
    lines = "";
}
/^GPC-TEST-BEGIN/ {
    doit = 1;
    next;
}
/^GPC-TEST-END/ {
    doit = 0;
    next;
}
doit == 0 {
    next;
}
/^TEST/ {
    name = $0;
    num++;
    if (NF > 1 && $3 ~ "OK") {
	ok = 1;
	num_ok++;
    }
    else {
	ok = 0;
	num_wrong++;
    }
    if (!ok) {
	printf "%s", lines;
	print name;
    }
    lines = "";
    next;
}
{
    lines = lines $0 "\n"
}
END {
    # printf "%s", lines;
    print "# of gpc tests     " num;
    print "# of gpc passes    " num_ok;
    print "# of gpc failures  " num_wrong;
}
'
