#!/bin/sh
#####
# NAME
#	texi2html-wrapper.sh
# USAGE
#	texi2html-wrapper texi-file1 texi-file2 ...
# COPYRIGHT
#  Copyright (C) 2000,2001 Steel Wheels Project.
#  This file is a apart of the papaya utilities. 
#  If you need the information of copyright of this file, see COPYING
#  file distributed with file or see http://www.asahi-net.or.jp/~em7t-hmd
#  web page.

this="texi2html-wrapper" ;

texi2html_command=/usr/pkg/bin/texi2html
# makeinfo is not used since we always have texi2html.
makeinfo_command=

html_sed1='s!<BODY>!<BODY BGCOLOR=white TEXT=black LINK=blue VLINK=green>!' ;
html_sed2='s!<BODY>!<BODY BGCOLOR=white TEXT=black LINK=blue VLINK=green>!' ;
html_filter="-e '$html_sed1' -e '$html_sed2'" ;

error(){
	echo "$this [ERROR] $1" 1>&2 ;
	exit 1 ;
}

if [ ! -d ./html ] ; then
	error "This script makes html files into \"html\" subdirectory." ;
fi

if [ ! -z $texi2html_command  ] && [ -x $texi2html_command ] ; then
	COMMAND="$texi2html_command -menu -split_chapter --output=./" ;
elif [ ! -z $makeinfo_command ] && [ -x $makeinfo_command ] ; then
	COMMAND="$makeinfo_command --html" ;
else
	error "this script requires texi2html or makeinfo" ;
fi

for TEXI in $* ; do
	$COMMAND $TEXI ;
	for HTML in *.html ; do
		# sed -e $html_sed $HTML > ./html/$HTML ;
		sed -e 's!<BODY>!<BODY BGCOLOR=white TEXT=black LINK=blue VLINK=green>!' \
		    -e 's!<body>!<body BGCOLOR=white TEXT=black LINK=blue VLINK=green>!' \
		    $html_sed $HTML > ./html/$HTML ;
	done
	rm -f *.html ;
done

exit 0 ;

