home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rximc175.zip / rexx.ref < prev    next >
Text File  |  2000-11-01  |  171KB  |  3,801 lines

  1. The REXX/imc Interpreter
  2.  
  3. This is a reference for the various language features supported by the
  4. REXX/imc interpreter.  An introduction, summary and technical reference
  5. may be found in rexx.info, rexx.summary and rexx.tech, respectively.
  6. _________________________________________________________________________
  7.  
  8. Invocation:   rexx [flags] filename args
  9.  
  10. where "filename" is the name of the REXX program you wish to execute,
  11. and "flags" are some optional commandline parameters, described later.
  12.  
  13. Notes:
  14.  
  15. 1. If the basename of "filename" does not contain a dot, then an
  16.    interpreter-supplied extension (usually ".rexx") will be appended, and
  17.    will become the "default extension".  If the file is not found with
  18.    this extension then it will be searched without the extension.  If the
  19.    basename of "filename" contains a dot and some following characters
  20.    then these characters will become the default extension (the default
  21.    extension is used when calling external functions).
  22.  
  23.    The interpreter-supplied extension may be changed at compile time
  24.    (see the compilation instructions) or at run time by setting the
  25.    environment variable REXXEXT.  For example: setenv REXXEXT ".exec".
  26.  
  27. 2. The argument string may be any sequence of characters, including
  28.    spaces, but not including NULs (\0). Bear in mind that quotes and/or
  29.    escape characters may be necessary, because the shell interprets
  30.    some characters as special and removes multiple spaces.
  31.  
  32. 3. The REXX program is assumed to be a text file whose lines are
  33.    separated by newline characters: thus newline characters may not
  34.    appear in the middle of a line.  All other characters are allowed
  35.    (but many characters are rejected unless they form part of a string
  36.    constant or comment). 
  37.  
  38. 4. If the given filename does not include a path specification, then
  39.    the interpreter will search through the directories listed in the
  40.    REXXPATH environment variable - or, if that is not defined, the
  41.    PATH environment variable - before looking in the current directory.
  42.    The current directory (.) may be placed in REXXPATH to change this
  43.    searching order.
  44.  
  45. Thus "rexx -ta test hello there" will call the program "test.rexx" with
  46. argument "hello there" and flag "-ta".
  47.  
  48. The flags which are allowed all start with a "-" and are case-
  49. insensitive.  They are:
  50.  
  51.   -option    where "option" is any option recognised by the OPTIONS
  52.              instruction (see below), for example: -tracefile=test1
  53.              (note that the file name in this option is case-sensitive
  54.              as usual).
  55.  
  56.   -v         The interpreter will print out the version string (as used
  57.              by "parse version").  The command "rexx -v" by itself will
  58.              terminate after printing the version string, but all other
  59.              forms will continue as if the -v option were not present
  60.              after printing the version string.
  61.  
  62.   -s string  The interpreter will execute the contents of "string" as
  63.   -c string  though it were a program.  The string may contain newline
  64.              characters, which will be recognised as line terminators
  65.              (in contrast to the string which appears in an INTERPRET
  66.              instruction).  Note that if the string contains any shell
  67.              metacharacters (including spaces) then it must be quoted to
  68.              prevent the shell from interpreting it or splitting it up.
  69.              The flags -s and -c are equivalent.  The latter is provided
  70.              for consistency with shell parameters.
  71.  
  72.   -t setting The interpreter will execute "TRACE setting" before
  73.              interpreting the program.  The space before the setting
  74.              may be omitted, for example: -t?i.  Note that the setting
  75.              may need to be quoted, because "?" is a shell metacharacter.
  76.  
  77.   -i         This equals "-t?a -s 'do forever;nop;end'".  The interpreter
  78.              will enter interactive mode for you to type Rexx
  79.              instructions.
  80.  
  81.   -x         This option is used for files with the execute bit set on:
  82.              it prevents a ".rexx" from being appended to the filename,
  83.              and it causes the first line of the file to be ignored
  84.              (see below).  In REXX/imc >= 1.7 this option is no longer
  85.              needed (since the interpreter will find the file without the
  86.              extension) unless "filename.rexx" is also in the REXXPATH or
  87.              the first line of the program is invalid in Rexx.
  88.  
  89. Except in the case that -i or -s is present, if a filename is omitted
  90. or "-" is specified as the filename then REXX/imc reads a program from
  91. the standard input.
  92.  
  93. The option "-x" and the filename "-" terminate the commandline flags.
  94. The following parameter is assumed to be a filename (except when -i, -s
  95. or - have been specified) followed by the Rexx program parameters.  To
  96. execute a program called "-", say "rexx -x -".
  97.  
  98. REXX/imc allows you to write a program starting with the line:
  99.  
  100. #!/path/rexx [-x]
  101.  
  102. (where /path/rexx is the absolute path name of the interpreter) at the
  103. top of the file so that the program can be made executable by the system.
  104. REXX/imc will ignore the first line if it starts with "#!"  or if the
  105. -x option is supplied.  The line will still be there, however, so line
  106. numbers in error reports will be correct (the `sourceline' function will
  107. also recognise the existence of this line).
  108.  
  109. Using the -x parameter to make REXX/imc ignore the first line allows
  110. a further trick: in order to write a rexx program which is able to be
  111. executed without knowing the exact path name to the interpreter, the
  112. first line of the program should not be as above, but as follows:
  113.  
  114. exec rexx -x "$0" "$*"
  115.  
  116. as long as "rexx" can be found in a directory which is on the current
  117. path.  Instead of that, however, it is now more desireable to use the
  118. following line which is both a valid Rexx comment and a valid Unix
  119. command to start the interpreter.
  120.  
  121. /*bin/true; exec rexx "$0" "$@" # REXX program */
  122.  
  123. The Rexx interpreter needs access to the program "rxque".  It will search
  124. for this file in the following directories (in order):
  125.  
  126.  - that named by REXXIMC, if this environment variable is set.  If it
  127.    is not set, then a default which was chosen at compile time is used
  128.    instead.
  129.  - the path name used when invoking Rexx, if any.  That is, if you type
  130.    "/foo/rexx myexec", then /foo will be searched.  If you type
  131.    "rexx myexec", then this step will be skipped.
  132.  - the directories named in the environment variable PATH
  133.  - the current directory.
  134.  
  135. It should not be necessary to set REXXIMC, but under certain
  136. circumstances it may speed up the initialisation time to do so.
  137.  
  138. Environment Variables
  139.  
  140. As described above, REXXPATH is used to search for any program which is
  141. called as a command, or PATH is used if that is not set.
  142.  
  143. REXXLIB is used to search for function libraries (see the technical
  144. reference for details about function libraries).  If that variable
  145. is not defined then REXX/imc looks in a path which was chosen at
  146. compile time.
  147.  
  148. REXXFUNC is used to search for functions and subroutines which are not
  149. found in any library (whether they are in Rexx or another language).  If
  150. that variable is not defined, then REXX/imc looks in the same place as
  151. for programs which are called as commands.
  152.  
  153. As described above, REXXIMC is used to search for the "rxque" program.
  154.  
  155. Each of REXXLIB, REXXFUNC, REXXPATH and PATH may be a colon-separated
  156. list of directories, but REXXIMC must be a single directory name.
  157. _________________________________________________________________________
  158.  
  159. The REXX Language, as interpreted by this implementation
  160.  
  161.  
  162. NOTE:  There will occasionally be comments headed by `NOTE', `BUG' or
  163.        `LOCAL'. The notes following these will usually be in the
  164.        following categories:
  165.     NOTE - (semi-)important information, pointing out traps or
  166.            differences with other implementations.
  167.     BUG  - a feature of the program (not always a particularly bad one,
  168.            though never beneficial) which may not get fixed.
  169.     LOCAL- a feature of the interpreter which I have deliberately (or
  170.            accidentally) added and is not `real' REXX
  171.  
  172. NOTE:  Just because any particular description does not contain a note
  173.        headed by `LOCAL', that does not necessarily mean that the
  174.        relevant function behaves exactly according to the REXX
  175.        specification. It does mean, however, that I would like to know
  176.        of such instances where there is a difference, so that I can
  177.        either change the program or add a note to describe the
  178.        behaviour.
  179.  
  180. The use of non-implemented REXX constructs will produce either error 82
  181. (Syntax error) or error 81 (Un-implemented function).  I hope that there
  182. is none of these, except that error 81 may occur when a .rxfn function
  183. file is found on a system which does not support dynamic libraries.
  184. _________________________________________________________________________
  185.  
  186. Summary:
  187.  
  188. Expressions
  189. Function or subroutine invocation
  190. Built-in functions
  191. Instructions:
  192.    NOP
  193.    SAY, SAYN (local)
  194.    Assignment
  195.    DROP
  196.    NUMERIC
  197.    EXIT
  198.    DO
  199.    LEAVE
  200.    ITERATE
  201.    IF
  202.    SELECT
  203.    PARSE
  204.    QUEUE, PUSH
  205.    CALL (and function calls)
  206.    RETURN
  207.    PROCEDURE
  208.    INTERPRET
  209.    SIGNAL
  210.    SIGNAL ON
  211.    TRACE
  212.    OPTIONS
  213.    ADDRESS
  214. Commands to the environment
  215. The REXX I/O model
  216. The stack
  217. Error messages
  218. _________________________________________________________________________
  219.  
  220. Expressions
  221.  
  222. Every expression evaluates to a string. There are no numeric expressions,
  223. but arithmetic may be performed on those strings which happen to
  224. represent numbers in decimal. From here on, references to "numbers" or
  225. "numeric" values will mean strings of the following format:
  226.    [+|-] [nnnnn][.][nnnn] [E [+|-] nnn]
  227. That is, an optional sign followed by a string of digits, possibly
  228. including a decimal point, followed by an optional exponent. The exponent
  229. consists of a letter `E' (or `e'), an optional sign, and a sequence of
  230. digits. No spaces are allowed within a number, but trailing or leading
  231. spaces are allowed, and spaces may occur between the leading sign and the
  232. first digit. There is no number which contains no digits before the
  233. exponent (if any), and "." is not a number.
  234.  
  235. Whenever REXX constructs a number (such as the result of an arithmetic
  236. operation), it is formatted according to the following rules:
  237.  
  238.    - a zero result is always expressed as the single digit "0".
  239.    - it is rounded up or down if necessary, so that the specified number
  240.      of significant figures is not exceeded. The number of significant
  241.      figures is usually 9, but can be changed with the NUMERIC DIGITS
  242.      instruction.
  243.    - If the number is negative, it is preceded by a minus sign, otherwise
  244.      there is no sign. A number never contains spaces.
  245.    - If the magnitude of the number is less than 1 (and if exponential
  246.      notation is not used) then a single zero digit precedes the
  247.      decimal point.
  248.    - An exponential form of the number - e.g. 1.234E+65 - will be used
  249.      if the number of digits otherwise required before or after the
  250.      decimal point exceeds NUMERIC DIGITS or twice that value,
  251.      respectively.
  252.    - If NUMERIC FORM SCIENTIFIC is in effect (the default) and the
  253.      number is expressed in exponential form, then the mantissa has
  254.      precisely one digit before the decimal point (if any), which is
  255.      non-zero. The exponent consists of the letter E followed by a plus
  256.      or minus sign, and then the exponent (with no spaces or leading
  257.      zeros).
  258.    - If NUMERIC FORM ENGINEERING is in effect and the number is
  259.      expressed in exponential form then the exponent is a multiple of
  260.      three. Up to three digits appear before the decimal point in the
  261.      mantissa, but otherwise the form is similar to the `scientific'
  262.      form described above.
  263.  
  264. See the NUMERIC command for some more information.
  265.  
  266. An expression consists of one or more constants or variables which
  267. may be combined with the use of operators and functions, as described
  268. below. Spaces are allowed within expressions, as long as they do not
  269. split up variable names or other integral items.
  270.  
  271. String Constants: These are enclosed in quotes. Either single or double
  272.              quotes may be used, but the terminating quote must be the
  273.              same as the initial quote. A string may contain any
  274.              characters, but to enclose a quote of the same
  275.              kind as the delimeters, the quote is typed twice.
  276.              A string containing no characters is a null string.
  277.              Example:
  278.                  "that's right"          has value   that's right
  279.                  '"I''m here," I said.'  has value   "I'm here," I said.
  280.                  ""                      is the null string.
  281.  
  282. Hex Constants:    A hex constant contains a sequence of hex digits
  283.              grouped in pairs. The first group may have just one digit,
  284.              in which case a `0' is added to the left. The groups are
  285.              optionally separated by spaces. Each group (pair) of hex
  286.              digits is translated into the character it represents in
  287.              ASCII. The list is enclosed in quotes and immediately
  288.              after the terminating quote is an `X' (or `x'). The `X'
  289.              must not form part of a longer word.
  290.              Example:
  291.                  "41 4243   44 "x        has value   ABCD
  292.  
  293. Binary Constants: A binary constant is like a hex constant, but has `B'
  294.              instead of `X' and contains binary digits ("0" or "1").
  295.              The digits are arranged in nybbles - that is, groups of 4,
  296.              which may optionally be separated by spaces.  The first
  297.              nybble may have less than 4 digits, in which case it is
  298.              extended on the left with zeros.  If an odd number of
  299.              nybbles is present, a zero nybble is added on the left.
  300.              Each pair of nybbles is then translated into an ASCII
  301.              character.  Example:
  302.                  '10 0011 00100001'b     has value   CA
  303.  
  304.              NOTE: the sequence of binary or hex digits must not contain
  305.                    leading or trailing blanks.
  306.  
  307. Symbols:          A symbol contains any number of letters, numbers,
  308.              dots and the characters @#$!?_ and is always translated
  309.              to upper case before use.  A constant symbol is one which
  310.              starts with a number or a dot, and when it is found in an
  311.              expression, the characters of the symbol itself are used.
  312.              In addition, a single plus or minus sign is allowed in a
  313.              constant symbol if it is part of (the exponent of) a number
  314.              as defined above.
  315.                   Any non-constant symbol may be assigned a value by the
  316.              statement
  317.                        symbol = expression
  318.                   A simple symbol is one which does not contain any dots
  319.              and does not start with a digit. When it is used in an
  320.              expression it names a variable, and if it has been assigned
  321.              a value then that value is used, otherwise the symbol itself
  322.              is used (after translating to upper case).
  323.                   A stem is a symbol which ends with a dot, but does not
  324.              contain any other dots and does not start with a digit or
  325.              dot.  It can be used in an expression or assigned to (see
  326.              below).
  327.                   A compound symbol is a symbol which consists of a stem
  328.              followed by a tail. The tail consists of a non-empty
  329.              sequence of `qualifiers' separated by dots. Each qualifier
  330.              is ordinarily a simple symbol, a constant symbol, or null
  331.              (that is, it contains no characters), but as a LOCAL
  332.              extension, some additional qualifiers are allowed.  The
  333.              following can be used as qualifiers:
  334.               1. a simple symbol, which is substituted by its value
  335.                  before being used in the compound variable name
  336.               2. a constant symbol, which is uppercased before being used
  337.                  in the compound symbol
  338.               3. a null qualifier (as in `a..b')
  339.               4. a string constant
  340.               5. a parenthesised expression.
  341.              The stem and all qualifiers (1) and (2) above are uppercased
  342.              before use, but the value of a symbol in (1) or of a string
  343.              constant or expression in (4) or (5) is not uppercased.
  344.                   After the name of a compound symbol has been found, if
  345.              it has a value then that value is used, otherwise the name
  346.              of the symbol is used (with no uppercasing).
  347.                   If a stem is assigned a value (as in `foo.=7'), then
  348.              every possible compound symbol is given that value (so, for
  349.              example, foo.bar now has value 7).  If a stem is used in an
  350.              expression, its value will be the last value assigned to the
  351.              stem, if any (and otherwise its value will be the stem's
  352.              name in uppercase).  So, for example, foo. now has value 7.
  353.  
  354.              Examples:
  355.              If foo has been assigned the value 5 but no other names have
  356.              been assigned values, then:
  357.                 foo is a simple symbol with a value
  358.                 foobar is a simple symbol without a value
  359.              and
  360.                 foo.5
  361.                 foo.Foo
  362.                 FOO.'5'
  363.                 foo.(foo*3-10)
  364.              all represent the same compound symbol (which has no value,
  365.              so the string "FOO.5" will be used).
  366.              However,
  367.                 foo.'bar'
  368.                 foo.'BAR'
  369.              represent different compound symbols, each of which has no
  370.              value (so the strings "FOO.bar" and "FOO.BAR" will be used
  371.              respectively).
  372. LOCAL:       Note that qualifiers (4) and (5) above are local extensions.
  373.  
  374. Literals:         A literal is another name for a constant symbol, or a
  375.              non-constant symbol without a value.
  376.  
  377. BUG:  There is an upper limit on the length of variable names. If at any
  378.       time during the interpretation of a variable name the interpreter's
  379.       copy of the name is likely to exceed about 250 characters, there
  380.       will be an error.
  381.  
  382. Operators:
  383.  
  384. Each operator described below will be given a priority. Operators are
  385. applied, from left to right, in order of their priority, 1 being
  386. carried out last. Thus, in "3+4*5/2" the operations carried out are, in
  387. order:
  388.    4*5=20  (priority 8)
  389.    20/2=10 (priority 8)
  390.    3+10=13 (priority 7)
  391.  
  392. Unary operators:  + 11  (+a is similar to 0+a)
  393.                   - 11  (arithmetical negation)
  394.                   ^
  395.               or  \ 11  (boolean negation)
  396. Binary operators: **10  (exponentiation)
  397.                   *  8  (multiplication)
  398.                   /  8  (division)
  399.                   %  8  (integer division)
  400.                   // 8  (remainder from integer division)
  401.                   +  7  (addition)
  402.                   -  7  (subtraction)
  403.                   || 6  (concatenation)
  404.                   =  5  (equality)
  405.                   == 5  (strong equality)
  406.                   <>
  407.               or  ><
  408.               or  ^=
  409.               or  \= 5  (not equality)
  410.                  ^==
  411.                  \== 5  (strong nequality)
  412.                   <  5
  413.                   <=
  414.               or  ^>
  415.               or  \> 5  (the usual relations)
  416.                   >  5
  417.                   >=
  418.               or  ^<
  419.               or  \< 5
  420.                   >> 5  (strong greater-than)
  421.                   << 5  (strong less-than)
  422.                  >>=
  423.               or ^<<
  424.               or \<< 5  (strong greater-or-equal)
  425.                  <<=
  426.               or ^>>
  427.               or \>> 5  (strong less-or-equal)
  428.                   &  3  (boolean and)
  429.                   |  2  (boolean or)
  430.                   && 2  (boolean xor)
  431.  
  432. NOTE: The character `\' and the character `^' both mean `not' and
  433.       are interchangeable.  The preferred `not' character is `\'.
  434.  
  435. In addition to these binary operations, there are two concatenation
  436. operators. Firstly, if two values are placed next to each other with
  437. no space in between (clearly they must be differentiable for this to
  438. make sense), they are concatenated, with priority 6. Secondly, if two
  439. values are placed next to each other with at least one space between,
  440. they are concatenated with a space between, with priority 6.
  441.  
  442. For example, 1"+"1"="1+1             has value   1+1=2
  443.              1    "+" 1   "="1+1     has value   1 + 1 =2
  444.  
  445. NOTE: There are a small number of cases where the space operator does
  446.      not give the intended result. Example:
  447.          1  -2   4   -7       does not equal 1 -2 4 -7
  448.                               but it equals  -1 -3
  449.      because spaces are allowed within expressions, and so this
  450.      expression is interpreted as meaning
  451.          1-2  4-7
  452.  
  453. Parentheses are used in order to circumvent the usual priorities of
  454. operators, so that, for example, (1+2)*3 is 9, whereas 1+2*3 is 7.
  455.  
  456. A function call consists of a function name (which is a symbol) followed
  457. immediately by a left parenthesis, a list of expressions separated by
  458. commas, and a right parenthesis.  Arguments may be omitted simply by
  459. putting no expression between one comma (or parenthesis) and the next.
  460. As with simple symbols, the function name is translated to upper case
  461. unless it is a string constant.  Note that a function name must not
  462. end with a dot unless it is quoted, because in that case it would be
  463. interpreted as a compound symbol containing a parenthesised expression.
  464. Also note that there must be no space between the function name and the
  465. opening parenthesis, because otherwise the space will be treated as a
  466. concatenation operator (see above).  When a function is called, it must
  467. return a result, otherwise an error will be raised.
  468.  
  469. Examples: time('c')       uname('-a')        format(x,,,,4)
  470.  
  471. See the section on function or subroutine invocation for more details.
  472.  
  473. Arithmetic Operators:
  474.  
  475.   The operand(s) must be numeric values. If they are not, then an error
  476. results.
  477.   The usual arithmetic rules apply. See the "NUMERIC" command.
  478.   The y operand the exponentiation operator in "x ** y" must be an
  479. integer, otherwise an error results. The exponentiation operator works
  480. effectively by multiplying x by itself y times, and taking the
  481. reciprocal if y<0. (It uses an O(log y) method).
  482.   The integer division operator % is defined so that x%y is the integer
  483. part of x/y (obtained by rounding towards zero), and x = y*(x%y) + (x//y)
  484. For example, 10 % 0.3 = 33  and  10 // 0.3 = 0.1
  485.   An integer is a whole number which lies within the range of the machine
  486. (-2**31 to 2**31-1).  A whole number is any number with no non-zero
  487. fractional part which would not be written in exponential notation when
  488. formatted.
  489.   The maximum exponent is about 999999999. An overflow or underflow
  490. will occur if the limit is exceeded.
  491.  
  492. BUG:  You might find that the maximum number boundary is a little `fuzzy'
  493.       but if you keep below 1E999999990 you should be alright!
  494. BUG:  Whole numbers must be less than 1999999999.
  495.  
  496. Boolean logic:
  497.  
  498. Several of the above operators operate on boolean values or create
  499. boolean values. The following rules apply:
  500.  
  501. 1. The result of a binary relation or of the \ (or ^) operator is always
  502.    1 for true, 0 or false.
  503. 2. A boolean value is represented by any number (attempts to use other
  504.    strings will result in an error). False is represented by zero, and
  505.    any other number represents true.
  506.  
  507. LOCAL: In `real' REXX a boolean value may only be represented by 0 or 1.
  508.  
  509. 3. \x has the obvious meaning consistent with the above (i.e. 1 if x=0,
  510.    and 0 otherwise).
  511. 4. x & y   is 0 if y is false but has the same value as x when y is true.
  512. 5. x | y   is 1 if y is true but has the same value as x when y is false.
  513. 6. x && y  has value x if y is false, and \x otherwise.
  514.  
  515. Binary relations:
  516.  
  517. (note that the symbol '\' means `not' and may be placed before any of the
  518. relations to negate its value, e.g. \=, \>> etc. Thus, for instance,
  519. \> and <= have the same meaning, as do \>> and <<=, etc.  The character
  520. `^` is a synonym for '\' - so ^== is the same as \==).
  521.  
  522. The operators ==, \==, <<, >>, <<=, >>= compare their two operands
  523. character by character and thus have the normal meaning of string
  524. equality, greater, less, etc.
  525.  
  526. All other operators depend on whether or not both operands are numeric.
  527. If they are, then they are subtracted and the result compared with zero.
  528. Otherwise, leading and trailing spaces are stripped and the operations
  529. are compared as strings usually are, with the shorter string being
  530. padded on the right with spaces before the comparison.
  531.  
  532. Hence:  "0.10"    \== "1e-1"        (strict string comparison)
  533.         "0.10"     =  "1e-1"        (numeric comparison)
  534.         "  hello" \== "hello  "     (strict comparison respects spaces)
  535.         "  hello"  =  "hello  "     (weak comparison strips spaces)
  536.         "abc "     >> "abc"         (strict comparison respects spaces)
  537.         "61626300"x < "616263"x     (the latter is padded with a space)
  538.         "61626364"x > "616263"x     (ordinary string comparison)
  539.         "2.5"       > "10abc"       (string comparison)
  540.         "2.5"       < "10"          (numeric comparison)
  541.         "2.5"      >> "10           (strict string comparison)
  542.  
  543. In this implementation, character comparisons are unsigned, that is to
  544. say "ff"x is greater than "00"x, etc.
  545. _________________________________________________________________________
  546.  
  547. Function or Subroutine Invocation
  548.  
  549. A function is a routine which is called using the syntax:
  550.  
  551.    symbolorstring(arguments)
  552.  
  553. whereas a subroutine is a routine which is called using the syntax:
  554.  
  555.    CALL symbolorstring arguments
  556.  
  557. In each case the method of searching for and executing the routine is
  558. that detailed below.  What happens when the routine returns depends upon
  559. whether the routine was called as a function or a subroutine: a function
  560. is required to return a result, whereas a subroutine need not.  Also, the
  561. result from a subroutine, if any, is assigned to the special variable
  562. RESULT after the subroutine finishes.  The remainder of this section
  563. describes the features which are common to subroutines and functions.
  564.  
  565. There are three types of routine, which are searched in the following
  566. order:
  567.   1. Internal routines.  These are not searched if the routine name is a
  568.      string constant.
  569.   2. Built-in routines (a list of which is given in the next section).
  570.      Note that if the routine name is a string constant, it must be in
  571.      upper case for the search to succeed.
  572.   3. External routines.
  573.  
  574. An internal routine is one which is stored in the currently executing
  575. program.  It is introduced by a label, which takes the form
  576.   name:
  577. and may be placed anywhere at the start of an instruction (or on its
  578. own on a line).  When an internal function is called, all labels are
  579. checked.  When a match is found, interpretation jumps to the instruction
  580. immediately following the label, and continues until the next RETURN
  581. statement (or EXIT, or the end of the program).  When RETURN is reached
  582. execution continues from the point of the call (but since reaching an
  583. EXIT or the end of the program causes the program to terminate, execution
  584. cannot continue in these cases). 
  585.  
  586. The arguments to an internal routine may be found using the "PARSE ARG"
  587. instruction.  A result may be returned to the caller by writing it as a
  588. parameter to the RETURN instruction.
  589.  
  590. The name of a label or of an internal routine may contain letters,
  591. numbers, dots and characters which are valid in symbols, but must not
  592. end with a dot.  The name is translated to uppercase (except in the
  593. case of string constants) but no variable substitution occurs, even
  594. after a dot.
  595.  
  596. On entry to an internal function, the special variable SIGL will be
  597. set to the line number of the instruction which caused the transfer of
  598. control.  This applies equally to function calls, subroutine calls with
  599. the CALL instruction, and instructions which cause a condition handler
  600. to be called (see "CALL ON").
  601.  
  602. An internal routine may or may not hide (some or all of) its variables
  603. using the PROCEDURE instruction, described below.  By default, all
  604. variables remain visible during an internal routine.
  605.  
  606. An external routine is any routine which is stored in a separate file
  607. on the system.  It may be in Rexx or in any other language, and it may
  608. be stored singly or in a library.  Libraries are searched first, in the
  609. directories named by environment variable REXXLIB, or, if that is not
  610. set, in the path chosen at compile time (see the technical reference for
  611. details on how to write a function library).  If a routine is not found
  612. in a library, it is searched for in the directories named by environment
  613. variable REXXFUNC or (if that is not set) REXXPATH or (if neither of
  614. those is set) PATH.  The name of the routine as given by the calling
  615. program will be translated to lower case, even if it is a string constant
  616. (though this may change in a future release).  The full path name of
  617. the routine, excluding its file extension, may be given by the calling
  618. program, but in this case the name will need to be enclosed in quotes
  619. because otherwise the slash (/) would be interpreted as a division
  620. operator.
  621.  
  622. An external routine or library may be written in one of four ways,
  623. which are searched for in order:
  624.    - A function registered by RXFUNCADD or by using the API;
  625.    - A dynamically loaded object file whose name ends with ".rxfn";
  626.    - A Rexx program whose name ends with either
  627.       * the default extension, or
  628.       * the interpreter-supplied extension (usually ".rexx"), or
  629.    - Any Unix program whose name matches that given by the caller
  630.      without a file extension.
  631.  
  632. The technical reference gives details on how to write external functions
  633. which can be registered or dynamically loaded, or which are Unix
  634. programs.  Note, however, that certain Unix system programs may be
  635. also called using this interface, for example: uname('-s')='SunOS'
  636. (perhaps).
  637.  
  638. An external routine which is a Rexx program will be executed as if it
  639. were a completely separate process.  All parameters such as NUMERIC
  640. DIGITS and ADDRESS will be set to default values, all condition traps
  641. (see "CALL ON" and "SIGNAL ON") will be reset, and none of the variables
  642. of the caller will be accessible (but see OPTIONS 'EXPOSE' below).  All
  643. these things will be preserved during the external routine and restored
  644. when the routine finishes.  However, OPTIONS settings may or may not be
  645. reset to their defaults and preserved.  There is thus no way for one REXX
  646. program to affect the variables of another, except via parameters and
  647. results.  (Note that data can be passed back and forth via the stack,
  648. however).
  649.  
  650. An external routine which is a Rexx program may use the "PARSE ARG"
  651. instruction to examine its arguments, and may return a result to
  652. the caller by specifying it as a parameter to the RETURN or EXIT
  653. instructions.  When the program terminates using RETURN or EXIT or
  654. when the interpreter reaches the end of the program, the caller will
  655. resume execution as normal.
  656.  
  657. NOTE: Once a ".rxfn" routine or library has been found, all the routines
  658.       defined within it become in effect built-in functions.  When the
  659.       interpreter is searching for such a routine, the name is not
  660.       translated to lower case, and any leading path name is ignored.
  661.       However, the name of the routine (i.e. that part which comes after
  662.       the last slash) will usually be required to be in upper case - so
  663.       "/my/directory/ROUTINE" is the preferred way to name a routine in
  664.       /my/directory.
  665. NOTE: The above notes about case translation will change in the future.
  666.  
  667. NOTE: When a single routine other than a ".rxfn" file is found, its
  668.       file name is stored by the interpreter.  This result will be
  669.       used for any future references to routines with the same spelling
  670.       (including case).  This makes the call faster, but it means that
  671.       files used as routines should not be renamed while the interpreter
  672.       is active.  A similar note applies to libraries: the interpreter
  673.       reads all library definitions at the first external routine call,
  674.       and therefore libraries should not be changed or renamed while the
  675.       interpreter is active.
  676.  
  677. Examples (assuming that the default extension is ".rexx"):
  678.   foo(3,,6)          calls an internal or built-in function named FOO,
  679.                      or an external function named foo.rxfn, foo.rexx
  680.                      or just foo, with arguments "3", nothing, "6".
  681.   'DATE'()           always calls the built-in function DATE with no
  682.                      arguments.
  683.   call "/bin/ABC" 6  calls an external subroutine named /bin/abc.rxfn,
  684.                      /bin/abc.rexx or /bin/abc with argument "6".
  685.  
  686. This program uses an internal function to calculate a factorial.
  687.  
  688.         parse arg x         /* this is an example factorial program. */
  689.         say x"!="fact(x)
  690.         exit
  691.  fact:  parse arg p         /* the argument to fact is assigned to p */
  692.         if p<3 then return p
  693.         return p*fact(p-1)
  694. _________________________________________________________________________
  695.  
  696. Built-In Functions
  697.  
  698. In this section, several of the function arguments are named with the
  699. following conventions:
  700.  
  701.  "number"   must be numeric.
  702.  "length"   must be a non-negative whole number.
  703.  "count"    must be a non-negative whole number.
  704.  "position" must be a positive whole number.
  705.  "pad"      must be a string of length 1.
  706.  "option"   must be a nonempty string.  Only the first character of the
  707.             option is significant, and it is translated to uppercase
  708.             before use.
  709.  "file"     must be the name of a stream.  This can be any nonempty
  710.             string which does not contain NUL characters ('0'x).
  711.  
  712.  
  713. ABBREV(information,info[,length])
  714.  
  715. This returns 1 if info is a valid abbreviation of information - that is,
  716. info is a prefix of information and its length is at least that specified
  717. by the optional third argument (whose default is the length of info). If
  718. the length given is zero, then a null string is a valid abbreviation of
  719. anything.
  720.  
  721. ABS(number)
  722.  
  723. The magnitude of the given number is returned.
  724.  
  725. ADDRESS()
  726.  
  727. The current environment string is returned (see ADDRESS instruction).
  728.  
  729. ARG([position][,option])
  730.  
  731. This function deals with the argument(s) passed into a REXX program,
  732. function or subroutine. With no parameters, the result is the number of
  733. arguments given; that is, the position of the last explicitly specified
  734. argument. If the parameter "position" is given, then the result is the
  735. "position"th argument string, or an empty string if the argument was
  736. not supplied. If the option is supplied, its first character must be
  737. "E" or "O", standing for "Exists" or "Omitted" respectively. The result
  738. of the function is then 0 or 1, depending on whether the "position"th
  739. argument string exists or was omitted, with 1 meaning that "option" is
  740. true.
  741.  
  742.   Example: if a rexx function was called by: 
  743.          foo(5,,7)
  744.   then   arg()      = 3
  745.          arg(1)     = 5
  746.          arg(2,'e') = 0
  747.  
  748. BITAND(string1[,[string2][,pad]])
  749.  
  750. This function performs a bitwise-AND on its two string arguments.  If
  751. the string2 argument is omitted, an empty string is used for string2
  752. instead.  Before the operation, the shorter of the two string arguments
  753. is padded with the pad character.  If no pad character is given, then
  754. 'FF'x is used, so that excess characters in the longer string remain
  755. unchanged after the operation.  The result of the operation is the
  756. string of characters such that the nth character in the string is the
  757. bitwise-AND of the nth character of string1 and the nth character of
  758. string2.
  759.  
  760. BITOR(string1[,[string2][,pad]])
  761.  
  762. This function performs a bitwise-OR on its two string arguments.  If
  763. the string2 argument is omitted, an empty string is used for string2
  764. instead.  Before the operation, the shorter of the two string arguments
  765. is padded with the pad character.  If no pad character is given, then
  766. '00'x is used, so that excess characters in the longer string remain
  767. unchanged after the operation.  The result of the operation is the string
  768. of characters such that the nth character in the string is the bitwise-OR
  769. of the nth character of string1 and the nth character of string2.
  770.  
  771. BITXOR(string1[,[string2][,pad]])
  772.  
  773. This function performs a bitwise-XOR on its two string arguments.  If
  774. the string2 argument is omitted, an empty string is used for string2
  775. instead.  Before the operation, the shorter of the two string arguments
  776. is padded with the pad character.  If no pad character is given, then
  777. '00'x is used, so that excess characters in the longer string remain
  778. unchanged after the operation.  The result of the operation is the
  779. string of characters such that the nth character in the string is the
  780. bitwise-XOR of the nth character of string1 and the nth character of
  781. string2.
  782.  
  783. C2X, C2D, B2X, B2D, D2C, D2B, D2X, X2B, X2C, X2D
  784.  
  785. Each of these is a function taking an argument and possibly a count and
  786. returning a conversion of that argument. Each function converts an
  787. argument of a type indicated by the first character of the function name
  788. (Character, heX, Binary or Decimal) into the type indicated by the last
  789. character of the name.
  790.  
  791.  Examples: c2x("abc") = "616263"   d2x(286)="11E"
  792.            d2c(65)="A"             d2b(65)="01000001"
  793.  
  794. BUG: Each of the conversion functions which deal with decimal numbers is
  795.      restricted to inputs which have a value of less than 2**31 when
  796.      converted to an unsigned integer.
  797. LOCAL: B2D and D2B are not defined in standard REXX.
  798.  
  799. Details of these functions are below:
  800. .........................................................................
  801.  
  802. B2D(binary)
  803.  
  804. The binary input is converted into a non-negative decimal number.  Spaces
  805. are allowed in the binary string between four-digit sequences, and the
  806. first "four-digit" sequence may contain fewer than four digits, in which
  807. case up to three leading '0' digits will be assumed.
  808.  
  809. B2X(binary)
  810.  
  811. Each set of four binary digits in the input is converted to a hex digit
  812. and these are concatenated together to form the result.  Spaces are
  813. allowed in the binary string between four-digit sequences, and the
  814. first "four-digit" sequence may contain fewer than four digits, in
  815. which case up to three leading '0' digits will be assumed.
  816.  
  817. D2B(decimal)
  818.  
  819. The decimal input is converted into binary. The length of the result is
  820. the smallest possible multiple of 8.
  821.  
  822. C2X(string)
  823.  
  824. The n-character string is converted into 2n hex digits.
  825.  
  826. C2D(string[,length])
  827.  
  828. The string is converted into a decimal number, interpreting the leftmost
  829. character as the most significant byte.  If length is omitted, then the
  830. whole string is converted and the result is positive. If the length is
  831. given, then the string is truncated or padded with zero bytes on the
  832. left to give a string of this length, and is then taken to be a twos
  833. complement number. In this case the result may therefore be negative.
  834.  
  835. D2C(decimal[,length])
  836.  
  837. The decimal number is converted into a string of characters (with the
  838. leftmost character being the most significant). If the length is given,
  839. then the result is truncated or sign-extended on the left to be of this
  840. length.  Otherwise the length of the result is such that the leftmost
  841. character is not '00'x (for positive numbers) or 'FF'x (for negative
  842. numbers) except in the case of zero, which is converted to '00'x.
  843.  
  844. D2X(decimal[,length])
  845.  
  846. The decimal number is converted into a hex number.  If the length is
  847. given, then the result is truncated or sign-extended on the left to be
  848. of this length.  Otherwise the length of the result is such that for
  849. positive numbers there is no leading zero, and for negative numbers
  850. there is no leading 'F' except in the case when the next hex digit is
  851. less than 8. D2X(0) returns a single zero digit.
  852.  
  853. X2B(hex)
  854.  
  855. Each digit in the given hex string is converted to four binary digits and
  856. these are concatenated together.  Spaces are optional between pairs of
  857. hex digits, and the first "pair" of digits may contain only one digit.
  858.  
  859. X2C(hex)
  860.  
  861. The hex string is converted to characters, just as when 'hex'x is typed.
  862. Spaces are optional between pairs of hex digits, and the first byte of
  863. the string may optionally contain only one digit, in which case a
  864. leading '0' is assumed.
  865.  
  866. X2D(hex[,length])
  867.  
  868. The hex string, which should contain only hex digits (and no spaces) is
  869. first truncated or extended with zeros on the left to be of the given
  870. length if necessary, and then converted into a decimal number.  If the
  871. length is given, then the hex is assumed to be in twos complement
  872. notation.  Otherwise the result will always be nonnegative.
  873. .........................................................................
  874.  
  875. CENTER(s,length[,pad])  or  CENTRE(s,length[,pad])
  876.  
  877. This function returns a string of the given length containing s. If s
  878. contains fewer than the required number of characters, then pad
  879. characters (pad, or by default, blanks) are added on each side to
  880. centre s in the result, otherwise characters are taken away from each
  881. side of s leaving the middle block of characters. If an odd number of
  882. characters needs to be added or taken away, then the right-hand side
  883. loses or gains one more than the left.
  884.  
  885. CHARIN([file] [,[position] [,count]])
  886.  
  887. Reads characters from a file. See the section on the REXX I/O model.
  888.  
  889. CHAROUT([file] [,[string] [,position]])
  890.  
  891. Writes characters to a file. See the section on the REXX I/O model.
  892.  
  893. CHARS([file])
  894.  
  895. Finds the number of characters available for reading. See the section on
  896. the REXX I/O model.
  897.  
  898. CLOSE(file)
  899.  
  900. Closes a file. See the section on the REXX I/O model.
  901.  
  902. COMPARE(s1,s2[,pad])
  903.  
  904. The strings s1 and s2 are compared, after first making them of equal
  905. length by adding pad characters (or spaces) to the right of the shorter.
  906. The result is 0 if the strings are identical, otherwise the position of
  907. the first character at which the strings disagree.
  908.  
  909. CONDITION([option])
  910.  
  911. This function returns information about the current trapped condition
  912. (see "SIGNAL ON" and "CALL ON" for more information).  If there is no
  913. such condition, then an empty string is returned.  If the option is
  914. present, it must be one of the following:
  915.  
  916.    'C': Returns the condition which was trapped (one of "SYNTAX",
  917.         "ERROR", "HALT", "NOVALUE", "FAILURE" or "NOTREADY").
  918.    'D': Returns a description of the event which caused the condition.
  919.         For "ERROR" and "FAILURE", this is the command string which
  920.         resulted in error or failure.  For "NOTREADY" it is the name of
  921.         the stream which was not ready.  For "NOVALUE" it is the
  922.         derived name of the variable which has no value.  For "HALT" it
  923.         is the Unix name of the signal which caused the interruption.
  924.         For "SYNTAX" it is the error message which would have been
  925.         displayed on the terminal if the error had not been trapped.
  926.    'I': Returns the instruction name "CALL" or "SIGNAL" as appropriate
  927.         to describe how the condition was trapped.
  928.    'S': Returns the current status of the condition as "ON", "OFF" or
  929.         "DELAY".
  930.  
  931. If the option is omitted then 'I' is assumed.
  932.  
  933. COPIES(s,count)
  934.  
  935. This function returns a string consisting of "count" copies of the
  936. string s concatenated together.
  937.  
  938. DATATYPE(string[,option])
  939.  
  940. This function tests the datatype of the string. If the function is called
  941. with just one argument, then the function returns "NUM" if the argument
  942. is a valid number, and "CHAR" otherwise.
  943.  
  944. If both arguments are supplied, then the answer is a logical value
  945. (0 or 1) indicating whether or not string is of the type given by the
  946. option.  Is s is an empty string then the answer is always 0 unless
  947. testing for a hex constant (the null string is a valid hex constant).
  948. The option must be one of the following:
  949.  
  950.    'A': s is alphanumeric (containing characters only from the ranges
  951.         "a-z", "A-Z" and "0-9")
  952.    'B': s contains bits (all characters 0 or 1)
  953.    'L': s is lower case (containing only "a-z")
  954.    'M': s is mixed case (containing only "a-z" and "A-Z")
  955.    'N': s is a valid number
  956.    'S': s is a valid REXX symbol (variable or constant)
  957.    'U': s is upper case (containing only "A-Z")
  958.    'W': s is a whole number
  959.    'X': s satisfies the rules for a hex constant (i.e. contains only
  960.         "0-9", "a-f", "A-F" and blanks in appropriate places).
  961.  
  962. DATE([option][,date[,option]])
  963.  
  964. When used with zero or one arguments, the DATE function returns the
  965. current date in a user-defined format.  When used with two or three
  966. arguments, it converts the date given in the second parameter from
  967. one format to another.
  968.  
  969. The format in which the date will be output is given by the first
  970. parameter, whose first letter must match that of one of the options
  971. listed below.  If the parameter is omitted then 'N' is assumed.
  972.  
  973. Base    - the theoretical number of days in the common era (i.e. since
  974.           1/1/1 AD).  On 1/1/1900 the result would be 693595.
  975. Century - the number of days so far since the zero year of the most
  976.           recent century (so on 1/1/1900 or 1/1/2000 the result would be
  977.           1).  This option is deprecated and was not adopted by ANSI; use
  978.           the Base option instead.
  979. Days    - the number of days so far in this year (so on 12 Jan 1986 the
  980.           result would be 12).
  981. European- the date in the format dd/mm/yy.
  982. Julian  - the date in the format yyddd (where ddd is as in "Days" above).
  983.           This option is deprecated and was not adopted by ANSI.
  984. Month   - the full name of the current month, e.g. August.
  985. Normal  - the date in the format dd Mmm yyyy, e.g. 27 Aug 1982 (with no
  986.           leading zero).
  987. Ordered - the date in the format yy/mm/dd.
  988. Standard- the date in the format yyyymmdd.
  989. USA     - the date in the format mm/dd/yy.
  990. Weekday - the full name of the current day, e.g. Tuesday.
  991.  
  992. If a date is given in the second parameter, the third parameter must
  993. state what format it is in (if the third parameter is omitted then 'N'
  994. is assumed).  The possible values for the third parameter are the same
  995. as listed above, with the exception that options 'W' and 'M' are not
  996. allowed.  If the input date has a two-digit year then the century is
  997. chosen so as to make the year no more than 49 years before or 50 years
  998. after the current year.
  999.  
  1000. On the first call to DATE or TIME in an expression, a time stamp is
  1001. made which is then used for all calls to these functions within that
  1002. expression.  Hence if multiple calls to these functions are made within
  1003. a single expression, they are guaranteed to be consistent with each
  1004. other.
  1005.  
  1006. BUG: The DATE function only works within the limits defined for Unix
  1007.      dates (usually approximately 1902-2037), and in any case the
  1008.      DATE('C') function only works between 1900 and 2099.  Using 'C' for
  1009.      the input format may occasionally result in the wrong century being
  1010.      chosen if the given date is very close to 50 years from this
  1011.      year.    
  1012. BUG: The DATE function is slightly lenient in what it accepts as a valid
  1013.      date from the second parameter.  For instance, "30 Feb 1997" would
  1014.      be accepted as if it said "2 Mar 1997".
  1015.  
  1016. DELSTR(string,position[,length])
  1017.  
  1018. A substring of string is deleted and the result returned. The substring
  1019. to be deleted starts at the given position and has length length. If
  1020. the length is not specified, then the rest of the string is deleted.
  1021. If the given position is greater than the length of the string, or if
  1022. length is zero, then the string is returned unchanged.
  1023.  
  1024. DELWORD(string,position[,count])
  1025.  
  1026. This function is a word-oriented version of DELSTR. It deletes the
  1027. substring of string which starts at the "position"th blank-delimited
  1028. word and is of "count" blank-delimited words. If there are not
  1029. "position" words in the string, or if count is 0, the string is
  1030. returned unchanged. The string deleted includes any blanks following
  1031. the final word deleted, but does not remove any blanks preceding the
  1032. first word deleted.
  1033.  
  1034. DIGITS()
  1035.  
  1036. The result is the current setting of NUMERIC DIGITS.
  1037.  
  1038. ERRORTEXT(i)
  1039.  
  1040. i must be a whole number. The result is the message that would be
  1041. displayed if error i were to occur, except that it does not include
  1042. information such as the name of an undefined label, etc.. If error i is
  1043. not defined, then an empty string is returned.
  1044.  
  1045. Standard Unix I/O errors may be retrieved with this function also.
  1046. Just add 100 to the error number.
  1047.  
  1048. See the section on error messages.
  1049.  
  1050. BUG: REXX/imc defines messages for the values 199-203.  Some systems have
  1051. more than 98 Unix I/O errors and on these systems messages 99-103 cannot
  1052. be returned by the ERRORTEXT function.
  1053.  
  1054. FDOPEN(fd [,[mode] [,file]])
  1055.  
  1056. Open a file descriptor for reading or writing. See the section on the
  1057. REXX I/O model.
  1058.  
  1059. FILENO(file)
  1060.  
  1061. Gives the fd number associated with a file. See the section on the REXX
  1062. I/O model.
  1063.  
  1064. FORM()
  1065.  
  1066. The result is either "SCIENTIFIC" or "ENGINEERING", according to the
  1067. current setting of NUMERIC FORM.
  1068.  
  1069. FORMAT(number [,[before] [,[after] [,[expp] [,expt]]]] )
  1070.  
  1071. The given number is rounded and formatted according to the information
  1072. given, as described below (note that the number is always rounded
  1073. according to NUMERIC DIGITS, if necessary, before being processed by
  1074. this function):
  1075.  
  1076. If just `number' is specified, then it is formatted according to the
  1077. usual rules for REXX numerics.
  1078.  
  1079. The number is formatted, possibly in exponential form, with `before'
  1080. digits before the decimal point and `after' digits after. `before' must
  1081. be strictly positive and includes any leading minus sign. `after' must
  1082. be non-negative. If `after' is zero, then there will be no decimal
  1083. point in the output. If either `before' or `after' is omitted, then
  1084. as many places as required are used. If `before' is too small then an
  1085. error results. If it is too large, then leading spaces are used to fill
  1086. the extra places. The number is rounded or extended with zeros as
  1087. necessary in order to have `after' digits after the decimal point
  1088. (note that this is not the same as TRUNC, which truncates the number
  1089. rather than rounding it). The rounding rules are as usual - the first
  1090. digit which is not required is checked and if it is 5 or more, the last
  1091. required digit is incremented.
  1092.  
  1093. `expt' specifies the trigger for exponential form. Exponential form is
  1094. used whenever the number would otherwise require more than `expt'
  1095. digits before or more than twice `expt' digits after the decimal point.
  1096. If `expt' is zero, exponential form is always used. The number will be
  1097. formatted according to NUMERIC FORM, and may need up to three places
  1098. before the decimal point if ENGINEERING form is in effect. The default
  1099. value for `expt' is the current setting of NUMERIC DIGITS.
  1100.  
  1101. `expp' specifies the number of digits (excluding the letter E and the
  1102. sign) used for the exponent. If it is zero, exponential form is never
  1103. used (this overrides the setting of `expt' if necessary). Otherwise, if
  1104. exponential form needs to be used, the exponent must fit in the specified
  1105. width, or an error results. Leading zeros are added as necessary to make
  1106. the exponent the correct width. A zero exponent, however, always causes
  1107. `expp+2' spaces to be added instead of the exponent (but no spaces if
  1108. expp is omitted, or is zero). If `expp' is omitted, then as many places
  1109. as required are used for the exponent.
  1110.  
  1111. Examples: (with NUMERIC FORM SCIENTIFIC and NUMERIC DIGITS 9)
  1112.  
  1113. format('3',4)             == '   3'
  1114. format('1.73',4,0)        == '   2'
  1115. format('1.73',4,3)        == '   1.730'
  1116. format('-.76',4,1)        == '  -0.8'
  1117. format('0.000')           == '0'
  1118. format('12345.73',,,2,2)  == '1.234573E+04'
  1119. format('12345.73',,3,,0)  == '1.235E+4'
  1120. format('1.2345',,3,2,0)   == '1.235    '
  1121. format('1234567e5',,3,0)  == '123456700000.000'
  1122.  
  1123. FTELL(file)
  1124.  
  1125. Gives the current pointer position of a file. See the section on the
  1126. REXX I/O model.
  1127.  
  1128. FUZZ()
  1129.  
  1130. The result is the current setting of NUMERIC FUZZ.
  1131.  
  1132. INSERT(new,target[,[n][,[length][,pad]]])
  1133.  
  1134. The new string is inserted into the target string after the nth character
  1135. or if n is omitted or is zero, the new string is inserted before the
  1136. beginning of the target string. If length is specified, then the new
  1137. string is padded or truncated to that length before inserting. The
  1138. default pad character is a blank.
  1139.  
  1140. JUSTIFY(s,length[,pad])
  1141.  
  1142. This function first removes all surplus space from s (as per SPACE(s) ),
  1143. then attempts to right-justify s in a string of "length" characters by
  1144. adding spaces between the words of s. If s does not fit in a field of
  1145. "length" characters, the first "length" characters of s are returned.
  1146. If the optional pad character is supplied, then the words in the output
  1147. string are separated by instances of that character rather than by
  1148. spaces.
  1149.  
  1150. LASTPOS(needle,haystack[,position])
  1151.  
  1152. This function finds the last occurrence, if any, of the needle within
  1153. haystack. The answer is the position of the last occurrence if there is
  1154. one (numbering from 1 to the length of haystack), or zero if needle does
  1155. not occur in haystack. If the optional position is supplied, the search
  1156. starts from this position instead of the end of haystack.  If the
  1157. needle is the empty string, zero is returned.
  1158.  
  1159. LEFT(string,length[,pad])
  1160.  
  1161. The first two mandatory parameters are a string and a length. The result
  1162. of this function is the leftmost "length" characters of string. If
  1163. string has fewer than this many characters, then it is padded up to the
  1164. required length with spaces on the right, or, if the pad character is
  1165. given, with this character.
  1166.  
  1167. Examples: left("12345",2) = "12"   left("123",5,"0") = "12300"
  1168.  
  1169. LENGTH(string)
  1170.  
  1171. The result is the number of characters in string.
  1172.  
  1173. LINEIN([file] [,[line] [,count]])
  1174.  
  1175. Inputs a line from a file. See the section on the REXX I/O model.
  1176.  
  1177. LINEOUT([file] [,[string] [,line]])
  1178.  
  1179. Outputs a line to a file. See the section on the REXX I/O model.
  1180.  
  1181. LINES([file])
  1182.  
  1183. Determines whether lines can be read from a file. See the section on the
  1184. REXX I/O model.
  1185.  
  1186. LINESIZE()
  1187.  
  1188. The function attempts to find out the terminal width using a TIOCGWINSZ
  1189. ioctl on the terminal, and returns the answer. If the ioctl returns an
  1190. error (for instance because there is no controlling terminal), then
  1191. zero is returned.
  1192.  
  1193. MAX(number[,number...])
  1194.  
  1195. This function returns the maximum of a non-empty list of numbers.
  1196.  
  1197. MIN(number[,number...])
  1198.  
  1199. This function returns the minimum of a non-empty list of numbers.
  1200.  
  1201. OPEN(path [,[mode] [,file]])
  1202.  
  1203. Opens a file for reading and/or writing. See the section on the REXX I/O
  1204. model.
  1205.  
  1206. OVERLAY(new,target[,[position][,[length][,pad]]])
  1207.  
  1208. The new string is padded or truncated to the given length and overlaid
  1209. on to the target string starting at the given position.  The default
  1210. position is 1, that is, the start of the target string.
  1211.  
  1212. PCLOSE(file)
  1213.  
  1214. Closes a file which was opened by POPEN. See the section on the REXX I/O
  1215. model.
  1216.  
  1217. POPEN(command [,[mode] [,file]])
  1218.  
  1219. Opens a pipe to a shell command. See the section on the REXX I/O model.
  1220.  
  1221. POS(needle,haystack[,position])
  1222.  
  1223. This function finds the first occurrence, if any, of needle within
  1224. haystack. The answer is the position of the occurrence if there is one
  1225. (starting from 1) or zero if needle does not occur in haystack. If the
  1226. optional position is supplied, the search starts from this position
  1227. instead of 1.  If the needle is the null string, zero is returned.
  1228.  
  1229. QUEUED()
  1230.  
  1231. This function returns the number of entries on the REXX stack.
  1232.  
  1233. RANDOM([min][,[max][,seed]])
  1234.  
  1235. A pseudo-random number is returned. If no arguments are supplied, the
  1236. number will be between 0 and 999 (inclusive). If one argument is supplied
  1237. then the result will be between 0 and that number. If both min and max
  1238. are given, then the result will be between min and max inclusive.
  1239. min must be no greater than max and the magnitude of the range (that is,
  1240. max - min) must not exceed 100000.  min, max and seed must be whole
  1241. numbers if they are specified.
  1242.  
  1243. Usually the third argument (the seed) is not supplied. In this case, on
  1244. the first call to this function the random number generator is seeded
  1245. from the system clock, and the seed is not affected on further calls, so
  1246. that a `good' sequence of random numbers is obtained.
  1247.  
  1248. The seed may be set to a specific value on each call by supplying the
  1249. third argument. To gain a predictable sequence of random numbers, the
  1250. seed is specified on the first call but not on subsequent calls.
  1251.  
  1252. REVERSE(string)
  1253.  
  1254. The function returns the reverse of string.
  1255.  
  1256. RIGHT(string,length[,pad])
  1257.  
  1258. In a similar manner to LEFT, this function returns the rightmost
  1259. "length" characters of string. If the string is too short then it is
  1260. padded on the left with spaces, or with the pad character if this is
  1261. supplied.
  1262.  
  1263. RXFUNCADD(rexxname,module,sysname)
  1264.  
  1265. This function attempts to register a function stored in a shared object
  1266. and returns zero if it was successful.  (This is simply an interface to
  1267. the API call RexxRegisterFunctionDll - see the technical reference - and
  1268. the possible return values are the same as those returned by that API
  1269. call.)
  1270.  
  1271. The "rexxname" parameter gives the name by which the function will
  1272. henceforth be known in Rexx.  The "module" parameter gives the name of
  1273. the shared object containing the function, and the "sysname" parameter
  1274. gives the name by which the function entry point is known in the shared
  1275. object.  The object will be searched for in the path given by the
  1276. environment variable REXXLIB or (if that is not set) REXXFUNC; if these
  1277. are not set then the compile-time default is used.  The module name will
  1278. be used unamended; if this is not found then ".rxfn" will be appended and
  1279. the search repeated.
  1280.  
  1281. NOTE: Since registered functions in REXX/imc are case sensitive, this
  1282. function will register the function twice: once with the given name and
  1283. once with an uppercased version of the given name (unless the given name
  1284. was already in upper case).  This allows you to say, for example:
  1285.  
  1286.    call RxFuncAdd "SysLoadFuncs","rxsysfn","SysLoadFuncs"
  1287.    call SysLoadFuncs
  1288.  
  1289. which would not otherwise work because the first line registers a
  1290. function called "SysLoadFuncs" whereas the second line looks for
  1291. "SYSLOADFUNCS".  The return value will be zero only if both operations
  1292. succeeded.
  1293.  
  1294. NOTE: Unlike the OS/2 version of this function, the REXX/imc version
  1295. attempts to load the function immediately and will return non-zero if the
  1296. function could not be found.
  1297.  
  1298. RXFUNCDROP(function)
  1299.  
  1300. This function attempts to deregister a function and returns zero
  1301. on success (otherwise the return value is 1).  A function can be
  1302. deregistered if it was loaded with RXFUNCADD, registered via the API or
  1303. auto-loaded.
  1304.  
  1305. In a similar manner to that of RXFUNCADD, this function will deregister
  1306. the name twice - once as given and once in upper case.  Zero is returned
  1307. if either operation succeeded.
  1308.  
  1309. RXFUNCQUERY(function)
  1310.  
  1311. This function returns zero if the given function is registered (that is,
  1312. it was loaded with RXFUNCADD, registered via the API or auto-loaded) and
  1313. 1 otherwise.
  1314.  
  1315. As with RXFUNCDROP, this function will return zero if the name is
  1316. registered either verbatim or in upper case.
  1317.  
  1318. SOURCELINE([i])
  1319.  
  1320. If i is omitted, then the result is the number of lines in the program.
  1321. Otherwise, i must be an integer between 1 and sourceline() and the result
  1322. is the ith program line.
  1323.  
  1324. SPACE(s[,[count][,pad]])
  1325.  
  1326. This function formats the blank-delimited words of s with "count" pad
  1327. characters between each word and with no leading or trailing blanks.
  1328. The default for "count" is 1, and the default pad character is a space.
  1329. If "count" is 0 then all blanks are removed.
  1330.  
  1331. STREAM(stream[,[option][,command]])
  1332.  
  1333. This function examines or executes a command upon a stream.  See the
  1334. section on the REXX I/O model for more information.
  1335.  
  1336. STRIP(string[,[option][,char]])
  1337.  
  1338. Up to three parameters may be supplied. The first is a string upon which
  1339. the operation is performed - this normally consists of stripping leading
  1340. and trailing spaces. The second parameter, if supplied, must start with
  1341. one of the letters "L", "T" or "B". This means strip leading spaces,
  1342. trailing spaces, or both, respectively. The third parameter, if
  1343. supplied, must be a single character, in which case this character is
  1344. stripped instead of spaces.
  1345.  
  1346. Example: strip("000123450","l","0") = "123450"
  1347.  
  1348. SUBSTR(string,position[,length[,pad]])
  1349.  
  1350. This function makes a substring of string. Usually the parameters
  1351. string, position and length are supplied and the result is the
  1352. substring of string of length "length" starting at the "position"th
  1353. character - so
  1354.    substr("abcdefg",3,2) = "cd".
  1355. If the length is omitted, then the substring continues to the end of the
  1356. string - so
  1357.    substr("abcdefg",4) = "defg".
  1358. If part of the substring requested is outside of string, then spaces are
  1359. added - or if the parameter pad is given, this character is used to pad
  1360. the result. Thus
  1361.    substr("abc",2,4,"0") = "bc00" and substr("abc",-1) = "  abc".
  1362.  
  1363. LOCAL: REXX/imc allows the position to be a negative whole number.
  1364.  
  1365. SUBWORD(string,position[,count])
  1366.  
  1367. A substring of the given string is returned, starting at the
  1368. "position"th blank-delimited word, and of length "count" words. If
  1369. "count" is not specified, then the rest of the string, starting at the
  1370. "position"th word, is returned. The result never contains leading or
  1371. trailing blanks, but it contains all spaces between the words extracted.
  1372.  
  1373. SYMBOL(name)
  1374.  
  1375. The argument is interpreted as a symbol (or a number); it is uppercased,
  1376. and if it is a compound symbol, any simple symbol components of the tail
  1377. are substituted in as with the VALUE function. The result is the three
  1378. character string "BAD", indicating that the name is not a valid symbol,
  1379. "VAR", indicating that the name is a variable (i.e. a symbol which has
  1380. been assigned a value), or "LIT", indicating that the name is either a
  1381. constant symbol or a symbol without a value.  For example, the program:
  1382.    b='*'; a.b=5
  1383.    say symbol('a') symbol('b') symbol('a.B') symbol(A.b)
  1384.    say symbol('a.*') symbol('b.a') symbol('b.*')
  1385. would say "LIT VAR VAR LIT" and "BAD LIT BAD".
  1386.  
  1387. TIME([option][,time[,option]])
  1388.  
  1389. The TIME function has three uses:
  1390.  - to return information about the current local time;
  1391.  - to operate an elapsed time counter, and
  1392.  - to convert a time from one format to another.
  1393.  
  1394. In order to return information about the current local time, a single
  1395. optional parameter is supplied whose first letter must match that of one
  1396. of the formatting options listed below.  If the parameter is omitted then
  1397. 'N' is assumed.
  1398.  
  1399. Civil   - The time in the format hh:mmxx where hh is the hour in 12-hour
  1400.           notation (no leading zero), mm is the minute, and xx is either
  1401.           am or pm.
  1402. Normal  - The time in 24-hour clock format as hh:mm:ss.
  1403. Long    - The time in 24-hour clock format as hh:mm:ss.uuuuuu where
  1404.           uuuuuu is the number of microseconds.
  1405. Hours   - the number of hours since midnight.
  1406. Minutes - the number of minutes since midnight.
  1407. Seconds - the number of seconds since midnight.
  1408. Offset  - the current difference (if known) between GMT and local time
  1409.           measured in seconds (positive if local time is ahead).
  1410.  
  1411. If two or three parameters are supplied then the second parameter is a
  1412. time which must be in one of the above formats (with the exception that
  1413. 'O' format is not allowed) and the optional third parameter must state
  1414. which format it is in.  If the third parameter is omitted then 'N' is
  1415. assumed.  If the input time is in 'M' or 'H' format then the seconds
  1416. and/or minutes values in the result will be filled in with zeros as
  1417. necessary.  This form of the TIME function makes straight conversions and
  1418. does not take account of any changes in daylight savings time.
  1419.  
  1420. The elapsed time counter is operated by calling the TIME function with
  1421. a single parameter whose first letter matches that of either of the
  1422. following.
  1423.  
  1424. Elapsed - On the first call the result is 0 and on subsequent calls
  1425.           the result is the elapsed time since then in the format
  1426.           sssss.uuuuuu (no leading zeros).
  1427. Reset   - same as Elapsed, but after the time is calculated, the timer
  1428.           is reset to zero.
  1429.  
  1430. On the first call to TIME or DATE in an expression, a time stamp is made
  1431. which is then used for all calls to these functions within that
  1432. expression. Hence if multiple calls to these functions are made within
  1433. a single expression, they are guaranteed to be consistent with each
  1434. other. Note that this means that:
  1435.  
  1436.         say time(e) sleep(2) time(e) x
  1437.         exit
  1438.   sleep:'sleep' arg(1)
  1439.         x=time(e)
  1440.         return ""
  1441.  
  1442. will type "0 0 2.062564" (perhaps) even though over two seconds elapse
  1443. during evaluation of sleep(2).  Also, the timestamp only applies to
  1444. time() calls within a single expression, so the line "x=time(e)" is not
  1445. affected by the timestamp.
  1446.  
  1447. The elapsed time counter is saved across function calls.  This means that
  1448. although a procedure inherits the elapsed time counter from its caller,
  1449. if it should reset the clock, this does not affect any timing which may
  1450. be in progress by the caller.
  1451.  
  1452. NOTE: The time is subject to the accuracy of the system clock, which may
  1453.       not give a very reliable number of microseconds.  The TIME('O')
  1454.       function relies on the operating system to return the correct
  1455.       offset and this may be unknown or inaccurate.  The TZ environment
  1456.       variable may have an effect on determining the current timezone.
  1457.  
  1458. TRACE([setting])
  1459.  
  1460. The result is the current trace setting, consisting of one upper case
  1461. letter, possibly preceded by a single question mark. If the setting
  1462. is supplied as a parameter, then this is used as a trace setting for
  1463. all further execution. See the TRACE command for details.
  1464.  
  1465. TRANSLATE(string[,[tableo][,[tablei][,pad]]])
  1466.  
  1467. This function translates characters in string to other characters, or
  1468. may be used to change the order of characters in a string.
  1469. If neither translate table is specified, then the string is translated
  1470. into uppercase. Otherwise each character of string which is found in
  1471. tablei is translated into the corresponding character in tableo -
  1472. characters which are not found in tablei remain unchanged. The default
  1473. input table is XRANGE('00'x,'ff'x) and the default output table is the
  1474. null string. The output table is padded or truncated in order to make
  1475. it the same length as the input table, the default pad character being
  1476. a blank.
  1477. Examples:
  1478.    translate('abc123DEF')              == 'ABC123DEF'
  1479.    translate('abbc','&','b')           == 'a&&c'
  1480.    translate('abcdef','12','ec')       == 'ab2d1f'
  1481.    translate('abcdef','12','abcd','.') == '12..ef'
  1482.    translate('4123','abcd','1234')     == 'dabc'
  1483.  
  1484. TRUNC(number[,length])
  1485.  
  1486. The number is rounded as necessary according to NUMERIC DIGITS, and then
  1487. truncated or padded so that the result has exactly "length" digits
  1488. after the decimal point. If the length is zero or is omitted, then the
  1489. result is an integer with no decimal point. The result will never be in
  1490. exponential form.
  1491.  
  1492. Examples:
  1493.    trunc(12.6)      == 12
  1494.    trunc(345e-2,1)  == 3.4
  1495.    trunc(26,5)      == 26.00000
  1496.  
  1497. VALUE(s[,[newvalue][,selector]])
  1498.  
  1499. s is treated as a symbol, and if it has a value, that value is returned.
  1500. If s is not a valid symbol then an error results. Otherwise the result
  1501. is just as for a symbol appearing in a program. For compound symbols,
  1502. substitution occurs as normal, except that string constants and
  1503. expressions (types 4 and 5 in the description of symbols above) are not
  1504. allowed.
  1505.  
  1506. If the newvalue parameter is provided, then this value is assigned to
  1507. the symbol described above.  The symbol's old value will be returned.
  1508. In this case the symbol must not be a constant symbol or an error will
  1509. result.
  1510.  
  1511. If the selector is provided, then this indicates an alternative
  1512. variable pool to use instead of the REXX variable pool (except that the
  1513. word "REXX" is accepted as a valid name for the usual REXX variable
  1514. pool).  The only selector recognised by REXX/imc is the word
  1515. "ENVIRONMENT", which allows the value() function to examine and alter
  1516. environment variables.  Note that the names and values of environment
  1517. variables may not contain NUL characters.
  1518.  
  1519. Example: the following program
  1520.  
  1521.    a=1; b='*'
  1522.    c.a=1; c.b=2
  1523.    say value("a") value("c.a") value("c.b") value("d.b",6)
  1524.    say value("d.*")
  1525.    
  1526. will output "1 1 2 D.*" then give an error, because "*" is not allowed
  1527. as a component of a symbol (however "b" is, even if b="*").  The value
  1528. of d.b after executing these lines will be 6.
  1529.  
  1530. The instructions
  1531.  
  1532.    a=value("FOO","ENVIRONMENT")
  1533.    call value "FOO","bar","ENVIRONMENT"
  1534.  
  1535. are similar to the instructions
  1536.  
  1537.    a=getenv("FOO")
  1538.    call putenv "FOO=bar"
  1539.  
  1540. respectively.
  1541.  
  1542. VERIFY(string,reference[,[option][,position]])
  1543.  
  1544. This verifies that the string contains only characters from reference
  1545. and returns 0 if this is true. Otherwise the result is the position of
  1546. the first character in string which is not in reference.
  1547.    If the option is specified, its first letter must be either 'N'
  1548. (nomatch) or 'M' (match).  The action for 'N' is as described above.
  1549. If 'M' is specified then the result is the position of the first
  1550. character which matches a character from the reference, and 0 if no
  1551. character from reference was found in the string.
  1552.    If the position is given, the verification starts from this position
  1553. in the string instead of from the beginning.
  1554.  
  1555. Examples:
  1556.    verify('123','1234567890')           = 0
  1557.    verify('1Z3','1234567890')           = 2
  1558.    verify('AB4T','1234567890','M')      = 3
  1559.    verify('1P3Q4','1234567890',,3)      = 4
  1560.  
  1561. WORD(string,position)
  1562.  
  1563. This function returns the "position"th blank-delimited word in string,
  1564. and is identical to SUBWORD(string,position,1). If there are not
  1565. "position" words in string then the empty string is returned.
  1566.  
  1567. WORDINDEX(string,position)
  1568.  
  1569. This function returns the character position of the "position"th
  1570. blank-delimited word in string, or 0 if there are not that many words
  1571. in string.
  1572.  
  1573. WORDLENGTH(string,position)
  1574.  
  1575. This function returns the length of the "position"th blank-delimited
  1576. word in string, and is identical to LENGTH(WORD(string,position)). If
  1577. there are not that many words in string then 0 is returned.
  1578.  
  1579. WORDPOS(phrase,string[,position])
  1580.  
  1581. This is a word-oriented version of POS. It returns the word number of
  1582. the first occurrence of the phrase in the string. If "position" is
  1583. specified, the the search starts at the specified word number instead
  1584. of the beginning.  If phrase contains no words, then 0 is returned.
  1585.    phrase is a sequence of blank-delimited words which must be present
  1586. in sequence in the string and match exactly, except that multiple
  1587. blanks between words are treated as single blanks, and leading and
  1588. trailing blanks are ignored.
  1589.    This function replaces the FIND function from VMREXX.
  1590.  
  1591. WORDS(string)
  1592.  
  1593. This function returns the number of blank-delimited words in the string.
  1594.  
  1595. XRANGE([a[,b]])
  1596.  
  1597. This function returns a range of ascii characters in a string. If they
  1598. are supplied, a and b must be single characters. The defualt values for
  1599. a and b are '00'x and 'ff'x respectively. The result is a string
  1600. consisting of ascii characters in sequence starting with a and ending
  1601. with b. If a>b then a string of (b-a+257) characters is returned,
  1602. starting at a and ending at b, wrapping around from 'ff'x to '00'x.
  1603.  
  1604. UNIX Specific Functions:
  1605.  
  1606. The following functions are built into this version of REXX, although
  1607. they are not standard REXX functions. Most of these functions appear in
  1608. the literature.
  1609.  
  1610. NOTE: many of these functions which accept string arguments will ignore
  1611.       any characters after (and including) a "00"x character.
  1612.  
  1613. CHDIR(directory)
  1614.  
  1615. This function attempts to change to the named directory, and returns an
  1616. error code. The code is zero if no error occurred, otherwise the message
  1617. corresponding to the code can be obtained with the ERRORTEXT function
  1618. by first adding 100 to the number.
  1619.  
  1620. GETCWD()
  1621.  
  1622. The current working directory name is returned. If an error occurs while
  1623. attempting to name the current directory then an error message is
  1624. returned instead. The first character of the result is a `/' if and only
  1625. if no error occurred.
  1626.  
  1627. GETENV(name)
  1628.  
  1629. If the current environment contains the named variable, then its value is
  1630. returned. Otherwise an empty string is returned.
  1631.  
  1632. This call is equivalent to VALUE(name,,"ENVIRONMENT"), and it may be
  1633. deleted in a future release.
  1634.  
  1635. PUTENV(string)
  1636.  
  1637. The string must be of the form "variable=value". The specified
  1638. environment variable is set to the given value and zero is returned.
  1639. If an error occurs then 1 is returned.
  1640.  
  1641. This call is similar to VALUE(variable,value,"ENVIRONMENT"), and it may
  1642. be deleted in a future release.
  1643.  
  1644. SYSTEM(s)
  1645.  
  1646. This function takes the string s, passes it to a bourne shell, and
  1647. returns as a result all text produced by that shell command on the
  1648. standard output. This function has a side effect, namely that the
  1649. variable `rc' is set to the exit status of the shell, or -1 if the shell
  1650. couldn't be invoked for some reason.  This may in turn cause the
  1651. condition "ERROR" or "FAILURE" to be trapped (see the SIGNAL ON and
  1652. CALL ON instructions).  Except in the case that a "SIGNAL" occurs,
  1653. there will always be a result whatever the return code, but it may be
  1654. the null string if an error occurred (or if the command produced no
  1655. output).
  1656.  
  1657. USERID()
  1658.  
  1659. The result is the login-name corresponding to the owner of the
  1660. interpreter process. If that cannot be determined for some reason, an
  1661. empty string is returned.
  1662.  
  1663. Mathematical Functions
  1664.  
  1665. The following functions are supplied as an external function package
  1666. called rxmathfn.  Either a REXX program or a dynamically-loadable
  1667. object may be used (see the section on function invocation).
  1668.  
  1669. All the functions described below give results according to the current
  1670. setting of NUMERIC DIGITS, but they use floating-point maths so a maximum
  1671. of about 16 digits of accuracy may be obtained.  The exception is the
  1672. square root function, which can always give the required number of
  1673. digits of accuracy (subject to machine resources).
  1674.  
  1675. ACOS(x)      the arc-cosine of x in radians (0<=acos(x)<=pi)
  1676. ASIN(x)      the arc-sine of x in radians (-pi/2<=asin(x)<=pi/2)
  1677. ATAN(x)      the arc-tangent of x in radians (-pi/2<=atan(x)<=pi/2)
  1678. COS(x)       the cosine of x radians
  1679. EXP(x)       the exponential of x (2.718281... to the power x)
  1680. LN(x)        the natural logarithm of x (x>0)
  1681. SIN(x)       the sine of x radians
  1682. SQRT(x)      the square root of x (x>=0) [arbitrary precision possible]
  1683. TAN(x)       the tangent of x radians (x <> pi/2)
  1684. TOPOWER(x,y) x to the power y (like x**y except non-integer values
  1685.              of y are allowed).  If y=0 then the result is 1.  If x=0
  1686.              and y>0 then the result is 0.  Otherwise the result is
  1687.              exp(y*ln(x)).
  1688. _________________________________________________________________________
  1689.  
  1690. Instructions
  1691.  
  1692. Comments are supported, and may appear anywhere that a space can, with
  1693. the exception that comments are not allowed within a multi-character
  1694. operator (e.g. ** or ==).  They can occupy any number of lines and may
  1695. be nested. 
  1696. /* This is a comment.  It is started by /* and ended by */.  */
  1697.  
  1698. The star and slash characters of the comment delimiters must not be
  1699. separated by whitespace.
  1700.  
  1701. Each command must usually appear all on one line. The exception to this
  1702. rule is when a line ends with a comma. In this instance, the comma is
  1703. deleted and the next line appended with a space. Multiple lines may be
  1704. appended in this way. Thus
  1705.    say,          /* spaces and/or comments may follow the comma */
  1706.    "this is",
  1707.    "a test"
  1708. will actually be interpreted as
  1709.    say "this is" "a test"
  1710. and will result in
  1711.    this is a test
  1712.  
  1713. Note that quotation marks must always be closed before the end of a line.
  1714. For example, the following will cause an error:
  1715.    say "this is,
  1716.    a test"
  1717.  
  1718. Instructions may be separated by semicolons or by the ends of lines.
  1719.  
  1720. The following REXX commands are currently implemented. They are displayed
  1721. in upper case, but may be typed in mixed case.
  1722.  
  1723. Square brackets indicate optional parts of constructions.
  1724. _________________________________________________________________________
  1725.  
  1726. NOP
  1727.  
  1728. This does nothing. It is provided for situations such as
  1729. IF xxxx THEN NOP ELSE yyyy.
  1730. _________________________________________________________________________
  1731.  
  1732. SAY [expression]
  1733.  
  1734. The expression is evaluated and displayed on the standard output,
  1735. followed by a newline character. If no expression is supplied then just
  1736. the newline character is output.
  1737.  
  1738. LOCAL: The command:  SAYN expression
  1739.        evaluates the expression and displays it without a newline
  1740.        character.  Note that a similar effect can be obtained with
  1741.        the function call charout, though the output may have to be
  1742.        flushed by calling charout a second time with no parameters.
  1743. _________________________________________________________________________
  1744.  
  1745. symbol=value
  1746.  
  1747. If `symbol' is a simple or compound symbol then it is assigned the value
  1748. `value', so that assignment in REXX has the usual meaning. A compound
  1749. symbol is subject to the usual substitution of qualifiers.
  1750.  
  1751. If `symbol' is a stem, then all possible compound symbols which start
  1752. with the given stem are assigned the value `value'.
  1753.  
  1754. Variables are allowed to have the same names as REXX keywords, with the
  1755. exception of some keywords within particular commands (e.g. "until" in a
  1756. DO construction). The following rule is applied, in order to distinguish
  1757. between an assignment and any other command: if the first word in the
  1758. line is followed by an `=' (after optional spaces), then it is an
  1759. assignment. This does not apply, however, to constant symbols, which can
  1760. not be assigned to.
  1761. _________________________________________________________________________
  1762.  
  1763. DROP symbol [symbol,...]
  1764.  
  1765. The DROP command un-assigns each symbol named after the DROP keyword.
  1766. Simple or compound symbols or stems may be dropped. If the symbol is a
  1767. stem, then all compound symbols starting with that stem are dropped.
  1768.  
  1769. If a variable has been passed to a procedure with the PROCEDURE EXPOSE
  1770. construction, then the variable in the calling procedure will be dropped
  1771. also. If a dropped symbol is subsequently assigned a value, then the
  1772. variable will also be assigned that value in the calling procedure.
  1773.  
  1774. It is not an error to DROP a non-existent symbol, or to DROP a symbol
  1775. twice.
  1776.  
  1777. NOTE: Even if a compound variable is dropped, its value will always be
  1778.       undefined immediately after the drop.  For example,
  1779.          stem.="Some value"
  1780.          drop stem.6
  1781.          say stem.5 stem.6 stem.7
  1782.       makes stem.6 undefined and says "Some value STEM.6 Some value".
  1783. _________________________________________________________________________
  1784.  
  1785. EXIT [expression]
  1786.  
  1787. The EXIT instruction returns control from a program to its most recent
  1788. external caller. This will either be a rexx external call (that is,
  1789. `CALL name' or `name()' where name is the name of the REXX program rather
  1790. than an internal or builtin function name) or a UNIX command, if the
  1791. program was not called by another REXX program. All the current DO,
  1792. SELECT, INTERPRET and internal call structures are terminated, and
  1793. control resumes at the point of the most recent external call. An
  1794. expression may follow the EXIT statement; this is passed back to the
  1795. caller in the same way as in the RETURN statement. If control is returned
  1796. back to UNIX, then the expression must be an integer if it is supplied,
  1797. and it is used as the exit value of the interpreter. If no value is
  1798. supplied then the exit code will be zero.
  1799.  
  1800. Note that reching the end of a program is the same as executing "EXIT".
  1801. In other words, reaching the end of a program terminates all internal
  1802. function calls.
  1803. _________________________________________________________________________
  1804.  
  1805. NUMERIC parameter value
  1806.  
  1807. NUMERIC DIGITS n
  1808. NUMERIC FUZZ n
  1809. NUMERIC FORM   SCIENTIFIC
  1810.              | ENGINEERING
  1811.              | "string constant"
  1812.              | [VALUE] expression
  1813.  
  1814. The expression evaluator uses arbitrary length arithmetic for numeric
  1815. operations. The precision to which operations are carried out by the
  1816. evaluator may be altered using the NUMERIC DIGITS command, and is
  1817. initially 9. The number supplied will be the number of digits kept after
  1818. each operation, not including the decimal point, or leading zeros, which
  1819. are dropped by all arithmetic operations. The upper limit for NUMERIC
  1820. DIGITS is about 10000 (defined in const.h).  Note that a single
  1821. multiplication or division can take many minutes at this precision.
  1822.  
  1823. NUMERIC FUZZ is initially zero and is set to zero by each NUMERIC DIGITS
  1824. command. It specifies a temporary reduction in the precision of
  1825. arithmetic when doing comparisons (remember, for all numeric comparisons,
  1826. the two operands are subtracted and the result is compared with zero. It
  1827. is the precision of the subtraction which is affected by NUMERIC FUZZ).
  1828. The upper limit for NUMERIC FUZZ is clearly one less than the current
  1829. value of NUMERIC DIGITS.
  1830.  
  1831. NUMERIC FORM is used to set the form of exponents to either `scientific'
  1832. mode or `engineering' mode. When an exponent is used, in the scientific
  1833. mode there is always precisely one digit, which is non-zero, before the
  1834. decimal point. In engineering mode, there are up to three digits before
  1835. the decimal point, and the exponent is always a multiple of three.
  1836.    If an expression is used, it must evaluate to "SCIENTIFIC" or
  1837. "ENGINEERING" in upper case. If the expression does not start with a
  1838. symbol or string constant, then the keyword VALUE may be omitted.
  1839.  
  1840. The NUMERIC settings are saved across function calls, and restored on
  1841. return from a function, so a function may set the precision, etc. that
  1842. it needs without affecting the caller.  Moreover, the settings will be
  1843. restored to their default settings just after entering any external
  1844. REXX procedure.
  1845. _________________________________________________________________________
  1846.  
  1847. DO
  1848.  
  1849. There are two uses of DO:
  1850.  
  1851. 1.  DO
  1852.     ...commands...
  1853.     END
  1854.  
  1855.   This is a compound statement, i.e. the DO and END are wrapped around
  1856.   the block of commands so that they appear like one statement and may
  1857.   be used in IF constructs.
  1858.  
  1859. 2.  DO [ symbol=start  [TO  finish]  ]     [WHILE expression_w]
  1860.        [               [BY  step  ]  ]
  1861.        [               [FOR count ]  ]     [UNTIL expression_u]
  1862.  
  1863.        [ expression_c                ]
  1864.        [FOREVER                      ]
  1865.  
  1866.     ...commands...
  1867.     
  1868.     END [symbol]
  1869.  
  1870.     where start, finish, step, count and the expressions are numerical
  1871.     expressions. Expression_c and count are required to be non-negative
  1872.     integers.
  1873.  
  1874.   This is a repetitive command. If `symbol' is present in the DO
  1875.   statement, then:
  1876.  
  1877.     a. `symbol' may be any simple or compound symbol
  1878.     b. the symbol name may appear after the END statement; if it does,
  1879.        then it must be the same one as after the DO.  The DO symbol and
  1880.        the END symbol are compared literally, without substituting any
  1881.        components in the tail of a compound symbol, but the comparison
  1882.        is case insensitive.
  1883.     c. the value of start is assigned to the symbol before the loop is
  1884.        entered.
  1885.     d. if [TO finish] is present, then the loop is not executed after the
  1886.        control variable (named by the symbol) passes the finish value.
  1887.        If it is not present, then the loop may potentially be executed
  1888.        for ever (unless a FOR clause is present).
  1889.     e. if [BY step] is present, then the variable is incremented by step
  1890.        after each pass. Otherwise the variable is incremented by 1.
  1891.     f. If [FOR count] is present, then the loop is executed at most
  1892.        count times.
  1893.     g. The TO, FOR and BY clauses may be specified in any order. (Note:
  1894.        each should be specified at most once, but specifying one or more
  1895.        of these twice will not cause an error. The last one encountered
  1896.        is the one which is used).
  1897.   If `symbol' is not present, then nothing must follow the END.
  1898.  
  1899.   If the expression_c is specified, then the loop is executed this number
  1900.   of times (unless terminated by some other condition).  Note that
  1901.   expression_c must not start with a symbol followed by '=', because it
  1902.   would then be taken to be a `symbol' as above.  This may be prevented
  1903.   by enclosing the expression in parentheses.
  1904.  
  1905.   If a WHILE clause is present, then expression_w is evaluated before
  1906.   each pass and the loop is terminated if the result is false.
  1907.   
  1908.   If an UNTIL clause is present, then expression_u is evaluated after
  1909.   each pass and the loop is terminated if the result is true.
  1910.   
  1911.   A `DO FOREVER' instruction creates a loop which never terminates
  1912.   (unless a LEAVE instruction is encountered).
  1913.   
  1914.   Note that if expression_w is false or if the variable clause needs no
  1915.   repetition, or if count or expression_c is zero, then the body of the
  1916.   loop will not be executed at all.
  1917.  
  1918. An END must appear for each DO construct, and if labelled with a symbol,
  1919. must have the correct symbol.
  1920.  
  1921. NOTE: The name of any variable specified at the DO statement is
  1922.       evaluated again each time it is incremented at the end of a
  1923.       pass through the loop.  This means, for example, that in
  1924.       "DO a.i=1 TO 10", the name of the variable which is incremented
  1925.       depends on the current value of i.  (Altering the value of i is,
  1926.       of course, not highly recommended).
  1927.  
  1928. Example: The code
  1929.  
  1930.         do name=expri to exprt by exprb for exprf while exprw (or until expru)
  1931.            ... instructions ...
  1932.         end
  1933.  
  1934. will be executed as if it were written thus:
  1935.  
  1936.         $tempi = expri       /* variables staring with $ are */
  1937.         $tempt = exprt       /* invisible to the rest of the */
  1938.         $tempb = exprb       /* program. */
  1939.         $tempf = exprf
  1940.         name = $tempi + 0
  1941.  
  1942.  $loop: if name > $tempt then goto $end    /* "goto" is a pseudo-op */
  1943.         if $tempf = 0 then goto $end       /* meaning the obvious   */
  1944.         if \exprw then goto $end
  1945.  
  1946.         ... instructions ...
  1947.  
  1948.  $iter: if expru then goto $end            /* "iterate" will come here */
  1949.         name = name + $tempb
  1950.         $tempf = $tempf - 1
  1951.         goto $loop
  1952.  $end:                                     /* "leave" will come here */
  1953.  
  1954. (If any of the constructs in the original code are left out, the
  1955. coresponding lines will be left out of this example).
  1956. _________________________________________________________________________
  1957.  
  1958. LEAVE [symbol]
  1959.  
  1960. If a symbol name is not specified, then LEAVE leaves the innermost
  1961. repetitive DO statement by jumping to the statement after the END
  1962. statement for that loop. If a symbol name is specified, then LEAVE
  1963. leaves the innermost loop with that symbol as control (i.e. where the
  1964. DO statement specified that symbol) - this may involve leaving several
  1965. inner loops.  The specified symbol must match that in the DO
  1966. instruction literally, except that case is ignored.
  1967.   The LEAVE statement will not return from procedures or functions.
  1968.   If there is no suitable loop to leave within the current function or
  1969. procedure call, then an error results.
  1970.  
  1971. NOTE: LEAVE will not exit from a string being interpreted: it is an
  1972.       error to use LEAVE within INTERPRET unless the corresponding DO
  1973.       occurs there as well.
  1974. _________________________________________________________________________
  1975.  
  1976. ITERATE [symbol]
  1977.  
  1978. This instruction is similar to LEAVE, but instead of leaving the loop
  1979. it jumps to execute the END statement and possibly continue with another
  1980. iteration around the loop.  The same NOTE applies.
  1981. _________________________________________________________________________
  1982.  
  1983. IF expression [;] THEN [;] instruction [ ; ELSE [;] instruction]
  1984.  
  1985. This construction has the obvious meaning. Note that the THEN and ELSE
  1986. must be followed by single instructions, but the DO-END or SELECT-END
  1987. (qv) and even IF-THEN-ELSE constructions count as single instructions
  1988. for this purpose.
  1989.  
  1990. A semicolon or line-end may optionally appear between the expression and
  1991. the THEN, but one must appear before ELSE, as above.
  1992.  
  1993. IF statements may be nested, but note that each ELSE statement
  1994. corresponds to the most recent IF statement without an ELSE. If a null
  1995. THEN or ELSE clause is needed, the NOP instruction must be used (as a
  1996. null statement is just ignored by REXX).
  1997.  
  1998. BUG: There is at present no way to detect incorrectly positioned ELSE
  1999.      statements. If an ELSE is detected during program interpretation,
  2000.      this will just cause the interpreter to skip the following statement
  2001.      and will not be an error. This bug also prevents the interpreter
  2002.      from flagging a construction such as "if expr then else ..." since
  2003.      in that case the "else" will be considered to be the statement to
  2004.      execute when expr is true.
  2005. _________________________________________________________________________
  2006.  
  2007. SELECT [expression]
  2008.    WHEN expression THEN instruction
  2009.    WHEN expression THEN instruction
  2010.    ...
  2011.    [OTHERWISE instructions]
  2012. END [SELECT]
  2013.  
  2014. If an expression is supplied after SELECT, then this construction is like
  2015. a Pascal or Modula `CASE' construction. The expression is compared with
  2016. each of the other expressions in turn, until one is found that matches
  2017. (using the `=' form of equality). If a match is found, then the
  2018. corresponding instruction is executed. If a match is not found, then an
  2019. OTHERWISE clause must be specified, or else an error is reported. The
  2020. instructions after OTHERWISE will be executed.
  2021.   If an expression is not specified after SELECT, then the construction
  2022. is a list of guarded commands - that is, each expression is evaluated
  2023. until a true one is found, and the corresponding action is taken. Again,
  2024. if no expression is true and there is no OTHERWISE then an error is
  2025. reported.
  2026.   The word SELECT may be placed after the closing END but is optional.
  2027. Adding the word SELECT allows easier detection of missing ENDs.
  2028.   It is an error for the word WHEN or OTHERWISE to appear anywhere except
  2029. immediately inside a SELECT construction.
  2030.   Precisely one instruction is required after each WHEN, so NOP should be
  2031. used if no action is required. NOP need not be used after OTHERWISE.
  2032.   If multiple instructions are required to follow each WHEN condition,
  2033. then they should be contained in a DO ... END block.  Multiple
  2034. instructions may follow the OTHERWISE keyword.
  2035.  
  2036. LOCAL: The optional expression following the SELECT keyword, and the
  2037.        optional SELECT following the END keyword are features of PL/1
  2038.        and not of standard REXX.
  2039. _________________________________________________________________________
  2040.  
  2041. PARSE [UPPER] string [template] (also: ARG [template], PULL [template])
  2042.  
  2043. [PARSE [UPPER]] ARG template
  2044. [PARSE [UPPER]] PULL [template]
  2045. PARSE [UPPER] LINEIN [template]
  2046. PARSE [UPPER] SOURCE template
  2047. PARSE [UPPER] VERSION template
  2048. PARSE [UPPER] NUMERIC template
  2049. PARSE [UPPER] VAR symbol template
  2050. PARSE [UPPER] VALUE expression WITH template
  2051.  
  2052. This command is a powerful parser which divides the operand up as
  2053. specified by the `template'. If the UPPER keyword is specified, then the
  2054. operand is uppercased before parsing.
  2055.  
  2056. The "ARG template" and "PULL template" commands are short forms of
  2057. "PARSE UPPER ARG template" and "PARSE UPPER PULL template" respectively.
  2058.  
  2059. The possible operands are as follows:
  2060.  
  2061. ARG   - the command-line arguments, or the arguments passed by a function
  2062.         or procedure call, are parsed.
  2063. PULL  - the top value on the stack, if one exists, is parsed; otherwise
  2064.         a line of input is read from the standard input and parsed as
  2065.         described for LINEIN below.  See QUEUE/PUSH for details about
  2066.         the stack.
  2067. LINEIN- A line is read directly from stdin.  The stack is not affected
  2068.         by this instruction.  In general, PULL is recommended in
  2069.         preference to LINEIN.
  2070.  
  2071.         If a line cannot be read because of an I/O error or EOF
  2072.         condition, then the NOTREADY condition will be raised and an
  2073.         empty string will be parsed.  The NOTREADY condition is ignored
  2074.         unless trapped by SIGNAL ON or CALL ON, in which case it is
  2075.         difficult to tell the difference between an empty input line
  2076.         and an I/O error.  However, the STREAM() function may be
  2077.         used to examine the most recent I/O error on stream "stdin".
  2078.  
  2079.         NOTE: If the program is interrupted (via ^C) while input is being
  2080.               read, then the characters which have been read in may be
  2081.               lost, but the remainder of a partially-input line will
  2082.               remain to be read again.
  2083.  
  2084. SOURCE- An implementation-dependent string representing the `source' of
  2085.         the program is parsed.
  2086.         In this implementation, the string contains five words:
  2087.          1. the system under which the interpreter runs (always UNIX)
  2088.          2. the way in which the program was called (one of COMMAND,
  2089.             FUNCTION or SUBROUTINE, depending whether the program was
  2090.             invoked by a command shell or as a function or subroutine)
  2091.          3. the name of the file containing the program, with the full
  2092.             path name (unless no directory was specified and getwd could
  2093.             not name the current directory)
  2094.          4. the name by which the program was called (always without a
  2095.             path name).
  2096.          5. the environment name which was current when the program
  2097.             started up
  2098. VERSION-A string representing the version of the REXX interpreter is
  2099.         parsed. This contains five words:
  2100.          1. A word describing the language, of which the first four
  2101.             letters are always REXX. In this implementation the word is
  2102.             REXX/imc.
  2103.          2. A string representing the version number (e.g. 1.0)
  2104.          3,4,5. The date on which the interpreter was compiled, in the
  2105.             same format as the DATE() function (e.g. 18 May 1990).
  2106. NUMERIC-The current NUMERIC settings are parsed.  There are three words
  2107.         in the string to be parsed: NUMERIC DIGITS, NUMERIC FUZZ and
  2108.         NUMERIC FORM respectively.
  2109. VAR   - The symbol specified is evaluated, and if it represents
  2110.         a currently defined variable, its value is substituted. The
  2111.         result is then parsed.
  2112. VALUE - The expression between "VALUE" and "WITH" is evaluated and then
  2113.         parsed (note that WITH is a reserved keyword in this instruction)
  2114.  
  2115. If no template is supplied, the information to be parsed is collected and
  2116. then thrown away.
  2117.  
  2118. The "ARG" and "VALUE" forms may parse more than one string at once. This
  2119. comes about with "ARG" when a function or procedure call (note - not a
  2120. command line call) passes more than one argument, or with "VALUE" when
  2121. the expression contains comma separators. In this case, the parse
  2122. template may contain commas. The part of the template before the first
  2123. comma applies to the first operand string, that part between the first
  2124. and second commas applies to the second string, and so on. E.g.
  2125.  
  2126.  PARSE VALUE 43 56,5*9,hello,there WITH template1,template2,
  2127.  
  2128. Here template1 applies to "43 56"; template2 applies to "5*9" and no
  2129. other parsing takes place. Note that there does not have to be a template
  2130. for each operand string, and also that there does not have to be an
  2131. operand string for each template (in this case the extra templates will
  2132. be applied to the empty string).
  2133.  
  2134. LOCAL: Parsing multiple strings with the PARSE VALUE construction is a
  2135.        local extension.
  2136.  
  2137. A parse template obeys the following grammar. A symbol in brackets
  2138. indicates that that symbol may be optionally present. A character in
  2139. single quotes indicates that that character should be typed literally.
  2140. A symbol in double quotes is a terminal symbol, indicating the
  2141. appropriate REXX entity should be present.
  2142.  
  2143.  template        -> [firstPosition] assignments [assignments]
  2144.  assignments     -> [nextPosition] varlist [stopPosition]
  2145.  varlist         -> varname [varlist]
  2146.  varname         ->   "non-constant symbol"
  2147.                     | '.'
  2148.  firstPosition   -> position
  2149.  nextPosition    -> position [nextPosition]
  2150.  stopPosition    -> position
  2151.  position        ->   searchPosition
  2152.                     | absPosition
  2153.                     | relPosition
  2154.                     | '(' "expression" ')'
  2155.  searchPosition  -> "string constant"
  2156.  absPosition     ->   "integer"
  2157.                     | '=' numexpr
  2158.  relPosition     ->   '+' numexpr
  2159.                     | '-' numexpr
  2160.  numexpr         ->   "integer"
  2161.                     | '(' "integer expression" ')'
  2162.  
  2163. Each position symbol in this grammar indicates a column number to the
  2164. parser. Positions are translated to column numbers (numbered from 1 up to
  2165. l+1, where l is the length of the string being parsed) in the following
  2166. way. Note that the absPosition indicator "1" is implicitly present
  2167. before and after any parse template.
  2168.  
  2169. absPosition:    gives the column number directly, except that numbers not
  2170.                 between 1 and l+1 are translated into 1 or l+1 as
  2171.                 appropriate.
  2172. searchPosition: searches for the given string constant in the string
  2173.                 being parsed, starting from the most recent column number
  2174.                 Usually, two column numbers result: the column number of
  2175.                 the first character which matched, and that of the first
  2176.                 character after the matching string. The latter number is
  2177.                 suppressed if the next position indicator (if any) is a
  2178.                 `relPosition'. If the string is not found, then the
  2179.                 single column number l+1 results.
  2180. "expression":   evaluates the expression and then treats it as the string
  2181.                 constant of a searchPosition
  2182. relPosition:    The given positive or negative number is added to the
  2183.                 previous column number to give the result. As for an
  2184.                 absolute position, numbers which are out of range are
  2185.                 translated into 1 or l+1 as appropriate.
  2186.  
  2187. For example, given the string "hello, world, hello!" and the position
  2188. indicators 1 "ello" +4 ! 5 -3 'x' -2 1, the resulting column numbers
  2189. would be:
  2190.   1  (the given number)
  2191.   2  (the first character of "ello" - the second number is suppressed)
  2192.   6  (+4 characters from the previous position)
  2193.  20}{(the first character of "!")
  2194.  21}{(the first character after "!")
  2195.   5  (the given number)
  2196.   2  (-3 characters from 5)
  2197.  21  (the end of the string, since "x" is not found)
  2198.  19  (-2 characters from 21)
  2199.   1  (the given number)
  2200.  
  2201. The position indicators are translated into column numbers independent
  2202. of the varlist, except in one case described below. Thus the parse
  2203. template may be reduced by the above rules into a sequence of column
  2204. numbers and varlists. Taking into account the rule that each template is
  2205. implicitly prefixed and suffixed by the column number "1", each varlist
  2206. thus occurs between two column numbers. Each varlist is treated
  2207. separately, as follows:
  2208.  
  2209. Denote the varlist, together with the column numbers immediately before
  2210. and after the varlist, as m v1 v2 ... vk n. If m<n, or if m=n and
  2211. n resulted from a search, then there exists a well-defined substring s of
  2212. the string being parsed, which starts at column m and is of length n-m.
  2213. (this string ends at, but does not include, column n). Otherwise, let s
  2214. be that substring which starts at column m and continues to the end of
  2215. the string being parsed. Then the string s is divided between the
  2216. variables of the varlist by assigning the blank-delimited tokens to v1,
  2217. v2, ... in order. If there are more varnames in the varlist than there
  2218. are blank-delimited tokens, then the extra varnames are assigned with the
  2219. empty string. The tokens assigned to varnames v1, v2, ... , v(k-1) will
  2220. contain no leading or trailing blanks, but the token assigned to vk will
  2221. contain all blanks which occur after v(k-1), except for the one blank
  2222. immediately after v(k-1).
  2223.  
  2224. Each varname is either a symbol name or a dot. If the varname is a dot,
  2225. then the token which would be assigned to it is thrown away. Otherwise
  2226. the token is assigned to it in the usual way, just as if there had been
  2227. an instruction: symbol = token
  2228.  
  2229. NOTE: Most versions of REXX allow only a symbol name between parentheses
  2230.       where this version allows an arbitrary expression.
  2231.  
  2232. The one case in which the presence of a varlist may affect the
  2233. translation from position indicators to column numbers is when one or
  2234. more of the symbols mentioned in an "expression" is also stated in a
  2235. varlist. Hence:
  2236.  
  2237. PARSE VALUE "s/this/that" WITH 2 delim +1 first (delim) second
  2238.  
  2239. will assign "/" to delim, "this" to first and "that" to second. This is
  2240. because the variable delim is assigned as soon as the "+1" is reached.
  2241. This provides a way to provide commands (such as locate commands) which
  2242. take any string parameter and also some options. It allows any delimiter
  2243. to separate the parameter from the options.
  2244. However,
  2245.  
  2246. PARSE VALUE "s / this/that" WITH . delim first (delim) second
  2247.  
  2248. will not have the same effect, since delim and first are not assigned
  2249. until after the expression (delim) has been searched for.
  2250.  
  2251. Note that the symbols are assigned in order from left to right, so
  2252.  
  2253. PARSE VALUE "1 2 3" WITH a x.a y.a
  2254.  
  2255. will assign 1 to a, then 2 to x.1, then 3 to y.1
  2256.  
  2257. Other Examples:
  2258.  
  2259. PARSE VALUE "Hello there ! etc.." WITH a b ! . "c" c
  2260.  
  2261. will assign "Hello" to a and "there " to b, then throw away " et" and
  2262. assign ".." to c.
  2263.  
  2264. PARSE VALUE "123456789" WITH a +4 b 6 c
  2265.  
  2266. will assign "1234" to a, "5" to b, and "6789" to c.
  2267.  
  2268. PARSE VALUE "   multiple   spaces   between   words" WITH a b c
  2269.  
  2270. will assign "multiple" to a, "spaces" to b and "  between   words" to c.
  2271.  
  2272. PARSE VALUE "a  b  c  d  e  f" WITH "b" a b "e"
  2273.  
  2274. will assign "c" to a and " d  " to b.
  2275.  
  2276. PARSE VALUE "hello-there" WITH a "-" b -1 c +1
  2277.  
  2278. This assigns "hello" to a, "-there" to b and "o" to c. 
  2279. _________________________________________________________________________
  2280.  
  2281. QUEUE [expression] ; PUSH  [expression]
  2282.  
  2283. These instructions place the specified single expression on to the stack.
  2284. If the expression is omitted, then the null string will be used.
  2285. If QUEUE is used, the expression will be added in FIFO order (it will be
  2286. retrieved after all currently existing stack items). If PUSH is used, the
  2287. expression will be added in LIFO order (it will be retrieved before all
  2288. currently existing stack items).
  2289.  
  2290. Other programs may communicate with the REXX stack to provide data for
  2291. or retrieve data from a REXX program. See the separate section on the
  2292. REXX stack for details.
  2293. _________________________________________________________________________
  2294.  
  2295. CALL name [arg][,[arg],...]]
  2296.  
  2297. The CALL command evaluates its arguments, if any, and passes them to the
  2298. named procedure.  The name may be either a symbol or a string constant.
  2299. If it is a symbol, then it will be translated to upper case before
  2300. use.
  2301.  
  2302. The procedure may or may not return a result.  If it does return a
  2303. result, then this is assigned to the variable RESULT, otherwise this
  2304. variable is dropped - that is, it will no longer have a value.
  2305.  
  2306. See the section on function or subroutine invocation for more details.
  2307.  
  2308. CALL ON  condition [NAME symbol]
  2309. CALL OFF condition
  2310.  
  2311. These call instructions provide error trapping.  The possible
  2312. conditions which may be trapped are as follows:
  2313.  
  2314.  FAILURE:  A command to the environment returned a "failure" code.
  2315.            Usually this means a negative return code, but see the
  2316.            section on commands to the environment.
  2317.  ERROR:    A command to the environment returned an "error" code.
  2318.            This usually means a non-zero return code.  Note that if
  2319.            "failures" are not being trapped, then "error" will catch
  2320.            failures also.
  2321.  NOTREADY: A function from the REXX I/O model (see the separate section)
  2322.            was unsuccessful because, for example, an input function
  2323.            encountered an end-of-file condition.
  2324.  HALT:     The user has attempted to halt the program, for example by
  2325.            typing Control-C.  Signals SIGHUP and SIGTERM also raise the
  2326.            HALT condition.
  2327.  
  2328. (These are the same conditions as for SIGNAL ON, except that the two
  2329. conditions SYNTAX and NOVALUE may not be trapped by CALL ON).
  2330.  
  2331. The CALL ON instruction turns on condition handling.  Whenever the
  2332. specified condition occurs, a CALL is made to a handling routine.  If
  2333. the NAME keyword is specified, then the following symbol is taken as
  2334. the name of the handling routine.  Otherwise the handling routine has
  2335. the same name as the condition.  On return from the call, execution
  2336. proceeds normally.  The RESULT variable will not be affected by the
  2337. call.  During the handling routine, the condition handling will be
  2338. set to "DELAY".  For the FAILURE, ERROR and NOTREADY conditions, this
  2339. means that further conditions will be ignored until the handling routine
  2340. returns or until handling is explicitly turned on or off.  For the HALT
  2341. condition, the program will continue executing but the halt signal will
  2342. be remembered until the handling routine returns or until handling is
  2343. explicitly turned on or off.  At that time the signal will be handled
  2344. in an appropriate way.
  2345.  
  2346. Condition handling with the CALL ON instruction always occurs at clause
  2347. boundaries.  When a condition occurs, it is delayed until the currently
  2348. executing clause has completed, and then the condition handler is
  2349. called.
  2350.  
  2351. At any time after the handling routine is called and before it returns,
  2352. the CONDITION() builtin function may be used to retrieve information
  2353. about the condition which was trapped.  The information provided by
  2354. this function is saved across function calls.  If a further condition
  2355. is handled while the handler is still active, this will not affect the
  2356. information which may be provided to the current handler.
  2357.  
  2358. When a condition handler is activated, the special variable SIGL is set
  2359. to the line number of the instruction in which the condition was
  2360. raised.  Also, for conditions ERROR and FAILURE, the special variable
  2361. RC will hold the return code of the command which caused the condition
  2362. to be raised.
  2363.  
  2364. Condition handling will always remain on until turned off with either
  2365. "CALL OFF condition" or "SIGNAL OFF condition".  If an external routine
  2366. is called, condition handling will be turned off temporarily until the
  2367. external routine finishes or turns condition handling on.
  2368.  
  2369. The status of condition handling is saved across function calls.  If a
  2370. subroutine uses a "CALL ON/OFF" or "SIGNAL ON/OFF" instruction, the
  2371. condition handling within the current routine will be unaffected.
  2372.  
  2373. A CALL OFF instructions cancels condition handling for a particular
  2374. condition.  If handling is turned off for ERROR, FAILURE or NOTREADY,
  2375. then the condition will be ignored whenever it occurs.  If handling is
  2376. turned off for HALT then the program will halt when the condition
  2377. occurs.
  2378.  
  2379. NOTE: Because calling the handling routine affects the special variable
  2380.       SIGL, this variable can no longer be trusted to remain constant
  2381.       when CALL ON HALT is in effect, since this condition can occur at
  2382.       any time without notice.
  2383.  
  2384. BUG:  The routine named in a CALL ON instruction must be an internal
  2385.       routine.  Built-in or external routines are not allowed.
  2386. _________________________________________________________________________
  2387.  
  2388. RETURN [value]
  2389.  
  2390. This statement returns control to the most recent caller, optionally
  2391. returning a value to the caller. All current DO and SELECT structures
  2392. are exited and, if appropriate, the current variables are deleted and
  2393. the caller's variables are reinstated.
  2394.  
  2395. If the caller was a function call or a CALL statement, the value may be
  2396. any string which is passed to the caller in the manner described above.
  2397. If the caller was a function call, the return value must be given or an
  2398. error results.  On return from a condition handler, the result is
  2399. ignored.
  2400.  
  2401. If the caller was a shell (that is, no CALL statement or function call
  2402. is currently active), then the RETURN statement exits from the REXX
  2403. interpreter. The return value need not be given, but if it is specified
  2404. it must be an integer, which is returned to the shell as an exit status.
  2405. _________________________________________________________________________
  2406.  
  2407. PROCEDURE
  2408. PROCEDURE EXPOSE var1 [var2 ...]
  2409. PROCEDURE HIDE var1 [var2 ...]    (LOCAL)
  2410.  
  2411. The PROCEDURE command is used in an internal function or procedure to
  2412. hide the caller's variables.
  2413.  
  2414. The PROCEDURE command on its own hides all the caller's variables and
  2415. makes sure that on return all the current function's variables are
  2416. erased. On return from a function containing this instruction, the
  2417. caller's old variables are reinstated when the current function's have
  2418. been deleted.
  2419.  
  2420. The PROCEDURE EXPOSE varlist command is like the form with no arguments
  2421. except that all the named variables are left visible. These variables
  2422. will all remain when the RETURN statement deletes all the other variables
  2423. from the current function. If any of the named variables are not defined,
  2424. then they will remain undefined until they are assigned a value. This
  2425. value will then be carried back to the calling procedure.
  2426.  
  2427. It is not an error to specify a symbol more than once; this will have
  2428. the same effect as specifying it just once.
  2429.  
  2430. Simple symbols, stems or compound symbols may be exposed.  If a stem is
  2431. named, then all possible compound symbols starting with that stem will
  2432. be exposed.
  2433.  
  2434. BUG: It is not possible to expose a stem and one of its compound
  2435.      symbols at the same time.  If a stem is named and one of its
  2436.      compound symbols appears later, then the compound symbol has in
  2437.      effect already been exposed and so the expected results will
  2438.      occur.  However, if a stem appears after one of its compound
  2439.      variables, the stem will be ignored without a warning.
  2440.  
  2441. Any symbol(s) in the list following PROCEDURE EXPOSE may be enclosed in
  2442. parentheses.  In such cases the value of the symbol is used as a list
  2443. of extra symbols to expose.  For example, if the assignment:
  2444.      list = "var1 var2 stem. misc.3"
  2445. occurred in the calling program, then the instruction:
  2446.      procedure expose test1 (list) test2
  2447. will expose the following symbols (in this order):
  2448.      test1 list var1 var2 stem. misc.3 test2
  2449. Notice that the symbol inside the parentheses is itself exposed before
  2450. its value is obtained.
  2451.  
  2452. LOCAL: The PROCEDURE HIDE varlist command hides only the named variables,
  2453.       leaving the rest visible. On return the hidden variables are
  2454.       deleted, leaving all the others. The action of PROCEDURE HIDE list
  2455.       is identical to that of
  2456.       PROCEDURE EXPOSE <every existing variable except those named>.
  2457.       (in fact what happens is that all existing symbols are exposed and
  2458.       then the named symbols are deleted from the new variable table.
  2459.       This command is therefore quite inefficient and should be used
  2460.       sparingly).
  2461.       The PROCEDURE HIDE statement may not hide individual compound
  2462.       variables. Only stems and simple symbols should be specified,
  2463.       otherwise a syntax error will result.
  2464. NOTE: This means that variables which are undefined when the
  2465.       PROCEDURE HIDE statement is executed will be deleted on return from
  2466.       the current function. However, if new compound variables are 
  2467.       defined having a stem in common with some compound variables which
  2468.       already exist, then the new compound variables will not be deleted
  2469.       on return.
  2470.  
  2471. NOTE: As in standard REXX, the order in which the symbols are named can
  2472.       have an effect. For example, if i=5 then
  2473.          procedure expose i a.i
  2474.       will expose i and the compound symbol a.5, but
  2475.          procedure expose a.i i
  2476.       will expose the compound symbol a.I and i. This is because the
  2477.       names are processed from left to right, and in the latter case the
  2478.       symbol i is not visible when the name a.i is encountered.
  2479.  
  2480. The PROCEDURE command will almost invariably be at the beginning of a
  2481. function or procedure. It may be used in the middle rather than at the
  2482. beginning, but this is not recommended. In fact the ANSI standard
  2483. states that PROCEDURE must be the first instruction of a subroutine, if
  2484. it is present. In any case, an error will result if it is used within
  2485. an INTERPRET, or a DO, or some other control structure.
  2486.  
  2487. LOCAL: If OPTIONS 'EXPOSE' (qv) is in effect then the PROCEDURE
  2488.        instruction will be allowed at the start of a program which is
  2489.        called as an external subroutine or function.  This allows
  2490.        variables from the caller (which would normally be hidden) to be
  2491.        exposed.  The instruction does not have to be the first in the
  2492.        program but it must not be placed inside any control structure (so
  2493.        it could, for example, be preceded by an OPTIONS 'EXPOSE'
  2494.        instruction).
  2495.  
  2496. Example: an improved version of the above factorial program
  2497.         parse arg x
  2498.         say x"!="fact(x)
  2499.         exit
  2500.  fact:  procedure           /* now we get a different p each time */
  2501.         parse arg p
  2502.         if p<3 then return p
  2503.         return fact(p-1) * p
  2504.  
  2505. NOTE: The special variable SIGL must be explicitly exposed if its current
  2506.       value is needed within the procedure.  It is set by the CALL
  2507.       instruction or the function call before any PROCEDURE instruction
  2508.       is encountered.
  2509. _________________________________________________________________________
  2510.  
  2511. INTERPRET string
  2512.  
  2513. This command evaluates the given string and interprets it as if it were
  2514. part of a real rexx program. The string may contain any commands that
  2515. the program line containing the INTERPRET command might have executed
  2516. except that any DO or SELECT control blocks within the string must be
  2517. complete.  That is, the string may not start any new DO or SELECT
  2518. control blocks to be continued by the main program, and nor can it
  2519. contain an END, LEAVE, WHEN, etc. corresponding to a control block of
  2520. the main program.  An interpreted command can, however, cause a return
  2521. from a function.
  2522.  
  2523. NOTE: Interpreted strings must not contain labels.
  2524.  
  2525. Example: This program evaluates an expression given on the command line:
  2526.  
  2527. #!/mclab/imc/sun4/rexx  
  2528. parse arg x
  2529. interpret "y="||x
  2530. say x"="y
  2531. _________________________________________________________________________
  2532.  
  2533. SIGNAL [VALUE] name  |  SIGNAL ON|OFF condition [NAME label]
  2534.  
  2535. 1. SIGNAL [VALUE] name
  2536.  
  2537. In this form, the SIGNAL instruction is a primitive form of `goto'.
  2538. Using it to control program flow in this manner is strongly discouraged.
  2539.  
  2540. When this command is encountered interpretation jumps to the named label
  2541. (SIGNAL labels work just like procedure labels - but SIGNAL never invokes
  2542. another rexx program).
  2543.  
  2544. If the VALUE keyword is present, or if the name does not start with a
  2545. symbol or a string constant, then the name is treated as an expression
  2546. which must evaluate to the name of a label (irrespective of case).
  2547.  
  2548. All current DO and SELECT structures within the current procedure are
  2549. terminated by the SIGNAL instruction before the jump is taken.
  2550.  
  2551. When the SIGNAL instruction is executed, the variable SIGL is set to hold
  2552. the number of the line at the time of the jump. This can be used in
  2553. error analysis - as in:
  2554.  
  2555.   if something_is_wrong then signal error
  2556.   ...
  2557.   error: say "Something is wrong at line" sigl
  2558.  
  2559. or it can be used to type out long texts or help - as in:
  2560.  
  2561.    <lots of argument checking>
  2562.    if something_is_wrong then signal help /*
  2563.    This is a paragraph of help. It is enclosed in comments, so
  2564.    the interpreter ignores it. However the help routine will
  2565.    use the sourceline function to type it out on to the screen.
  2566.    */
  2567.    ...
  2568.    help: do i=sigl+1 while sourceline(i)~="*/"
  2569.    say sourceline(i)
  2570.    end
  2571.  
  2572. The SIGNAL VALUE construction is useful for calling procedures with
  2573. variable names. This can be done as follows:
  2574.  
  2575.    /* procname is set to the name of a procedure */
  2576.    call jumpto procname,arguments
  2577.    ...
  2578.    jumpto: parse arg jumpname
  2579.    signal value jumpname
  2580.    ...
  2581. When the named procedure is called, its first argument will be its name,
  2582. and the subsequent arguments will be those supplied by the caller.
  2583. The DO and SELECT structures in the calling program are protected from
  2584. the SIGNAL instruction, since the latter is encountered within procedure
  2585. `jumpto'.
  2586.  
  2587. 2. SIGNAL ON  condition [NAME symbol]
  2588.    SIGNAL OFF condition
  2589.  
  2590. These instructions maintain exception handlers for the following
  2591. contitions:
  2592.  
  2593.  SYNTAX:   Any syntax error (for example "Bad arithmetic conversion" or
  2594.            "Unexpected ',' or ')'") which occurs during interpretation.
  2595.  NOVALUE:  A variable name is used which has no value.
  2596.            NOTE: This condition is not raised during interpretation of
  2597.                  sub-names in compound variables. Hence, if `foo' has no
  2598.                  value, then "a=foo+1" will cause a novalue error but
  2599.                  "a=abc.foo" will not cause an error unless ABC.'FOO' has
  2600.                  no value.  Also, the builtin function VALUE() will never
  2601.                  raise the NOVALUE condition.
  2602.  HALT:     The user has attempted to halt the program, for example by
  2603.            typing Control-C.  Signals SIGHUP and SIGTERM also raise the
  2604.            HALT condition.
  2605.  FAILURE:  A command to the environment returned a "failure" code.
  2606.            Usually this means a negative return code, but see the
  2607.            section on commands to the environment.
  2608.  ERROR:    A command to the environment returned an "error" code.
  2609.            This usually means a non-zero return code.  Note that if
  2610.            "failures" are not being trapped, then "error" will catch
  2611.            failures also.
  2612.  NOTREADY: A function from the REXX I/O model (see the separate section)
  2613.            was unsuccessful because, for example, an input function
  2614.            encountered an end-of-file condition.
  2615.            
  2616. (These are the same conditions as for CALL ON, with the two extra
  2617. conditions SYNTAX and NOVALUE).
  2618.  
  2619. The SIGNAL ON instruction turns on condition handling.  Whenever the
  2620. specified condition occurs, a SIGNAL is made to a handler.  If the NAME
  2621. keyword is specified, then the following symbol is taken as the name of
  2622. the handler.  Otherwise the handler has the same name as the condition.
  2623. At this point, RC holds the number of the error which caused the jump
  2624. (except in the case of NOTREADY) and SIGL holds the line number in
  2625. which the error occurred.  The routine in which the SIGNAL ON
  2626. instruction was encountered becomes the current routine; all internal
  2627. routines which became active since then are terminated.  All
  2628. DO/SELECT/IF control structures within the current routine are also
  2629. terminated.  The SIGNAL ON instruction is then cancelled, and another
  2630. SIGNAL ON instruction will be necessary to reinstate handling of this
  2631. particular condition.
  2632.  
  2633. At any time after control is passed to the handler, and before the
  2634. handler causes a return from the current subroutine, the CONDITION()
  2635. builtin function may be used to retrieve information about the
  2636. condition which was trapped.
  2637.  
  2638. A SIGNAL OFF instructions cancels condition handling for a particular
  2639. condition.  If handling is turned off for ERROR, FAILURE, NOTREADY or
  2640. NOVALUE, then the condition will be ignored whenever it occurs.  If
  2641. handling is turned off for HALT or SYNTAX, then the program will halt
  2642. when the condition occurs.
  2643.  
  2644. Condition handling persists from the point of the SIGNAL ON instruction
  2645. until the current function returns, or until a SIGNAL OFF instruction
  2646. is executed.  If an external routine is called, condition handling will
  2647. be turned off temporarily until the external routine finishes or turns
  2648. condition handling on.
  2649.  
  2650. The status of condition handling is saved across function calls.  If a
  2651. subroutine uses a "SIGNAL ON/OFF" or "CALL ON/OFF" instruction, the
  2652. condition handling within the current routine will be unaffected.
  2653.  
  2654. NOTE: The SIGNAL ON SYNTAX command does not trap fatal system errors or
  2655.       the error which is caused when EXIT or RETURN returns a non-integer
  2656.       to the UNIX environment (this is because the latter is, in effect,
  2657.       raised by the environment rather than by the interpreter itself).
  2658. _________________________________________________________________________
  2659.  
  2660. TRACE [symbol]
  2661. TRACE "string"
  2662. TRACE VALUE expression
  2663.  
  2664. The symbol, string constant or expression is evaluated (the VALUE keyword
  2665. may be omitted if the expression does not start with a symbol or a string
  2666. constant).  It must evaluate to a word consisting of zero or more
  2667. question marks, followed by an optional letter, followed by an optional
  2668. string of characters. Each question mark at the start of the string
  2669. toggles the `interactive tracing' mode (see below), and the following
  2670. letter, if any, is translated to upper case and must be one of the
  2671. following:
  2672.  
  2673.    A (All):      all clauses are traced before execution
  2674.    C (Commands): all commands to the environment are traced before
  2675.                  execution, together with the actual string passed to
  2676.                  the environment. If the command results in a non-zero
  2677.                  return code, then the return code is traced after
  2678.                  execution.
  2679.    E (Error):    Any command to the environment resulting in an error
  2680.                  (i.e. non-zero return code) is traced after execution,
  2681.                  together with the return code
  2682.    F (Failure):  Any command to the environment resulting in failure
  2683.                  (i.e. negative return code) is traced after execution,
  2684.                  together with the return code
  2685.    I (Intermediates): All clauses are traced before execution, and all
  2686.                  calculations are traced, including intermediate values
  2687.                  evaluated during the calculation. Assignments made by
  2688.                  PARSE instructions are also traced.
  2689.    L (Labels):   All labels passed during execution are traced
  2690.    N (Normal):   the default setting - same as F.
  2691.    O (Off):      Nothing is traced, and interactive tracing is also
  2692.                  switched off.
  2693.    R (Results):  All clauses are traced before execution, and the results
  2694.                  from all calculations are traced. Assignments made by
  2695.                  PARSE instructions are also traced.
  2696.  
  2697. If no setting is specified or if the setting is an empty string, then
  2698. interactive tracing is turned off and tracing is set to "N".
  2699.  
  2700. When clauses are being traced (i.e. A, R or I), when an INTERPRET command
  2701. is traced, the actual string being interpreted is also traced. When an
  2702. END command is traced, the source statement to which the END corresponds
  2703. is also traced.
  2704.  
  2705. A program may be made to trace itself during execution by signalling
  2706. it with SIGQUIT (on the Suns this can be done by pressing "control \").
  2707. When this signal is received, the tracing mode switches to "?i". If
  2708. a SIGQUIT is received whilst in interactive tracing mode and if an
  2709. interruption has already been received but not handled, the program
  2710. exits immediately (as is the case when SIGQUIT is not handled).  This
  2711. feature exists mainly to stop the interpreter in case of a bug.
  2712.  
  2713. A program may be made to trace itself when execution starts by using the
  2714. "-t" commandline flag (see the invocation section for details).
  2715.  
  2716. Interactive tracing
  2717.  
  2718. In interactive trace mode, all TRACE instructions passed in the program
  2719. are ignored and the interpreter will pause after tracing each clause,
  2720. label, command or return code (as appropriate for the trace setting).
  2721. The interpreter prompts for input with the string ">trace>".
  2722.    If an empty line is entered (without spaces), execution of the
  2723. program continues normally until the next event which is traced.
  2724.    If a line of REXX is entered, then that line is interpreted with
  2725. tracing set to "E".  If the line calls a program, then TRACE
  2726. instructions in that program are ignored. If the line itself uses the
  2727. TRACE instruction, then the trace setting is altered accordingly and
  2728. execution of the program will continue after the input line has been
  2729. interpreted.
  2730.    If the input line does not contain a TRACE instruction, then when it
  2731. has been interpreted the prompt will reappear for more input.
  2732.    If an error occurs during interpretation of the input line, a message
  2733. is displayed and the prompt reappears (unless the command executed a
  2734. TRACE instruction). The error does not cause the program to exit, and
  2735. no signalling takes place (unless the error occurred in a program which
  2736. was called by the input line and which contains its own SIGNAL ON xxx
  2737. command).
  2738.    Commands to the environment within the string will not set the
  2739. variable RC, but will have non-zero return codes traced.
  2740.    All condition traps are turned off during interpretation of the
  2741. string.
  2742.  
  2743. It is possible to make the interpreter change tracing and also prompt
  2744. for more input by using the built-in TRACE function rather than the
  2745. TRACE instruction, for example:
  2746.    call trace r
  2747. sets the `results' tracing mode (whilst keeping interactive mode) without
  2748. continuing execution of the program.
  2749.  
  2750. The interactive tracing mode is useful for the following purposes (and
  2751. others):
  2752.    - single-stepping through a program (use trace ?a)
  2753.    - setting breakpoints (use trace ?l and put a label at the breakpoint)
  2754.    - examining or changing variables during execution.
  2755.  
  2756. The input line is interpreted in exactly the same way as with the
  2757. INTERPRET command, and so the same restrictions apply (e.g. DO and END
  2758. instructions etc must be matched properly).
  2759.  
  2760. BUG:The following also applies, however:
  2761.   - some of the source information is lost, so any PARSE SOURCE
  2762.     instruction in the line will have the calling method and the calling
  2763.     name replaced by "TRACE" (this does not apply to PARSE SOURCE
  2764.     instructions within programs that may be called by the input line).
  2765.  
  2766. If the input line transfers control by a SIGNAL instruction, then control
  2767. is immediately transferred to the target instruction and it is executed
  2768. before tracing resumes. If the input line contains a RETURN or EXIT
  2769. instruction, then execution returns to the caller and continues to the
  2770. end of the current statement. The return may cause a change in the
  2771. tracing mode, since this is saved across function calls. However, if
  2772. interactive tracing is still in effect, then tracing will resume at the
  2773. next instruction.
  2774.  
  2775. NOTE:If the interpreter has a controlling terminal (that is, "/dev/tty"
  2776.      can be opened when the interpreter initialises), then the trace
  2777.      prompt will be written to the terminal, and input will be read from
  2778.      the terminal. Otherwise, stderr and stdin are used respectively.
  2779.      If an error occurs during a command which was typed in interactive
  2780.      trace mode, then the error message will be written to the terminal.
  2781.      However, all normal input and output use stdin and stdout, while
  2782.      trace output is written to the requested file (see OPTIONS).  In
  2783.      particular, if tracing has been redirected, then no trace output
  2784.      will appear on the terminal. Therefore it is not a good idea to
  2785.      redirect tracing when interactive tracing will be used.
  2786.  
  2787. BUG: Interactive tracing is not recursive, i.e. if, during interactive
  2788.      tracing, a line is entered such as:
  2789.         trace i;say a+b
  2790.      then the tracing of "say a+b" (and other statements following the
  2791.      TRACE instruction) will not be interactive, even though the
  2792.      interactive tracing mode is (in theory) still in operation.
  2793.  
  2794. TRACE output
  2795.  
  2796. Each line of trace output is preceded by three characters which identify
  2797. the type of trace output. Any clause or command traced will be indented
  2798. according to its logical depth of nesting. Results (or intermediate
  2799. values) will be indented a further two spaces, and have leading and
  2800. trailing quotes added. The line numbers of source statements and labels
  2801. are displayed before the three-character prefix.  An interpreted
  2802. instruction or a command about to be executed will be displayed without
  2803. a line number.
  2804.  
  2805. The three-character prefixes are:
  2806.  
  2807. +++ A trace message (an error message, or the return code from a command)
  2808.  
  2809. *-* A source statement or label (exactly as it appears in the source).
  2810. *,* A source statement which is continued from the previous line.
  2811. *~* The result of evaluating an expression which is either a command to
  2812.     be passed to the environment or the parameter of an INTERPRET
  2813.     instruction.
  2814.  
  2815. >>> The result of an expression displayed in "trace r", or the value
  2816.     assigned to a variable during parsing or during update of the
  2817.     control variable of a repetitive DO loop.
  2818. >.> The value `assigned' to a placeholder (dot) during parsing.
  2819.  
  2820. The following prefixes are used during TRACE I:
  2821.  
  2822. >V> The contents of a variable
  2823. >L> a literal (that is, a constant symbol or number, an uninitialised
  2824.     variable, or a string/hex/binary constant)
  2825. >F> The result of applying a function
  2826. >P> The result of applying a prefix operator
  2827. >O> The result of applying a (binary) operator
  2828. >C> The name of a compound variable (after substitution and before use).
  2829.  
  2830. The trace setting is saved across function calls, so that if tracing is
  2831. switched on or off during a function, the previous setting is restored
  2832. when the function returns. This means that:
  2833.   - if a function is known to work, then "trace off" may be placed at
  2834.     the start. When a program is being traced, tracing is switched off
  2835.     when the function is entered, and back on when the function returns.
  2836.   - if a function is known not to work, then a trace instruction placed
  2837.     at the start of the function will switch tracing on only for the
  2838.     duration of the function call.
  2839. _________________________________________________________________________
  2840.  
  2841. OPTIONS expression
  2842.  
  2843. The expression is evaluated and broken into blank-delimited words.
  2844. Each word is examined to see if it is recognised as a valid interpreter
  2845. option for this implementation.  Any word which is not recognised is
  2846. skipped over, since it probably applies to some other implementation.
  2847.  
  2848. In REXX/imc, the case of the options is not significant, and options
  2849. may be abbreviated.  The minimum abbreviation for each option is shown
  2850. in uppercase.  Options which require an '=' are only recognised if the
  2851. '=' sign is present and followed by a valid string. 
  2852.  
  2853. REXX/imc currently recognises the following options (options starting
  2854. "no" are listed under their opposites):
  2855.  
  2856.  EXPose              This option makes the PROCEDURE EXPOSE instruction
  2857.  NOEXPose            legal at the beginning of a program which is called
  2858.                      as an external subroutine or function, so that it
  2859.                      can gain access to the variables of the caller.  The
  2860.                      NOEXPose option restores the standard behaviour in
  2861.                      which PROCEDURE will cause an error when written at
  2862.                      the beginning of a program.  See also the PROCEDURE
  2863.                      instruction.
  2864.  
  2865.  SETRC               This option causes the I/O operations linein,
  2866.  NOSETRC             charin, lineout, charout, parse pull and parse
  2867.                      linein to set the RC special variable as they did in
  2868.                      earlier versions of REXX/imc.  If the NOTREADY
  2869.                      condition is not being trapped then an I/O operation
  2870.                      which sets RC to a nonzero value will instead
  2871.                      cause an ERROR condition to be raised, if that
  2872.                      is being trapped.  Option NOSETRC restores the
  2873.                      behaviour of I/O operations to the documented
  2874.                      behaviour.
  2875.  
  2876.  SIGPipe             Usually the interpreter terminates silently when it
  2877.  NOSIGPipe           receives a SIGPIPE signal.  This occurs when a
  2878.                      program tries to write data down a pipe with no
  2879.                      process to read it: for example, the command
  2880.  
  2881.                        rexx -s "do forever; say hello; end" | head -1
  2882.  
  2883.                      will echo one line of output before the "head"
  2884.                      process terminates, and the Rexx program will then
  2885.                      receive a SIGPIPE and terminate.
  2886.  
  2887.                      Using the SIGPipe option will make the interpreter
  2888.                      trap this signal and continue running.  In this
  2889.                      case the program should take care to detect error
  2890.                      conditions from LINEOUT, CHAROUT and other I/O
  2891.                      functions to avoid wasting resources.
  2892.  
  2893.                      Using the NOSIGPipe option will restore the
  2894.                      behaviour of terminating when a SIGPIPE signal is
  2895.                      received.
  2896.  
  2897.  TRACEfile=filespec  If "filespec" represents a filename which can be
  2898.                      opened for writing, then an information message is
  2899.                      written to the standard output and all trace output
  2900.                      is redirected to the named file.  Otherwise an error
  2901.                      message is written to the standard error and tracing
  2902.                      remains unchanged.  Instead of a regular file the
  2903.                      filespec can be "stdout" to send trace output to
  2904.                      the standard output or "stderr" to send it to the
  2905.                      standard error.
  2906. _________________________________________________________________________
  2907.  
  2908. ADDRESS [VALUE] [environment]  |  ADDRESS environment command
  2909.  
  2910. When  the REXX interpreter finds a program statement which is not an
  2911. instruction (as listed above), then it evaluates the whole statement as
  2912. an expression (if it can), and issues the resulting string to the
  2913. current environment as a command.
  2914.  
  2915. The first form of the ADDRESS instruction stated above changes the
  2916. environment (until the next ADDRESS instruction).  If the environment
  2917. name is given, it may be a symbol (which is translated to upper case,
  2918. but not substituted by its value) or a string constant, or a string
  2919. expression preceded by the keyword VALUE.  The VALUE may be omitted if
  2920. the expression does not start with a symbol or a string constant.  The
  2921. current environment is changed to the given string.
  2922.  
  2923. If no environment name follows the ADDRESS instruction, then the previous
  2924. environment is made current.  For example:
  2925.  
  2926.    address unix       /* "UNIX" is current   */
  2927.    address "MY_ENV"   /* "MY_ENV" is current */
  2928.    address            /* "UNIX" is current   */
  2929.    address            /* "MY_ENV" is current */
  2930.  
  2931. The second form of the ADDRESS instruction given above executes a command
  2932. in a given environment without changing the current environment.  The
  2933. environment name must be a symbol or string constant, and the command may
  2934. be any string expression.  So, if the following line is appended to the
  2935. previous example:
  2936.  
  2937.    address command "ls -al"
  2938.  
  2939. the command "ls -al" is executed in environment "COMMAND", while the
  2940. current environment is still "MY_ENV".
  2941.  
  2942. Whenever a command is executed, the special variable RC is set to the
  2943. return code given by the command.  If this return code is non-zero,
  2944. then the command will also cause a FAILURE or ERROR condition to be
  2945. raised.  These conditions are ignored unless trapped by CALL ON or
  2946. SIGNAL ON.
  2947.  
  2948. Two environments are built in to REXX/imc:
  2949.  
  2950. ADDRESS UNIX
  2951.  
  2952. Each command sent to the "UNIX" environment is executed in a separate
  2953. Bourne shell.  Note that this involves considerable overhead, and
  2954. moreover no command can make a permanent change to the environment (e.g.
  2955. "set" and "export" will have no effect).  However, it does allow the
  2956. flexible syntax of the Bourne shell to be used, including piping, I/O
  2957. redirection, and filename expansion.
  2958.  
  2959. In this environment, any command which returns a code of 1 will raise
  2960. the FAILURE condition, as well as any command which returns a negative
  2961. return code.  This is because the Bourne shell always returns 1 when
  2962. it fails to find the requested command.
  2963.  
  2964. ADDRESS COMMAND
  2965.  
  2966. Each command sent to the "COMMAND" environment is tokenised and executed
  2967. by a primitive shell which is built into the interpreter (in shell.c).
  2968. This makes for quicker execution of each command, but note that at
  2969. present the only "meta-characters" which are supported are quotes.  That
  2970. is, enclosing a string in quotes passes it verbatim (i.e. untokenised)
  2971. as a parameter to a command.  In particular, piping, file redirection
  2972. and filename expansion are not supported.  Nor does this shell have any
  2973. builtin commands (such as cd, set), with the exception of "hash" (see
  2974. later).  For speed of execution, each time a command is executed its
  2975. path is remembered in a hash table.  The hash table statistics may be
  2976. obtained with the "hash" builtin command, which is similar to that of
  2977. the Bourne shell (and bash).  The command "hash name1 [name2 ...]" will
  2978. search for each of the given names and add the results to the hash
  2979. table, but if any of the names is "-r" then the hash table will be
  2980. cleared.  The names are examined from left to right, so "hash cat -r
  2981. ls" will result in just "/bin/ls" in the hash table.  The hash table is
  2982. also cleared whenever putenv() or value(,,"ENVIRONMENT") is used to
  2983. change PATH.  The command "hash" will print out the list of hash table
  2984. entries.  "hits" represents the number of times a command has been
  2985. looked up in the table, and "cost" represents the amount of work which
  2986. was initially carried out in searching along the path for the command.
  2987. A plus-sign in column 1 indicates that the entry was placed in the same
  2988. hash bucket as the previous entry; the commands within hash buckets are
  2989. arranged in alphabetical order.  The hash buckets are listed in no
  2990. particular order.
  2991.  
  2992. In this environment, an unrecognised command produces return code -3.
  2993. Any command which produces a negative return code will raise the
  2994. FAILURE condition.
  2995.  
  2996. Other environments may be added by application programs.
  2997.  
  2998. If a command is sent to an unrecognised environment, then return code
  2999. -3 and a FAILURE condition results.
  3000.  
  3001. The environment when a program starts up is usually UNIX.  The current
  3002. environment may be found by calling address(), and the environment at
  3003. startup may be found using "parse source".
  3004.  
  3005. Here is a simple shell program to demonstrate the use of commands:
  3006.  
  3007. do i
  3008.    sayn i'>'
  3009.    parse pull command
  3010.    parse upper var command word .
  3011.    if word='EXIT' then exit
  3012.    command
  3013.    if rc!=0 then say "The return code was" rc
  3014. end i
  3015.  
  3016. Each command is read from standard input. If the command 'Exit' is
  3017. received, the shell quits. Otherwise, the command is issued to a Bourne
  3018. Shell and the return code is checked.
  3019.  
  3020. Both the ADDRESS settings (that is, the current environment and the most
  3021. recent one) are saved across function calls.
  3022.  
  3023. NOTE: The program rxstack (in Oxford /mclab/imc/sun4/rxstack) may be
  3024.       used to access the stack while executing a shell command.  See
  3025.       the stack section below for details.
  3026. _________________________________________________________________________
  3027.  
  3028. The REXX I/O Model
  3029.  
  3030. Standard REXX allows files to be accessed using the seven functions
  3031. charin, charout, chars, linein, lineout, lines, stream.  This REXX
  3032. version has fourteen I/O functions in total; the others remain for
  3033. backward compatibility but may be removed in future because their
  3034. functionality is covered by the stream() function.
  3035.  
  3036. Each I/O function may accept a stream name as a parameter.  Usually,
  3037. the stream name is the path name of a file which will be accessed -
  3038. though other meanings may be given to streams by the "open", "popen"
  3039. and "stream" functions.
  3040.  
  3041. Associated with each currently accessed stream is a read pointer and a
  3042. write pointer.  Characters or lines can be read from the file at the
  3043. position indicated by the read pointer, or they may be written to the
  3044. file at the position indicated by the write pointer.  In each case the
  3045. pointer is updated to indicate the new file position after the read or
  3046. write.  The file pointers may be also moved explicitly by various
  3047. functions.  Note that the read and write pointers will in general be
  3048. different, in contrast to the usual Unix file pointer.
  3049.  
  3050. Each file is opened by REXX when it is first accessed, and closed when
  3051. REXX exits.  Therefore files need not be opened and closed explicitly,
  3052. though in this version functions are provided for that purpose.  If
  3053. many files are to be accessed, it is advisable to close files which are
  3054. no longer needed because otherwise the Unix error "Too many open files"
  3055. may result.
  3056.  
  3057. Two kinds of stream exist: persistent and transient.  A persistent
  3058. stream is one which refers to a regular file, whereas a transient
  3059. stream is any other kind.  In particular, ttys and pipes are transient
  3060. streams.  The main difference between the two is that the read and write
  3061. pointers of a permanent stream may be repositioned, whereas those of a
  3062. transient stream may not.
  3063.  
  3064. If a function encounters an I/O error and is unable to perform its
  3065. function, then it will raise the NOTREADY condition.  This condition
  3066. will be ignored unless it is trapped by SIGNAL ON or CALL ON.  However,
  3067. in all cases it is possible to examine the most recent I/O error using
  3068. the STREAM() function.
  3069.  
  3070. The three streams "stdin", "stdout" and "stderr" are already open when
  3071. REXX starts up.  They may be used just as any other files, but they are
  3072. also accessed by instructions such as "say" and "pull", and by Unix
  3073. commands.  Because of this, REXX/imc only guarantees to be well-behaved
  3074. if stdin is never written to, and stdout and stderr are never read from.
  3075.  
  3076. The standard I/O functions CHARIN, CHAROUT, CHARS, LINEIN, LINEOUT,
  3077. LINES and STREAM all accept the empty string as a stream name.  This is
  3078. interpreted identically to the word "stdin", except in the cases of
  3079. CHAROUT and LINEOUT, in which it means "stdout".  However, the empty
  3080. string may not be used in the STREAM function in conjunction with the
  3081. the stream commands open, fdopen, popen or flush.
  3082.  
  3083. The I/O functions, and their descriptions, follow.  Note that no
  3084. "stream" or "file" name may contain a NUL character (i.e. "00"x).
  3085.  
  3086. CHARIN([stream] [,[position] [,count]])
  3087.  
  3088. If stream is supplied, it is read from, otherwise "stdin" is read.  The
  3089. charin function attempts to read a character from the stream, and
  3090. returns the result.  If count is supplied, then that many characters
  3091. are read and returned.  The length of the result may be less than the
  3092. number of characters requested if an error occurs.  If position is
  3093. supplied, then the read pointer is seeked to that position (with 1
  3094. being the first character of the stream) before reading.  If count is
  3095. zero, then the seek is performed without reading any characters.
  3096.  
  3097. If count>0 and no characters are read then the NOTREADY condition will
  3098. be raised.
  3099.  
  3100. If an interruption (^C) occurs during the read, then characters already
  3101. read may be lost.
  3102.  
  3103. NOTE: In order to read single characters from the keyboard, it is
  3104.       necessary to set the terminal into a suitable mode.  For example
  3105.       the Unix command "stty cbreak -echo" allows single characters
  3106.       to be read without echoing.  This should be reset with
  3107.       "stty -cbreak echo" before the program exits.
  3108.  
  3109. CHAROUT([stream] [,[string] [,position] ]
  3110.  
  3111. If stream is supplied, it is written to, otherwise stdout is written to.
  3112. If the string is supplied, it is written to the stream, otherwise no
  3113. write is performed.  If the position is supplied, the write pointer is
  3114. set to that position (with 1 being the first character) before the
  3115. write (if any).
  3116.  
  3117. If no string and no position are supplied, then all pending output to
  3118. the stream is flushed, and the write pointer is set to the end of the
  3119. stream.
  3120.  
  3121. The result will be the number of characters left unwritten, and if that
  3122. is non-zero then the NOTREADY condition will be raised.
  3123.  
  3124. CHARS([stream])
  3125.  
  3126. The result will be the number of characters which are immediately
  3127. available for reading from stream or, if it is omitted, from "stdin".
  3128. If the stream is not open and does not name a file which can be read,
  3129. zero will be returned and the NOTREADY condition raised.
  3130.  
  3131. CLOSE(stream)
  3132.  
  3133. The named stream is closed and REXX's table of information for that
  3134. stream is deleted.  The result will be the return code from the close
  3135. system call.
  3136.  
  3137. NOTE: if stream is one of "stdin" or "stdout" then future input or output
  3138.       operations with "say" and "pull" will fail to work properly.
  3139.  
  3140. This call is equivalent to STREAM(stream,'c','close) and may be deleted
  3141. in future releases.
  3142.  
  3143. FDOPEN(fd [,[mode] [,stream]])
  3144.  
  3145. This function is for accessing files which have already been opened by
  3146. another program and whose file descriptor numbers are known.  It should
  3147. not be used for opening files to which REXX already has access.
  3148.  
  3149. If mode is supplied, its first character must be one of "r" or "w",
  3150. meaning that the descriptor is to be opened for reading or read-write
  3151. respectively. The default is "r".  This mode should match the mode of
  3152. the already-open file descriptor.
  3153.  
  3154. If the stream argument is supplied, then the given fd will be opened and
  3155. given that name so that all future references to the fd will call it by
  3156. the given name.  Otherwise, future references to the fd will be by its
  3157. number.
  3158.  
  3159. If a stream argument is supplied which names an open stream, that
  3160. will be closed first.  Note that the new stream will be opened on a
  3161. different descriptor, so in particular this function should not be used
  3162. to redirect the standard input, output or error.
  3163.  
  3164. The result from fdopen will be the return code given by the fdopen
  3165. system call.
  3166.  
  3167. Example. If this program is called "foo.rexx":
  3168.  
  3169.         /* write to file descriptor 3 */
  3170.         call fdopen 3,"w"
  3171.         call lineout 3,"This is a line of text"
  3172.  
  3173. then the Bourne Shell command "rexx foo 3>foobar" will write a line of
  3174. text to the file foobar.
  3175.  
  3176. This call is equivalent to STREAM(stream,'c','fdopen' [mode] [,fd]) and
  3177. may be deleted in future releases.
  3178.  
  3179. FILENO(stream)
  3180.  
  3181. The result of this function is the file desriptor number associated with
  3182. the named stream, or -1 if that could not be determined (for example, the
  3183. stream is not open).  This function may be used to pass file descriptors
  3184. on to shell commands, for instance as in "cat <&7".
  3185.  
  3186. This call is equivalent to STREAM(stream,'c','fileno') and may be
  3187. deleted in future releases.
  3188.  
  3189. FTELL(stream)
  3190.  
  3191. The result of this function is the current file pointer associated with
  3192. the given stream (with 1 meaning the beginning), that can be used as a
  3193. position parameter to the charin or charout calls.  If that could not
  3194. be determined (for example, the stream is a pipe or is not open) then -1
  3195. will be returned.
  3196.  
  3197. NOTE: This is the actual file pointer, not the read or write pointer as
  3198.       stored by REXX (though the answer will probably equal one of those,
  3199.       according as to whether the last operation on the stream was a read
  3200.       or a write).
  3201.  
  3202. This call is equivalent to STREAM(stream,'c','ftell') and may be
  3203. deleted in future releases.
  3204.  
  3205. LINEIN([stream] [,[line] [,count]])
  3206.  
  3207. If stream is supplied, it is read from, otherwise "stdin" is read.  The
  3208. linein function attempts to read a line from the stream, and returns the
  3209. result (with the terminating newline character removed).  If count is
  3210. supplied, it must be zero or one.  If zero, then no read is performed,
  3211. and if one, one line is read.  If an error occurs and no characters have
  3212. been read, then an empty string is returned and the NOTREADY condition
  3213. is raised.  If line is supplied, then the read pointer is seeked to
  3214. that line number (with 1 being the first line of the stream) before
  3215. reading.  If count is zero, then the seek is performed without reading
  3216. any characters.
  3217.  
  3218. If an interruption (^C) occurs during the read, then characters already
  3219. read may be lost.
  3220.  
  3221. NOTE: Seeking by line number is very inefficient, because every
  3222.       character of the stream before that line has to be read (unless the
  3223.       current read pointer is at a known line number less than that
  3224.       requested, in which case only every character between the current
  3225.       read position and the required position need be read).
  3226.  
  3227. LINEOUT([stream] [,[string] [,line]])
  3228.  
  3229. If stream is supplied, it is written to, otherwise stdout is written to.
  3230. If the string is supplied, it is written to the stream and terminated
  3231. with a newline character, otherwise no write is performed.  If line is
  3232. supplied, the write pointer is set to that line number (with 1 being the
  3233. first line) before the write (if any).  The line must not contain any
  3234. newline characters, because these will act as line separators in the
  3235. stream.  To write text containing newline characters, please use charout
  3236. instead.
  3237.  
  3238. If no string and no line number are supplied, then all pending output to
  3239. the stream is flushed, and the write pointer is set to the end of the
  3240. stream.
  3241.  
  3242. The result will be 1 if the line was not successfully written, in which
  3243. case the NOTREADY condition will be raised.  Otherwise the result will
  3244. be zero.
  3245.  
  3246. NOTE: seeking by line number is very inefficient.
  3247.  
  3248. LINES([stream])
  3249.  
  3250. If the named stream, or "stdin" if no stream is named, is a persistent
  3251. stream (or the name of a regular file), then the number of lines
  3252. available for reading will be counted and returned.  Note that this
  3253. implies reading every character remaining in the file, and this should
  3254. be avoided if possible.
  3255.  
  3256. If the stream is a transient stream, then the result will be "1" if
  3257. characters may be read immediately from the stream, and "0" otherwise.
  3258. It is impossible to calculate the exact number of lines in this case.
  3259.  
  3260. If the stream is not already open and does not name a file which can be
  3261. read, then zero will be returned and the NOTREADY condition raised.
  3262.  
  3263. OPEN(file [,[mode] [,stream]])
  3264.  
  3265. The file specified is opened, if possible, and the error code from the
  3266. system call is returned.  If mode is omitted, then the file is opened
  3267. for reading only, otherwise the first character of the mode must be
  3268. "r" (to open for reading), "w" (to open for read/write, with the file
  3269. being created or truncated initially), or "a" (to append, i.e. open for
  3270. read/write with the write pointer at the end of any existing data in the
  3271. file initially).
  3272.  
  3273. This function will not raise the NOTREADY condition, nor will it record
  3274. any error for STREAM() - the stream will remain unopened (or "UNKNOWN")
  3275. if the open fails.  The return code from the call should be checked to
  3276. see whether an error occurred.
  3277.  
  3278. If the stream argument is supplied, then any future reference to the
  3279. open file will use this as the stream name - otherwise the filename
  3280. (exactly as specified in the open function call) will be used.
  3281.  
  3282. If a stream argument is supplied which already refers to an open file,
  3283. then that will be closed and the new file will be opened on the same
  3284. descriptor.  The standard input, output or error may be redirected by
  3285. calling open with 'stdin', 'stdout' or 'stderr' as the stream argument.
  3286.  
  3287. This call is equivalent to STREAM(stream,'c','open' [mode][,file]) and
  3288. may be deleted in future releases.
  3289.  
  3290. PCLOSE(stream)
  3291.  
  3292. This function must be used to close any stream which was opened by the
  3293. popen function.  The result will be the error code from the pclose system
  3294. call, which will in turn be the exit code of the command being run at the
  3295. other end of the pipe if the pipe was closed successfully or -1 if not.
  3296. A result of -1 may mean that the given stream was not opened with popen.
  3297.  
  3298. This function will not raise the NOTREADY condition, nor will it record
  3299. any error for STREAM().
  3300.  
  3301. This call is equivalent to STREAM(stream,'c','pclose') and may be
  3302. deleted in future releases.
  3303.  
  3304. POPEN(command [,[mode] [,stream]])
  3305.  
  3306. A Bourne Shell is started off in the background to run the given command
  3307. with a one-way pipe leading from or to it.  If the mode is omitted, or
  3308. starts with the letter R, then the output of the command may be read
  3309. from the pipe.  If a mode starting with the letter W is given, then the
  3310. input of the command may be written down the pipe.
  3311.  
  3312. NOTE: Care must be taken when opening pipes for writing, because if the
  3313.       command fails or terminates unexpectedly then the Rexx program
  3314.       will receive a SIGPIPE and terminate.  To counter this see OPTIONS
  3315.       'SIGPIPE' and always check for the NOTREADY condition when writing
  3316.       down the pipe.
  3317.  
  3318. The return value from popen will be zero if the pipe was opened
  3319. successfully, or an error number if not.  Note that the pipe may still
  3320. be opened successfully even if the command can not be executed: it
  3321. is the Bourne Shell's job to report that the command can not be executed.
  3322. The return code from the shell can be obtained with the pclose function.
  3323.  
  3324. This function will not raise the NOTREADY condition, nor will it record
  3325. any error for STREAM().
  3326.  
  3327. If the stream argument is supplied, then any future reference to the pipe
  3328. will use this as the stream name - otherwise the command in full will be
  3329. used.
  3330.  
  3331. If a stream argument is supplied which already refers to an open
  3332. stream, then that will be closed after the pipe has been successfully
  3333. opened.  This means that the pipe will be opened on a different
  3334. descriptor, and the popen function should not be used to redirect the
  3335. standard input, output or error.
  3336.  
  3337. The pipe should be closed with the pclose function so that the shell
  3338. process may be removed from the process table.  If that is not done,
  3339. then defunct processes will remain until REXX exits.  This may be
  3340. acceptable for a small number of popen calls, but not if the REXX
  3341. program calls popen many times or is long-lived.
  3342.  
  3343. Example: the following program outputs in hex, using an "od" process:
  3344.  
  3345.     output= "/bin/od -x"
  3346.     call popen output,"w"
  3347.     call lineout output,"This is some sample output"
  3348.     call pclose output
  3349.  
  3350. This call is equivalent to STREAM(stream,'c','popen' [mode][,command])
  3351. and may be deleted in future releases.
  3352.  
  3353. STREAM(stream[,[option][,command]])
  3354.  
  3355. This function provides miscellaneous operations on the named stream.
  3356. The first character of the option must be "C", "D" or "S" (in upper or
  3357. lower case), if the option is given.  If the option is omitted, then
  3358. "S" is assumed.  The command parameter must be given if and only if the
  3359. option is "C".
  3360.  
  3361. Option "S"
  3362.  
  3363. The function returns the status of the stream as one of the following
  3364. strings:
  3365.  "READY"     - the stream is ready for input or output.
  3366.  "NOTREADY"  - the stream is not ready; usually this indicates that the
  3367.                end of the file was reached.
  3368.  "ERROR"     - an I/O error has occurred.
  3369.  "UNKNOWN"   - the stream has not been accessed.
  3370.  
  3371. Option "D"
  3372.  
  3373. The function returns a description of the stream's status.  This will
  3374. be "Ready", "Unknown", or the text of an error which has occurred.
  3375. This option may be used after a NOTREADY condition is trapped, to find
  3376. out what happened to the stream.
  3377.  
  3378. Option "C"
  3379.  
  3380. The function executes the given command on the stream and returns a
  3381. result depending on the command.
  3382.  
  3383. Valid commands in REXX/imc follow.  All command names and mode
  3384. parameters may be given in mixed case, and wherever a comma appears in
  3385. the command, a space is acceptable as long as the parameter before it
  3386. is not omitted.  For example, stream('file','c','Open R /tmp/testfile')
  3387. is a valid call to this function.
  3388.  
  3389.  close      - the named stream is closed and the return value from the
  3390.               system call is returned.  See CLOSE() for details.
  3391.  
  3392.  fdopen [mode][,number] - if the number is given, it is used as a
  3393.               numeric file descriptor and opened on the given stream.
  3394.               Otherwise, the given stream is taken to be a numeric file
  3395.               descriptor and opened.  If the mode is omitted, "r" is
  3396.               assumed.  The return value from the system call is
  3397.               returned.  See FDOPEN() for details.
  3398.  
  3399.  fileno     - the file descriptor corresponding to the given stream is
  3400.               returned.  See FILENO() for details.
  3401.  
  3402.  flush      - the named stream is flushed.  This is similar to calling
  3403.               charout(stream).  The return value is zero on success and
  3404.               -1 on error, which may result if the stream is not open or
  3405.               if a write error occurs on the stream.  If a write error
  3406.               occurs then the NOTREADY condition will be raised.
  3407.  
  3408.  ftell      - the file pointer of the given stream is returned.  See
  3409.               FTELL() for details.
  3410.  
  3411.  open [mode][,file] - if the file name is supplied, it is opened on
  3412.               the given stream.  Otherwise, the given stream is taken
  3413.               to be a file name and opened.  If the mode is omitted,
  3414.               "read" is assumed.  The return value from the system call
  3415.               is returned.  See OPEN() for details.  In addition, the
  3416.               following options are supported for compatibility with
  3417.               OS/2 Object Rexx and Regina, but note that the command
  3418.               "OPEN WRITE" is incompatible because it truncates the file
  3419.               whereas on OS/2 it appends to the file.  Also note that
  3420.               opening a stream for writing currently also implies opening
  3421.               it for reading.
  3422.  open write append  - open the stream for appending.
  3423.  open write replace - truncate and open the stream for writing.
  3424.  open both          - open the stream for reading and appending.
  3425.  open both append   - same as "open both".
  3426.  open both replace  - truncate and open the stream for reading and
  3427.                       writing.
  3428.  
  3429.  pclose     - the stream, which must have been opened by "popen", is
  3430.               closed.  The return value from the system call is
  3431.               returned.  See PCLOSE() for details.
  3432.  
  3433.  persistent - the stream will be treated as a persistent stream.
  3434.               Changing this attribute is not generally a good idea but it
  3435.               might be useful if, for example, you open the floppy disk
  3436.               device and want to seek to a particular block.  Normally
  3437.               the device would be considered a transient stream and
  3438.               seeking would not be allowed on it.
  3439.  
  3440.  popen [mode][,command] - if the command is supplied, a Bourne shell is
  3441.               started up to execute it.  Otherwise, the given stream
  3442.               name is assumed to be a command and the shell is started
  3443.               up to execute that.  A pipe is opened from the shell to
  3444.               the given stream.  If the mode is omitted, "r" is
  3445.               assumed.  The return value from the system call is
  3446.               returned.  See POPEN() for details.
  3447.  
  3448.  query <info> - the requested information is returned as detailed below.
  3449.               The return value will be the empty string unless the first
  3450.               argument of the STREAM function names either an open stream
  3451.               or an existing file on the system.  The <info> is one of
  3452.               the following words.
  3453.     datetime - returns the last modification time of the file in the
  3454.               format mm-dd-yy hh:mm:ss.  This function is deprecated in
  3455.               favour of "timestamp" since it only returns a two-digit
  3456.               year.
  3457.     exists -  returns a canonical name for the file (or, as detailed
  3458.               above, an empty string if the file does not exist).  If the
  3459.               stream refers to a file whose full path name can be found,
  3460.               the return value will be this name.  Otherwise the return
  3461.               value will be either a partial path name for the file, if
  3462.               one is known, or the same as the stream name.
  3463.     handle -  returns the file descriptor corresponding to the stream
  3464.               if it is currently open, otherwise an empty string (very
  3465.               similar to the "fileno" stream command).
  3466.     size   -  returns the size of the file in bytes, if it is a regular
  3467.               file.  Zero is returned if the file exists but is not a
  3468.               regular file.
  3469.     streamtype - returns "UNKNOWN" if the stream is not currently open,
  3470.               otherwise "PERSISTENT" or "TRANSIENT" as appropriate to the
  3471.               type of stream.
  3472.     timestamp - returns the last modification time of the file in the
  3473.               format yyyy-mm-dd hh:mm:ss.
  3474.  
  3475.  transient -  the stream will be treated as a transient stream (see the
  3476.               "persistent" command).
  3477. _________________________________________________________________________
  3478.  
  3479. The REXX Stack
  3480.  
  3481. The REXX stack is implemented by a stack process, with which the
  3482. interpreter communicates by means of a socket. The PUSH, QUEUE, and PULL
  3483. instructions and the QUEUED() function all communicate with the stack
  3484. process.
  3485.  
  3486. If a stack exists, then the standalone program rxstack may be used to
  3487. stack or retrieve data. This can be used to communicate to rexx the
  3488. output of a command (for instance "ls -al | rxstack") or to input data
  3489. from rexx (for instance "rxstack -print > /tmp/file"). The invocation
  3490. syntax of this program is:
  3491.  
  3492. rxstack [-fifo|-lifo] [-print|-pop|-peek|-drop|-num|-string "data"]
  3493.  
  3494. The meaning of these flags is as follows:
  3495.    -fifo   stack in FIFO order (the default)
  3496.    -lifo   stack in LIFO order
  3497.    -print  empty the stack, outputting each item on standard output
  3498.    -pop    pop one item and output on standard output
  3499.    -peek   output the first item on standard output without deleting it
  3500.    -drop   discard one item
  3501.    -num    output the number of items currently stacked on standard
  3502.            output in decimal, followed by newline character
  3503.    -string interpret the next argument as a literal string to be stacked
  3504. If none of the above flags (except -fifo or -lifo) is specified, then
  3505. each line of standard input is stacked until an EOF is received.
  3506.  
  3507. Each stack item may contain arbitrary characters, including newline
  3508. characters, but when rxstack takes input from standard input, all
  3509. newline characters are taken to be item separators and are deleted
  3510. before each item is stacked. Similarly, when rxstack outputs stack items
  3511. each item is followed by a newline character.
  3512.  
  3513. The name of the socket used for communication is stored in the
  3514. environment variable RXSTACK. It is assumed that a stack exists if and
  3515. only if this variable exists. Multiple processes may share the same stack
  3516. but multiple users may not usually share one stack because the sockets
  3517. for each user are kept in a separate protected directory belonging to
  3518. that user.
  3519.  
  3520. When REXX is invoked, if no stack exists then one is created, and is
  3521. destroyed when REXX exits. If a stack exists then REXX uses that stack.
  3522.  
  3523. The program rxque may be used to create a stack process independently of
  3524. REXX (for instance, so that REXX need not create one on startup, or so
  3525. that stack data may persist across invocations of REXX). This is done
  3526. by the program rxque. It may be invoked in three different ways:
  3527.  
  3528. rxque
  3529.    starts a stack process in the background and outputs two environment
  3530.    variables to stdout in the format
  3531.    RXSTACK=<name> RXSTACKPROC=<number>
  3532.    where RXSTACKPROC is the process number of the stack, which must be
  3533.    killed when the stack is no longer needed. To avoid unwanted processes
  3534.    being left around when errors occur, rxque will terminate itself if it
  3535.    finds that its parent process no longer exists when it has been
  3536.    sleeping for five minutes without communication.
  3537.    
  3538.    This output can either be parsed by a controlling program or used
  3539.    directly by a shell, for instance by:
  3540.    eval `rxque`;export RXSTACK RXSTACKPROC
  3541.  
  3542. rxque -csh
  3543.    is similar to the above but outputs two setenv commands in a format
  3544.    acceptable for the c-shell, so that
  3545.    eval `rxque -csh`
  3546.    will set the environment variables correctly in the c-shell.
  3547.  
  3548. rxque <filename>
  3549.    starts a stack process in the background which uses <filename> as the
  3550.    communication socket. This file will be deleted if it exists, before
  3551.    the socket with that name is opened. The process number of the stack
  3552.    process will be output to stdout, followed by a newline.
  3553.  
  3554. For instance:
  3555. % eval `rxque -csh`
  3556. % ls -al | rxstack -lifo
  3557. % rxstack -num
  3558. 45
  3559. % rxstack -print
  3560. [many lines deleted]
  3561. drwxr-xr-x 13 imc          1536 Oct 28 16:56 ..
  3562. drwx------  5 imc          1024 Oct 28 13:12 .
  3563. total 194
  3564. % kill $RXSTACKPROC
  3565. % unsetenv RXSTACK
  3566. % rxstack
  3567. RX Stack not found
  3568. _________________________________________________________________________
  3569.  
  3570. Error Messages
  3571.  
  3572. As far as is possible, this interpreter conforms to the standard
  3573. numbering system for error messages. Messages which may be produced by
  3574. this interpreter are as follows (explanations are omitted when the
  3575. meaning is obvious):
  3576.  
  3577. Failure returns (negative)
  3578.  
  3579. -3 Error loading program
  3580.    A message indicating the reason will usually be displayed
  3581.    immediately before this message.
  3582.    
  3583. -1 Initialisation error
  3584.    A failure in some essential service, such as not being able to start
  3585.    up the stack process.  Alternatively, some error occurred while
  3586.    processing the commandline arguments (in which case an explanation
  3587.    follows the message text).
  3588.  
  3589. Standard REXX errors (1-50)
  3590.  
  3591.  4 Program interrupted
  3592.    Control-C has been typed, or a SIGHUP or SIGTERM signal has been
  3593.    received.
  3594.  
  3595.  5 Machine storage exhausted
  3596.  
  3597.  6 Unmatched '/*' or quote
  3598.    (this is reported as the program is loaded, before execution. The line
  3599.    number given corresponds to the start of the string or comment which
  3600.    is unterminated. Alternatively, the error may occur during an
  3601.    INTERPRET instruction, in which case the INTERPRET instruction itself
  3602.    is named. This also applies to errors 13 and 37).
  3603.    
  3604.  7 Expected WHEN/OTHERWISE
  3605.    Either a SELECT is not followed immediately by a WHEN, or the end of
  3606.    the SELECT structure has been reached, no condition was true, and no
  3607.    OTHERWISE clause is present.
  3608.    
  3609.  8 Unexpected THEN/ELSE
  3610.  
  3611.  9 Unexpected WHEN/OTHERWISE
  3612.  
  3613. 10 Unexpected or unmatched END
  3614.  
  3615. 13 Invalid character in program: [char]
  3616.    The only characters which are allowed in program text (excluding
  3617.    comments and string constants) are spaces, tabs, newlines, the
  3618.    alphanumerics (A-Z, a-z, 0-9) and the symbols:
  3619.             @#.?!_$|&*()-+=^\'";:<,>%/
  3620.    (see also error 6)
  3621.  
  3622. 14 Incomplete DO/SELECT/IF
  3623.    An END is probably missing.
  3624.  
  3625. 15 Invalid binary or hexadecimal string
  3626.  
  3627. 16 Label not found: [label]
  3628.    The target of a SIGNAL (whether explicit or caused by a trap) is
  3629.    missing.
  3630.  
  3631. 17 Unexpected PROCEDURE
  3632.    The PROCEDURE instruction should only be placed directly after the
  3633.    entry point of a function.
  3634.    
  3635. 18 Expected THEN
  3636.  
  3637. 19 String or symbol expected
  3638.    A string or symbol was expected (e.g. after SIGNAL or NUMERIC FORM)
  3639.    but was missing or invalid.
  3640.    
  3641. 20 Symbol expected
  3642.    A symbol was expected (e.g. after PARSE VAR or, optionally, after
  3643.    LEAVE or ITERATE) but was missing or invalid.
  3644.  
  3645. 21 Invalid data on end of clause
  3646.    Extra characters were found when the interpreter expected a line end
  3647.    or a semicolon. In the special case of the END instruction, the symbol
  3648.    (or SELECT) appearing after the END did not match up with the
  3649.    beginning of the structure being ended.
  3650.    
  3651. 24 Invalid TRACE request
  3652.  
  3653. 25 Invalid subkeyword found
  3654.    In an instruction such as NUMERIC which requires a subkeyword (e.g.
  3655.    NUMERIC DIGITS, etc), that subkeyword was missing or invalid.
  3656.    
  3657. 26 Invalid whole number
  3658.    A function call or an instruction required an integer expression, but
  3659.    either a non-integer or an out-of-range number was supplied.  The
  3660.    magnitude of a whole number should not exceed 1999999999.
  3661.    
  3662. 27 Invalid DO syntax
  3663.  
  3664. 28 Invalid LEAVE or ITERATE
  3665.    A symbol specified after LEAVE or ITERATE was either invalid or did
  3666.    not correspond to an active loop, or there is no loop currently
  3667.    active.
  3668.    
  3669. 30 Symbol > [nnn] characters
  3670.    A variable name exceeded the implementation limit.
  3671.  
  3672. 31 Name starts with number or '.'
  3673.    The name in this case will be a symbol which is being given a value in
  3674.    an attempted assignment.
  3675.    
  3676. 35 Invalid expression
  3677.    A syntax error occurred during the evaluation of an expression. This
  3678.    error also sometimes results when an expression is missing.
  3679.    
  3680. 36 Unmatched '('
  3681.  
  3682. 37 Unexpected ',' or ')'
  3683.    When reported during loading or before interpreting a string (see
  3684.    error 6), this means that a comma occurred at the end of a line
  3685.    which has no successor. At other times, it means that either an
  3686.    unmatched right parenthesis was found or that a comma was found in
  3687.    an inappropriate position (such as in SAY 1,2)
  3688.    
  3689. 38 Invalid template
  3690.    A PARSE instruction has invalid syntax.
  3691.  
  3692. 39 Evaluation stack overflow (> [nn] pending operations)
  3693.    An expression was too complex to evaluate.  This usually only occurs
  3694.    if there is a large number of successive prefix operations, such as
  3695.    in: say ++++++++++++++++++++++++++++1.
  3696.  
  3697. 40 Incorrect call to routine
  3698.    A call to a function or subroutine specified the wrong number of
  3699.    parameters, or missed out a mandatory parameter, or supplied an
  3700.    inappropriate parameter for the function.
  3701.  
  3702. 41 Bad arithmetic conversion
  3703.    An arithmetic operator was used on a string which is not a number.
  3704.    
  3705. 42 Arithmetic overflow or underflow
  3706.  
  3707. 43 Routine not found: [name]
  3708.  
  3709. 44 Function did not return data
  3710.    When the caller of a function discovers that it did not return
  3711.    anything, this error is raised.
  3712.  
  3713. 45 No data specified on function RETURN
  3714.    When a Rexx program or subroutine was called as a function, RETURN
  3715.    must be followed by an expression or the RETURN instruction will
  3716.    raise this error.
  3717.  
  3718. 47 Unexpected label
  3719.    A label was present in the expression following INTERPRET.
  3720.  
  3721. 48 Failure in system service
  3722.    This indicates either that a communication error occurred whilst
  3723.    dealing with the stack, or that an error occurred whilst trying to
  3724.    load a ".rxfn" file to call an external function.
  3725.    
  3726. 49 Implementation error
  3727.    The REXX interpreter has discovered a bug in itself, since some
  3728.    internal structure is inconsistent.  Naturally, you will never see
  3729.    this message. ;-)
  3730.  
  3731. Implementation-defined errors (80-99)
  3732.  
  3733. 80 No-value error
  3734.    This is the value to which the special variable rc is set when a
  3735.    SIGNAL ON NOVALUE trap is activated.
  3736.  
  3737. 81 Use of an un-implemented feature!
  3738.  
  3739. 82 Syntax error
  3740.    A syntax error has been discovered which cannot be described by any
  3741.    of the other messages (This message should never appear except when
  3742.    a LOCAL feature is being used).
  3743.  
  3744. 83 Label ends with '.'
  3745.    (this error is reported as the program is read in)
  3746.    Labels ending with '.' are disallowed since a program containing
  3747.    such a label may be unaware that foo.(3) is not a call to the
  3748.    function "foo." but a reference to a compound symbol.
  3749.    
  3750. 84 Too many arguments (> [nn])
  3751.    A call to a function or subroutine specified too many actual
  3752.    parameters for the interpreter to handle.
  3753.  
  3754. 85 ERROR condition occurred
  3755.    This code is used internally when a "SIGNAL ON ERROR" occurs.
  3756.    You may see this message if the signal handler does not exist.
  3757.  
  3758. 86 FAILURE condition occurred
  3759.    This code is used internally when a "SIGNAL ON FAILURE" occurs.
  3760.    You may see this message if the signal handler does not exist.
  3761.  
  3762. 88 Unexpected '*/'
  3763.    This "error" is no longer used.
  3764.  
  3765. Unix system errors (101-198)
  3766.  
  3767.    These are the error messages which may result from a call to
  3768.    stream() with the "Describe" option.  They are defined by the Unix
  3769.    run-time library, and include such messages as "Permission denied"
  3770.    and "No such file or directory".  The number of the message is just
  3771.    100 plus its usual value in Unix.
  3772.  
  3773. Other I/O errors (100,199-210)
  3774.  
  3775.    These are the error messages which may result from a call to
  3776.    stream() with the "Describe" option and which are provided by the
  3777.    interpreter rather than by the system.
  3778.  
  3779. 100 Unknown error occurred during I/O
  3780.     An error occurred, but the system call failed to set errno to a
  3781.     meaningful value.
  3782.  
  3783. 199 End of file
  3784.  
  3785. 200 File position was out of bounds
  3786.     REXX level 4.00 does not allow you to use charin or linein to point
  3787.     to a non-existent character, or to use charout or lineout to point
  3788.     more than one byte beyond the end of file.  If you attempt this,
  3789.     then NOTREADY will be raised with this error.
  3790.  
  3791. 201 Reposition attempted on transient stream
  3792.     REXX does not allow you to reposition a stream unless it is a
  3793.     persistent stream (i.e., a regular file).  Repositioning on a pipe
  3794.     or tty is not allowed and will raise NOTREADY with this error.
  3795.  
  3796. 202 Write attempted on a read-only stream
  3797.     This error occurs if you try to write to stdin, or to any stream
  3798.     which was opened via the stream function without a name in read
  3799.     mode (for instance, with popen or fdopen).
  3800. _________________________________________________________________________
  3801.