#!/bin/sh
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=''

FlInfo() {
    /bin/ls -ldgL $* |
	sed -e 's@^\(..........\)\([^ 	]\)@\1 \2@'	\
    ;
}
	
FlOwner() {
    $jsr FlInfo $* | awk '{print $3}'
}

FlGroup() {
    $jsr FlInfo $* | awk '{print $4}'
}

FlSize() {
    $jsr FlInfo $* | awk '{print $5}'
}

LinkName() {
    $jsr FlInfo $* | awk '{print $11}'
}

IsSymLink() {
    test -h $1
    return $?
}


DirentExists() {		#non-referencing symLinks included
    test -d $1 -o -f $1 || $jsr IsSymLink $1
    return $?
}
	
FlsNewer() {
    than=`echo $1 | sed 's@[/.]@\\\\&@g'`	#stick in backslashes to escape
    {
	echo ""					#in case none newer
	/bin/ls -Ldtr $* 
    } | sed -e '1,/^'$than'$/d' -e '/^'$than'$/d'
}

FlsOlder() {
    than=`echo $1 | sed 's@[/.]@\\\\&@g'`	#stick in backslashes to escape
    {
	echo ""					#in case none older
	/bin/ls -Ldt $* 
    } | sed -e '1,/^'$than'$/d' -e '/^'$than'$/d'
}



FsFragSize() {
    echo 1024
}

TreeSizeK() {
    du -s $1 | awk '{print $1}'
}


FlSizeK() {
    $jsr FlSize $1 | awk '{print int($1 / 1024 + 0.99) }'
}


Df() {					#reports info in Kbytes, hierarchically
    echo "\
Filesystem                          avail Kb  Mounted on"
    df="df"
    $df $* | sed -e 's@//@/@g' -e 's@\([^ 	]\)/$@\1@' | awk '\
	NR == 1  { next }
	NF == 1  { filesys = $1; next }		#broken into two lines
	{   if ( $0 ~ /^[^ 	].*/ ) filesys = $1
	    mntPt = $(NF)
	    avail = $(NF-2)
	    if ( avail < 0 ) avail = 0
	    printf( "%-35s %8d  %s\n", filesys, avail, mntPt )
	}' | sort -b +2
}


DfTree() {
    (
	if [ $# -eq 1 ]; then
	    cd $1 || return 1
	fi

	$jsr Df | awk '\
	BEGIN   { here = "'`/bin/pwd`'" }	#requires real absolute path
	NR == 1 { print; next }
	{
	    if ( here == "/" ) {
		print				#filesys is descendant of $here
	    } else if ( $3 == "/" || \
			$3 "/" == substr( here , 1, length($3)+1 ) ) {
		pending = $0			#filesys is ancestor of $here
	    } else if ( $3 == here ) {		
		pending = ""
		print				#filesys is $here
	    } else if ( substr( $3, 1, length(here)+1 ) == here "/" ) {
		if ( pending != "" ) print pending
		pending = ""
		print				#filesys is descendant of $here
	    }
	}
	END {
	    if ( pending != "" ) print pending
	}'

    )
}


DkAvail() {
    ( cd $1 && $jsr Df . ) | awk 'NR == 2 {print $2}'
}


Dirname() {					#print argument minus leaf, or .
    case $1 in
	*/* )	echo $1 | sed 's@/[^/]*$@/@' ;;
	*)	echo "." ;;
    esac
}

Leafname() {					#print leaf
    case $1 in
	*/* )	echo $1 | sed 's@.*/@@' ;;
	*)	echo $1 ;;
    esac
}

Fullpath() {					#print rooted path to arg dir
    ( cd $1 && /bin/pwd |
	sed 's@^/tmp_mnt/@/@' )			#print automount access dir
}

Dirpath() {					#print rooted path to arg - leaf
    $jsr Fullpath `$jsr Dirname $1`
}

Suffix() {
    echo $1 | sed -n 's@.*\.@@p'
}

Prefix() {
    echo $1 | sed 's@\.[^.]*$@@'
}

OSvendor=sun4
OSarchs=$OSvendor
Proot=`$jsr Fullpath ../..` ; export Proot

echo `$jsr DfTree $Proot | sed '1d' | awk ' {print $2} '` > $1 
