#include <exec/types.h>
#include <exec/lists.h>
#include <exec/nodes.h>
#include <exec/memory.h>

#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/amigaguide_protos.h>

#include <libraries/amigaguide.h>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

extern struct Library *AmigaGuideBase;

struct List *NameList010List=NULL;
struct List *AddrList010List=NULL;
struct List *addrlist_g=NULL;
struct List *namelist_g=NULL;

AMIGAGUIDECONTEXT Contact97Guide;
struct NewAmigaGuide Contact97Help;

struct AddressAddress {
	struct Node nn_Node;
	char nn_Data[30];
};	

struct AddressMaster {
	char AddrName[30];
	char AddrComp[30];
	char AddrEmail[30];
	char AddrTel[20];
	char AddrFax[20];
};

struct NameNode {
    struct Node nn_Node;        	/* System Node structure */
    struct AddressMaster nn_Address;	/* Node-specific data */
};

#define NAMENODE_ID   100       /* The type of "NameNode" */
#define ADDRNODE_ID   101       /* The type of "NameNode" */

long selected_g=-1;

#include "Contact97Gui.c"
#include "Contact97Gui_Handle.c"

/***********************************************
	Entry Point for Workbench
************************************************/

int wbmain()
{
	main();
return 0;
}

/***********************************************
	Contact97 Main Program Entry Point
************************************************/

int main()
{
	int running=0;

/***********************************************
	Initialise Exec Lists
************************************************/

	NameList010List=AllocMem(sizeof(struct List),MEMF_CLEAR);
	AddrList010List=AllocMem(sizeof(struct List),MEMF_CLEAR);

	NewList(NameList010List);
	NewList(AddrList010List);

/***********************************************
	Load Data From File (if possible)
************************************************/

	LoadContactData(NameList010List,AddrList010List);

/***********************************************
	Setup Screen & Open Main Window + help
************************************************/

	SetupScreen();

	Contact97Help.nag_Flags =HTF_NOACTIVATE;
	Contact97Help.nag_BaseName ="Contact97";
	Contact97Help.nag_Name="Contact97.guide";
	Contact97Help.nag_ClientPort = "Contact97_Help";
	Contact97Help.nag_Context = NULL;
	
	Contact97Guide =OpenAmigaGuideAsync(&Contact97Help,NULL);

	OpenProject0Window();

/***********************************************
	Setup ListView in Main Window
************************************************/

	UpdateLVList(Project0Wnd,Project0Gadgets[4],NameList010List,1);

/***********************************************
	Wait for Intuition Response(s)
************************************************/

	while(running!=100)
	{
		running=HandleProject0IDCMP();
	}

/***********************************************
	Close Main Window & Screen + help
************************************************/

	CloseProject0Window();

	if(Contact97Guide !=NULL) CloseAmigaGuide(Contact97Guide);	

	CloseDownScreen();

/***********************************************
	Close Down Program
************************************************/
	if(NameList010List!=NULL)
	{
		FreeNameNodes(NameList010List,1);
		FreeMem(NameList010List,sizeof(struct List));
	}
	if(AddrList010List!=NULL)
	{ 
		FreeNameNodes(AddrList010List,0);
		FreeMem(AddrList010List,sizeof(struct List));
	}
	if(addrlist_g!=NULL)
	{ 
		FreeNameNodes(addrlist_g,0);
		FreeMem(addrlist_g,sizeof(struct List));
	}
	if(namelist_g!=NULL)
	{
		FreeMem(namelist_g,sizeof(struct List));
	}
return 0;
}

