Changeset 17


Ignore:
Timestamp:
Sep 21, 2014, 8:45:02 AM (11 years ago)
Author:
Alex Taylor
Message:

More work on named-pipe and I/O functions. Added some test cases for the new functionality. Updated documentation.

Location:
rxutilex/trunk
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/FUNCTIONS

    r16 r17  
    44
    55Sys2CheckNamedPipe          - Check the status of a named pipe
     6Sys2Close                   - Close a file or named pipe
    67Sys2ConnectNamedPipe        - Enable client sessions on a named pipe
    78Sys2CreateNamedPipe         - Create a named pipe
     
    1415Sys2LoadFuncs               - Register all functions
    1516Sys2LocateDLL               - Search for a loaded/loadable DLL
     17Sys2Open                    - Open a file or stream (with >2GB support)
    1618Sys2PutClipboardText        - Copy a text string to the clipboard
    1719Sys2QueryForegroundProcess  - Get the PID of the current foreground process
     
    1921Sys2QueryProcess            - Get information about a process
    2022Sys2QueryProcessList        - Get the list of running processes
    21 Sys2Read                    -
     23Sys2Read                    - Read bytes from a file or named pipe
    2224Sys2ReplaceModule           - Unlock a DLL (DosReplaceModule wrapper)
     25Sys2Seek                    - Set file read/write pointer (with >2GB support)
    2326Sys2Version                 - Get the version of this library
     27Sys2Write                   - Write bytes to a file or named pipe
    2428
    2529
     
    4549
    4650-------------------------------------------------------------------------
     51Sys2Close
     52
     53Close a file or stream (wrapper to DosClose).
     54
     55REXX ARGUMENTS:
     56  1. File handle (returned by Sys2Open).  (REQUIRED)
     57
     58REXX RETURN VALUE:
     59  1 on success, or 0 if an error occurred.
     60
     61
     62-------------------------------------------------------------------------
    4763Sys2ConnectNamedPipe
    4864
     
    6076Sys2CreateNamedPipe
    6177
    62 Creates a named pipe with the specified name and parameters.
     78Creates a named pipe with the specified name and parameters.  Only byte
     79mode is supported; message mode is not.
    6380
    6481Note that the standard REXX functions such as CHARIN/OUT, which operate
    6582directly on file names, are not capable of using the pipe handle returned
    6683from this function. While the client end can use such functions after
    67 using STREAM to issue an OPEN WRITE or OPEN READ command, the host end
     84using STREAM to issue an OPEN WRITE or OPEN READ command, the server end
    6885needs to use the pipe handle from this function, and must therefore use
    6986Sys2Read/Sys2Write in order to read and write data from the pipe.
     87
     88Named pipes can be created in inbound-only, outbound-only, or duplex
     89(inbound/outbound) mode.  An error will result if attempting to write
     90to an inbound-only pipe, or read from an outbound-only pipe.
     91
     92To activate a named pipe so that client processes can connect to it, use
     93Sys2ConnectNamedPipe.  To check the pipe's connection status, as well as
     94the amount of data currently in the pipe, use Sys2CheckNamedPipe.  To
     95unlock a named pipe after a client has closed the connection, use
     96Sys2DisconnectNamedPipe.  Finally, the pipe should be destroyed using
     97Sys2Close when no longer needed.
    7098
    7199REXX ARGUMENTS:
     
    232260
    233261-------------------------------------------------------------------------
    234 
     262Sys2Open
     263
     264Opens a file or other stream; files larger than 2GB are supported (this
     265function is a wrapper to DosOpenL).  Direct-DASD mode is not supported by
     266this function, nor is setting the initial extended attributes.
     267
     268REXX ARGUMENTS:
     269  1. Name of file or stream to open.                           (REQUIRED)
     270  2. Open action flags, must be either "O" (open if exists), "R" (replace
     271     if exists), or nothing (fail if exists), optionally followed by "C"
     272     (create if file does not exist).  If "C" is not specified, the
     273     operation will fail if the file does not exist.  Note that a value
     274     of "" alone will therefore fail automatically.        (DEFAULT: "O")
     275     In summary, the possible combinations are:
     276       O = Open only (if file exists, open it; if not, fail)
     277       OC= Open/create (if file exists, open it; if not, create it)
     278       R = Replace only (if file exists, replace it; if not, fail)
     279       RC= Replace/create (if file exists, replace it; if not, create it)
     280       C = Create only (if file exists, fail; if not, create it)
     281       (empty) = No-op (if file exists, fail; if not, fail)
     282  3. Access mode flags, one or both of:                   (DEFAULT: "RW")
     283       R = Open file with read access.
     284       W = Open file with write access.
     285  4. Sharing mode flags, any combination of:               (DEFAULT: "W")
     286       R = Deny read access to other processes
     287       W = Deny write access to other processes
     288  5. Deny legacy DosOpen access, one of:
     289       0 = Allow DosOpen to access the file                     (DEFAULT)
     290       1 = Deny access using the DosOpen API
     291  6. Privacy/inheritance flag, one of:
     292       0 = The file handle is inherited by child processes.     (DEFAULT)
     293       1 = The file handle is private to the current process.
     294  7. Initial file attributes when creating a file:          (DEFAULT: "")
     295       A = Archive attribute set
     296       D = Directory attribute set
     297       S = System attribute set
     298       H = Hidden attribute set
     299       R = Read-only attribute set
     300  8. Initial file size when creating or replacing a file; ignored if
     301     access mode is read-only.                               (DEFAULT: 0)
     302  9. I/O mode flags, any or all of:                         (DEFAULT: "")
     303      T = Write-through mode (default is normal write)
     304      N = No-cache mode (default is to use filesystem cache)
     305      S = Sequential access
     306      R = Random access
     307         * S and R can combine as follows:
     308             Neither: No locality known (default)
     309             S only:  Mainly sequential access
     310             R only:  Mainly random access
     311             Both:    Random/sequential (i.e. random with some locality)
     312
     313REXX RETURN VALUE:
     314  File handle, or "" in case of error.
     315
     316
     317-------------------------------------------------------------------------
    235318Sys2PutClipboardText
    236319
     
    323406Sys2Read
    324407
    325 Read bytes from a previously-opened stream (wrapper to DosRead).  The
    326 format of file handles supported by this function is currently limited
    327 to those returned by Sys2CreateNamedPipe.
    328 
    329 REXX ARGUMENTS:
    330   1. File handle (as returned by Sys2CreateNamedPipe).  (REQUIRED)
     408Read bytes from a previously-opened stream (wrapper to DosRead).
     409
     410REXX ARGUMENTS:
     411  1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
     412     (REQUIRED)
    331413  2. Number of bytes to read.  (REQUIRED)
    332414
     
    350432
    351433-------------------------------------------------------------------------
     434Sys2Seek
     435
     436Move the read/write pointer to the specified location in an open
     437file/stream; files larger than 2GB are supported (this function is a
     438wrapper to DosSetFilePtrL).
     439
     440REXX ARGUMENTS:
     441  1. File handle (returned by Sys2Open).  (REQUIRED)
     442  2. The signed distance in bytes to move.  (REQUIRED)
     443  3. Move method, one of:
     444       B = Beginning of file
     445       C = Current position (DEFAULT)
     446       E = End of file
     447
     448REXX RETURN VALUE:
     449  The new file position, in bytes.
     450
     451
     452-------------------------------------------------------------------------
    352453Sys2Version
    353454
     
    357458REXX RETURN VALUE: Current version in the form "major.minor.refresh"
    358459
     460
     461-------------------------------------------------------------------------
     462Sys2Write
     463
     464Write bytes to a previously-opened stream (wrapper to DosWrite).
     465
     466REXX ARGUMENTS:
     467  1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
     468     (REQUIRED)
     469  2. Data to be written.  (REQUIRED)
     470
     471REXX RETURN VALUE:
     472  The number of bytes successfully written.
     473
  • rxutilex/trunk/TODO

    r16 r17  
    22
    33 * Sys2ReplaceModule - A wrapper for DosReplaceModule()
     4 * Named pipe management functions
     5 * Open/Close/Seek/Read/Write functions with large file support
    46 - Sys2TokenizeString - A string tokenizer
    57 - Sys2FormatNumber - Format a number according to locale
    68 - Sys2FormatCurrency - A strfmon wrapper
    79 - Sys2GetResource - DosGetResource wrapper
    8  - Sys2PrintFile - Print a file to a port or queue
    910 - Sys2IsDirectory - Determine if filespec is a directory
    1011
    1112Under consideration:
    12  - BLDLEVEL parser
     13 - Sys2PrintFile - Print a file to a port or queue
     14 - Sys2StemSort - Sort the values in an array stem
    1315 - SYSLEVEL parser
    14  - Functions to open/read/write Large files
    15  ? Named pipe creation/deletion?
     16 - BLDLEVEL parser                  <-- exists in rxunlock
    1617 ? Install a font
    17  ? Create a printer port
    18  ? Create a printer queue
    19  ? Install a printer "driver.device"
    2018 ? Sys2IncFileName: find the next available filename according to a pattern
    2119     (e.g. CONFIG.001, log_0004.txt, etc.)
     20 ? Create a printer port              <-- in rxprtutil
     21 ? Create a printer queue             <-- in rxprtutil
     22 ? Install a printer "driver.device"  <-- in rxprtutil
    2223 ? Access to the Win32 registry     <-- exists in sp1utils
    2324 ? Sys2CloseWindow & Sys2ExitWindow <-- exists in pr1util
  • rxutilex/trunk/readme.txt

    r4 r17  
     1REXX Utility Functions - Extended (RXUTILEX.DLL)
     2http://trac.netlabs.org/rexxlibs/
     3
    14OBJECTIVE
    25
    36The purpose behind the RXUTILEX library is that it should basically provide
    4 everything that _should_ have been in RexxUtil, but isn't.  Specifically, 
     7everything that _should_ have been in RexxUtil, but isn't.  Specifically,
    58useful system-related functions of a relatively general-purpose nature,
    69as well as commonly-needed data formatting routines.
    7  
    8 This includes things like 
     10
     11This includes things like
    912(* = already at least partially implemented):
    1013 - clipboard access *
     
    1215 - system information (like installed RAM*)
    1316 - locked-file replacement *
    14  - wrappers for strftime()*, mktime()*, and strfmon()
     17 - wrappers for strftime()*, mktime()*, and strfmon()
     18 - named pipe creation/deletion *
     19 - functions to read/write huge (>2GB) files *
    1520 - a string tokenizer
    16  - named pipe creation/deletion
    1721 - access to resources (DosGetResource)
    18  - functions to read/write huge (>2GB) files
    1922and other things that the community decides is needed.
    20  
    21 While it is true that many of these functions already exist in a scattering of 
    22 other REXX libraries, many of those other libraries are no longer maintained 
    23 and/or are closed-source, and cannot be updated by the community.  Others are 
     23
     24While it is true that many of these functions already exist in a scattering of
     25other REXX libraries, many of those other libraries are no longer maintained
     26and/or are closed-source, and cannot be updated by the community.  Others are
    2427relatively special-purpose, and only include one or two general-utility
    2528functions.
    26  
    27 One of the main motivations of this project is to try and reduce "Yet Another
    28 REXX Library" syndrome - where a REXX application requires a myriad of different
    29 REXX DLLs purely for the same of one or two useful functions in each one.  It
    30 would be nice if most of the commonly-required functions were available in a
    31 single library.  Moreover, that library should be open source and maintained by
    32 the OS/2 community, able to be updated and extended as needed.
    33  
    34 On the other hand, it is also important to avoid overloading RXUTILEX with too
    35 many functions.  RXUTILEX should ideally be limited to providing functions which
    36 are generally useful for a wide variety of applications.  (There will always be
    37 relatively specialized areas of support which SHOULD have their own dedicated
    38 REXX libraries - RXLVM and RXULS are obvious examples.)
    39  
    40  
     29
     30One of the main motivations of this project is to try and reduce "Yet Another
     31REXX Library" syndrome - wherein a REXX application requires a myriad of REXX
     32DLLs purely for the sake of one or two useful functions in each one.  It would
     33be nice if most of the commonly-required functions were available in a single
     34library.  Moreover, that library should be open source and maintained by the
     35OS/2 community, able to be updated and extended as needed.
     36
     37On the other hand, it is also desirable to avoid overloading RXUTILEX with too
     38many functions.  RXUTILEX should be limited to providing functions which are
     39generally useful for a wide variety of applications.  (There will always be
     40relatively specialized areas of support which should continue to have their
     41own dedicated REXX libraries - RXLVM, for example.)
     42
     43
     44BUILD NOTES
     45
     46The included Makefile is for the IBM C/C++ compiler.  Version 3.6 or later
     47is required in order to support the parsing of 64-bit integers.
     48
     49
    4150TERMS OF USE
    4251
    43 Once the logistics are worked out, the source code for RXUTILEX will become
    44 available via SVN under a non-restrictive open source license (which is still
    45 to be determined).
     52  REXX Utility Functions - Extended (RXUTILEX)
     53  (C) 2011, 2014 Alex Taylor.
    4654
    47 Until then, this binary-only preview release of RXUTILEX may be used freely and
    48 with no restrictions. 
     55  Redistribution and use in source and binary forms, with or without
     56  modification, are permitted provided that the following conditions are
     57  met:
    4958
    50 This release of RXUTILEX has no warranty, and is not guaranteed to work as
    51 advertised or to be fit for any purpose whatsoever.
     59  1. Redistributions of source code must retain the above copyright
     60     notice, this list of conditions and the following disclaimer.
     61
     62  2. Redistributions in binary form must reproduce the above copyright
     63     notice, this list of conditions and the following disclaimer in the
     64     documentation and/or other materials provided with the distribution.
     65
     66  3. The name of the author may not be used to endorse or promote products
     67     derived from this software without specific prior written permission.
     68
     69  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
     70  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     71  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     72  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     73  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     74  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     75  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     76  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     77  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     78  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     79  POSSIBILITY OF SUCH DAMAGE.
     80
     81The source code for RXUTILEX is available via SVN at
     82http://svn.netlabs.org/repos/rexxlibs/rxutilex/
     83
  • rxutilex/trunk/rxutilex.c

    r16 r17  
    17131713 * Sys2Close                                                                 *
    17141714 *                                                                           *
    1715  * Wrapper to DosWrite: write bytes to a previously-opened stream.           *
     1715 * Wrapper to DosClose: close a file/stream.                                 *
    17161716 *                                                                           *
    17171717 * REXX ARGUMENTS:                                                           *
     
    17911791        strupr( argv[2].strptr );
    17921792        if ( strcspn(argv[2].strptr, "BCE") > 0 ) return ( 40 );
    1793         switch ( argv[1].strptr[0] ) {
     1793        switch ( argv[2].strptr[0] ) {
    17941794            case 'B': ulMethod = FILE_BEGIN;   break;
    17951795            case 'E': ulMethod = FILE_END;     break;
     
    18741874 *                                                                           *
    18751875 * REXX RETURN VALUE:                                                        *
    1876  *   1 on success, or 0 if an error occurred.                                *
     1876 *   Number of bytes written.                                                *
    18771877 * ------------------------------------------------------------------------- */
    18781878ULONG APIENTRY Sys2Write( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     
    18801880    HFILE  hf;
    18811881    ULONG  cbActual;
     1882    CHAR   szActual[ US_INTEGER_MAXZ ];
    18821883    APIRET rc;
    18831884
     
    18941895    // (Second argument can be left in standard RXSTRING form)
    18951896
    1896     rc = DosWrite( hf, argv[0].strptr, argv[0].strlength, &cbActual );
     1897    rc = DosWrite( hf, argv[1].strptr, argv[1].strlength, &cbActual );
    18971898    if ( rc != NO_ERROR ) {
    18981899        WriteErrorCode( rc, "DosWrite");
    18991900        MAKERXSTRING( *prsResult, "0", 1 );
    1900     }
    1901     else {
    1902         MAKERXSTRING( *prsResult, "1", 1 );
    1903     }
    1904 
     1901        return ( 0 );
     1902    }
     1903
     1904    sprintf( szActual, "%d", cbActual );
     1905    MAKERXSTRING( *prsResult, szActual, strlen( szActual ));
    19051906    return ( 0 );
    19061907}
     
    21822183
    21832184    if ( pszContext == NULL )
    2184         sprintf( szErrorText, "%X", ulError );
     2185        sprintf( szErrorText, "%u", ulError );
    21852186    else
    2186         sprintf( szErrorText, "%X: %s", ulError, pszContext );
     2187        sprintf( szErrorText, "%u: %s", ulError, pszContext );
    21872188    MAKERXSTRING( shvVar.shvname,  SZ_ERROR_NAME, strlen(SZ_ERROR_NAME) );
    21882189    MAKERXSTRING( shvVar.shvvalue, szErrorText,   strlen(szErrorText) );
  • rxutilex/trunk/rxutilex.def

    r16 r17  
    11LIBRARY     RXUTILEX INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.0.5#@##1## 20 Sep 2014 20:12:24     REINFORCE::::::@@Extra REXX Utility Functions'
     3DESCRIPTION '@#Alex Taylor:0.0.5#@##1## 21 Sep 2014 15:39:46     REINFORCE::::::@@Extra REXX Utility Functions'
    44
    55EXPORTS     Sys2LoadFuncs
  • rxutilex/trunk/testlib.cmd

    r16 r17  
    3535say Sys2LocateDLL('ehxdlmri')
    3636
    37 hp = Sys2CreateNamedPipe("\PIPE\RNPTEST", 0, 100 )
    38 if hp == "" then say SYS2ERR
    39 else do
    40     ok = Sys2ConnectNamedPipe( hp )
    41     if ok == 0 then say SYS2ERR
    42     else do
    43         PARSE VALUE Sys2CheckNamedPipe( hp ) WITH _cb _state
    44         say _cb 'bytes waiting'
    45         /*data = Sys2Read( hp, _cb )*/
    46         data = charin("\PIPE\RNPTEST",, _cb)
    47         say 'Data: "'c2x(data)'"'
    48     end
    49     ok = Sys2DisconnectNamedPipe( hp )
    50     if ok == 0 then say SYS2ERR
    51 end
    52 
    5337call Sys2DropFuncs
    5438return 0
Note: See TracChangeset for help on using the changeset viewer.