#
# /etc/services processing
#
# Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>

$have_services = 0;

sub read_services {
	local($_, $serv, $port, $rest);

	return if ($have_services);
	open(SERVICES, "<$source{services}") ||
		&fatal("can't open $source{services}: $!");
	while (<SERVICES>) {
		chop;
		s/#.*//o;
		s/^\s+//o;
		s/\s+$//o;
		next if (/^$/);
		($serv, $port, $rest) = /(\S+)\s+(\S+)\s*(.*)/o;
		$serv2port{$serv} = $_;
		foreach $serv (split(/\s+/, $rest)) {
			$serv2port{$serv} = $_;
		}
	}
	close SERVICES;
	$have_services = 1;
}

sub services_byname {

	local($serv);

	&read_services;

	foreach $serv (keys %serv2port) {
		printf OUT "$serv\t$serv2port{$serv}\n";
	}
}

1;
