8
Arg: RxString; // argument string for REXX
9
RexxRetVal: RxString; // return value from REXX
10
RC: Cardinal; // return code from REXX
12
Str: PChar = 'These words will be swapped'; // text to swap
13
RexxRc: Integer = 0; // return code from function
15
Write('This program will call the REXX interpreter ');
16
WriteLn('to reverse the order of the');
17
Write(#9'words in a string. ');
18
WriteLn('The interpreter is invoked with an initial');
19
Write(#9'environment name of "FNC" ');
20
WriteLn('and a file name of "backward.fnc"');
22
// By setting the strlength of the output RXSTRING to zero, we
23
// force the interpreter to allocate memory and return it to us.
24
// We could provide a buffer for the interpreter to use instead.
26
RexxRetVal.StrLength:=0; // initialize return to empty
28
MakeRxString(Arg, Str, StrLen(Str)); // create input argument
30
// Here we call the interpreter. We don't really need to use
31
// all the casts in this call; they just help illustrate
32
// the data types used.
33
RC:=RexxStart(1, // number of arguments
34
addr(arg), // array of arguments
35
'backward.fnc', // name of REXX file
37
'FNC', // Command env. name
38
RXSUBROUTINE, // Code for how invoked
39
0, // No EXITs on this call
40
rexxrc, // Rexx program output
41
rexxretval ); // Rexx program output
43
WriteLn('Interpreter Return Code: ', RC);
44
WriteLn('Function Return Code: ', rexxrc);
45
WriteLn('Original String: ', arg.strptr);
46
WriteLn('Backwards String: ', StrPas(rexxretval.strptr));
49
DosFreeMem(RexxRetVal.StrPtr); // Release storage
51
{$WARNING Memory allocated for RexxRetVal.StrPtr^ should be freed using native API!}