]> granicus.if.org Git - python/commitdiff
Issue #18377: Code cleanup in Python Launcher
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 7 Jul 2013 07:53:08 +0000 (09:53 +0200)
committerRonald Oussoren <ronaldoussoren@mac.com>
Sun, 7 Jul 2013 07:53:08 +0000 (09:53 +0200)
This changeset fixes a number of compiler warnings in the Python Launcher
binary for OSX. It also cleans up whitespace usage in those sources.

Mac/PythonLauncher/FileSettings.h
Mac/PythonLauncher/FileSettings.m
Mac/PythonLauncher/MyAppDelegate.m
Mac/PythonLauncher/MyDocument.m
Mac/PythonLauncher/PreferencesWindowController.m
Mac/PythonLauncher/doscript.h
Mac/PythonLauncher/doscript.m
Mac/PythonLauncher/main.m

index d807bae59cc30ddc38fc9a2cfdda9a19ad5ff662..7b74a9b24d2dd07fb5ca059593a40a08a57e7545 100755 (executable)
 + (id)getFactorySettingsForFileType: (NSString *)filetype;
 + (id)newSettingsForFileType: (NSString *)filetype;
 
-//- (id)init;
 - (id)initForFileType: (NSString *)filetype;
 - (id)initForFSDefaultFileType: (NSString *)filetype;
 - (id)initForDefaultFileType: (NSString *)filetype;
-//- (id)initWithFileSettings: (FileSettings *)source;
 
 - (void)updateFromSource: (id <FileSettingsSource>)source;
 - (NSString *)commandLineForScript: (NSString *)script;
 
-//- (void)applyFactorySettingsForFileType: (NSString *)filetype;
-//- (void)saveDefaults;
-//- (void)applyUserDefaults: (NSString *)filetype;
 - (void)applyValuesFromDict: (NSDictionary *)dict;
 - (void)reset;
 - (NSArray *) interpreters;
