From 3d3b74677a440b00d94b6b4e71e7f2f97800c427 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Mon, 17 Feb 2003 15:40:00 +0000 Subject: Optionally honour #! paths in scripts. Fixes #676358. --- .../English.lproj/MyDocument.nib/classes.nib | 5 ++-- .../English.lproj/MyDocument.nib/info.nib | 10 ++++---- .../English.lproj/MyDocument.nib/objects.nib | Bin 4174 -> 4441 bytes Mac/OSX/PythonLauncher/FileSettings.h | 2 ++ Mac/OSX/PythonLauncher/FileSettings.m | 26 ++++++++++++++++++++- Mac/OSX/PythonLauncher/MyDocument.h | 1 + Mac/OSX/PythonLauncher/MyDocument.m | 2 ++ .../PreferenceWindow.nib/classes.nib | 1 + .../PythonLauncher/PreferenceWindow.nib/info.nib | 6 ++--- .../PreferenceWindow.nib/objects.nib | Bin 7678 -> 7874 bytes .../PythonLauncher/PreferencesWindowController.h | 1 + .../PythonLauncher/PreferencesWindowController.m | 2 ++ .../PythonLauncher.pbproj/project.pbxproj | 2 +- Mac/OSX/PythonLauncher/factorySettings.plist | 10 ++++++-- 14 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib index 7c58149..7778ff0 100644 --- a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib +++ b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib @@ -2,12 +2,13 @@ IBClasses = ( {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, { - ACTIONS = {do_apply = id; do_cancel = id; do_reset = id; do_run = id; }; + ACTIONS = {"do_apply" = id; "do_cancel" = id; "do_reset" = id; "do_run" = id; }; CLASS = MyDocument; LANGUAGE = ObjC; OUTLETS = { commandline = NSTextField; debug = NSButton; + honourhashbang = NSButton; inspect = NSButton; interpreter = NSTextField; nosite = NSButton; @@ -15,7 +16,7 @@ others = NSTextField; tabs = NSButton; verbose = NSButton; - with_terminal = NSButton; + "with_terminal" = NSButton; }; SUPERCLASS = NSDocument; } diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib index c767646..0630cb9 100644 --- a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib +++ b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib @@ -1,16 +1,16 @@ - - + + IBDocumentLocation - 265 40 356 240 0 0 800 578 + 551 90 356 240 0 0 1280 1002 IBFramework Version - 263.2 + 286.0 IBOpenObjects 5 IBSystem Version - 5S66 + 6I32 diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib index 33521ad..97eb230 100644 Binary files a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib and b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib differ diff --git a/Mac/OSX/PythonLauncher/FileSettings.h b/Mac/OSX/PythonLauncher/FileSettings.h index 80c11f1..f70b05f 100755 --- a/Mac/OSX/PythonLauncher/FileSettings.h +++ b/Mac/OSX/PythonLauncher/FileSettings.h @@ -10,6 +10,7 @@ @protocol FileSettingsSource - (NSString *) interpreter; +- (BOOL) honourhashbang; - (BOOL) debug; - (BOOL) verbose; - (BOOL) inspect; @@ -24,6 +25,7 @@ { NSString *interpreter; // The pathname of the interpreter to use NSArray *interpreters; // List of known interpreters + BOOL honourhashbang; // #! line overrides interpreter BOOL debug; // -d option: debug parser BOOL verbose; // -v option: verbose import BOOL inspect; // -i option: interactive mode after script diff --git a/Mac/OSX/PythonLauncher/FileSettings.m b/Mac/OSX/PythonLauncher/FileSettings.m index b2961d2..7b28daa 100755 --- a/Mac/OSX/PythonLauncher/FileSettings.m +++ b/Mac/OSX/PythonLauncher/FileSettings.m @@ -69,6 +69,7 @@ if (!self) return self; interpreter = [source->interpreter retain]; + honourhashbang = source->honourhashbang; debug = source->debug; verbose = source->verbose; inspect = source->inspect; @@ -182,6 +183,7 @@ - (void)updateFromSource: (id )source { interpreter = [[source interpreter] retain]; + honourhashbang = [source honourhashbang]; debug = [source debug]; verbose = [source verbose]; inspect = [source inspect]; @@ -196,6 +198,7 @@ NSUserDefaults *defaults; NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: interpreter, @"interpreter", + [NSNumber numberWithBool: honourhashbang], @"honourhashbang", [NSNumber numberWithBool: debug], @"debug", [NSNumber numberWithBool: verbose], @"verbose", [NSNumber numberWithBool: inspect], @"inspect", @@ -216,6 +219,8 @@ value = [dict objectForKey: @"interpreter"]; if (value) interpreter = [value retain]; + value = [dict objectForKey: @"honourhashbang"]; + if (value) honourhashbang = [value boolValue]; value = [dict objectForKey: @"debug"]; if (value) debug = [value boolValue]; value = [dict objectForKey: @"verbose"]; @@ -236,9 +241,27 @@ - (NSString *)commandLineForScript: (NSString *)script { + NSString *cur_interp = NULL; + char hashbangbuf[1024]; + FILE *fp; + char *p; + + if (honourhashbang && + (fp=fopen([script cString], "r")) && + fgets(hashbangbuf, sizeof(hashbangbuf), fp) && + strncmp(hashbangbuf, "#!", 2) == 0 && + (p=strchr(hashbangbuf, '\n'))) { + *p = '\0'; + p = hashbangbuf + 2; + while (*p == ' ') p++; + cur_interp = [NSString stringWithCString: p]; + } + if (!cur_interp) + cur_interp = interpreter; + return [NSString stringWithFormat: @"\"%@\"%s%s%s%s%s%s %@ \"%@\" %s", - interpreter, + cur_interp, debug?" -d":"", verbose?" -v":"", inspect?" -i":"", @@ -254,6 +277,7 @@ // FileSettingsSource protocol - (NSString *) interpreter { return interpreter;}; +- (BOOL) honourhashbang { return honourhashbang; }; - (BOOL) debug { return debug;}; - (BOOL) verbose { return verbose;}; - (BOOL) inspect { return inspect;}; diff --git a/Mac/OSX/PythonLauncher/MyDocument.h b/Mac/OSX/PythonLauncher/MyDocument.h index 47c7be38..dd2b4fe 100755 --- a/Mac/OSX/PythonLauncher/MyDocument.h +++ b/Mac/OSX/PythonLauncher/MyDocument.h @@ -14,6 +14,7 @@ @interface MyDocument : NSDocument { IBOutlet NSTextField *interpreter; + IBOutlet NSButton *honourhashbang; IBOutlet NSButton *debug; IBOutlet NSButton *verbose; IBOutlet NSButton *inspect; diff --git a/Mac/OSX/PythonLauncher/MyDocument.m b/Mac/OSX/PythonLauncher/MyDocument.m index fdcf86a..09a0024 100755 --- a/Mac/OSX/PythonLauncher/MyDocument.m +++ b/Mac/OSX/PythonLauncher/MyDocument.m @@ -52,6 +52,7 @@ // [[self window] setTitle: script]; [interpreter setStringValue: [settings interpreter]]; + [honourhashbang setState: [settings honourhashbang]]; [debug setState: [settings debug]]; [verbose setState: [settings verbose]]; [inspect setState: [settings inspect]]; @@ -152,6 +153,7 @@ // FileSettingsSource protocol - (NSString *) interpreter { return [interpreter stringValue];}; +- (BOOL) honourhashbang { return [honourhashbang state];}; - (BOOL) debug { return [debug state];}; - (BOOL) verbose { return [verbose state];}; - (BOOL) inspect { return [inspect state];}; diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib index 43a1936..467aa8b 100644 --- a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib +++ b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib @@ -9,6 +9,7 @@ commandline = NSTextField; debug = NSButton; filetype = NSPopUpButton; + honourhashbang = NSButton; inspect = NSButton; interpreter = NSTextField; nosite = NSButton; diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib index f5b17b6..e4c54c1 100644 --- a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib +++ b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib @@ -3,14 +3,14 @@ IBDocumentLocation - 126 59 356 240 0 0 1024 746 + 660 84 519 534 0 0 1280 1002 IBFramework Version - 291.0 + 286.0 IBOpenObjects 5 IBSystem Version - 6G30 + 6I32 diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib index f220e5c..12539d0 100644 Binary files a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib and b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib differ diff --git a/Mac/OSX/PythonLauncher/PreferencesWindowController.h b/Mac/OSX/PythonLauncher/PreferencesWindowController.h index 57821c5..63c1836 100644 --- a/Mac/OSX/PythonLauncher/PreferencesWindowController.h +++ b/Mac/OSX/PythonLauncher/PreferencesWindowController.h @@ -8,6 +8,7 @@ { IBOutlet NSPopUpButton *filetype; IBOutlet NSTextField *interpreter; + IBOutlet NSButton *honourhashbang; IBOutlet NSButton *debug; IBOutlet NSButton *verbose; IBOutlet NSButton *inspect; diff --git a/Mac/OSX/PythonLauncher/PreferencesWindowController.m b/Mac/OSX/PythonLauncher/PreferencesWindowController.m index e7ddfdd..fd65194 100644 --- a/Mac/OSX/PythonLauncher/PreferencesWindowController.m +++ b/Mac/OSX/PythonLauncher/PreferencesWindowController.m @@ -30,6 +30,7 @@ // [[self window] setTitle: script]; [interpreter setStringValue: [settings interpreter]]; + [honourhashbang setState: [settings honourhashbang]]; [debug setState: [settings debug]]; [verbose setState: [settings verbose]]; [inspect setState: [settings inspect]]; @@ -74,6 +75,7 @@ // FileSettingsSource protocol - (NSString *) interpreter { return [interpreter stringValue];}; +- (BOOL) honourhashbang { return [honourhashbang state]; }; - (BOOL) debug { return [debug state];}; - (BOOL) verbose { return [verbose state];}; - (BOOL) inspect { return [inspect state];}; diff --git a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj index 2cfdaf1..5b4a06c 100755 --- a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj +++ b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj @@ -132,7 +132,6 @@ 4A9504D0FFE6A4CB11CA0CBA, 4A9504D1FFE6A4CB11CA0CBA, ); - hasScannedForEncodings = 1; isa = PBXProject; mainGroup = 2A37F4AAFDCFA73011CA2CEA; projectDirPath = ""; @@ -404,6 +403,7 @@ "; + shouldUseHeadermap = 0; }; 2A37F4C7FDCFA73011CA2CEA = { buildActionMask = 2147483647; diff --git a/Mac/OSX/PythonLauncher/factorySettings.plist b/Mac/OSX/PythonLauncher/factorySettings.plist index 46092b5..1d8d039 100644 --- a/Mac/OSX/PythonLauncher/factorySettings.plist +++ b/Mac/OSX/PythonLauncher/factorySettings.plist @@ -16,6 +16,8 @@ /usr/bin/pythonw /Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python + honourhashbang + nosite optimize @@ -45,7 +47,9 @@ /usr/bin/pythonw /Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python - nosite + honourhashbang + + nosite optimize @@ -69,7 +73,9 @@ /Library/Frameworks/Python.framework/Versions/Current/bin/python /usr/bin/python - nosite + honourhashbang + + nosite optimize -- cgit v0.12