#!/bin/sh
#
# Use the $min and $max from new to see how many test seq #s are available
#

tmp=/var/tmp/$$
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15

_do_range()
{
    awk '
BEGIN	{ first = last = -2 }
	{ if ($1 == last+1) {
	    last = $1
	  }
	  else {
	    if (first != -2) {
		if (first == last) print first
		else print first "-" last
	    }
	    first = last = $1
	  }
	}'
}

eval `grep '^min=' new`
eval `grep '^max=' new`

sed -n <group >$tmp.taken \
    -e 's/:\(retired\|reserved\) / /' \
    -e '/^[0-9]/s/[        ].*//p' \
# end

try=000
while [ $try -lt $min ]
do
    if [ ! -f "$try" ]
    then
	if grep "^$try\$" $tmp.taken >/dev/null
	then
	    :
	else
	    echo $try
	fi
    fi
    try=`expr $try + 1`
    try=`printf "%03d" $try`
done >$tmp.avail

if [ -s $tmp.avail ]
then
    echo "Below min=$min [`wc -l <$tmp.avail | sed -e 's/ //g'` available] ..."
    echo "9999999" >>$tmp.avail
    _do_range <$tmp.avail
    echo
fi

try=$min
while [ $try -le $max ]
do
    if [ ! -f "$try" ]
    then
	if grep "^$try\$" $tmp.taken >/dev/null
	then
	    :
	else
	    echo $try
	fi
    fi
    try=`expr $try + 1`
    try=`printf "%03d" $try`
done >$tmp.avail

if [ -s $tmp.avail ]
then
    echo "Between min=$min and max=$max [`wc -l <$tmp.avail | sed -e 's/ //g'` available] ..."
    echo "9999999" >>$tmp.avail
    _do_range <$tmp.avail
fi



