Previous Next Chapter

ARexx Support

You can also control ED from ARexx by sending and receiving commands through ED's ARexx port. Each copy of ED running concurrently has an individual ARexx port name that must be specified to handle information for the correct session. The ARexx port names are assigned as follows:

Many of ED's extended commands can be used from ARexx. By using ED's RV command in ARexx programs, you can send information from ED to ARexx. This gives information about the status of ED, such as the current line number of the name of the file being edited.

The RV command accepts the name of the ARexx stem variable to store its argument information. For example, in ARexx:

address `Ed' `RV /stem/'

assigns values to the following variables:

stem.LEFT

Current left margin

stem.RIGHT

Current right margin

stem.TABSTOP

Current tab stop setting

stem.LMAX

Maximum number of lines visible on screen

stem.WIDTH

Width of the screen in characters

stem.X

Cursor X position in the ED window (1 is the left edge)

stem.Y

Cursor Y position in the ED window (1 is the top line)

stem.BASE

Window base (normally 0, but non-zero when the screen is shifted to the right)

stem.EXTEND

Extended margin value (Extend Margins command)

stem.FORCECASE

Case sensitivity flag (Ignore Case = 1, Case Sensitive = 0)

stem.LINE

Current line number in the file (1 is the first line)

stem.FILENAME

Name of the file being edited

stem.CURRENT

Text of the current line

stem.LASTCMD

Last extended command issued

stem.SEARCH

Lst string searched for

Any valid ARexx symbol can be substituted for "stem". Enclose the name in proper delimiters. These variables can be treated as ordinary ARexx stem variables.

ED/ARexx Example Program

The example program, Transpose.ed, illustrates the use of several extended commands from ARexx. This program transposes two characters when launched from ED. For example, if a line contains the string 123 and the cursor is highlighted the 3, Transpose.ed changes the string to 213.

Enter this program and save it as REXX:Transpose.ed. Then, open ED and edit an existing file or create a new one. Place the cursor one character to the right of the ones to be transposed, press Esc, and enter:

RX /transpose.ed/

The program executes and the characters are transposed if ARexx is running and everything is entered correctly. The entire file name, including the extension, must be specified to run the program.

Sample Program

/*Transpose.ed: An example program to transpose two characters. */

/*Given string `123', if cursor is on 3, this macro converts */

/*string into `213'. */

HOST = address () /*find out which ED session invoked this program*/

address VALUE HOST /*...and talk to that session */

`rv''/CURR/' /*Ask ED to store info in stem variable CURR */

/*Obtain two pieces of information: */

currpos = CURR.X /*1.position of cursor on line */

currling = CURR.CURRENT /*2. Contents of current line */

if /currpos >2) then /*Work only on the current line */

currpos = currpos - 1

else do /*Otheriwse, report error and exit */

`sm/Cusor must be at position 2 or further to the right/'

exit 10

end

/*Next the code needs to reverse the CURRPOSth and CURRPOSth-1 */

/*characters and then replace the current line with the new one. */

/*drop CURR. CURR is no longer needed; dropping it saves some */

/*memory. */

`d' /*Tell ED to delete current line */

currlin = swapch (currpos,currlin) /*Swap the two characters */

`i/'||currlin||'/' /*Insert modified line */

do i = 1 to currpos /*Place cursor back where it started */

`cr' /*ED's `cursor right' command */

end

exit /*Program has finished */

/*Function to swap two characters */

Swapch: procedure */

parse arg cpos,clin

ch1 = substr(clin,cpos1) /*Get character */

clin = delstr(clin,cpos1) /*Delete it from string */

clin = insert(ch1,clin,cpos-2,1) /*Insert to create transposition */

return clin /*Return modified string */

Top Previous Next Chapter