#import <Cocoa/Cocoa.h>

@interface Delegate : NSObject { }
@end

@implementation Delegate
- (void) sound: (NSSound *) sound didFinishPlaying: (BOOL) aBool
{
  [[NSApplication sharedApplication] terminate: nil];
}
@end

int playsound (char *soundfile)
{
  [[NSAutoreleasePool alloc] init];
  
  NSSound *sound = [[NSSound alloc] initWithContentsOfFile:
    [NSString stringWithCString:soundfile encoding:NSASCIIStringEncoding]
    byReference: YES];
  
  [sound setDelegate: [(id <NSSoundDelegate>) [[Delegate alloc] init]
    autorelease]];
  [sound play];

//  [[NSRunLoop currentRunLoop] run];

  return 1; // failed
}
