#!/bin/sh             

# vxsize                                                             
# casey@ccii.co.za
# This works in hex now
SIZE='i386-wrs-vxworks-size'                

# remove all leading 0's
#h_adr=`echo $3 | sed -e 's/0*//'`
#l_adr=`echo $2 | sed -e 's/0*//'`

h_adr="0x$3"                                                                    
l_adr="0x$2"

# calcuate the difference                                                       
lmt="$[ ( $h_adr - $l_adr ) ]"                                                  

# extract correct fields                                                        
$SIZE -x $4 |grep $4 > /tmp/size
t="0x`cut -f1 /tmp/size`"                                                       
d="0x`cut -f2 /tmp/size`"
b="0x`cut -f3 /tmp/size`"                                                       
rm /tmp/size

# determine total                                                       
ADD="$[ $t + $d + $b ]" 

if `test $lmt -gt $ADD`
then                                                                   
        excess="$[ $lmt - $ADD ]"                                       
        echo "$4: $t(t) + $d(d) + $b(b) = $ADD ($excess under)"
else
        excess="$[ $ADD - $lmt ]"
        echo "$4: $t(t) + $d(d) + $b(b) = $ADD ($excess over)"
        echo "warning: image is larger than $lmt bytes!"     
fi         
