#!/usr/bin/perl

$default_class = 'westnet';

open (STDERR, ">&STDOUT");
select ((select(STDOUT), $| = 1)[0]); # Synchronize STDOUT
select ((select(STDERR), $| = 1)[0]); # with STDERR

($dns_lib = $0) =~ s:(^|/)[^/]*$::;
($script=$0) =~ s:^.*/([^/]*)$:$1:;	# Get the simple name of this script.

push (@INC, $dns_lib);

require 5.0;
require 'dns_lib.perl';

umask 0117;

@dirs = ();

rcs_co ('.', '.zoneinfo');
open (TEMP, ">$tree_root/.zoneinfo_tmp") || die "Cannot open temp file: $!\n";
push (@dirs, $tree_root);

while ($current = pop (@dirs)) {

    $zone = $current;
    $zone =~ s/^$tree_root\/*//o;
    $zone = join ('.', reverse (split ('/', $zone)));

    opendir (DIR, $current);
    @files = readdir (DIR);
    closedir (DIR);

    foreach $file (@files) {

	next if $file eq 'RCS';
	next if $file =~ m/\..*/;

	if (-d "$current/$file") {

	    print TEMP "$file";
	    print TEMP ".$zone" if $zone;
	    print TEMP ".\n";
	    push (@dirs, "$current/$file");

	}

    }

}

close TEMP;

rename ("$tree_root/.zoneinfo", "$tree_root/.zoneinfo.old");
rename ("$tree_root/.zoneinfo_tmp", "$tree_root/.zoneinfo");
unlink ("$tree_root/.zoneinfo.old");
unlink ("$tree_root/.zoneinfo_tmp");

system ($build_class);

rcs_ci ('.', '.zoneinfo', 'Script: $script -- .zoneinfo rebuilt.');
    
exit;
