2
0

callrexx.pas 2.0 KB

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