#!/usr/athena/bin/perl -lw

use strict;
use IO::File;

do "./dex";
die "no exception raised" unless $@;
undef $@;
use vars qw( %dex %category );


my %ref = ('RP' => 'C/REF-P', 'RH' => 'C/REF-H');
my %ran = ('RP' => 'C/RAN-P', 'RH' => 'C/RAN-H');

my @reserve = qw( R/REF-P R/REF-H );

exists $category{$_} or die "'$_' is not a shelfcode"
  for keys %ref, values %ref, values %ran;

$ref{'did'} = $ran{'did'} = 0;

*menuloop= sub
  {
    my ($nran, $nref) = (0, 0);
    for my $bk (@{$dex{main}})
      {
	my %hash = codetohash ($$bk{code});
	my @old = grep { exists $hash{$_} } keys %ref or next;
	my $to = ( grep { exists $hash{$_} } @reserve ) ? \%ref : \%ran;
	$$to{'did'} += ( $hash{$$to{$_}} = delete $hash{$_} ) for @old;
	$$bk{code} = hashtocode (%hash);
	print panther($bk);
      }
    print "";
    print "sent $ref{did} to C/REF, $ran{did} to C/RAN";
    savedex ('main');
    tryquit();
  };

panthercomm();
