#!/bin/sh
# This file is copyright (c) 2004,2005,2006 by Panu Kalliokoski
# and released under the license in ../LICENSE

BASE=.
usage() {
	cat $BASE/messages/extract_usage_from_stx.usage 1>&2
	exit $1
}

case "$1" in
	--help|-\?) usage 0 ;;
	--version|-V)
		cat $BASE/messages/version.msg
		exit 0
		;;
esac

sed -n \
  -e '/^! *SYNOPSIS/,/^!/{' \
  -e '/^$/,/./{' \
  -e 's#^[^ 	!]#Usage: &#' \
  -e '}' \
  -e '/^!/!p' \
  -e '}' \
  -e '/^! *OPTIONS/,/^!/{' \
  -e 's#^! *OPTIONS.*#Options:#p' \
  -e '/^!/d' \
  -e '/^[^ 	].*::$/,/\./{' \
  -e 's#\.  .*#.#' \
  -e 'p' \
  -e '}' \
  -e '}' $@ || usage 1

