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