Пример #1
0
static unsigned long ExecIO_Write_From_Queue (
   PLL pll)                      /* Pointer to file linked list item  */
   {

   /* Local function variables */
   char * Item;                  /* Item pulled from the queue        */
   long items;

   /* process request */
   if (ExecIO_Options.lRcdCnt == 0) {
      return 0;
      }
   /* start at the proper place in the queue */
   while (ExecIO_Options.lStartRcd > 1 && queued() > 0) {
      Item = pull();
      if (Item != NULL) {
         RexxFreeMemory(Item);
         }
      ExecIO_Options.lStartRcd--;
      }
   if (ExecIO_Options.lRcdCnt == -1) {
      /* process an "*" record count */
      items = queued();
      while (items > 0) {
         Item = pull();
         if (Item != NULL) {
            fputs(Item, pll -> pFile);
            fputs("\n", pll -> pFile);
            RexxFreeMemory(Item);
            }
         else {
            goto return_point;
            }
         items--;
         }
      }
   else {
      /* process a specific record count */
      while (ExecIO_Options.lRcdCnt > 0) {
         if (queued() == 0)
            break;
         Item = pull();
         if (Item != NULL) {
            fputs(Item, pll -> pFile);
            fputs("\n", pll -> pFile);
            RexxFreeMemory(Item);
            }
         else {
            goto return_point;
            }
         ExecIO_Options.lRcdCnt--;
         }
      }

   return_point:
   fflush (pll -> pFile);

   /* return with successful return code */
   return 0;
   }
Пример #2
0
static unsigned long ExecIO_Write_From_Stem (
   PLL pll)                      /* Pointer to file linked list item  */
   {

   /* Local function variables */
   char *      Stem;             /* Stem variable name                */
   char *      Index;            /* Stem index value (string)         */
   RXSTRING rxVal;               /* Rexx stem variable value          */
   int      elements;

   /* process request */
   if (ExecIO_Options.lRcdCnt == 0)
      return 0;
   Stem = (char *)malloc(strlen(ExecIO_Options.aStem) + 33);
   if (Stem == NULL) {
      return 20;
      }
   strcpy(Stem, ExecIO_Options.aStem);
   Index = Stem + strlen(Stem);
   if (ExecIO_Options.lRcdCnt == -1) {
      /* process an "*" record count */
      // get the number of elements
      sprintf(Index, "%u", 0);
      FetchRexxVar(Stem, &rxVal);
      elements = atoi(rxVal.strptr);
      RexxFreeMemory(rxVal.strptr);
      while (ExecIO_Options.lStartRcd <= elements) {
         sprintf(Index, "%ld", ExecIO_Options.lStartRcd);
         FetchRexxVar(Stem, &rxVal);
         fputs(rxVal.strptr, pll -> pFile);
         fputs("\n", pll -> pFile);
         RexxFreeMemory(rxVal.strptr);
         ExecIO_Options.lStartRcd++;
         }
      }
   else {
      /* process a specific record count */
      while (ExecIO_Options.lStartRcd <= ExecIO_Options.lRcdCnt) {
         sprintf(Index, "%ld", ExecIO_Options.lStartRcd);
         FetchRexxVar(Stem, &rxVal);
         fputs(rxVal.strptr, pll -> pFile);
         fputs("\n", pll -> pFile);
         RexxFreeMemory(rxVal.strptr);
         ExecIO_Options.lStartRcd++;
         }
      }
   fflush (pll -> pFile);

   /* return with successful return code */
   return 0;
   }
