Annotation of OpenXM/src/cfep/MyEnvironment.m, Revision 1.1
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: }
! 130:
! 131: myDefaultTypingAttributes=
! 132: [NSDictionary dictionaryWithObject: [NSFont fontWithName: @"Courier" size: 12] forKey: @"NSFont"];
! 133: [myDefaultTypingAttributes retain];
! 134: // [textViewIn setTypingAttributes: adic];
! 135:
! 136:
! 137: }
! 138: [self retain];
! 139: return self;
! 140: }
! 141: -(void) dealloc {
! 142: NSLog(@"dealloc of MyEnvironment.\n");
! 143: [OpenXM_HOME autorelease]; // or release ?
! 144: [peerEndEvaluateMark autorelease];
! 145: [peerStartupString autorelease];
! 146: [peerInitializationString autorelease];
! 147: [peerHelpDir autorelease];
! 148: [peerOptionString autorelease];
! 149: [myUnixEnvironment autorelease];
! 150: [super dealloc];
! 151: }
! 152: +(int) checkX {
! 153: NSEnumerator *apps = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator ];
! 154: NSDictionary *dicApp;
! 155: while (dicApp = [apps nextObject]) {
! 156: if ([@"X11" compare: [dicApp objectForKey: @"NSApplicationName"]] == NSOrderedSame) {
! 157: NSLog(@"X11 is running.\n");
! 158: return 1;
! 159: }
! 160: }
! 161: NSLog(@"X11 is NOT running.\n");
! 162: return 0;
! 163: }
! 164: -(void) showForDebug {
! 165: NSLog(@"OpenXM_HOME=%@\n",OpenXM_HOME);
! 166: NSLog(@"peer=%d\n",peer);
! 167: NSLog(@"peerEndEvaluateMark=%@\n",peerEndEvaluateMark);
! 168: NSLog(@"peerStartupString=%@\n",peerStartupString);
! 169: NSLog(@"peerInitializationString=%@\n",peerInitializationString);
! 170: NSLog(@"peerHelpDir=%@\n",peerHelpDir);
! 171: NSLog(@"peerOptionString=%@\n",peerOptionString);
! 172: NSLog(@"myUnixEnvironment=%@\n",myUnixEnvironment);
! 173: }
! 174: -(NSMutableDictionary *) getMyUnixEnvironment {
! 175: return myUnixEnvironment;
! 176: }
! 177: -(enum peer_type) getPeer {
! 178: return peer;
! 179: }
! 180: -(NSData *)getPeerEndEvaluateMark {
! 181: return peerEndEvaluateMark;
! 182: }
! 183: -(NSString *)getOpenXM_HOME {
! 184: return OpenXM_HOME;
! 185: }
! 186: -(NSString *)getPeerStartupString {
! 187: return peerStartupString;
! 188: }
! 189: -(NSString *)getPeerInitializationString {
! 190: return peerInitializationString;
! 191: }
! 192: -(NSString *)getPeerOptionString {
! 193: return peerOptionString;
! 194: }
! 195: -(NSDictionary *)getMyDefaultTypingAttributes {
! 196: return myDefaultTypingAttributes;
! 197: }
! 198:
! 199:
! 200: @end
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>