index 66b4fdc0866355d42d2b46ca181472ffcb19f704..3438870b7484c48218dcf5083b350ae93ed637fb 100755 (executable)
@@ -14,7 +14,7 @@
 {
     static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
     FileSettings **curdefault;
-    
+
     if ([filetype isEqualToString: @"Python Script"]) {
         curdefault = &fsdefault_py;
     } else if ([filetype isEqualToString: @"Python GUI Script"]) {
@@ -36,7 +36,7 @@
 {
     static FileSettings *default_py, *default_pyw, *default_pyc;
     FileSettings **curdefault;
-    
+
     if ([filetype isEqualToString: @"Python Script"]) {
         curdefault = &default_py;
     } else if ([filetype isEqualToString: @"Python GUI Script"]) {
@@ -57,7 +57,7 @@
 + (id)newSettingsForFileType: (NSString *)filetype
 {
     FileSettings *cur;
-    
+
     cur = [FileSettings new];
     [cur initForFileType: filetype];
     return [cur retain];
@@ -67,7 +67,7 @@
 {
     self = [super init];
     if (!self) return self;
-    
+
     interpreter = [source->interpreter retain];
     honourhashbang = source->honourhashbang;
     debug = source->debug;
     with_terminal = source->with_terminal;
     prefskey = source->prefskey;
     if (prefskey) [prefskey retain];
-    
+
     return self;
 }
 
 - (id)initForFileType: (NSString *)filetype
 {
     FileSettings *defaults;
-    
+
     defaults = [FileSettings getDefaultsForFileType: filetype];
     self = [self initWithFileSettings: defaults];
     origsource = [defaults retain];
     return self;
 }
 
-//- (id)init
-//{
-//    self = [self initForFileType: @"Python Script"];
-//    return self;
-//}
-
 - (id)initForFSDefaultFileType: (NSString *)filetype
 {
     int i;
     NSString *filename;
     NSDictionary *dict;
     static NSDictionary *factorySettings;
-    
+
     self = [super init];
     if (!self) return self;
-    
+
     if (factorySettings == NULL) {
         NSBundle *bdl = [NSBundle mainBundle];
         NSString *path = [ bdl pathForResource: @"factorySettings"
 {
     NSUserDefaults *defaults;
     NSDictionary *dict;
-    
+
     defaults = [NSUserDefaults standardUserDefaults];
     dict = [defaults dictionaryForKey: filetype];
     if (!dict)
         return;
     [self applyValuesFromDict: dict];
 }
-    
+
 - (id)initForDefaultFileType: (NSString *)filetype
 {
     FileSettings *fsdefaults;
-    
+
     fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
     self = [self initWithFileSettings: fsdefaults];
     if (!self) return self;
 - (void)applyValuesFromDict: (NSDictionary *)dict
 {
     id value;
-    
+
     value = [dict objectForKey: @"interpreter"];
     if (value) interpreter = [value retain];
     value = [dict objectForKey: @"honourhashbang"];
 
 - (NSString*)_replaceSingleQuotes: (NSString*)string
 {
-       /* Replace all single-quotes by '"'"', that way shellquoting will
-        * be correct when the result value is delimited  using single quotes.
-        */
-       NSArray* components = [string componentsSeparatedByString:@"'"];
+    /* Replace all single-quotes by '"'"', that way shellquoting will
+     * be correct when the result value is delimited  using single quotes.
+     */
+    NSArray* components = [string componentsSeparatedByString:@"'"];
 
-       return [components componentsJoinedByString:@"'\"'\"'"];
+    return [components componentsJoinedByString:@"'\"'\"'"];
 }
 
 - (NSString *)commandLineForScript: (NSString *)script
 
     script_dir = [script substringToIndex:
            [script length]-[[script lastPathComponent] length]];
-    
+
     if (honourhashbang &&
        (fp=fopen([script fileSystemRepresentation], "r")) &&
        fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
     }
     if (!cur_interp)
         cur_interp = interpreter;
-        
+
     return [NSString stringWithFormat:
         @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
        [self _replaceSingleQuotes:script_dir],
 
 - (NSArray *) interpreters { return interpreters;};
 
-// FileSettingsSource protocol 
+// FileSettingsSource protocol
 - (NSString *) interpreter { return interpreter;};
 - (BOOL) honourhashbang { return honourhashbang; };
 - (BOOL) debug { return debug;};
index a5ba7510784c97b7920298443be85eca77a7644f..e75fb06616b68d6a8cdf8d9f93a62ee9ec11a0a6 100644 (file)
@@ -33,7 +33,7 @@
 
 - (BOOL)shouldShowUI
 {
-    // if this call comes before applicationDidFinishLaunching: we 
+    // if this call comes before applicationDidFinishLaunching: we
     // should terminate immedeately after starting the script.
     if (!initial_action_done)
         should_terminate = YES;
@@ -62,7 +62,7 @@
     static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
     NSString **ext_p;
     int i;
-    
+
     if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
         return;
     ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
@@ -92,5 +92,5 @@
         }
     }
 }
-        
+
 @end
index 8f851e74e301a00a1ed2296a7be57f9cdfaa2d8c..90c5db9dc5b60d142d62964d8479f80c1ece249a 100755 (executable)
@@ -16,7 +16,7 @@
 {
     self = [super init];
     if (self) {
-    
+
         // Add your subclass-specific initialization here.
         // If an error occurs here, send a [self dealloc] message and return nil.
         script = [@"<no script>.py" retain];
 {
     NSApplication *app = [NSApplication sharedApplication];
     [super close];
-    if ([[app delegate] shouldTerminate])
+    if ([(MyAppDelegate*)[app delegate] shouldTerminate])
         [app terminate: self];
 }
 
 - (void)load_defaults
 {
-//    if (settings) [settings release];
     settings = [FileSettings newSettingsForFileType: filetype];
 }
 
 - (void)update_display
 {
-//    [[self window] setTitle: script];
-    
     [interpreter setStringValue: [settings interpreter]];
     [honourhashbang setState: [settings honourhashbang]];
     [debug setState: [settings debug]];
@@ -62,7 +59,7 @@
     [others setStringValue: [settings others]];
     [scriptargs setStringValue: [settings scriptargs]];
     [with_terminal setState: [settings with_terminal]];
-    
+
     [commandline setStringValue: [settings commandLineForScript: script]];
 }
 
@@ -75,7 +72,7 @@
 {
     const char *cmdline;
     int sts;
-    
+
      cmdline = [[settings commandLineForScript: script] UTF8String];
    if ([settings with_terminal]) {
         sts = doscript(cmdline);
 {
     // Insert code here to read your document from the given data.  You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
     BOOL show_ui;
-    
-    // ask the app delegate whether we should show the UI or not. 
-    show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
+
+    // ask the app delegate whether we should show the UI or not.
+    show_ui = [(MyAppDelegate*)[[NSApplication sharedApplication] delegate] shouldShowUI];
     [script release];
     script = [fileName retain];
     [filetype release];
     filetype = [type retain];
-//    if (settings) [settings release];
     settings = [FileSettings newSettingsForFileType: filetype];
     if (show_ui) {
         [self update_display];
     [self update_display];
 }
 
-// FileSettingsSource protocol 
+// FileSettingsSource protocol
 - (NSString *) interpreter { return [interpreter stringValue];};
 - (BOOL) honourhashbang { return [honourhashbang state];};
 - (BOOL) debug { return [debug state];};
index 311c37502bb2208715261ce0b1992a7f0235dae0..dc65064463c48dcb80aeb1ccede986000a66de39 100644 (file)
@@ -5,7 +5,7 @@
 + getPreferencesWindow
 {
     static PreferencesWindowController *_singleton;
-    
+
     if (!_singleton)
         _singleton = [[PreferencesWindowController alloc] init];
     [_singleton showWindow: _singleton];
 - (void)load_defaults
 {
     NSString *title = [filetype titleOfSelectedItem];
-    
+
     settings = [FileSettings getDefaultsForFileType: title];
 }
 
 - (void)update_display
 {
-//    [[self window] setTitle: script];
-    
-       [interpreter reloadData];
+    [interpreter reloadData];
     [interpreter setStringValue: [settings interpreter]];
     [honourhashbang setState: [settings honourhashbang]];
     [debug setState: [settings debug]];
@@ -41,7 +39,6 @@
     [others setStringValue: [settings others]];
     [with_terminal setState: [settings with_terminal]];
     // Not scriptargs, it isn't for preferences
-    
     [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
 }
 
@@ -75,7 +72,7 @@
     [self update_display];
 }
 
-// FileSettingsSource protocol 
+// FileSettingsSource protocol
 - (NSString *) interpreter { return [interpreter stringValue];};
 - (BOOL) honourhashbang { return [honourhashbang state]; };
 - (BOOL) debug { return [debug state];};
index eef0b5641f679eb8182cb552ce439d8f1a72566c..3fd3187cd4a578e54a05a89ee72fef45e904a97d 100644 (file)
@@ -9,4 +9,4 @@
 
 #include <Carbon/Carbon.h>
 
-extern int doscript(const char *command);
\ No newline at end of file
+extern int doscript(const char *command);
index 024b883f1903b0d0b1e0d9289520b710c06c4a1f..cbb783ba3e893d09b7395ec6c740b407da5afa74 100644 (file)
 #import <ApplicationServices/ApplicationServices.h>
 #import "doscript.h"
 
-extern int 
+extern int
 doscript(const char *command)
 {
-       char *bundleID = "com.apple.Terminal";
-       AppleEvent evt, res;
-       AEDesc desc;
-       OSStatus err;
+    char *bundleID = "com.apple.Terminal";
+    AppleEvent evt, res;
+    AEDesc desc;
+    OSStatus err;
 
-       [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
+    [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
 
-       // Build event
-       err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
-                                typeApplicationBundleID,
-                                bundleID, strlen(bundleID),
-                                kAutoGenerateReturnID,
-                                kAnyTransactionID,
-                                &evt, NULL,
-                                "'----':utf8(@)", strlen(command),
-                                command);
-       if (err) {
-               NSLog(@"AEBuildAppleEvent failed: %d\n", err);
-               return err;
-       }
+    // Build event
+    err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
+                             typeApplicationBundleID,
+                             bundleID, strlen(bundleID),
+                             kAutoGenerateReturnID,
+                             kAnyTransactionID,
+                             &evt, NULL,
+                             "'----':utf8(@)", strlen(command),
+                             command);
+    if (err) {
+        NSLog(@"AEBuildAppleEvent failed: %ld\n", (long)err);
+        return err;
+    }
 
-       // Send event and check for any Apple Event Manager errors
-       err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
-       AEDisposeDesc(&evt);
-       if (err) {
-               NSLog(@"AESendMessage failed: %d\n", err);
-               return err;
-       }
-       // Check for any application errors
-       err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
-       AEDisposeDesc(&res);
-       if (!err) {
-               AEGetDescData(&desc, &err, sizeof(err));
-               NSLog(@"Terminal returned an error: %d", err);
-               AEDisposeDesc(&desc);
-       } else if (err == errAEDescNotFound) {
-               err = noErr;
-       } else {
-               NSLog(@"AEGetPArmDesc returned an error: %d", err);
-       }
+    // Send event and check for any Apple Event Manager errors
+    err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
+    AEDisposeDesc(&evt);
+    if (err) {
+        NSLog(@"AESendMessage failed: %ld\n", (long)err);
+        return err;
+    }
+    // Check for any application errors
+    err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
+    AEDisposeDesc(&res);
+    if (!err) {
+        AEGetDescData(&desc, &err, sizeof(err));
+        NSLog(@"Terminal returned an error: %ld", (long)err);
+        AEDisposeDesc(&desc);
+    } else if (err == errAEDescNotFound) {
+        err = noErr;
+    } else {
+        NSLog(@"AEGetPArmDesc returned an error: %ld", (long)err);
+    }
 
-       return err;
+    return err;
 }
index 6841433f429f3fa21d7f126ccb64567cb63f5079..04b4d7321f74ebeb7acb0229fc8fd01c276a3ea6 100755 (executable)
@@ -11,7 +11,7 @@
 
 int main(int argc, const char *argv[])
 {
-       char *home = getenv("HOME");
-       if (home) chdir(home);
+    char *home = getenv("HOME");
+    if (home) chdir(home);
     return NSApplicationMain(argc, argv);
 }