#!/usr/local/bin/perl
#
# getnames - print list of first names from ph files
#
# usage: profsadd config [files]
#	         $CONFIG $STDIN

if ($#ARGV<1)
  {print STDERR "Usage: getnames config [files]\n";exit 1;}
 
#
# find the numbers of the id and name fields
$inum = $nnum = -1;
$config = shift;
open (CONFIG,$config) || die "$config: $!\n";
while (<CONFIG>)
{
	if (/:id:/) {($inum)=(split(':'))[0];}
	elsif (/:name:/) {($nnum)=(split(':'))[0];}
}
close(CONFIG);

# Now read lines from input file printing the first name from each
while (<>) {
	chop;
	tr/A-Z/a-z/;
	$name = $_;
	if (! /\t$inum:/ && !/^$inum:/) {next;}
	$name =~ s/.*\t$nnum:[^ 	]* ([^ 	]*).*/\1/;
	print "$name\n";
}
