Annotation of OpenXM/src/cfep/MyEnvironment.m, Revision 1.5
1.1 takayama 1: //
2: // MyEnvironment.m
3: // cfep
4: //
5: // Created by Nobuki Takayama on 06/01/22.
6: // Copyright 2006 OpenXM.org. All rights reserved.
7: //
8:
9: #import "MyEnvironment.h"
10:
11:
12: @implementation MyEnvironment
13:
14: // -(MyEnvironment *) initFor:with: ; // init with a filename to load. MyEnvironment may be written in the file.
15:
16: // init sets up protocol resources and environment for the task.
17: -(MyEnvironment *) init {
18: return [self initFor: OX_TEXMACS];
19: }
20: -(MyEnvironment *) initFor: (enum peer_type) myPeerType {
21: int i;
22: NSString *s;
23: NSSocketPort *s6000;
24: #define SIZE_e 5
25: NSString *e[] ={@"ASIRRC", @"OX_XTERM", @"LC_CTYPE",@"LC_ALL", @"LANG"};
26: NSString *eDefault[]={nil , nil, nil, nil, nil };
27: if (self = [super init]) {
28: peer = myPeerType;
29:
30: isXRunning = [MyEnvironment checkX];
31:
32: //long initialization to the default value. Personal initialization will be read in the different method.
33: //(1)local string ( or default value)-->(2)preferences by .cfep/cfep.init
34: // --> private in the file
35: OpenXM_HOME=[[[NSBundle mainBundle] bundlePath] stringByAppendingString: @"/OpenXM"];
36: [OpenXM_HOME retain];
37:
38:
39: s = NSLocalizedString(@"PEER_END_EVALUATE_MARK",nil);
40: if ([s compare: @"PEER_END_EVALUATE_MARK"] == NSOrderedSame) {
41: // default value
42: if (myPeerType == OX_TEXMACS)
43: peerEndEvaluateMark = [NSData dataWithBytes: (void *)"\005" length: 1];
44: else peerEndEvaluateMark = [NSData dataWithBytes: (void *)"\n" length: 1];
45: }else{
46: NSLog(@"PEER_END_EVALUATION_MARK. Not yet implemented.");
47: }
48: [peerEndEvaluateMark retain];
49:
50: s = NSLocalizedString(@"PEER_STARTUP_STRING",nil);
51: if ([s compare: @"PEER_STARTUP_STRING"] == NSOrderedSame) {
52: // default value
53: if (myPeerType == OX_TEXMACS)
54: peerStartupString = [OpenXM_HOME stringByAppendingString: @"/bin/ox_texmacs --view cfep --engineLogToStdout -asirInitFile cfep-init.rr\n"];
55: else peerStartupString = @"\n";
56: }else{
57: if (myPeerType == OX_TEXMACS)
58: peerStartupString = [OpenXM_HOME stringByAppendingString: [NSString stringWithString: s]];
59: else peerStartupString = @"\n";
60: }
61: [peerStartupString retain];
62:
63: s = NSLocalizedString(@"PEER_INITIALIZATION_STRING",nil);
64: if ([s compare: @"PEER_INITIALIZATION_STRING"] == NSOrderedSame) {
65: // default value
66: peerInitializationString = @"";
67: }else{
68: peerInitializationString = [NSString stringWithString: s];
69: }
70: [peerInitializationString retain];
71:
72: s = NSLocalizedString(@"PEER_HELP_DIR",nil);
73: if ([s compare: @"PEER_HELP_DIR"] == NSOrderedSame) {
74: // default value
75: peerHelpDir = [OpenXM_HOME stringByAppendingString:
76: @"/doc/cfep/intro-ja.html"];
77: }else{
78: peerHelpDir = [NSString stringWithString: s];
79: }
80: [peerHelpDir retain];
81:
82: s = NSLocalizedString(@"PEER_OPTION_STRING",nil);
83: if ([s compare: @"PEER_OPTION_STRING"] == NSOrderedSame) {
84: // default value
85: if (myPeerType == OX_TEXMACS) peerOptionString = @""; // @" --noWindow ";
86: else peerOptionString =@"";
87: }else{
88: peerOptionString = [NSString stringWithString: s];
89: }
90: [peerOptionString retain];
91:
92: myUnixEnvironment = [NSMutableDictionary dictionaryWithCapacity: 32];
93: [myUnixEnvironment retain];
94: [myUnixEnvironment setObject: OpenXM_HOME forKey: @"OpenXM_HOME"];
95: for (i=0; i< SIZE_e; i++) {
96: s = NSLocalizedString(e[i],nil);
97: if ([s compare: e[i]] == NSOrderedSame) {
98: if (eDefault[i] != nil) {
99: [myUnixEnvironment setObject: eDefault[i] forKey: e[i]];
100: }
101: }else{
102: [myUnixEnvironment setObject: [NSString stringWithString: s]
103: forKey: e[i]];
104: }
105: }
106:
107: s = NSLocalizedString(@"DISPLAY",nil);
108: if ([s compare: @"DISPLAY"] == NSOrderedSame) {
109: if (isXRunning) [myUnixEnvironment setObject: @":0.0" forKey: @"DISPLAY"];
110: }else{
111: [myUnixEnvironment setObject: s forKey: @"DISPLAY"];
112: }
113:
114: s = NSLocalizedString(@"XAUTHORITY",nil);
115: if ([s compare: @"XAUTHORITY"] == NSOrderedSame) {
116: if (isXRunning)
117: [myUnixEnvironment setObject: [NSHomeDirectory() stringByAppendingString: @"/.Xauthority"]
118: forKey: @"XAUTHORITY"];
119: }else{
120: [myUnixEnvironment setObject: s forKey: @"XAUTHORITY"];
121: }
122:
123: s = NSLocalizedString(@"DYLD_LIBRARY_PATH",nil);
124: if ([s compare: @"DYLD_LIBRARY_PATH"] == NSOrderedSame) {
125: [myUnixEnvironment setObject: [OpenXM_HOME stringByAppendingString: @"/lib"]
126: forKey: @"DYLD_LIBRARY_PATH"];
127: }else{
128: [myUnixEnvironment setObject: s forKey: @"DYLD_LIBRARY_PATH"];
129: }
1.2 takayama 130:
131: s = NSHomeDirectory();
132: [myUnixEnvironment setObject: s forKey: @"HOME"];
133:
134: s = NSLocalizedString(@"PATH",nil);
135: if ([s compare: @"PATH"] == NSOrderedSame) {
136: char *path;
137: NSString *defaultPath;
1.5 ! takayama 138: defaultPath=@"/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/sw/bin:/sw/sbin:/usr/local/bin";
1.2 takayama 139: path = getenv("PATH");
140: if (!path) {
141: s = [NSString stringWithCString: path length: strlen(path)];
142: s = [s stringByAppendingString: @":"];
143: s = [s stringByAppendingString: defaultPath];
144: [myUnixEnvironment setObject: s forKey: @"PATH"];
145: } else [myUnixEnvironment setObject: defaultPath forKey: @"PATH"];
146: } else {
147: [myUnixEnvironment setObject: s forKey: @"PATH"];
148: }
149:
1.1 takayama 150:
151: myDefaultTypingAttributes=
152: [NSDictionary dictionaryWithObject: [NSFont fontWithName: @"Courier" size: 12] forKey: @"NSFont"];
153: [myDefaultTypingAttributes retain];
154: // [textViewIn setTypingAttributes: adic];
155:
156:
157: }
158: [self retain];
159: return self;
160: }
161: -(void) dealloc {
162: NSLog(@"dealloc of MyEnvironment.\n");
163: [OpenXM_HOME autorelease]; // or release ?
164: [peerEndEvaluateMark autorelease];
165: [peerStartupString autorelease];
166: [peerInitializationString autorelease];
167: [peerHelpDir autorelease];
168: [peerOptionString autorelease];
169: [myUnixEnvironment autorelease];
170: [super dealloc];
171: }
172: +(int) checkX {
1.4 takayama 173: return 1;
174: // I need a sample code for runningApplications. 2016.09.30
175: /*
1.1 takayama 176: NSEnumerator *apps = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator ];
177: NSDictionary *dicApp;
178: while (dicApp = [apps nextObject]) {
179: if ([@"X11" compare: [dicApp objectForKey: @"NSApplicationName"]] == NSOrderedSame) {
180: NSLog(@"X11 is running.\n");
181: return 1;
182: }
183: }
184: NSLog(@"X11 is NOT running.\n");
185: return 0;
1.4 takayama 186: */
1.1 takayama 187: }
188: -(void) showForDebug {
189: NSLog(@"OpenXM_HOME=%@\n",OpenXM_HOME);
190: NSLog(@"peer=%d\n",peer);
191: NSLog(@"peerEndEvaluateMark=%@\n",peerEndEvaluateMark);
192: NSLog(@"peerStartupString=%@\n",peerStartupString);
193: NSLog(@"peerInitializationString=%@\n",peerInitializationString);
194: NSLog(@"peerHelpDir=%@\n",peerHelpDir);
195: NSLog(@"peerOptionString=%@\n",peerOptionString);
196: NSLog(@"myUnixEnvironment=%@\n",myUnixEnvironment);
197: }
198: -(NSMutableDictionary *) getMyUnixEnvironment {
199: return myUnixEnvironment;
200: }
201: -(enum peer_type) getPeer {
202: return peer;
203: }
204: -(NSData *)getPeerEndEvaluateMark {
205: return peerEndEvaluateMark;
206: }
207: -(NSString *)getOpenXM_HOME {
208: return OpenXM_HOME;
209: }
210: -(NSString *)getPeerStartupString {
211: return peerStartupString;
212: }
213: -(NSString *)getPeerInitializationString {
214: return peerInitializationString;
215: }
216: -(NSString *)getPeerOptionString {
217: return peerOptionString;
218: }
219: -(NSDictionary *)getMyDefaultTypingAttributes {
220: return myDefaultTypingAttributes;
221: }
1.3 takayama 222: +(int) isX11Installed {
223: NSFileManager *manager = [NSFileManager defaultManager];
1.5 ! takayama 224: if ([manager fileExistsAtPath: @"/opt/X11/bin/X"]) return 1;
1.3 takayama 225: else return 0;
226: }
227: +(int) isGccInstalled {
228: NSFileManager *manager = [NSFileManager defaultManager];
229: if ([manager fileExistsAtPath: @"/usr/bin/gcc"]) return 1;
230: else return 0;
231: }
232:
1.1 takayama 233:
234:
235: @end
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>