// AmyShutDown
// Copyright © 1997 Infinity Labs Development Organization
// All Rights Reserved
// Version 1.00
// Author: Manolis S. Pappas

/* Libraries */
#include <libraries/mui.h>
#include <libraries/gadtools.h> /* for BARLABEL in MenuItem */

/* Prototypes */
#include <clib/muimaster_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>


/*  Pragmas  */
#include <pragmas/muimaster_pragmas.h>
#include <pragmas/exec_pragmas.h>

/*  Ansi  */
#include <stdlib.h>
#include <stdio.h>
/* GenCodeC header end */

/* Include generated by GenCodeC */
#include "ShutDownGUI.h"

extern long __stack=10000;     // enough stack for MUI

/* ASL Requester structure -- used for error handling if MUI fails */

struct EasyStruct errorReq={
    sizeof(struct EasyStruct),
    0,
    "AmyShutDown",
    "%s",
    "Ok",
};

/* Declarations for libraries (inserted by GenCodeC) */
struct Library * IntuitionBase;
struct Library * MUIMasterBase;
struct Library * LocaleBase;

/* Init() function */
void init( void )
{
        if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
        {
                EasyRequest(NULL,&errorReq,0,"Can't open intuition.library");
                exit(20);
        }
        if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
        {
                EasyRequest(NULL,&errorReq,0,"Can't open muimaster.library\nMake sure you have MUI installed\nand try again!");
                CloseLibrary(IntuitionBase);
                exit(20);
        }
        if (!(LocaleBase = OpenLibrary("locale.library",38)))
        {
                EasyRequest(NULL,&errorReq,0,"Can't open locale.library\nBuilt-in English Strings will be used!");
        }
        OpenAppCatalog(NULL,NULL);
}
/* GenCodeC init() end */

/* End() function */
void end( void )
{
        CloseAppCatalog();
        if (LocaleBase)
                CloseLibrary(LocaleBase);
        CloseLibrary(MUIMasterBase);
        CloseLibrary(IntuitionBase);
        exit(20);
}
/* GenCodeC end() end */

/* Main Function inserted by GenCodeC */
int main(int argc,char **argv)
{
        struct ObjApp * App = NULL;     /* Object */
        BOOL    running = TRUE;
        ULONG   signal;
        int     selection=0;
        
        /* Program initialisation : generated by GenCodeC */
        init();

        /* Create Object : generated by GenCodeC */
        if (!(App = CreateApp()))
        {
                EasyRequest(NULL,&errorReq,0,"Can't create MUI application");
                end();
        }

        while (running)
        {
                switch (DoMethod(App->App,MUIM_Application_Input,&signal))
                {
                        case MUIV_Application_ReturnID_Quit:
                                running = FALSE;
                                break;

                        /* Insert your code between the "case" statement and comment "end of case ..." */
                        case OK:
                        
                        // read the active selection button
                        get(App->radOptions,MUIA_Radio_Active,&selection);
                        
                        // decide what we'll do: 0=shutdown, 1=reboot
                        
                        if(selection==0)
                                Execute("AmyShutDown.ShutDown <NIL: >NIL:",0,0);
                        else
                                Execute("AmyShutDown.Reboot <NIL: >NIL:",0,0);
                                
                        break;        
                        
                        /* End computing of IDCMP */

                        default:
                        break;
                }
                if (running && signal) Wait(signal);
        }
        DisposeApp(App);
        end();
}
