home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / VariableInterface / VarTestC.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  60 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.  
  8. #include "exec/types.h"
  9.  
  10. #include "rexx/storage.h"
  11. #include "rexx/rxslib.h"
  12.  
  13. #include <stdio.h>
  14.  
  15. #define VALUE "A-OK"
  16.  
  17. struct RexxLib *RexxSysBase;
  18.  
  19. extern LONG  CheckRexxMsg(struct RexxMsg *);
  20. extern LONG  GetRexxMsg(struct RexxMsg *,STRPTR,STRPTR *);
  21. extern LONG  SetRexxMsg(struct RexxMsg *,STRPTR,STRPTR,LONG);
  22.  
  23. main(argc,argv)
  24. int argc;
  25. char **argv;
  26. {
  27.    struct MsgPort MyPort;
  28.    struct RexxMsg *rmptr;
  29.    LONG           test,error;
  30.    STRPTR         value;
  31.  
  32.    RexxSysBase = OpenLibrary("rexxsyslib.library",(LONG) RXSVERS);
  33.    if (RexxSysBase == 0) {
  34.       printf("Bad News -- no REXX library\n");
  35.       return(20L);
  36.       }
  37.  
  38.    /* Initialize our message port   */
  39.    InitPort(&MyPort,"VarTest");
  40.  
  41.    /* Make the port public          */
  42.    AddPort(&MyPort);
  43.  
  44.    for (;;) {                          /* wait for messages             */
  45.       Wait(1L<<MyPort.mp_SigBit);
  46.       rmptr = (struct RexxMsg *) GetMsg(&MyPort);
  47.  
  48.       /* Show what we got           */
  49.       printf("VarTest: received command %s\n",rmptr->rm_Args[0]);
  50.  
  51.       /* Make sure it's a valid context */
  52.       if (CheckRexxMsg(rmptr)) {
  53.          printf("VarTest: valid REXX context\n");
  54.  
  55.          if ((error = GetRexxVar(rmptr,"A.1",&value)) == 0)
  56.             printf("VarTest: value of A.1 is %s\n",value);
  57.          else printf("VarTest: error from get %ld\n",error);
  58.  
  59.          error = SetRexxVar(rmptr,"STATUS",VALUE,strlen(VALUE));
  60.          if (error != 0) printf("VarTest: error from 7