/*********************************************************
 * Gotcha library example code.
 * (c)1995 Thomas Bickel. All rights reserved.
 *
 * Show extra configs from the database.
 *********************************************************/
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>

#include <exec/memory.h>
#include <exec/types.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 *cont;
struct gl_address add;
struct gl_address add2;

UBYTE *s;
ULONG x,found=0;
UBYTE adr[64];

int main(long argc, char *argv[])
{
	if (argc<2) {
		printf("Usage: %s <address>\n"
		"<address> may contain wild cards (*,?).\n",argv[0]);
		exit(10);
	}

	if (!(GotchaLibBase = OpenLibrary("gotcha.library",1))) {
		puts("Could not open 'gotcha.library'!");
		exit(20);
	}

	if (cont = GL_OpenNL("nodelist:")) {

        GL_XtractInfos(&add,argv[1]);
        x = NULL;

		do {
			x = GL_GetConfig(cont,&add,x,&s,&add2);
			if (s) {
				if (!found) puts("Node                   Config\n"
								 "-------------------------------------------------------------------");
				found++;
				GL_AddressToString(&add2,adr);
				printf("%-22.22s %s\n",adr,s);
			}
		} while (x);

		if (found) printf("\nMatched %ld entries in the database.\n",found);
		else puts("No entries matched the template.");

		GL_CloseNL(cont);
	} else
		printf("Could not open the nodelist!\n");

	CloseLibrary(GotchaLibBase);
}
