#include <exec/types.h>
#include <proto/exec.h>
#include "nl.h"

/*------------------------------------------------------------------------*/
#define NODELISTDIR	"Nodelist:"

/*-------------------------------------------------------------------------*/
extern void printf(char *,...);
extern void puts(char *);
extern int atol(char *);
extern void exit(int);

void main(int, char **);

/*------------------------------------------------------------------------*/
struct Library *NodelistBase;
Addr TheAddr;

/*-------------------------------------------------------------------------*/
/// Updated client routine with new "UWORD region"
BOOL call_me(Addr *addr, UWORD region, void *the_nodelist)
	{
	// Matches in a certain net //

	if(addr->Zone == TheAddr.Zone	&&
		addr->Net  == TheAddr.Net )
		{
		NodeDesc *nd;

		// Find that node in nodelist //

		if(nd = NLIndexFind(the_nodelist, addr, 0))
			{
			printf("%ld:%ld/%ld.%ld %s in %s\n", addr->Zone, addr->Net,
					addr->Node, addr->Point, nd->System, nd->City);

			NLFreeNode(nd);
			}

		}		

	return (addr->Net <= TheAddr.Net);
	}

/*-------------------------------------------------------------------------*/
void main(int argc, char **argv)
	{
	NodeList the_nodelist;
	Addr def = { 2, 310, 0, 0 };

	if (argc != 2)
		{
		printf("Usage: %s FQFA\n", argv[0]);
		exit(5);
		}

	if(!(NodelistBase = OpenLibrary(TRAPLIST_NAME, TRAPLIST_VER)))
		{
		printf("Can't open library\n");
		exit(5);
		}

	NLParseAddr(&TheAddr, argv[1], &def);

	TheAddr.Node =
	TheAddr.Point= 0;

	if((the_nodelist = NLOpen(NODELISTDIR, 0)))
		{
		NLEnumNode(the_nodelist, 0, &TheAddr, call_me, the_nodelist);
		NLClose(the_nodelist);
		}
	else	
		puts("Nodelist won't open");

	CloseLibrary(NodelistBase);
	}

/*-------------------------------------------------------------------------*/
/* ID: 22.1@1886  Last Changed: 13 Feb 1991 19:57:14 by max */
