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

require '/afs/athena/contrib/perl/dev/lib/sun4c_411/getopts.pl';
&Getopts("f:l:u:y:p:h:m:r:ao:");
$|=1;
$dbfile = $ARGV[0];
open(DB, $dbfile);
while(<DB>){
	chop;
	($foo_f, $foo_l, $foo_u, $foo_y, $foo_h, $foo_r, $foo_p, @lists)=split(/[ \t]+/);
	$fnm = $lnm = $unm = $yem = $hom = $rom = $phm = $lim = 1 unless $opt_a;
	$chopthis = $foo_h;
	$foo_r = chop($chopthis)."-$foo_r";
	$foo_n = $foo_f.' '.$foo_l.' 'x(20-length($foo_f)-length($foo_l));
	$foo_u .= ' 'x(9-length($foo_u));
	$foo_p = 'x'.substr($foo_p, 0, 1).'-'.substr($foo_p, 1);
	chop($foo_h) if(length($foo_h) > 1);

	($fnm = ($foo_f =~ $opt_f)) if $opt_f;
	($lnm = ($foo_l =~ $opt_l)) if $opt_l;
	($unm = ($foo_u =~ $opt_u)) if $opt_u;
	($yem = ($foo_y =~ $opt_y)) if $opt_y;
	($hom = ($foo_h =~ $opt_h)) if $opt_h;
	($rom = ($foo_r =~ $opt_r)) if $opt_r;
	($phm = ($foo_p =~ $opt_p)) if $opt_p;
	($lim = (grep(/$opt_m/, @lists))) if $opt_m;

	if($opt_a){
	    $match = ($fnm || $lnm || $unm || $yem || $hom || $rom || $phm || $lim);
	}
	else{
	    $match = ($fnm && $lnm && $unm && $yem && $hom && $rom && $phm && $lim);
	}
	if($match){
	    @output = split(//, $opt_o);
	    for $o (@output){
		eval("print(\"\$foo_$o\\t\")");
	    }
	    print("\n");
	}

}

