Previous Next Chapter

REXXSupport.Library Functions

The functions listed in this section are part of the REXXSupport.library. They may only be used if this library has been opened. Below is an example that shows you how to open this library.

Program 14. OpenLibrary.rexx

/*Add rexxsupport.library if it isn't already open.*/
IF ~ SHOW (`L', "rexxsupport.library") THEN DO
/*If the library isn't open, try to open it*/
IF ADDLIB(`rexxsupport.library', 0, -30,0)
THEN SAY "Added rexxsupport.library."
ELSE DO
SAY `ARexx support library not available, exiting'
EXIT 10 /*Exit if ADDLIB() failed*/
END
END

ALLOCMEM()

ALLOCMEM(length[,attribute])

Allocates a block of memory of the specified length from the system free-memory pool and returns its address as a four-byte string. The optional attribute parameter must be a standard EXEC memory allocation flag, supplied as a four-byte string. The default attribute is for "PUBLIC" memory (not cleared). Refer to the Amiga ROM Kernel Reference Manual: Libraries for information on memory types and attribute parameters.

This function should be used whenever memory is allocated for use by external programs. It is the user's responsibility to release the memory space when it is no longer needed. See also FREEMEM(). For example:

SAY C2X(ALLOCMEM(1000)) -> 00050000
SAY C2X(ALLOCMEM (1000, '00 01 00 0 1'X)) -> 00228400
/*1000 bytes of CLEAR Public memory*/

Closes the message port specified by the name argument, which must have been allocated by a call to OPENPORT() within the current ARexx program. Any messages received but not yet REPLYed are automatically returned with the return code set to 10. See also OPENPORT(). For example:

CLOSEPORT()

CLOSEPORT(name)

CALL CLOSEPORT myport

FREEMEM()

FREEMEM(address,length)

Releases a block of memory of the given length to the system free list. The address parameter is a four-byte string, typically obtained by a prior call to ALLOCMEM(). FREEMEM() cannot be used to release memory allocated using GETSPACE(), the ARexx internal memory allocator. The returned value is a Boolean success flag. See also ALLOCMEM(). For example:

MemoryRequest = 1024
MyMem = ALLOCMEM(MemoryRequest)
SAY C2X(MyMem) -> 07C987B0
SAY FREEMEM(MyMem, MemoryRequest) -> 1
/*Or: SAY FREEMEM(`07C987B0'x,1024)*/

Caution:

Before your program terminates, you must use a matching FREEMEM() to release the exact amount of memory you allocated with each ALLOCMEM(). Otherwise, you may crash the system or leave memory unavailable until you reboot.

Extracts a command, function name, or argument string from a message packet. The packet argument must be a four-byte address obtained from a prior call to GETPKT(). The optional [n] argument specifies the slot containing the string to be extracted and must be less than or equal to the actual argument count for the packet. Commands and function names are always in slot 0. Function packets my have argument strings in slots 1-15. For example:

command = GETARG(packet)
function = GETARG(packet,0) /*name string*/
arg1 = GETARG(packet,1) /*1st argument*/

GETPKT()

GETPKT(name)

Checks the message port specified by the name argument to see whether any messages are available. The named message port must have been opened by a prior call to OPENPRT() within the current ARexx program. The returned value is the four-byte address of the first message packet, or `0000 0000'x if no packets were available.

The function returns immediately whether or not a packet is enqueued at the message port. Programs should never be designed to "busy-loop" on a message port. If there is no useful work to be done until the next message packet arrives, the program should call WAITPKT() and allow other tasks to proceed. See also WAITPKT(). For example:

packet = GETPKT (`MyPort')

OPENPORT()

OPENPORT(name)

Creates a public message port with the given name. The returned Boolean value indicates whether the port was successfully opened. An initialization failure will occur if another port of the same name already exists or if a signal bit couldn't be allocated. The message port is allocated as a Port Resource node and is linked into the program's global data structure. Ports are automatically closed when the program exits and any pending messages are returned to the sender. See also CLOSEPORT(). For example:

success = OPENPORT("MyPort")

Returns a message packet to the sender, with the primary result field set to the value given by the rc argument. The secondary result is cleared. The packet argument must be supplied as a four-byte address, and the rc argument must be a whole number. For example:

REPLY()

REPLY(packet,rc)

CALL REPLY(packet,10) /*Error return*/

Returns the contents of the specified directory as a string of names separated by blanks. The second parameter is an option keyword that selects whether all entries, only files, or only subdirectories, will be included. For example:

SHOWDIR()

SHOWDIR(directory[,'ALL'|'FILE'|'DIR'][,pad])

SAY SHOWDIR(`SYS:REXXC', `f', `;')

-> WaitForPort;TS;TE;TCO;RXSET;RXLIB;RXC;RX;HI

SHOWLIST()

SHOWLIST({`A' | `D' | `H' | `T' | `L' | `M' | `P' | `R' | `S' | `T' | `V' | `W'}[,name][,pad])

An argument is entered using its initial letter. The arguments are:

A

ASSIGNS and Assigned Device

D

Device Drivers

H

Handlers

I

I nterrupts

L

Libraries

M

Memory List Items

P

Ports

R

Resources

S

Semaphores

T

Tasks (Ready)

V

Volume Names

W

Waiting Tasks

If only one argument is supplied, SHOWLIST() returns a string separated by blanks: If a pad character is supplied, names will be separated by the pad rather than by blanks. If the name parameter is supplied. SHOWLIST() returns a Boolean value which indicates if the specified list contains that name. Names are case-sensitive. To provide an accurate snapshot of the current list, task switching is forbidden when the list is scanned.

SAY SHOWLIST(`P') -> REXX MyCon
SAY SHOWLIST(`P',,';') -> REXX;MyCon
SAY SHOWLIST(`P', `REXX') -> 1

STATEF()

STATEF(filename)

Returns a string containing information about an external file. The string is formatted as:

"{DIR | FILE} length blocks protection days minutes ticks comment."

The length token gives the file length in bytes, and the block token specifies the file length in blocks. For example:

SAY STATEF("LIBS:REXXSupport.library")
/*might give "File 2524 5 ----RW-D 4866 817 2088*/

Top Previous Next Chapter