/*
** Reccoon UTILITY template v1.00
**
** A shell for a utility, does all the necessary stuff to make it
** work. Now you only have to think about the main coding.
*/

#include <exec/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <exec/exec.h>
#include <dos/dos.h>

#include <Reccoon/Shared.h>
#define RLIB_MACRO
#include <Reccoon/Recclib.h>

extern struct DosLibrary *DOSBase;

#define VERSION "1.00"

/* __COMMODORE_DATE__ is Dice-only */

UBYTE *Version = "\0$VER: MyUtility "VERSION" ("__COMMODORE_DATE__")";

struct CtrlMessage  ctrlmsg;
struct fig      *   fig             = 0;
struct control  *   ctrl            = 0;
struct MsgPort  *   ctrlport        = 0;
struct MsgPort  *   ctrlreplyport   = 0;
struct Library  *   RecclibBase     = 0;

int Sluta( int );

void main(UWORD ac, UBYTE *av[])
{
    RecclibBase=OpenLibrary("reccoon.library",0);
    if(!RecclibBase){
        puts("Couldn't open Reccoon.library\n");
        exit(20);
    }

    ctrl=OpenRCtrl(0,65535,&ctrlmsg,&ctrlport,&ctrlreplyport);
    if(!ctrl){
        puts("Couldn't access ReccControl!\nYou must have it running to use this program.\n");
        CloseLibrary(RecclibBase);
        exit(10);
    }

    fig=ctrl->fig;

    atexit((void *)Sluta);

    /* This is were to put the code */

    /* Inbetween these remarks      */

    exit(0);
}

int Sluta(int e) /* Sluta is swedish for Quit */
{
    if(RecclibBase)
    {
        CloseRCtrl(ctrlport,ctrlreplyport,&ctrlmsg);
        CloseLibrary(RecclibBase);
        RecclibBase=0;
    }
    return(e);
}

