#! /bin/sh

########################################################################
#                 copyright 2001, Amoco Production Company             #
#                             All Rights Reserved                      #
#                     an affiliate of BP America Inc.                  #
########################################################################

#
umask 2

if ( test $# -le 1 || test "${FreeUSP}" = "" ) then
	echo " "
	echo "apps-mancopy:  copy manual pages from specified section_# "
	echo "          to remote systems using shadowcopy facility"
	echo "          & to ${FreeUSP}/dist/man/${product}/man/[man#,cat#] "
	echo "          The new date is also stamped onto the man page"
	echo "          If a pattern file exists for XIKP, that is also"
	echo "          copied to the ${FreeUSP}/dist/etc/usp/xui_pattern"
        echo "          directory."
	echo " "
	echo "Usage:"
	echo "          apps-mancopy product section_# [program names]"
	echo " "
	echo " Please set the env var FreeUSP to the proper location"
	exit 1
fi
#set pgm = $argv[1]
product=$1
shift
suffix=$1
section=`echo $suffix | sed s/[a-z].*//`
shift
cdir=`pwd`

for args
	do
#
	if (test ! -f $args.${suffix}) then
	  exit 0
	fi
	date="`date '+\"%a %h %d %Y\"' `"
	line=".TH $1 ${suffix}  $date \"From FreeUSP\""
	sed "1,$ s/\.TH.*/$line/" $args.${suffix} > tmp.$$
	"mv" tmp.$$ $args.${suffix}
	cp ${args}.${suffix} ${FreeUSP}/dist/man/${product}/man/man${section}
	if (test -f ${args}.pattern) then
	  cp ${args}.pattern ${FreeUSP}/dist/etc/usp/xui_pattern
	fi

#
# Run  a man command native to our architecture to generate the cat1 file.
#
	MANPAGER=cat
	export MANPAGER

	Vendor=`usp-osarch -v`

	if test "${Vendor}" = "Sun"
	then
	  Version=`usp-osarch -R`
	  if test ${Version} -eq 4
	  then
 	    man - -M ${FreeUSP}/dist/man/${product}/man $suffix $args
	  else
	    man -F -M ${FreeUSP}/dist/man/${product}/man -s $suffix - $args
	  fi
	elif test "${Vendor}" = "Linux"
	then
 	  man --preformat -M ${FreeUSP}/dist/man/${product}/man $suffix $args
	elif test "${Vendor}" = "SGI"
	then
 	  man -M ${FreeUSP}/dist/man/${product}/man $suffix $args
	else
 	  man - -M ${FreeUSP}/dist/man/${product}/man $suffix $args
	fi

done 
