summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-07-31 13:15:59 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-07-31 13:15:59 (GMT)
commitb7276cdf71d807f4ccdb8b52a309b2b943e31bab (patch)
tree3fcfd48d23b92cc420e11fa8cc65d430e92ce486
parent33876f514a2ed2311cf94adb6f4bdb0db9fa6bdd (diff)
downloadcpython-b7276cdf71d807f4ccdb8b52a309b2b943e31bab.zip
cpython-b7276cdf71d807f4ccdb8b52a309b2b943e31bab.tar.gz
cpython-b7276cdf71d807f4ccdb8b52a309b2b943e31bab.tar.bz2
Implemented starting Python in a terminal window. The implementation isn't
optimal, especially if Terminal wasn't running yet, but it works.
-rwxr-xr-xMac/OSX/PythonLauncher/FileSettings.m2
-rwxr-xr-xMac/OSX/PythonLauncher/MyDocument.m11
-rwxr-xr-xMac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj40
-rw-r--r--Mac/OSX/PythonLauncher/doscript.h12
-rw-r--r--Mac/OSX/PythonLauncher/doscript.m118
5 files changed, 177 insertions, 6 deletions
diff --git a/Mac/OSX/PythonLauncher/FileSettings.m b/Mac/OSX/PythonLauncher/FileSettings.m
index 99a1166..b3fc25a 100755
--- a/Mac/OSX/PythonLauncher/FileSettings.m
+++ b/Mac/OSX/PythonLauncher/FileSettings.m
@@ -165,7 +165,7 @@
tabs?" -t":"",
others,
script,
- with_terminal? "" : " &"];
+ with_terminal? "&& exit" : " &"];
}
// FileSettingsSource protocol
diff --git a/Mac/OSX/PythonLauncher/MyDocument.m b/Mac/OSX/PythonLauncher/MyDocument.m
index a4c20d1..2571857 100755
--- a/Mac/OSX/PythonLauncher/MyDocument.m
+++ b/Mac/OSX/PythonLauncher/MyDocument.m
@@ -8,6 +8,7 @@
#import "MyDocument.h"
#import "MyAppDelegate.h"
+#import "doscript.h"
@implementation MyDocument
@@ -71,12 +72,12 @@
const char *cmdline;
int sts;
- if ([settings with_terminal]) {
- NSLog(@"Terminal not implemented yet\n");
- return NO;
+ cmdline = [[settings commandLineForScript: script] cString];
+ if ([settings with_terminal]) {
+ sts = doscript(cmdline);
+ } else {
+ sts = system(cmdline);
}
- cmdline = [[settings commandLineForScript: script] cString];
- sts = system(cmdline);
if (sts) {
NSLog(@"Exit status: %d\n", sts);
return NO;
diff --git a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
index 849aeb3..607e8ee 100755
--- a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
+++ b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
@@ -57,6 +57,7 @@
1058C7A6FEA54F5311CA2CBB = {
children = (
1058C7A7FEA54F5311CA2CBB,
+ F5AA9D0102F807EE0110C447,
);
isa = PBXGroup;
name = "Linked Frameworks";
@@ -179,7 +180,9 @@
};
2A37F4AFFDCFA73011CA2CEA = {
children = (
+ F5AA9C6A02F8042D0110C447,
2A37F4B0FDCFA73011CA2CEA,
+ F5AAA21D02F8115D0110C447,
);
isa = PBXGroup;
name = "Other Sources";
@@ -401,6 +404,7 @@
F52A90D002EB5C6A01000102,
F5A4C14202F2055D01000102,
F5A4C14702F2070D01000102,
+ F5AA9C6C02F8042D0110C447,
);
isa = PBXHeadersBuildPhase;
};
@@ -432,6 +436,7 @@
F52A90CF02EB5C6A01000102,
F5A4C14302F2055D01000102,
F5A4C14602F2070D01000102,
+ F5AAA21E02F8115D0110C447,
);
isa = PBXSourcesBuildPhase;
};
@@ -455,6 +460,7 @@
buildActionMask = 2147483647;
files = (
1058C7A9FEA54F5311CA2CBB,
+ F5AA9D9B02F807EF0110C447,
);
isa = PBXFrameworksBuildPhase;
};
@@ -607,6 +613,40 @@
settings = {
};
};
+ F5AA9C6A02F8042D0110C447 = {
+ isa = PBXFileReference;
+ path = doscript.h;
+ refType = 4;
+ };
+ F5AA9C6C02F8042D0110C447 = {
+ fileRef = F5AA9C6A02F8042D0110C447;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ F5AA9D0102F807EE0110C447 = {
+ isa = PBXFrameworkReference;
+ name = Carbon.framework;
+ path = /System/Library/Frameworks/Carbon.framework;
+ refType = 0;
+ };
+ F5AA9D9B02F807EF0110C447 = {
+ fileRef = F5AA9D0102F807EE0110C447;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ F5AAA21D02F8115D0110C447 = {
+ isa = PBXFileReference;
+ path = doscript.m;
+ refType = 4;
+ };
+ F5AAA21E02F8115D0110C447 = {
+ fileRef = F5AAA21D02F8115D0110C447;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
};
rootObject = 2A37F4A9FDCFA73011CA2CEA;
}
diff --git a/Mac/OSX/PythonLauncher/doscript.h b/Mac/OSX/PythonLauncher/doscript.h
new file mode 100644
index 0000000..eef0b56
--- /dev/null
+++ b/Mac/OSX/PythonLauncher/doscript.h
@@ -0,0 +1,12 @@
+/*
+ * doscript.h
+ * PythonLauncher
+ *
+ * Created by Jack Jansen on Wed Jul 31 2002.
+ * Copyright (c) 2002 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <Carbon/Carbon.h>
+
+extern int doscript(const char *command); \ No newline at end of file
diff --git a/Mac/OSX/PythonLauncher/doscript.m b/Mac/OSX/PythonLauncher/doscript.m
new file mode 100644
index 0000000..c2c5886
--- /dev/null
+++ b/Mac/OSX/PythonLauncher/doscript.m
@@ -0,0 +1,118 @@
+/*
+ * doscript.c
+ * PythonLauncher
+ *
+ * Created by Jack Jansen on Wed Jul 31 2002.
+ * Copyright (c) 2002 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import "doscript.h"
+
+/* I assume I could pick these up from somewhere, but where... */
+#define CREATOR 'trmx'
+
+#define ACTIVATE_CMD 'misc'
+#define ACTIVATE_SUITE 'actv'
+
+#define DOSCRIPT_CMD 'dosc'
+#define DOSCRIPT_SUITE 'core'
+#define WITHCOMMAND 'cmnd'
+
+/* ... and there's probably also a better way to do this... */
+#define START_TERMINAL "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal &"
+
+extern int
+doscript(const char *command)
+{
+ OSErr err;
+ AppleEvent theAEvent, theReply;
+ AEAddressDesc terminalAddress;
+ AEDesc commandDesc;
+ OSType terminalCreator = CREATOR;
+
+ /* set up locals */
+ AECreateDesc(typeNull, NULL, 0, &theAEvent);
+ AECreateDesc(typeNull, NULL, 0, &terminalAddress);
+ AECreateDesc(typeNull, NULL, 0, &theReply);
+ AECreateDesc(typeNull, NULL, 0, &commandDesc);
+
+ /* create the "activate" event for Terminal */
+ err = AECreateDesc(typeApplSignature, (Ptr) &terminalCreator,
+ sizeof(terminalCreator), &terminalAddress);
+ if (err != noErr) {
+ NSLog(@"doscript: AECreateDesc: error %d\n", err);
+ goto bail;
+ }
+ err = AECreateAppleEvent(ACTIVATE_SUITE, ACTIVATE_CMD,
+ &terminalAddress, kAutoGenerateReturnID,
+ kAnyTransactionID, &theAEvent);
+
+ if (err != noErr) {
+ NSLog(@"doscript: AECreateAppleEvent(activate): error %d\n", err);
+ goto bail;
+ }
+ /* send the event */
+ err = AESend(&theAEvent, &theReply, kAEWaitReply,
+ kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
+ if ( err == -600 ) {
+ int count=10;
+ /* If it failed with "no such process" try to start Terminal */
+ err = system(START_TERMINAL);
+ if ( err ) {
+ NSLog(@"doscript: system(): %s\n", strerror(errno));
+ goto bail;
+ }
+ do {
+ sleep(1);
+ /* send the event again */
+ err = AESend(&theAEvent, &theReply, kAEWaitReply,
+ kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
+ } while (err == -600 && --count > 0);
+ if ( err == -600 )
+ NSLog(@"doscript: Could not activate Terminal\n");
+ }
+ if (err != noErr) {
+ NSLog(@"doscript: AESend(activate): error %d\n", err);
+ goto bail;
+ }
+
+ /* create the "doscript with command" event for Terminal */
+ err = AECreateAppleEvent(DOSCRIPT_SUITE, DOSCRIPT_CMD,
+ &terminalAddress, kAutoGenerateReturnID,
+ kAnyTransactionID, &theAEvent);
+ if (err != noErr) {
+ NSLog(@"doscript: AECreateAppleEvent(doscript): error %d\n", err);
+ goto bail;
+ }
+
+ /* add the command to the apple event */
+ err = AECreateDesc(typeChar, command, strlen(command), &commandDesc);
+ if (err != noErr) {
+ NSLog(@"doscript: AECreateDesc(command): error %d\n", err);
+ goto bail;
+ }
+ err = AEPutParamDesc(&theAEvent, WITHCOMMAND, &commandDesc);
+ if (err != noErr) {
+ NSLog(@"doscript: AEPutParamDesc: error %d\n", err);
+ goto bail;
+ }
+
+ /* send the event to the Finder */
+ err = AESend(&theAEvent, &theReply, kAEWaitReply,
+ kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
+
+ if (err != noErr) {
+ NSLog(@"doscript: AESend(docommand): error %d\n", err);
+ goto bail;
+ }
+ /* clean up and leave */
+bail:
+ AEDisposeDesc(&commandDesc);
+ AEDisposeDesc(&theAEvent);
+ AEDisposeDesc(&terminalAddress);
+ AEDisposeDesc(&theReply);
+ return err;
+} \ No newline at end of file