sub cfghost {my $F='cfghost';
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Given a config-file path and a host name, we extract the info from the file #
# and  save it in @cfg.  We also look for a few specific lines and save their #
# data in some other global arrays.  We return the number of lines read  from #
# the config file, or undef if we can't open the file.                        #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
	local($cfile,$host) = @_;
	local($cfg,$flg,$i,$line,$lines,$opt,$pat);
	print V "$F: Called with V='$V'\n" if $V>1;
	print V "$F: cfile=\"$cfile\"\n" if $V>1;
	print V "$F:  host=\"$host\"\n" if $V>1;
	return undef unless $cfile;	# Fail if file name is missing or null
	@cfg = ();
	unless (open(CFG,$cfile)) {
		print V "$F: Can't read config file \"$cfile\" ($!)\n" if $V>1;
		return undef;		# Fail if we can't read the file
	}
	print V "$F: Reading config info from \"$cfile\"\n" if $V>1;
	$lines = 0;
	for $line (<CFG>) {
		++$lines;
		$line =~ s/[\s\r]+$//;
		print V "$F: LINE:\"$line\"\n" if $V>2;
		if ($line =~ /^\s*#/) {		# Ignore comments
			print V "$F: Ignore: \"$line\"\n" if $V>1;
		} elsif ($line =~ /^[+0-9]*\s*(C)[:\s]\s*(.*)/) {	# C: command to get file
			$Getcmd{"$1$host"} = $2;
			print V "$F: Get command \"$2\" for $host (from cfg file)\n" if $V>1;
		} elsif (($flg,$opt) = ($line =~ /^([-+])(CGI)$/i)) {	# +CGI to allow CGI calls
			print V "$F: CGI option flg='$flg' opt='$opt' from \"$line\"\n" if $V>1;
			$Opt{CGI} = $flg eq '+' ? 1 : 0;			# Turn CGI on/off
			print V "$F: CGI option '" . $Opt{CGI} . "' (\"$line\")\n" if $V>1;
		} elsif ($line =~ /^[+0-9]*\s*(D)[:\s]\s*(\d+)/) {	# D: Depth limit
			$DepthHost{$host} = $2;
			print V "$F: Depth limit \"$2\" for $host (from cfg file)\n" if $V>1;
		} elsif ($line =~ /^[+0-9]*\s*(T)[:\s]\s*(\d+)/) {	# D: TIme limit; exit if no tunes found in this many seconds
			$giveuptime = int($2);	
			print V "$F: Time limit \"$2\" for $host (from cfg file)\n" if $V>1;
		} elsif ($line =~ /^[+0-9]*\s*(L)[:\s]\s*(\d+)/) {	# L: Line max before giving up
			$maxlines = $2;
			print V "$F: maxlines=$maxlines for $host (from cfg file)\n" if $V>1;
		} elsif (($cfg,$flg,$opt) = ($line =~ /^[+\d]*\s*(\w)[:\s]\s*([-+]*)(.+)/)) {	# X:name
			print V "$F: $cfg: '$flg' \"$opt\" option.\n" if $V>1;
			if ($cfg eq 'O') {
				print V "$F: O: '$flg' \"$opt\" option.\n" if $V>1;
				if ($opt =~ /^(CGI|tagP)$/i) {	# On/off controls
					print V "$F: Set $opt option to '$flg'\n" if $V>1;
					$Opt{$opt} = $flg;	# Remember this option's on/off flag
				} elsif ($opt =~ /^U(\d+)$/i) {	# URL limit
					$maxurls = int($1);
					print V "$F: Limit to maxurls=$maxurls URLs\n" if $V>1;
				} else {
					print V "$F: Unrecognized option '$opt' in \"$line\"\n" if $V>1;
				}
			} else {
				print V "$F: Unrecognized config command '$cfg' in \"$line\"\n" if $V>1;
			}
		} elsif ($line =~ m"^HTTP/([.\d]+)") {			# HTTP/1.0
			$HTTPversion = $1;		# Global notice of this value
			print V "$F: HTTPversion=\"$HTTPversion\"\n" if $V>0;
		} elsif ($line =~ /^Crawl-delay:*\s*(\d+)/) {
			$crawldelay = int($1);		# Global notice of this value
			print V "$F: crawldelay=$crawldelay [$line]\n" if $V>0;
		} elsif ($line =~ /^(delay):*\s*(\d+)/i) {		# delay: seconds
			print V "$F: crawldelay=$2 sec. [$line]\n" if $V>3;
			$crawldelay = int($2);			 # Min time between requests
		} elsif ($line =~ m"^Avoid[:\s]\s*(.*)\s*$"i) {	# Hosts to avoid
			print V "$F: Avoid \"$1\"\n" if $V>1;
			&avoid($1);
		} elsif ($line =~ /^Disallow:*\s*(.*)$/) {		# Disallow: URI
			if ($1) {
				$Disallow{$1}++;
				$hstmsg = "Disallow \"$1\"";
				print V "$F: $hstmsg\n" if $V>0;
			}
		} elsif ($line =~ s"^(Rpl|Replace|Rewrite)[:\s]\s*(.+)$"$1"i) {    # URL edits
			$pat = $2;
			print V "$F: Rewrite \"$pat\"\n" if $V>1;
			&cfgRewrite($pat);
		} elsif ($line =~ /^QuotesOK/) {		# Disallow: URI
			$QuotesOK = 1;
			print V "$F: Quotes allowed in URLs.\n" if $V>1;
		} else {
			print V "$F: Config line \"$line\" not matched.\n" if $V>1;
		}
		push @cfg, $line;
	}
	close CFG;
	return $lines;
}

1;
