#!/usr/athena/bin/perl
$| = 1;


$directory = $ARGV[0];

$type = `uname -a`;
if ($type =~ /IRIX/)
{
    $lstype = "ls -laR";
}
elsif ($type =~ /SunOS\s+\S+\s+4.*/i)
{
    $lstype = "ls -lagR";
}
elsif ($type =~ /SunOS\s+\S+\s+5.*/i)
{
    $lstype = "ls -laR";
}
else
{
    $lstype = "ls -lagR";               # Default might change.
}

chdir "$directory" || print "Can't chdir!\n";

open (HANDLE, "$lstype |") || die "Failed to cd into $directory!\n";
$dir = $directory;
while ($line = <HANDLE>)
{
    if ($line =~ /^(\S+)\:/)
    {
        $dir = $1;
        $dir =~ s/^\.//;
        $dir =~ s/^\///;
        $dir = $directory . "/" . $dir;
    }
#    elsif ($line =~ /^(\S+)\s+\d+\s+(\S+)\s+(\S+)\s+\d+\s+\S+\s+\d+\s+\S+\s+(\S+).*/)
    elsif ($line =~ /^(\S+)\s+\d+\s+(\S+)\s+(\S+)\s+(\d+)\s+\S+\s+\d+\s+\S+\s+(.*)/)
    {
        $settings = $1;
        $owner = $2;
        $group = $3;
	$size = $4;
        $file = $5;
        $file =~ s/\s*$//;
        if ($file eq "..")
        {
            next;
        }

#-rw-rw-r--    1 root     wwwadmin     281 Sep 29 10:38 Math::BigFloat.z
#lrwxr-xr-x    1 root     wwwadmin      40 Oct 12 11:46 httpd -> /usr/netscape/httpd/install/bin/ns-httpd
#Probably won't see these:
#crw-rw-rw-    1 root     sys       39,  0 Aug 28 20:00 audio
#        print "Exp: $settings $owner $group $dir/$file\n";
        print "Exp: $dir/$file: $size\n";
	$totalsize = $totalsize + $size;

    }
#    elsif ($line =~ /^(\S+)\s+\d+\s+(\S+)\s+\d+\s+\S+\s+\d+\s+\S+\s+(\S+).*/)
    elsif ($line =~ /^(\S+)\s+\d+\s+(\S+)\s+(\d+)\s+\S+\s+\d+\s+\S+\s+(.*)/)
    {
        $settings = $1;
        $owner = $2;
	$size = $3;
        $file = $4;
        $group = "unknown";
        $file =~ s/\s*$//;
        if ($file eq "..")
        {
            next;
        }

#-rw-rw-r--  1 rei         20284 Oct 16 15:53 wa_publish.exp
#        print "Exp: $settings $owner $group $dir/$file\n";
        print "Exp: $dir/$file: $size\n";
	$totalsize = $totalsize + $size;

    }

}
print "\nTotal: $totalsize bytes\n";

$megs = ($totalsize/1048576);

printf ("\n   or: %4.6s megabytes\n", $megs);
