#!/bin/sh

#
#  pdtMappkg outfile [-f infile] [-p pdtpat] [pdtstr ...] 
#
#    Try to find the packages based upon products <infile> or
#    products list
#
#    Algorithm:
#       use list of products (infile) to find corresponding packages 
#
#############################################################################
#############################################################################
#
#	Copyright (C) Cadence Design Systems, Inc. All rights
#	reserved.  Unpublished -- rights reserved under the
#	copyright laws of the United States of America.
#
#			RESTRICTED RIGHTS LEGEND
#	Use, duplication, or disclosure by the Government is subject
#	to restrictions as set forth in subparagraph (c)(l)(ii) of 
#	the Rights in Technical Data and Computer Software clause 
#	at DFARS 52.227-7013.
#
#			Cadence Design Systems, Inc.
#			555 River Oaks Parkway
#			San Jose, CA 95134	USA
#
#############################################################################
BOURNE=/bin/sh
XTERMPATH=/usr/openwin/bin
XTERMBIN=xterm
XTERMOPTS="-T 'SoftLoad 6.0 Console' -fn 9x15  -sl 200 -g 80x40+0+0 -bg \#e0e0e0 -fg \#800000 -sb -e ${BOURNE} softload_GUI"
sysPATH=/bin:/usr/bin:/usr/ucb:$XTERMPATH

jsr=''
OSvendor=sun4
OSarchs=$OSvendor

LegalVendor() {
    OSVER=`/bin/uname -r`
    OSTYPE=`/bin/uname -s`
    test $OSTYPE = "SunOS" && test $OSVER -lt 5
    return $?
}


test -z "$Rm"	&& Rm=/bin/rm;		export Rm
if [ -z "$Proot" ]; then  
    echo "$0 environment not initialized" 				1>&2
    exit 1 
fi
export Proot

usagestr="usage:
	pdtMappkg outfile [-f infile] [-p pdtpat] [pdtstr ....]"

NL="
"
outfile=$1; shift
> $outfile

#either pass bundles file, products list of productpat
pdtstrs=
pdtpats=

if [ "X$1" = "X-f" ]; then
   shift	
   infile=$1; shift
elif [ "X$1" = "X-p" ]; then
   shift
   pdtpats=$1; shift
else
   pdtstrs="$*"
fi	

if [ -z "$InstPlat" ]; then
  echo "Installation platform not specified"
  exit 1
fi
export InstPlat

tmp=$Proot/install/tmp
pdts=$Proot/install/pdts
pkginfo=$tmp/pkginfo.$InstPlat
bundles=$tmp/bundles.$InstPlat
pdtPatFl=$tmp/bndlpats$$

if [ ! -z "$infile" ]; then     #no regular expressions
  if [ -s $bundles ]; then
   sed  's@\([^ ]*\).*$@$1 == "\1" { print $2 }@' $infile > $tmp/awkb$$
  else
   # if bundle file not exists, then we use products nok file to get
   # package information.
   cat $infile | while read pdtdesc pkgname pdtname pdtsize platform FMrelease; do
        Root="$pdts/${pdtname}_${platform}_${FMrelease}"
        test -s $Root.nok && sed -n '2,$p' $Root.nok
   done | sort -u > $pdtPatFl
  fi
else
   (
   set -f                      #disable filename generation
   if [ ! -z "$pdtstrs" ]; then
     for pdtstr in $pdtstrs; do
       echo "$pdtstr"
     done
   else
       cat $pdtpats
   fi

    ) | sed  's@^.*$@$1 == "&" { print $2 }@' > $tmp/awkb$$
fi

test -s $tmp/awkb$$ && {
	awk -f $tmp/awkb$$  $bundles  | sort -u > $pdtPatFl
	$Rm $tmp/awkb$$
}
test -s $pdtPatFl && {
	$BOURNE pkg_fltr -pkg $pkginfo +$pdtPatFl > $outfile
	$Rm $pdtPatFl
}