Пример #3
0
RexxMethod0(RexxObjectPtr, rexx_linein_queue)
{
   RexxReturnCode rc;                  /* pull return code                  */
   RexxObjectPtr queue_name;           /* current queue name                */
   RXSTRING buf;

                                       /* get the queue name                */
   queue_name = context->GetObjectVariable("NAMED_QUEUE");

   buf.strptr = NULL;                  /* ask for a returned buffer         */
   buf.strlength = 0;

   // since we don't know how long we'll be waiting here, turn off the
   // guard so we don't lock up other threads.
   context->SetGuardOff();
                                       /* pull a line                       */
   rc = RexxPullFromQueue(context->ObjectToStringValue(queue_name), &buf, NULL, RXQUEUE_WAIT);

   if (!rc)                            /* get a pulled line?                */
   {
       RexxObjectPtr result = context->NewString(buf.strptr, buf.strlength);
       if (buf.strptr != OREF_NULL)
       {
           RexxFreeMemory(buf.strptr);
       }
       return result;
   }
   return context->Nil();        /* give back a failure               */
}
int SysCall main(int argc, char **argv)
{
  char fn[2][BUFFERLEN];
  int  silent = 0;
  int  j = 0;

  HINSTANCE hDll=NULL;

  hDll = LoadLibrary(DLLNAME);

  for (j=1; j<argc; j++)
  {
      if (((argv[j][0] == '/') || (argv[j][0] == '-'))
      && ((argv[j][1] == 's') || (argv[j][1] == 'S'))) silent = j;
  }
  if (!silent)
  {
      char *ptr = RexxGetVersionInformation();
      if (ptr) {
          printf(ptr, "Tokenizer");
          printf("\n");
          RexxFreeMemory(ptr);
      }
  }

  /* check arguments: at least 1 argument, max. 2, /s must be last */
  if ((argc < 2) || (argc > 4) ||           /* invalid no. of args */
      (silent && (argc == 2)) ||            /* only /s             */
      (silent && (silent+1 != argc)) ||     /* /s not last arg     */
      (!silent && (argc == 4)))             /* 3 args, no /s       */
  {
      if (argc > 2) {
      DisplayError(hDll, Error_REXXC_cmd_parm_incorrect);
      }
      DisplayError(hDll, Error_REXXC_wrongNrArg);
      DisplayError(hDll, Error_REXXC_SynCheckInfo);
      if (hDll) FreeLibrary(hDll);
      exit(-1);
  }

  strcpy(fn[0], argv[1]);
  if (argc >= 3) strcpy(fn[1], argv[2]);

  if ( ((argc>3) || ((argc==3) && !silent)) &&
       (strcmp(strupr(fn[0]), strupr(fn[1])) == 0))
  {
      DisplayError(hDll, Error_REXXC_outDifferent);
      if (hDll) FreeLibrary(hDll);
      exit(-2);
  }

  if (hDll) FreeLibrary(hDll);

  if ((argc == 2) || ((argc==3) && silent) )  /* just doing a syntax check? */
                                       /* go perform the translation        */
    return RexxTranslateProgram(argv[1], NULL, NULL);
  else                                 /* translate and save the output     */
    return RexxTranslateProgram(argv[1], argv[2], NULL);
}
Пример #5
0
unsigned long FetchRexxVar (
   char *    pszVar,             /* Variable name                     */
   PRXSTRING prxVar)             /* REXX variable contents            */
   {

   /* local function variables */
   SHVBLOCK      RxVarBlock;
   unsigned long ulRetc;
   char *        pszTemp;

   /* initialize the shared variable block */
   RxVarBlock.shvnext = NULL;
   RxVarBlock.shvname.strptr = pszVar;
   RxVarBlock.shvname.strlength = strlen(pszVar);
   RxVarBlock.shvnamelen = RxVarBlock.shvname.strlength;
   RxVarBlock.shvvalue.strptr = NULL;
   RxVarBlock.shvvalue.strlength = 0;
   RxVarBlock.shvvaluelen = 0;
   RxVarBlock.shvcode = RXSHV_SYFET;
   RxVarBlock.shvret = RXSHV_OK;

   /* fetch variable from pool */
   ulRetc = RexxVariablePool(&RxVarBlock);

   /* test return code */
   if (ulRetc != RXSHV_OK && ulRetc != RXSHV_NEWV) {
      prxVar -> strptr = NULL;
      prxVar -> strlength = 0;
      }
   else {
      /* allocate a new buffer for the Rexx variable pool value */
      pszTemp = (char *) RexxAllocateMemory(RxVarBlock.shvvalue.strlength + 1);
      if (pszTemp == NULL) {
         /* no buffer available so return a NULL Rexx value */
         prxVar -> strptr = NULL;
         prxVar -> strlength = 0;
         ulRetc = RXSHV_MEMFL;
         }
      else {
         /* copy to new buffer and zero-terminate */
         memmove(pszTemp, RxVarBlock.shvvalue.strptr,
                  RxVarBlock.shvvalue.strlength);
         *(pszTemp + RxVarBlock.shvvalue.strlength) = '\0';
         prxVar -> strptr = pszTemp;
         prxVar -> strlength = RxVarBlock.shvvalue.strlength;
         }
      // free memory returned from RexxVariablePool API
      RexxFreeMemory(RxVarBlock.shvvalue.strptr);
      }

   return ulRetc;
   }
