Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12400)

Side by Side Diff: Mac/PythonLauncher/FileSettings.m

Issue 15550: Trailing white spaces
Patch Set: Created 7 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // 1 //
2 // FileSettings.m 2 // FileSettings.m
3 // PythonLauncher 3 // PythonLauncher
4 // 4 //
5 // Created by Jack Jansen on Sun Jul 21 2002. 5 // Created by Jack Jansen on Sun Jul 21 2002.
6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved. 6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved.
7 // 7 //
8 8
9 #import "FileSettings.h" 9 #import "FileSettings.h"
10 10
11 @implementation FileSettings 11 @implementation FileSettings
12 12
13 + (id)getFactorySettingsForFileType: (NSString *)filetype 13 + (id)getFactorySettingsForFileType: (NSString *)filetype
14 { 14 {
15 static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; 15 static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
16 FileSettings **curdefault; 16 FileSettings **curdefault;
17 17
18 if ([filetype isEqualToString: @"Python Script"]) { 18 if ([filetype isEqualToString: @"Python Script"]) {
19 curdefault = &fsdefault_py; 19 curdefault = &fsdefault_py;
20 } else if ([filetype isEqualToString: @"Python GUI Script"]) { 20 } else if ([filetype isEqualToString: @"Python GUI Script"]) {
21 curdefault = &fsdefault_pyw; 21 curdefault = &fsdefault_pyw;
22 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { 22 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
23 curdefault = &fsdefault_pyc; 23 curdefault = &fsdefault_pyc;
24 } else { 24 } else {
25 NSLog(@"Funny File Type: %@\n", filetype); 25 NSLog(@"Funny File Type: %@\n", filetype);
26 curdefault = &fsdefault_py; 26 curdefault = &fsdefault_py;
27 filetype = @"Python Script"; 27 filetype = @"Python Script";
28 } 28 }
29 if (!*curdefault) { 29 if (!*curdefault) {
30 *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype]; 30 *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype];
31 } 31 }
32 return *curdefault; 32 return *curdefault;
33 } 33 }
34 34
35 + (id)getDefaultsForFileType: (NSString *)filetype 35 + (id)getDefaultsForFileType: (NSString *)filetype
36 { 36 {
37 static FileSettings *default_py, *default_pyw, *default_pyc; 37 static FileSettings *default_py, *default_pyw, *default_pyc;
38 FileSettings **curdefault; 38 FileSettings **curdefault;
39 39
40 if ([filetype isEqualToString: @"Python Script"]) { 40 if ([filetype isEqualToString: @"Python Script"]) {
41 curdefault = &default_py; 41 curdefault = &default_py;
42 } else if ([filetype isEqualToString: @"Python GUI Script"]) { 42 } else if ([filetype isEqualToString: @"Python GUI Script"]) {
43 curdefault = &default_pyw; 43 curdefault = &default_pyw;
44 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { 44 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
45 curdefault = &default_pyc; 45 curdefault = &default_pyc;
46 } else { 46 } else {
47 NSLog(@"Funny File Type: %@\n", filetype); 47 NSLog(@"Funny File Type: %@\n", filetype);
48 curdefault = &default_py; 48 curdefault = &default_py;
49 filetype = @"Python Script"; 49 filetype = @"Python Script";
50 } 50 }
51 if (!*curdefault) { 51 if (!*curdefault) {
52 *curdefault = [[FileSettings new] initForDefaultFileType: filetype]; 52 *curdefault = [[FileSettings new] initForDefaultFileType: filetype];
53 } 53 }
54 return *curdefault; 54 return *curdefault;
55 } 55 }
56 56
57 + (id)newSettingsForFileType: (NSString *)filetype 57 + (id)newSettingsForFileType: (NSString *)filetype
58 { 58 {
59 FileSettings *cur; 59 FileSettings *cur;
60 60
61 cur = [FileSettings new]; 61 cur = [FileSettings new];
62 [cur initForFileType: filetype]; 62 [cur initForFileType: filetype];
63 return [cur retain]; 63 return [cur retain];
64 } 64 }
65 65
66 - (id)initWithFileSettings: (FileSettings *)source 66 - (id)initWithFileSettings: (FileSettings *)source
67 { 67 {
68 self = [super init]; 68 self = [super init];
69 if (!self) return self; 69 if (!self) return self;
70 70
71 interpreter = [source->interpreter retain]; 71 interpreter = [source->interpreter retain];
72 honourhashbang = source->honourhashbang; 72 honourhashbang = source->honourhashbang;
73 debug = source->debug; 73 debug = source->debug;
74 verbose = source->verbose; 74 verbose = source->verbose;
75 inspect = source->inspect; 75 inspect = source->inspect;
76 optimize = source->optimize; 76 optimize = source->optimize;
77 nosite = source->nosite; 77 nosite = source->nosite;
78 tabs = source->tabs; 78 tabs = source->tabs;
79 others = [source->others retain]; 79 others = [source->others retain];
80 scriptargs = [source->scriptargs retain]; 80 scriptargs = [source->scriptargs retain];
81 with_terminal = source->with_terminal; 81 with_terminal = source->with_terminal;
82 prefskey = source->prefskey; 82 prefskey = source->prefskey;
83 if (prefskey) [prefskey retain]; 83 if (prefskey) [prefskey retain];
84 84
85 return self; 85 return self;
86 } 86 }
87 87
88 - (id)initForFileType: (NSString *)filetype 88 - (id)initForFileType: (NSString *)filetype
89 { 89 {
90 FileSettings *defaults; 90 FileSettings *defaults;
91 91
92 defaults = [FileSettings getDefaultsForFileType: filetype]; 92 defaults = [FileSettings getDefaultsForFileType: filetype];
93 self = [self initWithFileSettings: defaults]; 93 self = [self initWithFileSettings: defaults];
94 origsource = [defaults retain]; 94 origsource = [defaults retain];
95 return self; 95 return self;
96 } 96 }
97 97
98 //- (id)init 98 //- (id)init
99 //{ 99 //{
100 // self = [self initForFileType: @"Python Script"]; 100 // self = [self initForFileType: @"Python Script"];
101 // return self; 101 // return self;
102 //} 102 //}
103 103
104 - (id)initForFSDefaultFileType: (NSString *)filetype 104 - (id)initForFSDefaultFileType: (NSString *)filetype
105 { 105 {
106 int i; 106 int i;
107 NSString *filename; 107 NSString *filename;
108 NSDictionary *dict; 108 NSDictionary *dict;
109 static NSDictionary *factorySettings; 109 static NSDictionary *factorySettings;
110 110
111 self = [super init]; 111 self = [super init];
112 if (!self) return self; 112 if (!self) return self;
113 113
114 if (factorySettings == NULL) { 114 if (factorySettings == NULL) {
115 NSBundle *bdl = [NSBundle mainBundle]; 115 NSBundle *bdl = [NSBundle mainBundle];
116 NSString *path = [ bdl pathForResource: @"factorySettings" 116 NSString *path = [ bdl pathForResource: @"factorySettings"
117 ofType: @"plist"]; 117 ofType: @"plist"];
118 factorySettings = [[NSDictionary dictionaryWithContentsOfFile: 118 factorySettings = [[NSDictionary dictionaryWithContentsOfFile:
119 path] retain]; 119 path] retain];
120 if (factorySettings == NULL) { 120 if (factorySettings == NULL) {
121 NSLog(@"Missing %@", path); 121 NSLog(@"Missing %@", path);
122 return NULL; 122 return NULL;
123 } 123 }
(...skipping 18 matching lines...) Expand all
142 if (interpreter == NULL) 142 if (interpreter == NULL)
143 interpreter = [@"no default found" retain]; 143 interpreter = [@"no default found" retain];
144 origsource = NULL; 144 origsource = NULL;
145 return self; 145 return self;
146 } 146 }
147 147
148 - (void)applyUserDefaults: (NSString *)filetype 148 - (void)applyUserDefaults: (NSString *)filetype
149 { 149 {
150 NSUserDefaults *defaults; 150 NSUserDefaults *defaults;
151 NSDictionary *dict; 151 NSDictionary *dict;
152 152
153 defaults = [NSUserDefaults standardUserDefaults]; 153 defaults = [NSUserDefaults standardUserDefaults];
154 dict = [defaults dictionaryForKey: filetype]; 154 dict = [defaults dictionaryForKey: filetype];
155 if (!dict) 155 if (!dict)
156 return; 156 return;
157 [self applyValuesFromDict: dict]; 157 [self applyValuesFromDict: dict];
158 } 158 }
159 159
160 - (id)initForDefaultFileType: (NSString *)filetype 160 - (id)initForDefaultFileType: (NSString *)filetype
161 { 161 {
162 FileSettings *fsdefaults; 162 FileSettings *fsdefaults;
163 163
164 fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; 164 fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
165 self = [self initWithFileSettings: fsdefaults]; 165 self = [self initWithFileSettings: fsdefaults];
166 if (!self) return self; 166 if (!self) return self;
167 interpreters = [fsdefaults->interpreters retain]; 167 interpreters = [fsdefaults->interpreters retain];
168 scriptargs = [@"" retain]; 168 scriptargs = [@"" retain];
169 [self applyUserDefaults: filetype]; 169 [self applyUserDefaults: filetype];
170 prefskey = [filetype retain]; 170 prefskey = [filetype retain];
171 return self; 171 return self;
172 } 172 }
173 173
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 [NSNumber numberWithBool: with_terminal], @"with_terminal", 213 [NSNumber numberWithBool: with_terminal], @"with_terminal",
214 nil]; 214 nil];
215 defaults = [NSUserDefaults standardUserDefaults]; 215 defaults = [NSUserDefaults standardUserDefaults];
216 [defaults setObject: dict forKey: prefskey]; 216 [defaults setObject: dict forKey: prefskey];
217 } 217 }
218 } 218 }
219 219
220 - (void)applyValuesFromDict: (NSDictionary *)dict 220 - (void)applyValuesFromDict: (NSDictionary *)dict
221 { 221 {
222 id value; 222 id value;
223 223
224 value = [dict objectForKey: @"interpreter"]; 224 value = [dict objectForKey: @"interpreter"];
225 if (value) interpreter = [value retain]; 225 if (value) interpreter = [value retain];
226 value = [dict objectForKey: @"honourhashbang"]; 226 value = [dict objectForKey: @"honourhashbang"];
227 if (value) honourhashbang = [value boolValue]; 227 if (value) honourhashbang = [value boolValue];
228 value = [dict objectForKey: @"debug"]; 228 value = [dict objectForKey: @"debug"];
229 if (value) debug = [value boolValue]; 229 if (value) debug = [value boolValue];
230 value = [dict objectForKey: @"verbose"]; 230 value = [dict objectForKey: @"verbose"];
231 if (value) verbose = [value boolValue]; 231 if (value) verbose = [value boolValue];
232 value = [dict objectForKey: @"inspect"]; 232 value = [dict objectForKey: @"inspect"];
233 if (value) inspect = [value boolValue]; 233 if (value) inspect = [value boolValue];
(...skipping 24 matching lines...) Expand all
258 - (NSString *)commandLineForScript: (NSString *)script 258 - (NSString *)commandLineForScript: (NSString *)script
259 { 259 {
260 NSString *cur_interp = NULL; 260 NSString *cur_interp = NULL;
261 NSString* script_dir = NULL; 261 NSString* script_dir = NULL;
262 char hashbangbuf[1024]; 262 char hashbangbuf[1024];
263 FILE *fp; 263 FILE *fp;
264 char *p; 264 char *p;
265 265
266 script_dir = [script substringToIndex: 266 script_dir = [script substringToIndex:
267 [script length]-[[script lastPathComponent] length]]; 267 [script length]-[[script lastPathComponent] length]];
268 268
269 if (honourhashbang && 269 if (honourhashbang &&
270 (fp=fopen([script fileSystemRepresentation], "r")) && 270 (fp=fopen([script fileSystemRepresentation], "r")) &&
271 fgets(hashbangbuf, sizeof(hashbangbuf), fp) && 271 fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
272 strncmp(hashbangbuf, "#!", 2) == 0 && 272 strncmp(hashbangbuf, "#!", 2) == 0 &&
273 (p=strchr(hashbangbuf, '\n'))) { 273 (p=strchr(hashbangbuf, '\n'))) {
274 *p = '\0'; 274 *p = '\0';
275 p = hashbangbuf + 2; 275 p = hashbangbuf + 2;
276 while (*p == ' ') p++; 276 while (*p == ' ') p++;
277 cur_interp = [NSString stringWithUTF8String: p]; 277 cur_interp = [NSString stringWithUTF8String: p];
278 } 278 }
279 if (!cur_interp) 279 if (!cur_interp)
280 cur_interp = interpreter; 280 cur_interp = interpreter;
281 281
282 return [NSString stringWithFormat: 282 return [NSString stringWithFormat:
283 @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s", 283 @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
284 [self _replaceSingleQuotes:script_dir], 284 [self _replaceSingleQuotes:script_dir],
285 [self _replaceSingleQuotes:cur_interp], 285 [self _replaceSingleQuotes:cur_interp],
286 debug?" -d":"", 286 debug?" -d":"",
287 verbose?" -v":"", 287 verbose?" -v":"",
288 inspect?" -i":"", 288 inspect?" -i":"",
289 optimize?" -O":"", 289 optimize?" -O":"",
290 nosite?" -S":"", 290 nosite?" -S":"",
291 tabs?" -t":"", 291 tabs?" -t":"",
292 others, 292 others,
293 [self _replaceSingleQuotes:script], 293 [self _replaceSingleQuotes:script],
294 scriptargs ? scriptargs : @"", 294 scriptargs ? scriptargs : @"",
295 with_terminal? "&& echo Exit status: $? && exit 1" : " &"]; 295 with_terminal? "&& echo Exit status: $? && exit 1" : " &"];
296 } 296 }
297 297
298 - (NSArray *) interpreters { return interpreters;}; 298 - (NSArray *) interpreters { return interpreters;};
299 299
300 // FileSettingsSource protocol 300 // FileSettingsSource protocol
301 - (NSString *) interpreter { return interpreter;}; 301 - (NSString *) interpreter { return interpreter;};
302 - (BOOL) honourhashbang { return honourhashbang; }; 302 - (BOOL) honourhashbang { return honourhashbang; };
303 - (BOOL) debug { return debug;}; 303 - (BOOL) debug { return debug;};
304 - (BOOL) verbose { return verbose;}; 304 - (BOOL) verbose { return verbose;};
305 - (BOOL) inspect { return inspect;}; 305 - (BOOL) inspect { return inspect;};
306 - (BOOL) optimize { return optimize;}; 306 - (BOOL) optimize { return optimize;};
307 - (BOOL) nosite { return nosite;}; 307 - (BOOL) nosite { return nosite;};
308 - (BOOL) tabs { return tabs;}; 308 - (BOOL) tabs { return tabs;};
309 - (NSString *) others { return others;}; 309 - (NSString *) others { return others;};
310 - (NSString *) scriptargs { return scriptargs;}; 310 - (NSString *) scriptargs { return scriptargs;};
311 - (BOOL) with_terminal { return with_terminal;}; 311 - (BOOL) with_terminal { return with_terminal;};
312 312
313 @end 313 @end
OLDNEW
« no previous file with comments | « Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib ('k') | Mac/PythonLauncher/Makefile.in » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+