Changeset 39


Ignore:
Timestamp:
Mar 9, 2017, 7:12:06 PM (8 years ago)
Author:
Alex Taylor
Message:

Changes for v0.1.5: Added functions Sys2ReadLine and Sys2BytesRemaining. Sys2Open now supports (and defaults to) DENYNONE mode.

Location:
rxutilex/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/Makefile

    r33 r39  
    88CFLAGS = /Ss /Q /Wuse /Gm /I$(SHARED) /DSZ_ERROR_NAME="\"SYS2ERR\""
    99#CFLAGS = /Ss /Q /Wuse /Gm /Gd /I$(SHARED) /DSZ_ERROR_NAME="\"SYS2ERR\""
    10 LFLAGS = /NOLOGO
     10LFLAGS = /NOLOGO /MAP
    1111NAME   = rxutilex
    1212LIBS   = rexx.lib
  • rxutilex/trunk/rxutilex.c

    r36 r39  
    5353#define INCL_DOSPROCESS
    5454#define INCL_DOSPROFILE
     55#define INCL_LONGLONG
    5556#ifndef OS2_INCLUDED
    5657    #include <os2.h>
     
    9192#define SZ_LIBRARY_NAME         "RXUTILEX"  // Name of this library
    9293//#define SZ_ERROR_NAME           "SYS2ERR"   // REXX variable used to store error codes
    93 #define SZ_VERSION              "0.1.4"     // Current version of this library
     94#define SZ_VERSION              "0.1.5"     // Current version of this library
    9495
    9596// Maximum string lengths...
     
    143144    "Sys2Close",
    144145    "Sys2Seek",
     146    "Sys2BytesRemaining",
    145147    "Sys2Read",
     148    "Sys2ReadLine",
    146149    "Sys2SyncBuffer",
    147150    "Sys2Write",
     
    19771980    }
    19781981    else
    1979         fsMode |= OPEN_SHARE_DENYWRITE;
     1982        fsMode |= OPEN_SHARE_DENYNONE;
    19801983
    19811984    // Fifth argument: deny legacy mode
     
    21542157
    21552158/* ------------------------------------------------------------------------- *
     2159 * Sys2BytesRemaining                                                        *
     2160 *                                                                           *
     2161 * Return the number bytes that remain in a stream following the current     *
     2162 * read/write position.                                                      *
     2163 *                                                                           *
     2164 * REXX ARGUMENTS:                                                           *
     2165 *   1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED) *
     2166 *                                                                           *
     2167 * REXX RETURN VALUE:                                                        *
     2168 *   The number of bytes remaining. In case of error, 0 will be returned and *
     2169 * SYS2ERR will be set.                                                      *
     2170 * ------------------------------------------------------------------------- */
     2171ULONG APIENTRY Sys2BytesRemaining( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     2172{
     2173    HFILE        hf;
     2174    FILESTATUS3L fst3l = {0};
     2175    LONGLONG ll = {0},
     2176             llPos,
     2177             llSize;
     2178    CHAR   achActual[ US_LONGLONG_MAXZ ];
     2179    APIRET rc;
     2180
     2181    // Reset the error indicator
     2182    WriteErrorCode( 0, NULL );
     2183
     2184    // Make sure we have one valid argument
     2185    if ( argc != 1  || ( !RXVALIDSTRING(argv[0]) )) return ( 40 );
     2186
     2187    // First argument: handle
     2188    if (( sscanf( argv[0].strptr, "%8X", &hf )) != 1 ) return ( 40 );
     2189
     2190    // Get the current position
     2191    rc = DosSetFilePtrL( hf, ll, FILE_CURRENT, &llPos );
     2192    if ( rc != NO_ERROR ) {
     2193        WriteErrorCode( rc, "DosSetFilePtrL");
     2194        SaveResultString( prsResult, NULL, 0 );
     2195        return ( 0 );
     2196    }
     2197
     2198    // Get the total file size
     2199    rc = DosQueryFileInfo( hf, FIL_STANDARDL, &fst3l, sizeof( fst3l ));
     2200    if ( rc != NO_ERROR ) {
     2201        WriteErrorCode( rc, "DosQueryFileInfoL");
     2202        SaveResultString( prsResult, NULL, 0 );
     2203        return ( 0 );
     2204    }
     2205    llSize = fst3l.cbFile - llPos;
     2206
     2207    // Return the position as the REXX result string
     2208    sprintf( achActual, "%lld", llSize );
     2209    SaveResultString( prsResult, achActual, strlen(achActual) );
     2210
     2211    return ( 0 );
     2212}
     2213
     2214
     2215/* ------------------------------------------------------------------------- *
    21562216 * Sys2Read                                                                  *
    21572217 *                                                                           *
     
    21952255    }
    21962256    SaveResultString( prsResult, pszData, cbActual );   // 2016-02-20 SHL
     2257
     2258cleanup:
     2259    free( pszData );
     2260    return ( 0 );
     2261}
     2262
     2263
     2264/* ------------------------------------------------------------------------- *
     2265 * Sys2ReadLine                                                              *
     2266 *                                                                           *
     2267 * Read a line (up to the next LF byte) from a previously-opened stream.     *
     2268 * Only line feed (0x0A) bytes are treated as line-end characters; they will *
     2269 * be stripped from the result string.  Carriage return bytes (0x0D) will    *
     2270 * be skipped over but otherwise ignored.                                    *
     2271 *                                                                           *
     2272 * REXX ARGUMENTS:                                                           *
     2273 *   1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED) *
     2274 *                                                                           *
     2275 * REXX RETURN VALUE:                                                        *
     2276 *   String containing the text read. In the event of error, this will be "" *
     2277 * and SYS2ERR will be set.                                                  *
     2278 * ------------------------------------------------------------------------- */
     2279ULONG APIENTRY Sys2ReadLine( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     2280{
     2281    HFILE  hf;
     2282    ULONG  cbBuf    = 0,
     2283           cbTotal  = 0,
     2284           cbActual = 0;
     2285    PSZ    pszData;
     2286    BOOL   fEOL = FALSE;
     2287    CHAR   ch;
     2288    APIRET rc;
     2289
     2290    // Reset the error indicator
     2291    WriteErrorCode( 0, NULL );
     2292
     2293    // Make sure we have one valid argument
     2294    if ( argc != 1  || ( !RXVALIDSTRING(argv[0]) )) return ( 40 );
     2295
     2296    // First argument: handle
     2297    if (( sscanf( argv[0].strptr, "%8X", &hf )) != 1 ) return ( 40 );
     2298
     2299    cbBuf = 1024;
     2300    pszData = (PSZ) malloc( cbBuf );
     2301    while ( !fEOL ) {
     2302        rc = DosRead( hf, &ch, 1, &cbActual );
     2303        if ( rc ) {
     2304            WriteErrorCode( rc, "DosRead");
     2305            SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL
     2306            goto cleanup;
     2307        }
     2308        if ( !cbActual || ch == '\n') {
     2309            fEOL = TRUE;
     2310            break;
     2311        }
     2312        else if ( ch == '\r')
     2313            continue;
     2314        if ( cbTotal >= cbBuf ) {
     2315            cbBuf += 256;
     2316            pszData = (PSZ) realloc( pszData, cbBuf );
     2317        }
     2318        pszData[ cbTotal++ ] = ch;
     2319    }
     2320    SaveResultString( prsResult, pszData, cbTotal );   // 2016-02-20 SHL
    21972321
    21982322cleanup:
  • rxutilex/trunk/rxutilex.def

    r36 r39  
    11LIBRARY     RXUTILEX INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.1.4#@##1## 12 Feb 2017 16:36:51     REINFORCE::::::@@Extended REXX Utility Functions'
     3DESCRIPTION '@#Alex Taylor:0.1.5#@##1## 9 Mar 2017 13:10:35      REINFORCE::::::@@Extended REXX Utility Functions'
    44
    55EXPORTS     Sys2LoadFuncs
     
    2929Sys2SyncBuffer
    3030Sys2QueryDriveInfo
     31Sys2ReadLine
     32Sys2BytesRemaining
  • rxutilex/trunk/rxutilex.txt

    r36 r39  
    11FUNCTIONS IN RXUTILEX.DLL
    22
     3Sys2BytesRemaining          - Get the number of bytes remaining in a file
    34Sys2CheckNamedPipe          - Check the status of a named pipe (server side)
    45Sys2Close                   - Close a file or named pipe
     
    2223Sys2QueryProcessList        - Get the list of running processes
    2324Sys2Read                    - Read bytes from a file or named pipe
     25Sys2ReadLine                - Read a line of text from a file or named pipe
    2426Sys2ReplaceModule           - Unlock a DLL (DosReplaceModule wrapper)
    2527Sys2Seek                    - Set file read/write pointer (with >2GB support)
     
    3335code, and description indicates the internal function call that failed.  If
    3436no error occurs, SYS2ERR will be "0".
     37
     38
     39
     40-------------------------------------------------------------------------
     41Sys2BytesRemaining
     42
     43Return the number bytes that remain in a stream following the current
     44read/write position.
     45
     46REXX ARGUMENTS:
     47  1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED)
     48
     49REXX RETURN VALUE:
     50  The number of bytes remaining. In case of error, 0 will be returned and
     51  SYS2ERR will be set.
    3552
    3653
     
    320337       R = Open file with read access.
    321338       W = Open file with write access.
    322   4. Sharing mode flags, any combination of:               (DEFAULT: "W")
     339  4. Sharing mode flags, any combination (or "") of:        (DEFAULT: "")
    323340       R = Deny read access to other processes
    324341       W = Deny write access to other processes
     342     Specifying "" will permit both read and write access.
    325343  5. Deny legacy DosOpen access, one of:
    326344       0 = Allow DosOpen to access the file                     (DEFAULT)
     
    492510
    493511-------------------------------------------------------------------------
     512Sys2ReadLine
     513
     514Read a line (up to the next line feed) from a previously-opened stream.
     515Only ASCII LF (0x0A) bytes are treated as line-end characters; they will
     516be stripped from the result string.  CR bytes (0x0D) will be skipped over
     517but otherwise ignored.
     518
     519REXX ARGUMENTS:
     520  1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED)
     521
     522REXX RETURN VALUE:
     523  String containing the text read. In the case of error, this will be ""
     524  and SYS2ERR will be set.
     525
     526
     527-------------------------------------------------------------------------
    494528Sys2ReplaceModule
    495529
  • rxutilex/trunk/testio.cmd

    r17 r39  
    2828    if data == '' then say SYS2ERR
    2929    else say '37 bytes from offset 86:' data
     30    remain = Sys2BytesRemaining( fh );
     31    say remain 'bytes left in file.'
    3032    ok = Sys2Close( fh )
    3133    IF ok == 0 then say SYS2ERR
Note: See TracChangeset for help on using the changeset viewer.