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

/*------------------------------------------------------------------------*/
// A "real" application should look it up in some config!

#define NODELISTDIR	"Nodelist:"
/// Accomodate max's taste for directories

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

void main(int, char **);

/*------------------------------------------------------------------------*/
struct Library *NodelistBase;

/*-------------------------------------------------------------------------*/
void main(int argc, char **argv)
	{
	NodeList the_nodelist;
	NodeDesc *node_desc;
	Addr find_me;

	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);
		}

	// Open the nodelist. NLOpen's arguments are the path to the		 //
	// nodelist directory, and flags (not used by this implementation) //

	if((the_nodelist = NLOpen(NODELISTDIR, 0)))
		{
		Addr def = { 2, 310, 6, 0 };

		if(NLParseAddr(&find_me, argv[1], &def))
			{
			printf("Invalid address %s\n", argv[1]);
			}
		else
			{
			// Try to find the node. If successful, a NodeDesc& is returned. //
			// If NULL, either the node does not exist, or some fatal error  //
			// occured (Eg. out of mem, I/O error).								  //

			if(node_desc = NLFind(the_nodelist, &find_me, 0))
				{
				printf("Node %ld:%ld/%ld.%ld, \"%s\" is in %s\n",
						 node_desc->Node.Zone, node_desc->Node.Net,
						 node_desc->Node.Node, node_desc->Node.Point,
						 node_desc->System, node_desc->City);

				printf("Operated by %s\n", node_desc->Sysop);

				printf("Region %ld, Hub %ld\n", node_desc->Region,
						 node_desc->HubNode);

				printf("Baud %ld\n", node_desc->BaudRate);

				printf("Phone %s, ", node_desc->Phone);

				if(node_desc->Cost != -1)
					{
					printf("Cost %01ld.%02ld\n",
							 node_desc->Cost/100, node_desc->Cost%100);
					}
				else
					{
					printf("Undialable\n");
					}

				printf("Flags %s\n", node_desc->Flags);

				if(*node_desc->Passwd)
					printf("Password %s\n", node_desc->Passwd);
			
				NLFreeNode(node_desc);
				}
			else
				{
				puts("Node not found");
				}
			}
		
		NLClose(the_nodelist);
		}
	else	
		puts("Nodelist won't open");

	CloseLibrary(NodelistBase);
	}

/*-------------------------------------------------------------------------*/
/* ID: 91.1@2609  Last Changed: 08 Feb 1991 03:14:39 by mjl */
