#!/bin/sh
# conform-gnuism [-hnq] file ... -- GNU forms in scripts that run on OpenBSD. One stderr line per
# form, "<file>:<line>: <what>"; stdout: the count. rc 0 clean, 1 forms found, 2 usage.
# -n is accepted for the convention of the family and changes nothing: the tool writes nothing.
PATH=/bin:/sbin:/usr/bin:/usr/sbin
set -u

awkdir=/usr/ports/pobj/conform-0.1/fake-amd64/usr/local/share/conform
case $awkdir in @*) awkdir=$(dirname "$0") ;; esac

usage() { echo "usage: conform-gnuism [-hnq] file ..." >&2; }
quiet=0
while getopts hnq o; do
	case $o in
	h) usage; exit 0 ;;
	n) ;;
	q) quiet=1 ;;
	*) usage; exit 2 ;;
	esac
done
shift $((OPTIND - 1))
[ $# -ge 1 ] || { usage; exit 2; }

out=$(awk -f "$awkdir/conform-gnuism.awk" "$@" < /dev/null 2>&1)
rc=$?
n=0
if [ -n "$out" ]; then
	echo "$out" >&2
	n=$(echo "$out" | wc -l | tr -d ' ')
fi
[ "$quiet" -eq 1 ] || echo "conform-gnuism: $n forms"
exit "$rc"
