#!/usr/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# cmdtext720 src/cmdtext/usr/bin/subndx/subj.sh 1.12 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1989,1994 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)13      1.12  src/cmdtext/usr/bin/subndx/subj.sh, cmdtext, cmdtext720 3/30/07 04:29:50
#
# COMPONENT_NAME: (CMDTEXT) Text Formatting Services
#
# FUNCTIONS:
#
# ORIGINS: 54,27,28
#
# (C) COPYRIGHT International Business Machines Corp. 1989,1998
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#

CAT=/usr/bin/cat
DSPMSG=/usr/bin/dspmsg
SORT=/usr/bin/sort

umask 077
TMPDIR=${TMPDIR:-$HOME/tmp}
[[ ! -d $TMPDIR ]] && TMPDIR=/tmp
TMPDIR=$TMPDIR/${0##*/}.$$
/usr/bin/mkdir $TMPDIR || {
        print -u2 "${0##*/}: Could not create temporary files"
        exit 1
}

trap  "/bin/rm -rf $TMPDIR 2>/dev/null" EXIT INT TERM QUIT HUP
UL=/usr/lib/dwb
d=d
if test "$1" = "-e"; then
	shift
	d=
fi
if test $# -eq 0 -o "$1" = "-"; then
	arg=$TMPDIR/subj0$$
	$CAT - >$arg
else
	arg=$*
fi
COUNT=0
for i in $arg
do
	if test ! \( -r $i \); then
        	$DSPMSG ndx.cat 16 "subj: subj aborted, cannot read \
the file  %s\n" $i >&2
        	$DSPMSG ndx.cat 17 "Please check to see that %s exists \
and is readable\n" $i >&2
        	exit 1
	fi
	TEXT=$TMPDIR/sbj$$
	/usr/bin/sed -e "s/[\][*]F//g" -e "s/[\]f(..//g" -e "s/[\]f.//g" -e "s/[\]s[+-][0-9]//g" \
	 -e "s/[\]s[0-9]\{1,2\}//g" $i > $TEXT
	
	HFILE=$TMPDIR/sbj1$$
	SFILE=$TMPDIR/sbj2$$
	CFILE=$TMPDIR/sbj3$$

	$UL/sbj1 $TEXT $HFILE $SFILE $CFILE $d > /dev/null
	sed  "/[.][ 	]*is[.]$/s// is./" $HFILE |
		$UL/parts -o    | $UL/sbj2 | $SORT -udf -o $HFILE
	$UL/parts -o  $SFILE | $UL/sbj3 | $SORT -udf -o $SFILE
	
	FINAL=$TMPDIR/sbj8$COUNT$$
	
	$SORT -udf  $CFILE -o  $CFILE
	
	$CAT -s  $HFILE $SFILE $CFILE | $SORT -udf > $FINAL
	/usr/bin/rm -f $TMPDIR/sbj[1-3]$$
	COUNT=`/usr/bin/expr "$COUNT" + 1`
done
$CAT $TMPDIR/sbj8*$$ |
	$SORT -udf -o $TMPDIR/sbj0$$
$CAT $TMPDIR/sbj0$$
/usr/bin/rm -f $TMPDIR/sbj*$$
$DSPMSG ndx.cat 18 'subj completed\n' >&2
