Example #1
0
int main(int argc, char *argv[])
{
   AREXXCONTEXT RexxStuff = InitARexx("TEST", "test");
   BOOL quit = FALSE;

   printf("running at port \"%s\" with mask %ld\n",
          ARexxName(RexxStuff), ARexxSignal(RexxStuff));

   do {
      ULONG signals = ARexxSignal(RexxStuff);
      struct RexxMsg *message = NULL;
      STRPTR result = NULL;

      signals = Wait(signals);
      message = GetARexxMsg(RexxStuff);
      while (message != NULL) {
         STRPTR command = NULL;

         printf("message = %p\n", message);

         command = ARG0(message);

         printf("command = %p \"%s\"\n", command, command);

         if (!stricmp(command, "quit")) {
            printf("Quitting.\n");
            quit = TRUE;
         }
         ReplyARexxMsg(RexxStuff, message, result, RC_OK);
         message = GetARexxMsg(RexxStuff);
      }
   }
   while (!quit);

   FreeARexx(RexxStuff);
}
Example #2
0
/*
 * This function closes down the ARexx context that was opened
 * with InitARexx...
 */
void FreeARexx(AREXXCONTEXT RexxContext)
{
    register	struct	RexxMsg	*rmsg;

    if (RexxContext)
    {
	/*
	 * Clear port name so it can't be found...
	 */
	RexxContext->PortName[0]='\0';

	/*
	 * Clean out any outstanding messages we had sent out...
	 */
	while (RexxContext->Outstanding)
	{
	    WaitPort(RexxContext->ARexxPort);
	    while (rmsg=GetARexxMsg(RexxContext))
	    {
		if (rmsg!=REXX_RETURN_ERROR)
		{
					/*
					 * Any messages that come now are blown
					 * away...
					 */
		    SetARexxLastError(RexxContext,rmsg,
				      "99: Port Closed!");
		    ReplyARexxMsg(RexxContext,rmsg,
				  NULL,100);
		}
	    }
	}

	/*
	 * Clean up the port and delete it...
	 */
	if (RexxContext->ARexxPort)
	{
	    while (rmsg=GetARexxMsg(RexxContext))
	    {
				/*
				 * Any messages that still are coming in are
				 * "dead"  We just set the LASTERROR and
				 * reply an error of 100...
				 */
		SetARexxLastError(RexxContext,rmsg,
				  "99: Port Closed!");
		ReplyARexxMsg(RexxContext,rmsg,NULL,100);
	    }
	    DeletePort(RexxContext->ARexxPort);
	}

	/*
	 * Make sure we close the library...
	 */
	if (RexxContext->arc_RexxSysBase)
	{
	    CloseLibrary(RexxContext->arc_RexxSysBase);
	}

	/*
	 * Free the memory of the RexxContext
	 */
	FreeMem(RexxContext,sizeof(struct ARexxContext));
    }
}