home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / message.c < prev    next >
C/C++ Source or Header  |  1998-06-21  |  3KB  |  146 lines

  1. /** message.c
  2.   *
  3.   *                     Copyright 1988, W.G.J. Langeveld
  4.   *                           All Rights Reserved
  5.   *                           Freely Distributable
  6.   *
  7.   *   Send a message to a particular host.
  8.   *
  9.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  10.   *   ============
  11.   *
  12.   *    CURRENT VERSION:
  13.   *
  14.   *    This version has been converted to SAS C 6.5 format. It has been modified
  15.   *    for modern definition sequences for ANSI compilation. This no longer works
  16.   *    with OS versions prior to 2.04.
  17.   *
  18.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  19.   *   ============
  20.   *
  21.   **/
  22.  
  23. #include <functions.h>
  24. #include "ralprotos.h"
  25. #include <exec/types.h>
  26. #include <exec/exec.h>
  27. #include <proto/rexxsyslib.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <ctype.h>
  32.  
  33. char *CAS( char * );
  34. /**
  35.  *
  36.  *   Send the command strings a through g to the port "portname".
  37.  *
  38. **/
  39. int SendPortMsg( char *portname, int n, char *args[], struct MsgPort *replyport )
  40. {
  41.     int result = 12, i;
  42.     struct RexxMsg *msg = NULL;
  43.     struct MsgPort *port = NULL, *rport = NULL;
  44.     
  45.     if (RexxSysBase == NULL)
  46.         return(result);
  47.     if (portname    == NULL)
  48.         return(result);
  49.     if (args        == NULL)
  50.         return(result);
  51.     
  52.     if (replyport == NULL) 
  53.     {
  54.         rport = CreatePort(NULL, 0L);
  55.         if (rport == NULL)
  56.             goto cleanup;
  57.         msg = CreateRexxMsg(rport, 0L, 0L);
  58.     }
  59.     else
  60.     {
  61.         msg = CreateRexxMsg(replyport, 0L, 0L);
  62.     }
  63.     
  64.     if (msg == NULL)
  65.         goto cleanup;
  66.     
  67.     for (i = 0; i < n; i++)
  68.         msg->rm_Args[i] = (STRPTR) args[i];
  69.     
  70.     FillRexxMsg(msg, (long) n, 0L);
  71.     msg->rm_Action = RXCOMM | (n - 1);
  72.     msg->rm_Node.mn_Node.ln_Name = RXSDIR;
  73.     
  74.     Forbid();
  75.     port = FindPort(portname);
  76.     if (port)
  77.         PutMsg(port,  (struct Message *) msg);
  78.     Permit();
  79.     
  80.     result = 13;
  81.     if (!port)
  82.         goto cleanup;
  83.     
  84.     if (rport) 
  85.     {
  86.         WaitPort(rport);
  87.         GetMsg(rport);
  88.         if (result = (int) msg->rm_Result1)
  89.             goto cleanup;
  90.     }
  91.     
  92.     result = 0;
  93.     
  94.     cleanup:
  95.     /*
  96.      *   Cleanup all allocated resources
  97.      */
  98.     if (rport) 
  99.     {
  100.         DeletePort(rport);
  101.         HandlePortReply(msg);
  102.     }
  103.     return(result);
  104. }
  105.  
  106.  
  107. char *rxf_sendp( long *err, int n, char *args[] )
  108. {
  109.     *err = 18;
  110.     
  111.     if ((n > 0) && args[0])
  112.         *err = SendPortMsg(args[0], n - 1, &args[1], NULL);
  113.     
  114.     if (*err)
  115.         return(NULL);
  116.     return(CAS("1"));
  117. }
  118.  
  119. char *whf_sendp( long *err, WORD n, char *args[] )
  120. {
  121.     char *msgargs[16];
  122.     int i;
  123.     
  124.     msgargs[0] = args[1];
  125.     msgargs[1] = args[0];
  126.     
  127.     for (i = 2; i < n; i++)
  128.         msgargs[i] = args[i];
  129.     
  130.     return(rxf_sendp(err, n, msgargs));
  131. }
  132.  
  133.  
  134. HandlePortReply( struct RexxMsg *msg )
  135. {
  136.     if (!RexxSysBase)
  137.         return;
  138.     
  139.     if (msg) 
  140.     {
  141.         ClearRexxMsg(msg, 16L);
  142.         DeleteRexxMsg(msg);
  143.     }
  144.     return;
  145. }
  146.