#!/bin/sh
# NAME
#	man2html-wrapper - wrapper command for man2html
# VERSION
#	$Id$
# CHANGELOG
#	$Log$
# USAGE:
#	man2html-wrapper input-file output-file
# NOTE:
#	There are 2 different implementations for command "man2html"
#	This script distinguish them.

this="man2html-wrapper"
man2html=""
groff="/usr/bin/groff"

error(){
	echo "$this [ERROR] $*" >&2 ;
	echo "usage: man2html-wrapper input-file output-file" ;
	exit 1 ;
}

# check the arguments
input=$1 ; output=$2 ;
if [ -z $input ] ; then
	error "input file name is not given" 
fi
if [ ! -f $input ] ; then
	error "input file \"$input\" is not found" 
fi
if [ -z $output ] ; then
	error "output file name is not given" 
fi

# execute man2html command
if [ -z $man2html ] ; then
	error "command 'man2html' is not found."
fi
if [ -z $groff ] ; then
	error "command 'groff' is not found."
fi
if $man2html -help | grep "Earl Hood" > /dev/null ; then
	echo "$this: this is Earl Hood's man2html" >&2 ;
	cat $input | $groff -Tascii -mandoc | $man2html > $output 
else
	echo "$this: this is NOT Earl Hood's man2html" >&2 ;
	$man2html $input > $output
fi

exit 0 ;

