C (6/178)

From:Christian Hattemer
Date:10 Jul 2000 at 00:17:35
Subject:Re: ARexx

On 07-Jul-00 Martyn Capewell wrote:

> Does anyone have any example C source that can send a command to the ARexx
> port of another program?

Try this Code:

Port : Port where to send the Command
Command : Command to send
ReplyPort: Open a Port with CreateMsgPort() and specify it here
Result : Result String (if any) is written here, specify something
like TEXT Result[200]

Primary Result is returned.

LONG SendRexxCommand(STRPTR Port, STRPTR Cmd, struct MsgPort *ReplyPort, STRPTR Result)
{
ULONG Error;

struct MsgPort *RexxPort;

*Result = '\0';

Forbid();

if (RexxPort = FindPort(Port))
{
struct RexxMsg *rexxMsg, *Answer;

if (rexxMsg = CreateRexxMsg(ReplyPort, NULL, NULL))
{
if (rexxMsg->rm_Args[0] = CreateArgstring(Cmd, strlen(Cmd)))
{
rexxMsg->rm_Action = RXCOMM | RXFF_RESULT;

PutMsg(RexxPort, &rexxMsg->rm_Node);

do
{
WaitPort(ReplyPort);
Answer = (struct RexxMsg *)GetMsg(ReplyPort);
} while (Answer == NULL);

Permit();

if ((Error = Answer->rm_Result1) == RC_OK)
{
if (Answer->rm_Result2)
{
strcpy(Result, (STRPTR)Answer->rm_Result2);
DeleteArgstring((UBYTE *)Answer->rm_Result2);
}
}

DeleteArgstring((UBYTE *)ARG0(Answer));
DeleteRexxMsg(Answer);

return Error;
}
else
{
DeleteRexxMsg(rexxMsg);
}
}
}

Permit();

return RC_FATAL;
}

To see it in action have a look at comm/mail/ML-Support_Src.lha on Aminet.

Bye, Chris



__
///
__ /// Amiga 4000T 040/40 Team *AMIGA*
\\\///
\XX/ http://www.riednet.wh.tu-darmstadt.de/~chris/

B�ren sind vom Aussterben bedroht!
Helfen Sie uns etwas dagegen zu tun!
Lassen Sie sich Ihren pers�nlichen B�ren aufbinden!

------------------------------------------------------------------------
Missing old school friends? Find them here:
http://click.egroups.com/1/5534/1/_/451227/_/963185113/
------------------------------------------------------------------------