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

#include <exec/execbase.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>

#include <proof/proof.h>
#include <proof/proof_protos.h>
#include <proof/proof_pragmas.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/intuition_pragmas.h>

/* Function prototypes */

/* Global variables */
extern struct Library *DOSBase;
struct Library *ProofBase;

char *version = "$VER: ProofOwner 1.0 (19.9.99)";

void main( int argc, char **argv )
{
	ULONG err;
	char *str;
	UBYTE att;

	ProofBase = OpenLibrary( "proof.library", NULL );
	if ( ProofBase != NULL )
	{
		struct ProofOwner *po = NULL;

		err = AllocProofOwner( &po, NULL );
		if ( err == PFERR_NONE )
		{
			int i;
			char tempstr[20];

			SetProofOwnerAttrs( po,
				PFN_ProofOwnerID, 50,
				PFN_ProofOwnerIdent, "Test user",
				TAG_DONE );

			for ( i = 0; i <=3; i++ )
			{
				sprintf( tempstr, "group %d", i );
				SetProofOwnerEntry( po, i, POWN_GROUP_NAME, tempstr );
			}

			SetProofOwnerEntry( po, 0, 2, "group 0 cat 2" );

			for ( i = 0; i <=3; i++ )
			{
				str = GetProofOwnerEntry( po, i, POWN_GROUP_NAME );
				if ( str ) printf("GET:%s\n",str);
			}

			err = SaveProofOwner( po, PFN_ProofOwnerName, "ram:test", TAG_DONE );
			if ( err != NULL ) printf("save error:%d\n",err);

			FreeProofOwner( &po, NULL );


			po = NULL;

			err = LoadProofOwner( "ram:test", &po, NULL );
			if ( err == PFERR_NONE )
			{
				GetProofOwnerAttrs( po, PFN_ProofOwnerID, &att, TAG_DONE );
				printf("OWNER ID=%d\n", att );
				GetProofOwnerAttrs( po, PFN_ProofOwnerIdent, &str, TAG_DONE );
				printf("OWNER=%s\n", str );

				for ( i = 0; i <=3; i++ )
				{
					str = GetProofOwnerEntry( po, i, POWN_GROUP_NAME );
					if ( str ) printf("GET:%s\n",str);
				}

				printf("%s\n", GetProofOwnerEntry( po, 0, 2 ) );

				FreeProofOwner( &po, NULL );
			}
			else printf("load error:%d\n",err);		
		}
		else printf("allocate error:%d\n",err);
	}

	if ( ProofBase != NULL ) CloseLibrary( ProofBase );
}
