/*********************************************************
 * Gotcha library example code.
 * (c)1995 Thomas Bickel. All rights reserved.
 *
 * Demonstrates the usage of the DZN functions
 *********************************************************/
#include <stdio.h>

#include <exec/lists.h>
#include <clib/exec_protos.h>
#include <pragmas/exec_pragmas.h>

#include <clib/gotchalib_protos.h>
#include <pragmas/gotchalib_pragmas.h>
#include <libraries/gotchalib.h>

struct Library *GotchaLibBase;
struct gl_context *context;

UWORD  *nets;
UWORD  *zones;
UBYTE  **dom;

ULONG a,b,c;

/***********************************************************************/
int main(long argc, char *argv[])
{
	if (GotchaLibBase = OpenLibrary("gotcha.library",1)) {
		if (context = GL_OpenNL("nodelist:")) {
			if (GL_GetDZNLists(context,&dom,&zones,&nets)) {

				a = b = c = 0;
				while (dom[a]) {
					printf("\n\nDomain: %s",dom[a]);

					while (zones[b] != 65535 ) {
						printf("\nNets in Zone %ld (%s):\n",zones[b],dom[a]);

						while (nets[c] != 65535) {
							printf("%ld ",nets[c]);
							c++;
						}
					c++; b++;
					}
                c++; b++; a++;
				}
				puts("\n\n");

				GL_FreeDZNLists(context,&dom,&zones,&nets);
			} else
				puts("Out of memory!");

			GL_CloseNL(context);
		} else
			puts("Could not open the nodlist!");

		CloseLibrary(GotchaLibBase);
	} else
		puts("Could not open 'gotcha.library'!");
}
