#!/usr/local/bin/perl5
@INC = ("/ra/ripe181/lib", @INC);

require "rconf.pl";
require "/usr/local/lib/perl/getopt.pl";

&Getopt('C');

$conffile=$ENV{"RIPEDBCNF"};
if ( $opt_C ) {
    $conffile= $opt_C;
}
if ( !$conffile ) {
    print STDERR "\nYou must specify -C <conffile>, eg, /ra/ripe181/conf.\n\n";
    exit;
}
&rconf($conffile);

print "\nobjects   attributes:\n";

foreach $key (keys %OBJATSQ) {
	print " $key       $OBJATSQ{$key}\n";
}
print "\n";

print "All attributes, sorted (across) by short name:\n";
$cnt = 0;
foreach $key (sort keys %ATTL) {
	printf "%2.2s = %-12.12s   ",  $key, $ATTL{$key};
	$cnt++;
	print "\n" if !($cnt % 4);
}
print "\n";

print "\nAll attributes, sorted (across) by long name:\n";
$cnt = 0;
foreach $k (sort values %ATTL) {
    printf "%2.2s = %-12.12s   ",  $ATTR{$k}, $k;
    $cnt++;
    print "\n" if !($cnt % 4);
}
print "\n";

#
# This cross check must be last, as we first destroy the ATTR array, then recreate it!
#
undef %ATTR;
print "\nCross-checking ATTR list...\n";
open(CONF, $conffile) || die "\ncannot open config \"$conffile\", $!";
$line = 0;	$errcnt = 0;
while (<CONF>) {
	$line++;
	if (/^ATTR\s+(..)\s+(\S*)/) {
		if ( $ATTR{$1} ) { 
			print "WARNING (conf line $line): attr $1 already exists ($ATTR{$1})\n";
			$errcnt++;
			next;
		}
		if ( $ATTR{$2} ) {
			print "WARNING (conf line $line): attr $2 already exists ($ATTR{$2})\n";
            $errcnt++;
            next;
        }
        $ATTR{$1}=$1; $ATTR{$2}=$1; $ATTL{$1}=$2;
        next;
    }
}
close(CONF);
print "Done with cross-check...$errcnt errors found.\n";

print "\n";

