View Single Post
Old 13 July 2015, 18:54   #54
BigFan
Registered User
 
BigFan's Avatar
 
Join Date: Feb 2014
Location: Germany
Posts: 261
Adding libraries

Libraries

ARexx is a bit limited regarding file system operations or user interaction, and
it lacks a graphical user interface.

One way to add more functions to ARexx is to use additional libraries. Of course,
those libraries have to support ARexx. ARexx comes with 2 libraries, the
rexxsyslib.library and rexxsupport.library. There are third party libraries
available on aminet.

We start with the rexxsupport.library as this offers to us a second way to have
more functionality. It enables us to open our own ports and listen silently while
staying in the background.

To open a library use Addlib(). We have to make sure that the requested library is
successfully opened. In other case, script will fail . Check loaded libs with Show()

Code:
/**/

Options Results

If Show(l,'rexxsupport.library')=0 Then Do
  If Addlib('rexxsupport.library',0,-30,0)=1 Then Exit
End

... Code to run ...
Show() returns 1 if named lib has been found. The code jumps to End where our
code continues.
If library is not loaded, Addlib() tries to open it.

Syntax Addlib('libname', priority, entry point, version)

Priority is a value ranging from -100 to 100. Do not use high priorities, it slows
down all other running tasks. Zero should be fine in most cases.

Entry point is an address offset to query the library if the requested command
is actually available. -30 is often correct, study the library docs if that value
differs from default.

Version is a major version number that represents the minimum version of the lib
to be open. If version is set to 39, any version lower than that causes an error.
Use it when necessary or set zero to ignore version.

An open library can be closed. Use Remlib(libname) for this purpose.

Addlib() opens ports also. Simply call Addlib(name,priority). Entry point and version
are not supported in this mode.

Rexxsupport.library grants access to the following functions:

Allocmem(bytes[,attrib]) - Allocates a block of memory in bytes, default attribute is 'Public'
Closeport(portname) - Closes a message port
Freemem(address, bytes) - Releases a block of Allocated memory
Getarg(message, slot) - Extracts command, function name or string from message pkt
Openport(portname) - Creates a public message port
Reply(message, rc) - Returns a msg pkt to the sender with a value
Showdir(directory[,'A'll|'F'ile|'D'ir][,pad]) - Returns contents of directory as strings of names
Showlist(option,name,pad) - works the same way as Show() but has more options
Statef(filename) - Returns a string containing file information like size and protection bits
Waitpkt(portname) - Waits for a msg pkt from port

Options for Showlist()
'A'ssigns and assigned devices
'D'evice drivers
'H'andlers
'I'nterrupts
'L'ibraries
'M'emory list items
'P'orts
'R'esources
'S'emaphores
'T'asks (ready)
'V'olume names
'W'aiting tasks

Last edited by BigFan; 14 July 2015 at 12:38. Reason: corrected library call and return code check
BigFan is offline  
 
Page generated in 0.04459 seconds with 11 queries