| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1993-1994 Anders Christensen <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* This file implements the client part of the SAA API when Regina |
| 22 |
* is linked into a program using SAA API. There is one routine for |
| 23 |
* each of the functions in SAA API, and the functionality is partly |
| 24 |
* implemented here, and partly by calling subroutines in Regina. |
| 25 |
* Note that the interface to Regina is as simple as possible, so that |
| 26 |
* a multitude of different transport mechanisms can be used (although |
| 27 |
* normal linking is probably the most common. |
| 28 |
* |
| 29 |
* The following SAA API functions is defined in this source file: |
| 30 |
* |
| 31 |
* RexxStart() --- execute Rexx code |
| 32 |
* RexxRegisterSubcomExe() --- register subcommand handler |
| 33 |
* RexxRegisterSubcomDll() --- ditto (from dynamic library) |
| 34 |
* RexxQuerySubcom() --- query subcommand handler |
| 35 |
* RexxDeregisterSubcom() --- deregister subcommand handler |
| 36 |
* RexxVariablePool() --- handle Rexx variable manipulation |
| 37 |
* RexxRegisterExitExe() --- register exit handler |
| 38 |
* RexxRegisterExitDll() --- ditto (from dynamic library) |
| 39 |
* RexxDeregisterExit() --- deregister exit handler |
| 40 |
* RexxQueryExit() --- query exit handler |
| 41 |
* RexxRegisterFunctionExe() --- register external function handler |
| 42 |
* RexxRegisterFunctionDll() --- ditto (from dynamic library) |
| 43 |
* RexxQueryFunction() --- query external function |
| 44 |
* RexxDeregisterFunction() --- deregister external function |
| 45 |
* RexxSetHalt() --- set Halt |
| 46 |
* RexxSetTrace() --- set Trace |
| 47 |
* RexxResetTrace() --- reset Trace |
| 48 |
* RexxCreateQueue() --- create named queued |
| 49 |
* RexxDeleteQueue() --- delete named queued |
| 50 |
* RexxQueryQueue() --- query named queued |
| 51 |
* RexxAddQueue() --- add line to named queued |
| 52 |
* RexxPullQueue() --- pull line from named queued |
| 53 |
* RexxAddMacro() --- add a macro to macrospace |
| 54 |
* RexxClearMacroSpace() --- remove all macros from macrospace |
| 55 |
* RexxDropMacro() --- remove macro from macrospace |
| 56 |
* RexxLoadMacroSpace() --- load macrospace macros from file |
| 57 |
* RexxQueryMacro() --- find a macro's search order |
| 58 |
* RexxReorderMacro() --- change the search order for a macro |
| 59 |
* RexxSaveMacroSpace() --- save macrospace to file |
| 60 |
* |
| 61 |
* These functions are Regina extensions |
| 62 |
* RexxFreeMemory() --- free memory allocated by Rexx API |
| 63 |
* RexxAllocateMemory() --- allocate memory to be freed by Rexx API |
| 64 |
* RexxCallBack() --- execute an internal procedure within the running script |
| 65 |
* ReginaVersion() --- version information |
| 66 |
* ReginaCleanup() --- generic cleanup routine |
| 67 |
* |
| 68 |
* These functions are all defined in the doc for SAA API. In addition, |
| 69 |
* a number of calls in Regina are called, as well as a number of calls |
| 70 |
* are defined for use by Regina. These all start with the prefix Ifc. |
| 71 |
* First the one defined in rexxsaa.c, which can be called from other |
| 72 |
* parts of Regina: |
| 73 |
* |
| 74 |
* IfcSubCmd() --- invoke a subcommand |
| 75 |
* IfcDoExit() --- invoke a system exit handler |
| 76 |
* IfcExecFunc() --- invoke an external function handler |
| 77 |
* IfcExecFuncDll() --- invoke an external function handler in a DLL |
| 78 |
* |
| 79 |
* Then the functions which are defined elsewhere, which can be called |
| 80 |
* by this source code: |
| 81 |
* |
| 82 |
* IfcExecScript() --- start to execute Rexx code |
| 83 |
* IfcExecCallBack() --- start to execute Rexx procedure |
| 84 |
* IfcVarPool() --- handle a variable manipulation request |
| 85 |
* IfcRegFunc() --- register an external function name |
| 86 |
* IfcDelFunc() --- deregister an external function name |
| 87 |
* IfcQueryFunc() --- queries an external function name |
| 88 |
* IfcAllocateMemory() --- allocate memory for API user |
| 89 |
* IfcFreeMemory() --- free memory from API user |
| 90 |
* IfcDeleteQueue() --- delete queue |
| 91 |
* IfcAddQueue() --- add a line to the queue |
| 92 |
* IfcPullQueue() --- pull a line off the queue |
| 93 |
* |
| 94 |
* All these routines are properly defined in the documentation for |
| 95 |
* Regina. Other than the functions listed, the code in this file has |
| 96 |
* been isolated as far as possible, and no functions specific to |
| 97 |
* Regina is used, not even for memory allocation. |
| 98 |
*/ |
| 99 |
|
| 100 |
/* |
| 101 |
* We need to define these symbols in order to get the proper macros, |
| 102 |
* datatypes, and declaration when including rexxsaa.h. |
| 103 |
*/ |
| 104 |
#define INCL_RXSHV |
| 105 |
#define INCL_RXSUBCOM |
| 106 |
#define INCL_RXFUNC |
| 107 |
#define INCL_RXSYSEXIT |
| 108 |
#define INCL_RXARI |
| 109 |
#define INCL_RXQUEUE |
| 110 |
#define INCL_RXMACRO |
| 111 |
|
| 112 |
#include "regina_c.h" |
| 113 |
|
| 114 |
#ifdef HAVE_CONFIG_H |
| 115 |
# include "config.h" |
| 116 |
#endif |
| 117 |
|
| 118 |
/* |
| 119 |
* The rexxsaa.h header file defines the interface between this file and |
| 120 |
* the client program which uses SAA API. The rxiface.h header file |
| 121 |
* defines the interface between this file and Regina. |
| 122 |
*/ |
| 123 |
#include "configur.h" |
| 124 |
/* |
| 125 |
* The following #define __REGINA_INTERNAL stops an error with MingW32 |
| 126 |
* |
| 127 |
*/ |
| 128 |
#define __REGINA_INTERNAL |
| 129 |
#include "rexxsaa.h" |
| 130 |
#include "defs.h" |
| 131 |
#define DONT_TYPEDEF_PFN |
| 132 |
#define RXLIB |
| 133 |
#include "rexx.h" |
| 134 |
#if defined(DYNAMIC) && defined(HAVE_GCI) |
| 135 |
# include "gci/gci.h" |
| 136 |
#endif |
| 137 |
#include "rxiface.h" |
| 138 |
#include "extstack.h" |
| 139 |
|
| 140 |
#include <limits.h> |
| 141 |
#include <stdio.h> |
| 142 |
#include <string.h> |
| 143 |
#ifdef HAVE_UNISTD_H |
| 144 |
# include <unistd.h> |
| 145 |
#endif |
| 146 |
#ifdef HAVE_ASSERT_H |
| 147 |
# include <assert.h> |
| 148 |
#endif |
| 149 |
#include <stdlib.h> |
| 150 |
#include <errno.h> |
| 151 |
#include <fcntl.h> |
| 152 |
#include <setjmp.h> |
| 153 |
|
| 154 |
#if defined(__EPOC32__) || defined(__WINS__) |
| 155 |
# ifdef APIRET |
| 156 |
# undef APIRET |
| 157 |
# endif |
| 158 |
# define APIRET unsigned long |
| 159 |
# ifdef APIENTRY |
| 160 |
# undef APIENTRY |
| 161 |
# endif |
| 162 |
#else |
| 163 |
# define EXPORT_C |
| 164 |
#endif |
| 165 |
|
| 166 |
typedef union { |
| 167 |
RXFNCCAL_PARM fnccal ; |
| 168 |
RXCMDHST_PARM cmdhst ; |
| 169 |
RXMSQPLL_PARM msqpll ; |
| 170 |
RXMSQPSH_PARM msqpsh ; |
| 171 |
RXMSQSIZ_PARM msqsiz ; |
| 172 |
RXMSQNAM_PARM msqnam ; |
| 173 |
RXSIOSAY_PARM siosay ; |
| 174 |
RXSIOTRC_PARM siotrc ; |
| 175 |
RXSIOTRD_PARM siotrd ; |
| 176 |
RXSIODTR_PARM siodtr ; |
| 177 |
RXHLTTST_PARM hlttst ; |
| 178 |
RXTRCTST_PARM trctst ; |
| 179 |
RXENVGET_PARM envget ; |
| 180 |
RXENVSET_PARM envset ; |
| 181 |
RXCWDGET_PARM cwdget ; |
| 182 |
RXCWDSET_PARM cwdset ; |
| 183 |
} EXIT ; |
| 184 |
|
| 185 |
/* The following value allows called programs to call "free" to the return |
| 186 |
* parameters without destroying our stack. |
| 187 |
*/ |
| 188 |
#define ILLEGAL_USE_SIZE (8 * sizeof(void *)) |
| 189 |
|
| 190 |
typedef struct { /* rex_tsd: static variables of this module (thread-safe) */ |
| 191 |
struct ExitHandlers *CurrentHandlers ; |
| 192 |
} rex_tsd_t; /* thread-specific but only needed by this module. see |
| 193 |
* init_rexxsaa |
| 194 |
*/ |
| 195 |
|
| 196 |
#define EXT_FUNCS_COUNT (sizeof(rt->saafuncs) / sizeof(rt->saafuncs[0])) |
| 197 |
|
| 198 |
struct ExitHandlers |
| 199 |
{ |
| 200 |
RexxExitHandler *(Handlers[RXNOOFEXITS]) ; /* for RexxRegisterExitExe */ |
| 201 |
struct ExitHandlers *prev ; |
| 202 |
} ; |
| 203 |
|
| 204 |
/* |
| 205 |
* The following RXMAP_TYPE() macro maps from the SAA API macros holding |
| 206 |
* the type of an invocation (function, subroutine or command), to its |
| 207 |
* equivalent value in the internal interface of Regina (as defined in |
| 208 |
* the file rxiface.h |
| 209 |
*/ |
| 210 |
#define RXMAP_TYPE(a) ((a)==RXCOMMAND ? RX_TYPE_COMMAND : \ |
| 211 |
(a)==RXFUNCTION ? RX_TYPE_FUNCTION : RX_TYPE_SUBROUTINE) |
| 212 |
|
| 213 |
|
| 214 |
/* init_rexxsaa initializes the module. |
| 215 |
* Currently, we set up the thread specific data. |
| 216 |
* The function returns 1 on success, 0 if memory is short. |
| 217 |
*/ |
| 218 |
int init_rexxsaa( tsd_t *TSD ) |
| 219 |
{ |
| 220 |
rex_tsd_t *rt; |
| 221 |
|
| 222 |
if (TSD->rex_tsd != NULL) |
| 223 |
return(1); |
| 224 |
|
| 225 |
if ( ( TSD->rex_tsd = MallocTSD( sizeof(rex_tsd_t) ) ) == NULL ) |
| 226 |
return(0); |
| 227 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 228 |
memset( rt, 0, sizeof(rex_tsd_t) ); /* correct for all values */ |
| 229 |
return(1); |
| 230 |
} |
| 231 |
|
| 232 |
/* deinit_rexxsaa deinitializes the module and frees used memory blocks not |
| 233 |
* allocated by the Malloc-Interface. There isn't anything to do currently. |
| 234 |
*/ |
| 235 |
void deinit_rexxsaa( tsd_t *TSD ) |
| 236 |
{ |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
/* StartupInterface initializes the Rexx system once per thread. Values |
| 241 |
* like __regina_get_tsd()->systeminfo are set. The true purpose of this |
| 242 |
* function is to create an environment which allows the run of the |
| 243 |
* interpreter. This is exactly the case when systeminfo exists. The last |
| 244 |
* systeminfo is hopefully never deleted but that won't do any harm if we |
| 245 |
* reinitialize the Rexx environment. |
| 246 |
* |
| 247 |
* There is a three-stage step to let a Rexx program run: |
| 248 |
* 1) Initialize the runtime system and programming environment. This is |
| 249 |
* done by __regina_get_tsd() done in GLOBAL_ENTRY_POINT(). |
| 250 |
* After this call you may use Malloc() and friends: basic things. |
| 251 |
* 2) Initialize the Rexx system. This is done by |
| 252 |
* setup_system() here or directly by any other caller of |
| 253 |
* __regina_faked_main() or main(): |
| 254 |
* You are then allowed to access variables from the variable pool, load |
| 255 |
* a Rexx program or just call a Rexx API function. |
| 256 |
* Hint: The detection of this step is done as follows: |
| 257 |
* Rexx_system_is_running = (__regina_get_tsd()->systeminfo != NULL); |
| 258 |
* or a similar compare. |
| 259 |
* 3) Load the Rexx program in memory. |
| 260 |
* Although you don't know, what program is currently loaded, you can |
| 261 |
* check if a program is loaded (and running) by checking: |
| 262 |
* Program_running = (__regina_get_tsd()->systeminfo->tree.root != NULL); |
| 263 |
* This step is done in RexxStart or by main()/__regina_faked_main() when |
| 264 |
* called as a program. |
| 265 |
* Never use __regina_get_tsd() when it is not needed, of course. |
| 266 |
* This function should be called as GLOBAL_ENTRY_POINT() at the very |
| 267 |
* start of the interpreter but after GLOBAL_ENTRY_POINT. |
| 268 |
*/ |
| 269 |
static void StartupInterface( tsd_t *TSD ) |
| 270 |
{ |
| 271 |
if (TSD->systeminfo != NULL) |
| 272 |
return; |
| 273 |
|
| 274 |
setup_system( TSD, 1 ); |
| 275 |
signal_setup( TSD ); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
/* |
| 280 |
* FillReq prepares a String with a given Length to be exported to an |
| 281 |
* external application. |
| 282 |
* The FillReq() function takes as parameter a pointer to a VarPool() |
| 283 |
* request structure variable, and the definition of a string, and |
| 284 |
* fill the content of the string into the request block. Note that the |
| 285 |
* third parameter is gobbled up, so it can not be used or released by |
| 286 |
* the calling function afterwards. Also, there are two macros defined, |
| 287 |
* which gives a better access to the contents of the function |
| 288 |
*/ |
| 289 |
#define FillReqName(a,b,c) FillReq(a,b,c,1) |
| 290 |
#define FillReqValue(a,b,c) FillReq(a,b,c,0) |
| 291 |
|
| 292 |
static void FillReq( PSHVBLOCK Req, ULONG Length, const char *String, int name ) |
| 293 |
{ |
| 294 |
RXSTRING *string; |
| 295 |
ULONG *strlen; |
| 296 |
|
| 297 |
string = name ? &Req->shvname : &Req->shvvalue; |
| 298 |
strlen = name ? &Req->shvnamelen : &Req->shvvaluelen; |
| 299 |
/* |
| 300 |
* SAA DOCUMENTATION BREAKAGE: |
| 301 |
* As stated in README.08h the OS/2 REXX modifies shvvaluelen instead of |
| 302 |
* shvvalue.strlength (name in the same way). Some software out there |
| 303 |
* relies on this behaviour. Sigh. |
| 304 |
* Thus we assign the shv???len parts too, as ORexx does. |
| 305 |
*/ |
| 306 |
|
| 307 |
/* |
| 308 |
* If the string is undefined, set ->strptr to NULL. It is not required |
| 309 |
* that the lengths parameters are set to zero, but I'll do this as |
| 310 |
* nice gest to the users; someone is probably going to believe that |
| 311 |
* this is how the data is returned. |
| 312 |
* shvnamelen and shvvaluelen are read-only values describing the maximum |
| 313 |
* size of the destination buffer, but see above at SAA DOCUMENTATION. |
| 314 |
*/ |
| 315 |
if ( (LONG)Length == RX_NO_STRING ) |
| 316 |
{ |
| 317 |
MAKERXSTRING( *string, NULL, 0 ); |
| 318 |
*strlen = 0; |
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
/* |
| 323 |
* If a string was supplied, use it, else allocate sufficient space. |
| 324 |
* The then part of the if will just copy the data to the user-supplied |
| 325 |
* return string data area, noting a truncation is one occurred. |
| 326 |
*/ |
| 327 |
if ( RXSTRPTR( *string ) ) |
| 328 |
{ |
| 329 |
/* |
| 330 |
* We need a terminator, therefore we need one byte more for allocation. |
| 331 |
* We may come to the funny situation indicating a truncation but have |
| 332 |
* copied all bytes from the string. |
| 333 |
*/ |
| 334 |
if ( *strlen <= Length ) |
| 335 |
{ |
| 336 |
Req->shvret |= RXSHV_TRUNC; |
| 337 |
Length = *strlen; |
| 338 |
} |
| 339 |
else |
| 340 |
{ |
| 341 |
string->strptr[Length] = '\0'; |
| 342 |
} |
| 343 |
memcpy(string->strptr, String, Length ); |
| 344 |
string->strlength = Length; |
| 345 |
/* |
| 346 |
* shvnamelen and shvvaluelen are read-only values describing the maximum |
| 347 |
* size of the destination buffer, but see above at SAA DOCUMENTATION. |
| 348 |
*/ |
| 349 |
*strlen = Length; |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
/* |
| 354 |
* The else part of the if will allocate new space for the data, and |
| 355 |
* fills in the data, or return a memory fault if data could not |
| 356 |
* properly be allocated. |
| 357 |
* |
| 358 |
* We have to ASCII0-terminate the string silently |
| 359 |
*/ |
| 360 |
string->strptr = (char *)IfcAllocateMemory( Length + 1 ); |
| 361 |
if ( string->strptr ) |
| 362 |
{ |
| 363 |
if ( Length ) |
| 364 |
memcpy( string->strptr, String, Length ); |
| 365 |
string->strptr[Length] = '\0'; |
| 366 |
string->strlength = Length; |
| 367 |
} |
| 368 |
else |
| 369 |
{ |
| 370 |
Req->shvret |= RXSHV_MEMFL; |
| 371 |
/* |
| 372 |
* Set strlength for convenience. |
| 373 |
*/ |
| 374 |
string->strlength = 0; |
| 375 |
Length = 0; |
| 376 |
} |
| 377 |
/* |
| 378 |
* shvnamelen and shvvaluelen are read-only values describing the maximum |
| 379 |
* size of the destination buffer, but see above at SAA DOCUMENTATION. |
| 380 |
*/ |
| 381 |
*strlen = Length; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
/* ======================================================================== */ |
| 386 |
|
| 387 |
/* RetLen and RetStr should point to {0,NULL}. They will be filled with |
| 388 |
* freshly allocated values. A return value will always exist. |
| 389 |
*/ |
| 390 |
int IfcSubCmd( tsd_t *TSD, int EnvLen, const char *EnvStr, |
| 391 |
int CmdLen, const char *CmdStr, |
| 392 |
int *RetLen, char **RetStr ) |
| 393 |
{ |
| 394 |
RXSTRING Cmd, Ret ; |
| 395 |
char *OldResult= NULL ; |
| 396 |
USHORT Flags=0 ; |
| 397 |
char *Command ; |
| 398 |
char *EnvNam; |
| 399 |
struct entry_point *Envir; |
| 400 |
int rvalue=0, RCode=0, rc=RXEXIT_NOT_HANDLED ; |
| 401 |
char subcmd_result[ILLEGAL_USE_SIZE+RXAUTOBUFLEN] ; |
| 402 |
RXCMDHST_PARM cmdhst; |
| 403 |
PUCHAR parm=NULL; |
| 404 |
rex_tsd_t *rt; |
| 405 |
|
| 406 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 407 |
|
| 408 |
Command = (char *)MallocTSD( CmdLen + 1); |
| 409 |
memcpy(Command,CmdStr,CmdLen); |
| 410 |
Command[CmdLen] = '\0'; |
| 411 |
memset( subcmd_result, 0, sizeof( subcmd_result ) ) ; |
| 412 |
MAKERXSTRING( Cmd, Command, CmdLen ) ; |
| 413 |
MAKERXSTRING( Ret, subcmd_result + ILLEGAL_USE_SIZE, RXAUTOBUFLEN) ; |
| 414 |
OldResult = subcmd_result + ILLEGAL_USE_SIZE; |
| 415 |
/* |
| 416 |
* Terminate the command string with nul character |
| 417 |
*/ |
| 418 |
Envir = subcom_hook( TSD, EnvStr , EnvLen ) ; |
| 419 |
if ( rt->CurrentHandlers && rt->CurrentHandlers->Handlers[RXCMD] ) |
| 420 |
{ |
| 421 |
EnvNam = (char *)MallocTSD( EnvLen + 1 ) ; |
| 422 |
memcpy(EnvNam, EnvStr, EnvLen ) ; |
| 423 |
EnvNam[EnvLen] = '\0'; |
| 424 |
cmdhst.rxcmd_flags.rxfcfail = 0; |
| 425 |
cmdhst.rxcmd_flags.rxfcerr = 0; |
| 426 |
cmdhst.rxcmd_command = Cmd ; |
| 427 |
cmdhst.rxcmd_address = (unsigned char *)EnvNam ; |
| 428 |
cmdhst.rxcmd_addressl = (USHORT) EnvLen ; |
| 429 |
cmdhst.rxcmd_retc = Ret; |
| 430 |
cmdhst.rxcmd_dll = NULL; |
| 431 |
cmdhst.rxcmd_dll_len = 0; |
| 432 |
if ( Envir != NULL ) |
| 433 |
{ |
| 434 |
if ( Envir->lib != NULL ) |
| 435 |
{ |
| 436 |
cmdhst.rxcmd_dll = (unsigned char*) Str_val( Envir->lib->name ) ; |
| 437 |
cmdhst.rxcmd_dll_len = (USHORT)Str_len( Envir->lib->name ); |
| 438 |
} |
| 439 |
} |
| 440 |
parm = (PUCHAR)&cmdhst; |
| 441 |
rc = (*(rt->CurrentHandlers->Handlers[RXCMD]))(RXCMD, RXCMDHST, parm); |
| 442 |
TSD->var_indicator = 0; |
| 443 |
assert( rc==RXEXIT_HANDLED || rc==RXEXIT_NOT_HANDLED || |
| 444 |
rc==RXEXIT_RAISE_ERROR ) ; |
| 445 |
if (cmdhst.rxcmd_flags.rxfcerr) |
| 446 |
RCode = RXFLAG_ERROR ; |
| 447 |
else if (cmdhst.rxcmd_flags.rxfcfail) |
| 448 |
RCode = RXFLAG_FAILURE ; |
| 449 |
else |
| 450 |
RCode = RXFLAG_OK; |
| 451 |
Ret = cmdhst.rxcmd_retc; |
| 452 |
FreeTSD( EnvNam ) ; |
| 453 |
} |
| 454 |
if (rc == RXEXIT_NOT_HANDLED) |
| 455 |
{ |
| 456 |
if ( Envir ) |
| 457 |
{ |
| 458 |
RexxSubcomHandler *handler; |
| 459 |
handler = (RexxSubcomHandler *) Envir->addr; |
| 460 |
MAKERXSTRING( Cmd, Command, CmdLen ) ; |
| 461 |
if (Ret.strlength && OldResult != Ret.strptr) /* Ignore return values*/ |
| 462 |
IfcFreeMemory( Ret.strptr ) ; |
| 463 |
MAKERXSTRING( Ret, subcmd_result + ILLEGAL_USE_SIZE, RXAUTOBUFLEN) ; |
| 464 |
OldResult = subcmd_result + ILLEGAL_USE_SIZE ; |
| 465 |
rvalue = handler( &Cmd, &Flags, &Ret ) ; |
| 466 |
TSD->var_indicator = 0; |
| 467 |
if (Flags==RXSUBCOM_OK) |
| 468 |
RCode = RXFLAG_OK ; |
| 469 |
else if (Flags==RXSUBCOM_ERROR) |
| 470 |
RCode = RXFLAG_ERROR ; |
| 471 |
else if (Flags==RXSUBCOM_FAILURE) |
| 472 |
RCode = RXFLAG_FAILURE ; |
| 473 |
else |
| 474 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 475 |
} |
| 476 |
else |
| 477 |
{ |
| 478 |
RCode = RXFLAG_NOTREG ; |
| 479 |
Ret.strlength = 0 ; |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
if (Ret.strlength) |
| 484 |
{ |
| 485 |
*RetLen = Ret.strlength ; |
| 486 |
*RetStr = (char *)MallocTSD( Ret.strlength ) ; |
| 487 |
memcpy( *RetStr, Ret.strptr, Ret.strlength ) ; |
| 488 |
} |
| 489 |
else |
| 490 |
{ |
| 491 |
*RetLen = 1 ; |
| 492 |
*RetStr = (char *)MallocTSD( 1 ) ; |
| 493 |
(*RetStr)[0] = '0' ; |
| 494 |
} |
| 495 |
|
| 496 |
if (Ret.strlength && OldResult != Ret.strptr) |
| 497 |
IfcFreeMemory( Ret.strptr ) ; |
| 498 |
|
| 499 |
FreeTSD(Command); |
| 500 |
return RCode ; |
| 501 |
} |
| 502 |
|
| 503 |
/* IfcDoExit calls an exit handler with one of the following codes set in Code. |
| 504 |
* The arguments may either be input or output or nothing but not both. |
| 505 |
* Parameter INIT TERMIN PULL TRCIN STDOUT STDERR GETENV PUTENV |
| 506 |
* --------------------------------------------------------------------------------------- |
| 507 |
* InputLength NULL NULL set set NULL NULL set NULL |
| 508 |
* InputString NULL NULL set set NULL NULL set NULL |
| 509 |
* OutputLength1 0 0 0 0 set set set set |
| 510 |
* OutputString1 NULL NULL NULL NULL set set set set |
| 511 |
* OutputLength2 0 0 0 0 0 0 0 set |
| 512 |
* OutputString2 NULL NULL NULL NULL NULL NULL NULL set |
| 513 |
* |
| 514 |
* Notes: |
| 515 |
* 1) An output string should always be a fresh copy. Although it is not |
| 516 |
* allowed the user program may destroy the contents. |
| 517 |
* For this reason OutputString is not declared as const. |
| 518 |
* OutputString should be 0-terminated (0 not counted in OutputLength). |
| 519 |
* 2) An input string is normally NOT required. Just provide a position |
| 520 |
* where to place the input to. Example: |
| 521 |
* char *in = NULL; |
| 522 |
* int inlen = 0; |
| 523 |
* IfcDoExit(?,?,0,NULL,0,NULL,&inlen,&in); |
| 524 |
* If the caller of this function provides a valid input string it is |
| 525 |
* ignored on exit. This function always returns back a freshly allocated |
| 526 |
* string in InputString (an empty string in case of errors). |
| 527 |
* 3) The user may change or overwrite the outcome of an exit like the return |
| 528 |
* values to functions. A user-allocated string will be freed. |
| 529 |
*/ |
| 530 |
int IfcDoExit( tsd_t *TSD, int Code, |
| 531 |
int OutputLength1, char *OutputString1, |
| 532 |
int OutputLength2, char *OutputString2, |
| 533 |
int *InputLength, char **InputString ) |
| 534 |
{ |
| 535 |
int rc=0; |
| 536 |
LONG SubCode=0, MainCode=0 ; |
| 537 |
ULONG retlen=0; |
| 538 |
char *retstr=NULL; |
| 539 |
char *mustFree; |
| 540 |
RXSIOSAY_PARM siosay; |
| 541 |
RXSIOTRD_PARM siotrd; |
| 542 |
RXSIODTR_PARM siodtr; |
| 543 |
RXENVSET_PARM envset; |
| 544 |
RXENVGET_PARM envget; |
| 545 |
RXCWDSET_PARM cwdset; |
| 546 |
RXCWDGET_PARM cwdget; |
| 547 |
PEXIT parm=NULL; |
| 548 |
rex_tsd_t *rt; |
| 549 |
|
| 550 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 551 |
|
| 552 |
MAKERXSTRING( siodtr.rxsiodtr_retc, NULL, 0) ; /* Make compiler happy */ |
| 553 |
MAKERXSTRING( siotrd.rxsiotrd_retc, NULL, 0) ; /* Make compiler happy */ |
| 554 |
MAKERXSTRING( envget.rxenv_value, NULL, 0) ; /* Make compiler happy */ |
| 555 |
MAKERXSTRING( cwdget.rxcwd_value, NULL, 0) ; /* Make compiler happy */ |
| 556 |
|
| 557 |
switch (Code) |
| 558 |
{ |
| 559 |
case RX_EXIT_STDERR: |
| 560 |
case RX_EXIT_STDOUT: |
| 561 |
assert(InputLength == NULL && |
| 562 |
InputString == NULL && |
| 563 |
OutputLength2 == 0 && |
| 564 |
OutputString2 == NULL && |
| 565 |
OutputLength2 == 0 && |
| 566 |
OutputString2 == NULL); |
| 567 |
siosay.rxsio_string.strptr = OutputString1 ; |
| 568 |
siosay.rxsio_string.strlength = OutputLength1 ; |
| 569 |
parm = (PEXIT)&siosay; |
| 570 |
SubCode = (Code==RX_EXIT_STDOUT) ? RXSIOSAY : RXSIOTRC ; |
| 571 |
break ; |
| 572 |
|
| 573 |
case RX_EXIT_TRCIN: |
| 574 |
assert(OutputLength1 == 0 && |
| 575 |
OutputString1 == NULL && |
| 576 |
InputLength != NULL && |
| 577 |
InputString != NULL && |
| 578 |
OutputLength2 == 0 && |
| 579 |
OutputString2 == NULL); |
| 580 |
siodtr.rxsiodtr_retc.strlength = *InputLength ; |
| 581 |
siodtr.rxsiodtr_retc.strptr = *InputString ; |
| 582 |
parm = (PEXIT)&siodtr; |
| 583 |
SubCode = RXSIODTR ; |
| 584 |
break ; |
| 585 |
|
| 586 |
case RX_EXIT_PULL: |
| 587 |
assert(OutputLength1 == 0 && |
| 588 |
OutputString1 == NULL && |
| 589 |
InputLength != NULL && |
| 590 |
InputString != NULL && |
| 591 |
OutputLength2 == 0 && |
| 592 |
OutputString2 == NULL); |
| 593 |
siotrd.rxsiotrd_retc.strlength = *InputLength ; |
| 594 |
siotrd.rxsiotrd_retc.strptr = *InputString ; |
| 595 |
parm = (PEXIT)&siotrd; |
| 596 |
SubCode = RXSIOTRD ; |
| 597 |
break ; |
| 598 |
|
| 599 |
case RX_EXIT_INIT: |
| 600 |
assert(OutputLength1 == 0 && |
| 601 |
OutputString1 == NULL && |
| 602 |
InputLength == NULL && |
| 603 |
InputString == NULL && |
| 604 |
OutputLength2 == 0 && |
| 605 |
OutputString2 == NULL); |
| 606 |
SubCode = RXINIEXT ; |
| 607 |
break ; |
| 608 |
|
| 609 |
case RX_EXIT_TERMIN: |
| 610 |
assert(OutputLength1 == 0 && |
| 611 |
OutputString1 == NULL && |
| 612 |
InputLength == NULL && |
| 613 |
InputString == NULL && |
| 614 |
OutputLength2 == 0 && |
| 615 |
OutputString2 == NULL); |
| 616 |
SubCode = RXTEREXT ; |
| 617 |
break ; |
| 618 |
|
| 619 |
case RX_EXIT_SETENV: |
| 620 |
assert(InputLength == NULL && |
| 621 |
InputString == NULL && |
| 622 |
OutputLength1 != 0 && |
| 623 |
OutputString1 != NULL && |
| 624 |
OutputLength2 != 0 && |
| 625 |
OutputString2 != NULL); |
| 626 |
envset.rxenv_name.strptr = OutputString1 ; |
| 627 |
envset.rxenv_name.strlength = OutputLength1 ; |
| 628 |
envset.rxenv_value.strptr = OutputString2 ; |
| 629 |
envset.rxenv_value.strlength = OutputLength2 ; |
| 630 |
parm = (PEXIT)&envset; |
| 631 |
SubCode = RXENVSET ; |
| 632 |
break ; |
| 633 |
|
| 634 |
case RX_EXIT_GETENV: |
| 635 |
assert(OutputLength1 != 0 && |
| 636 |
OutputString1 != NULL && |
| 637 |
InputLength != NULL && |
| 638 |
InputString != NULL && |
| 639 |
OutputLength2 == 0 && |
| 640 |
OutputString2 == NULL); |
| 641 |
envget.rxenv_value.strlength = *InputLength ; |
| 642 |
envget.rxenv_value.strptr = *InputString ; |
| 643 |
envget.rxenv_name.strptr = OutputString1 ; |
| 644 |
envget.rxenv_name.strlength = OutputLength1 ; |
| 645 |
parm = (PEXIT)&envget; |
| 646 |
SubCode = RXENVGET ; |
| 647 |
break ; |
| 648 |
|
| 649 |
case RX_EXIT_SETCWD: |
| 650 |
assert(InputLength == NULL && |
| 651 |
InputString == NULL && |
| 652 |
OutputLength1 != 0 && |
| 653 |
OutputString1 != NULL); |
| 654 |
cwdset.rxcwd_value.strptr = OutputString1 ; |
| 655 |
cwdset.rxcwd_value.strlength = OutputLength1 ; |
| 656 |
parm = (PEXIT)&cwdset; |
| 657 |
SubCode = RXCWDSET ; |
| 658 |
break ; |
| 659 |
|
| 660 |
case RX_EXIT_GETCWD: |
| 661 |
assert(OutputLength1 == 0 && |
| 662 |
OutputString1 == NULL && |
| 663 |
InputLength != NULL && |
| 664 |
InputString != NULL && |
| 665 |
OutputLength2 == 0 && |
| 666 |
OutputString2 == NULL); |
| 667 |
cwdget.rxcwd_value.strlength = *InputLength ; |
| 668 |
cwdget.rxcwd_value.strptr = *InputString ; |
| 669 |
parm = (PEXIT)&cwdget; |
| 670 |
SubCode = RXCWDGET ; |
| 671 |
break ; |
| 672 |
|
| 673 |
default: |
| 674 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 675 |
break; |
| 676 |
} |
| 677 |
MainCode = IfcMapExits( Code ); |
| 678 |
|
| 679 |
//assert( rt->CurrentHandlers->Handlers[MainCode] ) ; |
| 680 |
if ( rt->CurrentHandlers->Handlers[MainCode] ) |
| 681 |
{ |
| 682 |
|
| 683 |
rc = (*(rt->CurrentHandlers->Handlers[MainCode]))(MainCode, SubCode, parm); |
| 684 |
TSD->var_indicator = 0; |
| 685 |
} |
| 686 |
else |
| 687 |
{ |
| 688 |
rc = RXEXIT_NOT_HANDLED; |
| 689 |
} |
| 690 |
assert( rc==RXEXIT_HANDLED || rc==RXEXIT_NOT_HANDLED || |
| 691 |
rc==RXEXIT_RAISE_ERROR ) ; |
| 692 |
|
| 693 |
mustFree = NULL; |
| 694 |
switch (Code) |
| 695 |
{ |
| 696 |
case RX_EXIT_STDERR: |
| 697 |
case RX_EXIT_STDOUT: |
| 698 |
case RX_EXIT_INIT: |
| 699 |
case RX_EXIT_TERMIN: |
| 700 |
case RX_EXIT_SETENV: |
| 701 |
case RX_EXIT_SETCWD: |
| 702 |
break ; |
| 703 |
|
| 704 |
case RX_EXIT_TRCIN: |
| 705 |
retlen = siodtr.rxsiodtr_retc.strlength ; |
| 706 |
retstr = siodtr.rxsiodtr_retc.strptr ; |
| 707 |
mustFree = ( retstr != *InputString ) ? retstr : NULL; |
| 708 |
break ; |
| 709 |
|
| 710 |
case RX_EXIT_PULL: |
| 711 |
retlen = siotrd.rxsiotrd_retc.strlength ; |
| 712 |
retstr = siotrd.rxsiotrd_retc.strptr ; |
| 713 |
mustFree = ( retstr != *InputString ) ? retstr : NULL; |
| 714 |
break ; |
| 715 |
|
| 716 |
case RX_EXIT_GETENV: |
| 717 |
retlen = envget.rxenv_value.strlength ; |
| 718 |
retstr = envget.rxenv_value.strptr ; |
| 719 |
mustFree = ( retstr != *InputString ) ? retstr : NULL; |
| 720 |
break ; |
| 721 |
|
| 722 |
case RX_EXIT_GETCWD: |
| 723 |
retlen = cwdget.rxcwd_value.strlength ; |
| 724 |
retstr = cwdget.rxcwd_value.strptr ; |
| 725 |
mustFree = ( retstr != *InputString ) ? retstr : NULL; |
| 726 |
break ; |
| 727 |
|
| 728 |
default: |
| 729 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 730 |
} |
| 731 |
|
| 732 |
if (rc==RXEXIT_HANDLED) |
| 733 |
rc = RX_HOOK_NOPE ; |
| 734 |
else if (rc==RXEXIT_NOT_HANDLED) |
| 735 |
rc = RX_HOOK_GO_ON ; |
| 736 |
else if (rc==RXEXIT_RAISE_ERROR) |
| 737 |
rc = RX_HOOK_ERROR ; |
| 738 |
|
| 739 |
if (InputLength != NULL) /* retlen and retstr forms a return string. */ |
| 740 |
{ |
| 741 |
if ((retlen == 0) || (retstr == NULL)) |
| 742 |
{ |
| 743 |
retlen = 0; |
| 744 |
retstr = ""; |
| 745 |
} |
| 746 |
|
| 747 |
/* Make a fresh copy, the user may change the value very fast. */ |
| 748 |
*InputString = (char *)MallocTSD( (retlen < 1) ? 1 : retlen ); |
| 749 |
memcpy(*InputString, retstr, retlen); |
| 750 |
*InputLength = retlen; |
| 751 |
} |
| 752 |
|
| 753 |
if ( mustFree ) |
| 754 |
IfcFreeMemory( mustFree ); |
| 755 |
return rc ; |
| 756 |
} |
| 757 |
|
| 758 |
/* ================================================================ */ |
| 759 |
/* ================ general purpose API functions ================= */ |
| 760 |
|
| 761 |
/* You are not allowed to use TSD or __regina_get_tsd() here! */ |
| 762 |
EXPORT_C APIRET APIENTRY RexxFreeMemory(PVOID MemoryBlock ) |
| 763 |
{ |
| 764 |
if (!MemoryBlock) |
| 765 |
return RXFUNC_BADTYPE; |
| 766 |
|
| 767 |
return IfcFreeMemory( MemoryBlock ); |
| 768 |
} |
| 769 |
|
| 770 |
/* You are not allowed to use TSD or __regina_get_tsd() here! */ |
| 771 |
EXPORT_C PVOID APIENTRY RexxAllocateMemory(ULONG size ) |
| 772 |
{ |
| 773 |
return IfcAllocateMemory( size ); |
| 774 |
} |
| 775 |
|
| 776 |
/* ================================================================ */ |
| 777 |
/* ================ in order to start Rexx scripts ================ */ |
| 778 |
|
| 779 |
EXPORT_C APIRET APIENTRY RexxStart(LONG ArgCount, |
| 780 |
PRXSTRING ArgList, |
| 781 |
PCSZ ProgName, |
| 782 |
PRXSTRING Instore, |
| 783 |
PCSZ EnvName, |
| 784 |
LONG CallType, |
| 785 |
PRXSYSEXIT Exits, |
| 786 |
PSHORT ReturnCode, |
| 787 |
PRXSTRING Result ) |
| 788 |
{ |
| 789 |
int cnt, RLength; |
| 790 |
char *RString; |
| 791 |
int ParLengths[MAX_ARGS_TO_REXXSTART]; |
| 792 |
const char *ParStrings[MAX_ARGS_TO_REXXSTART]; |
| 793 |
int ExitFlags; |
| 794 |
int EnvNamLen; |
| 795 |
const char *EnvNamStr; |
| 796 |
int WhereCode,rc; |
| 797 |
const char *SourcePtr; |
| 798 |
const void *TinPtr; |
| 799 |
unsigned long SourceLen,TinLen; |
| 800 |
struct ExitHandlers *Handlers; |
| 801 |
RexxExitHandler *handler; |
| 802 |
struct entry_point *EnvPtr; |
| 803 |
unsigned long instore_length; |
| 804 |
void *instore_buf; |
| 805 |
PCSZ ProgramName=ProgName; |
| 806 |
tsd_t *TSD; |
| 807 |
rex_tsd_t *rt; |
| 808 |
int restricted = 0; |
| 809 |
|
| 810 |
TSD = GLOBAL_ENTRY_POINT(); |
| 811 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 812 |
StartupInterface( TSD ); |
| 813 |
|
| 814 |
if ( ( ArgCount < 0 ) || ( ( ArgCount > 0 ) && ( ArgList == NULL ) ) ) |
| 815 |
return RXFUNC_BADTYPE; |
| 816 |
if ( !ProgName ) |
| 817 |
return RXFUNC_BADTYPE; |
| 818 |
/* |
| 819 |
* Check if running in restricted mode first. |
| 820 |
*/ |
| 821 |
if ( CallType & RXRESTRICTED ) |
| 822 |
{ |
| 823 |
restricted = 1; |
| 824 |
CallType -= RXRESTRICTED; |
| 825 |
} |
| 826 |
if ( ( CallType != RXCOMMAND ) && |
| 827 |
( CallType != RXSUBROUTINE ) && |
| 828 |
( CallType != RXFUNCTION ) ) |
| 829 |
return RXFUNC_BADTYPE; |
| 830 |
if ( ( CallType == RXCOMMAND ) && ( ArgCount > 1 ) ) |
| 831 |
return RX_START_TOOMANYP; |
| 832 |
if ( ArgCount > (int) ( sizeof( ParLengths ) / sizeof( ParLengths[0] ) ) ) |
| 833 |
return RX_START_TOOMANYP; |
| 834 |
|
| 835 |
if ( Instore ) |
| 836 |
{ |
| 837 |
if ( Instore[1].strptr && ( Instore[1].strlength < 1 ) ) |
| 838 |
return RX_START_BADP; |
| 839 |
} |
| 840 |
|
| 841 |
for ( cnt = 0; cnt < ArgCount; cnt++ ) |
| 842 |
{ |
| 843 |
ParLengths[cnt] = ArgList[cnt].strlength; |
| 844 |
ParStrings[cnt] = ArgList[cnt].strptr; |
| 845 |
if ( ParStrings[cnt] == NULL ) |
| 846 |
ParLengths[cnt] = RX_NO_STRING; |
| 847 |
} |
| 848 |
|
| 849 |
if ( Result != NULL ) |
| 850 |
{ |
| 851 |
RLength = (int) RXSTRLEN( *Result ); |
| 852 |
if ( ( RString = RXSTRPTR( *Result ) ) == NULL ) |
| 853 |
RLength = RX_NO_STRING; |
| 854 |
} |
| 855 |
else |
| 856 |
{ |
| 857 |
RString = NULL; |
| 858 |
RLength = RX_NO_STRING; |
| 859 |
} |
| 860 |
|
| 861 |
Handlers = (struct ExitHandlers *)TSD->MTMalloc( TSD, sizeof( struct ExitHandlers ) ); |
| 862 |
Handlers->prev = rt->CurrentHandlers; |
| 863 |
rt->CurrentHandlers = Handlers; |
| 864 |
for ( cnt = 0; cnt < RXNOOFEXITS; cnt++ ) |
| 865 |
rt->CurrentHandlers->Handlers[cnt] = NULL; |
| 866 |
|
| 867 |
ExitFlags = 0; |
| 868 |
for ( cnt = 0; Exits && ( Exits->sysexit_code != RXENDLST ); Exits++ ) |
| 869 |
{ |
| 870 |
if ( ( Exits->sysexit_name == NULL ) |
| 871 |
|| ( strlen( Exits->sysexit_name ) == 0 ) ) |
| 872 |
return RX_START_BADP; |
| 873 |
|
| 874 |
EnvPtr = exit_hook( TSD, Exits->sysexit_name, |
| 875 |
strlen( Exits->sysexit_name ) ); |
| 876 |
if ( !EnvPtr ) |
| 877 |
continue; |
| 878 |
|
| 879 |
handler = (RexxExitHandler *) EnvPtr->addr; |
| 880 |
switch ( Exits->sysexit_code ) |
| 881 |
{ |
| 882 |
case RXSIO: |
| 883 |
ExitFlags |= ( 1 << RX_EXIT_STDOUT ) | ( 1 << RX_EXIT_STDERR ) | |
| 884 |
( 1 << RX_EXIT_TRCIN ) | ( 1 << RX_EXIT_PULL ); |
| 885 |
rt->CurrentHandlers->Handlers[RXSIO] = handler; |
| 886 |
break ; |
| 887 |
|
| 888 |
case RXINI: |
| 889 |
ExitFlags |= 1 << RX_EXIT_INIT; |
| 890 |
rt->CurrentHandlers->Handlers[RXINI] = handler; |
| 891 |
break ; |
| 892 |
|
| 893 |
case RXTER: |
| 894 |
ExitFlags |= 1 << RX_EXIT_TERMIN; |
| 895 |
rt->CurrentHandlers->Handlers[RXTER] = handler; |
| 896 |
break; |
| 897 |
|
| 898 |
case RXCMD: |
| 899 |
ExitFlags |= 1 << RX_EXIT_SUBCOM; |
| 900 |
rt->CurrentHandlers->Handlers[RXCMD] = handler; |
| 901 |
break; |
| 902 |
|
| 903 |
case RXFNC: |
| 904 |
ExitFlags |= 1 << RX_EXIT_FUNC; |
| 905 |
rt->CurrentHandlers->Handlers[RXFNC] = handler; |
| 906 |
break; |
| 907 |
|
| 908 |
case RXENV: |
| 909 |
ExitFlags |= ( 1 << RX_EXIT_GETENV ) | ( 1 << RX_EXIT_SETENV ) | |
| 910 |
( 1 << RX_EXIT_GETCWD ) | ( 1 << RX_EXIT_SETCWD ); |
| 911 |
rt->CurrentHandlers->Handlers[RXENV] = handler; |
| 912 |
break; |
| 913 |
|
| 914 |
default: |
| 915 |
return RX_START_BADP; |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
if ( EnvName ) |
| 920 |
{ |
| 921 |
EnvNamLen = strlen( EnvName ); |
| 922 |
EnvNamStr = EnvName; |
| 923 |
} |
| 924 |
else |
| 925 |
{ |
| 926 |
EnvNamLen = RX_NO_STRING; |
| 927 |
EnvNamStr = NULL; |
| 928 |
} |
| 929 |
|
| 930 |
SourcePtr = NULL; |
| 931 |
SourceLen = 0; |
| 932 |
TinPtr = NULL; |
| 933 |
TinLen = 0; |
| 934 |
if ( Instore && Instore[1].strptr ) |
| 935 |
{ |
| 936 |
WhereCode = RX_TYPE_INSTORE; |
| 937 |
TinPtr = Instore[1].strptr; |
| 938 |
TinLen = Instore[1].strlength; |
| 939 |
SourcePtr = Instore[0].strptr; |
| 940 |
SourceLen = Instore[0].strlength; |
| 941 |
} |
| 942 |
else if ( Instore && Instore[0].strptr ) |
| 943 |
{ |
| 944 |
WhereCode = RX_TYPE_SOURCE; |
| 945 |
SourcePtr = Instore[0].strptr; |
| 946 |
SourceLen = Instore[0].strlength; |
| 947 |
} |
| 948 |
else if ( Instore ) |
| 949 |
WhereCode = RX_TYPE_MACRO; |
| 950 |
else |
| 951 |
WhereCode = RX_TYPE_EXTERNAL; |
| 952 |
|
| 953 |
starttrace( TSD ); |
| 954 |
|
| 955 |
rc = IfcExecScript( TSD, strlen(ProgramName), ProgramName, |
| 956 |
ArgCount, ParLengths, (const char **) ParStrings, |
| 957 |
RXMAP_TYPE( CallType ), ExitFlags, EnvNamLen, EnvNamStr, |
| 958 |
WhereCode, restricted, SourcePtr, SourceLen, |
| 959 |
TinPtr, TinLen, &RLength, &RString, |
| 960 |
&instore_buf, &instore_length); |
| 961 |
Handlers = rt->CurrentHandlers; |
| 962 |
rt->CurrentHandlers = Handlers->prev; |
| 963 |
TSD->MTFree( TSD, Handlers ); |
| 964 |
|
| 965 |
if ( WhereCode == RX_TYPE_SOURCE ) |
| 966 |
{ |
| 967 |
Instore[1].strptr = (char *)instore_buf; |
| 968 |
Instore[1].strlength = instore_length; |
| 969 |
} |
| 970 |
|
| 971 |
if ( ReturnCode ) |
| 972 |
{ |
| 973 |
if ( RLength > 0 ) |
| 974 |
*ReturnCode = (SHORT) atoi( RString ); |
| 975 |
else |
| 976 |
*ReturnCode = 0; |
| 977 |
} |
| 978 |
|
| 979 |
if ( Result != NULL ) |
| 980 |
{ |
| 981 |
MAKERXSTRING( *Result, RString, RLength ); |
| 982 |
} |
| 983 |
else |
| 984 |
{ |
| 985 |
if ( RString != NULL ) |
| 986 |
IfcFreeMemory( RString ); |
| 987 |
} |
| 988 |
|
| 989 |
/* |
| 990 |
* Close all open files. |
| 991 |
*/ |
| 992 |
CloseOpenFiles( TSD, fpdCLEAR ); |
| 993 |
if ( TSD->systeminfo->input_file != NULL ) |
| 994 |
{ |
| 995 |
Free_stringTSD( TSD->systeminfo->input_file ); |
| 996 |
TSD->systeminfo->input_file = NULL; |
| 997 |
} |
| 998 |
free_orphaned_libs( TSD ); |
| 999 |
|
| 1000 |
return rc; |
| 1001 |
} |
| 1002 |
|
| 1003 |
/* |
| 1004 |
* In opposite to the documentation we accept a NULL parameter of Result |
| 1005 |
* silently. |
| 1006 |
*/ |
| 1007 |
EXPORT_C APIRET APIENTRY RexxCallBack( PCSZ ProcedureName, |
| 1008 |
LONG ArgCount, |
| 1009 |
PRXSTRING ArgList, |
| 1010 |
PSHORT ReturnCode, |
| 1011 |
PRXSTRING Result ) |
| 1012 |
{ |
| 1013 |
int rc, cnt, RLength; |
| 1014 |
char *RString; |
| 1015 |
int ParLengths[MAX_ARGS_TO_REXXSTART]; |
| 1016 |
const char *ParStrings[MAX_ARGS_TO_REXXSTART]; |
| 1017 |
tsd_t *TSD; |
| 1018 |
|
| 1019 |
/* |
| 1020 |
* This can only be called with an active Rexx session running |
| 1021 |
* and from the same thread as the interpreter is running in |
| 1022 |
* The above is true UNLESS you have userd OPTIONS SINGLE_INTERPRETER |
| 1023 |
*/ |
| 1024 |
TSD = getGlobalTSD(); |
| 1025 |
if ( TSD == NULL ) |
| 1026 |
TSD = __regina_get_tsd(); |
| 1027 |
|
| 1028 |
if ( TSD == NULL || TSD->systeminfo == NULL ) |
| 1029 |
return RX_CB_NOTSTARTED; |
| 1030 |
|
| 1031 |
if ( ( ArgCount < 0 ) || ( ( ArgCount > 0 ) && ( ArgList == NULL ) ) ) |
| 1032 |
return RX_CB_BADP; |
| 1033 |
if ( !ProcedureName ) |
| 1034 |
return RX_CB_BADP; |
| 1035 |
|
| 1036 |
if (ArgCount > (int) (sizeof( ParLengths ) / sizeof( ParLengths[0] ) ) ) |
| 1037 |
return RX_CB_TOOMANYP; |
| 1038 |
|
| 1039 |
for ( cnt = 0; cnt < ArgCount; cnt++ ) |
| 1040 |
{ |
| 1041 |
ParLengths[cnt] = (int) RXSTRLEN( ArgList[cnt] ); |
| 1042 |
ParStrings[cnt] = RXSTRPTR( ArgList[cnt] ); |
| 1043 |
if ( ParStrings[cnt] == NULL ) |
| 1044 |
ParLengths[cnt] = RX_NO_STRING; |
| 1045 |
} |
| 1046 |
if ( Result != NULL ) |
| 1047 |
{ |
| 1048 |
RLength = (int) RXSTRLEN( *Result ); |
| 1049 |
if ( ( RString = RXSTRPTR( *Result ) ) == NULL ) |
| 1050 |
RLength = RX_NO_STRING; |
| 1051 |
} |
| 1052 |
else |
| 1053 |
{ |
| 1054 |
RString = NULL; |
| 1055 |
RLength = RX_NO_STRING; |
| 1056 |
} |
| 1057 |
|
| 1058 |
rc = IfcExecCallBack( TSD, strlen(ProcedureName), ProcedureName, |
| 1059 |
ArgCount, ParLengths, (const char **) ParStrings, |
| 1060 |
&RLength, &RString ); |
| 1061 |
if ( rc == RX_CODE_NOSUCH ) |
| 1062 |
rc = RX_CB_BADN; |
| 1063 |
|
| 1064 |
/* |
| 1065 |
* Determine numeric return code and pass it back |
| 1066 |
*/ |
| 1067 |
if ( ReturnCode ) |
| 1068 |
{ |
| 1069 |
if ( RLength > 0 ) |
| 1070 |
*ReturnCode = (SHORT) atoi( RString ); |
| 1071 |
else |
| 1072 |
*ReturnCode = 0; |
| 1073 |
} |
| 1074 |
|
| 1075 |
/* |
| 1076 |
* Determine text return code and pass it back |
| 1077 |
*/ |
| 1078 |
if ( Result != NULL ) |
| 1079 |
{ |
| 1080 |
MAKERXSTRING( *Result, RString, RLength ); |
| 1081 |
} |
| 1082 |
else |
| 1083 |
{ |
| 1084 |
if ( RString != NULL ) |
| 1085 |
IfcFreeMemory( RString ); |
| 1086 |
} |
| 1087 |
|
| 1088 |
return rc; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
/* ============================================================= */ |
| 1093 |
/* subcom handler subsystem */ |
| 1094 |
|
| 1095 |
EXPORT_C APIRET APIENTRY RexxRegisterSubcomExe(PCSZ EnvName, |
| 1096 |
#ifdef RX_WEAKTYPING |
| 1097 |
PFN EntryPoint, |
| 1098 |
#else |
| 1099 |
RexxSubcomHandler *EntryPoint, |
| 1100 |
#endif |
| 1101 |
PUCHAR UserArea ) |
| 1102 |
{ |
| 1103 |
tsd_t *TSD = getGlobalTSD(); |
| 1104 |
|
| 1105 |
if ( TSD == NULL ) |
| 1106 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1107 |
StartupInterface( TSD ); |
| 1108 |
|
| 1109 |
/* |
| 1110 |
* Perform sanity check on the parameters; UserArea may be NULL |
| 1111 |
*/ |
| 1112 |
if ( !EnvName || !EntryPoint ) |
| 1113 |
return RXSUBCOM_BADTYPE; |
| 1114 |
|
| 1115 |
return IfcRegSubcom( TSD, EnvName, NULL, NULL, (PFN)EntryPoint, UserArea ); |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
EXPORT_C APIRET APIENTRY RexxRegisterSubcomDll(PCSZ EnvName, |
| 1120 |
PCSZ ModuleName, |
| 1121 |
PCSZ ProcedureName, |
| 1122 |
PUCHAR UserArea, |
| 1123 |
ULONG DropAuth ) |
| 1124 |
{ |
| 1125 |
tsd_t *TSD = getGlobalTSD(); |
| 1126 |
|
| 1127 |
if ( TSD == NULL ) |
| 1128 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1129 |
StartupInterface( TSD ); |
| 1130 |
|
| 1131 |
if ( !EnvName || !ModuleName || !ProcedureName ) |
| 1132 |
return RXSUBCOM_BADTYPE; |
| 1133 |
if ( ( DropAuth != RXSUBCOM_DROPPABLE ) && ( DropAuth != RXSUBCOM_NONDROP ) ) |
| 1134 |
return RXSUBCOM_BADTYPE; |
| 1135 |
|
| 1136 |
return IfcRegSubcom( TSD, EnvName, ModuleName, ProcedureName, NULL, |
| 1137 |
UserArea ); |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
EXPORT_C APIRET APIENTRY RexxQuerySubcom(PCSZ EnvName, |
| 1142 |
PCSZ ModuleName, |
| 1143 |
PUSHORT Flag, |
| 1144 |
PUCHAR UserWord ) |
| 1145 |
{ |
| 1146 |
int ret; |
| 1147 |
tsd_t *TSD = getGlobalTSD(); |
| 1148 |
|
| 1149 |
if ( TSD == NULL ) |
| 1150 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1151 |
StartupInterface( TSD ); |
| 1152 |
|
| 1153 |
if ( !EnvName || !Flag || !Flag ) |
| 1154 |
return RXSUBCOM_BADTYPE; |
| 1155 |
|
| 1156 |
if ( ( ret = IfcQuerySubcom( TSD, EnvName, ModuleName, UserWord ) ) == |
| 1157 |
RXSUBCOM_OK ) |
| 1158 |
*Flag = RXSUBCOM_ISREG; |
| 1159 |
else |
| 1160 |
*Flag = 0; |
| 1161 |
|
| 1162 |
return ret; |
| 1163 |
} |
| 1164 |
|
| 1165 |
EXPORT_C APIRET APIENTRY RexxDeregisterSubcom(PCSZ EnvName, |
| 1166 |
PCSZ ModuleName ) |
| 1167 |
{ |
| 1168 |
tsd_t *TSD = getGlobalTSD(); |
| 1169 |
|
| 1170 |
if ( TSD == NULL ) |
| 1171 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1172 |
StartupInterface( TSD ); |
| 1173 |
|
| 1174 |
if ( !EnvName ) |
| 1175 |
return RXSUBCOM_BADTYPE; |
| 1176 |
|
| 1177 |
return IfcDelSubcom( TSD, EnvName, ModuleName ); |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
/* ============================================================ */ |
| 1183 |
/* Variable subsystem */ |
| 1184 |
/* JH 20-10-99 */ /* To make Direct setting of stems Direct and not Symbolic. */ |
| 1185 |
/**************************************************************************** |
| 1186 |
* |
| 1187 |
* JH 13/12/1999 (Original code changes on 20/10/1999) |
| 1188 |
* |
| 1189 |
* BUG022 To make Direct setting of stems Direct and not Symbolic. |
| 1190 |
* - Added checks for the direct variable functions RX_GETVAR and RX_SETVAR. |
| 1191 |
* In the switch that determines what to do, based on the value passed in |
| 1192 |
* shvcode, symbolics still fall through to the code that is under the |
| 1193 |
* direct labels, but it sets a variable to denote that symbolic processing |
| 1194 |
* is to take place. The direct section only sets this variable if it has |
| 1195 |
* not been set before. |
| 1196 |
* - Added new variable IVPcode (IfcVariablePool) that will contain the code |
| 1197 |
* used to call IfcVariablePool(), instead of hard coding the parameter, |
| 1198 |
* |
| 1199 |
* NB that this routine lumps the Drop's and Set's together, before calling |
| 1200 |
* IfcVarPool(). At some point it might be better to pass the shvcode |
| 1201 |
* value, rather than translating it and later performing additional |
| 1202 |
* checks to split it back out. |
| 1203 |
* |
| 1204 |
****************************************************************************/ |
| 1205 |
EXPORT_C APIRET APIENTRY RexxVariablePool(PSHVBLOCK RequestBlockList ) |
| 1206 |
{ |
| 1207 |
int Code=0, RetCode=0, IVPcode; |
| 1208 |
int Lengths[2] ; |
| 1209 |
int rc=0, allocated ; |
| 1210 |
char *Strings[2] ; |
| 1211 |
PSHVBLOCK Req=RequestBlockList ; |
| 1212 |
rex_tsd_t *rt; |
| 1213 |
tsd_t *TSD = getGlobalTSD(); |
| 1214 |
|
| 1215 |
if ( TSD == NULL ) |
| 1216 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1217 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 1218 |
StartupInterface(TSD); |
| 1219 |
|
| 1220 |
if (!RequestBlockList) /* FGC: I assume we must have at least one param */ |
| 1221 |
return RXFUNC_BADTYPE; |
| 1222 |
|
| 1223 |
if (TSD->systeminfo->tree.root==NULL) /* Doesn't the interpreter run? */ |
| 1224 |
return RXSHV_NOAVL ; |
| 1225 |
|
| 1226 |
RetCode = 0 ; |
| 1227 |
|
| 1228 |
for (;Req;Req=Req->shvnext) |
| 1229 |
{ |
| 1230 |
IVPcode = 0; /* Needed for a correct IVPcode on a second request */ |
| 1231 |
allocated = 0; |
| 1232 |
switch (Req->shvcode) |
| 1233 |
{ |
| 1234 |
case RXSHV_SYDRO: |
| 1235 |
case RXSHV_SYSET: |
| 1236 |
IVPcode = RX_SETSVAR; /* JH 20-10-99 */ |
| 1237 |
case RXSHV_DROPV: /* MH 26-12-95 */ |
| 1238 |
case RXSHV_SET: /* MH 26-12-95 */ |
| 1239 |
{ |
| 1240 |
IVPcode = IVPcode ? IVPcode : RX_SETVAR; /* JH 20-10-99 */ |
| 1241 |
Lengths[0] = Req->shvname.strlength ; |
| 1242 |
Strings[0] = Req->shvname.strptr ; |
| 1243 |
if (Req->shvcode==RXSHV_SYSET /* MH 26-12-95 */ |
| 1244 |
|| Req->shvcode==RXSHV_SET) /* MH 26-12-95 */ |
| 1245 |
{ |
| 1246 |
Lengths[1] = Req->shvvalue.strlength ; |
| 1247 |
Strings[1] = Req->shvvalue.strptr ; |
| 1248 |
} |
| 1249 |
else |
| 1250 |
Lengths[1] = RX_NO_STRING ; |
| 1251 |
|
| 1252 |
Code = IfcVarPool( TSD, IVPcode, Lengths, Strings, &allocated ); |
| 1253 |
|
| 1254 |
Req->shvret = RXSHV_OK ; |
| 1255 |
if (Code==RX_CODE_NOVALUE) |
| 1256 |
Req->shvret |= RXSHV_NEWV ; |
| 1257 |
else if (Code==RX_CODE_INVNAME) |
| 1258 |
Req->shvret |= RXSHV_BADN ; |
| 1259 |
else if (Code!=RXSHV_OK) |
| 1260 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 1261 |
TSD->var_indicator=0; |
| 1262 |
break ; |
| 1263 |
} |
| 1264 |
case RXSHV_SYFET: |
| 1265 |
IVPcode = RX_GETSVAR; /* JH 20-10-99 */ |
| 1266 |
case RXSHV_FETCH: /* MH 26-12-95 */ |
| 1267 |
{ |
| 1268 |
IVPcode = IVPcode ? IVPcode : RX_GETVAR; /* JH 20-10-99 */ |
| 1269 |
Lengths[0] = Req->shvname.strlength ; |
| 1270 |
Strings[0] = Req->shvname.strptr ; |
| 1271 |
Code = IfcVarPool( TSD, IVPcode, Lengths, Strings, &allocated ); |
| 1272 |
|
| 1273 |
Req->shvret = RXSHV_OK ; |
| 1274 |
if (Code==RX_CODE_NOVALUE) |
| 1275 |
Req->shvret |= RXSHV_NEWV ; |
| 1276 |
else if (Code==RX_CODE_INVNAME) |
| 1277 |
Req->shvret |= RXSHV_BADN ; |
| 1278 |
else if (Code!=RXSHV_OK) |
| 1279 |
exiterror( ERR_INTERPRETER_FAILURE, 1, __FILE__, __LINE__, "" ) ; |
| 1280 |
FillReqValue( Req, Lengths[1], Strings[1] ) ; |
| 1281 |
TSD->var_indicator=0; |
| 1282 |
break ; |
| 1283 |
} |
| 1284 |
|
| 1285 |
case RXSHV_PRIV: |
| 1286 |
{ |
| 1287 |
Req->shvret = RXSHV_OK ; |
| 1288 |
if (Req->shvname.strlength==4 && Req->shvname.strptr && |
| 1289 |
!strncmp(Req->shvname.strptr, "PARM", 4 )) |
| 1290 |
{ |
| 1291 |
rc = IfcVarPool( TSD, RX_CODE_PARAMS, Lengths, Strings, &allocated ); |
| 1292 |
FillReqValue( Req, Lengths[0], Strings[0] ) ; |
| 1293 |
} |
| 1294 |
|
| 1295 |
else if (Req->shvname.strlength>=5 && Req->shvname.strptr && |
| 1296 |
!strncmp(Req->shvname.strptr, "PARM.", 5 )) |
| 1297 |
{ |
| 1298 |
Lengths[0] = Req->shvname.strlength - 5 ; |
| 1299 |
Strings[0] = Req->shvname.strptr + 5 ; |
| 1300 |
|
| 1301 |
rc = IfcVarPool( TSD, RX_CODE_PARAM, Lengths, Strings, &allocated ); |
| 1302 |
if (rc == RX_CODE_OK) |
| 1303 |
FillReqValue( Req, Lengths[1], Strings[1] ) ; |
| 1304 |
else |
| 1305 |
Req->shvret |= RXSHV_BADN ; |
| 1306 |
} |
| 1307 |
|
| 1308 |
else |
| 1309 |
{ |
| 1310 |
Code=0 ; |
| 1311 |
if (Req->shvname.strptr) |
| 1312 |
{ |
| 1313 |
if (Req->shvname.strlength==7 && |
| 1314 |
!memcmp(Req->shvname.strptr, "QUENAME", 7)) |
| 1315 |
{ |
| 1316 |
Code = RX_CODE_QUEUE ; |
| 1317 |
} |
| 1318 |
else if (Req->shvname.strlength==7 && |
| 1319 |
!memcmp(Req->shvname.strptr, "VERSION", 7)) |
| 1320 |
{ |
| 1321 |
Code = RX_CODE_VERSION ; |
| 1322 |
} |
| 1323 |
else if (Req->shvname.strlength==6 && |
| 1324 |
!memcmp(Req->shvname.strptr, "SOURCE", 6)) |
| 1325 |
{ |
| 1326 |
Code = RX_CODE_SOURCE ; |
| 1327 |
} |
| 1328 |
else |
| 1329 |
Req->shvret |= RXSHV_BADN ; |
| 1330 |
|
| 1331 |
if ((!Req->shvret) | RXSHV_BADN) |
| 1332 |
{ |
| 1333 |
rc=IfcVarPool( TSD, Code, Lengths, Strings, &allocated ); |
| 1334 |
FillReqValue( Req, Lengths[0], Strings[0] ) ; |
| 1335 |
} |
| 1336 |
} |
| 1337 |
else |
| 1338 |
Req->shvret |= RXSHV_BADN ; |
| 1339 |
} |
| 1340 |
break ; |
| 1341 |
} |
| 1342 |
|
| 1343 |
case RXSHV_NEXTV: |
| 1344 |
{ |
| 1345 |
int Items ; |
| 1346 |
|
| 1347 |
Req->shvret = RXSHV_OK ; |
| 1348 |
Items = IfcVarPool( TSD, RX_NEXTVAR, Lengths, Strings, &allocated ); |
| 1349 |
assert( Items==0 || Items==2 ) ; |
| 1350 |
|
| 1351 |
if (Items==2) |
| 1352 |
{ |
| 1353 |
FillReqValue( Req, Lengths[1], Strings[1] ) ; |
| 1354 |
FillReqName( Req, Lengths[0], Strings[0] ) ; |
| 1355 |
} |
| 1356 |
else |
| 1357 |
Req->shvret |= RXSHV_LVAR ; |
| 1358 |
|
| 1359 |
break ; |
| 1360 |
} |
| 1361 |
|
| 1362 |
default: |
| 1363 |
Req->shvret = RXSHV_BADF ; |
| 1364 |
} |
| 1365 |
if (allocated & 1) /* fixes bug 596686 */ |
| 1366 |
FreeTSD( Strings[0] ); |
| 1367 |
if (allocated & 2) |
| 1368 |
FreeTSD( Strings[1] ); |
| 1369 |
RetCode |= ( Req->shvret & 0x007f ) ; |
| 1370 |
} |
| 1371 |
|
| 1372 |
return RetCode ; |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
/* ================================================================ */ |
| 1378 |
/* system exit handler subsystem */ |
| 1379 |
|
| 1380 |
EXPORT_C APIRET APIENTRY RexxRegisterExitExe(PCSZ EnvName, |
| 1381 |
#ifdef RX_WEAKTYPING |
| 1382 |
PFN EntryPoint, |
| 1383 |
#else |
| 1384 |
RexxExitHandler *EntryPoint, |
| 1385 |
#endif |
| 1386 |
PUCHAR UserArea ) |
| 1387 |
{ |
| 1388 |
tsd_t *TSD = getGlobalTSD(); |
| 1389 |
|
| 1390 |
if ( TSD == NULL ) |
| 1391 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1392 |
StartupInterface( TSD ); |
| 1393 |
|
| 1394 |
/* |
| 1395 |
* Perform sanity check on the parameters; UserArea may be NULL |
| 1396 |
*/ |
| 1397 |
if ( !EnvName || !EntryPoint ) |
| 1398 |
return RXEXIT_BADTYPE; |
| 1399 |
|
| 1400 |
return IfcRegExit( TSD, EnvName, NULL, NULL, (PFN)EntryPoint, UserArea ); |
| 1401 |
} |
| 1402 |
|
| 1403 |
EXPORT_C APIRET APIENTRY RexxRegisterExitDll(PCSZ EnvName, |
| 1404 |
PCSZ ModuleName, |
| 1405 |
PCSZ ProcedureName, |
| 1406 |
PUCHAR UserArea, |
| 1407 |
ULONG DropAuth ) |
| 1408 |
{ |
| 1409 |
tsd_t *TSD = getGlobalTSD(); |
| 1410 |
|
| 1411 |
if ( TSD == NULL ) |
| 1412 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1413 |
StartupInterface( TSD ); |
| 1414 |
|
| 1415 |
if ( !EnvName || !ModuleName || !ProcedureName ) |
| 1416 |
return RXEXIT_BADTYPE; |
| 1417 |
if ( ( DropAuth != RXEXIT_DROPPABLE ) && ( DropAuth != RXEXIT_NONDROP ) ) |
| 1418 |
return RXEXIT_BADTYPE; |
| 1419 |
|
| 1420 |
return IfcRegExit( TSD, EnvName, ModuleName, ProcedureName, NULL, UserArea ); |
| 1421 |
} |
| 1422 |
|
| 1423 |
|
| 1424 |
EXPORT_C APIRET APIENTRY RexxDeregisterExit(PCSZ EnvName, |
| 1425 |
PCSZ ModuleName ) |
| 1426 |
{ |
| 1427 |
tsd_t *TSD = getGlobalTSD(); |
| 1428 |
|
| 1429 |
if ( TSD == NULL ) |
| 1430 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1431 |
StartupInterface( TSD ); |
| 1432 |
|
| 1433 |
if ( !EnvName ) |
| 1434 |
return RXEXIT_BADTYPE; |
| 1435 |
|
| 1436 |
return IfcDelExit( TSD, EnvName, ModuleName ); |
| 1437 |
} |
| 1438 |
|
| 1439 |
EXPORT_C APIRET APIENTRY RexxQueryExit(PCSZ EnvName, |
| 1440 |
PCSZ ModuleName, |
| 1441 |
PUSHORT Flag, |
| 1442 |
PUCHAR UserArea) |
| 1443 |
{ |
| 1444 |
int ret; |
| 1445 |
tsd_t *TSD = getGlobalTSD(); |
| 1446 |
|
| 1447 |
if ( TSD == NULL ) |
| 1448 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1449 |
StartupInterface( TSD ); |
| 1450 |
|
| 1451 |
if ( !EnvName || !Flag || !Flag ) |
| 1452 |
return RXEXIT_BADTYPE; |
| 1453 |
|
| 1454 |
if ( ( ret = IfcQueryExit( TSD, EnvName, ModuleName, UserArea ) ) == |
| 1455 |
RXEXIT_OK ) |
| 1456 |
*Flag = RXEXIT_ISREG; |
| 1457 |
else |
| 1458 |
*Flag = 0; |
| 1459 |
|
| 1460 |
return ret; |
| 1461 |
} |
| 1462 |
|
| 1463 |
/* =================================================================== */ |
| 1464 |
|
| 1465 |
/* |
| 1466 |
* This section contains the support for the external functions |
| 1467 |
*/ |
| 1468 |
|
| 1469 |
EXPORT_C APIRET APIENTRY RexxRegisterFunctionExe( PCSZ Name, |
| 1470 |
#ifdef RX_WEAKTYPING |
| 1471 |
PFN EntryPoint ) |
| 1472 |
#else |
| 1473 |
RexxFunctionHandler *EntryPoint ) |
| 1474 |
#endif |
| 1475 |
{ |
| 1476 |
tsd_t *TSD = getGlobalTSD(); |
| 1477 |
|
| 1478 |
if ( TSD == NULL ) |
| 1479 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1480 |
StartupInterface( TSD ); |
| 1481 |
|
| 1482 |
if ( !Name || !EntryPoint ) |
| 1483 |
return RXFUNC_BADTYPE; |
| 1484 |
|
| 1485 |
return IfcRegFunc( TSD, Name, NULL, NULL, (PFN)EntryPoint ); |
| 1486 |
} |
| 1487 |
|
| 1488 |
EXPORT_C APIRET APIENTRY RexxRegisterFunctionDll( PCSZ ExternalName, |
| 1489 |
PCSZ LibraryName, |
| 1490 |
PCSZ InternalName ) |
| 1491 |
{ |
| 1492 |
tsd_t *TSD = getGlobalTSD(); |
| 1493 |
|
| 1494 |
if ( TSD == NULL ) |
| 1495 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1496 |
StartupInterface( TSD ); |
| 1497 |
|
| 1498 |
if ( !ExternalName || !LibraryName || !InternalName ) |
| 1499 |
return RXFUNC_BADTYPE; |
| 1500 |
|
| 1501 |
return IfcRegFunc( TSD, ExternalName, LibraryName, InternalName, NULL ); |
| 1502 |
} |
| 1503 |
|
| 1504 |
EXPORT_C APIRET APIENTRY RexxQueryFunction( PCSZ Name ) |
| 1505 |
{ |
| 1506 |
tsd_t *TSD = getGlobalTSD(); |
| 1507 |
|
| 1508 |
if ( TSD == NULL ) |
| 1509 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1510 |
StartupInterface( TSD ); |
| 1511 |
|
| 1512 |
if ( !Name ) |
| 1513 |
return RXFUNC_BADTYPE; |
| 1514 |
return IfcQueryFunc( TSD, Name ); |
| 1515 |
} |
| 1516 |
|
| 1517 |
|
| 1518 |
EXPORT_C APIRET APIENTRY RexxDeregisterFunction( PCSZ Name ) |
| 1519 |
{ |
| 1520 |
tsd_t *TSD = getGlobalTSD(); |
| 1521 |
|
| 1522 |
if ( TSD == NULL ) |
| 1523 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1524 |
StartupInterface( TSD ); |
| 1525 |
|
| 1526 |
if ( !Name ) |
| 1527 |
return RXFUNC_BADTYPE; |
| 1528 |
|
| 1529 |
return IfcDelFunc( TSD, Name ); |
| 1530 |
} |
| 1531 |
|
| 1532 |
/* The caller of IfcFunctionExit should call this function with fresh copies of |
| 1533 |
* Name and params to be bullet-proof. The called function MAY |
| 1534 |
* change the values although this is illegal. |
| 1535 |
*/ |
| 1536 |
static int IfcFunctionExit( tsd_t *TSD, |
| 1537 |
PSZ Name, |
| 1538 |
int Params, |
| 1539 |
RXSTRING *params, |
| 1540 |
PCSZ queuename, |
| 1541 |
int queuelen, |
| 1542 |
PRXSTRING Retstr, |
| 1543 |
int *RCode, |
| 1544 |
char called ) |
| 1545 |
{ |
| 1546 |
int rc=0 ; |
| 1547 |
RXFNCCAL_PARM fnccal; |
| 1548 |
PUCHAR parm=NULL; |
| 1549 |
rex_tsd_t *rt; |
| 1550 |
|
| 1551 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 1552 |
|
| 1553 |
if ( rt->CurrentHandlers && rt->CurrentHandlers->Handlers[RXFNC] ) |
| 1554 |
{ |
| 1555 |
fnccal.rxfnc_flags.rxfferr = 0; |
| 1556 |
fnccal.rxfnc_flags.rxffnfnd = 0; |
| 1557 |
fnccal.rxfnc_flags.rxffsub = (called) ? 1 : 0; |
| 1558 |
fnccal.rxfnc_name = (unsigned char *)Name; |
| 1559 |
fnccal.rxfnc_namel = (USHORT) strlen(Name); |
| 1560 |
fnccal.rxfnc_que = (unsigned char *)queuename; |
| 1561 |
fnccal.rxfnc_quel = (USHORT) queuelen; |
| 1562 |
fnccal.rxfnc_argc = (USHORT) Params; |
| 1563 |
fnccal.rxfnc_argv = params; |
| 1564 |
fnccal.rxfnc_retc = *Retstr; |
| 1565 |
parm = (PUCHAR)&fnccal; |
| 1566 |
rc = (*(rt->CurrentHandlers->Handlers[RXFNC]))(RXFNC, RXFNCCAL, parm); |
| 1567 |
TSD->var_indicator = 0; |
| 1568 |
assert( rc==RXEXIT_HANDLED || rc==RXEXIT_NOT_HANDLED || |
| 1569 |
rc==RXEXIT_RAISE_ERROR ) ; |
| 1570 |
if (rc == RXEXIT_HANDLED) |
| 1571 |
{ |
| 1572 |
if (fnccal.rxfnc_flags.rxfferr) |
| 1573 |
*RCode = RXFLAG_ERROR ; |
| 1574 |
else if (fnccal.rxfnc_flags.rxffnfnd) |
| 1575 |
*RCode = RXFLAG_FAILURE ; |
| 1576 |
else |
| 1577 |
*RCode = RXFLAG_OK; |
| 1578 |
} |
| 1579 |
*Retstr = fnccal.rxfnc_retc; |
| 1580 |
return(rc); |
| 1581 |
} |
| 1582 |
else |
| 1583 |
{ |
| 1584 |
return (RXEXIT_NOT_HANDLED); |
| 1585 |
} |
| 1586 |
} |
| 1587 |
|
| 1588 |
/* The caller of IfcExecFunc should call this function with fresh copies of |
| 1589 |
* Name, Length and Strings to be bullet-proof. The called function MAY |
| 1590 |
* change the values although this is illegal. |
| 1591 |
* RetLength and RetString should point to {0,NULL}. They will be filled with |
| 1592 |
* freshly allocated values if there are some. |
| 1593 |
*/ |
| 1594 |
int IfcExecFunc( tsd_t *TSD, |
| 1595 |
PFN Func, |
| 1596 |
char *Name, int Params, |
| 1597 |
int *Lengths, char **Strings, |
| 1598 |
int queue_name_len, char *queue_name, |
| 1599 |
int *RetLength, char **RetString, |
| 1600 |
int *RC, char called, void *gci_info ) |
| 1601 |
{ |
| 1602 |
int i=0, length=0, rc=0, RCode=0 ; |
| 1603 |
RXSTRING *params, retstr ; |
| 1604 |
rex_tsd_t *rt; |
| 1605 |
char execfunc_result[ILLEGAL_USE_SIZE+RXAUTOBUFLEN] ; |
| 1606 |
RexxFunctionHandler *FullFunc; |
| 1607 |
|
| 1608 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 1609 |
assert( Name ) ; |
| 1610 |
assert( Params >= 0 ) ; |
| 1611 |
FullFunc = (RexxFunctionHandler *)Func; |
| 1612 |
|
| 1613 |
params = (RXSTRING *)MallocTSD( sizeof(RXSTRING)*Params ) ; |
| 1614 |
for (i=0; i<Params; i++) |
| 1615 |
{ |
| 1616 |
length = Lengths[i] ; |
| 1617 |
if (length==RX_NO_STRING) |
| 1618 |
{ |
| 1619 |
params[i].strptr = NULL ; |
| 1620 |
params[i].strlength = 0 ; |
| 1621 |
} |
| 1622 |
else |
| 1623 |
{ |
| 1624 |
params[i].strptr = Strings[i] ; |
| 1625 |
params[i].strlength = length ; |
| 1626 |
} |
| 1627 |
} |
| 1628 |
|
| 1629 |
memset( execfunc_result, 0, sizeof( execfunc_result ) ) ; |
| 1630 |
retstr.strptr = execfunc_result + ILLEGAL_USE_SIZE ; |
| 1631 |
retstr.strlength = RXAUTOBUFLEN; /* MH 26-12-95 */ |
| 1632 |
|
| 1633 |
rc = IfcFunctionExit( TSD, Name, Params, params, queue_name, queue_name_len, |
| 1634 |
&retstr, &RCode, called ); |
| 1635 |
switch(rc) |
| 1636 |
{ |
| 1637 |
case RXEXIT_NOT_HANDLED: |
| 1638 |
if ( Func == NULL ) |
| 1639 |
{ |
| 1640 |
*RC = ERR_ROUTINE_NOT_FOUND; |
| 1641 |
} |
| 1642 |
else |
| 1643 |
{ |
| 1644 |
#if defined(DYNAMIC) && defined(HAVE_GCI) |
| 1645 |
if ( gci_info != NULL ) |
| 1646 |
rc = GCI_Dispatcher( TSD, (PFN)Func, gci_info, Params, params, &retstr ); |
| 1647 |
else |
| 1648 |
#endif |
| 1649 |
/* Func will inherit a possible return value in |
| 1650 |
* retstr. This might be a problem, expect suspicious results |
| 1651 |
* if the called functions are not error free. |
| 1652 |
*/ |
| 1653 |
rc = (*(FullFunc))( Name, Params, params, queue_name, &retstr ) ; |
| 1654 |
|
| 1655 |
if (rc) |
| 1656 |
*RC = ERR_INCORRECT_CALL; |
| 1657 |
else |
| 1658 |
*RC = 0; |
| 1659 |
TSD->var_indicator = 0; |
| 1660 |
} |
| 1661 |
break; |
| 1662 |
case RXEXIT_HANDLED: |
| 1663 |
if (RCode == RXFLAG_ERROR) |
| 1664 |
*RC = ERR_INCORRECT_CALL; |
| 1665 |
else if (RCode == RXFLAG_FAILURE) |
| 1666 |
*RC = ERR_ROUTINE_NOT_FOUND; |
| 1667 |
else |
| 1668 |
*RC = 0; |
| 1669 |
break; |
| 1670 |
case RXEXIT_RAISE_ERROR: |
| 1671 |
*RC = ERR_SYSTEM_FAILURE; |
| 1672 |
break; |
| 1673 |
} |
| 1674 |
|
| 1675 |
FreeTSD( params ) ; |
| 1676 |
|
| 1677 |
if (!(*RC) && retstr.strptr) |
| 1678 |
{ |
| 1679 |
*RetString = (char *)MallocTSD( (retstr.strlength < 1) ? 1 : retstr.strlength ) ; |
| 1680 |
memcpy( *RetString, retstr.strptr, retstr.strlength ) ; |
| 1681 |
*RetLength = retstr.strlength ; |
| 1682 |
} |
| 1683 |
else |
| 1684 |
*RetLength = RX_NO_STRING ; |
| 1685 |
|
| 1686 |
if (retstr.strptr && retstr.strptr != execfunc_result + ILLEGAL_USE_SIZE) |
| 1687 |
IfcFreeMemory( retstr.strptr ) ; |
| 1688 |
|
| 1689 |
return RX_CODE_OK ; |
| 1690 |
} |
| 1691 |
|
| 1692 |
int IfcHaveFunctionExit(const tsd_t *TSD) |
| 1693 |
{ |
| 1694 |
rex_tsd_t *rt; |
| 1695 |
|
| 1696 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 1697 |
if ( rt->CurrentHandlers && rt->CurrentHandlers->Handlers[RXFNC] ) |
| 1698 |
return 1; |
| 1699 |
else |
| 1700 |
return 0; |
| 1701 |
} |
| 1702 |
|
| 1703 |
/* ============================================================= */ |
| 1704 |
/* Asynchronous Rexx API interface */ |
| 1705 |
|
| 1706 |
extern tsd_t *__regina_get_tsd_for_threadid( unsigned long threadid ); |
| 1707 |
extern tsd_t *__regina_get_next_tsd( int idx ); |
| 1708 |
extern int __regina_get_number_concurrent_regina_threads(void); |
| 1709 |
|
| 1710 |
EXPORT_C APIRET APIENTRY RexxSetHalt(LONG dummyProcess, |
| 1711 |
LONG threadid ) |
| 1712 |
{ |
| 1713 |
tsd_t *TSD; |
| 1714 |
int mcrt,i; |
| 1715 |
/* |
| 1716 |
* Only the current process can halt a running thread. |
| 1717 |
*/ |
| 1718 |
if ( threadid == 0 ) |
| 1719 |
{ |
| 1720 |
/* |
| 1721 |
* Halt every thread |
| 1722 |
*/ |
| 1723 |
mcrt = __regina_get_number_concurrent_regina_threads(); |
| 1724 |
for ( i = 0; i < mcrt ; i++ ) |
| 1725 |
{ |
| 1726 |
TSD = __regina_get_next_tsd( i ); |
| 1727 |
if ( TSD != NULL ) |
| 1728 |
set_rexx_halt( TSD ); |
| 1729 |
} |
| 1730 |
} |
| 1731 |
else |
| 1732 |
{ |
| 1733 |
/* |
| 1734 |
* Only halt the specified thread |
| 1735 |
*/ |
| 1736 |
TSD = __regina_get_tsd_for_threadid( threadid ); |
| 1737 |
if ( TSD == NULL ) |
| 1738 |
return RXARI_NOT_FOUND; |
| 1739 |
set_rexx_halt( TSD ); |
| 1740 |
} |
| 1741 |
return RXARI_OK ; |
| 1742 |
} |
| 1743 |
|
| 1744 |
EXPORT_C APIRET APIENTRY RexxSetTrace(LONG dummyProcess, |
| 1745 |
LONG threadid ) |
| 1746 |
{ |
| 1747 |
tsd_t *TSD; |
| 1748 |
int mcrt,i; |
| 1749 |
streng trace; |
| 1750 |
|
| 1751 |
/* |
| 1752 |
* Create our parameter to set_trace() manually. We have problems with memory allocation if |
| 1753 |
* we use any of the Str*() functions |
| 1754 |
*/ |
| 1755 |
#ifdef CHECK_MEMORY /* FGC: Test */ |
| 1756 |
trace.value = "?i"; |
| 1757 |
#else |
| 1758 |
trace.value[0] = '?'; |
| 1759 |
trace.value[1] = 'i'; |
| 1760 |
#endif |
| 1761 |
trace.len = 2; |
| 1762 |
trace.max = 2; |
| 1763 |
/* |
| 1764 |
* Only the current process can trace a running thread. |
| 1765 |
*/ |
| 1766 |
if ( threadid == 0 ) |
| 1767 |
{ |
| 1768 |
/* |
| 1769 |
* Trace every thread |
| 1770 |
*/ |
| 1771 |
mcrt = __regina_get_number_concurrent_regina_threads(); |
| 1772 |
for ( i = 0; i < mcrt ; i++ ) |
| 1773 |
{ |
| 1774 |
TSD = __regina_get_next_tsd( i ); |
| 1775 |
if ( TSD != NULL ) |
| 1776 |
{ |
| 1777 |
if ( !TSD->systeminfo->interactive ) |
| 1778 |
{ |
| 1779 |
set_trace( TSD, &trace ); |
| 1780 |
} |
| 1781 |
} |
| 1782 |
} |
| 1783 |
} |
| 1784 |
else |
| 1785 |
{ |
| 1786 |
/* |
| 1787 |
* Only trace the specified thread |
| 1788 |
*/ |
| 1789 |
TSD = __regina_get_tsd_for_threadid( threadid ); |
| 1790 |
if ( TSD == NULL ) |
| 1791 |
return RXARI_NOT_FOUND; |
| 1792 |
if ( !TSD->systeminfo->interactive ) |
| 1793 |
{ |
| 1794 |
set_trace( TSD, &trace ); |
| 1795 |
} |
| 1796 |
} |
| 1797 |
return RXARI_OK ; |
| 1798 |
} |
| 1799 |
|
| 1800 |
EXPORT_C APIRET APIENTRY RexxResetTrace(LONG dummyProcess, |
| 1801 |
LONG threadid ) |
| 1802 |
{ |
| 1803 |
tsd_t *TSD; |
| 1804 |
int mcrt,i; |
| 1805 |
streng trace; |
| 1806 |
|
| 1807 |
/* |
| 1808 |
* Create our parameter to set_trace() manually. We have problems with memory allocation if |
| 1809 |
* we use any of the Str*() functions |
| 1810 |
*/ |
| 1811 |
#ifdef CHECK_MEMORY /* FGC: Test */ |
| 1812 |
trace.value = "O"; |
| 1813 |
#else |
| 1814 |
trace.value[0] = 'O'; |
| 1815 |
#endif |
| 1816 |
trace.len = 1; |
| 1817 |
trace.max = 1; |
| 1818 |
/* |
| 1819 |
* Only the current process can trace a running thread. |
| 1820 |
*/ |
| 1821 |
if ( threadid == 0 ) |
| 1822 |
{ |
| 1823 |
/* |
| 1824 |
* Trace every thread |
| 1825 |
*/ |
| 1826 |
mcrt = __regina_get_number_concurrent_regina_threads(); |
| 1827 |
for ( i = 0; i < mcrt ; i++ ) |
| 1828 |
{ |
| 1829 |
TSD = __regina_get_next_tsd( i ); |
| 1830 |
if ( TSD != NULL ) |
| 1831 |
{ |
| 1832 |
if ( TSD->systeminfo->interactive ) |
| 1833 |
{ |
| 1834 |
set_trace( TSD, &trace ); |
| 1835 |
} |
| 1836 |
} |
| 1837 |
} |
| 1838 |
} |
| 1839 |
else |
| 1840 |
{ |
| 1841 |
/* |
| 1842 |
* Only trace the specified thread |
| 1843 |
*/ |
| 1844 |
TSD = __regina_get_tsd_for_threadid( threadid ); |
| 1845 |
if ( TSD == NULL ) |
| 1846 |
return RXARI_NOT_FOUND; |
| 1847 |
if ( TSD->systeminfo->interactive ) |
| 1848 |
{ |
| 1849 |
set_trace( TSD, &trace ); |
| 1850 |
} |
| 1851 |
} |
| 1852 |
return RXARI_OK ; |
| 1853 |
} |
| 1854 |
|
| 1855 |
/* ============================================================= */ |
| 1856 |
/* Named queue interface */ |
| 1857 |
|
| 1858 |
EXPORT_C APIRET APIENTRY RexxCreateQueue( PSZ Buffer, |
| 1859 |
ULONG BuffLen, |
| 1860 |
PSZ RequestedName, |
| 1861 |
ULONG* DupFlag) |
| 1862 |
{ |
| 1863 |
int code; |
| 1864 |
tsd_t *TSD = getGlobalTSD(); |
| 1865 |
|
| 1866 |
if ( TSD == NULL ) |
| 1867 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1868 |
StartupInterface(TSD); |
| 1869 |
|
| 1870 |
TSD->called_from_saa = 1; |
| 1871 |
code = IfcCreateQueue( TSD, RequestedName, (RequestedName) ? strlen( RequestedName): 0, Buffer, DupFlag, BuffLen ); |
| 1872 |
TSD->called_from_saa = 0; |
| 1873 |
return code; |
| 1874 |
} |
| 1875 |
|
| 1876 |
EXPORT_C APIRET APIENTRY RexxDeleteQueue( PSZ QueueName ) |
| 1877 |
{ |
| 1878 |
int code; |
| 1879 |
tsd_t *TSD = getGlobalTSD(); |
| 1880 |
|
| 1881 |
if ( TSD == NULL ) |
| 1882 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1883 |
StartupInterface(TSD); |
| 1884 |
|
| 1885 |
TSD->called_from_saa = 1; |
| 1886 |
if (!QueueName || !strlen(QueueName)) |
| 1887 |
code = RXQUEUE_BADQNAME; |
| 1888 |
else |
| 1889 |
code = IfcDeleteQueue( TSD, QueueName, strlen( QueueName ) ); |
| 1890 |
TSD->called_from_saa = 0; |
| 1891 |
return code; |
| 1892 |
} |
| 1893 |
|
| 1894 |
EXPORT_C APIRET APIENTRY RexxQueryQueue( PSZ QueueName, |
| 1895 |
ULONG* Count) |
| 1896 |
{ |
| 1897 |
int code; |
| 1898 |
tsd_t *TSD = getGlobalTSD(); |
| 1899 |
|
| 1900 |
if ( TSD == NULL ) |
| 1901 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1902 |
StartupInterface(TSD); |
| 1903 |
|
| 1904 |
TSD->called_from_saa = 1; |
| 1905 |
if (!QueueName || !strlen(QueueName)) |
| 1906 |
code = RXQUEUE_BADQNAME; |
| 1907 |
else |
| 1908 |
code = IfcQueryQueue( TSD, QueueName, strlen( QueueName ), Count ); |
| 1909 |
TSD->called_from_saa = 0; |
| 1910 |
return code; |
| 1911 |
} |
| 1912 |
|
| 1913 |
EXPORT_C APIRET APIENTRY RexxAddQueue( PSZ QueueName, |
| 1914 |
PRXSTRING EntryData, |
| 1915 |
ULONG AddFlag) |
| 1916 |
{ |
| 1917 |
int code; |
| 1918 |
tsd_t *TSD = getGlobalTSD(); |
| 1919 |
|
| 1920 |
if ( TSD == NULL ) |
| 1921 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1922 |
StartupInterface(TSD); |
| 1923 |
|
| 1924 |
TSD->called_from_saa = 1; |
| 1925 |
if (!QueueName || !strlen(QueueName)) |
| 1926 |
code = RXQUEUE_BADQNAME; |
| 1927 |
else |
| 1928 |
code = IfcAddQueue( TSD, QueueName, strlen( QueueName), EntryData->strptr, EntryData->strlength, AddFlag==RXQUEUE_LIFO ); |
| 1929 |
TSD->called_from_saa = 0; |
| 1930 |
return code; |
| 1931 |
} |
| 1932 |
|
| 1933 |
EXPORT_C APIRET APIENTRY RexxPullQueue( PSZ QueueName, |
| 1934 |
PRXSTRING DataBuf, |
| 1935 |
PDATETIME TimeStamp, |
| 1936 |
ULONG WaitFlag) |
| 1937 |
{ |
| 1938 |
int code; |
| 1939 |
tsd_t *TSD = getGlobalTSD(); |
| 1940 |
|
| 1941 |
if ( TSD == NULL ) |
| 1942 |
TSD = GLOBAL_ENTRY_POINT(); |
| 1943 |
StartupInterface( TSD ); |
| 1944 |
|
| 1945 |
if ( WaitFlag != RXQUEUE_WAIT && WaitFlag != RXQUEUE_NOWAIT ) |
| 1946 |
return RXQUEUE_BADWAITFLAG; |
| 1947 |
|
| 1948 |
if ( DataBuf == NULL ) |
| 1949 |
return RXQUEUE_MEMFAIL; |
| 1950 |
|
| 1951 |
TSD->called_from_saa = 1; |
| 1952 |
if ( !QueueName || !strlen( QueueName ) ) |
| 1953 |
code = RXQUEUE_BADQNAME; |
| 1954 |
else |
| 1955 |
{ |
| 1956 |
code = IfcPullQueue( TSD, |
| 1957 |
QueueName, strlen( QueueName ), |
| 1958 |
&DataBuf->strptr, &DataBuf->strlength, |
| 1959 |
WaitFlag==RXQUEUE_WAIT ); |
| 1960 |
if ( code == 0 ) |
| 1961 |
{ |
| 1962 |
if ( TimeStamp ) |
| 1963 |
TimeStamp->valid = 0; |
| 1964 |
} |
| 1965 |
} |
| 1966 |
TSD->called_from_saa = 0; |
| 1967 |
return code; |
| 1968 |
} |
| 1969 |
|
| 1970 |
/* ============================================================= */ |
| 1971 |
/* MacroSpace Rexx API interface */ |
| 1972 |
|
| 1973 |
EXPORT_C APIRET APIENTRY RexxAddMacro( PSZ FuncName, |
| 1974 |
PSZ SourceFile, |
| 1975 |
ULONG Position ) |
| 1976 |
{ |
| 1977 |
return 0; |
| 1978 |
} |
| 1979 |
|
| 1980 |
EXPORT_C APIRET APIENTRY RexxDropMacro( PSZ FuncName) |
| 1981 |
{ |
| 1982 |
return 0; |
| 1983 |
} |
| 1984 |
|
| 1985 |
EXPORT_C APIRET APIENTRY RexxSaveMacroSpace( ULONG FuncCount, |
| 1986 |
PSZ * FuncNames, |
| 1987 |
PSZ MacroLibFile) |
| 1988 |
{ |
| 1989 |
return 0; |
| 1990 |
} |
| 1991 |
|
| 1992 |
EXPORT_C APIRET APIENTRY RexxLoadMacroSpace( ULONG FuncCount, |
| 1993 |
PSZ * FuncNames, |
| 1994 |
PSZ MacroLibFile) |
| 1995 |
{ |
| 1996 |
return 0; |
| 1997 |
} |
| 1998 |
|
| 1999 |
EXPORT_C APIRET APIENTRY RexxQueryMacro( PSZ FuncName, |
| 2000 |
PUSHORT Position ) |
| 2001 |
{ |
| 2002 |
return 0; |
| 2003 |
} |
| 2004 |
|
| 2005 |
EXPORT_C APIRET APIENTRY RexxReorderMacro( PSZ FuncName, |
| 2006 |
ULONG Position ) |
| 2007 |
{ |
| 2008 |
return 0; |
| 2009 |
} |
| 2010 |
|
| 2011 |
EXPORT_C APIRET APIENTRY RexxClearMacroSpace( VOID ) |
| 2012 |
{ |
| 2013 |
return 0; |
| 2014 |
} |
| 2015 |
|
| 2016 |
/* ============================================================= */ |
| 2017 |
/* Regina extensions */ |
| 2018 |
/* see rexxsaa.h for a description */ |
| 2019 |
EXPORT_C APIRET APIENTRY ReginaVersion( PRXSTRING VersionString ) |
| 2020 |
{ |
| 2021 |
char low[3]; |
| 2022 |
unsigned len; |
| 2023 |
tsd_t *TSD = getGlobalTSD(); |
| 2024 |
|
| 2025 |
if ( TSD == NULL ) |
| 2026 |
TSD = GLOBAL_ENTRY_POINT(); |
| 2027 |
StartupInterface(TSD); |
| 2028 |
|
| 2029 |
if (!VersionString) |
| 2030 |
goto fastexit; |
| 2031 |
|
| 2032 |
if ( VersionString->strlength == 0 ) |
| 2033 |
{ |
| 2034 |
if ( ( VersionString->strptr = (char *)IfcAllocateMemory( sizeof(PARSE_VERSION_STRING) ) ) == NULL ) |
| 2035 |
goto fastexit; |
| 2036 |
VersionString->strlength = sizeof(PARSE_VERSION_STRING); |
| 2037 |
} |
| 2038 |
|
| 2039 |
if ((len = VersionString->strlength) > sizeof(PARSE_VERSION_STRING)) |
| 2040 |
len = sizeof(PARSE_VERSION_STRING); |
| 2041 |
memcpy(VersionString->strptr,PARSE_VERSION_STRING,len); |
| 2042 |
|
| 2043 |
/* sizeof includes the terminating 0. Subtract it if we should. */ |
| 2044 |
if (len > sizeof(PARSE_VERSION_STRING) - 1) |
| 2045 |
len = sizeof(PARSE_VERSION_STRING) - 1; |
| 2046 |
VersionString->strlength = len; |
| 2047 |
|
| 2048 |
fastexit: |
| 2049 |
low[0] = REGINA_VERSION_MINOR[0]; |
| 2050 |
if (low[0] == '0') /* atoi may have problems with leading zeros (octal) */ |
| 2051 |
{ |
| 2052 |
low[0] = REGINA_VERSION_MINOR[1]; |
| 2053 |
low[1] = '\0'; |
| 2054 |
} |
| 2055 |
else |
| 2056 |
low[1] = REGINA_VERSION_MINOR[1]; |
| 2057 |
low[2] = '\0'; |
| 2058 |
return( (atoi(REGINA_VERSION_MAJOR) << 8) | atoi(low) ) ; |
| 2059 |
} |
| 2060 |
|
| 2061 |
EXPORT_C APIRET APIENTRY ReginaCleanup( VOID ) |
| 2062 |
{ |
| 2063 |
return( IfcReginaCleanup() ); |
| 2064 |
} |
| 2065 |
|
| 2066 |
/* |
| 2067 |
* Maps the "internal" system exit codes used in client.c to the SAA exit codes |
| 2068 |
*/ |
| 2069 |
int IfcMapExits( int internal ) |
| 2070 |
{ |
| 2071 |
int MainCode = 0; |
| 2072 |
switch( internal ) |
| 2073 |
{ |
| 2074 |
case RX_EXIT_STDERR: |
| 2075 |
case RX_EXIT_STDOUT: |
| 2076 |
MainCode = RXSIO ; |
| 2077 |
break; |
| 2078 |
case RX_EXIT_TRCIN: |
| 2079 |
MainCode = RXSIO ; |
| 2080 |
break; |
| 2081 |
case RX_EXIT_PULL: |
| 2082 |
MainCode = RXSIO ; |
| 2083 |
break; |
| 2084 |
case RX_EXIT_INIT: |
| 2085 |
MainCode = RXINI ; |
| 2086 |
break; |
| 2087 |
case RX_EXIT_TERMIN: |
| 2088 |
MainCode = RXTER ; |
| 2089 |
break; |
| 2090 |
case RX_EXIT_SETENV: |
| 2091 |
MainCode = RXENV ; |
| 2092 |
break; |
| 2093 |
case RX_EXIT_GETENV: |
| 2094 |
MainCode = RXENV ; |
| 2095 |
break; |
| 2096 |
case RX_EXIT_SETCWD: |
| 2097 |
MainCode = RXENV ; |
| 2098 |
break; |
| 2099 |
case RX_EXIT_GETCWD: |
| 2100 |
MainCode = RXENV ; |
| 2101 |
break; |
| 2102 |
} |
| 2103 |
return MainCode; |
| 2104 |
} |
| 2105 |
|
| 2106 |
/* |
| 2107 |
* Determine if the current interpreter has regsitered handlers for the supplied "internal" |
| 2108 |
* exit handler. |
| 2109 |
* Called from client.c |
| 2110 |
*/ |
| 2111 |
int IfcExitHandlerExists( tsd_t *TSD, int internal ) |
| 2112 |
{ |
| 2113 |
int MainCode; |
| 2114 |
rex_tsd_t *rt; |
| 2115 |
|
| 2116 |
MainCode = IfcMapExits( internal ); |
| 2117 |
rt = (rex_tsd_t *)TSD->rex_tsd; |
| 2118 |
if ( !rt->CurrentHandlers ) |
| 2119 |
return 0; |
| 2120 |
if ( !rt->CurrentHandlers->Handlers[MainCode] ) |
| 2121 |
return 0; |
| 2122 |
return 1; |
| 2123 |
} |