#!/usr/bin/perl
$Ver = "0.4";
#
# simple perl script to extract informations from the nodelist
# about a given sysop name.
# i don't know about the format of the nodelist, so perhaps it
# will not work 100% right :)
#
# Usage: ifinfo <sysop_name>
#    if you give the full name quote it or replace the space
#    through a '_'
#
# rasca, berlin 1994 (Rasca Gmelch, 2:2410/305.4)
#

# *** EDIT the next LINE to the right path!!! ***
$nodelist = `find /usr/fido/nodelist/nodelist.[0-9][0-9][0-9]`;

# use the first nodelist, which is found..
# perhaps here should be a loop to process all found nodelists.
($nodelist) = split (/\s+/, $nodelist);
# or use a fix filename
# $nodelist = "/usr/fido/nodelist/linuxnet.lst";

# default domain
$domain = "fidonet.org";

if ((@ARGV != 1) || $ARGV[0] eq "-?" || $ARGV[0] eq "-h") {
	&usage;
}
$input = $ARGV[0];

# substitute spaces in the name argument through "_"
$input =~ s/ +/_/g;

open (NLIST, "<$nodelist")  || die "can't open nodelist '$nodelist'";
while ($line=<NLIST>) {
	#
	# skip lines with comments
	#
	if ($line =~ /^[^;]/) {
		#
		# split the line..
		($key, $num, $sys, $locate, $name, $phone, $speed, $flags) = split(/,/,
$line, 8);
		#
		# and have a look at the first field..
		#
		if ($key eq "Zone") {
			$zone = $num;

		} elsif ($key eq "Host") {
			$net = $num;

		} elsif ($key eq "Hub") {
			$hub = "f$num.n$net.z$zone.$domain ($sys)";

		} elsif ($name =~ /$input/) {
			$feed = $num;
			# i don't know about the meaning of all keywords in the nodelist,
			# so print the not known keys behind the system name :-)
			if ($key ne "")
				{ $sys .= " ($key)"; }
			$name =~ s/_/\./g;
			print "System:    $sys\n";
			print "Sysop:     $name@f$feed.n$net.z$zone.$domain\n";
			print "Location:  $locate\n";
			print "PhoneNo.:  $phone\n";
			print "Speed:     $speed\n";
			print "NL-Flags:  $flags";
			print "HubSystem: $hub\n\n";
			$found++;
		}
	}
}
close (NLIST);
if (!$found) {
	print ("$0: \"$input\" not found\n");
	exit (1);
}


sub usage {
	print ("$0 Version $Ver\n");
	print ("Usage: $0 <sysop_name>\n");
	exit (2);
}

