3 #include <Carbon/Carbon.h>
7 static OSErr Handler(const AppleEvent *event, AppleEvent *reply, long handlerRefcon);
12 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, Handler, 0, false);
13 RunApplicationEventLoop();
18 GetFullPathname(FSSpec *fss, char *path, int len)
24 err = FSpMakeFSRef(fss, &fsr);
26 /* FSSpecs can point to non-existing files, fsrefs can't. */
30 err = FSMakeFSSpec(fss->vRefNum, fss->parID,
31 (unsigned char*)"", &fss2);
34 err = FSpMakeFSRef(&fss2, &fsr);
37 err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len-1);
40 /* This part is not 100% safe: we append the filename part, but
41 ** I'm not sure that we don't run afoul of the various 8bit
42 ** encodings here. Will have to look this up at some point...
45 tocopy = fss->name[0];
46 if ((strlen(path) + tocopy) >= len)
47 tocopy = len - strlen(path) - 1;
49 strncat(path, (char*)fss->name+1, tocopy);
54 err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len);
65 printf("err %d\n", err);
71 Handler(const AppleEvent *event, AppleEvent *reply, long handlerRefcon)
81 chk(AEGetParamDesc(event, keyDirectObject, typeAEList, &list));
82 chk(AECountItems(&list, &len));
83 chk(AEGetNthPtr(&list, 1, typeFSS, &keyword, &type, (Ptr*)&f, sizeof(FSSpec), &actual));
84 chk(GetFullPathname(&f, s, sizeof s));
88 // uncomment to keep handling more open events