home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Anwendungen / Kurztests / GoldED / data / tools / PRJSource / main.c next >
C/C++ Source or Header  |  1995-02-19  |  4KB  |  166 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Example: How to read GoldED's project list. DICE:
  4.  
  5.   dcc main.c -// -o ram:ReadList
  6.  
  7.   ------------------------------------------------------------------------------
  8. */
  9.  
  10. /// "includes & prototypes"
  11.  
  12. #include <amiga20/exec/exec.h>
  13. #include <amiga20/rexx/errors.h>
  14. #include <amiga20/rexx/rxslib.h>
  15. #include <amiga20/clib/exec_protos.h>
  16. #include <amiga20/clib/rexxsyslib_protos.h>
  17.  
  18. #define Prototype extern
  19.  
  20. Prototype void   main(ULONG, char **);
  21. Prototype struct RexxMsg *SendRexxCommand(char *, char *, struct MsgPort *);
  22. Prototype void   FreeRexxCommand (struct RexxMsg *);
  23. Prototype ULONG  WaitForAnswer(struct MsgPort *, char *);
  24.  
  25. ///
  26. /// "main"
  27.  
  28. void
  29. main(argc, argv)
  30.  
  31. ULONG argc;
  32. char *argv[];
  33. {
  34.     const char *version = "$VER: PRJ 1.1 (24.3.94)";
  35.  
  36.     struct MsgPort *replyPort;
  37.  
  38.     char *host = "GOLDED.1";
  39.  
  40.     if (replyPort = CreateMsgPort()) {
  41.  
  42.         if (SendRexxCommand(host, "LOCK CURRENT", replyPort)) {
  43.  
  44.             char result[80];
  45.  
  46.             if (WaitForAnswer(replyPort, result) == RC_OK) {
  47.  
  48.                 if (SendRexxCommand(host, "QUERY PRJLIST", replyPort)) {
  49.  
  50.                     if (WaitForAnswer(replyPort, result) == RC_OK) {
  51.  
  52.                         struct List *list;
  53.                         struct Node *node;
  54.  
  55.                         list = (struct List *)atol(result);
  56.  
  57.                         if (list->lh_Head->ln_Succ) {
  58.  
  59.                             for (node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
  60.                                 printf("%s (selected: %s)\n", node->ln_Name, node->ln_Pri ? "YES" : "NO");
  61.                         }
  62.                         else
  63.                             puts("project list is empty");
  64.                     }
  65.                 }
  66.                 if (SendRexxCommand(host, "UNLOCK", replyPort))
  67.                     WaitForAnswer(replyPort, result);
  68.             }
  69.         }
  70.         DeleteMsgPort(replyPort);
  71.     }
  72.     exit(0);
  73. }
  74.  
  75. ///
  76. /// "ARexx"
  77.  
  78. /* -------------------------------------- WaitForAnswer -----------------------
  79.  
  80.   Wait for answer on previously sent message. Free message afterwards. Primary
  81.   return code is returned, the result string (if any) written to <result>.
  82.  
  83. */
  84.  
  85. ULONG
  86. WaitForAnswer(port, result)
  87.  
  88. struct MsgPort *port;
  89. char   *result;
  90. {
  91.     struct RexxMsg *rexxMsg;
  92.     ULONG  error;
  93.  
  94.     *result = NULL;
  95.  
  96.     do {
  97.         
  98.         WaitPort(port);
  99.  
  100.         if (rexxMsg = (struct RexxMsg *)GetMsg(port))
  101.             if ((error = rexxMsg->rm_Result1) == RC_OK)
  102.                 if (rexxMsg->rm_Result2)
  103.                     strcpy(result, (char *)rexxMsg->rm_Result2);
  104.  
  105.     } while (!rexxMsg);
  106.  
  107.     FreeRexxCommand(rexxMsg);
  108.     return(error);
  109. }
  110.  
  111. /* ------------------------------------- FreeRexxCommand ----------------------
  112.  
  113.  Free ARexx message
  114.  
  115. */
  116.  
  117. void
  118. FreeRexxCommand(rexxmessage)
  119.  
  120. struct RexxMsg *rexxmessage;
  121. {
  122.     if (rexxmessage->rm_Result1 == RC_OK) 
  123.         if (rexxmessage->rm_Result2)
  124.             DeleteArgstring((char *)rexxmessage->rm_Result2);
  125.  
  126.     DeleteArgstring((char *)ARG0(rexxmessage));
  127.  
  128.     DeleteRexxMsg(rexxmessage);
  129. }
  130.  
  131. /* ---------------------------------- SendRexxCommand -------------------------
  132.  
  133.  Send ARexx message
  134.  
  135. */
  136.  
  137. struct RexxMsg *
  138. SendRexxCommand(port, cmd, replyPort)
  139.  
  140. char   *cmd,   *port;
  141. struct MsgPort *replyPort;
  142. {
  143.     struct MsgPort *rexxport;
  144.     struct RexxMsg *rexx_command_message = NULL;
  145.  
  146.     Forbid();
  147.  
  148.     if (rexxport = FindPort(port)) {
  149.  
  150.         if (rexx_command_message = CreateRexxMsg(replyPort, NULL, NULL)) {
  151.  
  152.             if (rexx_command_message->rm_Args[0] = CreateArgstring(cmd, strlen(cmd))) {
  153.  
  154.                 rexx_command_message->rm_Action = RXCOMM | RXFF_RESULT;
  155.  
  156.                 PutMsg(rexxport, &rexx_command_message->rm_Node);
  157.             }
  158.         }
  159.     }
  160.  
  161.     Permit();
  162.     return(rexx_command_message);
  163. }
  164.  
  165. ///
  166.