head     1.1;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.1
date     89.07.20.12.45.30;  author sarah;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#!/bin/sh
#
# romsize - compute ROM size
#
# modification history
# --------------------
# 01a,12dec88,gae  written.
#            +dnw
#
# SYNOPSIS
# romsize [-k nnn] file
#
# DESCRIPTION
# This tool calculates ROM size.  The -k option specifies the maximum
# size of the ROM in K bytes; the default is 128K.  If the calculated
# rom size (text + data) is greater than the maximum then a warning is
# emitted.
#
# EXAMPLE
#
#     % romsize -k 256 bootrom
#     romsize: 244988(t) + 59472(d) = 304460 (256K=262144); unused = -42316
#       WARNING: bootrom LARGER THAN 256K!
#
#
# SEE ALSO
#  size (1)
#*/

# set defaults

tool=`basename $0`
usage="usage: $tool [-k nnn] filename"
rsawk=/tmp/rs.awk_$$
trap "rm -f $rsawk; exit" 1 2 3 15
ks=128

# crack parameters

if (test $# -lt 1) then
    echo $usage
    exit 0
fi

readoptions=true
while ($readoptions) do
    case $1 in
    -k)	ks=$2; shift;;
    -*)	echo "$tool: invalid option $1"; exit 0;;
    *)	readoptions=false; ;;
    esac

    if ($readoptions) then
	shift
    fi
done

if (test $# -lt 1) then
    echo $usage
    exit 0
fi

# generate awk file

cat << EOF > $rsawk
NR==2	{
	sum=\$1 + \$2;
	totsize=$ks * 1024;
	printf ("$tool: %d(t) + %d(d) = %d (${ks}K=%d); unused = %d\n", \
		\$1, \$2, sum, totsize, (totsize - sum));
	if (sum > totsize)
	    print ("  WARNING: $1 LARGER THAN ${ks}K!");
	printf ("\n");
	}
EOF

# do calculation

size $1 | awk -f $rsawk

# clean up

rm -f $rsawk

exit 0
@
