home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1820.lha / XDME / AREXX / VarTestC.c < prev   
C/C++ Source or Header  |  1993-01-27  |  3KB  |  89 lines

  1. /* A test program to demonstrate the direct variable interface to ARexx.
  2.  * Opens a public port called "VarTest" and then waits for REXX messages.
  3.  * The port stays open until a "CLOSE" command is received.
  4.  * Usage:  run vartest
  5.  * Then send commands from within ARexx by "address 'VarTest' command"
  6.  *
  7.  *    This version for Manx. WGL
  8.  */
  9.  
  10. #include "exec/types.h"
  11.  
  12. #include "rexx/storage.h"
  13. #include "rexx/rxslib.h"
  14. #include "rexx/errors.h"
  15. #include "rexx/rexxio.h"
  16.  
  17. #include <stdio.h>
  18. #ifdef MANX
  19. #include <functions.h>
  20. #endif
  21.  
  22. #define VALUE "A-OK"
  23.  
  24. struct RexxLib *RexxSysBase;
  25.  
  26. extern LONG  CheckRexxMsg();
  27. extern LONG  GetRexxMsg();
  28. extern LONG  SetRexxMsg();
  29.  
  30. main(argc,argv)
  31. int argc;
  32. char **argv;
  33. {
  34.    struct MsgPort MyPort;
  35.    struct RexxMsg *rmptr;
  36.    LONG           test,error;
  37.    STRPTR         value;
  38.  
  39.    RexxSysBase = (struct RexxLib *) OpenLibrary("rexxsyslib.library",0L);
  40.    if (RexxSysBase == 0L) {
  41.       printf("Bad News -- no REXX library\n");
  42.       return(20L);
  43.       }
  44.  
  45.    /* Initialize our message port   */
  46.    InitPort(&MyPort,"VarTest");
  47.  
  48.    /* Make the port public          */
  49.    AddPort(&MyPort);
  50.  
  51.    for (;;) {                          /* wait for messages             */
  52.       Wait(1L<<MyPort.mp_SigBit);
  53.       rmptr = (struct RexxMsg *) GetMsg(&MyPort);
  54.  
  55.       /* Show what we got           */
  56.       printf("VarTest: received command %s\n",rmptr->rm_Args[0]);
  57.  
  58.       /* Make sure it's a valid context */
  59.       if (CheckRexxMsg(rmptr))
  60.          {
  61.          printf("VarTest: valid REXX context\n");
  62.  
  63.          if ((error = GetRexxVar(rmptr,"A.1",&value)) == 0L)
  64.             printf("VarTest: value of A.1 is %s\n",
  65.                    (value ? value : "(No Value)"));
  66.          else
  67.             printf("VarTest: error from get %ld\n",error);
  68.  
  69.          error = SetRexxVar(rmptr,"STATUS",VALUE,sizeof(VALUE));
  70.          if (error != 0L) printf("VarTest: error from set %ld\n",error);
  71.          }
  72.      else printf("VarTest: invalid context!\n");
  73.  
  74.       /* See whether it's the close command                             */
  75.       test = strcmp(rmptr->rm_Args[0],"CLOSE");
  76.  
  77.       rmptr->rm_Result1 = 0L;           /* return code                   */
  78.       rmptr->rm_Result2 = 0L;           /* secondary result              */
  79.       ReplyMsg(rmptr);                  /* send it back                  */
  80.  
  81.       if (test == 0L) break;            /* all done?                     */
  82.       }
  83.  
  84.    RemPort(&MyPort);                   /* unlink it                     */
  85.    FreePort(&MyPort);                  /* release the port resources    */
  86.  
  87.    return(0L);
  88. }
  89.