#!/bin/sh
test -n "${DEBUG}" && set -x

if [ $# -ne 1 ] ; then
  echo "usage: $0 filepath" >&2
  exit 1
fi

if [ -d "$1" ] ; then
  # process the entire directory (files *.tt and *.inc)
  exec find "$1" -type f -a \( -name '*.tt' -o -name '*.inc' \) -exec "$0" "{}" \;

elif [ -f "$1" ] ; then
  # process one file
  DIR="`dirname "$0"`"
  MSG="`"${DIR}/directive-template" < "$1"`"

  # if output (error or found directive in tag), display them (with filename)
  if [ -n "${MSG}" ] ; then
    echo "$1: ${MSG}"
  fi

else
  echo "error: '$1': not a directory or a regular file" >&2
  exit 2
fi

