Changeset 39
- Timestamp:
- Mar 9, 2017, 7:12:06 PM (8 years ago)
- Location:
- rxutilex/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
rxutilex/trunk/Makefile
r33 r39 8 8 CFLAGS = /Ss /Q /Wuse /Gm /I$(SHARED) /DSZ_ERROR_NAME="\"SYS2ERR\"" 9 9 #CFLAGS = /Ss /Q /Wuse /Gm /Gd /I$(SHARED) /DSZ_ERROR_NAME="\"SYS2ERR\"" 10 LFLAGS = /NOLOGO 10 LFLAGS = /NOLOGO /MAP 11 11 NAME = rxutilex 12 12 LIBS = rexx.lib -
rxutilex/trunk/rxutilex.c
r36 r39 53 53 #define INCL_DOSPROCESS 54 54 #define INCL_DOSPROFILE 55 #define INCL_LONGLONG 55 56 #ifndef OS2_INCLUDED 56 57 #include <os2.h> … … 91 92 #define SZ_LIBRARY_NAME "RXUTILEX" // Name of this library 92 93 //#define SZ_ERROR_NAME "SYS2ERR" // REXX variable used to store error codes 93 #define SZ_VERSION "0.1. 4" // Current version of this library94 #define SZ_VERSION "0.1.5" // Current version of this library 94 95 95 96 // Maximum string lengths... … … 143 144 "Sys2Close", 144 145 "Sys2Seek", 146 "Sys2BytesRemaining", 145 147 "Sys2Read", 148 "Sys2ReadLine", 146 149 "Sys2SyncBuffer", 147 150 "Sys2Write", … … 1977 1980 } 1978 1981 else 1979 fsMode |= OPEN_SHARE_DENY WRITE;1982 fsMode |= OPEN_SHARE_DENYNONE; 1980 1983 1981 1984 // Fifth argument: deny legacy mode … … 2154 2157 2155 2158 /* ------------------------------------------------------------------------- * 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 * ------------------------------------------------------------------------- */ 2171 ULONG 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 /* ------------------------------------------------------------------------- * 2156 2216 * Sys2Read * 2157 2217 * * … … 2195 2255 } 2196 2256 SaveResultString( prsResult, pszData, cbActual ); // 2016-02-20 SHL 2257 2258 cleanup: 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 * ------------------------------------------------------------------------- */ 2279 ULONG 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 2197 2321 2198 2322 cleanup: -
rxutilex/trunk/rxutilex.def
r36 r39 1 1 LIBRARY RXUTILEX INITINSTANCE TERMINSTANCE 2 2 DATA MULTIPLE NONSHARED 3 DESCRIPTION '@#Alex Taylor:0.1. 4#@##1## 12 Feb 2017 16:36:51REINFORCE::::::@@Extended REXX Utility Functions'3 DESCRIPTION '@#Alex Taylor:0.1.5#@##1## 9 Mar 2017 13:10:35 REINFORCE::::::@@Extended REXX Utility Functions' 4 4 5 5 EXPORTS Sys2LoadFuncs … … 29 29 Sys2SyncBuffer 30 30 Sys2QueryDriveInfo 31 Sys2ReadLine 32 Sys2BytesRemaining -
rxutilex/trunk/rxutilex.txt
r36 r39 1 1 FUNCTIONS IN RXUTILEX.DLL 2 2 3 Sys2BytesRemaining - Get the number of bytes remaining in a file 3 4 Sys2CheckNamedPipe - Check the status of a named pipe (server side) 4 5 Sys2Close - Close a file or named pipe … … 22 23 Sys2QueryProcessList - Get the list of running processes 23 24 Sys2Read - Read bytes from a file or named pipe 25 Sys2ReadLine - Read a line of text from a file or named pipe 24 26 Sys2ReplaceModule - Unlock a DLL (DosReplaceModule wrapper) 25 27 Sys2Seek - Set file read/write pointer (with >2GB support) … … 33 35 code, and description indicates the internal function call that failed. If 34 36 no error occurs, SYS2ERR will be "0". 37 38 39 40 ------------------------------------------------------------------------- 41 Sys2BytesRemaining 42 43 Return the number bytes that remain in a stream following the current 44 read/write position. 45 46 REXX ARGUMENTS: 47 1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED) 48 49 REXX RETURN VALUE: 50 The number of bytes remaining. In case of error, 0 will be returned and 51 SYS2ERR will be set. 35 52 36 53 … … 320 337 R = Open file with read access. 321 338 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: "") 323 340 R = Deny read access to other processes 324 341 W = Deny write access to other processes 342 Specifying "" will permit both read and write access. 325 343 5. Deny legacy DosOpen access, one of: 326 344 0 = Allow DosOpen to access the file (DEFAULT) … … 492 510 493 511 ------------------------------------------------------------------------- 512 Sys2ReadLine 513 514 Read a line (up to the next line feed) from a previously-opened stream. 515 Only ASCII LF (0x0A) bytes are treated as line-end characters; they will 516 be stripped from the result string. CR bytes (0x0D) will be skipped over 517 but otherwise ignored. 518 519 REXX ARGUMENTS: 520 1. File handle (returned by Sys2Open or Sys2CreateNamedPipe) (REQUIRED) 521 522 REXX 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 ------------------------------------------------------------------------- 494 528 Sys2ReplaceModule 495 529 -
rxutilex/trunk/testio.cmd
r17 r39 28 28 if data == '' then say SYS2ERR 29 29 else say '37 bytes from offset 86:' data 30 remain = Sys2BytesRemaining( fh ); 31 say remain 'bytes left in file.' 30 32 ok = Sys2Close( fh ) 31 33 IF ok == 0 then say SYS2ERR
Note:
See TracChangeset
for help on using the changeset viewer.