arexxlib
ARexx is the scripting language of AmigaOS. With these commands a
program can start ARexx scripts and send them commands, and it can be
an ARexx host: a program with a named message port to which scripts
send their commands. The library needs rexxsyslib.library.
ARexx talks through messages. CreateRexxMsg makes one for a reply
port of the program, SendRexxCommand sends it with a command, and the
reply comes back to that port. RexxEvent takes the next message from
the port: either a reply to a message sent, with GetRexxResult and
GetResultString for its results, or a command of a script, which
GetRexxCommand reads and ReplyRexxMsg answers.
port.l=CreateMsgPort("MYHOST")
msg.l=CreateRexxMsg(port,"rexx","MYHOST")
SendRexxCommand msg,"myscript",$01020000 ; RXCOMM with RXFF_RESULTStrings to and from ARexx are ArgStrings: the address of the text,
with ARexx’s information about it in front of it. CreateArgString
and DeleteArgString make and free them; most commands of the library
do it themselves. Messages and ArgStrings the program made are freed
at its end.
The action codes of SendRexxCommand are those of ARexx. A code is
one of the actions, with modifiers added to it, such as these:
| Code | Name | Kind | Meaning |
|---|---|---|---|
| $01000000 | RXCOMM | action | runs a command or script |
| $02000000 | RXFUNC | action | calls a function, with the number of arguments in the low byte |
| $00020000 | RXFF_RESULT | modifier | asks for a result string |
| $00040000 | RXFF_STRING | modifier | the script is given as the command string itself |
When something fails, such as missing memory or a missing
ARexx port, the library shows a recoverable alert, which waits for a
mouse button, and the command does not do its work; CreateRexxMsg
then returns 4 instead of a message.
Based on the arexxlib guide by Acid Software.
Library number 92.
Commands
ClearRexxMsg
Deletes the ArgStrings in the 16 argument slots of an ARexx message and clears the slots. RexxEvent does this itself for a reply.
Statement. Help text: rexxmsg
Arguments: .l
CreateArgString
Makes an ArgString from a string and returns its address, which is that of the text.
Function, result .l. Help text: ArgString=CreateArgString(String)
Arguments: $
An ArgString holds at most 65535 characters; of a longer string it holds the first 65535.
CreateRexxMsg
Makes an ARexx message and returns its address. ReplyPort is the address of the program’s message port to which ARexx replies, Exten the file extension of the scripts (such as “rexx”), and Host the name of the host port.
Function, result .l. Help text: MsgPtr=CreateRexxMsg(ReplyPort,Exten,Host)
Arguments: .l, $, $
DeleteArgString
Frees an ArgString, whether the program or ARexx made it.
Statement. Help text: argstring
Arguments: .l
DeleteRexxMsg
Frees an ARexx message made with CreateRexxMsg.
Statement. Help text: rexxmsg.l
Arguments: .l
FillRexxMsg
Fills the 16 argument slots of an ARexx message from a NewType of a word of flags and 16 longs, given by its address. A set flag bit makes its slot a number; for a clear bit, the long is the address of a string, which becomes an ArgString. Bit 15 belongs to the first slot, bit 14 to the second, and so on.
Statement. Help text: rexxmsg,&FillStruct
Arguments: .l, .l
It is needed for function calls (RXFUNC) and other advanced uses of ARexx. A string address of 0 ends the list; a number 0 is stored like any other number. At most the 16 slots are filled.
GetResultString
The result string of a message ARexx replied to; the ArgString is freed afterwards.
Function, result $. Help text: String=GetResultString(rexxmsg)
Arguments: .l
The message’s result field is cleared with it, so a second call gives the empty string.
GetRexxCommand
The text of argument slot ARGNum of a message, from 1; slot 1 holds the command a script sent.
Function, result $. Help text: String=GetRexxCommand(rexxmsg,ARGNum)
Arguments: .l, .l
With runtime error checking, an ARGNum outside 1 to 16 is the error
“Illegal Argument Number”.
GetRexxResult
Result number ResultNum (1 or 2) of a message ARexx replied to; result 1 is 0 for success, else an error level.
Function, result .l. Help text: Result=GetRexxResult(rexxmsg,ResultNum)
Arguments: .l, .l
With runtime error checking, a ResultNum other than 1 or 2 is the
error “Illegal Result Number”.
IsRexxMsg
1 if the message is an ARexx message, else 0; note that this true value is 1, not -1.
Function, result .l. Help text: Boolean=IsRexxMsg(rexxmsg)
Arguments: .l
ReplyRexxMsg
Answers a command that came from an ARexx script, with the results Result1 (0 for success) and Result2; if Result1 is 0, ResultString can become the result string, as the note below says.
Statement. Help text: rexxmsg,Result1,Result2,ResultString
Arguments: .l, .l, .l, $
ResultString becomes the result string only if the sender asked for
one (the flag RXFF_RESULT in the action) and Result1 is 0; it then
takes the place of Result2. Otherwise the reply carries the number
Result2.
RexxError
The text of an ARexx error code, such as the second result of a failed command.
Function, result $. Help text: ErrorString=RexxError(ErrorCode)
Arguments: .l
RexxEvent
Takes the next message from the message port at PortAddress and returns its address, or 0 if none is waiting; a reply is cleared with ClearRexxMsg first.
Function, result .l. Help text: rexxmsg=RexxEvent(PortAddress)
Arguments: .l
SendRexxCommand
Sends an ARexx message to ARexx with CommandString, normally the name of a script, and the action codes the introduction describes. ARexx looks for the script also with the message’s extension added.
Statement. Help text: rexxmsg,CommandString,ActionCodes
Arguments: .l, $, .l