Пример #6
0
int SysCall main(int argc, char **argv)
{
  int  silent = 0;
  int  j = 0;

  for (j = 1; j < argc; j++)
  {
      if (((argv[j][0] == '/') || (argv[j][0] == '-'))
      && ((argv[j][1] == 's') || (argv[j][1] == 'S'))) silent = j;
  }
  if (!silent)
  {
      char *ptr = RexxGetVersionInformation();
      printf("%s\n", ptr);
      RexxFreeMemory(ptr);
  }

  /* check arguments: at least 1 argument, max. 2, /s must be last */
  if ((argc < 2) || (argc > 4) ||           /* invalid no. of args */
      (silent && (argc == 2)) ||            /* only /s             */
      (silent && (silent+1 != argc)) ||     /* /s not last arg     */
      (!silent && (argc == 4)))             /* 3 args, no /s       */
  {
      if (argc > 2)
      {
         DisplayError(Error_REXXC_cmd_parm_incorrect);
      }
      DisplayError(Error_REXXC_wrongNrArg);
      DisplayError(Error_REXXC_SynCheckInfo);
      exit(-1);
  }

  if ( ((argc>3) || ((argc==3) && !silent)) &&
       (stricmp(argv[1], argv[2]) == 0))
  {
      DisplayError(Error_REXXC_outDifferent);
      exit(-2);
  }

  if ((argc == 2) || ((argc==3) && silent) )
  {
                                       /* go perform the translation        */
      return RexxTranslateProgram(argv[1], NULL, NULL);
  }
  else                                 /* translate and save the output     */
  {
      return RexxTranslateProgram(argv[1], argv[2], NULL);
  }
}
Пример #7
0
RexxMethod0(RexxObjectPtr, rexx_pull_queue)
{
   RXSTRING buf;                       /* pulled line buffer                */
   RexxReturnCode rc;                  /* pull return code                  */

                                       /* get the queue name                */
   RexxObjectPtr queue_name = context->GetObjectVariable("NAMED_QUEUE");

   buf.strptr = NULL;                  /* ask for a returned buffer         */
   buf.strlength = 0;
                                       /* pull a line                       */
   rc = RexxPullFromQueue(context->ObjectToStringValue(queue_name), &buf, NULL, RXQUEUE_NOWAIT);

   if (!rc)
   {                                   /* get a pulled line?                */
       RexxObjectPtr result = context->NewString(buf.strptr, buf.strlength);
       if (buf.strptr != OREF_NULL)
       {
           RexxFreeMemory(buf.strptr);
       }
       return result;
   }
   return context->Nil();              /* give back a failure               */
}
Пример #8
0
//
//  MAIN program
//
int __cdecl main(int argc, char *argv[])
{
    RXSYSEXIT exit_list[9];              /* Exit list array                   */
    short    rexxrc = 0;                 /* return code from rexx             */
    int   rc;                            /* actually running program RC       */
    CONSTRXSTRING argument;              /* rexxstart argument                */
    RXSTRING rxretbuf;                   // program return buffer

    rc = 0;                              /* set default return                */

    /* just one argument is accepted by this program */
    if ((argc < 2) || (argc > 3))
    {
        printf("Wrong arguments: REXXEXIT program [argument]\n");
        exit(-1);
    }

    /*
     * Convert the input array into a single string for the Object REXX
     * argument string. Initialize the RXSTRING variable to point to this
     * string. Keep the string null terminated so we can print it for debug.
     * First argument is name of the REXX program
     * Next argument(s) are parameters to be passed
    */

    /* By setting the strlength of the output RXSTRING to zero, we   */
    /* force the interpreter to allocate memory and return it to us. */
    /* We could provide a buffer for the interpreter to use instead. */
    rxretbuf.strlength = 0L;          /* initialize return to empty*/

    if (argc == 3)
    {
        MAKERXSTRING(argument, argv[2], strlen(argv[2]));/* create input argument     */
    }
    else
        MAKERXSTRING(argument, "", 0);/* create blank argument     */

    // register IO exit
    rc = RexxRegisterExitExe("MY_IOC", (REXXPFN)&MY_IOEXIT, NULL);

    /* run this via RexxStart            */
    exit_list[0].sysexit_name = "MY_IOC";
    exit_list[0].sysexit_code = RXSIO;
    exit_list[1].sysexit_code = RXENDLST;

    /* Here we call the interpreter.                                  */
    rc=REXXSTART(1,              /* number of arguments   */
                 &argument,      /* array of arguments    */
                 argv[1],        /* name of REXX file     */
                 NULL,           /* No INSTORE used       */
                 "CMD",          /* Command env. name     */
                 RXCOMMAND,      /* Code for how invoked  */
                 exit_list,      /* exits for this call   */
                 &rexxrc,        /* Rexx program output   */
                 &rxretbuf );    /* Rexx program output   */

    /* free memory allocated for the return result */
    if (rc==0)
    {
        RexxFreeMemory(rxretbuf.strptr);
    }
    RexxDeregisterExit("MY_IOC",NULL);     // remove the exit in exe exit list
    // return interpeter or rexx program return code
    return rc ? rc : rexxrc;
}
Пример #9
0
int main(int argc, char **argv)
{
    CONSTRXSTRING arg[4];                   /* argument string for Rexx  */
    RXSTRING rexxretval;                    /* return value from Rexx    */
    RXSTRING instore[2];                    /* in storage parms          */
    PFNREXXSTART FuncAddress;
    void    *pLibHandle = NULL;             /* Library handle             */
    RexxReturnCode   rc = 0;                        /* return code from Rexx      */
    short    rexxrc = 0;                    /* return code from function  */
    const char *pszLibraryName = "librexx.so"; /* define the library name    */
    char returnBuffer[100];

    char    val;
    const char *str1 = "Arg number one";                   /* text to swap   */
    const char *str2 = "Arg number two";                   /* text to swap   */
    const char *str3 = "Arg number three";                 /* text to swap   */
    const char *str4 = "Arg number four";                  /* text to swap   */

    const char *sync_tst = "call time 'Reset';" \
                        "object1 = .example~new;" \
                        "object2 = .example~new;" \
                        "object3 = .example~new;" \
                        "a.1 = object1~start('REPEAT', 4 , 'Object 1 running');" \
                        "say a.1~result;" \
                        "say 'The result method waits until the START message has completed:';" \
                        "a.2 = object2~start('REPEAT', 2, 'Object 2 running');" \
                        "a.3 = object3~start('REPEAT', 2, 'Object 3 running');" \
                        "say a.2~result;" \
                        "say a.3~result;" \
                        "say 'main ended';" \
                        "say 'Elapsed time: ' time('E');" \
                        "exit;" \
                        "::REQUIRES 'example.rex'";

    if (!(pLibHandle = dlopen(pszLibraryName, RTLD_LAZY )))
    {                            /* Load and resolve symbols immediately  */
      fprintf(stderr, " *** Unable to load library %s !\nError message: %s\n",
               pszLibraryName, dlerror());
      return 99;
    }

    if(!(FuncAddress = (PFNREXXSTART) dlsym(pLibHandle, "RexxStart")))
    {
      rc = 1;                               /* could not resolve          */
      fprintf(stderr, " *** Unable to load function %s !\nError message: %s\n",
                                            "RexxStart", dlerror());
      return 99;
    }


    /* By setting the strlength of the Rexx output to zero, the           */
    /* interpreter allocates memory.                                      */
    /* We can provide a buffer for the interpreter to use instead.        */
    /* If the returned value does not fit into the buffer,                */
    /* Open Object Rexx creates a new one.                                */

    system("clear");

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    printf("This is an easy sample of how to invoke the Rexx interpreter. \n");
    printf("The Rexx commandfile which is started is named: startrx1.rex\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);


    /* This is the interpreter invocation. ------------------------------ */

    rc =    (*FuncAddress)(
            0,                       /* number of arguments   */
             NULL,                   /* array of arguments    */
             "startrx1.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    if (rexxretval.strptr != NULL)
    {
        RexxFreeMemory(rexxretval.strptr);
    }

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("In this case a previously defined Resultstring is \n");
    printf("delivered to Open Object Rexx, which is large enough to \n");
    printf("hold the Return Value of the Rexx commandfile.\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = returnBuffer;
    rexxretval.strlength = sizeof(returnBuffer);

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "startrx1.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("rexxretval.strptr contains %s\n", rexxretval.strptr);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);
    /* if Rexx needed to allocate a new buffer, release that one */
    if (rexxretval.strptr != returnBuffer)
    {
        RexxFreeMemory(rexxretval.strptr);
    }

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("In this case a previously defined Resultstring is \n");
    printf("delivered to Open Object Rexx, which is too small to\n");
    printf("hold the Return Value of the Rexx commandfile.\n");
    printf("Rexx reallocates the buffer which needs to be freed.\n");
    printf("in the calling program\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = (char *)returnBuffer;
    rexxretval.strlength = 2;

    printf("The length of the Resultstring is %d\n", rexxretval.strlength);

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "startrx1.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("The ResultString contains %s after call\n", rexxretval.strptr);
    printf("The length is now %d\n", rexxretval.strlength);

    /* if Rexx needed to allocate a new buffer, release that one */
    if (rexxretval.strptr != returnBuffer)
    {
        RexxFreeMemory(rexxretval.strptr);
    }

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    printf("This is a sample with 4 arguments delivered to  \n");
    printf("REXXSTART\n");
    printf("The Rexx commandfile which is started is named: startrx2.rex\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    MAKERXSTRING(arg[0], str1, strlen(str1));  /* create input argument 1 */
    MAKERXSTRING(arg[1], str2, strlen(str2));  /* create input argument 2 */
    MAKERXSTRING(arg[2], str3, strlen(str3));  /* create input argument 3 */
    MAKERXSTRING(arg[3], str4, strlen(str4));  /* create input argument 4 */

    rc = (*FuncAddress)(
             4,                      /* number of arguments   */
             arg,                    /* array of arguments    */
             "startrx2.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("This is a sample with 2 arguments delivered to  \n");
    printf("REXXSTART\n");
    printf("The Rexx commandfile which is started is named: startrx2.rex\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    rc = (*FuncAddress)(
             2,                      /* number of arguments   */
             arg,                    /* array of arguments    */
             "startrx2.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("This is a sample where the directory listing of the   \n");
    printf("actual directory is returned by the Rexx program. The \n");
    printf("returned ResultString is displayed\n");
    printf("The Rexx commandfile which is started is named: startrx3.rex\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "startrx3.rex",         /* name of Rexx file     */
             NULL,                   /* No INSTORE used       */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("This is a sample where the instore parameter [0] is \n");
    printf("tested. Instore parameter [0] is loaded with \n");
    printf("a small Open Object Rexx script showing the concurrency feature.\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    instore[0].strptr = (const char *)sync_tst;
    instore[0].strlength = strlen(instore[0].strptr);
    instore[1].strptr = NULL;
    instore[1].strlength = 0;

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    rc = (*FuncAddress)(
             0,                       /* number of arguments   */
             NULL,                   /* array of arguments    */
             NULL,                   /* no name for Rexx file */
             instore,                /* INSTORE used          */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("Now instore[1] is loaded with the content of instore[0]. \n");
    printf("It can be used on subsequent calls. instore[0] is set to NULL \n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    instore[0].strptr = NULL;
    instore[0].strlength = 0;

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             NULL,                   /* no name for Rexx file */
             instore,                /* INSTORE used          */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    free(instore[1].strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("This is a sample to show how to use the Rexx MacroSpace facility. \n");
    printf("First of all load_macro.rex is called to load \n");
    printf("the Rexx script macros.rex into Macrospace. The Macrospace- \n");
    printf("name is upload.rex. \n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "load_macro.rex", /* name for Rexx macrospacefile*/
             NULL,                   /* INSTORE not used      */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("Now the Open Object Rexx script macros.rex (named upload.rex) has been loaded\n");
    printf("into Macrospace. It is now used in the name option of\n");
    printf("the REXXSTART command. \n");
    printf("It is very important that instore paramenter [0] and [1] are\n");
    printf("initialized to NULL rsp. 0 and used as REXXSTART parameters\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rexxretval.strptr = NULL;       /* initialize return-pointer to empty */
    rexxretval.strlength = 0;       /* initialize return-length to zero   */

    instore[1].strptr = NULL;
    instore[1].strlength = 0;
    instore[0].strptr = NULL;
    instore[0].strlength = 0;

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "upload.rex",           /* name for Rexx macrospacefile */
             instore,                /* INSTORE used          */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    free(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");

    printf("Finally del_macro.rex is called to delete macros.rex (named upload.rex)\n");
    printf("out of the Open Object Rexx Macrospace.\n");

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    rc = (*FuncAddress)(
             0,                      /* number of arguments   */
             NULL,                   /* array of arguments    */
             "del_macro.rex",        /* name for Rexx macrospacefile */
             NULL,                   /* INSTORE not used      */
             "ksh",                  /* Command env. name     */
             RXCOMMAND,              /* Code for how invoked  */
             NULL,                   /* No EXITs on this call */
             &rexxrc,                /* Rexx program output   */
             &rexxretval );          /* Rexx program output   */

    printf("CALLREXX2 - Back from REXXSTART:  Return Code: %d\n", rc);
    printf("CALLREXX2 - RESULT-LENGTH:           %d\n", rexxretval.strlength);
    printf("CALLREXX2 - RESULT-Value:            %s\n", rexxretval.strptr);

    RexxFreeMemory(rexxretval.strptr);

    printf("Press Enter to continue\n");
    scanf("%c", &val);

    system("clear");
    return 0;
}
Пример #10
0
//
//  MAIN program
//
int __cdecl main(int argc, char *argv[]) {
    short    rexxrc = 0;                 /* return code from rexx             */
    int   i;                             /* loop counter                      */
    int  rc;                             /* actually running program RC       */
    const char *program_name;            /* name to run                       */
    char  arg_buffer[8192];              /* starting argument buffer          */
    char *cp;                            /* option character pointer          */
    CONSTRXSTRING arguments;             /* rexxstart argument                */
    size_t argcount;
    RXSTRING rxretbuf;                   // program return buffer
    BOOL from_string = FALSE;            /* running from command line string? */
    BOOL real_argument = TRUE;           /* running from command line string? */
    RXSTRING instore[2];

    RexxInstance        *pgmInst;
    RexxThreadContext   *pgmThrdInst;
    RexxArrayObject      rxargs, rxcargs;
    RexxDirectoryObject  dir;
    RexxObjectPtr        result;

    rc = 0;                              /* set default return                */

    /*
     * Convert the input array into a single string for the Object REXX
     * argument string. Initialize the RXSTRING variable to point to this
     * string. Keep the string null terminated so we can print it for debug.
     * First argument is name of the REXX program
     * Next argument(s) are parameters to be passed
    */

    arg_buffer[0] = '\0';                /* default to no argument string     */
    program_name = NULL;                 /* no program to run yet             */

    for (i = 1; i < argc; i++)           /* loop through the arguments        */
    {
        /* is this an option switch?         */
        if ((*(cp=*(argv+i)) == '-' || *cp == '/')) {
            switch (*++cp) {
                case 'e':
                case 'E':                /* execute from string               */
                    if (from_string == FALSE) {  /* only treat 1st -e differently */
                        from_string = TRUE;
                        if ( argc == i+1 ) {
                            break;
                        }
                        program_name = "INSTORE";
                        instore[0].strptr = argv[i+1];
                        instore[0].strlength = strlen(instore[0].strptr);
                        instore[1].strptr = NULL;
                        instore[1].strlength = 0;
                        real_argument = FALSE;
                    }
                    break;
                case 'v':
                case 'V': {                                /* version display */
                    char *ptr = RexxGetVersionInformation();
                    if (ptr)
                    {
                        fprintf(stdout, ptr);
                        fprintf(stdout, "\n");
                        RexxFreeMemory(ptr);
                    }
                    return 0;
                }
                default:                       /* ignore other switches       */
                    break;
            }
        }
        else                             /* convert into an argument string   */
        {
            if (program_name == NULL) {       /* no name yet?                  */
                program_name = argv[i];        /* program is first non-option  */
                break;     /* end parsing after program_name has been resolved */
            }
            else if ( real_argument )  {  /* part of the argument string       */
                if (arg_buffer[0] != '\0')  {   /* not the first one?          */
                    strcat(arg_buffer, " ");     /* add an blank               */
                }
                strcat(arg_buffer, argv[i]);  /* add this to the argument string */
            }
            real_argument = TRUE;
        }
    }

    if (program_name == NULL) {
        /* give a simple error message       */
#undef printf
        printf("\n");
        fprintf(stderr,"Syntax is \"rexx filename [arguments]\"\n");
        fprintf(stderr,"or        \"rexx -e program_string [arguments]\"\n");
        fprintf(stderr,"or        \"rexx -v\".\n");
        return -1;
    }
    else {                              /* real program execution              */
        getArguments(NULL, GetCommandLine(), &argcount, &arguments);
        rxretbuf.strlength = 0L;                 /* initialize return to empty */

#ifdef REXXC_DEBUG
        printf("program_name = %s\n", program_name);
        printf("argv 0 = %s\n", argv[0]);
        printf("argv 1 = %s\n", argv[1]);
        printf("argv 2 = %s\n", argv[2]);
        printf("argument.strptr = %s\n", argument.strptr);
        printf("argument.strlenth = %lu\n", argument.strlength);
#endif


        if (from_string) {
            /* Here we call the interpreter.  We don't really need to use      */
            /* all the casts in this call; they just help illustrate           */
            /* the data types used.                                            */
            rc=REXXSTART(argcount,                    /* number of arguments   */
                         &arguments,                   /* array of arguments   */
                         program_name,                /* name of REXX file     */
                         instore,               /* rexx code from command line */
                         "CMD",                       /* Command env. name     */
                         RXCOMMAND,                   /* Code for how invoked  */
                         NULL,
                         &rexxrc,                     /* Rexx program output   */
                         &rxretbuf );                 /* Rexx program output   */
            /* rexx procedure executed*/
            if ((rc==0) && rxretbuf.strptr) {
                RexxFreeMemory(rxretbuf.strptr);    /* Release storage only if */
            }
            freeArguments(NULL, &arguments);
        }
        else {
            RexxCreateInterpreter(&pgmInst, &pgmThrdInst, NULL);
            // configure the traditional single argument string

            if ( arguments.strptr != NULL )
            {
                rxargs = pgmThrdInst->NewArray(1);
                pgmThrdInst->ArrayPut(rxargs, pgmThrdInst->String(arguments.strptr), 1);
            }
            else
            {
                rxargs = pgmThrdInst->NewArray(0);
            }

            // set up the C args into the .local environment
            dir = (RexxDirectoryObject)pgmThrdInst->GetLocalEnvironment();
            if ( argc > 2 )
            {
                rxcargs = pgmThrdInst->NewArray(argc - 2);
            }
            else
            {
                rxcargs = pgmThrdInst->NewArray(0);
            }
            for (i = 2; i < argc; i++)
            {
                pgmThrdInst->ArrayPut(rxcargs,
                                      pgmThrdInst->NewStringFromAsciiz(argv[i]),
                                      i - 1);
            }
            pgmThrdInst->DirectoryPut(dir, rxcargs, "SYSCARGS");
            // call the interpreter
            result = pgmThrdInst->CallProgram(program_name, rxargs);
            // display any error message if there is a condition.
            // if there was an error, then that will be our return code.
            // Although the return is a wholenumber_t we know there is no error
            // code too big to fit in an int.
            rc = (int)pgmThrdInst->DisplayCondition();
            if (rc != 0)
            {
                pgmInst->Terminate();
                return -rc;   // well, the negation of the error number is the return code
            }
            // now handle any potential return value
            if (result != NULL) {
                pgmThrdInst->ObjectToInt32(result, &rc);
            }

            pgmInst->Terminate();

            return rc;
        }
    }
    return rc ? rc : rexxrc;                    // rexx program return cd
}
Пример #11
0
LONG REXXENTRY Api_Read_All_Elements_Of_A_Specific_Stem_From_REXX_VP(
  PSZ       name,                      /* Function name              */
  LONG      numargs,                   /* Number of arguments        */
  RXSTRING  args[],                    /* Argument array             */
  PSZ       queuename,                 /* Current queue              */
  PRXSTRING retstr )                   /* Return RXSTRING            */
{
   SHVBLOCK rxshv;
   SHVBLOCK *prxshv = &rxshv, *temp, *interim;
   RexxReturnCode rc;
   char array[20], value[10];
   char pch[64], *result;
   char *varName;

   int chars;
   int j, k = 0;

   if (numargs != 1 )                    /* validate arg count         */
    return INVALID_ROUTINE;
   strcpy(retstr->strptr, "0");
   retstr->strlength = strlen(retstr->strptr);

   strncpy(pch, args[0].strptr, 64);

   prxshv->shvnext = NULL;
   prxshv->shvname.strptr = pch;   /* here we use our own buffer that is limited to 64 characters */
   prxshv->shvname.strlength = strlen(pch);
   prxshv->shvvalue.strptr = NULL; /* let rexx allocate for me */
   prxshv->shvcode = RXSHV_SYFET;

   rc = RexxVariablePool(prxshv);
   if (rc)
   {
      strcpy(retstr->strptr, "ApiFETCH failed \n");
      retstr->strlength = strlen(retstr->strptr);
      return VALID_ROUTINE;
   }

   j = atoi(prxshv->shvvalue.strptr);

   chars = '.';
   result = strrchr(pch, chars);
   result++;
   *result = 0x00;

   temp = prxshv;

   memset(array, 0x00, sizeof(array));
   memset(value, 0x00, sizeof(value));
   for (k = 1;k <= j; k++)
   {
      temp->shvnext = (PSHVBLOCK)malloc(sizeof(SHVBLOCK));  /* allocate a new node */
      temp = temp->shvnext;
      if (!temp)
      {
         strcpy(retstr->strptr, "Allocation error occured");
         retstr->strlength = strlen(retstr->strptr);
         return VALID_ROUTINE;
      }
      strcpy(array, pch);
      sprintf(value, "%d", k);
      strcat(array, value);
      temp->shvnext = NULL;
      temp->shvname.strlength = strlen(array);
      varName = malloc(strlen(array)+1);
      strcpy(varName, array);
      temp->shvname.strptr = varName;
      temp->shvvalue.strptr = NULL; /* let rexx allocate it for me */
      temp->shvcode = RXSHV_SYFET;
   }

   temp = prxshv->shvnext;   /* first allocated one */
   rc = RexxVariablePool(temp);
   if (rc)
   {
      if (rc== RXSHV_MEMFL)
      {
         strcpy(retstr->strptr, "Allocation error occured");
         retstr->strlength = strlen(retstr->strptr);
         return VALID_ROUTINE;
      }
      else if (rc != RXSHV_LVAR)
      {
         printf("ERROR: shvret is %x hex after var nr. %d\n",rc,k);
         return INVALID_ROUTINE;
      }
   }

   for (k = 1;k <= j; k++)
   {
      printf("Name of the Stem-variable from the Variable Pool: %s, Value: %s \n", temp->shvname.strptr,temp->shvvalue.strptr);
      free((void *)temp->shvname.strptr);   /* allocated by us and therefore freed with free */
      RexxFreeMemory(temp->shvvalue.strptr);  /* allocated by REXX and therefore freed by RexxFreeMemory */
      interim = temp;
      temp = temp->shvnext;  /* process next in list */
      free(interim);         /* free current node */
   }
   RexxFreeMemory(prxshv->shvvalue.strptr);  /* allocated by REXX and freed by RexxFreeMemory */

   return VALID_ROUTINE;
}
Пример #12
0
LONG REXXENTRY Api_Read_All_Variables_From_REXX_VP(
  PSZ       name,                      /* Function name              */
  LONG      numargs,                   /* Number of arguments        */
  RXSTRING  args[],                    /* Argument array             */
  PSZ       queuename,                 /* Current queue              */
  PRXSTRING retstr )                   /* Return RXSTRING            */
{
   SHVBLOCK rxshv;
   SHVBLOCK *prxshv = &rxshv;
   RexxReturnCode rc;
   int i = 1;

   strcpy(retstr->strptr, "0");
   retstr->strlength = strlen(retstr->strptr);

   prxshv->shvnext = NULL;
   prxshv->shvname.strlength = 0;
   prxshv->shvname.strptr = NULL;  /* let rexx allocate it for me */
   prxshv->shvvalue.strptr = NULL; /* let rexx allocate it for me */
   /* Another way would be to assign an existing buffer and specify its max. length */
   prxshv->shvcode = RXSHV_NEXTV;

/* Now reading all variables from the REXX-variable pool ***********/

   rc = RexxVariablePool(prxshv);
   if (rc)
   {
      if (rc != RXSHV_LVAR)
      {
        printf("ERROR: shvret is %x hex after var nr. %d \n",rc,i);
        return INVALID_ROUTINE;
      }
   }

   if (prxshv->shvvalue.strlength)
       printf("Name of the variable from the Variable Pool: %s, Value: %s \n", prxshv->shvname.strptr, prxshv->shvvalue.strptr);
   else
       printf("Name of the variable from the Variable Pool: %s, Empty\n", prxshv->shvname.strptr);
   i++;
   RexxFreeMemory((void *)prxshv->shvname.strptr);  /* free pointers allocated by REXX */
   RexxFreeMemory(prxshv->shvvalue.strptr); /* free pointers allocated by REXX */

   while (!prxshv->shvret)
   {
      prxshv->shvret = 0;
      prxshv->shvnext = NULL;
      prxshv->shvname.strlength = 0;
      prxshv->shvname.strptr = NULL;  /* let rexx allocate it for me */
      prxshv->shvvalue.strptr = NULL; /* let rexx allocate it for me */
      prxshv->shvcode = RXSHV_NEXTV;
      rc = RexxVariablePool(prxshv);
      if (rc)
      {
         if (rc== RXSHV_MEMFL)
         {
           strcpy(retstr->strptr, "Allocation error occured");
           retstr->strlength = strlen(retstr->strptr);
           return VALID_ROUTINE;
         }
         else if (rc != RXSHV_LVAR)
         {
           printf("ERROR: shvret is %x hex after var nr. %d\n",rc,i);
           return INVALID_ROUTINE;
         }
      }
      i++;
      if (!prxshv->shvret)
      {
          if (prxshv->shvvalue.strlength)
              printf("Name of the variable from the Variable Pool: %s, Value: %s \n", prxshv->shvname.strptr, prxshv->shvvalue.strptr);
          else
              printf("Name of the variable from the Variable Pool: %s, Empty\n", prxshv->shvname.strptr);
          RexxFreeMemory((void *)prxshv->shvname.strptr);  /* free pointers allocated by REXX */
          RexxFreeMemory(prxshv->shvvalue.strptr); /* free pointers allocated by REXX */
      }
   }
  return VALID_ROUTINE;
}