#!/bin/sh
# runs morbig on all debian maintainer scripts found under directory $1,
# producing for each of them a concrete syntax tree in bin format.

corpusroot=${1:?}

if [ ! -x /usr/bin/time ]; then
  echo 'Please install /usr/bin/time (apt-get install time).'
  exit 2
fi

cd ${corpusroot}

echo -n "Cleaning up ... "
find . -regextype posix-extended \
	 -regex '.*/.*\.(json|morbig|sjson|morbigerror)'\
	 -delete
echo "done."

echo "Start parsing `find . -regextype posix-extended -regex '.*/(pre|post)(inst|rm)' | wc -l` files."

find . -regextype posix-extended -regex '.*/(pre|post)(inst|rm)' | \
	/usr/bin/time -f "%E real, %U user, %S sys" \
	morbig \
	  --as bin \
	  --continue-after-error \
	  --from-stdin \
	  --skip-nosh \
	  --display-stats
