#! /bin/sh
#	merge_man_entries - merges 4gl doc. files, sorting by function name
#
#	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.
#

awk '
#set record separator
BEGIN		{
		    FS="\""
		    linecount=0
		    preamble=0
		    infunction=0
		}

#scan for function names
/^<P><A NAME/	{
		    currfunct=$2;
		    if (preamble==1) preamble=2
		    linecount=0
		    infunction=1
		}

#print line with sort key
(infunction)	{
		    print "11" currfunct sprintf("%07d", linecount) " " $0
		    linecount++
		    infunction=length($0)
		    next
		}

# print the file header
(preamble!=2)	{
		    print "00" sprintf("%07d", linecount) " " $0
		    preamble=1
		    linecount++
		    next
		}

# print the trailer
		{
		    print "zz" sprintf("%07d", linecount) " " $0
		    linecount++
		}
' $* |
#
# it is assumend that you are smart enough not to feed repeatedly the same
# functions to this script. the -u it's there just in case :-)
#
sort -u -t " " +0 |
sed -e 's/^[^ ]\+ //'
