Skip to content

Commit 4e327c9

Browse files
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.
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

-5
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

+20-26
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

+3-3
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

+8-12
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

+4-7
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

+1-1
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);

0 commit comments

Comments
 (0)