(3.3->default) 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.
This commit is contained in:
Ronald Oussoren 2013-07-07 09:54:08 +02:00
commit 071029fac6
8 changed files with 77 additions and 95 deletions

View File

@ -45,18 +45,13 @@
+ (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;

View File

@ -95,12 +95,6 @@
return self;
}
//- (id)init
//{
// self = [self initForFileType: @"Python Script"];
// return self;
//}
- (id)initForFSDefaultFileType: (NSString *)filetype
{
int i;
@ -247,12 +241,12 @@
- (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

View File

@ -37,20 +37,17 @@
{
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]];
@ -109,12 +106,11 @@
BOOL show_ui;
// 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 = [fileName retain];
[filetype release];
filetype = [type retain];
// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype];
if (show_ui) {
[self update_display];

View File

@ -27,9 +27,7 @@
- (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>"]];
}

View File

@ -14,46 +14,46 @@
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;
}

View File

@ -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);
}