#!/usr/bin/perl -w
#
# gather_option.pl
#
# kjl/11nov2003
#
# Print option value from gather.cf.
#

# Print usage and exit
usage () if ($#ARGV != 1);

open (IN, "<$ARGV[0]") or die "Can't open \"$ARGV[0]\": $!";

$ret_val = 1;

while (<IN>) {
    next if /^(\s+$|#)/;
    last if /^\</;
    if (parse_line ($_)) {
	$ret_val = 0;
	last;
    }
}

close (IN);

exit $ret_val;

#
# print usage and exit
#
sub usage {
    print STDERR "Usage: gather_option.pl <CONFIGFILE> <OPTION>\n";
    print STDERR "Read CONFIGFILE and print gatherer configuration value for OPTION.\n";
    exit 1;
}


#
# parse a line and returns
#   0: line was not matching
#   1: line was matching
#
sub parse_line {

    $_ = shift;

    ($key, $val) = /(.*):\s+(\S.*)/;

    if (lc ($ARGV[1]) eq lc ($key)) {
	print "$val\n";
	return 1;
    }

    return 0;
}
