#! /bin/bash -f

# Takes a c file for a module in SCM and makes the template for the
# documentation, assuming it uses the "PROCIFY" macro setup, a la tcp.c:
#
#  Each primitive is named by a line of the form:
# static char p_<c-name>[] = MOD "<scheme-name>"
#  this may span two lines.
#
#  Each primitive has a line somewhere in the file of the form:
# PROCIFY(<c-name>)

NAME=`echo $1 | sed "s/.c//
s|.*/||"`

MOD=`grep ' *#define *MOD' $1 | sed 's/[^"]*"\([^:]*\):".*/\1/'`

grep '^ *PROCIFY' $1 | sed 's|[^(]*(\([^)]*\))|grep -1 "static char s_\1" '$1'|' | /bin/sh | sed -n 's/[^"]*"\([^"]*\)".*/\1/p' | sed 's/\&/\&amp;/
s/>/\&gt;/
s/</\&lt;/' > temp.procs

echo "<title>The "$MOD" module</title>
<h1>The "$MOD" module</h1>
<h2>Primitives</h2>
<ul>" > $NAME.html.template
sed 's|\([^?]*\)\?*|<li>(<a href = "#\1">'$MOD':&</a>)</li>|' temp.procs  >> $NAME.html.template
echo "</ul>
<h2>Primitives</h2>
" >> $NAME.html.template
sed 's|\([^?]*\)\?*|<p><a name = \1>(<b>'$MOD':&</b>)<p>|' temp.procs >> $NAME.html.template
echo "<hr><p>
<address></address>
Template auto-generated from "$1" on " >> $NAME.html.template
date >> $NAME.html.template
echo "<br>
<!-- hhmts start -->
<!-- hhmts end -->" >> $NAME.html.template

rm temp.procs

