Annotation of OpenXM/src/cfep/MyEnvironment.m, Revision 1.2
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;
! 138: defaultPath=@"/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/sw/bin:/sw/sbin:/usr/local/bin";
! 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 {
173: NSEnumerator *apps = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator ];
174: NSDictionary *dicApp;
175: while (dicApp = [apps nextObject]) {
176: if ([@"X11" compare: [dicApp objectForKey: @"NSApplicationName"]] == NSOrderedSame) {
177: NSLog(@"X11 is running.\n");
178: return 1;
179: }
180: }
181: NSLog(@"X11 is NOT running.\n");
182: return 0;
183: }
184: -(void) showForDebug {
185: NSLog(@"OpenXM_HOME=%@\n",OpenXM_HOME);
186: NSLog(@"peer=%d\n",peer);
187: NSLog(@"peerEndEvaluateMark=%@\n",peerEndEvaluateMark);
188: NSLog(@"peerStartupString=%@\n",peerStartupString);
189: NSLog(@"peerInitializationString=%@\n",peerInitializationString);
190: NSLog(@"peerHelpDir=%@\n",peerHelpDir);
191: NSLog(@"peerOptionString=%@\n",peerOptionString);
192: NSLog(@"myUnixEnvironment=%@\n",myUnixEnvironment);
193: }
194: -(NSMutableDictionary *) getMyUnixEnvironment {
195: return myUnixEnvironment;
196: }
197: -(enum peer_type) getPeer {
198: return peer;
199: }
200: -(NSData *)getPeerEndEvaluateMark {
201: return peerEndEvaluateMark;
202: }
203: -(NSString *)getOpenXM_HOME {
204: return OpenXM_HOME;
205: }
206: -(NSString *)getPeerStartupString {
207: return peerStartupString;
208: }
209: -(NSString *)getPeerInitializationString {
210: return peerInitializationString;
211: }
212: -(NSString *)getPeerOptionString {
213: return peerOptionString;
214: }
215: -(NSDictionary *)getMyDefaultTypingAttributes {
216: return myDefaultTypingAttributes;
217: }
218:
219:
220: @end
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>