home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rximc175.zip / rexx.tech < prev    next >
Text File  |  2002-08-06  |  82KB  |  1,534 lines

  1. The REXX/imc Technical Reference
  2.  
  3. This reference contains information for programmers of functions,
  4. subcommand interfaces and other utilities to be called by or to call
  5. the Rexx interpreter.
  6.  
  7. Information for Rexx programmers can be found in rexx.summary, rexx.info and
  8. rexx.ref.
  9. ______________________________________________________________________________
  10.  
  11. 1. The Application Programming Interface
  12.  
  13. REXX/imc has an implementation of the "SAA API" based on that of OS/2.  This
  14. API is at present partially implemented and "mostly" compatible with OS/2,
  15. but it will be standardised and completed in a future release.
  16.  
  17. Programs using the API are typically written in C. The supplied header file
  18. and the descriptions below use C declarations to describe the available
  19. functions and their parameters.
  20.  
  21. The API allows an application to start the REXX interpreter under program
  22. control, to add subcommand environments and external functions, to access
  23. the REXX variable pool, and to install system exits to process certain
  24. interpreter activities.
  25.  
  26. A C program using the API should include the header file "rexxsaa.h".
  27. Before including this file, the program should define appropriate
  28. preprocessor symbols to indicate which parts of the API are required.
  29. By default, the header file includes only enough information for the
  30. application to start the interpreter.  The symbols which may be defined
  31. are:
  32.  
  33.    INCL_RXSUBCOM     include definitions for the subcommand interface
  34.    INCL_RXSHV        include definitions for the variable pool interface
  35.    INCL_RXFUNC       include definitions for the external function interface
  36.    INCL_RXSYSEXIT    include definitions for the system exit interface.
  37.  
  38. If all of the above are required, the program may just define:
  39.  
  40.    INCL_REXXSAA      include definitions for the whole API.
  41.  
  42. When an application is compiled, it should be linked with the REXX/imc
  43. library using the compiler flag "-lrexx".  The compiler may need to be
  44. told the location of the library file using the "-L/path/" flag.  Either
  45. a statically linked library or a dynamically linked library may be used.
  46. Details of how to make the libraries are contained in the installation
  47. instructions for REXX/imc.
  48.  
  49. 1(a). RXSTRINGs
  50.  
  51. The rexxsaa.h header file defines the RXSTRING datatype as follows to
  52. hold a REXX string:
  53.  
  54.    typedef struct {
  55.            ULONG strlength;     /* length of the string */
  56.            char *strptr;        /* pointer to the string */
  57.    } RXSTRING;
  58.  
  59.    typedef RXSTRING *PRXSTRING; /* a pointer to an RXSTRING */
  60.  
  61. All the API functions which deal with REXX strings use this structure.
  62. Any RXSTRING which has a value will have the strptr field set to a valid
  63. character pointer and the strlength field set to a length value.  The
  64. empty string is represented by having the strlength field set to zero.
  65. An RXSTRING may be NULL, in which case the strptr field will be set to
  66. a NULL pointer.  This represents an undefined string, for example the
  67. second parameter in the function call foo(1,,2), and is not the same
  68. as an empty string, for example the second parameter in the function
  69. call foo(1,'',2).
  70.  
  71. Associated with the RXSTRING structure are the following helper macros:
  72.  
  73.    MAKERXSTRING(rxstring,ptr,len)
  74.                        - sets the strptr field of the string to the given
  75.                          a pointer and the strlength field to the given
  76.                          length.
  77.    RXNULLSTRING(x)     - returns true if x is a NULL string.
  78.    RXSTRLEN(x)         - returns the length of the string x.  This function
  79.                          returns zero if x is a NULL string.
  80.    RXSTRPTR(x)         - returns the strptr field of the string x.
  81.    RXVALIDSTRING(x)    - returns true if x is neither NULL nor of length zero.
  82.    RXZEROLENSTRING(x)  - returns true if x is not NULL but is of length zero.
  83.  
  84. Note that since these are macros they should not be trusted with arguments
  85. that have side-effects.
  86.  
  87. 1(b). Starting the REXX interpreter
  88.  
  89. The function RexxStart invokes the interpreter to execute a REXX program.
  90.  
  91.    long RexxStart(long argc,
  92.                   PRXSTRING argv, 
  93.                   PSZ *name,
  94.                   PRXSTRING instore,
  95.                   PSZ envname,
  96.                   long calltype,
  97.                   PRXSYSEXIT exits,
  98.                   PSHORT rc,
  99.                   PRXSTRING result);
  100.  
  101. The parameters are:
  102.  
  103.    argc:    the number of arguments passed to the program
  104.    argv:    an array of argc RXSTRINGs containing the arguments passed to
  105.             the program.  Any omitted arguments should be passed as NULL
  106.             strings.
  107.    name:    a name for the program.  This will usually be the file name of
  108.             the program on disk (which will be searched for in the usual
  109.             way as described in the REXX programming reference, but will
  110.             not have any file extension added to it).  However, if the
  111.             instore parameter contains the source of the program, then the
  112.             name parameter is used only for the PARSE SOURCE instruction.
  113.    instore: either NULL or a pointer to the first of two RXSTRINGs which
  114.             define an in-storage REXX program.  If instore is NULL, then the
  115.             program is loaded from a disk file named by the name parameter.
  116.             Otherwise, instore[0] must be a valid RXSTRING which contains
  117.             the source to be executed and instore[1] must be a NULL string.
  118.             The source contained in instore[0] should be in the same format
  119.             as it would be if it had just been loaded from disk.  Note that
  120.             REXX/imc will not, at present, return a tokenised image of the
  121.             program in instore[1].
  122.    envname: either NULL or a null-terminated string which contains the name
  123.             of the initial subcommand environment for the REXX program.  The
  124.             environment name must be at most 30 characters in length.  If
  125.             envname is NULL then a default will be chosen.  This will be
  126.             the uppercased file extension, if this is present and suitable,
  127.             otherwise the string "UNIX".
  128.    calltype:one of the three integer values RXCOMMAND, RXSUBROUTINE
  129.             or RXFUNCTION as defined in rexxsaa.h.  This determines
  130.             the invocation method as given by the instruction
  131.             "PARSE SOURCE . method .".  In addition, if the calltype
  132.             is RXFUNCTION then any RETURN instruction which causes the
  133.             program to end will be required to return a result.
  134.    exits:   either NULL or a pointer to the first in an array of RXSYSEXIT
  135.             structures defining the exits which will be used (see the
  136.             section on system exits for more information).  The last item
  137.             in the array must have an exit code of RXENDLST.  Exits will
  138.             not be used if the exits parameter is NULL.
  139.    rc:      a pointer to a short which will receive the numeric form of the
  140.             result string.  If the result string is a whole number in the
  141.             range -32767 to +32767 then it will be converted to an integer
  142.             and stored in rc.  Otherwise, rc will be set to (short)(1<<15),
  143.             but note that this is an extension which is present in REXX/imc
  144.             only.  This parameter is documented as PLONG, but it seems to be
  145.             PSHORT in most versions so for the time being it is a PSHORT in
  146.             REXX/imc.
  147.    result:  a pointer to an RXSTRING which will receive the result string
  148.             returned by a RETURN or EXIT instruction from the REXX program,
  149.             or NULL to indicate that the return value should be discarded.
  150.             If the program did not return a result, then this parameter
  151.             will be set to a NULL string.  If result points to an RXSTRING
  152.             then the caller of RexxStart may set it to either a NULL string
  153.             or a valid string.  If result is a valid string which is long
  154.             enough to hold the result, then the result will be copied into
  155.             that string and result->strlength will be set to indicate its
  156.             length.  Otherwise, REXX will allocate (using malloc) a string
  157.             to hold the result and the caller of RexxStart is responsible
  158.             for freeing this storage.
  159.  
  160. The possible return values from RexxStart are:
  161.  
  162.    negative:  a syntax error (or other REXX error) occurred.  The absolute
  163.               value of the return value will be the same as the REXX error
  164.               number.
  165.    zero:      the program ended normally.
  166.    positive:  some error occurred which made it impossible to execute the
  167.               program.  A return value of 3 means that the program could not
  168.               be read in (although this number may change in the future).  A
  169.               return value of 1 means that the parameters were incorrect or
  170.               that the interpreter could not initialise properly.
  171.  
  172. Note that the interpreter will never return a result string to the caller
  173. if an error occurred, and in this case the value of rc is undefined when
  174. RexxStart returns.
  175.  
  176. RexxStart is recursive - that is, the application may call it from within
  177. a subcommand handler, external function call or system exit even though a
  178. previous call to RexxStart has still not finished.  It is not, however,
  179. re-entrant, so if the operating system supports threads or lightweight
  180. processes (LWPs), the SAA API should only be called from within a single
  181. thread.
  182.  
  183. 1(c). The Subcommand Interface
  184.  
  185. A subcommand handler is a function supplied by the application which
  186. processes commands (that is, REXX instructions which consist only of
  187. expressions, or occurrences of "command" in instructions of the form
  188. "ADDRESS environment command").  Each subcommand handler must be registered
  189. under an environment name, and these names are selected by the ADDRESS
  190. instruction in REXX.
  191.  
  192. A subcommand handler must be declared as a function with the following
  193. prototype:
  194.  
  195.    ULONG command_handler(
  196.       PRXSTRING command,
  197.       PUSHORT flags,
  198.       PRXSTRING result);
  199.  
  200. where:
  201.  
  202.    command  is the command string created by REXX.  The character just
  203.             after the end of the string is guaranteed to be a null, but
  204.             the command may also contain other null characters.
  205.    flags    is a pointer to a short integer to receive the completion status
  206.             of the command.  The subcommand handler should set this to one
  207.             of RXSUBCOM_OK, RXSUBCOM_ERROR or RXSUBCOM_FAILURE in order to
  208.             indicate that the command completed successfully, completed with
  209.             ERROR status, or completed with FAILURE status respectively.
  210.    result   is a pointer to an RXSTRING which will receive the return
  211.             code from the command in the form of a string (note that any
  212.             numeric return code must be converted to a string before it
  213.             can be passed to REXX).  This string will be assigned to the
  214.             variable RC when the subcommand handler returns.  If result
  215.             is a NULL string, then REXX will assign the string "0" to RC.
  216.  
  217.             REXX will set result to a 256-byte string before calling the
  218.             subcommand handler.  The handler may store the result in this
  219.             string (and set result->strlength to the length of the string),
  220.             or (if the result is longer than that) it may allocate another
  221.             using malloc.  If the handler allocates a new string to hold
  222.             the result, then REXX will call free to release the storage
  223.             after the handler returns.
  224.  
  225. The only valid return value from a subcommand handler seems to be 0.
  226.  
  227. The following functions are available to register, deregister and query
  228. subcommand handlers:
  229.  
  230. ULONG RexxRegisterSubcomExe(
  231.    PSZ envname,
  232.    RexxSubcomHandler *handler,
  233.    PUCHAR userarea);
  234.  
  235.    The RexxRegisterSubcomExe function registers the subcommand handler
  236.    whose address is given by the parameter handler under the environment
  237.    name given by the parameter envname.
  238.  
  239.    The userarea parameter may be NULL or it may point to a user-defined
  240.    eight byte area of memory which will be associated with the subcommand
  241.    handler.  The user area information may be retrieved with the
  242.    RexxQuerySubcom function.
  243.  
  244.    The possible return values from RexxRegisterSubcomExe are:
  245.  
  246.    RXSUBCOM_OK        The handler was registered.
  247.    RXSUBCOM_NOTREG    The handler was not registered because there was
  248.                       another already registered under the same name.
  249.    RXSUBCOM_NOEMEM    The handler was not registered due to lack of
  250.                       memory.
  251.    RXSUBCOM_BADTYPE   The handler was not registered due to a parameter
  252.                       error.
  253.  
  254. ULONG RexxDeregisterSubcom(PSZ envname, PSZ module);
  255.  
  256.    The RexxDeregisterSubcom function deregisters the subcommand handler
  257.    which was registered under the name given by the parameter envname.
  258.    The module parameter is not used by REXX/imc.
  259.  
  260.    The possible return values from RexxDeregisterSubcom are:
  261.  
  262.    RXSUBCOM_OK        The handler was deregistered.
  263.    RXSUBCOM_NOTREG    The handler was not found.
  264.    RXSUBCOM_BADTYPE   The handler was not deregistered due to a parameter
  265.                       error.
  266.  
  267. ULONG RexxQuerySubcom(PSZ envname, PSZ module, PUSHORT flag, PUCHAR userarea);
  268.  
  269.    The RexxQuerySubcom function queries any subcommand handler which might
  270.    have been registered under the name given by the parameter envname.  The
  271.    module parameter is not used by REXX/imc.  The result is both stored in
  272.    the short integer pointed to by the flag parameter and returned as the
  273.    result of the function.  If the userarea parameter is supplied, it must
  274.    point to an eight-byte area which will receive the user area which was
  275.    given when the subcommand handler was registered.
  276.  
  277.    The possible return values from RexxQuerySubcom are:
  278.  
  279.    RXSUBCOM_OK        The handler is registered.
  280.    RXSUBCOM_NOTREG    The handler is not registered.
  281.    RXSUBCOM_BADTYPE   The parameters were in error.
  282.  
  283. 1(d). External Functions
  284.  
  285. An external function may be registered with REXX/imc using the SAA API.
  286. After it has been registered, it may be called by a Rexx program as usual,
  287. but only using the name under which it was registered.  The names of
  288. functions are case-sensitive and unquoted function names are always
  289. translated into upper case, so that a function to be called with the REXX
  290. function call foo() must be registered under the name FOO.  This is a
  291. difference from OS/2.  Functions registered using the SAA interface of
  292. REXX/imc are searched just after the built-in functions, and at the same
  293. time as functions loaded from ".rxfn" files (see section 2).  Function names
  294. registered under the SAA interface of REXX/imc must not contain the slash
  295. character (/).  Note that function names in REXX function calls have all
  296. characters up to and including the last slash character removed before they
  297. are matched against function names which have been loaded from ".rxfn" files
  298. or registered under the SAA interface, so that "/tmp/FOO" matches a
  299. function registered under the name "FOO".  [This was done so that the path
  300. name of an auto-registering function may be specified, but will not
  301. prevent the function from being found on subsequent calls when it has
  302. already been registered.  This behaviour might be removed in a future
  303. release.]
  304.  
  305. An external function to be registered using the SAA interface must be a
  306. function with the following prototype:
  307.  
  308.    LONG function_handler(
  309.       PSZ name,
  310.       long argc,
  311.       PRXSTRING argv,
  312.       PSZ queuename,
  313.       PRXSTRING result);
  314.  
  315. where:
  316.  
  317.    name      is a null-terminated string giving the name by which REXX
  318.              called the function.
  319.    argc      is the number of arguments passed to the function.
  320.    argv      is an array of argc RXSTRINGs giving the arguments passed to
  321.              the function.  Any omitted arguments will be passed as NULL
  322.              strings.  The character just after the end of each argument
  323.              which is present is guaranteed to be a null, but the arguments
  324.              may also contain other null characters.
  325.    queuename is the null-terminated name of the current queue, which is
  326.              currently meaningless in REXX/imc and will equal the string
  327.              "SESSION".
  328.    result    is a pointer to an RXSTRING which will receive the result from
  329.              the function.  If the function does not return a result, then
  330.              it should set this RXSTRING to a NULL string.  If the function
  331.              handler was called as a function, then the result will be used
  332.              directly (and an error will be raised if the function did not
  333.              return a result).  If it was called as a subroutine, the result
  334.              (if any) will be assigned to the REXX variable RESULT.
  335.  
  336.              REXX will set result to a 256-byte string before calling the
  337.              function.  The function may copy the result into this string
  338.              (and set result->strlength to the length of the result), or
  339.              (if the result is longer than 256 bytes) it may allocate a new
  340.              string using malloc and set the result string to that.  If the
  341.              function handler allocates a new string, REXX will use free to
  342.              release it when the function returns.
  343.  
  344. The valid return values from a function handler are:
  345.  
  346.      0    The function completed successfully.
  347.     40    An error occurred.  The REXX interpreter will raise error 40
  348.           (incorrect call to routine) when the function returns.  Note
  349.           that if the function returns this value, it must not return a
  350.           result.
  351.  
  352. The following functions are available to register, deregister and query
  353. external functions:
  354.  
  355. ULONG RexxRegisterFunctionExe(PSZ funcname, RexxFunctionHandler *handler);
  356.  
  357.    The RexxRegisterFunctionExe function registers the function given by
  358.    the handler parameter under the name given by the funcname parameter,
  359.    which is a null-terminated string.
  360.  
  361.    The possible return values from RexxRegisterFunctionExe are:
  362.  
  363.    RXFUNC_OK       The function was registered.
  364.    RXFUNC_DEFINED  The function was not registered because it has already
  365.                    been registered or loaded from a ".rxfn" file.
  366.    RXFUNC_NOMEM    The function was not registered due to lack of memory.
  367.  
  368. ULONG RexxRegisterFunctionDll(PSZ funcname, PSZ dllname, PSZ entryname);
  369.  
  370.    The RexxRegisterFunctionDll call registers a function stored in a shared
  371.    object file (or DLL).  The name of the shared object is given in the
  372.    dllname parameter (see below).  The name of the function handler within
  373.    the shared object is given in the entryname parameter, and the name by
  374.    which Rexx will call the function is given by the funcname parameter.
  375.  
  376.    The dllname parameter may be either the exact path name of a file or a
  377.    relative file name which will be searched for along a path given by one
  378.    of the following: the REXXLIB environment variable; if that is not set
  379.    the REXXFUNC environment variable; or if neither is set the compile-time
  380.    default.  If the name of the shared object ends with ".rxfn" then this
  381.    may be omitted from the dllname parameter.
  382.  
  383.    This version of the RexxRegisterFunctionDll function differs from the
  384.    OS/2 version in that it attempts to load the function before returning
  385.    control to the caller, and it returns an indication of whether this
  386.    succeeded.  The possible return values are:
  387.  
  388.    RXFUNC_OK       The function was registered.
  389.    RXFUNC_NOTREG   The function was not registered because the shared object
  390.                    could not be loaded or did not contain the required entry
  391.                    point.
  392.    RXFUNC_DEFINED  The function was not registered because it has already
  393.                    been registered or loaded from a ".rxfn" file.
  394.    RXFUNC_NOMEM    The function was not registered due to lack of memory.
  395.  
  396. ULONG RexxDeregisterFunction(PSZ funcname);
  397.  
  398.    The RexxDeregisterFunction function deregisters the function which was
  399.    previously registered under the name given by the funcname parameter,
  400.    which is a null-terminated string.  Note that this function is also
  401.    able to deregister functions which were loaded from ".rxfn" files.
  402.  
  403.    The possible return values from RexxDeregisterFunction are:
  404.  
  405.    RXFUNC_OK       The function was deregistered.
  406.    RXFUNC_NOTREG   The function was not found.
  407.  
  408. ULONG RexxQueryFunction(PSZ funcname);
  409.  
  410.    The RexxQueryFunction function queries whether or not a function has
  411.    been registered or loaded from a ".rxfn" file under the name given by
  412.    the funcname parameter, which is a null-terminated string.
  413.  
  414.    The possible return values from RexxQueryFunction are:
  415.  
  416.    RXFUNC_OK       The function is registered.
  417.    RXFUNC_NOTREG   The function is not registered.
  418.  
  419. 1(e). System Exits
  420.  
  421. The application may define functions which REXX will call instead of using
  422. its own system interface in certain circumstances, such as whenever it needs
  423. to write out a line as a result of the SAY instruction.  The application
  424. registers its system exit functions under names (which are similar to
  425. environment names, although they occupy a separate name space) before
  426. executing a REXX program.  When the application starts REXX, it specifies
  427. the system exits which it wishes to handle and associates each with a named
  428. exit handler.  Each system exit has a major function code and a subfunction
  429. code; these are listed later in this section.
  430.  
  431. A system exit handler must be a function with the following prototype:
  432.  
  433.    LONG exit_handler(long exitcode, long subcode, PEXIT parmblock);
  434.  
  435. where:
  436.  
  437.    exitcode  is the major function code of the exit which the handler has
  438.              been called to handle.
  439.    subcode   is the subfunction code of the exit which the handler has been
  440.              called to handle.
  441.    parmblock is a pointer to a parameter block whose contents depend on
  442.              the exit being handled.  The exit descriptions below give
  443.              details on the parameter block required for each exit.  Some
  444.              exits may not require a parameter block at all, in which case
  445.              the parmblock parameter will be a NULL pointer.
  446.  
  447.              Since each exit requires a different kind of parameter block,
  448.              the PEXIT data type has been declared as a union data type.  It
  449.              is probably most convenient for each exit handler to convert
  450.              the parameter block pointer into a pointer of the required type
  451.              for the exit (which is allowed in C (I think!)).
  452.  
  453. The valid return values from a system exit handler are:
  454.  
  455.    RXEXIT_HANDLED      The exit handler processed the system exit as required.
  456.    RXEXIT_NOT_HANDLED  The exit handler did not process the system exit, and
  457.                        therefore REXX should behave as if the exit handler
  458.                        had not been called.
  459.    RXEXIT_RAISE_ERROR  An error occurred.  REXX will raise error 48 (failure
  460.                        in system service) when the handler returns this
  461.                        value.
  462.  
  463. A system exit handler should begin by checking the function and subfunction
  464. codes, and return immediately with RXEXIT_NOT_HANDLED if they correspond to
  465. an exit which the handler was not supposed to handle.
  466.  
  467. The following functions are available to register, deregister and query
  468. system exit handlers.
  469.  
  470. ULONG RexxRegisterExitExe(PSZ name, RexxExitHandler *handler, UCHAR *userarea);
  471.  
  472.    The RexxRegisterExitExe function registers the system exit handler given
  473.    by the handler parameter under the name given by the name parameter,
  474.    which is a null-terminated string.
  475.  
  476.    The userarea parameter may be NULL or it may point to a user-defined
  477.    eight byte area of memory which will be associated with the system
  478.    exit handler.  The user area information may be retrieved with the
  479.    RexxQueryExit function.
  480.  
  481.    The possible return values from RexxRegisterExitExe are:
  482.  
  483.    RXEXIT_OK       The handler was registered.
  484.    RXEXIT_NOTREG   The handler was not registered because there is already a
  485.                    system exit handler registered under the given name.
  486.    RXEXIT_NOEMEM   The handler was not registered due to lack of memory.
  487.    RXEXIT_BADTYPE  The handler was not registered due to a parameter error.
  488.  
  489. ULONG RexxDeregisterExit(PSZ name, PSZ module);
  490.  
  491.    The RexxDeregisterExit function deregisters the system exit handler which
  492.    was registered under the name given by the name parameter, which is a
  493.    null-terminated string.  The module parameter is not used by REXX/imc.
  494.  
  495.    The possible return values from RexxDeregisterExit are:
  496.  
  497.    RXEXIT_OK       The handler was deregistered.
  498.    RXEXIT_NOTREG   The handler was not found.
  499.    RXEXIT_BADTYPE  The parameters were in error.
  500.  
  501. ULONG RexxQueryExit(PSZ name, PSZ module, PUSHORT flag, PUCHAR userarea);
  502.  
  503.    The RexxQueryExit function queries any system exit handler which may have
  504.    been registered under the name given by the name parameter, which is a
  505.    null-terminated string.  The module parameter is not used by REXX/imc.
  506.    The flag parameter is a pointer to a short integer which will be set to
  507.    the return value from RexxQueryExit.  If the userarea parameter is not
  508.    NULL, it must point to an eight-byte area of memory which will receive
  509.    the user area which was given when the exit handler was registered.
  510.  
  511.    The possible return values from RexxQueryExit are:
  512.  
  513.    RXEXIT_OK       The handler is registered.
  514.    RXEXIT_NOTREG   The handler is not registered.
  515.    RXEXIT_BADTYPE  The parameters were in error.
  516.  
  517. Once the required system exit handlers have been registered, they may
  518. be used by passing them to RexxStart in the "exits" parameter.  This
  519. parameter is an array of structures of the form:
  520.  
  521.    typedef struct {
  522.       char *sysexit_name;   /* name of exit handler */
  523.       short sysexit_code;   /* major function code of system exit */
  524.    } RXSYSEXIT;
  525.  
  526. Each of these structures associates a system exit handler which was
  527. previously registered under the name given by the sysexit_name field
  528. of the structure with the system exits whose major function codes agree
  529. with the sysexit_code field of the structure.  Note that an exit handler
  530. must handle all the subfunctions of any particular system exit; it may do
  531. this by immediately returning RXEXIT_NOT_HANDLED as described earlier.
  532.  
  533. The last element of the array of RXSYSEXIT structures must have sysexit_code
  534. set to RXENDLST.
  535.  
  536. The possible system exits are as follows.  Each major exit code is given
  537. by a name of the form RXxxx, and each subfunction code is given by a name
  538. of the form RXxxxyyy, where the RXxxx is the same as the major exit code.
  539.  
  540. RXCMD: Call a subcommand handler
  541.  
  542.    RXCMDHST: This exit is called when REXX is about to carry out a command.
  543.              By default, REXX will call the appropriate subcommand handler
  544.              to execute the command, but the exit may instead choose to
  545.              process the command.  The parameter block for this exit is:
  546.  
  547.              typedef struct {
  548.                 struct {
  549.                    unsigned int rxfcfail:1;   /* completed with FAILURE */
  550.                    unsigned int rxfcerr:1;    /* completed with ERROR */
  551.                 } rxcmd_flags;
  552.                 char *rxcmd_address;          /* environment name */
  553.                 unsigned short rxcmd_addressl;/* environment length */
  554.                 char *rxcmd_dll;              /* not used by REXX/imc */
  555.                 unsigned short rxcmd_dll_len; /* not used by REXX/imc */
  556.                 RXSTRING rxcmd_command;       /* the command to be executed */
  557.                 RXSTRING rxcmd_retc;          /* the return string */
  558.              } RXCMDHST_PARM;
  559.  
  560.              The handler may set either rxfcfail or rxfcerr to raise a
  561.              FAILURE or ERROR condition, respectively.  The rxcmd_address
  562.              parameter is the null-terminated name of the environment to
  563.              which the command is being sent.  The rxcmd_command is an
  564.              RXSTRING containing the command to be executed.  The character
  565.              just after the end of the string is guaranteed to be a null,
  566.              but the command may also contain other null characters.  The
  567.              rxcmd_retc is an RXSTRING which is to receive the return code
  568.              from the command as a string.  Any numeric return code must be
  569.              translated into a string before it is returned.  REXX will
  570.              provide a 256-byte buffer into which the return string may
  571.              be copied.  The handler may allocate another using malloc, in
  572.              which case REXX will use free to release it after the handler
  573.              returns.
  574.              
  575. RXSIO: Perform input or output
  576.  
  577.    RXSIOSAY: This exit is called when REXX is about to write a line as a
  578.              result of a SAY instruction.  The exit may choose to deal with
  579.              the line as it requires; otherwise the interpreter will write
  580.              the line to the standard output stream.  The parameter block
  581.              for this exit is:
  582.  
  583.              typedef struct {
  584.                 RXSTRING rxsio_string;
  585.              } RXSIOSAY_PARM;
  586.  
  587.              The rxsio_string is the string to be written out.  The
  588.              character just after the end of the string is guaranteed
  589.              to be a null, but the string may also contain other null
  590.              characters.  The string will not contain an end-of-line
  591.              character unless one was present in the SAY instruction.
  592.  
  593.    RXSIOTRC: This exit is called when REXX is about to write a line during
  594.              tracing.  The exit may choose to deal with the line as it
  595.              requires; otherwise the interpreter will write the line to
  596.              the trace output stream (usually the standard error).  The
  597.              parameter block for this exit is:
  598.  
  599.              typedef struct {
  600.                 RXSTRING rxsio_string;
  601.              } RXSIOTRC_PARM;
  602.  
  603.              The rxsio_string is the string to be written out.  The
  604.              character just after the end of the string is guaranteed
  605.              to be a null.  The string will not contain an end-of-line
  606.              character.
  607.  
  608.    RXSIOTRD: This exit is called when REXX is about to read a line of input
  609.              as a result of the PARSE PULL instruction when the REXX stack
  610.              is empty.  The exit may choose to supply a line of its own;
  611.              otherwise the interpreter will read the line from the standard
  612.              input stream.  The parameter block for this exit is:
  613.  
  614.              typedef struct {
  615.                 RXSTRING rxsiotrd_retc;
  616.              } RXSIOTRD_PARM;
  617.  
  618.              The input line should be returned in the rxsiotrd_retc string.
  619.              It should not contain any end-of-line character which might
  620.              have been used to terminate the line of input (but it may
  621.              contain other end-of-line characters).  REXX will provide a
  622.              256-byte string in which the handler may place the input line.
  623.              The handler may allocate its own using malloc, in which case
  624.              REXX will use free to release it when the handler returns.
  625.  
  626.    RXSIODTR: This exit is called when REXX is about to read a line of input
  627.              at a pause during interactive tracing.  The exit may choose to
  628.              supply a line of its own; otherwise the interpreter will read
  629.              the line from the standard input stream.  The parameter block
  630.              for this exit is:
  631.  
  632.              typedef struct {
  633.                 RXSTRING rxsiodtr_retc;
  634.              } RXSIODTR_PARM;
  635.  
  636.              The input line should be returned in the rxsiotrd_retc string.
  637.              It should not contain any end-of-line character which might
  638.              have been used to terminate the line of input.  REXX will
  639.              provide a 256-byte string in which the handler may place the
  640.              input line.  The handler may allocate its own using malloc, in
  641.              which case REXX will use free to release it when the handler
  642.              returns.
  643.  
  644.    Note: the PARSE LINEIN instruction and the built-in functions LINEIN,
  645.    LINEOUT, CHARIN and CHARS do not call the RXSIO exit handler.
  646.  
  647. RXINI: Initialisation processing
  648.  
  649.    RXINIEXT: This exit is called when initialisation is complete, just
  650.              before execution of the REXX program starts.  The exit handler
  651.              may use this exit to perform initialisation functions such as
  652.              setting REXX variables.  There is no parameter block for this
  653.              exit.
  654.  
  655. RXTER: Termination processing
  656.  
  657.    RXTEREXT: This exit is called just after the REXX program has finished,
  658.              and just before termination processing.  The exit handler
  659.              may use this exit to perform terminatino functions such as
  660.              retrieving REXX variables.  There is no parameter block for
  661.              this exit.
  662.  
  663. 1(f). The Variable Pool Interface
  664.  
  665. Variables in the REXX program may be accessed using the RexxVariablePool
  666. function, which processes one or more request blocks arranged in a linked
  667. list.  Each request is a structure of the form:
  668.  
  669.    typedef struct shvnode
  670.    {
  671.       struct shvnode *shvnext;
  672.       RXSTRING shvname;
  673.       RXSTRING shvvalue;
  674.       ULONG shvnamelen;
  675.       ULONG shvvaluelen;
  676.       UCHAR shvcode;
  677.       UCHAR shvret;
  678.    } SHVBLOCK;
  679.  
  680. where:
  681.  
  682.    shvnext     is the address of the next request block, or NULL if this is
  683.                the last request block.
  684.    shvcode     is the request code.  Valid request codes are listed below.
  685.    shvname     is an RXSTRING containing a REXX variable name.  It may be
  686.                an input or an output parameter according to the request
  687.                code.
  688.    shvnamelen  is the length of the buffer which the shvname RXSTRING points
  689.                to.
  690.    shvvalue    is an RXSTRING containing the value of a REXX variable.
  691.                It may be an input or an output parameter according to the
  692.                request code.
  693.    shvvaluelen is the length of the buffer which the shvvalue RXSTRING points
  694.                to.
  695.    shvret      is a return code which will be set when the request has been
  696.                processed.  It will be set to the OR of zero or more of the
  697.                following flags:
  698.  
  699.                RXSHV_NEWV   the named variable was uninitialised before the
  700.                             request was processed
  701.                RXSHV_LVAR   no more variables are available for an
  702.                             RXSHV_NEXTV request.
  703.                RXSHV_TRUNC  A returned variable name or value was truncated
  704.                             because the supplied RXSTRING was too short to
  705.                             hold the name or value.
  706.                RXSHV_BADN   An invalid variable name was given.
  707.                RXSHV_MEMFL  The request was not processed due to lack of
  708.                             memory.
  709.                RXSHV_BADF   An invalid function code was given.
  710.  
  711. The valid request codes and their meanings are:
  712.  
  713.    RXSHV_SYSET: Symbolic set.  The name given in the shvname field is
  714.                 interpreted as a variable as if it were present in a REXX
  715.                 program.  It is set to the value given in the shvvalue
  716.                 field.
  717.    RXSHV_SET:   Direct set.  The variable whose name matches that given in
  718.                 the shvname field is set to the value given in the shvvalue
  719.                 field.
  720.    RXSHV_SYFET: Symbolic fetch.  The name given in the shvname field is
  721.                 interpreted as a variable as if it were present in a REXX
  722.                 program.  Its value is fetched and stored in the shvvalue
  723.                 RXSTRING.  If the application has set this to a NULL string,
  724.                 then REXX allocates one using malloc.  The application
  725.                 is responsible for freeing this storage.  Otherwise,
  726.                 shvvaluelen gives the maximum length of a string which REXX
  727.                 can store in the shvvalue RXSTRING.  If the value is longer
  728.                 than this then it is truncated.  The RXSHV_TRUNC flag will
  729.                 then be set in shvret.
  730.    RXSHV_FETCH: Direct fetch.  The value of the variable whose name matches
  731.                 that given in the shvname field is fetched and stored in the
  732.                 shvvalue RXSTRING, as in the RXSHV_SYFET request.
  733.    RXSHV_SYDRO: Symbolic drop.  The name given in the shvname field is
  734.                 interpreted as a variable as if it were present in a REXX
  735.                 program.  It is dropped (that is, it becomes undefined).
  736.    RXSHV_DROPV: Direct drop.  The variable whose name matches that given
  737.                 in the shvname field is dropped (that is, it becomes
  738.                 undefined).
  739.    RXSHV_NEXTV: Fetch next variable.  Each time this request is processed
  740.                 the interpreter returns the name and value of a variable
  741.                 which is currently accessible by the executing REXX program.
  742.                 The interpreter keeps track of which variables have been
  743.                 returned, and successive RXSHV_NEXTV requests will return
  744.                 different variables (in no particular order) until all the
  745.                 accessible variables have been returned.  When there is no
  746.                 variable left to return, the RXSHV_NEXTV request will set
  747.                 the RXSHV_LVAR flag in shvret and will leave the returned
  748.                 variable and value undefined.  The information about which
  749.                 variables have been returned is reset every time the REXX
  750.                 program resumes execution, and also at every set, fetch or
  751.                 drop request from the variable pool.
  752.  
  753.                 The name of each returned variable will be stored in the
  754.                 shvname field of the request block.  If the application
  755.                 has set this to a NULL string then REXX allocates one using
  756.                 malloc.  The application is responsible for freeing this
  757.                 storage.  Otherwise, shvnamelen gives the maximum length
  758.                 of a string which REXX can store in the shvname RXSTRING.
  759.                 If the name is longer than this then it is truncated.  The
  760.                 RXSHV_TRUNC flag will then be set in shvret.
  761.  
  762.                 The value of each variable is returned in an analogous
  763.                 manner in the shvvalue field (in exactly the same way as
  764.                 for the RXSHV_SYFET and RXSHV_FETCH requests).
  765.  
  766.                 In the current release of REXX/imc, simple symbols and
  767.                 stems are returned in (approximately) the order in which
  768.                 they became defined.  The compound symbols of any one stem
  769.                 are returned consecutively in a similar order, just after
  770.                 the stem (if any) is returned.  Note that it is in general
  771.                 not possible to tell the difference between a stem being
  772.                 returned (for example, after the instruction foo.=3) and a
  773.                 compound variable whose tail has length zero (for example,
  774.                 after the instructions bar=''; foo.bar=3).  However, if
  775.                 "foo."  is returned after any other variable with that
  776.                 stem (including "foo."  itself), it is always the case
  777.                 that this occurrence of "foo."  is a compound variable.
  778.                 The converse is unfortunately not true.  That is, if
  779.                 "foo."  is the first variable with that stem, it is not
  780.                 necessarily a stem variable unless another copy of "foo."
  781.                 appears, in which case the first one is a stem and the
  782.                 second is a compound variable.
  783.  
  784. A symbolic variable name is one which is interpreted according to REXX
  785. rules.  That is, it must contain only letters, digits, dots, and a small
  786. number of other characters that are valid in symbols and must not start
  787. with a digit or dot; it is uppercased before use, and each simple symbol
  788. component of a compound symbol (except the stem) is replaced by its value
  789. before use.
  790.  
  791. A direct variable name is the exact name of a variable which appears in
  792. the variable pool (and it is the kind of variable name that RXSHV_NEXTV
  793. returns).  It is the kind of name that a symbolic variable name turns into
  794. after it has been processed as described in the above paragraph.  That part
  795. of the name up to the first dot must satisfy the conditions for a symbolic
  796. name and must be in upper case.  After the first dot, the name is allowed
  797. to contain any character.
  798.  
  799. Variable pool requests are processed by the function:
  800.  
  801. ULONG RexxVariablePool(PSHVBLOCK RequestBlockList);
  802.  
  803. The parameter is a pointer to the first request block in the linked list.
  804. The return value may be RXSHV_NOAVL, meaning that the variable pool API is
  805. not available.  In this case, none of the requests will have been processed.
  806. The API is made available just before execution of a program begins (just
  807. before the RXINIEXT exit is called) and may be used until just after the
  808. execution finishes (just after the RXTEREXT exit is called).
  809.  
  810. If the return value is not RXSHV_NOAVL, then it will be the OR of all the
  811. return codes which have been returned individually in the shvret fields of
  812. the request blocks.
  813. ______________________________________________________________________________
  814.  
  815. 2. Writing external functions for REXX/imc
  816.  
  817. There are four ways to write external functions for REXX/imc:
  818.  
  819.   (a) in REXX
  820.   (b) using the SAA application programming interface
  821.   (c) as a ".rxfn" file, and
  822.   (d) as a Unix program.
  823.  
  824. External functions in REXX are covered in the REXX programming reference.
  825. The SAA application programming interface for external functions is covered
  826. in section 1(d).  The remaining methods are described in this section.
  827.  
  828. 2(c). Writing a ".rxfn" file
  829.  
  830. A function written as a ".rxfn" file will be searched for and linked in
  831. with the interpreter at the time when it is first requested.  This gives an
  832. advantage over using the SAA API in that SAA functions must be registered by
  833. the application before they may be used by a REXX program - though this
  834. is made easier by the inclusion of the RxFuncAdd REXX function in the
  835. interpreter.  In general, the function(s) in a ".rxfn" file may either be
  836. SAA function handlers as described above or specially written functions
  837. for REXX/imc.  However, the latter type is the only one supported for
  838. stand-alone functions; files containing only SAA functions must be supplied
  839. as a library with a ".rxlib" file (see section 3).  This is because it is
  840. the ".rxlib" file which tells the interpreter that the functions must be
  841. called using the SAA calling sequence (either that, or a REXX/imc-style
  842. function must use the SAA interface to register all the SAA functions).
  843.  
  844. A ".rxfn" file should be compiled and then linked in the normal way for
  845. shared objects.  This differs between operating systems, but if the "Make"
  846. program knows how to compile shared objects on your system then try making
  847. rxmathfn.rxfn to see what flags it uses.  For a stand-alone function the
  848. name of the output file should be the name by which the function is to
  849. be called with ".rxfn" appended, all in lower case.  If this file is in
  850. the rexx function search order (see the section on function or subroutine
  851. invocation in the REXX/imc programming reference) then the file will be
  852. loaded and linked in with the interprter automatically the first time that
  853. the function is called.  Future calls to the same function will not have to
  854. load the function from a file.
  855.  
  856. The REXX/imc-style function is described in the remainder of this section.
  857. It is not really recommended for new functions because of portability
  858. issues, so skip to the next section if this is not of interest.
  859.  
  860. A REXX/imc function will need access to several of the interpreter's
  861. functions, so its source must include "functions.h".  It may also need
  862. access to certain global variables, in which case it should include
  863. "globals.h".  Useful functions and global variables are listed below.
  864. In addition, the function may call any routine from the API, in which
  865. case it should include "rexxsaa.h" as described in section 1.
  866.  
  867. A REXX/imc function should be declared as:
  868.  
  869.     int rxfunction(char *name, int argc);
  870.  
  871. (including the name rxfunction).  The name parameter gives the name by which
  872. the function was called, excluding any path name.  That is, any part of the
  873. name up to and including the last slash (/) will have been removed.  This
  874. may be used to distinguish between several function calls that have all
  875. been implemented by the same routine (this is more common in a function
  876. library; see the section on function libraries).  The argc parameter gives
  877. the number of arguments which were passed to the function.  These will be
  878. placed on the calculator stack in LIFO order.  Any missing parameters will
  879. have been stacked as strings of length -1.
  880.  
  881. The function will be expected to remove all its parameters from the
  882. calculator stack and either
  883.  
  884.   (i) place a result on the calculator stack and return 1, or
  885.  (ii) return 0 without placing anything on the calculator stack.  This means
  886.       that the function has not returned a result.
  887.  
  888. However, the function may choose to return an error.  In this case, it
  889. need not remove all arguments from the calculator stack.  A valid error
  890. code is a negative number whose absolute value is the number of a REXX
  891. error.  When the function returns, that error will be reported.
  892.  
  893. REXX/imc contains a function declared as follows:
  894.  
  895.    int funccall(RexxFunctionHandler *func,char *name,int argc);
  896.  
  897. This function enables a function that has a REXX/imc-style calling sequence
  898. to call a function that has an SAA-style calling sequence.  For example,
  899. if function_handler is an external function designed for use with the SAA
  900. API, then it can be saved as a REXX/imc-style ".rxfn" file by appending the
  901. following function:
  902.  
  903.    int rxfunction(char *name, int argc)
  904.    {
  905.       return funccall(function_handler,name,argc);
  906.    }
  907.  
  908. This gives the SAA function the advantage of being able to be loaded on
  909. demand instead of having to be registered.
  910.  
  911. A single function stored in a REXX/imc file should not contain a public
  912. symbol called rxdictionary; this is reserved for function libraries.
  913.  
  914. Useful functions, including functions to retrieve arguments and stack the
  915. answer, are the following:
  916.  
  917. char *delete(len)  int *len;
  918.  
  919. Deletes a string from the calculator stack, and returns an address where it
  920. can be found.  On return, len will be set to the length of the argument.
  921. The string is guaranteed to be followed by two bytes of available memory,
  922. so that the application may teminate it with a null character if necessary,
  923. and the string may be written to.  The string is not guaranteed to be
  924. null-terminated when it is unstacked.  The string is not actually moved in
  925. memory, so it will be invalidated whenever the calculator stack is changed
  926. (that means that it may not be used as an argument to stack()).  However,
  927. further calls to delete() will not corrupt the string.
  928.  
  929. int getint(flag)  int *flag;
  930.  
  931. Deletes a string from the calculator stack, interprets it as an integer, and
  932. returns the result.  If the string is not a number which can be held in an
  933. int variable, the function will die.  If the string is not an integer and
  934. the flag is non-zero, the function will die, otherwise the number will be
  935. converted into the nearest integer.
  936.  
  937. void stack(string,len)  char *string; int len;
  938.  
  939. Copies the given string of the given length on to the calculator stack.
  940.  
  941. void stackint(i)  int i;
  942.  
  943. Stacks a string representing the integer i on the calculator stack.
  944.  
  945. int isnull()
  946.  
  947. Returns 1 if the next value to be unstacked is null (that is, it has
  948. length -1 indicating an omitted parameter), and zero otherwise.
  949.  
  950. void die(rc)  int rc;
  951.  
  952. Raise the error whose code is rc.  The interpreter will then either halt
  953. with diagnostics or signal to an appropriate label, according to the current
  954. settings of "SIGNAL ON".  This function never returns to its caller.
  955.  
  956. int num(minus,exp,zero,len)  int *minus,*exp,*zero,*len;
  957.  
  958. Attempts to extract a number from the top value on the calculator stack,
  959. returning it as a sequence of digits.  The value is always left stacked.  If
  960. unsuccessful, num returns a negative number (except when the top value is
  961. null, in which case num dies).  Otherwise, num stores a sequence of digits
  962. in the workspace (see below), and returns the offset from the start of the
  963. workspace to the start of the sequence of digits (which always equals the
  964. old value of eworkptr).  The value eworkptr is updated to point past the end
  965. of the sequence of digits.  The length of the sequence is returned in len.
  966. If the number is zero, then zero is set to 1, and otherwise it is set to 0.
  967. If it is negative, then minus is set to 1, and otherwise 0.  The exponent
  968. stored in exp is such that if a decimal point were placed between the first
  969. two digits of the sequence and the result were multiplied by ten to the
  970. power exp, then the original number would be recovered.
  971.  
  972. void stacknum(num,len,exp,minus) char *num; int exp,len,minus;
  973.  
  974. A sequence of digits starting at address num and of length len is formatted
  975. according to the Rexx rules for numerics and stacked.  The exponent "exp" and
  976. sign "minus" are interpreted according to the rules in "num" above.
  977.  
  978. The following functions from the variable interface should probably not
  979. be used.  Use the SAA API instead.
  980.  
  981. char *varget(name,namelen,len) char *name; int varlen; int *len;
  982.  
  983. The variable whose name is "name" and contains "namelen" characters is
  984. searched for in the current symbol table.  If the name is a compound symbol
  985. or a stem, then the first character of the name must have bit 7 set.  The
  986. name is used as-is, that is, it is not translated to upper case, and if it
  987. is a compound variable then no substitution occurs in the tail.  A pointer
  988. to the variable's value is returned, and "len" is set to its length.  If the
  989. variable has not been assigned a value then "len" and the result are zero
  990. and the null pointer, respectively.  The copy of the value which is returned
  991. must not be changed in any way.  It may be invalidated whenever the symbol
  992. table is changed (and may not be used as a parameter to varset()).
  993.  
  994. void varset(name,namelen,value,len) char *name,*value; int namelen,len;
  995.  
  996. The parameters "name" and "namelen" name a variable and satisfy the same
  997. conditions as in varget above.  The parameters "value" and "len" describe
  998. the position and length respectively of a string which is to be assigned to
  999. the variable.  The assignment always succeeds unless there is insufficient
  1000. memory available, in which case the routine dies.
  1001.  
  1002. Note: the variable name and the string may contain arbitrary characters, and
  1003. neither is validated.  If you assign a value to a simple symbol called, e.g.
  1004. "blah" (in lower case) or "XYZ.123" (containing a dot), etc.  then the
  1005. symbol will not be accessible to the Rexx program, but it may be recovered
  1006. using varget(), provided it has not been hidden or destroyed by a PROCEDURE
  1007. instruction.
  1008.  
  1009. Any other function from the Rexx source may be used, but they are [or
  1010. perhaps are not!] described elsewhere.  Try in the source itself...
  1011.  
  1012. A function may use global data from Rexx.  It may either include the
  1013. header file "globals.h" (which defines all the global variables of the Rexx
  1014. interpreter) or simply include declarations for the particular variables it
  1015. uses.  Some useful variables are:
  1016.  
  1017. char *workptr; unsigned eworkptr,worklen;
  1018.  
  1019. The workspace, which may be used freely by a function.  The space starts at
  1020. workptr, and is of maximum length worklen.  The variable eworkptr may be
  1021. used to hold the length of the data currently stored in the workspace.
  1022.  
  1023. int precision,fuzz;
  1024.  
  1025. The setting of "NUMERIC DIGITS", and precision minus the setting of "NUMERIC
  1026. FUZZ", respectively.  That is, "precision" holds the precision of ordinary
  1027. calculations, and "fuzz" holds the precision of comparison operations.
  1028.  
  1029. char numform;
  1030.  
  1031. Zero if "NUMERIC FORM SCIENTIFIC" is in effect, and one if "NUMERIC FORM
  1032. ENGINEERING".
  1033.  
  1034. int ppc;
  1035.  
  1036. The number of the instruction being interpreted.
  1037.  
  1038. int rxstacksock;
  1039.  
  1040. A file descriptor which is connected to the Rexx stack process via a socket.
  1041.  
  1042. FILE *ttyin,*ttyout;
  1043.  
  1044. Streams which may be used to communicate with the terminal.
  1045.  
  1046.  
  1047. A Rexx memory structure (for example the workspace) may be extended using
  1048. the macros mtest or dtest.  These are called like functions, but note that
  1049. some arguments may be evaluated more than once or not at all.
  1050.  
  1051. mtest(memptr,alloc,length,extend)
  1052.  
  1053. Check that the desired length for the area, "length", is not greater than
  1054. the actual length, "alloc".  If it is, then attempt to reallocate the area,
  1055. pointed to by "memptr", with "extend" more bytes than its previous length.
  1056. The parameters memptr and alloc will be updated to reflect the new position
  1057. and length of the area.  The macro will die if not enough memory is
  1058. available.
  1059.  
  1060. dtest(memptr,alloc,length,extend)
  1061.  
  1062. Perform mtest on the four arguments, but return 0 if the area did not move,
  1063. and non-zero otherwise.  In order to use this macro, the current function
  1064. must contain variables:
  1065.  
  1066. char *mtest_old;
  1067. long mtest_diff;
  1068.  
  1069. If the memory pointer has moved, then mtest_diff contains the difference
  1070. (the new pointer minus the old).
  1071.  
  1072. 2(d). Writing an external function as a Unix program
  1073.  
  1074. If a REXX program calls a function which is not internal or built-in and
  1075. cannot be found in any of the other categories of external function, then
  1076. REXX/imc searches for a file having the same name as the function in lower
  1077. case without a file extension, and this is assumed to be a Unix program.
  1078. The program may be written in any language supported by Unix such as C or
  1079. perl (even REXX, but note that although the programs will share the same
  1080. stack, a fresh copy of the interpreter will be loaded and some of the
  1081. parameter information will be lost as usual for a REXX program called
  1082. as a command).  If the program is interpreted then it must start with a
  1083. "#!" comment that names its interpreter, and the Unix kernel must be able
  1084. to recognise this form of comment. 
  1085.  
  1086. REXX/imc will execute the Unix program with argv[0] containing the name
  1087. by which the function was called, excluding any path name (that part of
  1088. the name up to and including the last slash character), and the rest of
  1089. argv[] containing the function's arguments.  The program will thus have
  1090. argc equal to one more than the number of arguments passed by REXX.  The
  1091. arguments will be null-terminated, which means that the arguments must not
  1092. contain null characters.
  1093.  
  1094. The program will be expected to print its result on its standard output,
  1095. followed by a newline character.  The program returns an empty string by
  1096. printing a single newline character.  The program returns no result by
  1097. printing nothing.
  1098.  
  1099. If the program finishes with an exit code of 255 (or -1), then REXX/imc will
  1100. raise error 50 (error in called routine).
  1101. ______________________________________________________________________________
  1102.  
  1103. 3. Writing Function Libraries for REXX/imc
  1104.  
  1105. Any of the four methods used in section 2 may be used to write a function
  1106. library, with some minor changes in certain circumstances.  A function
  1107. library is a single file which implements several functions (although there
  1108. is nothing to say that a library must contain more than one function).  Each
  1109. function library is accompanied by a ".rxlib" file, described below, which
  1110. lists the functions contained in the library.
  1111.  
  1112. If the file is a REXX program or a Unix program, then the same entry
  1113. point (the start of the program) is used for all the functions in the
  1114. library, and the program must examine the name by which it was called
  1115. in order to determine which function to carry out.  In a Unix program,
  1116. this is argv[0] as described in section 2(d).  In a REXX program, the
  1117. name may be found from PARSE SOURCE (in the fourth word).
  1118.  
  1119. If the file is a ".rxfn" file, then the functions have separate entry points
  1120. and must be listed in a dictionary within the file.  [The only time when
  1121. a ".rxfn" file would not have a dictionary is when it contains a single
  1122. function whose entry point is called rxfunction; in that case the only
  1123. difference between a stand-alone function and a library is the presence of a
  1124. ".rxlib" file, described below.  The name by which Rexx calls the function
  1125. will be the name listed in the ".rxlib" file.]  A ".rxfn" dictionary is a
  1126. public symbol whose name is rxdictionary and whose type is an array of
  1127. dictionary elements, thus:
  1128.  
  1129.    typedef struct _dictionary {
  1130.       char *name;
  1131.       int (*function)();
  1132.    } dictionary;
  1133.  
  1134.    dictionary rxdictionary[];
  1135.  
  1136. Each name field must be initialised to the null-terminated name of a
  1137. function, as called by a REXX program.  The names are case-sensitive and
  1138. should usually be in upper case.  Each function field must be initialised
  1139. to the entry point of the function, which will have either the calling
  1140. sequence described in section 2(c) or the SAA calling sequence (whichever
  1141. choice is made, all functions should have the same calling sequence).  The
  1142. last element of the dictionary array must have both fields set to NULL.
  1143. When a ".rxfn" file is opened, all the functions in the dictionary are
  1144. registered automatically and will not need to be loaded again from the file
  1145. on subsequent references.
  1146.  
  1147. Once the functions have been collected together in one file as described
  1148. above, the library should be placed in a directory which REXX/imc will
  1149. search for function libraries (see the section on function or subroutine
  1150. invocation in the REXX/imc programming reference).  REXX/imc also needs
  1151. to be made aware of the library's contents.  This is done by writing a
  1152. text file whose name is the same as that of the library (but without the
  1153. file extension such as ".rxfn" or ".rexx") with ".rxlib" appended.  The
  1154. text file contains the names of the functions which may be found in the
  1155. library, separated by blanks, newlines or tab characters.  The names are
  1156. case-sensitive.  REXX/imc will only load a function library if the required
  1157. function name is found within this text file.  The name of the function
  1158. library itself is irrelevant; REXX/imc will read all ".rxlib" files found in
  1159. the appropriate directories and store the names found inside.
  1160.  
  1161. If the function library is a set of functions using the SAA interface
  1162. then the first token in the ".rxlib" file must be "rxsaa:".  If this is
  1163. missing then the functions will be called using the wrong protocol and the
  1164. interpreter will crash.
  1165.  
  1166. The set of mathematical functions, rxmathfn.*, is an example of a function
  1167. library.  It is supplied in two forms: a REXX program and a ".rxfn" file.
  1168. Either will work.
  1169.  
  1170. The rxmathfn.rexx function library demonstrates a kludge in the library
  1171. interface: if the ".rxlib" file contains the token "rxmathfn:" then the REXX
  1172. interpreter will skip the usual procedure of resetting NUMERIC DIGITS to 9
  1173. whenever it starts an external function.  The setting is still preserved,
  1174. and restored when the function returns, but if the ".rxlib" file contains
  1175. the token "rxmathfn:" then the function library can inherit the value.  This
  1176. token is only meaningful when the function library is a REXX program.  It is
  1177. ignored for the other forms of library.
  1178. ______________________________________________________________________________
  1179.  
  1180. 4. Accessing the REXX stack
  1181.  
  1182.  (a) Initialising
  1183.  
  1184.      When the application which requires access to the stack initialises, or
  1185.      when it first wants to use the stack, it should do the following:
  1186.  
  1187.      i.  If the environment variable RXSTACK is set, then a stack already
  1188.      exists and uses a socket whose name is the value of RXSTACK.  This
  1189.      should always happen if the application is called from within
  1190.      REXX.  The application may choose to use this stack, or create
  1191.      another.
  1192.      ii. In order to create a new stack, the application should run "rxque"
  1193.      and store the output.  If the application prefers a particular
  1194.      filename for the stack socket, it should give that as a parameter
  1195.      to "rxque" and also set the environment variable RXSTACK to that
  1196.      name.  The output from "rxque filename" will be the stack's process
  1197.      number in the format "%d\n".  The output from "rxque" will be in
  1198.      the form "RXSTACK=%s RXSTACKPROC=%d".  The "%s" in this format is
  1199.      the stack's socket name, and the "%d" is the stack's process number.
  1200.      The RXSTACK variable must be exported to the environment.  The
  1201.      process number must be remembered, so that the stack can be
  1202.      terminated later.
  1203.      iii.When a socket name has been obtained, the application should
  1204.          connect to it a socket of type SOCK_STREAM.  This socket will be
  1205.      used in all further communication with the stack.
  1206.  
  1207.      The stack obtained by the application in this way can be accessed by
  1208.      any other process, providing it knows the socket name and has
  1209.      permission to access it.  This will usually be limited to descendants
  1210.      of the application.  In particular, if the application executes the
  1211.      REXX interpreter, the interpreter will use the same stack.
  1212.  
  1213.  (b) Terminating
  1214.  
  1215.      If the application did not create the stack, it has nothing further to
  1216.      do.  Otherwise it must kill the stack process (using the pid which was
  1217.      remembered earlier) with signal 15 (SIGTERM).
  1218.  
  1219.      In case the application crashes, the stack process will terminate after
  1220.      five minutes of inactivity if it finds that its parent no longer
  1221.      exists (that means that when the stack server is executed it should be
  1222.      executed as a child of the application, and not a grandchild or other
  1223.      descendant).
  1224.  
  1225.  (c) Communications
  1226.  
  1227.      There are three data types which may be communicated: commands, lengths
  1228.      and data.  A command is a single character.  A length is a sequence of
  1229.      six hex digits followed by a newline character: seven bytes in all.
  1230.      Data is an arbitrary sequence of characters of a pre-determined
  1231.      length.  All communications are written unbuffered.
  1232.      Each communication with the stack Each is initiated by the application
  1233.      writing a command character down the socket.  The possible command
  1234.      characters are as follows:
  1235.      N (for Number):  The stack responds by writing a length down the
  1236.        socket, representing the number of items on the stack.
  1237.      S (for Stack):  The stack expects the application to write a length
  1238.        value followed by a data item of that length.  It stacks that data
  1239.        item in lifo order.
  1240.      Q (for Queue):  The stack expects the application to write a length
  1241.        value followed by a data item of that length.  It queues that data
  1242.        item in fifo order.
  1243.      G (for Get):  The stack responds by writing the length of the top stack
  1244.        entry followed by its data, and removes the entry from the stack.
  1245.      P (for Peek):  The stack responds by writing the length of the top stack
  1246.        entry followed by its data, but leaves the stack unchanged.
  1247.      D (for Drop):  No further communication occurs, but the stack deletes
  1248.        its top entry.
  1249.      K (for Kill me): The stack expects the application to write a length
  1250.        value followed by one more byte.  The length value is interpreted as
  1251.        the pid of a process, and the byte as a signal number.  On receipt of
  1252.        this information, the stack server will (attempt to) kill the given
  1253.        process with the given signal.  This command may be used to make an
  1254.        application allow the stack to catch up, in case some of the
  1255.        communications are still en route to the server (the Num command could
  1256.        also be used for this purpose).
  1257.      If the stack process receives an incorrect command value or encounters
  1258.      an error while reading from the socket, then the connection to the
  1259.      offending application will be broken immediately.
  1260. ______________________________________________________________________________
  1261. 5. The REXX/imc internal data structures
  1262. REXX/imc has several data structures including the program, the label
  1263. table, the symbol table, and the program stack.  Each is kept as a block of
  1264. "malloc"ed memory which is grown dynamically as necessary (the "growing" is
  1265. usually performed by the mtest and dtest macros, mentioned above).
  1266. (a) The Source
  1267.     The source code is stored in memory as it appears in the REXX program
  1268.     on disk, except that newline characters are translated into zero bytes.
  1269.     The address of each line (numbered from 1 to the number of lines in the
  1270.     program) is stored in an array (which is another block of "malloc"ed
  1271.     memory), and accessed using the construction "source[num]".  The
  1272.     zeroth element of source stores the file name of the source, which is
  1273.     stored in a separately allocated block of memory.  The block allocated
  1274.     for the source itself is guaranteed to start at source[1].
  1275. (b) The Program
  1276.     The "program", or preprocessed source, is stored as a list of
  1277.     instructions, and prog[num] is a structure containing details about the
  1278.     "num"th instruction.  There are "stmts" instructions in this list.  Note
  1279.     that "THEN", "ELSE" and "OTHERWISE" are counted as individual
  1280.     instructions, and that null clauses do not appear in the list of
  1281.     instructions.  prog[0] contains some pointers to the starts of things
  1282.     (namely the block allocated for the tokenised program itself, the block
  1283.     allocated for the source, and the beginning of the first comment in the
  1284.     source).  prog[stmts] is a null instruction which points to the end of
  1285.     the source.
  1286.     
  1287.     Each instruction is obtained from the source by removing all comments
  1288.     and labels; stripping all unnecessary blanks and collapsing multiple
  1289.     spaces into one; concatenating lines together whenever the continuation
  1290.     character "," appears; tokenising keywords into special characters, and
  1291.     translating "^" (the variant NOT operator) into "\" (the real NOT
  1292.     operator).  The source is also checked for mismatched quotes, invalid
  1293.     labels and invalid characters during preprocessing.
  1294.     Whereas "source" always contains the source of the program being
  1295.     interpreted, "prog" can sometimes contain the list of instructions
  1296.     obtained from an "interpret" instruction.  In this case, the source
  1297.     pointer in prog[0] is used instead of source[1] when freeing the source.
  1298.     Also, certain instructions (such as "call") are required to save the
  1299.     current program temporarily and go back to the original program, by
  1300.     searching for it on the program stack.
  1301.     The current instruction number within the program is stored in the global
  1302.     variable ppc.  The current character position within the program line is
  1303.     stored in a local variable, often called lineptr.
  1304.     Each prog[num] consists of the following structure, called "program":
  1305.        int num;         The line number in the source where the instruction
  1306.                         originates - used when tracing source instructions.
  1307.        char *source;    The start of this instruction in the source
  1308.        char *sourcend;  The end of this instruction in the source
  1309.        int related;     Reserved for future use
  1310.        char *line;      The address of the tokenised instruction
  1311.     The source between "source" and "sourcend" is the current instruction
  1312.     including any comments on the same line but not including labels.
  1313.     Comments on separate lines and labels will appear after "sourcend" or
  1314.     before "source".
  1315. (c) The Labels    
  1316.     Labels within a program are separated off and stored in a table while
  1317.     the program is being preprocessed.  The table is stored in a block of
  1318.     memory at address labptr and of length lablen.  While the table is being
  1319.     built up the length of data so far is elapbtr.  The table consists of
  1320.     the concatenation of elements in the following format:
  1321.        int    total length of this element
  1322.        int    instruction number of label
  1323.        char[] name of label, terminated with a zero character and padded [*]
  1324.     The last element in the table is followed by the integer zero.
  1325.     [*] In all the data structures used by REXX/imc, variable-length string
  1326.     entries are padded (with random bytes) to a multiple of 4 bytes, in
  1327.     order that later data is aligned to the Sun SPARCstation's requirements.
  1328.     The alignment is done by macros in const.h and may be changed.
  1329. (d) The Calculator Stack
  1330.     The calculator stack is simply a list of values in temporary storage
  1331.     during the evaluation of an expression.  Expressions are in effect
  1332.     translated to reverse polish notation (e.g. 1+2 becomes 1 2 +), with
  1333.     each operation stacking and removing values as appropriate.  The stack
  1334.     is stored in a block of memory addressed by cstackptr and of cstacklen
  1335.     bytes.  The total size of the data on the stack is ecstackptr.  Each
  1336.     element on the stack consists of a string (padded as necessary [*])
  1337.     followed by its integer length.
  1338. (e) The Workspace
  1339.     The workspace is a block of memory which is used by various parts of the
  1340.     interpreter to store transient data.  It is addressed by workptr and is
  1341.     of length worklen.  Some routines (especially num()) maintain the length
  1342.     of the currently stored data in eworkptr.
  1343. (f) The Symbol Table
  1344.     The symbol table is a multiple-level associative array containing the
  1345.     definitions of all the REXX symbols which have been assigned values.  It
  1346.     is stored in a block of memory addressed by vartab and of length varlen.
  1347.     Each level of the table is a separate entity, referring to the active
  1348.     variables of a program fragment which used the PROCEDURE instruction to
  1349.     hide the earlier levels, except that each level may contain pointers to
  1350.     earlier levels as a result of the PROCEDURE EXPOSE instruction.
  1351.     The start of each level is stored in the array varstk[] as an integer
  1352.     offset from the start of the entire table.  The number of levels is
  1353.     varstkptr, and the number of elements in the array is varstklen.  The
  1354.     total length of all current levels of the symbol table is
  1355.     varstk[varstkptr+1].
  1356.     Each level of the symbol table contains all currently active simple
  1357.     symbols and stems as a binary search tree.  The elements of the tree are
  1358.     in the following format (as described by the varent data type):
  1359.        int    total length of this element
  1360.        int    position of the left child (as offset from start of level)
  1361.        int    position of the right child (as offset from start of level)
  1362.        int    length of the symbol's name
  1363.        int    amount of memory allocated to hold the symbol's value
  1364.        int    actual length of the symbol's value
  1365.        char[] the symbol's name, padded [*]
  1366.        char[] space for the symbol's value
  1367.     If the symbol is a stem, the terminating dot of the name is not stored,
  1368.     but the most significant bit of the first character of the name is set.
  1369.     If the length of the value is negative, then the symbol is considered
  1370.     to be undefined; it has been deleted by DROP or some other process.
  1371.     If the "amount of memory" element of the structure is negative, then
  1372.     this symbol is actually located in an earlier level; the negative value
  1373.     gives the level number, starting at -1 which means the earliest level
  1374.     (i.e. the first in the memory block).
  1375.     Each stem entry in the symbol table has a value containing a default
  1376.     value and a mini-symbol table.  The default value is stored first, in
  1377.     the format:
  1378.        int    the amount of space allocated to the default value
  1379.        int    the actual length of the default value
  1380.        char[] space for the default value
  1381.     Immediately following that are entries for all the tails, in exactly the
  1382.     same format as for the main symbol table.
  1383. (g) The Program Stack
  1384.     The program stack holds information relating to currently active control
  1385.     structures, e.g. function calls and DO-END blocks.  It is stored in a
  1386.     block of memory addressed by pstackptr and of length pstacklen.  The
  1387.     length of all data currently on the program stack is epstackptr.  The
  1388.     stack holds a sequence of various entries in the following formats, and
  1389.     the number of entries in the current function is held in pstacklev:
  1390.     for a simple DO-END block (type 0), a SELECT block (type 2),
  1391.     a DO WHILE or DO FOREVER block or (type 8), a "struct minstack" entry:
  1392.        int stmt    the statement number where the block started
  1393.        char *pos   the character where the block started (used for finding the
  1394.                    WHILE or UNTIL part of a repetitive DO instruction)
  1395.        int len     the length of this structure (16)
  1396.        int type    the type value (as mentioned above)
  1397.     for a repetitive DO with a control variable, an extended "struct
  1398.     minstack" entry:
  1399.        int stmt    the statement number where the block started
  1400.        char *pos   the character where the block started
  1401.        char[]      the limit value, padded [*] (empty string for "no limit")
  1402.        int         the length of the limit value
  1403.        char[]      the step value, padded [*]
  1404.        int         the length of the step value
  1405.        char[]      the name of the control variable, padded [*]
  1406.        int         the length of the control variable name
  1407.        int         the value which appeared after FOR, or -1 for "no value"
  1408.        int len     the total length of this structure
  1409.        int type    the number 10.
  1410.     for a repetitive block introduced by "DO count", a "struct forstack" entry:
  1411.        int stmt    the statement number where the block started
  1412.        char *pos   the character where the block started
  1413.        int fornum  the value specified after "DO"
  1414.        int len     the length of this structure (20)
  1415.        int type    the number 15.
  1416.     for an internal function call, a "struct procstack2" entry:
  1417.        int stmt    the statement number where the function call ocurred
  1418.        char *csp   the caller's cstackptr
  1419.        int ecsp    the caller's ecstaclptr
  1420.        int csl     the caller's cstacklen
  1421.        char trc    the caller's trace flag
  1422.        char tim    the caller's timestamp flag
  1423.        char form   the caller's NUMERIC FORM (0 for SCIENTIFIC)
  1424.                    the compiler will probably insert one byte here
  1425.        int digits  the caller's NUMERIC DIGITS
  1426.        int fuzz    the caller's "NUMERIC DIGITS minus NUMERIC FUZZ"
  1427.        long mic    the caller's timestamp microseconds value
  1428.        long sec    the caller's timestamp seconds value
  1429.        int address1 the caller's environment number (for ADDRESS)
  1430.        int address2 the caller's alternate environment number
  1431.        program *prg the program which was being interpreted at the time
  1432.        int stmts   the number of statements in that program
  1433.        int len     the length of this structure (60)
  1434.        int type    the number 11, becoming 12 when the PROCEDURE instruction
  1435.                    has been executed
  1436.     Note: the program is stored in case it was generated by "interpret"; if
  1437.     that is so then the "real" program will be reinstated before the call.
  1438.     for an INTERPRET instruction, a "struct interpstack" entry:
  1439.        int stmt     the statement number where the INTERPRET occurred
  1440.        program *prg the program which was being interpreted at the time
  1441.        int stmts    the number of instructions in that program
  1442.        int len      the length of this structure (20)
  1443.        int type     the number 14.
  1444.     for a command typed during interactive trace mode, a "struct
  1445.     interactstack" entry (note that a "struct interpstack" entry also
  1446.     appears above this):
  1447.        int stmt    the statement number where the interruption occurred
  1448.        char *csp   the interrupted program's cstackptr
  1449.        int ecs     the interrupted program's ecstackptr
  1450.        int csl     the interrupted program's cstacklen
  1451.        int len     the length of this structure (16)
  1452.        int type    the number 16.
  1453.     Occasionally, the interpreter stacks a program line with the sole intent
  1454.     of having it appear in the traceback.  Such an entry would be in the
  1455.     format of a "struct errorstack":
  1456.        int stmt     the statement number where the error occurred
  1457.        program *prg the program where the error occurred
  1458.        int stmts    the number of statements in this program
  1459.        int len      the length of this structure (20)
  1460.        int type     the number 20
  1461.     Note that external calls are no longer stored on the program stack.  For
  1462.     most purposes, they can be seen to be executed by a separate incarnation
  1463.     of the interpreter.
  1464.        
  1465. (h) The "Hash" Tables
  1466.     There are three "hash" tables, each arranged in a similar way to one
  1467.     level of the symbol table; however the value of each symbol in the hash
  1468.     table is a single void* pointer rather than a string of characters.
  1469.     There are three hash tables, each occupying a separate block of memory
  1470.     addressed by hashptr[i] and of length hashlen[i] (for i=0,1,2).  They
  1471.     are used to store environment variables, details of open files, and
  1472.     details about loaded functions respectively.  Each element of a hash
  1473.     table is arranged as follows (and as indicated in the "hashent" data
  1474.     type):
  1475.        int    length of this element
  1476.        int    position of the left child
  1477.        int    position of the right child
  1478.        void*  value of the element
  1479.        char[] name of the element, terminated by a zero byte and padded [*]
  1480.     The value of each element may be one of the following:
  1481.     In hash table 0:  a pointer to the string "NAME=VALUE" which has been
  1482.     used in a putenv() call.
  1483.     In hash table 1:  either a null pointer, or a pointer to a block of
  1484.     memory which contains a "struct fileinfo" followed by a zero-terminated
  1485.     filename (which may be empty if the file name is unknown).  The "struct
  1486.     fileinfo" is described in const.h.
  1487.     In hash table 2:  a pointer to a "funcinfo" structure containing the
  1488.     address of a loaded function.  One of the functions loaded from each
  1489.     function package also contains the handle which was returned from
  1490.     dlopen().
  1491. (i) The Signal Stack
  1492.     REXX stores the context of each invocation of the interpreter()
  1493.     function, so that it can be restored whenever an EXIT or a caught signal
  1494.     is encountered.  The context is stored in the array sigstack[], which at
  1495.     any time has sigstacklen elements allocated to it.  The number of the
  1496.     highest used element of sigstack[] is interplev.  Each entry of the
  1497.     signal stack contains:
  1498.        short bits    The combined bits for all SIGNAL ON traps which are on
  1499.        short bitson  ...all SIGNAL ON traps which were executed at this level
  1500.        short callon  ...all CALL ON traps which are on
  1501.        short delay   ...all conditions which are delayed
  1502.        char type     1 if a "signal" trap just occurred, 2 if "call", 0 if none
  1503.        char which    The number for the condition which just occurred (if any)
  1504.        char *data    A description for for the condition which just occurred
  1505.        int ppc[6]    The statement numbers to jump to for all the conditions
  1506.                      or minus the statement number to flag with "label not
  1507.              found" if a condition occurs
  1508.        jmp_buf jmp   The context of this level of the interpreter.
  1509.     Note: a negative number in ppc[i] means that the trap instruction for
  1510.     this condition named a non-existent label.  -ppc[i] will be the
  1511.     statement number of this trap instruction.  This means that we can
  1512.     delay the "label not found" error until it actually happens: moreover,
  1513.     we can include the condition trap instruction in the traceback.
  1514.     However, an interpreted condition trap instruction is not guaranteed to
  1515.     stay around, and therefore it is reported as an error immediately if it
  1516.     names a non-existent label.
  1517. (j) The Shell's Hash Table
  1518.     The builtin shell keeps a record of where it found each command in a
  1519.     hash table (yes, a real one ;-) ).  The variable "hashtable" points to
  1520.     an array of bucket pointers, and the variable "hashbuckets" holds the
  1521.     number of pointers in the table.  A bucket pointer is null if there are
  1522.     no entries in the bucket; otherwise it points to a hashitem structure,
  1523.     representing the first item in the bucket.  That item may in turn point
  1524.     to another item in the bucket.  The items in each bucket are kept in
  1525.     alphabetical order, to reduce the average time taken for an unsuccessful
  1526.     search (or an insertion).  Each item contains the following information:
  1527.        struct _hashitem *next  The next item in the bucket, or null
  1528.        int hits                Number of times this has been found
  1529.        int expense             Position within $PATH
  1530.        int dot                 Whether dot occurred in the path before this
  1531.        int data                Offset from end of header to data
  1532.        char[]                  The key; a string of characters ending with 0.
  1533.        char[]                  The data; another nul-terminated string.
  1534.