#!/afs/athena/contrib/perl/perl

# ./main.pl config-file dirname
# config-file is the name of the config file
# and dirname is the name of the directory in /usr/tmp to dump stuff

unshift(@INC, "/mit/mkgray/project/comprehensive");

require 'should.pl';		# Should and auxilliary routines
require 'log.pl';		# Logging routines & badlink
require 'analyze.pl';		# Analyze document.  get_* & is_real...
require 'queue.pl';		# Qeueuing routines
require 'url.pl';		# get_url and auxilliary stuff
require 'process.pl';

$debug = 0;
$|=1;

&queue'init;
&logger'init;
$SIG{'HUP'} = 'wrapup';
$SIG{'INT'} = 'wrapup';


$starting_point = &load_config;

&do_url($starting_point);
#&mail_errors;
&process_results;
&zme($myresults);

sub do_url {
    local($url, @ancestors) = @_;

    if(($hdrs, $doc) = &get_url($url)){
	&badlink($message, $url, @ancestors) 
	    if (($message = &is_real_document($hdrs, $doc)) != 200);
	@local_links = &get_links($doc);
	for $link (@local_links){ # 
	    &logger'write_memory_log($link);
	}			# 
    }
}

sub wrapup {
    &queue'wrapup;
}
