#! /bin/sh
#	postprocess - script that automates function entries insertion in docs.
#
#	Marco Greco (marcog@ctonline.it), Catania, Italy
#
#	Initial release: Sep 97
#	Current release: Oct 97
#
#				NOTICE
# 	Permission to use, copy, modify and redistribute this software and
#	its documentation is hereby granted without fee provided that
#
#	- all copies of the software and related documentation contain this
#	  notice and authorship information, UNMODIFIED
#
#	- no fee is charged for the physical act of redistributing this
#	  software or modified copies thereof
# 
#	THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
#	EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
#	WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#
#	IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
#	INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
#	RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED
#	OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING
#	OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
#	ALL RISKS CONNECTED TO THE USE OF THIS SOFTWARE OR IMPOSSIBILITY 
#	THEREOF LIE SOLELY ON YOU.
#	USE OF THIS SOFTWARE CONSTITUES AGREEMENT WITH THE ABOVE TERMS 
#	AND CONDITIONS.
#

# a couple of temp files
tmp=/tmp/4gld$$
tmp_toc=/tmp/4glt$$

# identify html TOC file to update, if any
case $1 in
-i)
    main_toc=$2
    shift
    shift
    ;;
esac

# identify documentation file
source=$1
shift

# need at least one file to insert!
if [ $# -eq 0 ]
then
    echo $0: needs at least a file to be included
    exit
fi

# merge man entries in main docs file, plus sort entries
merge_man_entries $source $* > $tmp
mv $tmp $source

# rebuild contents index
build_index $source > $tmp_toc

# insert index on top of main docs file
insert_index $source $tmp_toc > $tmp
mv $tmp $source

# if we have a master TOC file, update that too
if [ -n "$main_toc" ]
then
    merge_index $main_toc $tmp_toc > $tmp
    mv $tmp $main_toc
fi
rm $tmp_toc
