plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

macargv.m (1189B)


      1 #import <Cocoa/Cocoa.h>
      2 #import <Foundation/Foundation.h>
      3 
      4 #include <u.h>
      5 #include <libc.h>
      6 
      7 AUTOFRAMEWORK(Foundation)
      8 AUTOFRAMEWORK(Cocoa)
      9 
     10 @interface appdelegate : NSObject<NSApplicationDelegate> @end
     11 
     12 void
     13 main(void)
     14 {
     15 	[NSApplication sharedApplication];
     16 	NSObject<NSApplicationDelegate> *delegate = [appdelegate new];
     17 	[NSApp setDelegate:delegate];
     18 
     19 	NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];    /* Register a call-back for URL Events */
     20 	[appleEventManager setEventHandler:delegate andSelector:@selector(handleGetURLEvent:withReplyEvent:)
     21 		forEventClass:kInternetEventClass andEventID:kAEGetURL];
     22 
     23 	[NSApp run];
     24 }
     25 
     26 @implementation appdelegate
     27 - (void)application:(id)arg openFiles:(NSArray*)file
     28 {
     29 	int i,n;
     30 	NSString *s;
     31 
     32 	n = [file count];
     33 	for(i=0; i<n; i++){
     34 		s = [file objectAtIndex:i];
     35 		print("%s\n", [s UTF8String]);
     36 	}
     37 	[NSApp terminate:self];
     38 }
     39 
     40 - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
     41 {
     42 	NSString* url = [[event descriptorForKeyword:keyDirectObject] stringValue];
     43 	print("%s\n", [url UTF8String] + (sizeof("plumb:") - 1));
     44 	[NSApp terminate:self];
     45 }
     46 @end