[Python-checkins] python/dist/src/Mac/OSX/PythonLauncher FileSettings.h,1.3,1.4 FileSettings.m,1.5,1.6 MyDocument.h,1.1,1.2 MyDocument.m,1.3,1.4 PreferencesWindowController.h,1.2,1.3 PreferencesWindowController.m,1.3,1.4 factorySettings.plist,1.2,1.3

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Mon, 17 Feb 2003 07:40:03 -0800


Update of /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher
In directory sc8-pr-cvs1:/tmp/cvs-serv21319/PythonLauncher

Modified Files:
	FileSettings.h FileSettings.m MyDocument.h MyDocument.m 
	PreferencesWindowController.h PreferencesWindowController.m 
	factorySettings.plist 
Log Message:
Optionally honour #! paths in scripts. Fixes #676358.


Index: FileSettings.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/FileSettings.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FileSettings.h	26 Dec 2002 22:10:53 -0000	1.3
--- FileSettings.h	17 Feb 2003 15:39:59 -0000	1.4
***************
*** 11,14 ****
--- 11,15 ----
  @protocol FileSettingsSource
  - (NSString *) interpreter;
+ - (BOOL) honourhashbang;
  - (BOOL) debug;
  - (BOOL) verbose;
***************
*** 25,28 ****
--- 26,30 ----
      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

Index: FileSettings.m
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/FileSettings.m,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** FileSettings.m	26 Dec 2002 22:10:53 -0000	1.5
--- FileSettings.m	17 Feb 2003 15:39:59 -0000	1.6
***************
*** 70,73 ****
--- 70,74 ----
      
      interpreter = [source->interpreter retain];
+     honourhashbang = source->honourhashbang;
      debug = source->debug;
      verbose = source->verbose;
***************
*** 183,186 ****
--- 184,188 ----
  {
      interpreter = [[source interpreter] retain];
+     honourhashbang = [source honourhashbang];
      debug = [source debug];
      verbose = [source verbose];
***************
*** 197,200 ****
--- 199,203 ----
          NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
              interpreter, @"interpreter",
+             [NSNumber numberWithBool: honourhashbang], @"honourhashbang",
              [NSNumber numberWithBool: debug], @"debug",
              [NSNumber numberWithBool: verbose], @"verbose",
***************
*** 217,220 ****
--- 220,225 ----
      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];
***************
*** 237,243 ****
  - (NSString *)commandLineForScript: (NSString *)script
  {
      return [NSString stringWithFormat:
          @"\"%@\"%s%s%s%s%s%s %@ \"%@\" %s",
!         interpreter,
          debug?" -d":"",
          verbose?" -v":"",
--- 242,266 ----
  - (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",
!         cur_interp,
          debug?" -d":"",
          verbose?" -v":"",
***************
*** 255,258 ****
--- 278,282 ----
  // FileSettingsSource protocol 
  - (NSString *) interpreter { return interpreter;};
+ - (BOOL) honourhashbang { return honourhashbang; };
  - (BOOL) debug { return debug;};
  - (BOOL) verbose { return verbose;};

Index: MyDocument.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/MyDocument.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MyDocument.h	29 Jul 2002 21:36:35 -0000	1.1
--- MyDocument.h	17 Feb 2003 15:39:59 -0000	1.2
***************
*** 15,18 ****
--- 15,19 ----
  {
      IBOutlet NSTextField *interpreter;
+     IBOutlet NSButton *honourhashbang;
      IBOutlet NSButton *debug;
      IBOutlet NSButton *verbose;

Index: MyDocument.m
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/MyDocument.m,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MyDocument.m	25 Nov 2002 13:11:05 -0000	1.3
--- MyDocument.m	17 Feb 2003 15:39:59 -0000	1.4
***************
*** 53,56 ****
--- 53,57 ----
      
      [interpreter setStringValue: [settings interpreter]];
+     [honourhashbang setState: [settings honourhashbang]];
      [debug setState: [settings debug]];
      [verbose setState: [settings verbose]];
***************
*** 153,156 ****
--- 154,158 ----
  // FileSettingsSource protocol 
  - (NSString *) interpreter { return [interpreter stringValue];};
+ - (BOOL) honourhashbang { return [honourhashbang state];};
  - (BOOL) debug { return [debug state];};
  - (BOOL) verbose { return [verbose state];};

Index: PreferencesWindowController.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/PreferencesWindowController.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PreferencesWindowController.h	26 Dec 2002 22:10:53 -0000	1.2
--- PreferencesWindowController.h	17 Feb 2003 15:39:59 -0000	1.3
***************
*** 9,12 ****
--- 9,13 ----
      IBOutlet NSPopUpButton *filetype;
      IBOutlet NSTextField *interpreter;
+     IBOutlet NSButton *honourhashbang;
      IBOutlet NSButton *debug;
      IBOutlet NSButton *verbose;

Index: PreferencesWindowController.m
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/PreferencesWindowController.m,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PreferencesWindowController.m	26 Dec 2002 22:10:53 -0000	1.3
--- PreferencesWindowController.m	17 Feb 2003 15:39:59 -0000	1.4
***************
*** 31,34 ****
--- 31,35 ----
      
      [interpreter setStringValue: [settings interpreter]];
+     [honourhashbang setState: [settings honourhashbang]];
      [debug setState: [settings debug]];
      [verbose setState: [settings verbose]];
***************
*** 75,78 ****
--- 76,80 ----
  // FileSettingsSource protocol 
  - (NSString *) interpreter { return [interpreter stringValue];};
+ - (BOOL) honourhashbang { return [honourhashbang state]; };
  - (BOOL) debug { return [debug state];};
  - (BOOL) verbose { return [verbose state];};

Index: factorySettings.plist
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/OSX/PythonLauncher/factorySettings.plist,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** factorySettings.plist	26 Dec 2002 22:10:53 -0000	1.2
--- factorySettings.plist	17 Feb 2003 15:40:00 -0000	1.3
***************
*** 17,20 ****
--- 17,22 ----
                      <string>/Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python</string>
                  </array>
+                 <key>honourhashbang</key>
+                 <false/>
                  <key>nosite</key>
                  <false/>
***************
*** 46,50 ****
                      <string>/Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python</string>
                  </array>
!                 <key>nosite</key>
                  <false/>
                  <key>optimize</key>
--- 48,54 ----
                      <string>/Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python</string>
                  </array>
!                 <key>honourhashbang</key>
!                 <false/>
!                  <key>nosite</key>
                  <false/>
                  <key>optimize</key>
***************
*** 70,74 ****
                      <string>/usr/bin/python</string>
                  </array>
!                 <key>nosite</key>
                  <false/>
                  <key>optimize</key>
--- 74,80 ----
                      <string>/usr/bin/python</string>
                  </array>
!                 <key>honourhashbang</key>
!                 <false/>
!                  <key>nosite</key>
                  <false/>
                  <key>optimize</key>