#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/lib/pios/piocustp.sh 1.15 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1992,1995 
# 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 
# @(#)37	1.15  src/bos/usr/lib/pios/piocustp.sh, cmdpios, bos720 3/13/07 06:54:29
#
# COMPONENT_NAME: (cmdpios) Printer Backend
#
# FUNCTIONS:
#
# ORIGINS: 27
#
# (C) COPYRIGHT International Business Machines Corp. 1992, 1997
# 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.
#
######
# Add attributes for Terminal Connected Printer Queues to virtual printer
# custom colon file.
######
# cmdline:
# piocustp -i colon_filename
######
# Called from mkvirprt
######


# Get command line option (colon filename)
#################
while getopts i: opt ; do
	case $opt in
	i)	CFILE=$OPTARG;;
	esac
done

# Get queue name
#############
qname=$(/usr/bin/basename $CFILE | /usr/bin/cut -f1 -d:)

# Get queue device name
#############
qdname=$(/usr/bin/basename $CFILE | /usr/bin/cut -f2 -d:)

# Get tty device name
######
TTYDEV=/dev/$(/usr/bin/grep ":mn:" $CFILE | /usr/bin/cut -f5 -d:)

# Get adapter hardware discipline from the ODM.
###########

ADAPTER=$(
   MAJOR=`/usr/bin/ls -l $TTYDEV | /usr/bin/awk -F, '{print $1}' | /usr/bin/awk '{print $5}'`
   /usr/bin/odmget -q "resource=ddins AND value2=$MAJOR" CuDvDr | /usr/bin/grep value1 | /usr/bin/cut -f2 -d\"
)
ADAPTER=${ADAPTER%%dd}

# Attribute default values
#################
rs_bufsiz=10
rs_delay=200000
lion_priority=30
cxma_maxcps=100
cxma_maxchar=50
cxma_bufsiz=100

# Get printer type
#################################################################
PRINTER=$(/usr/bin/grep ":mt:" $CFILE | /usr/bin/cut -f5 -d:)

# Set virtual printer attribute
###############################
case "$PRINTER" in
	ibm4201-2|ibm4201-3)
	# IBM 4201 
		cxma_maxcps=270
		;;
	ibm4207|ibm4208-2)
	# IBM 4207 & 4208
		cxma_maxcps=270
		;;
	ibm4019)
	# IBM 4019
		;;
	hplj-2)
	# HPLJ II
		;;
	ibm4202-2|ibm4202-3)
	# IBM 4202
		cxma_maxcps=270
		;;
	ibm5204)
	# IBM 5204
		cxma_maxcps=350
		;;
	ibm2380|ibm2381)
	# IBM 2380 & 2381 
		cxma_maxcps=320
		;;
	ibm2390|ibm2391)
	# IBM 2390 & 2391
		cxma_maxcps=200
		;;
	ibm4029)
	# IBM 4029
		;;
	hplj-3)
	# HPLJ III
		;;
esac

# Update virtual printer custom file
#############################
echo ":599:__TAP::" >> $CFILE
echo ":613:y0::$ADAPTER" >> $CFILE
case "$ADAPTER" in
rs)
	echo ":600:y1::$rs_bufsiz\n:601:y2::$rs_delay" >> $CFILE ;;
sty)
	echo ":600:y1::$rs_bufsiz\n:601:y2::$rs_delay" >> $CFILE ;;
lion)
	echo ":602:y1::$lion_priority" >> $CFILE ;;
cxia)
	echo ":603:y1::$cxma_maxcps\n:604:y2::$cxma_maxchar\n:605:y3::$cxma_bufsiz" >> $CFILE ;;
cxma)
	echo ":603:y1::$cxma_maxcps\n:604:y2::$cxma_maxchar\n:605:y3::$cxma_bufsiz" >> $CFILE ;;
pci/cxpa)
	echo ":603:y1::$cxma_maxcps\n:604:y2::$cxma_maxchar\n:605:y3::$cxma_bufsiz" >> $CFILE ;;
# All other adapters will be considered to be 3rd party adapters and will be
# handled like the native port.
*)
	echo ":600:y1::$rs_bufsiz\n:601:y2::$rs_delay" >> $CFILE ;;
esac
exit 0
