#! /bin/sh

cd `dirname $0`

cat <<@ >index.phtml
!! This file is automatically generated! Do not edit it.
!! Edit the script 'mkindex'.

!default slib_cmd=help
!default slib_detname=special_cmd
!set slib_detail=\$(\$slib_detname)
<p>
!if \$slib_detail!=\$empty
 !readproc slib/\$slib_detail slib_header
 !distribute lines \$slib_parms into slpcnt,slp1,slp2,slp3,slp4,slp5,slp6,slp7,slp8,slp9,slp10
 !for i=1 to \$slpcnt
  !set slpdflt\$i=!item 1 of \$(slp\$i)
  !set slp\$i=!item 2 to -1 of \$(slp\$i)
 !next i
 <p><center><table border=2 bgcolor=\$wims_ref_bgcolor cellpadding=3>
 <caption>Library script</caption>
 <tr><th>Name</th><td><tt>\$slib_detail</tt> </td></tr>
 <tr><th>Effect</th><td>\$slib_title </td></tr>
 <tr><th>Call from module</th><td><tt>!readproc slib/\$slib_detail [parameters]</tt></td></tr>
 <tr><th>Call from OEF / DOC</th><td><tt>slib(\$slib_detail [parameters])</tt></td></tr>
 <tr><th>Parameters</th><td>
 !if \$slpcnt>1
  Up to \$slpcnt, comma-separated
 !else
  \$slpcnt
 !endif
 </td></tr>
 !for i=1 to \$slpcnt
  <tr><th>Parameter \$i</th>
  <td>\$(slp\$i)
  !if \$(slpdflt\$i)!=\$empty
   <em>(default: \$(slpdflt\$i))</em>
  !endif
  </td></tr>
 !next i
 <tr><th>Output</th><td>\$slib_out</td></tr>
 !if \$slib_comment!=$empty
  <tr><th>Comment</th><td>\$slib_comment</td></tr> 
 !endif
 </table> <p> 
 !reset \$slib_detname
 !exit
!endif
Scripts in this library can be called from modules using the command 
<tt>!read</tt> (or <tt>!readproc</tt> from within an phtml file).
For example, the line
<pre>
\$ !read slib/matrix/random 3,5,10
</pre>
will generate a random matrix 3&times;5 with integer coefficients of range 10.
The output of the script will be placed in the variable <tt>slib_out</tt>.
They can also be called from OEF exercises, documents or forum messages, via the
function <tt>slib()</tt>.
<p>
Only variables with prefix <tt>slib_</tt> will be modified by these scripts.

<p><center><table border=2 bgcolor=\$wims_ref_bgcolor cellpadding=3>
<caption>Available scripts in slib</caption>
<tr><th>Name</th><th>Effect</th></tr>
@

cnt=0
for f in `find . -type f | sed 's!^\./!!g' | grep ./ | sort`
do
 echo $f
 tit=`awk -F= '$1=="slib_title" {print $2; exit}' $f`
 if [ -n "$tit" ]; then
  cnt=$((cnt+1))
  cat <<@ >>index.phtml
<tr><td><tt>$f</tt></td><td>$tit
!href cmd=\$slib_cmd&module=\$module&\$slib_detname=$f\$slib_detailanchor [detail]
</td</tr>
@
 fi
done

cat <<@ >>index.phtml
</table></center> <p>
@

echo
echo Indexed $cnt scripts.
echo

