Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4e327c9

Browse files
committedJul 7, 2013
Issue python#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.
1 parent 385521c commit 4e327c9

File tree

8 files changed

+77
-95
lines changed

8 files changed

+77
-95
lines changed
 

‎Mac/PythonLauncher/FileSettings.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,13 @@
4545
+ (id)getFactorySettingsForFileType: (NSString *)filetype;
4646
+ (id)newSettingsForFileType: (NSString *)filetype;
4747

48-
//- (id)init;
4948
- (id)initForFileType: (NSString *)filetype;
5049
- (id)initForFSDefaultFileType: (NSString *)filetype;
5150
- (id)initForDefaultFileType: (NSString *)filetype;
52-
//- (id)initWithFileSettings: (FileSettings *)source;
5351

5452
- (void)updateFromSource: (id <FileSettingsSource>)source;
5553
- (NSString *)commandLineForScript: (NSString *)script;
5654

57-
//- (void)applyFactorySettingsForFileType: (NSString *)filetype;
58-
//- (void)saveDefaults;
59-
//- (void)applyUserDefaults: (NSString *)filetype;
6055
- (void)applyValuesFromDict: (NSDictionary *)dict;
6156
- (void)reset;
6257
- (NSArray *) interpreters;

‎Mac/PythonLauncher/FileSettings.m

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ + (id)getFactorySettingsForFileType: (NSString *)filetype
1414
{
1515
static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
1616
FileSettings **curdefault;
17-
17+
1818
if ([filetype isEqualToString: @"Python Script"]) {
1919
curdefault = &fsdefault_py;
2020
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
@@ -36,7 +36,7 @@ + (id)getDefaultsForFileType: (NSString *)filetype
3636
{
3737
static FileSettings *default_py, *default_pyw, *default_pyc;
3838
FileSettings **curdefault;
39-
39+
4040
if ([filetype isEqualToString: @"Python Script"]) {
4141
curdefault = &default_py;
4242
} else if ([filetype isEqualToString: @"Python GUI Script"]) {
@@ -57,7 +57,7 @@ + (id)getDefaultsForFileType: (NSString *)filetype
5757
+ (id)newSettingsForFileType: (NSString *)filetype
5858
{
5959
FileSettings *cur;
60-
60+
6161
cur = [FileSettings new];
6262
[cur initForFileType: filetype];
6363
return [cur retain];
@@ -67,7 +67,7 @@ - (id)initWithFileSettings: (FileSettings *)source
6767
{
6868
self = [super init];
6969
if (!self) return self;
70-
70+
7171
interpreter = [source->interpreter retain];
7272
honourhashbang = source->honourhashbang;
7373
debug = source->debug;
@@ -81,36 +81,30 @@ - (id)initWithFileSettings: (FileSettings *)source
8181
with_terminal = source->with_terminal;
8282
prefskey = source->prefskey;
8383
if (prefskey) [prefskey retain];
84-
84+
8585
return self;
8686
}
8787

8888
- (id)initForFileType: (NSString *)filetype
8989
{
9090
FileSettings *defaults;
91-
91+
9292
defaults = [FileSettings getDefaultsForFileType: filetype];
9393
self = [self initWithFileSettings: defaults];
9494
origsource = [defaults retain];
9595
return self;
9696
}
9797

98-
//- (id)init
99-
//{
100-
// self = [self initForFileType: @"Python Script"];
101-
// return self;
102-
//}
103-
10498
- (id)initForFSDefaultFileType: (NSString *)filetype
10599
{
106100
int i;
107101
NSString *filename;
108102
NSDictionary *dict;
109103
static NSDictionary *factorySettings;
110-
104+
111105
self = [super init];
112106
if (!self) return self;
113-
107+
114108
if (factorySettings == NULL) {
115109
NSBundle *bdl = [NSBundle mainBundle];
116110
NSString *path = [ bdl pathForResource: @"factorySettings"
@@ -149,18 +143,18 @@ - (void)applyUserDefaults: (NSString *)filetype
149143
{
150144
NSUserDefaults *defaults;
151145
NSDictionary *dict;
152-
146+
153147
defaults = [NSUserDefaults standardUserDefaults];
154148
dict = [defaults dictionaryForKey: filetype];
155149
if (!dict)
156150
return;
157151
[self applyValuesFromDict: dict];
158152
}
159-
153+
160154
- (id)initForDefaultFileType: (NSString *)filetype
161155
{
162156
FileSettings *fsdefaults;
163-
157+
164158
fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
165159
self = [self initWithFileSettings: fsdefaults];
166160
if (!self) return self;
@@ -220,7 +214,7 @@ - (void)updateFromSource: (id <FileSettingsSource>)source
220214
- (void)applyValuesFromDict: (NSDictionary *)dict
221215
{
222216
id value;
223-
217+
224218
value = [dict objectForKey: @"interpreter"];
225219
if (value) interpreter = [value retain];
226220
value = [dict objectForKey: @"honourhashbang"];
@@ -247,12 +241,12 @@ - (void)applyValuesFromDict: (NSDictionary *)dict
247241

248242
- (NSString*)_replaceSingleQuotes: (NSString*)string
249243
{
250-
/* Replace all single-quotes by '"'"', that way shellquoting will
251-
* be correct when the result value is delimited using single quotes.
252-
*/
253-
NSArray* components = [string componentsSeparatedByString:@"'"];
244+
/* Replace all single-quotes by '"'"', that way shellquoting will
245+
* be correct when the result value is delimited using single quotes.
246+
*/
247+
NSArray* components = [string componentsSeparatedByString:@"'"];
254248

255-
return [components componentsJoinedByString:@"'\"'\"'"];
249+
return [components componentsJoinedByString:@"'\"'\"'"];
256250
}
257251

258252
- (NSString *)commandLineForScript: (NSString *)script
@@ -265,7 +259,7 @@ - (NSString *)commandLineForScript: (NSString *)script
265259

266260
script_dir = [script substringToIndex:
267261
[script length]-[[script lastPathComponent] length]];
268-
262+
269263
if (honourhashbang &&
270264
(fp=fopen([script fileSystemRepresentation], "r")) &&
271265
fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
@@ -278,7 +272,7 @@ - (NSString *)commandLineForScript: (NSString *)script
278272
}
279273
if (!cur_interp)
280274
cur_interp = interpreter;
281-
275+
282276
return [NSString stringWithFormat:
283277
@"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
284278
[self _replaceSingleQuotes:script_dir],
@@ -297,7 +291,7 @@ - (NSString *)commandLineForScript: (NSString *)script
297291

298292
- (NSArray *) interpreters { return interpreters;};
299293

300-
// FileSettingsSource protocol
294+
// FileSettingsSource protocol
301295
- (NSString *) interpreter { return interpreter;};
302296
- (BOOL) honourhashbang { return honourhashbang; };
303297
- (BOOL) debug { return debug;};

‎Mac/PythonLauncher/MyAppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
3333

3434
- (BOOL)shouldShowUI
3535
{
36-
// if this call comes before applicationDidFinishLaunching: we
36+
// if this call comes before applicationDidFinishLaunching: we
3737
// should terminate immedeately after starting the script.
3838
if (!initial_action_done)
3939
should_terminate = YES;
@@ -62,7 +62,7 @@ - (void)testFileTypeBinding
6262
static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
6363
NSString **ext_p;
6464
int i;
65-
65+
6666
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
6767
return;
6868
ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
@@ -92,5 +92,5 @@ - (void)testFileTypeBinding
9292
}
9393
}
9494
}
95-
95+
9696
@end

‎Mac/PythonLauncher/MyDocument.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ - (id)init
1616
{
1717
self = [super init];
1818
if (self) {
19-
19+
2020
// Add your subclass-specific initialization here.
2121
// If an error occurs here, send a [self dealloc] message and return nil.
2222
script = [@"<no script>.py" retain];
@@ -37,20 +37,17 @@ - (void)close
3737
{
3838
NSApplication *app = [NSApplication sharedApplication];
3939
[super close];
40-
if ([[app delegate] shouldTerminate])
40+
if ([(MyAppDelegate*)[app delegate] shouldTerminate])
4141
[app terminate: self];
4242
}
4343

4444
- (void)load_defaults
4545
{
46-
// if (settings) [settings release];
4746
settings = [FileSettings newSettingsForFileType: filetype];
4847
}
4948

5049
- (void)update_display
5150
{
52-
// [[self window] setTitle: script];
53-
5451
[interpreter setStringValue: [settings interpreter]];
5552
[honourhashbang setState: [settings honourhashbang]];
5653
[debug setState: [settings debug]];
@@ -62,7 +59,7 @@ - (void)update_display
6259
[others setStringValue: [settings others]];
6360
[scriptargs setStringValue: [settings scriptargs]];
6461
[with_terminal setState: [settings with_terminal]];
65-
62+
6663
[commandline setStringValue: [settings commandLineForScript: script]];
6764
}
6865

@@ -75,7 +72,7 @@ - (BOOL)run
7572
{
7673
const char *cmdline;
7774
int sts;
78-
75+
7976
cmdline = [[settings commandLineForScript: script] UTF8String];
8077
if ([settings with_terminal]) {
8178
sts = doscript(cmdline);
@@ -107,14 +104,13 @@ - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type;
107104
{
108105
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
109106
BOOL show_ui;
110-
111-
// ask the app delegate whether we should show the UI or not.
112-
show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
107+
108+
// ask the app delegate whether we should show the UI or not.
109+
show_ui = [(MyAppDelegate*)[[NSApplication sharedApplication] delegate] shouldShowUI];
113110
[script release];
114111
script = [fileName retain];
115112
[filetype release];
116113
filetype = [type retain];
117-
// if (settings) [settings release];
118114
settings = [FileSettings newSettingsForFileType: filetype];
119115
if (show_ui) {
120116
[self update_display];
@@ -152,7 +148,7 @@ - (IBAction)do_apply:(id)sender
152148
[self update_display];
153149
}
154150

155-
// FileSettingsSource protocol
151+
// FileSettingsSource protocol
156152
- (NSString *) interpreter { return [interpreter stringValue];};
157153
- (BOOL) honourhashbang { return [honourhashbang state];};
158154
- (BOOL) debug { return [debug state];};

‎Mac/PythonLauncher/PreferencesWindowController.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ @implementation PreferencesWindowController
55
+ getPreferencesWindow
66
{
77
static PreferencesWindowController *_singleton;
8-
8+
99
if (!_singleton)
1010
_singleton = [[PreferencesWindowController alloc] init];
1111
[_singleton showWindow: _singleton];
@@ -21,15 +21,13 @@ - (id) init
2121
- (void)load_defaults
2222
{
2323
NSString *title = [filetype titleOfSelectedItem];
24-
24+
2525
settings = [FileSettings getDefaultsForFileType: title];
2626
}
2727

2828
- (void)update_display
2929
{
30-
// [[self window] setTitle: script];
31-
32-
[interpreter reloadData];
30+
[interpreter reloadData];
3331
[interpreter setStringValue: [settings interpreter]];
3432
[honourhashbang setState: [settings honourhashbang]];
3533
[debug setState: [settings debug]];
@@ -41,7 +39,6 @@ - (void)update_display
4139
[others setStringValue: [settings others]];
4240
[with_terminal setState: [settings with_terminal]];
4341
// Not scriptargs, it isn't for preferences
44-
4542
[commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
4643
}
4744

@@ -75,7 +72,7 @@ - (IBAction)do_apply:(id)sender
7572
[self update_display];
7673
}
7774

78-
// FileSettingsSource protocol
75+
// FileSettingsSource protocol
7976
- (NSString *) interpreter { return [interpreter stringValue];};
8077
- (BOOL) honourhashbang { return [honourhashbang state]; };
8178
- (BOOL) debug { return [debug state];};

‎Mac/PythonLauncher/doscript.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
#include <Carbon/Carbon.h>
1111

12-
extern int doscript(const char *command);
12+
extern int doscript(const char *command);

‎Mac/PythonLauncher/doscript.m

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,49 @@
1111
#import <ApplicationServices/ApplicationServices.h>
1212
#import "doscript.h"
1313

14-
extern int
14+
extern int
1515
doscript(const char *command)
1616
{
17-
char *bundleID = "com.apple.Terminal";
18-
AppleEvent evt, res;
19-
AEDesc desc;
20-
OSStatus err;
17+
char *bundleID = "com.apple.Terminal";
18+
AppleEvent evt, res;
19+
AEDesc desc;
20+
OSStatus err;
2121

22-
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
22+
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
2323

24-
// Build event
25-
err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
26-
typeApplicationBundleID,
27-
bundleID, strlen(bundleID),
28-
kAutoGenerateReturnID,
29-
kAnyTransactionID,
30-
&evt, NULL,
31-
"'----':utf8(@)", strlen(command),
32-
command);
33-
if (err) {
34-
NSLog(@"AEBuildAppleEvent failed: %d\n", err);
35-
return err;
36-
}
24+
// Build event
25+
err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
26+
typeApplicationBundleID,
27+
bundleID, strlen(bundleID),
28+
kAutoGenerateReturnID,
29+
kAnyTransactionID,
30+
&evt, NULL,
31+
"'----':utf8(@)", strlen(command),
32+
command);
33+
if (err) {
34+
NSLog(@"AEBuildAppleEvent failed: %ld\n", (long)err);
35+
return err;
36+
}
3737

38-
// Send event and check for any Apple Event Manager errors
39-
err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
40-
AEDisposeDesc(&evt);
41-
if (err) {
42-
NSLog(@"AESendMessage failed: %d\n", err);
43-
return err;
44-
}
45-
// Check for any application errors
46-
err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
47-
AEDisposeDesc(&res);
48-
if (!err) {
49-
AEGetDescData(&desc, &err, sizeof(err));
50-
NSLog(@"Terminal returned an error: %d", err);
51-
AEDisposeDesc(&desc);
52-
} else if (err == errAEDescNotFound) {
53-
err = noErr;
54-
} else {
55-
NSLog(@"AEGetPArmDesc returned an error: %d", err);
56-
}
38+
// Send event and check for any Apple Event Manager errors
39+
err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
40+
AEDisposeDesc(&evt);
41+
if (err) {
42+
NSLog(@"AESendMessage failed: %ld\n", (long)err);
43+
return err;
44+
}
45+
// Check for any application errors
46+
err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
47+
AEDisposeDesc(&res);
48+
if (!err) {
49+
AEGetDescData(&desc, &err, sizeof(err));
50+
NSLog(@"Terminal returned an error: %ld", (long)err);
51+
AEDisposeDesc(&desc);
52+
} else if (err == errAEDescNotFound) {
53+
err = noErr;
54+
} else {
55+
NSLog(@"AEGetPArmDesc returned an error: %ld", (long)err);
56+
}
5757

58-
return err;
58+
return err;
5959
}

‎Mac/PythonLauncher/main.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
int main(int argc, const char *argv[])
1313
{
14-
char *home = getenv("HOME");
15-
if (home) chdir(home);
14+
char *home = getenv("HOME");
15+
if (home) chdir(home);
1616
return NSApplicationMain(argc, argv);
1717
}

0 commit comments

Comments
 (0)
Please sign in to comment.