#!/bin/sh

#
# Creates HTML files of java applications.  Lists source code and output.
#

unset CLASSPATH
export CLASSPATH

[ -d "$1" ] && chdir $1

for file in `ls *.java`
do
	/bin/echo "$file: \c"
	prints=`grep -c println $file`
	isApp=`grep -c "public static void main" $file`
	if [ $prints -gt 0 ] && [ $isApp -gt 0 ]
	then
		echo is printing application.
		base=`basename $file .java`
		html="$base.html"
		cat > $html << EOF
<HTML>
<HEAD>
<TITLE> $file </TITLE>
</HEAD>
<BODY BGCOLOR=#ffffff>

<H3> Source code for $file: </H3>
<BLOCKQUOTE>
<PRE>
EOF
		cat $file >> $html
		cat >> $html << EOF
</PRE>
</BLOCKQUOTE>
<HR>

<H3> Output from $file: </H3>
<p>
<PRE>
<BLOCKQUOTE>
EOF
		java $base >> $html 2>&1
		cat >> $html << EOF
</BLOCKQUOTE>
</PRE>
<p>
<I> --- Output Ends --- </I>

<H4> NOTE: </H4>
You are reading previously generated output.  You are not currently running
the $base application at the momement.  You need to compile and run the
source code first.
<p>
<H4> To run this program: </H4>
<UL>
	<CODE>
	<LI> javac $file
	<LI> java $base
	</CODE>
</UL>
<HR>

<FONT SIZE=1>
Authors: Kevin Chu and Eric Brower
<br>
Copyright 2000 Prentice Hall PTR
</BODY>
</HTML>
EOF
	else
		echo NOT prints=$prints isApp=$isApp
	fi
done
