#!/bin/sh

REGEXP="( Linux version )|(^CMDLINE)|(^FSTEST)|(^MNTOPTS)|(^CPUS:)|(^MEM:)|(^BEGIN)|(^MOUNT_OPTIONS)|(^MKFS_OPTIONS)|(^END)|(^EXT4-fs error)|(WARNING)|(^Ran: )|(^Failures: )|(^Passed)|(inconsistent)|(^Shutdown reason)"

case "$1" in
    --summary|-s)
	# this is the default
	shift
	;;
    --failures|-F)
REGEXP="(^CMDLINE)|(^FSTEST)|(^MNTOPTS)|(^CPUS:)|(^MEM:)|(^BEGIN)|(^Failures: )|(^Passed)|(^Shutdown reason)"
	do_failure="yes"
	shift
	;;
esac

IN="$*"

if test -z "$IN"
then
    IN=-
fi

grep -E "$REGEXP" "$IN"
if test -n "$do_failure"; then
    b=$(grep -E ^BEGIN "$IN" | wc -l)
    e=$(grep -E ^END "$IN" | wc -l)
    if test "$b" -gt "$e" ; then
	l=$(grep -E ^BEGIN "$IN" | tail -n 1 | sed -e 's/BEGIN //')
	echo " "
	echo Missing END "$l"
    fi
fi
