REXX Tips & Tricks:Miscellaneous
This section contains some further useful information.
Using PMREXX
The syntax for PMREXX is:
>>──PMREXX───┬────┬──┬─────────────┬─┬───────────┬─>< ├─/Q─┤ └─rexxprogram─┘ └─parameter─┘ └─/T─┘
Where:
- /Q
- Close PMREXX after the REXX program ends (no "The program has ended" message box)
- /T
- Start PMREXX in trace mode
- rexxprogram
- Name of the rexx program
- parameter
- Parameter for the REXX program
All parameters, except rexxprogram, are optional.
Using PMREXX with the parameter /Q is useful for simple programs which only need to show a PM messagebox (using RxMessageBox). For an example see Saving the Desktop (3.0)
(see Run a REXX program under a specific environment on how to force a program to run under PMREXX)
Please note that you cannot use OS/2 commands that change the environment in a REXX program running under PMREXX. You have to use a similar REXX function for that purpose (e.g. directory() instead of CD, VALUE() instead of SET, etc.).
Warning: The default address environment for a REXX program started via PMREXX in WARP 3 is PMREXX; the default environment in WARP 4 is CMD. Therefore, you cannot distinguish between the environments using ADDRESS() in WARP 4!
- Note
- see also PMPopup/2 if you only want to use simple dialog boxes in REXX programs.
The RXQUEUE filter
The purpose of the RXQUEUE filter is to copy the output of an OS/2 program into a REXX queue (The RXQUEUE filter is the external program RXQUEUE.EXE - not the built-in function RXQUEUE!) The syntax for RXQUEUE filter is:
>>──RXQUEUE──┬───────────┬──┬────────┬──────>< └─queuename─┘ ├─/FIFO──┤ ├─/LIFO──┤ └─/CLEAR─┘
The RXQUEUE filter usually operates on the default queue named "SESSION". However, if an environment variable named "RXQUEUE" exists, the RXQUEUE value is used for the queue name.
Parameters
- queuename
- This is the name of the queue to use. The queue must already exist. The name of a queue can only contain the following characters: 'A'...'Z', '0'...'9', '.', '!', '?' and '_'. Lowercase letters are converted to uppercase letters.
- /LIFO
- Stacks items from STDIN last in, first out (LIFO) on a REXX queue.
- /FIFO
- Queues items from STDIN first in, first out (FIFO) on a REXX queue.
- /CLEAR
- Removes all lines from a REXX queue.
- Note
- Again, do not confuse the RXQUEUE filter with the RXQUEUE built-in function! Note further that you cannot use the RXQUEUE filter to write a REXX queue to STDOUT - you've to write a REXX program to do this task. (see Write the REXX Queue to STDOUT for an example).
Return code of the function ADDRESS
A REXX program can use the function ADDRESS to detect the current environment. Following is a list of environments I know about (see Passing parameter to Rexx Dialog programs and Run a REXX program under a specific environment for examples for using this function.):
Return code of ADDRESS | Environment | Comments |
---|---|---|
CMD | OS/2 REXX Interpreter; also Object REXX for Win95/WinNT | use PARSE SOURCE to distinguish between the interpreter: OS/2 REXX returns OS/2; Object REXX for WinNT returns WIN32 |
CMS | VM/ESA 1.1 REXX Interpreter | |
COMMAND | Bill's REXX for DOS IBM PC DOS 7 REXX Interpreter |
Use PARSE VERSION to distinguish between the environments. |
CPEDIT | CPEDIT, an XEDIT clone from IBM | |
CPICOMM | SAA common environment especially used with communications | |
DFS | Display File Systems | |
DOS | Bill's REXX for DOS IBM PC DOS 7 REXX Interpreter |
Use PARSE VERSION to distinguish between the environments. |
EPM | EPM, OS/2 Editor | |
GLOBE | PMGlobe 2.18 | IBM EWS Graphic program from Mike Cowlishaw, IBM UK Laboratories |
FLEETSTREET | FleetStreet v1.03 | Msg Reader & Editor for Squish msg bases |
INT2E | Bill's REXX for DOS | |
ispcir | OS/2 DialogManager, IBM | |
IPSEXEC | Tritus SPF, Tritus Inc. | |
ISREDIT | SPF/2, CTC | |
KEDIT | KEDIT, an XEDIT clone from Mansfield Software | |
ksh | IBM's AIX REXX | The value is independent from the current shell |
MVS | OS/390 v1.2 (PGM=IRXJCL) REXX Interpreter | |
NULL | DrDialog | this is an alternate SubCommand-Handler for DrDialog programs |
PMREXX | PMREXX, OS/2 PMREXX.EXE (see the warning in the section Using PMREXX) | |
REXXTERM | REXXTERM, Quercus Software | |
RXDLG | Rexx Dialog | |
SAY | DrDialog | this is an alternate SubCommand-Handler for DrDialog programs |
STARTDOS | StartDOS | a program to start DOS VDMs by Monte Copeland |
SYSTEM | Bill's REXX for DOS Mark Hesslings's Regina REXX for Windows NT |
use PARSE SOURCE to distinguish between the interpreter: Bill's REXX returns MSDOS, Mark's REXX returns WIN32 |
TE2 | TE/2, Oberon Software | |
THE | THE Hessling Editor by Mark Hessling | THE is an XEDIT clone for various operating systems |
TSO | OS/390 v1.2 (TSO) REXX Interpreter | |
VISION | ObjectVision, Borland | |
UNIX | uniREXX on Solaris v2.6 | |
ZOC | ZOC 2.x, Markus Schmidt | One of the best OS/2 terminal programs available! |
ANSI ESC Sequences
ANSI ESC Sequences - also called ANSI commands - are useful for doing some display I/O control in REXX.
To use ANSI commands the OS/2 ANSI support must be active. To activate the ANSI support use the OS/2 command ANSI ON and to deactivate the ANSI support use the OS/2 command ANSI OFF. To get the current status of the ANSI support use the OS/2 command ANSI without a parameter. The default for the ANSI support is ON. (see Check if ANSI is active - 1 - or Check if ANSI is active - 2 - for REXX source to detect if ANSI support is active from within a REXX program)
Each ANSI command begins with the sequence ESC[. where ESC represents the ASCII code 1Bh (= 27 decimal). If there is more than one parameter for an ANSI command, use a semicolon (;) to separate the parameter.
To output ANSI commands you can use the functions LINEOUT and CHAROUT or the statement SAY. Example:
say "1B"x || "[30;41m" || "This text is black on red" call lineOut , "1B"x || "[31;40m" || "This text is red on black" call charOut , "1B"x || "[0m" || "This text is in default color"
(see Using ANSI sequences for some sample code using ANSI sequences and RxLBox - menu routine in REXX is a menu program using only ANSI sequences to implement the navigation with cursor keys and function keys)
- Note
- To use the ANSI commands to set or get the cursor position you must use the function CHAROUT! (see SysCls for another minor restriction)
- Further Note
- Almost all ANSI Control Characters are documented in the command reference of WARP version 4.
Command | Function |
---|---|
ESC[colsA | Cursor up # lines |
ESC[colsB | Cursor down # lines |
ESC[rowsC | Cursor right # columns |
ESC[rowsD | Cursor left # columns |
ESC[row;colH | Position the cursor (the upper left corner is 1,1) |
ESC[2J | Clear the whole screen |
ESC[K | Clear the rest of the line |
ESC[6n | Get the current cursor position (see Get the current cursor position) |
ESC[row;colf | Position the cursor (like "H") |
ESC[row;colR | Report current cursor line and column (*) |
ESC[=modeh | Set the display mode (see below) |
ESC[=model | Set the display mode (see below) |
ESC[attr;attr;..m | Set the color attribute (see below) |
ESC[key;"str"p | Redefine the key "key" with the string "str" (see Key redefinitions and Key Codes for key redefinitions) |
ESC[s | Save the current cursor position (nested calls are not allowed) |
ESC[u | Restore the cursor position (nested calls are not allowed) |
Attribute | Description |
---|---|
0 | all attributes off (white on black) |
1 | bold |
2 | normal |
4 | underline (only on b/w displays) |
5 | blink |
7 | reverse video |
8 | invisible |
30-37 | set the foreground color:
|
40-47 | set the background color:
|
Mode | Description |
---|---|
0 | Text 40x25 monochrome |
1 | Text 40x25 color |
2 | Text 80x25 monochrome |
3 | Text 80x25 color |
4 | Graphics 320x200 4 colors |
5 | Graphics 320x200 2 color |
6 | Graphics 640x200 2-color |
7 | cursor wrap off (7l) or on (7h) |
"Compiling" REXX programs
Prevent REXX from creating a token image
Set the read-only attribute of REXX cmds for which the REXX interpreter should not create a token image (or copy them to a read-only disk or to a filesystem not supporting Extended Attributes).
"Undocumented" REXX functions
The following REXX functions to work with DBCS mixed Strings are only documented in the IBM: OS/2 2.0 Procedures Language/2 Reference Manual and in the Object-Oriented REXX online documentation:
- DBADJUST
- DBBRACKET
- DBCENTER
- DBLEFT
- DBRIGHT
- DBRLEFT
- DBRRIGHT
- DBTODBCS
- DBTOSBCS
- DBUNBRACKET
- DBVALIDATE
- DBWIDTH
Well, for the "normal" REXX programmer only two of these functions are interesting (The functions also work with SBCS strings):
Name DBRLEFT( string, n {,option} ) Function Delete n chars beginning with the first char Example DBRLEFT( "ABCDEFG", 2 ) gives "CDEFG" Note The parameter option is only needed for DBCS strings) For SBCS strings you should not use this parameter.
Name DBRRIGHT( string, n {,option} ) Function Delete n chars beginning with the last char Example DBRRIGHT( "ABCDEFG", 3 ) gives "ABCD" Note The parameter option is only needed for DBCS strings) For SBCS strings you should not use this parameter.