#!/bin/sh
# MFOUR="m4 -B 8192"
MFOUR="m4"

(cat << 'END'
undefine(`eval')
undefine(`index')
undefine(`format')
undefine(`include')
undefine(`substr')
undefine(`paste')
define(KEYWORD,`')
define(COMMENT,`')
define(TITLE,`
<HEAD><title>$2</title></HEAD><BODY>
<A NAME=HEADING1></A>
[ <A HREF="../index.html">top</A> | <A HREF="index.html"> up</A> ]
<CENTER><H2><I>$2</I></H2></CENTER>')
define(USAGE,`
<H3><I>Syntax</I></H3>
<PRE>$1</PRE>
')
define(ALIAS,`dnl')
define(BEGIN_ARGUMENTS,`<H3><I>`Arguments'</I></H3>
<TABLE>')
define(END_ARGUMENTS,`</TABLE>')
define(ARGUMENTS,`
<H3><I>`Arguments'</I></H3>
<TABLE>
$1
</TABLE>
')
define(ARG,``<TR VALIGN=TOP><TD><CODE>$1</CODE>
<TD>
$2'')
define(ITEM,`<TR VALIGN=TOP><TD><CODE>$1</CODE>
<TD>
$2>')
define(DESCRIPTION,`<H3><I>`Description'</I></H3>
$1
')
define(NOTE,`<H3><I>`Note'</I></H3>
$1
')
define(VALUE,`<H3><I>`Value'</I></H3>
$1
')
define(SECTION,`<H3><I>$1</I></H3>$2')
define(VALUES,`<H3><I>`Values'</I></H3>
$1
<DL>
$2
</DL>
')
define(REFERENCES,`<H3><I>`References'</I></H3>
$1
')
define(SEEALSO,`<H3><I>See Also</I></H3>
$1
')
define(LINK,`<A HREF = "$1.html">$1</A>')
define(EXAMPLES,`<H3><I>`Examples'</I></H3>
<XMP>$1</XMP>
')

define(CTRL,`^$1')
define(LANG,`<CODE>$1</CODE>')dnl
define(ITALIC,`<I>$1</I>')dnl
define(BOLD,`<B>$1</B>')dnl
define(PARA,`<P>')dnl
define(LDOTS,`...')
define(EQUALS,`=')
define(LT,``&#60;'')
define(GT,``&#62;'')
define(LE,``&#60;='')
define(GE,``&#62;='')
define(OVER,`$1 / $2')
define(SUP,`{$1}^{$2}^')
define(SUB,`{{$1}_{$2}_}')
define(CHOOSE,`{\left(\begin{array}{c} $1 \\ $2 \end{array} \right)}')
define(PAREN,`{\left( $1 \right)}')
define(SP,`')
define(greekAlpha,`&Alpha;')
define(greekGamma,`&Gamma;')
define(greekalpha,`&alpha;')
define(greekpi,`&pi;')
define(greekmu,`&mu;')
define(greeksigma,`&sigma;')
define(greeklambda,`&lambda;')
define(boldgreekbeta,`\bold{&beta;}')
define(boldgreekepsilon,`\bold{&epsilon;}')
define(LOG,`\log')
define(SQRT,`\sqrt{$1}')
define(EQBOLD,`\bold{$1}')
define(EQN,`<i>$1</i>')
define(DEQN,`<P align=center>
<i>$2</i></P>
<H5 align=center>((Equations will(?) come with HTML 3.x ))</H5>')
define(DEQTEX,`')
define(DEQHTML,`<P align=center><i>$1</i></P>')
END
# Fix up the input to protect things that m4 is sensitive about.
sed '
/^ALIAS/,/^EXAMPLES/s/^ *//
/^ARGUMENTS/,/^EXAMPLES/s/^ *//
/^DESCRIPTION/,/^EXAMPLES/s/^ *//
s/unix/M4_unix/g
s/#/M4_HASH/g
s/\\(/M4_LP/g
s/\\(/M4_LP/g
s/\\)/M4_RP/g
s/`/M4_LQ/g
s/'\''/M4_RQ/g
s/,/M4_COMMA/g
s/ @@ /,/g
s/@@/,/g
s/ifelse/M4_IFELSE/g
' $*) | $MFOUR |sed '
/^$/d
s/^BLANK$//
s/DOTS/\.\.\./g
s/M4_unix/unix/g
s/M4_HASH/#/g
s/M4_LP/(/g
s/M4_RP/)/g
s/M4_LQ/`/g
s/M4_RQ/'\''/g
s/M4_COMMA/,/g
s/M4_IFELSE/ifelse/g
'
echo '</BODY>'