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

use strict;
use IO::File;

@ARGV or die "no pairs specified";
@ARGV % 2 and die "must specify in pairs";
{ my %x; undef @x{@ARGV}; keys %x == @ARGV or die "shelfcodes not distinct"; }
my %dest = map { uc } @ARGV;

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

exists $category{$_} or die "'$_' is not a shelfcode" for values %dest;
exists $category{$_} and die "'$_' is still a shelfcode" for keys %dest;

*menuloop= sub
  {
    my $tot = 0;
    for my $bk (@{$dex{main}})
      {
	my %hash = codetohash ($$bk{code});
	my $hit = 0;
	$hit += ( $hash{$dest{$_}} = delete $hash{$_} )
	  for grep { exists $hash{$_} } keys %dest;
	next unless $hit;
	$tot += $hit;
	$$bk{code} = hashtocode (%hash);
	print panther($bk);
      }
    print "changed $tot volumes";
    savedex ('main');
    tryquit ();
  };

panthercomm ();

