aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/devdraw/macargv.c90
-rw-r--r--src/cmd/devdraw/mkfile5
-rw-r--r--src/cmd/devdraw/mkwsysrules.sh1
-rw-r--r--src/cmd/rio/mkfile3
4 files changed, 99 insertions, 0 deletions
diff --git a/src/cmd/devdraw/macargv.c b/src/cmd/devdraw/macargv.c
new file mode 100644
index 00000000..a5ea1ade
--- /dev/null
+++ b/src/cmd/devdraw/macargv.c
@@ -0,0 +1,90 @@
+#include <u.h>
+#include <stdio.h>
+#include <Carbon/Carbon.h>
+
+AUTOFRAMEWORK(Carbon)
+
+static OSErr Handler(const AppleEvent *event, AppleEvent *reply, long handlerRefcon);
+
+int
+main(void)
+{
+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, Handler, 0, false);
+ RunApplicationEventLoop();
+ return 0;
+}
+
+static OSErr
+GetFullPathname(FSSpec *fss, char *path, int len)
+{
+ FSRef fsr;
+ OSErr err;
+
+ *path = '\0';
+ err = FSpMakeFSRef(fss, &fsr);
+ if (err == fnfErr) {
+ /* FSSpecs can point to non-existing files, fsrefs can't. */
+ FSSpec fss2;
+ int tocopy;
+
+ err = FSMakeFSSpec(fss->vRefNum, fss->parID,
+ (unsigned char*)"", &fss2);
+ if (err)
+ return err;
+ err = FSpMakeFSRef(&fss2, &fsr);
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len-1);
+ if (err)
+ return err;
+ /* This part is not 100% safe: we append the filename part, but
+ ** I'm not sure that we don't run afoul of the various 8bit
+ ** encodings here. Will have to look this up at some point...
+ */
+ strcat(path, "/");
+ tocopy = fss->name[0];
+ if ((strlen(path) + tocopy) >= len)
+ tocopy = len - strlen(path) - 1;
+ if (tocopy > 0)
+ strncat(path, (char*)fss->name+1, tocopy);
+ }
+ else {
+ if (err)
+ return err;
+ err = (OSErr)FSRefMakePath(&fsr, (unsigned char*)path, len);
+ if (err)
+ return err;
+ }
+ return 0;
+}
+
+static void
+chk(int err)
+{
+ if(err != 0) {
+ printf("err %d\n", err);
+ exit(1);
+ }
+}
+
+static OSErr
+Handler(const AppleEvent *event, AppleEvent *reply, long handlerRefcon)
+{
+ AEDesc list;
+ DescType type;
+ FSSpec f;
+ AEKeyword keyword;
+ Size actual;
+ long len;
+ char s[1000];
+
+ chk(AEGetParamDesc(event, keyDirectObject, typeAEList, &list));
+ chk(AECountItems(&list, &len));
+ chk(AEGetNthPtr(&list, 1, typeFSS, &keyword, &type, (Ptr*)&f, sizeof(FSSpec), &actual));
+ chk(GetFullPathname(&f, s, sizeof s));
+ printf("%s\n", s);
+ fflush(stdout);
+
+ // uncomment to keep handling more open events
+ exit(0);
+}
diff --git a/src/cmd/devdraw/mkfile b/src/cmd/devdraw/mkfile
index eda896d9..67a865c0 100644
--- a/src/cmd/devdraw/mkfile
+++ b/src/cmd/devdraw/mkfile
@@ -41,3 +41,8 @@ CLEANFILES=latin1.h $O.mklatinkbd
devdraw-cocoa: devdraw.o latin1.o mouseswap.o winsize.o osx-screen-objc.o osx-draw.o osx-srv-objc.o osx-delegate-objc.o
$LD -o $target $prereq
+install-macargv: $O.macargv
+ install $O.macargv $PLAN9/bin/macargv
+
+$O.macargv: macargv.$O
+ $LD -o $target $prereq
diff --git a/src/cmd/devdraw/mkwsysrules.sh b/src/cmd/devdraw/mkwsysrules.sh
index 5e65a29c..788a0e61 100644
--- a/src/cmd/devdraw/mkwsysrules.sh
+++ b/src/cmd/devdraw/mkwsysrules.sh
@@ -52,6 +52,7 @@ elif [ $WSYSTYPE = osx ]; then
echo 'LDFLAGS=$LDFLAGS -F/System/Library/PrivateFrameworks'
fi
echo 'WSYSOFILES=$WSYSOFILES osx-screen-carbon-objc.o osx-draw.o osx-srv.o'
+ echo 'install: install-macargv'
elif [ $WSYSTYPE = nowsys ]; then
echo 'WSYSOFILES=nowsys.o'
fi
diff --git a/src/cmd/rio/mkfile b/src/cmd/rio/mkfile
index e5426865..ec8710eb 100644
--- a/src/cmd/rio/mkfile
+++ b/src/cmd/rio/mkfile
@@ -41,3 +41,6 @@ error.$O: showevent/ShowEvent.c
$O.xshove: xshove.$O
$LD -o $O.xshove xshove.$O -lX11
+# bug in reusing mksysrules.sh
+install-macargv:
+ true