annotate Mac/PythonLauncher/FileSettings.m @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 14e2750e2506
children 5d41ebc79738
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 //
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 // FileSettings.m
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 // PythonLauncher
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 //
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 // Created by Jack Jansen on Sun Jul 21 2002.
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 // Copyright (c) 2002 __MyCompanyName__. All rights reserved.
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 //
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 #import "FileSettings.h"
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 @implementation FileSettings
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
12
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
13 + (id)getFactorySettingsForFileType: (NSString *)filetype
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
14 {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
15 static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
16 FileSettings **curdefault;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
17
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
18 if ([filetype isEqualToString: @"Python Script"]) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
19 curdefault = &fsdefault_py;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
20 } else if ([filetype isEqualToString: @"Python GUI Script"]) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
21 curdefault = &fsdefault_pyw;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
22 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
23 curdefault = &fsdefault_pyc;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
24 } else {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
25 NSLog(@"Funny File Type: %@\n", filetype);
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
26 curdefault = &fsdefault_py;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
27 filetype = @"Python Script";
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
28 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
29 if (!*curdefault) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
30 *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
31 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
32 return *curdefault;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
33 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
34
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 + (id)getDefaultsForFileType: (NSString *)filetype
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 static FileSettings *default_py, *default_pyw, *default_pyc;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 FileSettings **curdefault;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 if ([filetype isEqualToString: @"Python Script"]) {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 curdefault = &default_py;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 } else if ([filetype isEqualToString: @"Python GUI Script"]) {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 curdefault = &default_pyw;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 } else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 curdefault = &default_pyc;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 } else {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 NSLog(@"Funny File Type: %@\n", filetype);
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 curdefault = &default_py;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 filetype = @"Python Script";
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 if (!*curdefault) {
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
52 *curdefault = [[FileSettings new] initForDefaultFileType: filetype];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 return *curdefault;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 + (id)newSettingsForFileType: (NSString *)filetype
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 FileSettings *cur;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
61 cur = [FileSettings new];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
62 [cur initForFileType: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
63 return [cur retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 - (id)initWithFileSettings: (FileSettings *)source
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 {
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
68 self = [super init];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
69 if (!self) return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
70
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 interpreter = [source->interpreter retain];
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
72 honourhashbang = source->honourhashbang;
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 debug = source->debug;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 verbose = source->verbose;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 inspect = source->inspect;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 optimize = source->optimize;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 nosite = source->nosite;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 tabs = source->tabs;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79 others = [source->others retain];
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
80 scriptargs = [source->scriptargs retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 with_terminal = source->with_terminal;
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
82 prefskey = source->prefskey;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
83 if (prefskey) [prefskey retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
85 return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
86 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
87
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
88 - (id)initForFileType: (NSString *)filetype
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
89 {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
90 FileSettings *defaults;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
91
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
92 defaults = [FileSettings getDefaultsForFileType: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
93 self = [self initWithFileSettings: defaults];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
94 origsource = [defaults retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 return self;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
98 //- (id)init
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
99 //{
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
100 // self = [self initForFileType: @"Python Script"];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
101 // return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
102 //}
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
103
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
104 - (id)initForFSDefaultFileType: (NSString *)filetype
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 {
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
106 int i;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
107 NSString *filename;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
108 NSDictionary *dict;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
109 static NSDictionary *factorySettings;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
110
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
111 self = [super init];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
112 if (!self) return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
113
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
114 if (factorySettings == NULL) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
115 NSBundle *bdl = [NSBundle mainBundle];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
116 NSString *path = [ bdl pathForResource: @"factorySettings"
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
117 ofType: @"plist"];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
118 factorySettings = [[NSDictionary dictionaryWithContentsOfFile:
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
119 path] retain];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
120 if (factorySettings == NULL) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
121 NSLog(@"Missing %@", path);
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
122 return NULL;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
123 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
124 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
125 dict = [factorySettings objectForKey: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
126 if (dict == NULL) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
127 NSLog(@"factorySettings.plist misses file type \"%@\"", filetype);
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
128 interpreter = [@"no default found" retain];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
129 return NULL;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
130 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
131 [self applyValuesFromDict: dict];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
132 interpreters = [dict objectForKey: @"interpreter_list"];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
133 interpreter = NULL;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
134 for (i=0; i < [interpreters count]; i++) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
135 filename = [interpreters objectAtIndex: i];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
136 filename = [filename stringByExpandingTildeInPath];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
137 if ([[NSFileManager defaultManager] fileExistsAtPath: filename]) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
138 interpreter = [filename retain];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
139 break;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
140 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
141 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
142 if (interpreter == NULL)
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
143 interpreter = [@"no default found" retain];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
144 origsource = NULL;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
145 return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
146 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
147
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
148 - (void)applyUserDefaults: (NSString *)filetype
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
149 {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
150 NSUserDefaults *defaults;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
151 NSDictionary *dict;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
152
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
153 defaults = [NSUserDefaults standardUserDefaults];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
154 dict = [defaults dictionaryForKey: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
155 if (!dict)
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
156 return;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
157 [self applyValuesFromDict: dict];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
158 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
159
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
160 - (id)initForDefaultFileType: (NSString *)filetype
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
161 {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
162 FileSettings *fsdefaults;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
163
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
164 fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
165 self = [self initWithFileSettings: fsdefaults];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
166 if (!self) return self;
26806
b204b4a72b4e Changed the input field for the interpreter to use (in the preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 26398
diff changeset
167 interpreters = [fsdefaults->interpreters retain];
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
168 scriptargs = [@"" retain];
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
169 [self applyUserDefaults: filetype];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
170 prefskey = [filetype retain];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
171 return self;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
172 }
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
173
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
174 - (void)reset
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
175 {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
176 if (origsource) {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
177 [self updateFromSource: origsource];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
178 } else {
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
179 FileSettings *fsdefaults;
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
180 fsdefaults = [FileSettings getFactorySettingsForFileType: prefskey];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
181 [self updateFromSource: fsdefaults];
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
182 }
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 - (void)updateFromSource: (id <FileSettingsSource>)source
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 interpreter = [[source interpreter] retain];
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
188 honourhashbang = [source honourhashbang];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 debug = [source debug];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 verbose = [source verbose];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 inspect = [source inspect];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192 optimize = [source optimize];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 nosite = [source nosite];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 tabs = [source tabs];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 others = [[source others] retain];
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
196 scriptargs = [[source scriptargs] retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 with_terminal = [source with_terminal];
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
198 // And if this is a user defaults object we also save the
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
199 // values
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 if (!origsource) {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 NSUserDefaults *defaults;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 interpreter, @"interpreter",
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
204 [NSNumber numberWithBool: honourhashbang], @"honourhashbang",
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 [NSNumber numberWithBool: debug], @"debug",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 [NSNumber numberWithBool: verbose], @"verbose",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 [NSNumber numberWithBool: inspect], @"inspect",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 [NSNumber numberWithBool: optimize], @"optimize",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 [NSNumber numberWithBool: nosite], @"nosite",
40051
20474d9e75e1 Fix for bug #1570284
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 39345
diff changeset
210 [NSNumber numberWithBool: tabs], @"tabs",
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 others, @"others",
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
212 scriptargs, @"scriptargs",
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 [NSNumber numberWithBool: with_terminal], @"with_terminal",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214 nil];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 defaults = [NSUserDefaults standardUserDefaults];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216 [defaults setObject: dict forKey: prefskey];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219
26398
a0d752be5577 Lots of restructuring, mostly suggested by Bill Bumgarner. Main
Jack Jansen <jack.jansen@cwi.nl>
parents: 24467
diff changeset
220 - (void)applyValuesFromDict: (NSDictionary *)dict
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 id value;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 value = [dict objectForKey: @"interpreter"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 if (value) interpreter = [value retain];
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
226 value = [dict objectForKey: @"honourhashbang"];
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
227 if (value) honourhashbang = [value boolValue];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228 value = [dict objectForKey: @"debug"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 if (value) debug = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 value = [dict objectForKey: @"verbose"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
231 if (value) verbose = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 value = [dict objectForKey: @"inspect"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 if (value) inspect = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 value = [dict objectForKey: @"optimize"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 if (value) optimize = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 value = [dict objectForKey: @"nosite"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 if (value) nosite = [value boolValue];
40051
20474d9e75e1 Fix for bug #1570284
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 39345
diff changeset
238 value = [dict objectForKey: @"tabs"];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 if (value) tabs = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240 value = [dict objectForKey: @"others"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 if (value) others = [value retain];
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
242 value = [dict objectForKey: @"scriptargs"];
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
243 if (value) scriptargs = [value retain];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 value = [dict objectForKey: @"with_terminal"];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 if (value) with_terminal = [value boolValue];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247
39345
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
248 - (NSString*)_replaceSingleQuotes: (NSString*)string
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
249 {
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
250 /* Replace all single-quotes by '"'"', that way shellquoting will
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
251 * be correct when the result value is delimited using single quotes.
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
252 */
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
253 NSArray* components = [string componentsSeparatedByString:@"'"];
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
254
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
255 return [components componentsJoinedByString:@"'\"'\"'"];
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
256 }
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
257
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258 - (NSString *)commandLineForScript: (NSString *)script
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 {
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
260 NSString *cur_interp = NULL;
39345
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
261 NSString* script_dir = NULL;
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
262 char hashbangbuf[1024];
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
263 FILE *fp;
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
264 char *p;
39345
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
265
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
266 script_dir = [script substringToIndex:
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
267 [script length]-[[script lastPathComponent] length]];
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
268
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
269 if (honourhashbang &&
52457
14e2750e2506 Remove usage of the deprecated '-cString' and '+stringWithCString:' API's
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 40051
diff changeset
270 (fp=fopen([script fileSystemRepresentation], "r")) &&
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
271 fgets(hashbangbuf, sizeof(hashbangbuf), fp) &&
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
272 strncmp(hashbangbuf, "#!", 2) == 0 &&
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
273 (p=strchr(hashbangbuf, '\n'))) {
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
274 *p = '\0';
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
275 p = hashbangbuf + 2;
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
276 while (*p == ' ') p++;
52457
14e2750e2506 Remove usage of the deprecated '-cString' and '+stringWithCString:' API's
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 40051
diff changeset
277 cur_interp = [NSString stringWithUTF8String: p];
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
278 }
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
279 if (!cur_interp)
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
280 cur_interp = interpreter;
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
281
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 return [NSString stringWithFormat:
39345
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
283 @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
284 [self _replaceSingleQuotes:script_dir],
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
285 [self _replaceSingleQuotes:cur_interp],
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 debug?" -d":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 verbose?" -v":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288 inspect?" -i":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 optimize?" -O":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 nosite?" -S":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 tabs?" -t":"",
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 others,
39345
232d156beb82 This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38644
diff changeset
293 [self _replaceSingleQuotes:script],
40051
20474d9e75e1 Fix for bug #1570284
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 39345
diff changeset
294 scriptargs ? scriptargs : @"",
26806
b204b4a72b4e Changed the input field for the interpreter to use (in the preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 26398
diff changeset
295 with_terminal? "&& echo Exit status: $? && exit 1" : " &"];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297
26806
b204b4a72b4e Changed the input field for the interpreter to use (in the preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 26398
diff changeset
298 - (NSArray *) interpreters { return interpreters;};
b204b4a72b4e Changed the input field for the interpreter to use (in the preferences
Jack Jansen <jack.jansen@cwi.nl>
parents: 26398
diff changeset
299
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 // FileSettingsSource protocol
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 - (NSString *) interpreter { return interpreter;};
27913
cdb1abc1b409 Optionally honour #! paths in scripts. Fixes #676358.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26806
diff changeset
302 - (BOOL) honourhashbang { return honourhashbang; };
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 - (BOOL) debug { return debug;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 - (BOOL) verbose { return verbose;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 - (BOOL) inspect { return inspect;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 - (BOOL) optimize { return optimize;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
307 - (BOOL) nosite { return nosite;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
308 - (BOOL) tabs { return tabs;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
309 - (NSString *) others { return others;};
29570
1aa9057c38b4 Added a field that allows the user to set sys.argv-style arguments
Jack Jansen <jack.jansen@cwi.nl>
parents: 27913
diff changeset
310 - (NSString *) scriptargs { return scriptargs;};
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
311 - (BOOL) with_terminal { return with_terminal;};
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
312
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 @end