PARSET: Parses an XEDIT target from the beginning of a string

Автор: Rex Swain

Дата: 1999

Источник: www.rexswain.com

The REXX program PARSET.REX parses an XEDIT target from the beginning of its argument and returns the length of the target.

This is very helpful when you want to write an XEDIT macro which allows additional arguments after a line target (like the PUT command does). Detecting the point in the argument where the target ends and the other arguments begin can be very tricky.

Example: Let's say you're writing FOO.REX and it's syntax is:

  • FOO target [filename [filetype [filemode]]]

You would code the beginning of FOO.REX like so:

/* FOO.REX */
 parse arg a              /* The entire argument        */

 i = parset(a)            /* Length of target           */
 t = left(a,i)            /* The target                 */
 r = substr(a,1+i)        /* Everything else            */
/* or: */
 i = 1 + parset(a)        /* 1 + Length of target       */
 parse var a t =(i) r     /* Same t and r as above      */

 say 'Target = "' || t || '"'
 say 'Remain = "' || r || '"'

If you execute:

  • FOO /x/&~,/,data txt

The following output will be produced:

Target = "/x/&~,/,"
Remain = "data txt"