unix/SysInterpreterInstance.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* Implementation of the SysInterpreterInstance class */
40 /* */
41 /******************************************************************************/
42 
43 #include "InterpreterInstance.hpp"
44 #include "SystemInterpreter.hpp"
45 #include "RexxActivation.hpp"
46 
47 
48 /**
49  * Initialize the interpreter instance.
50  *
51  * @param i Our interpreter instance container.
52  * @param options The options used to initialize us. We can add additional
53  * platform-specific options if we wish.
54  */
56 {
57  instance = i;
58 
59  externalTraceEnabled = false; // off by default
60  externalTraceOption = NULL;
61  /* scan current environment, */
62  // value syntax: ON or <traceOption>[:<depth>]
63  // ON is equivalent to ?R
64  // Example of possible values : on i i:10 ?r ?r:10
65  const char *rxTraceBuf = getenv("RXTRACE");
66  if (rxTraceBuf != NULL)
67  {
68  externalTraceOption = (char *)SystemInterpreter::allocateResultMemory(1+strlen(rxTraceBuf));
69  if (externalTraceOption != NULL)
70  {
71  strcpy(externalTraceOption, rxTraceBuf);
72  externalTraceEnabled = true; // turn on tracing of top-level activations for this instance
73  }
74  }
75 
76  // add our default search extension as both upper and lower case
77  addSearchExtension(".REX");
78  addSearchExtension(".rex");
79 }
80 
81 
82 /**
83  * Terminate the interpreter instance.
84  */
86 {
88 }
89 
90 
91 /**
92  * Append a system default extension to the extension search order.
93  *
94  * @param name The name to add.
95  */
97 {
98  // if the extension is not already in the extension list, add it
99  RexxString *ext = new_string(name);
101  {
103  }
104 }
105 
107 /******************************************************************************/
108 /* Function: Do system specific program setup */
109 /******************************************************************************/
110 {
111  // trace this activation if turned on externally when the instance was started
113  {
115  }
116 }
117 
118 /**
119  * Build a search path used for this resolution step.
120  *
121  * @param parentDir The location of the program calling us (can be null).
122  * @param extensionPath
123  * The system extension path (can be null).
124  */
125 SysSearchPath::SysSearchPath(const char *parentDir, const char *extensionPath)
126 {
127  // jlf : dangerous to have 2 successive calls:
128  // The return value from getenv() may point to static data which may be overwritten by subsequent calls to getenv
129  const char *sysPath = getenv("PATH");
130  const char *rexxPath = getenv("REXX_PATH");
131  size_t sysPathSize = sysPath == NULL ? 0 : strlen(sysPath);
132  size_t rexxPathSize = rexxPath == NULL ? 0 : strlen(rexxPath);
133  size_t parentSize = parentDir == NULL ? 0 : strlen(parentDir);
134  size_t extensionSize = extensionPath == NULL ? 0 : strlen(extensionPath);
135 
136 
137  // enough room for separators and a terminating null
138  path = (char *)SystemInterpreter::allocateResultMemory(sysPathSize + rexxPathSize + parentSize + extensionSize + 16);
139  *path = '\0'; // add a null character so strcat can work
140  if (parentDir != NULL)
141  {
142  strcpy(path, parentDir);
143  strcat(path, ":");
144  }
145 
146  // add on the current directory
147  strcat(path, ".:");
148 
149  if (extensionPath != NULL)
150  {
151  strcat(path, extensionPath);
152  if (path[strlen(path) - 1] != ':')
153  {
154  strcat(path, ":");
155  }
156  }
157 
158  // the rexxpath
159  if (rexxPath != NULL)
160  {
161  strcat(path, rexxPath);
162  if (path[strlen(path) - 1] != ':')
163  {
164  strcat(path, ":");
165  }
166  }
167 
168  // and finally the normal path
169  if (sysPath != NULL)
170  {
171  strcat(path, sysPath);
172  if (path[strlen(path) - 1] != ':')
173  {
174  strcat(path, ":");
175  }
176  }
177 }
178 
179 
180 /**
181  * Deconstructor for releasing storage used by the constructed path.
182  */
184 {
186 }
#define TheFalseObject
Definition: RexxCore.h:195
RexxString * new_string(const char *s, stringsize_t l)
void enableExternalTrace(const char *option)
RexxObject * append(RexxObject *)
Definition: ListClass.cpp:538
RexxObject * hasItem(RexxObject *)
Definition: ListClass.cpp:994
void addSearchExtension(const char *name)
void initialize(InterpreterInstance *i, RexxOption *options)
void setupProgram(RexxActivation *activation)
SysSearchPath(const char *parent, const char *extension)
static void * allocateResultMemory(size_t)
static void releaseResultMemory(void *)