Exemple #1
0
/* Rexx command line interface */
ULONG
RexxInterface(PRXSTRING rxCmd, PUSHORT pusErr, PRXSTRING rxRc)
{
    int rc;
    static JMP_BUF keepenv;
    int cmdlen;

    memcpy(keepenv, command_line_env, sizeof(JMP_BUF));
    if (!SETJMP(command_line_env, 1)) {
	/* Set variable gp_input_line.
	   Watch out for line length of NOT_ZERO_TERMINATED strings ! */
	cmdlen = rxCmd->strlength + 1;
	/* FIXME HBB 20010121: 3rd argument doesn't make sense. Either
	 * this should be gp_input_line_len, or it shouldn't use
	 * safe_strncpy(), here */
	safe_strncpy(gp_input_line, rxCmd->strptr, cmdlen);
	gp_input_line[cmdlen] = NUL;
	rc = do_line();
	*pusErr = RXSUBCOM_OK;
	rxRc->strptr[0] = rc + '0';
	rxRc->strptr[1] = NUL;
	rxRc->strlength = strlen(rxRc->strptr);
    } else {
/*
   We end up here when bail_to_command_line() is called.
   Therefore sometimes this call should be avoided when
   executing a REXX program (e.g. 'Cancel' from
   PM GUI after a 'pause -1' command)
*/
	*pusErr = RXSUBCOM_ERROR;
	RexxSetHalt(getpid(), 1);
    }
    memcpy(command_line_env, keepenv, sizeof(JMP_BUF));
    return 0;
}
Exemple #2
0
RexxReturnCode RexxEntry GrxHost(PCONSTRXSTRING command,
                                 unsigned short int *flags,
                                 PRXSTRING retc)
   {

   /* Local function variables */
   unsigned long i, rc = 0;
   PLL pll;

   #ifdef HOSTEMU_DEBUG
   printf("HOSTEMU: Subcom called.\n");
   #endif

   /* request the semaphore so we can get exclusive access to         */
   /* our variables                                                   */
   pthread_mutex_lock(&hmtxExecIO);

   /* initialize the global variables */
   memset(&ExecIO_Options, '\0', sizeof(EXECIO_OPTIONS));
   ExecIO_Options.lStartRcd = 1;
   prxCmd = command;
   lCmdPtr = 0;
   ulNumSym = 0;
   *flags = RXSUBCOM_OK;

   /* parse the command */
   if (!yyparse ()) {
      #ifdef HOSTEMU_DEBUG
      printf("HOSTEMU: Parse complete.\n");
      #endif
      if (lStmtType == HI_STMT) {
         RexxSetHalt(getpid(), pthread_self());
         }
      else if (lStmtType == TE_STMT) {
         RexxResetTrace(getpid(), pthread_self());
         }
      else if (lStmtType == TS_STMT) {
         RexxSetTrace(getpid(), pthread_self());
         }
      else if (lStmtType == EXECIO_STMT) {
         #ifdef HOSTEMU_DEBUG
         printf("HOSTEMU: Executing execio statement.\n");
         #endif
         /* check to see if the file is already open */
         pll = Search_LL(ExecIO_Options.aFilename);
         if (pll == NULL) {
            /* it is a new file, so open it and add to the list */
            pll = (PLL)malloc(sizeof (LL));
            if (pll == NULL) {
               rc = 20;
               *flags = RXSUBCOM_FAILURE;
               goto return_point;
               }
            memset(pll, '\0', sizeof (LL));
            strcpy(pll -> FileName, ExecIO_Options.aFilename);
            if (ExecIO_Options.fRW) {
               /* DISKW */
               pll -> pFile = fopen(pll -> FileName, "w+");
               }
            else {
               /* DISKR */
               pll -> pFile = fopen(pll -> FileName, "r+");
               }
            if ((pll -> pFile == NULL)) {
               /* file could be opened so return an error */
               free(pll);
               rc = 20;
               *flags = RXSUBCOM_FAILURE;
               goto return_point;
               }
            Insert_LL(pll);
            }
         /* is this a read or write operation? */
         if (ExecIO_Options.fRW) {
            /* DISKW */
            /* is this a stem or queue operation? */
            if (strlen (ExecIO_Options.aStem)) {
               rc = ExecIO_Write_From_Stem(pll);
               }
            else {
               rc = ExecIO_Write_From_Queue(pll);
               }
            }
         else {
            /* DISKR */
            /* is this a stem or queue operation? */
            if (strlen(ExecIO_Options.aStem)) {
               rc = ExecIO_Read_To_Stem(pll);
               }
            else {
               rc = ExecIO_Read_To_Queue(pll);
               }
            }
         /* process the FINIS option */
         if (ExecIO_Options.fFinis) {
            fclose(pll -> pFile);
            Delete_LL(pll);
            }
         /* if the return code is 20 then set the failure flag */
         if (rc == 20) {
            *flags = RXSUBCOM_FAILURE;
            }
         }
      else { /* bad statement type */
         *flags = RXSUBCOM_ERROR;
         rc = 20;
         }
      }
   else { /* parse failed */
      *flags = RXSUBCOM_ERROR;
      rc = 20;
      }

   return_point:

   /* release our symbol table memory */
   if (ulNumSym != 0) {
      for (i = 0; i < ulNumSym; i++) {
         free(pszSymbol[i]);
         }
      }

   pthread_mutex_unlock(&hmtxExecIO);

   sprintf(retc->strptr, "%ld", rc);
   retc->strlength = strlen(retc->strptr);
   #ifdef HOSTEMU_DEBUG
   printf("HOSTEMU: Subcom return code = %u.\n", rc);
   #endif
   return rc;
   }