:
#	@(#) initorder 23.7 92/01/09 
#
#	Copyright (C) 1990-1992 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#

#########################################################################
# initorder - print the order in which the xxinit() routines are called #
#	      given a particular mdevice and sdevice.			#
#########################################################################

tmp=/tmp/initord$$

cleanup() {
	rm -f $tmp.?
	exit $1
}

cd `dirname $0`
[ "$ROOT" -o ! -f mdevice ] && cd $ROOT/etc/conf/cf.d

rm -f $tmp.?
trap 'cleanup 1' 1 2 3 15

# extract all the drivers out of mdevice that have an
# xxinit() entry-point, noting entry-point name also
#
awk '$1 !~ /\*/ && $2 ~ /I/ {print $1 " " $4}' mdevice > $tmp.m || cleanup $?

# extract all the drivers out of sdevice that are linked into the kernel
# note: it is more reliable to refer to sdevice than to sdevice.d, since
# it reflects the last link of the kernel, whereas sdevice.d may have
# been modified since e.g. by initialization of the linkkit
#
awk '$1 !~ /\*/ && $2=="Y" {print $1}' sdevice > $tmp.s || cleanup $?

# deduce from mdevice whether this release had Sdevinit:
# 3.2.0 GT, 3.2.0 MC, 3.2.1 GT had no Sdevinit
#
Sdevinit=NONE

# if there is a "string" driver then this is 3.2v4 which has scsi_config
grep -l "^string " $tmp.m > /dev/null && Sdevinit=32v4 || {

# if there is a "first" driver then this is 3.2v2 which had Sdevinit
grep -l "^first " $tmp.m > /dev/null && Sdevinit="" || {

	# if there is an "hf" driver but no "ct6157" driver,
	# then this is 3.2.1 MC which also had Sdevinit
	#
	grep -l "^hf " $tmp.m > /dev/null && {
		grep -l "^ct6157 " $tmp.m > /dev/null
		[ $? -ne 0 ] && Sdevinit=""
	}
}
}

count=0
exec < $tmp.m
while read driver epname
do
	# select configured-in drivers from those with init routines
	# note: only one init though driver may be repeated in sdevice
	#
	grep -l "^$driver$" $tmp.s > /dev/null
	[ $? -ne 0 ] && continue
	echo "F$count\t$driver\t${epname}init"

	case $driver in
	Sxxx)	# any 3rd-party drivers named S* which do
		# not participate in the Sdevinit scheme
		# should be added into this case
		count=`expr $count + 1`
		;;
	Sdsk)	# the first Sdev disturbs the sequence in 3.2.1 MC & 3.2v2
		# Sdskinit2 got called before the other Sdevinit2s
		[ "$Sdevinit" ] && count=`expr $count + 1` || echo "&\c"
		case "$Sdevinit" in
		32v4*)	Sdevinit="$Sdevinit $driver"	;;
		NONE)					;;
		*)	Sdevinit="$driver $Sdevinit"	;;
		esac
		;;
	S*)	# the first Sdev disturbs the sequence in 3.2.1 MC & 3.2v2
		[ "$Sdevinit" ] && count=`expr $count + 1` || echo "&\c"
		Sdevinit="$Sdevinit $driver"
		;;
	*)	count=`expr $count + 1`
		;;
	esac
done

case "$Sdevinit" in
NONE)	;;	# no Sdevinit in this release

"")	;;	# no Sdevs to init in this configuration

32v4*)	for driver in $Sdevinit
	do  [ $driver = 32v4 ] || {
		echo "F$count\t$driver\t${driver}init2"
		count=`expr $count + 1`
	    }
	done
	;;

*)	echo "F$count\t-\tSdevinit"
	for driver in $Sdevinit
	do	echo "&F$count\t$driver\t${driver}init2"
	done
	;;
esac

cleanup 0
