#!/usr/local/bin/perl
# Contributed by: howie@warlok.ds.boeing.com (Howard Modell)

@config = `/usr/sbin/prtconf -pv`;
$i = 0;
foreach $line (@config)
{
        if ( $line =~ /\sname:\s+'memory'/ )
        {
                $j = $i - 2;
                if ($config[$j] =~ /\sreg:/)
                {
                        $gotit = $config[$j];
                        chop $gotit;
                        goto GotIt;
                }
        }
        $i = $i + 1;
}
printf "no 'memory' line??\n";
exit;

GotIt:
$gotit =~ s/\s+reg:\s+//;
$gotit =~ s/'//g;
@slots = split(/\./, $gotit);
$slot = 1;
$totmem = 0;
$machine = `/usr/bin/uname -m`;
chop $machine;
print "On this $machine machine ...\n";
if ("$machine" =~ /sun4u/)
{
        $val0 = 3;
        $valinc = 4;
        $cardtype = "DIMM";
}
else
{
        $val0 = 2;
        $valinc = 3;
        $cardtype = "SIMM";
}
$OneMeg = 0x00100000;
@banks = ("J201", "J303", "J202", "J301", "J305", "J203", "J302", "J304");
for($val=$val0; $val < scalar(@slots); $val = $val + $valinc)
{
        $simm = $slots[$val];
        $simmsize = hex($simm) / $OneMeg;
        $totmem += $simmsize;
        if ("$cardtype" =~ /SIMM/)
        {
                printf "slot $slot has a " .  $simmsize . "M $cardtype \n";
        }
        else
        {
                printf "bank $slot has 2 " .  ($simmsize / 2) . "M SIMMs \n";
        }
        $slot = $slot + 1;
}
printf "total memory = " . $totmem . "M\n";
