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

$have_rpc = 0;

sub read_rpc {
	local($_, $prog, $number, $rest);

	return if ($have_rpc);
	open(RPC, "<$source{rpc}") ||
		&fatal("can't open $source{rpc}: $!");
	while (<RPC>) {
		chop;
		s/#.*//o;
		s/^\s+//o;
		s/\s+$//o;
		next if (/^$/);
		($prog, $number, $rest) = /(\S+)\s+(\S+)\s*(.*)/o;
		$prog2number{$prog} = $_;
		$number2prog{$number} = $_;
		foreach $prog (split(/\s+/, $rest)) {
			$prog2number{$prog} = $_;
		}
	}
	close RPC;
	$have_rpc = 1;
}

sub rpc_byname {

	local($prog);

	&read_rpc;

	foreach $prog (keys %prog2number) {
		printf OUT "$prog\t$prog2number{$prog}\n";
	}
}

sub rpc_bynumber {

	local($number);

	&read_rpc;

	foreach $number (keys %number2prog) {
		printf OUT "$number\t$number2prog{$number}\n";
	}
}

1;
