[BACK]Return to MyEnvironment.m CVS log [TXT][DIR] Up to [local] / OpenXM / src / cfep

Annotation of OpenXM/src/cfep/MyEnvironment.m, Revision 1.7

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.7     ! takayama  138:         defaultPath=@"/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/opt/local/bin:/opt/local/sbin:/opt/bin:/opt/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.6       takayama  173:     /* still use an deprecated functions */
1.1       takayama  174:   NSEnumerator *apps = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator ];
                    175:   NSDictionary *dicApp;
                    176:   while (dicApp = [apps nextObject]) {
1.6       takayama  177:     if ([@"XQuartz" compare: [dicApp objectForKey: @"NSApplicationName"]] == NSOrderedSame) {
1.1       takayama  178:          NSLog(@"X11 is running.\n");
                    179:          return 1;
                    180:        }
                    181:   }
                    182:   NSLog(@"X11 is NOT running.\n");
1.6       takayama  183:   return 0;
1.1       takayama  184: }
                    185: -(void) showForDebug {
                    186:   NSLog(@"OpenXM_HOME=%@\n",OpenXM_HOME);
                    187:   NSLog(@"peer=%d\n",peer);
                    188:   NSLog(@"peerEndEvaluateMark=%@\n",peerEndEvaluateMark);
                    189:   NSLog(@"peerStartupString=%@\n",peerStartupString);
                    190:   NSLog(@"peerInitializationString=%@\n",peerInitializationString);
                    191:   NSLog(@"peerHelpDir=%@\n",peerHelpDir);
                    192:   NSLog(@"peerOptionString=%@\n",peerOptionString);
                    193:   NSLog(@"myUnixEnvironment=%@\n",myUnixEnvironment);
                    194: }
                    195: -(NSMutableDictionary *) getMyUnixEnvironment {
                    196:   return myUnixEnvironment;
                    197: }
                    198: -(enum peer_type) getPeer {
                    199:   return peer;
                    200: }
                    201: -(NSData *)getPeerEndEvaluateMark {
                    202:   return peerEndEvaluateMark;
                    203: }
                    204: -(NSString *)getOpenXM_HOME {
                    205:   return OpenXM_HOME;
                    206: }
                    207: -(NSString *)getPeerStartupString {
                    208:   return peerStartupString;
                    209: }
                    210: -(NSString *)getPeerInitializationString {
                    211:   return peerInitializationString;
                    212: }
                    213: -(NSString *)getPeerOptionString {
                    214:   return peerOptionString;
                    215: }
                    216: -(NSDictionary *)getMyDefaultTypingAttributes {
                    217:   return myDefaultTypingAttributes;
                    218: }
1.3       takayama  219: +(int) isX11Installed {
                    220:   NSFileManager *manager = [NSFileManager defaultManager];
1.5       takayama  221:   if ([manager fileExistsAtPath: @"/opt/X11/bin/X"]) return 1;
1.3       takayama  222:   else return 0;
                    223: }
                    224: +(int) isGccInstalled {
                    225:   NSFileManager *manager = [NSFileManager defaultManager];
                    226:   if ([manager fileExistsAtPath: @"/usr/bin/gcc"]) return 1;
                    227:   else return 0;
                    228: }
                    229:
1.1       takayama  230:
                    231:
                    232: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>