ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

RexxStartDispatcher.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.oorexx.org/license.html */
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 #include "RexxCore.h"
40 #include "RexxStartDispatcher.hpp"
41 #include "ProtectedObject.hpp"
42 #include "RoutineClass.hpp"
43 #include "SystemInterpreter.hpp"
44 #include "InterpreterInstance.hpp"
45 #include "RexxNativeActivation.hpp"
46 
47 
53 {
54  ProtectedSet savedObjects;
55 
56  // set default return values
57  rc = 0;
58  retcode = 0;
59 
60  RexxString *name = OREF_NULLSTRING; // name of the invoked program
61  RexxString *fullname = name; // default the fulllength name to the simple name
62 
63  if (programName != NULL) /* have an actual name? */
64  {
65  /* get string version of the name */
66  name = new_string(programName);
67  }
68 
69  savedObjects.add(name); /* protect from garbage collect */
70  // get an array version of the arguments and protect
71  RexxArray *new_arglist = new_array(argcount);
72  savedObjects.add(new_arglist);
73 
74  // for compatibility reasons, if this is a command invocation and there is a leading blank
75  // on the only argument, then remove that leading blank from the argument
76  if (calltype == RXCOMMAND && argcount == 1 && arglist[0].strlength > 1 && arglist[0].strptr != NULL && arglist[0].strptr[0] == ' ')
77  {
78  new_arglist->put(new_string(arglist[0].strptr + 1, arglist[0].strlength - 1), 1);
79  }
80  else {
81  /* loop through the argument list */
82  for (size_t i = 0; i < argcount; i++)
83  {
84  /* have a real argument? */
85  if (arglist[i].strptr != NULL)
86  {
87  /* add to the argument array */
88  new_arglist->put(new_string(arglist[i]), i + 1);
89  }
90  }
91  }
92 
93  RexxString *source_calltype;
94 
95  switch (calltype) /* turn calltype into a string */
96  {
97  case RXCOMMAND: /* command invocation */
98  source_calltype = OREF_COMMAND; /* this is the 'COMMAND' string */
99  break;
100 
101  case RXFUNCTION: /* function invocation */
102  /* 'FUNCTION' string */
103  source_calltype = OREF_FUNCTIONNAME;
104  break;
105 
106  case RXSUBROUTINE: /* subroutine invocation */
107  /* 'SUBROUTINE' string */
108  source_calltype = OREF_SUBROUTINE;
109  break;
110 
111  default:
112  source_calltype = OREF_COMMAND; /* this is the 'COMMAND' string */
113  break;
114  }
115 
116  RoutineClass *program = OREF_NULL;
117 
118  if (instore == NULL) /* no instore request? */
119  {
120  /* go resolve the name */
121  fullname = activity->resolveProgramName(name, OREF_NULL, OREF_NULL);
122  if (fullname == OREF_NULL) /* not found? */
123  {
124  /* got an error here */
126  }
127  savedObjects.add(fullname);
128  /* try to restore saved image */
129  program = RoutineClass::fromFile(fullname);
130  }
131  else /* have an instore program */
132  {
133  /* go handle instore parms */
134  program = RoutineClass::processInstore(instore, name);
135  if (program == OREF_NULL) /* couldn't get it? */
136  {
137  /* got an error here */
139  }
140  }
141 
142  RexxString *initial_address = activity->getInstance()->getDefaultEnvironment();
143  /* actually need to run this? */
144  if (program != OREF_NULL)
145  {
146  ProtectedObject program_result;
147  // call the program
148  program->runProgram(activity, source_calltype, initial_address, new_arglist->data(), argcount, program_result);
149  if (result != NULL) /* if return provided for */
150  {
151  /* actually have a result to return? */
152  if ((RexxObject *)program_result != OREF_NULL)
153  {
154  /* force to a string value */
155  program_result = ((RexxObject *)program_result)->stringValue();
156  // copy this into the result RXSTRING
157  ((RexxString *)program_result)->copyToRxstring(*result);
158  }
159  else /* make this an invalid string */
160  {
161  MAKERXSTRING(*result, NULL, 0);
162  }
163  }
164  /* If there is a return val... */
165  if ((RexxObject *)program_result != OREF_NULL)
166  {
167  wholenumber_t return_code;
168 
169  /* if a whole number... */
170  if (((RexxObject *)program_result)->numberValue(return_code) && return_code <= SHRT_MAX && return_code >= SHRT_MIN)
171  {
172  /* ...copy to return code. */
173  retcode = (short)return_code;
174  }
175  }
176  }
177 }
178 
179 
187 {
188  // use the base error handling and set our return code to the negated error code.
190  retcode = (short)rc;
191  // process the error to display the error message.
193 }
194 
195 
196 
201 {
202  if (arguments != OREF_NULL)
203  {
204  // we use a null string for the name when things are called directly
205  routine->call(activity, OREF_NULLSTRING, arguments->data(), arguments->size(), result);
206  }
207  else
208  {
209  // we use a null string for the name when things are called directly
210  routine->call(activity, OREF_NULLSTRING, NULL, 0, result);
211  }
212 }
213 
214 
215 
220 {
221  RexxString *targetName = new_string(program);
222  /* go resolve the name */
224  if (name == OREF_NULL) /* not found? */
225  {
226  /* got an error here */
228  }
229  ProtectedObject p(name);
230  // create a routine from this file
231  RoutineClass *routine = RoutineClass::fromFile(name);
232  p = routine;
233 
234  if (arguments != OREF_NULL)
235  {
236  // use the provided name for the call name
238  }
239  else
240  {
241  // we use a null string for the name when things are called directly
242  routine->runProgram(activity, NULL, 0, result);
243  }
244 }
CallProgramDispatcher::run
virtual void run()
Definition: RexxStartDispatcher.cpp:219
new_array
RexxArray * new_array(size_t s)
Definition: ArrayClass.hpp:250
RexxArray
Definition: ArrayClass.hpp:100
RoutineClass::runProgram
void runProgram(RexxActivity *activity, RexxString *calltype, RexxString *environment, RexxObject **arguments, size_t argCount, ProtectedObject &result)
Definition: RoutineClass.cpp:293
CallRoutineDispatcher::result
ProtectedObject result
Definition: RexxStartDispatcher.hpp:74
ActivityDispatcher::handleError
virtual void handleError(wholenumber_t, RexxDirectory *)
Definition: ActivityDispatcher.cpp:62
ActivityDispatcher::activation
RexxNativeActivation * activation
Definition: ActivityDispatcher.hpp:68
RexxArray::data
RexxObject ** data()
Definition: ArrayClass.hpp:202
RoutineClass.hpp
RoutineClass
Definition: RoutineClass.hpp:49
RexxNativeActivation.hpp
RexxArray::size
size_t size()
Definition: ArrayClass.hpp:200
Error_Program_unreadable_name
#define Error_Program_unreadable_name
Definition: RexxErrorCodes.h:58
reportException
void reportException(wholenumber_t error)
Definition: ActivityManager.hpp:136
CallProgramDispatcher::result
ProtectedObject result
Definition: RexxStartDispatcher.hpp:90
RexxStartDispatcher::calltype
int calltype
Definition: RexxStartDispatcher.hpp:60
RexxActivity::error
wholenumber_t error()
Definition: RexxActivity.cpp:323
RexxStartDispatcher::run
virtual void run()
Definition: RexxStartDispatcher.cpp:52
RexxStartDispatcher.hpp
ProtectedSet
Definition: ProtectedObject.hpp:170
ProtectedSet::add
void add(RexxObject *)
Definition: ProtectedObject.cpp:44
RoutineClass::call
void call(RexxActivity *, RexxString *, RexxObject **, size_t, RexxString *, RexxString *, int, ProtectedObject &)
Definition: RoutineClass.cpp:237
new_string
RexxString * new_string(const char *s, stringsize_t l)
Definition: StringClass.hpp:524
MAKERXSTRING
#define MAKERXSTRING(r, p, l)
Definition: rexx.h:182
SystemInterpreter.hpp
ActivityDispatcher::conditionData
RexxDirectory * conditionData
Definition: ActivityDispatcher.hpp:63
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
CallRoutineDispatcher::routine
RoutineClass * routine
Definition: RexxStartDispatcher.hpp:77
RexxArray::put
void put(RexxObject *eref, size_t pos)
Definition: ArrayClass.cpp:203
CallProgramDispatcher::arguments
RexxArray * arguments
Definition: RexxStartDispatcher.hpp:94
RexxDirectory
Definition: DirectoryClass.hpp:49
ProtectedObject.hpp
ProtectedObject
Definition: ProtectedObject.hpp:46
RXCOMMAND
#define RXCOMMAND
Definition: rexxapidefs.h:64
RexxStartDispatcher::instore
PRXSTRING instore
Definition: RexxStartDispatcher.hpp:58
CallRoutineDispatcher::arguments
RexxArray * arguments
Definition: RexxStartDispatcher.hpp:78
Error_Program_unreadable_notfound
#define Error_Program_unreadable_notfound
Definition: RexxErrorCodes.h:60
RexxStartDispatcher::retcode
short retcode
Definition: RexxStartDispatcher.hpp:61
RexxStartDispatcher::arglist
PCONSTRXSTRING arglist
Definition: RexxStartDispatcher.hpp:56
RexxStartDispatcher::handleError
virtual void handleError(wholenumber_t, RexxDirectory *)
Definition: RexxStartDispatcher.cpp:186
RoutineClass::processInstore
static RoutineClass * processInstore(PRXSTRING instore, RexxString *name)
Definition: RoutineClass.cpp:653
wholenumber_t
ssize_t wholenumber_t
Definition: rexx.h:229
ActivityDispatcher::rc
wholenumber_t rc
Definition: ActivityDispatcher.hpp:62
RXSUBROUTINE
#define RXSUBROUTINE
Definition: rexxapidefs.h:65
RXFUNCTION
#define RXFUNCTION
Definition: rexxapidefs.h:66
ActivityDispatcher::activity
RexxActivity * activity
Definition: ActivityDispatcher.hpp:67
CallProgramDispatcher::program
const char * program
Definition: RexxStartDispatcher.hpp:93
RoutineClass::fromFile
static RoutineClass * fromFile(RexxString *filename)
Definition: RoutineClass.cpp:845
CallRoutineDispatcher::run
virtual void run()
Definition: RexxStartDispatcher.cpp:200
InterpreterInstance.hpp
RexxCore.h
InterpreterInstance::getDefaultEnvironment
RexxString * getDefaultEnvironment()
Definition: InterpreterInstance.hpp:73
RexxStartDispatcher::result
PRXSTRING result
Definition: RexxStartDispatcher.hpp:62
RexxStartDispatcher::argcount
size_t argcount
Definition: RexxStartDispatcher.hpp:55
RexxObject
Definition: ObjectClass.hpp:311
RexxActivity::resolveProgramName
RexxString * resolveProgramName(RexxString *, RexxString *, RexxString *)
Definition: RexxActivity.cpp:3187
RexxStartDispatcher::programName
const char * programName
Definition: RexxStartDispatcher.hpp:57
RexxString
Definition: StringClass.hpp:119
RexxActivity::getInstance
InterpreterInstance * getInstance()
Definition: RexxActivity.hpp:250