Desktop Magic work-alike

;/* Execute me to compile
gcc  splat.c -gstabs -o Splat -Wall -N -lauto
quit
;*/
#define __USE_INLINE__
 
#include <proto/exec.h>
#include <proto/dos.h>
#include <stdio.h>
#include <proto/intuition.h>
#include <proto/datatypes.h>
#include <clib/alib_protos.h>
#include <datatypes/soundclass.h>
#include <exec/execbase.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <dos/dos.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <SDI_compiler.h>
#include <string.h>
#include "intuition.lvo"
#define HANDLER_PRIORITY 55
#define PROGNAME "MagicHandler"
 
TEXT __attribute((used)) ver[] = "$VER: Splat 0.1 (30.12.2012)";  // dd.mm.yyyy
 
void (* openWindow) (void);
Object *o;
 
static struct InputEvent * MagicEvent (REG(a0,struct InputEvent * events), REG(a1,APTR handlerData));
struct Interrupt MagicEventInt;
 
void Playsnd1()
 {
char *name = "bogus.wav";
 
  if (o = NewDTObject (name,DTA_GroupID,GID_SOUND,TAG_END))
	{
		DoMethod (o,DTM_TRIGGER,NULL,STM_PLAY,NULL);
        Delay(40);
        DisposeDTObject (o);
    }
  else
  {
    printf("error - wave file %s not found?\n",name);
    }
}
 
 
void Playsnd2()
 {
char *name = "A1000.aiff";
 
  if (o = NewDTObject (name,DTA_GroupID,GID_SOUND,TAG_END))
	{
		DoMethod (o,DTM_TRIGGER,NULL,STM_PLAY,NULL);
        Delay(40);
        DisposeDTObject (o);
    }
  else
  {
    printf("error - wave file %s not found?\n",name);
    }
}
 
 
// Note - if RUN, you cannot exit out with CTRL-C!
 
int main(int argc,char **argv)
{
	struct MsgPort  * InputMP;
	struct IOStdReq * InputIO;
 
 
 if (!IntuitionBase)
     return (30);
 
//	  printf("Splat running - CTRL-C to exit...\n");
 
    Playsnd2();
 
	InputMP = CreateMsgPort();
	if (InputMP) {
		InputIO = (struct IOStdReq *)CreateIORequest(InputMP, sizeof(struct IOStdReq));
		if (InputIO) {
			if (!OpenDevice("input.device", 0, (struct IORequest *)InputIO, 0)) {
				ULONG sigmask = 0, waitsigs;
 
				memset(&MagicEventInt, 0, sizeof(MagicEventInt));
				MagicEventInt.is_Node.ln_Pri = HANDLER_PRIORITY;
				MagicEventInt.is_Node.ln_Name = PROGNAME;
				MagicEventInt.is_Code = (void (*)())MagicEvent;
 
				/* add handler to system */
				InputIO->io_Command = IND_ADDHANDLER;
				InputIO->io_Data = (APTR)&MagicEventInt;
				DoIO((struct IORequest *)InputIO);
 
				waitsigs = SIGBREAKF_CTRL_C;
				while (!(sigmask & SIGBREAKF_CTRL_C)) {
					sigmask = Wait(waitsigs);
				}
 
				/* remove handler from system */
				InputIO->io_Command = IND_REMHANDLER;
				InputIO->io_Data = (APTR)&MagicEventInt;
				DoIO((struct IORequest *)InputIO);
 
				CloseDevice((struct IORequest *)InputIO);
			}
			DeleteIORequest((struct IORequest *)InputIO);
		}
		DeleteMsgPort(InputMP);
	}
 
 
 
//	  Wait(SIGBREAKF_CTRL_C);
 
 
	printf("Splat exiting\n");
 
	return 0;
}
 
static struct InputEvent * MagicEvent (REG(a0,struct InputEvent * events), REG(a1,APTR handlerData))
{
	struct InputEvent * event;
	/* loop through events */
	event = events;
	while (event != NULL) {
        if ((event->ie_Class != IECLASS_TIMER)&&(event->ie_Class != IECLASS_RAWMOUSE))
        {
        //printf("Event Class = %d, qualifier = %d, code = %d\n",event->ie_Class,event->ie_Qualifier,event->ie_Code);
        }
        if (event->ie_Class == IECLASS_CLOSEWINDOW)
        {
        Playsnd2();
        }
        else if (event->ie_Class == IECLASS_DISKINSERTED)
        {
        Playsnd1();
            }
        else if (event->ie_Class == IECLASS_RAWKEY)
             {
             Playsnd2();
             }
 
 
		event = event->ie_NextEvent;
	}
	return events;
}