Kaydet (Commit) 4e327c9d authored tarafından Ronald Oussoren's avatar Ronald Oussoren

Issue #18377: Code cleanup in Python Launcher

This changeset fixes a number of compiler warnings in the Python Launcher
binary for OSX. It also cleans up whitespace usage in those sources.
üst 385521c9
...@@ -45,18 +45,13 @@ ...@@ -45,18 +45,13 @@
+ (id)getFactorySettingsForFileType: (NSString *)filetype; + (id)getFactorySettingsForFileType: (NSString *)filetype;
+ (id)newSettingsForFileType: (NSString *)filetype; + (id)newSettingsForFileType: (NSString *)filetype;
//- (id)init;
- (id)initForFileType: (NSString *)filetype; - (id)initForFileType: (NSString *)filetype;
- (id)initForFSDefaultFileType: (NSString *)filetype; - (id)initForFSDefaultFileType: (NSString *)filetype;
- (id)initForDefaultFileType: (NSString *)filetype; - (id)initForDefaultFileType: (NSString *)filetype;
//- (id)initWithFileSettings: (FileSettings *)source;
- (void)updateFromSource: (id <FileSettingsSource>)source; - (void)updateFromSource: (id <FileSettingsSource>)source;
- (NSString *)commandLineForScript: (NSString *)script; - (NSString *)commandLineForScript: (NSString *)script;
//- (void)applyFactorySettingsForFileType: (NSString *)filetype;
//- (void)saveDefaults;
//- (void)applyUserDefaults: (NSString *)filetype;
- (void)applyValuesFromDict: (NSDictionary *)dict; - (void)applyValuesFromDict: (NSDictionary *)dict;
- (void)reset; - (void)reset;
- (NSArray *) interpreters; - (NSArray *) interpreters;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
{ {
static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
FileSettings **curdefault; FileSettings **curdefault;
if ([filetype isEqualToString: @"Python Script"]) { if ([filetype isEqualToString: @"Python Script"]) {
curdefault = &fsdefault_py; curdefault = &fsdefault_py;
} else if ([filetype isEqualToString: @"Python GUI Script"]) { } else if ([filetype isEqualToString: @"Python GUI Script"]) {
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
{ {
static FileSettings *default_py, *default_pyw, *default_pyc; static FileSettings *default_py, *default_pyw, *default_pyc;
FileSettings **curdefault; FileSettings **curdefault;
if ([filetype isEqualToString: @"Python Script"]) { if ([filetype isEqualToString: @"Python Script"]) {
curdefault = &default_py; curdefault = &default_py;
} else if ([filetype isEqualToString: @"Python GUI Script"]) { } else if ([filetype isEqualToString: @"Python GUI Script"]) {
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
+ (id)newSettingsForFileType: (NSString *)filetype + (id)newSettingsForFileType: (NSString *)filetype
{ {
FileSettings *cur; FileSettings *cur;
cur = [FileSettings new]; cur = [FileSettings new];
[cur initForFileType: filetype]; [cur initForFileType: filetype];
return [cur retain]; return [cur retain];
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
{ {
self = [super init]; self = [super init];
if (!self) return self; if (!self) return self;
interpreter = [source->interpreter retain]; interpreter = [source->interpreter retain];
honourhashbang = source->honourhashbang; honourhashbang = source->honourhashbang;
debug = source->debug; debug = source->debug;
...@@ -81,36 +81,30 @@ ...@@ -81,36 +81,30 @@
with_terminal = source->with_terminal; with_terminal = source->with_terminal;
prefskey = source->prefskey; prefskey = source->prefskey;
if (prefskey) [prefskey retain]; if (prefskey) [prefskey retain];
return self; return self;
} }
- (id)initForFileType: (NSString *)filetype - (id)initForFileType: (NSString *)filetype
{ {
FileSettings *defaults; FileSettings *defaults;
defaults = [FileSettings getDefaultsForFileType: filetype]; defaults = [FileSettings getDefaultsForFileType: filetype];
self = [self initWithFileSettings: defaults]; self = [self initWithFileSettings: defaults];
origsource = [defaults retain]; origsource = [defaults retain];
return self; return self;
} }
//- (id)init
//{
// self = [self initForFileType: @"Python Script"];
// return self;
//}
- (id)initForFSDefaultFileType: (NSString *)filetype - (id)initForFSDefaultFileType: (NSString *)filetype
{ {
int i; int i;
NSString *filename; NSString *filename;
NSDictionary *dict; NSDictionary *dict;
static NSDictionary *factorySettings; static NSDictionary *factorySettings;
self = [super init]; self = [super init];
if (!self) return self; if (!self) return self;
if (factorySettings == NULL) { if (factorySettings == NULL) {
NSBundle *bdl = [NSBundle mainBundle]; NSBundle *bdl = [NSBundle mainBundle];
NSString *path = [ bdl pathForResource: @"factorySettings" NSString *path = [ bdl pathForResource: @"factorySettings"
...@@ -149,18 +143,18 @@ ...@@ -149,18 +143,18 @@
{ {
NSUserDefaults *defaults; NSUserDefaults *defaults;
NSDictionary *dict; NSDictionary *dict;
defaults = [NSUserDefaults standardUserDefaults]; defaults = [NSUserDefaults standardUserDefaults];
dict = [defaults dictionaryForKey: filetype]; dict = [defaults dictionaryForKey: filetype];
if (!dict) if (!dict)
return; return;
[self applyValuesFromDict: dict]; [self applyValuesFromDict: dict];
} }
- (id)initForDefaultFileType: (NSString *)filetype - (id)initForDefaultFileType: (NSString *)filetype
{ {
FileSettings *fsdefaults; FileSettings *fsdefaults;
fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
self = [self initWithFileSettings: fsdefaults]; self = [self initWithFileSettings: fsdefaults];
if (!self) return self; if (!self) return self;
...@@ -220,7 +214,7 @@ ...@@ -220,7 +214,7 @@
- (void)applyValuesFromDict: (NSDictionary *)dict - (void)applyValuesFromDict: (NSDictionary *)dict
{ {
id value; id value;
value = [dict objectForKey: @"interpreter"]; value = [dict objectForKey: @"interpreter"];
if (value) interpreter = [value retain]; if (value) interpreter = [value retain];
value = [dict objectForKey: @"honourhashbang"]; value = [dict objectForKey: @"honourhashbang"];
...@@ -247,12 +241,12 @@ ...@@ -247,12 +241,12 @@
- (NSString*)_replaceSingleQuotes: (NSString*)string - (NSString*)_replaceSingleQuotes: (NSString*)string
{ {
/* Replace all single-quotes by '"'"', that way shellquoting will /* Replace all single-quotes by '"'"', that way shellquoting will
* be correct when the result value is delimited using single quotes. * be correct when the result value is delimited using single quotes.
*/ */
NSArray* components = [string componentsSeparatedByString:@"'"]; NSArray* components = [string componentsSeparatedByString:@"'"];
return [components componentsJoinedByString:@"'\"'\"'"]; return [components componentsJoinedByString:@"'\"'\"'"];
} }
- (NSString *)commandLineForScript: (NSString *)script - (NSString *)commandLineForScript: (NSString *)script
...@@ -265,7 +259,7 @@ ...@@ -265,7 +259,7 @@
script_dir = [script substringToIndex: script_dir = [script substringToIndex:
[script length]-[[script lastPathComponent] length]]; [script length]-[[script lastPathComponent] length]];
if (honourhashbang && if (honourhashbang &&
(fp=fopen([script fileSystemRepresentation], "r")) && (fp=fopen([script fileSystemRepresentation], "r")) &&
fgets(hashbangbuf, sizeof(hashbangbuf), fp) && fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
...@@ -278,7 +272,7 @@ ...@@ -278,7 +272,7 @@
} }
if (!cur_interp) if (!cur_interp)
cur_interp = interpreter; cur_interp = interpreter;
return [NSString stringWithFormat: return [NSString stringWithFormat:
@"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s", @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
[self _replaceSingleQuotes:script_dir], [self _replaceSingleQuotes:script_dir],
...@@ -297,7 +291,7 @@ ...@@ -297,7 +291,7 @@
- (NSArray *) interpreters { return interpreters;}; - (NSArray *) interpreters { return interpreters;};
// FileSettingsSource protocol // FileSettingsSource protocol
- (NSString *) interpreter { return interpreter;}; - (NSString *) interpreter { return interpreter;};
- (BOOL) honourhashbang { return honourhashbang; }; - (BOOL) honourhashbang { return honourhashbang; };
- (BOOL) debug { return debug;}; - (BOOL) debug { return debug;};
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
- (BOOL)shouldShowUI - (BOOL)shouldShowUI
{ {
// if this call comes before applicationDidFinishLaunching: we // if this call comes before applicationDidFinishLaunching: we
// should terminate immedeately after starting the script. // should terminate immedeately after starting the script.
if (!initial_action_done) if (!initial_action_done)
should_terminate = YES; should_terminate = YES;
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL}; static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
NSString **ext_p; NSString **ext_p;
int i; int i;
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"]) if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
return; return;
ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]]; ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
...@@ -92,5 +92,5 @@ ...@@ -92,5 +92,5 @@
} }
} }
} }
@end @end
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
{ {
self = [super init]; self = [super init];
if (self) { if (self) {
// Add your subclass-specific initialization here. // Add your subclass-specific initialization here.
// If an error occurs here, send a [self dealloc] message and return nil. // If an error occurs here, send a [self dealloc] message and return nil.
script = [@"<no script>.py" retain]; script = [@"<no script>.py" retain];
...@@ -37,20 +37,17 @@ ...@@ -37,20 +37,17 @@
{ {
NSApplication *app = [NSApplication sharedApplication]; NSApplication *app = [NSApplication sharedApplication];
[super close]; [super close];
if ([[app delegate] shouldTerminate]) if ([(MyAppDelegate*)[app delegate] shouldTerminate])
[app terminate: self]; [app terminate: self];
} }
- (void)load_defaults - (void)load_defaults
{ {
// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype]; settings = [FileSettings newSettingsForFileType: filetype];
} }
- (void)update_display - (void)update_display
{ {
// [[self window] setTitle: script];
[interpreter setStringValue: [settings interpreter]]; [interpreter setStringValue: [settings interpreter]];
[honourhashbang setState: [settings honourhashbang]]; [honourhashbang setState: [settings honourhashbang]];
[debug setState: [settings debug]]; [debug setState: [settings debug]];
...@@ -62,7 +59,7 @@ ...@@ -62,7 +59,7 @@
[others setStringValue: [settings others]]; [others setStringValue: [settings others]];
[scriptargs setStringValue: [settings scriptargs]]; [scriptargs setStringValue: [settings scriptargs]];
[with_terminal setState: [settings with_terminal]]; [with_terminal setState: [settings with_terminal]];
[commandline setStringValue: [settings commandLineForScript: script]]; [commandline setStringValue: [settings commandLineForScript: script]];
} }
...@@ -75,7 +72,7 @@ ...@@ -75,7 +72,7 @@
{ {
const char *cmdline; const char *cmdline;
int sts; int sts;
cmdline = [[settings commandLineForScript: script] UTF8String]; cmdline = [[settings commandLineForScript: script] UTF8String];
if ([settings with_terminal]) { if ([settings with_terminal]) {
sts = doscript(cmdline); sts = doscript(cmdline);
...@@ -107,14 +104,13 @@ ...@@ -107,14 +104,13 @@
{ {
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. // 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; BOOL show_ui;
// ask the app delegate whether we should show the UI or not. // ask the app delegate whether we should show the UI or not.
show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI]; show_ui = [(MyAppDelegate*)[[NSApplication sharedApplication] delegate] shouldShowUI];
[script release]; [script release];
script = [fileName retain]; script = [fileName retain];
[filetype release]; [filetype release];
filetype = [type retain]; filetype = [type retain];
// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype]; settings = [FileSettings newSettingsForFileType: filetype];
if (show_ui) { if (show_ui) {
[self update_display]; [self update_display];
...@@ -152,7 +148,7 @@ ...@@ -152,7 +148,7 @@
[self update_display]; [self update_display];
} }
// FileSettingsSource protocol // FileSettingsSource protocol
- (NSString *) interpreter { return [interpreter stringValue];}; - (NSString *) interpreter { return [interpreter stringValue];};
- (BOOL) honourhashbang { return [honourhashbang state];}; - (BOOL) honourhashbang { return [honourhashbang state];};
- (BOOL) debug { return [debug state];}; - (BOOL) debug { return [debug state];};
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
+ + getPreferencesWindow + + getPreferencesWindow
{ {
static PreferencesWindowController *_singleton; static PreferencesWindowController *_singleton;
if (!_singleton) if (!_singleton)
_singleton = [[PreferencesWindowController alloc] init]; _singleton = [[PreferencesWindowController alloc] init];
[_singleton showWindow: _singleton]; [_singleton showWindow: _singleton];
...@@ -21,15 +21,13 @@ ...@@ -21,15 +21,13 @@
- (void)load_defaults - (void)load_defaults
{ {
NSString *title = [filetype titleOfSelectedItem]; NSString *title = [filetype titleOfSelectedItem];
settings = [FileSettings getDefaultsForFileType: title]; settings = [FileSettings getDefaultsForFileType: title];
} }
- (void)update_display - (void)update_display
{ {
// [[self window] setTitle: script]; [interpreter reloadData];
[interpreter reloadData];
[interpreter setStringValue: [settings interpreter]]; [interpreter setStringValue: [settings interpreter]];
[honourhashbang setState: [settings honourhashbang]]; [honourhashbang setState: [settings honourhashbang]];
[debug setState: [settings debug]]; [debug setState: [settings debug]];
...@@ -41,7 +39,6 @@ ...@@ -41,7 +39,6 @@
[others setStringValue: [settings others]]; [others setStringValue: [settings others]];
[with_terminal setState: [settings with_terminal]]; [with_terminal setState: [settings with_terminal]];
// Not scriptargs, it isn't for preferences // Not scriptargs, it isn't for preferences
[commandline setStringValue: [settings commandLineForScript: @"<your script here>"]]; [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
} }
...@@ -75,7 +72,7 @@ ...@@ -75,7 +72,7 @@
[self update_display]; [self update_display];
} }
// FileSettingsSource protocol // FileSettingsSource protocol
- (NSString *) interpreter { return [interpreter stringValue];}; - (NSString *) interpreter { return [interpreter stringValue];};
- (BOOL) honourhashbang { return [honourhashbang state]; }; - (BOOL) honourhashbang { return [honourhashbang state]; };
- (BOOL) debug { return [debug state];}; - (BOOL) debug { return [debug state];};
......
...@@ -9,4 +9,4 @@ ...@@ -9,4 +9,4 @@
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
extern int doscript(const char *command); extern int doscript(const char *command);
\ No newline at end of file
...@@ -11,49 +11,49 @@ ...@@ -11,49 +11,49 @@
#import <ApplicationServices/ApplicationServices.h> #import <ApplicationServices/ApplicationServices.h>
#import "doscript.h" #import "doscript.h"
extern int extern int
doscript(const char *command) doscript(const char *command)
{ {
char *bundleID = "com.apple.Terminal"; char *bundleID = "com.apple.Terminal";
AppleEvent evt, res; AppleEvent evt, res;
AEDesc desc; AEDesc desc;
OSStatus err; OSStatus err;
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"]; [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
// Build event // Build event
err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript, err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
typeApplicationBundleID, typeApplicationBundleID,
bundleID, strlen(bundleID), bundleID, strlen(bundleID),
kAutoGenerateReturnID, kAutoGenerateReturnID,
kAnyTransactionID, kAnyTransactionID,
&evt, NULL, &evt, NULL,
"'----':utf8(@)", strlen(command), "'----':utf8(@)", strlen(command),
command); command);
if (err) { if (err) {
NSLog(@"AEBuildAppleEvent failed: %d\n", err); NSLog(@"AEBuildAppleEvent failed: %ld\n", (long)err);
return err; return err;
} }
// Send event and check for any Apple Event Manager errors // Send event and check for any Apple Event Manager errors
err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout); err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
AEDisposeDesc(&evt); AEDisposeDesc(&evt);
if (err) { if (err) {
NSLog(@"AESendMessage failed: %d\n", err); NSLog(@"AESendMessage failed: %ld\n", (long)err);
return err; return err;
} }
// Check for any application errors // Check for any application errors
err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc); err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
AEDisposeDesc(&res); AEDisposeDesc(&res);
if (!err) { if (!err) {
AEGetDescData(&desc, &err, sizeof(err)); AEGetDescData(&desc, &err, sizeof(err));
NSLog(@"Terminal returned an error: %d", err); NSLog(@"Terminal returned an error: %ld", (long)err);
AEDisposeDesc(&desc); AEDisposeDesc(&desc);
} else if (err == errAEDescNotFound) { } else if (err == errAEDescNotFound) {
err = noErr; err = noErr;
} else { } else {
NSLog(@"AEGetPArmDesc returned an error: %d", err); NSLog(@"AEGetPArmDesc returned an error: %ld", (long)err);
} }
return err; return err;
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home) chdir(home); if (home) chdir(home);
return NSApplicationMain(argc, argv); return NSApplicationMain(argc, argv);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment