#! /usr/bin/env bash
#+
# NAME:
#	hash_documentation
# PURPOSE:
#	Prints software headers to standard output
# CATEGORY:
#	general/bash
# CALLING SEQUENCE:
#	hash_documentation <program>
# INPUTS:
#	<program>	fully-qualified path to script
# OUTPUTS:
#	Prints to stdout
# PROCEDURE:
#	Prints every line between the first "#+" line and
#	the first "#-" line.
#	The first character of each line is stripped off
#	(should be a hash)
# MODIFICATION HISTORY:
#	JUN-2011, Paul Hick (UCSD/CAIDA; pphick@caida.org)
#-

program="$1"
if [ ! -f "$program" ]; then
	program=`which $program`
	if [ -z "$program" ]; then
		echo "script not found in PATH, $1"
		exit 0
	fi
fi

hash_plus_found=0
count_docs=0
set -f

cat $program |
while read line; do
	if [ $hash_plus_found -eq 0 ]; then
		if [ "${line:0:2}" = "#+" ]; then
			if [ $count_docs -ne 0 ]; then
				echo
				echo
				echo
			fi
			#echo "$line"
			hash_plus_found=1
			((count_docs++))
		fi
	else
		if [ "${line:0:2}" = "#-" ]; then
			hash_plus_found=0
		else
			echo "${line:1}"
		fi
	fi 
done

exit 0
