home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / rexx / api / callrexx / callrexx.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  4KB  |  69 lines

  1. /*********************************************************************/
  2. /*                                                                   */
  3. /*  File Name:          CALLREXX.C                                   */
  4. /*                                                                   */
  5. /*  Description:        Provides a sample call to the REXX           */
  6. /*                      interpreter, passing in an environment name, */
  7. /*                      a file name, and a single argument string.   */
  8. /*                                                                   */
  9. /*  Entry Points:       main - main entry point                      */
  10. /*                                                                   */
  11. /*  Input:              None                                         */
  12. /*                                                                   */
  13. /*  Output:             returns 0 in all cases.                      */
  14. /*                                                                   */
  15. /*********************************************************************/
  16.  
  17. #define INCL_REXXSAA
  18. #include <rexxsaa.h>                   /* needed for RexxStart()     */
  19. #include <stdio.h>                     /* needed for printf()        */
  20. #include <string.h>                    /* needed for strlen()        */
  21.  
  22. int main(void);                        /* main entry point           */
  23.  
  24. int main()
  25.     {
  26.     RXSTRING arg;                       /* argument string for REXX  */
  27.     RXSTRING rexxretval;                /* return value from REXX    */
  28.  
  29.     UCHAR    *str = "These words will be swapped"; /* text to swap   */
  30.  
  31.     APIRET   rc;                        /* return code from REXX     */
  32.     SHORT    rexxrc = 0;                /* return code from function */
  33.  
  34.     printf("\nThis program will call the REXX interpreter ");
  35.     printf("to reverse the order of the\n");
  36.     printf("\twords in a string.  ");
  37.     printf("The interpreter is invoked with an initial\n");
  38.     printf("\tenvironment name of 'FNC' ");
  39.     printf("and a file name of 'BACKWARD.FNC'\n\n");
  40.  
  41.     /* By setting the strlength of the output RXSTRING to zero, we   */
  42.     /* force the interpreter to allocate memory and return it to us. */
  43.     /* We could provide a buffer for the interpreter to use instead. */
  44.     rexxretval.strlength = 0L;          /* initialize return to empty*/
  45.  
  46.     MAKERXSTRING(arg, str, strlen((const char *)str));/* create input argument     */
  47.  
  48.     /* Here we call the interpreter.  We don't really need to use    */
  49.     /* all the casts in this call; they just help illustrate         */
  50.     /* the data types used.                                          */
  51.     rc=RexxStart((LONG)      1,             /* number of arguments   */
  52.                 (PRXSTRING)  &arg,          /* array of arguments    */
  53.                 (PSZ)        "BACKWARD.FNC",/* name of REXX file     */
  54.                 (PRXSTRING)  0,             /* No INSTORE used       */
  55.                 (PSZ)        "FNC",         /* Command env. name     */
  56.                 (LONG)       RXSUBROUTINE,  /* Code for how invoked  */
  57.                 (PRXSYSEXIT) 0,             /* No EXITs on this call */
  58.                 (PSHORT)     &rexxrc,       /* Rexx program output   */
  59.                 (PRXSTRING)  &rexxretval ); /* Rexx program output   */
  60.  
  61.     printf("Interpreter Return Code: %d\n", rc);
  62.     printf("Function Return Code:    %d\n", (int) rexxrc);
  63.     printf("Original String:         '%s'\n", arg.strptr);
  64.     printf("Backwards String:        '%s'\n", rexxretval.strptr);
  65.     DosFreeMem(rexxretval.strptr);          /* Release storage       */
  66.                                             /* given to us by REXX.  */
  67.     return 0;
  68.     }
  69.