#! /bin/ksh

# genpub cetgory=books|journals|videos|conferences acm#s

. functions
PGM=$0

category=$1; shift
catrec=`sssearch "type=pub&category=$category" pubs.db`
pagename="`echo "$catrec" | ssformat -t %title`"
sortkeys=`echo "$catrec" | ssformat -t %sortkeys`
tabent=`echo "$catrec" | ssformat -t %tabent`   # summary in category page
summary=`echo "$catrec" | ssformat -t %summary` # summary inside pub page

#-----------------------------------------------------------------------------
function genitem # generate page for one item
{
	# read in record from $category.db and assign to shell variables
	record=`sssearch acmordernumber=$1 $category.db`
	tmp=`genfields $category.db`
	. $tmp
	rm $tmp

	genheader "$title" "$url" "$pagename"
	gencomment This page generated `date` by $0 in $PGM

	if test "$editor$author"
	then
		echo "<dl>"
	fi
	if test "$editor"
	then
		echo "<dt>Edited by:<dd>"
		echo "$editor" | genname 
	fi
	if test "$author"
	then
		echo "<dt>Written by:<dd>"
		echo "$author" | genname 
	fi
	if test "$editor$author"
	then
		echo "</dl>"
	fi

	echo "<table border=1>"
	echo "<tr>"

		if test "$imagesmall"
		then
			echo "<td rowspan=20 valign=top>"
			if test "$imagelarge"
			then
				echo "<a href=$imagelarge>"
			fi
			echo "<img border=0 src=$imagesmall><br>"
			if test "$imagelarge"
			then
				echo "</a>"
			fi
		fi

		echo "$summary" |
			while read line
			do
				gentabent $line
			done

	echo "</table>"

	if test "$desc"
	then
		echo "<p>"
		echo "$desc"
	fi

	if test "$contents"
	then
		echo "<p>"
		echo "<b>Contents</b><br>"
		firstchar=${contents%${contents#?}}
		if test "$firstchar" != "<" # not HTML tagged
		then
			echo "<pre>"
			echo "$contents" | expand -3
			echo "</pre>"
		else
			echo "$contents"
		fi
	fi
	genfooter $category

}


#-----------------------------------------------------------------------------
# Executable Section

if test "$*"
then
	items="$*"
	nitems=$#
else
	items=`sssort -f "$sortkeys" $category.db | ssformat -t %acmordernumber`
	nitems=`echo $items | wc -w`
fi

for item in $items
do
	echo $item > /dev/tty
	genitem $item > $item.html
done
