| Figure 2 - REXXUTIL functions |
| Screen |
| | SysCls() |
| | SysCurPos() |
| | SysCurState() |
| | SysTextScreenRead() |
| | SysTextScreenSize() |
| | |
| File System |
| | SysDriveInfo() |
| | SysDriveMap() |
| | SysFileDelete() |
| | SysFileSearch() |
| | SysFileTree() |
| | SysMkDir() |
| | SysRmDir() |
|
| | SysSearchPath() |
| | SysTempFileName() |
| | |
| WPS Manipulation |
| | SysCopyObject() * |
| | SysCreateObject() |
| | SysCreateShadow() * |
| | SysDeregister ObjectClass() |
| | SysDestroyObject() |
| | SysMoveObject() * |
| | SysOpenObject() * |
| | SysQueryClassList() |
| | SysRegister ObjectClass() |
|
| | SysSaveObject() * |
| | SysSetIcon() |
| | SysSetObjectData() |
| | |
| Miscellaneous System Functions |
| | SysDropFuncs() |
| | SysGetEA() |
| | SysGetKey() |
| | SysGetMessage() |
| | SysIni() |
| | SysOS2Ver() |
| | SysPutEA() |
| | SysSleep() |
| | SysWaitNamedPipe() |
|
The functions provide access and control of OS/2 related functions and data.
Other, third party external function modules are available both as freeware, from
various OS/2 related BBSs, as shareware, and from commercial vendors.
All REXX functions may be either referenced with the CALL keyword
instruction or used any place in a REXX clause where an expression is allowed.
When explicitly called, each parameter passed to the function, except the last, is
terminated with a comma. For example, CALL DATE 'N' results in the system
date, in the format dd Mon yyyy (where dd represents the current day, Mon
represents the current month abbreviation, and yyyy represents the four digit
year). This result is stored in the special REXX variable RESULT. The user
program may then assign the contents of RESULT to another variable. A CALL
to any other function causes the value returned by the call to the DATE()
function to be replaced.
The above example could be written using the function as an expression. For
example, todays_date = DAY('N'). When any function is used as an
expression, the function name must be immediately followed by a left parenthesis
(no intervening space is allowed). Any number of spaces may surround the fields
which occur within the parenthesis.
It is obviously more meaningful to use the DATE() function as an expression;
however, other functions, particularly where the value they return is not
significant, are more meaningful to the observer when used with the CALL
keyword instruction. Remember that the RESULT special variable is assigned a
value when a function is used.
Trap Processing
REXX provides the user with the ability to "trap" unusual occurrences. Trap
means to alter the program flow when a specified event occurs and provide the
program with the information necessary to identify the event. there are six events
which may be monitored: ERROR, FAILURE, HALT, NOTREADY,
NOVALUE, and SYNTAX. Each of these conditions is briefly described in the
rexx.inf file on your system and can be found by doing a search on the word signal.
While a full explanation of all of these six conditions goes beyond the scope of
this column, I do want to describe the use of the NOVALUE condition and how it
should be used.
Since REXX is an "untyped data structure" language (meaning that variables need
not be previously defined prior to their use, many programmers feel
uncomfortable when taking advantage of this convenience in the REXX language.
Still others decry this coding style as a negative characteristic of the language.
Much of this negative criticism can be overcome by use of the NOVALUE
condition associated with either the CALL or SIGNAL keyword instruction.
Either of these two instructions, when used with the NOVALUE condition, cause
program flow to be interrupted and redirected to the label specified within the
CALL or SIGNAL clause to receive control when an initialized variable is used
in a program for any purpose other than to assign a value to it.
Figure 3 contains both the source statements and the output of the TRACE
instruction which result from the presence of an uninitialized variable along with
the reference to the variable being trapped.
Figure 3
/* 9401FIG3.CMD - Show NOVALUE */ /* 0001 */
trace r /* 0002 */
signal on NOVALUE name NOVALUE_TRAP /* 0003 */
a = 1 /* 0004 */
c = a + b /* 0005 */
exit /* 0006 */
/* 0007 */
NOVALUE_TRAP: /* 0008 */
say 'NOVALUE trap on source line' SIGL /* 0009 */
exit /* 0010 */
3 *-* Signal On NOVALUE Name NOVALUE_TRAP;
4 *-* a = 1;
>>> "1"
5 *-* c = a + b;
8 *-* NOVALUE_TRAP:
9 *-* Say 'NOVALUE trap on source line' sigl;
>>> "NOVALUE trap on source line 5"
10 *-* Exit;
When reference is made to variable b, control transfers to the label
NOVALUE_TRAP since b is an uninitialized variable (it has not had a value
assigned to it).
In summary, the CALL and SIGNAL instructions should always be used in REXX
programs of any length to prevent the unintended use of uninitialized variables
as well as other exception conditions that can occur within a REXX program.
Registering External Modules in startup.cmd
The RxFuncAdd() function makes a DLL known to the REXX interpreter in any
given session. However, the entry points within the DLL are not really registered
until one of two conditions occur: either the individual function entry points
within the DLL must be called or referenced in an expression or an entry point
designed into the DLL which registers all of the other entry points in the DLL
must be referenced.
Once a function name, or entry point is registered, it is then available to all
sessions. REXXUTIL, which is part of REXX distributed with OS/2 is a DLL that
provides an entry point that allows all of the individual functions with the DLL to
be registered. That entry point name is SysLoadFuncs.
Since almost every REXX program you use will want to have access to the various
functions with REXXUTIL, and since a single CALL to SysLoadFuncs() results in
all of the functions in the DLL being available to all other OS/2 sessions, by
placing a registration call to REXXUTIL and its self-registering entry point in your
startup.cmd file in the root directory of your OS/2 drive, it then will not be
necessary to register REXXUTIL in any of your other REXX programs.
If you already have a startup.cmd file, you probably already have the following
included in it. If you do not have a startup.cmd file, simply create one with your
favorite ASCII editor with the instructions in Figure 4. The REXXUTIL functions
will then be available in all other sessions.
Figure 4
/* Register REXXUTIL in STARTUP.CMD */
if RxFuncQuery( 'SysLoadFuncs' ) = 0 then
return /* function registered */
if RxFuncAdd( 'SysLoadFuncs' , 'REXXUTIL', 'SysLoadFuncs' ) = 0 then
do
call SysLoadFuncs
if RESULT <> '' then
do
Say 'SysLoadFuncs ' ||,
'returned ' ||,
RESULT
exit
end
end
else
do
Say 'RxFuncAdd returned ' ||,
RESULT ||,
' registering REXXUTIL'
exit
end