#!/bin/sh
processline()
{
	echo "- $1 -"
	name="$1"
	anchors="<object type=\"application/x-oleobject\" classid=\"clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e\"><param name=\"ALink Name\" value=\"$1\"></object>" 
	title=""
	stylesheet="xaoshelp.css"
	shift
	while [ "$1" != "" ] ; do
	  if [ "$1" != "$name" ] ; then
	    anchors="$anchors <object type=\"application/x-oleobject\" classid=\"clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e\"><param name=\"ALink Name\" value=\"\$name\"></object>" 
	  fi
	  shift
	done
	# I changed "0" to "$" because my sed
	# doesn't want to understand "0".
	# -- Zoltan
	cat xaos.hlp | sed '/%'"$name"'/H' | sed '1,/%'"$name"'/d;/^%/,$ d' | sed \
'1,3s_<head>\([^<]*\)</head>_\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\
<HTML>\
<HEAD>\
  <TITLE>\1</TITLE>\
  '"$title"'\
  <LINK HREF="'"$stylesheet"'" REL="stylesheet" TYPE="text/css">\
</HEAD>\
<BODY>\
'"$anchors"'\
<H1>\1</H1>\
_g
s_<head>_<H2>_g
s_</head>_</H2>_g
s_<center>__g
s_</center>__g
s_<emph>_<STRONG>_g
s_<submenu>__g
s_<menuhead>__g
s_</menuhead>__g
s_<mainmenu>__g
s_<main>__g
s_<math>__g
s_<menuitems>__g
s_<notex>__g
s_</notex>__g
s_<node.*>__g
s_</emph>_</STRONG>_g
s_<tt>_<CODE>_g
s_</tt>_</CODE>_g
s_<tutor \([^>]*\)>_<strong>_g
s_</tutor>_</strong>_g
s_<a \([^>]*\)>_<A HREF="\1.html">_g
s/'\'\''/"/g
s/``/"/g' > $name.html
	echo "</BODY></HTML>" >> $name.html
	tidy -qm $name.html
	case $name in
		main)	mv $name.html xaoshelp/index.html;;
		*)	mv $name.html xaoshelp;;
	esac
}
process()
{
	while read line ; do
		eval "processline $line"
	done
}
rm -rf xaoshelp
mkdir -p xaoshelp
cp xaoshelp.css xaoshelp
grep "^%" xaos.hlp | sed '/%%/d;s/%//g' | process
