source: rxutilex/trunk/FUNCTIONS@ 17

Last change on this file since 17 was 17, checked in by Alex Taylor, 11 years ago

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

File size: 17.7 KB
RevLine 
[4]1FUNCTIONS IN RXUTILEX.DLL
2
3(See file 'TODO' for functions which are under consideration to be added.)
4
[16]5Sys2CheckNamedPipe - Check the status of a named pipe
[17]6Sys2Close - Close a file or named pipe
[16]7Sys2ConnectNamedPipe - Enable client sessions on a named pipe
8Sys2CreateNamedPipe - Create a named pipe
9Sys2DisconnectNamedPipe - Acknowledge that a named pipe session has ended
[4]10Sys2DropFuncs - Deregister all functions
11Sys2FormatTime - Format calender time (strftime wrapper)
12Sys2GetClipboardText - Retrieve the current clipboard text
13Sys2GetEpochTime - Get or convert calender time (seconds from epoch)
14Sys2KillProcess - Kill a process by name or PID
15Sys2LoadFuncs - Register all functions
16Sys2LocateDLL - Search for a loaded/loadable DLL
[17]17Sys2Open - Open a file or stream (with >2GB support)
[4]18Sys2PutClipboardText - Copy a text string to the clipboard
19Sys2QueryForegroundProcess - Get the PID of the current foreground process
20Sys2QueryPhysicalMemory - Get the amount of installed RAM
21Sys2QueryProcess - Get information about a process
22Sys2QueryProcessList - Get the list of running processes
[17]23Sys2Read - Read bytes from a file or named pipe
[4]24Sys2ReplaceModule - Unlock a DLL (DosReplaceModule wrapper)
[17]25Sys2Seek - Set file read/write pointer (with >2GB support)
[4]26Sys2Version - Get the version of this library
[17]27Sys2Write - Write bytes to a file or named pipe
[4]28
29
30If an internal error occurs in any function, the variable SYS2ERR will contain
[16]31an error message of the form "RC: description" where RC is a non-zero error
[4]32code, and description indicates the internal function call that failed. If
33no error occurs, SYS2ERR will be "0".
34
35
36-------------------------------------------------------------------------
[16]37Sys2CheckNamedPipe
38
39Check the status of a named pipe.
40
41REXX ARGUMENTS:
42 1. The pipe handle (from Sys2CreateNamedPipe or DosOpen). (REQUIRED)
43
44REXX RETURN VALUE:
45 String of the format "bytes status", where bytes is the number of bytes
46 currently waiting in the pipe, and status is one of: DISCONNECTED,
47 LISTENING, CONNECTED, or CLOSING.
48
49
50-------------------------------------------------------------------------
[17]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-------------------------------------------------------------------------
[16]63Sys2ConnectNamedPipe
64
65Start 'listening' by allowing clients to connect to a previously-created
66named pipe.
67
68REXX ARGUMENTS:
69 1. The pipe handle, as returned by Sys2CreateNamedPipe. (REQUIRED)
70
71REXX RETURN VALUE:
72 1 on success, or 0 if an error occurred.
73
74
75-------------------------------------------------------------------------
76Sys2CreateNamedPipe
77
[17]78Creates a named pipe with the specified name and parameters. Only byte
79mode is supported; message mode is not.
[16]80
81Note that the standard REXX functions such as CHARIN/OUT, which operate
82directly on file names, are not capable of using the pipe handle returned
83from this function. While the client end can use such functions after
[17]84using STREAM to issue an OPEN WRITE or OPEN READ command, the server end
[16]85needs to use the pipe handle from this function, and must therefore use
86Sys2Read/Sys2Write in order to read and write data from the pipe.
87
[17]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.
98
[16]99REXX ARGUMENTS:
100 1. The name of the pipe, in the form "\PIPE\something". (REQUIRED)
101 2. The size of the outbound buffer, in bytes. (REQUIRED)
102 3. The size of the inbound buffer, in bytes. (REQUIRED)
103 4. The pipe's timeout value, in milliseconds. (DEFAULT: 3000)
104 5. The number of simultaneous instances of this pipe which are allowed.
105 Must be between 1 and 254, or 0 indicating no limit. (DEFAULT: 1)
106 6. Pipe blocking mode, one of:
107 W = WAIT mode, read and write block waiting for data (DEFAULT)
108 N = NOWAIT mode, read and write return immediately
109 7. Pipe mode, one of:
110 I = Inbound pipe (DEFAULT)
111 O = Outbound pipe
112 D = Duplex (inbound/outbound) pipe
113 8. Privacy/inheritance flag, one of:
114 0 = The pipe handle is inherited by child processes (DEFAULT)
115 1 = The pipe handle is private to the current process
116 9. Write-through flag, one of:
117 0 = Allow delayed writes (write-behind) to remote pipes (DEFAULT)
118 1 = Force immediate writes (write-through) to remote pipes
119
120REXX RETURN VALUE: A four-byte pipe handle.
121
122
123-------------------------------------------------------------------------
124Sys2DisconnectNamedPipe
125
126Unlocks a named pipe after a client has closed its connection.
127
128REXX ARGUMENTS:
129 1. The pipe handle, as returned by Sys2CreateNamedPipe. (REQUIRED)
130
131REXX RETURN VALUE:
132 1 on success, or 0 if an error occurred.
133
134
135-------------------------------------------------------------------------
[4]136Sys2DropFuncs
137
138Deregisters all Sys2* REXX functions.
139
140REXX ARGUMENTS: None
141REXX RETURN VALUE: ""
142
143
144-------------------------------------------------------------------------
145Sys2FormatTime
146
147Converts a number of seconds from the epoch (1970-01-01 0:00:00 UTC) into
148a formatted date and time string.
149
150REXX ARGUMENTS:
151 1. Number of seconds (a positive integer) to be converted. (REQUIRED)
152 This value cannot be greater than 2,147,483,647.
153 2. Format type, one of:
154 D = return in the form 'yyyy-mm-dd hh:mm:ss (w)' where w
155 represents the weekday (0-6 where 0=Sunday) (DEFAULT)
156 I = return in ISO8601 combined form 'yyyy-mm-ddThh:mm:ss[Z]'
157 L = return in the form 'day month year (weekday) time' where month
158 and weekday are language-dependent abbreviations
159 Note: With D and I, time is returned in 24-hour format; L may vary.
160 3. TZ conversion flag (indicates whether to convert to UTC from local
161 time), one of:
162 U = return UTC or unconverted time
163 L = assume the input is in Coordinated Universal Time, and convert
164 to local time using the current TZ (DEFAULT)
165
166REXX RETURN VALUE: The formatted time string, or "" on error.
167
168
169-------------------------------------------------------------------------
170Sys2GetClipboardText
171
172Retrieves a plain-text string from the clipboard if one is available.
173
174This function requires Presentation Manager to be active, although the
175REXX program itself need not be running in a PM process.
176
177REXX ARGUMENTS:
178 None.
179
180REXX RETURN VALUE: The retrieved clipboard string
181
182
183-------------------------------------------------------------------------
184Sys2GetEpochTime
185
186Converts formatted date and time into a number of seconds (UTC) from the
187epoch (defined as 1970-01-01 0:00:00). The input time is assumed to
188refer to the current timezone as defined in the TZ environment variable.
189
190If no parameters are specified, the current system time is used. If at
191least one parameter is specified, then any missing parameter is assumed
192to be its minimum possible value (1 for day or month, 0 for all others).
193
194The time is formatted according to the C runtime's locale support, as
195configured via the LANG and LC_* environment variables.
196
197REXX ARGUMENTS:
198 1. The year (1970-2037)
199 Years prior to 1970 or later than 2037 cannot be supported due to the
200 limitations in how the C library calculates epoch time. Specifying
[16]201 1969 or earlier will generate a REXX error. Any date later than 2037
[4]202 will return a value of 0 (and SYS2ERR will report an error in 'mktime').
203 NOTE: A 2-digit year can be specified, in which case the number will be
[16]204 added to 1900 if it is 70 or higher, or to 2000 otherwise.
[4]205 e.g. '20' ==> 2020
206 '75' ==> 1975
207 This is subject to the limitation noted above, such that values
208 from 38 to 69 will result in a return value of 0.
209 2. The month (1-12)
210 3. The day (1-31)
211 4. Hours (0-23)
212 5. Minutes (0-59)
213 6. Seconds (0-61)
214
215REXX RETURN VALUE: The number of seconds since the epoch, or 0 on error.
216
217
218-------------------------------------------------------------------------
219Sys2KillProcess
220
221Terminates the (first) running process with the specified executable name
222or process-ID.
223
224REXX ARGUMENTS:
225 1. The process identifier (program name or process ID) (REQUIRED)
226 2. Flag indicicating the identifier type:
227 'P': decimal process ID
228 'H': hexadecimal process ID
229 'N': executable program name (with or without extension) (DEFAULT)
230
231REXX RETURN VALUE: 1 on success or 0 on failure.
232
233
234-------------------------------------------------------------------------
235Sys2LoadFuncs
236
237Registers all Sys2* REXX functions (except this one, obviously).
238
239REXX ARGUMENTS: None
240REXX RETURN VALUE: ""
241
242
243-------------------------------------------------------------------------
[16]244Sys2LocateDLL
[4]245
[16]246Searches for a DLL by name and returns its fully-qualified path.
247
[4]248If a DLL with the given name is currently loaded, that instance of the
249DLL will be returned. Otherwise, standard DLL loading rules (according
250to the current LIBPATH and/or extended LIBPATH configuration) are used to
[16]251search for a DLL whose module name matches the one specified.
[4]252
[16]253REXX ARGUMENTS:
254 1. The name of the DLL to search for. (REQUIRED)
[4]255
256
[16]257REXX RETURN VALUE:
258 The fully-qualified path of the DLL, if found; "" otherwise.
259
260
[4]261-------------------------------------------------------------------------
[17]262Sys2Open
[4]263
[17]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-------------------------------------------------------------------------
[4]318Sys2PutClipboardText
319
320Writes a string to the clipboard in plain-text format. Specifying either
321no value or an empty string in the first argument will simply clear the
322clipboard of CF_TEXT data.
323
324This function requires Presentation Manager to be active, although the
325REXX program itself need not be running in a PM process.
326
327REXX ARGUMENTS:
328 1. String to be written to the clipboard (DEFAULT: "")
329 2. Flag indicating whether other clipboard formats should be cleared:
330 Y = yes, call WinEmptyClipbrd() before writing text (DEFAULT)
331 N = no, leave (non-CF_TEXT) clipboard data untouched
332
333REXX RETURN VALUE: 1 on success, 0 on failure
334
335
336-------------------------------------------------------------------------
337Sys2QueryForegroundProcess
338
339Queries the PID of the current foreground process.
340
341REXX ARGUMENTS: None
342
343REXX RETURN VALUE:
344 Integer representing the process ID (in decimal), or 0 if an error
345 occurred.
346
347
348-------------------------------------------------------------------------
349Sys2QueryPhysicalMemory
350
351Queries the amount of physical memory (RAM) installed in the system.
352
353REXX ARGUMENTS: None
354
355REXX RETURN VALUE:
356 Integer representing the amount of installed memory, in KiB, or 0 if an
357 error occurred.
358
359
360-------------------------------------------------------------------------
361Sys2QueryProcess
362
363Queries information about the specified process.
364
365REXX ARGUMENTS:
366 1. The process identifier (program name or process ID) (REQUIRED)
367 2. Flag indicicating the identifier type:
368 'P': decimal process ID
369 'H': hexadecimal process ID
370 'N': executable program name (with or without extension) (DEFAULT)
371
372REXX RETURN VALUE:
373 A string of the format
374 pid parent-pid process-type priority cpu-time executable-name
375 "priority" is in hexadecimal notation, all other numbers are decimal.
376 "" is returned if the process was not found or if an internal error
377 occurred.
378
379
380-------------------------------------------------------------------------
381Sys2QueryProcessList
382
383Gets a list of running processes. The results will be returned in a stem
[16]384variable, where stem.0 contains number of items, and each stem item is a
[4]385string of the form:
386 pid parent-pid process-type priority cpu-time executable-name
387"priority" is in hexadecimal notation, all other numbers are decimal.
388
389Notes:
390 - "process-type" will be one of:
391 0 Full screen protect-mode session
392 1 Requires real mode. Dos emulation.
393 2 VIO windowable protect-mode session
394 3 Presentation Manager protect-mode session
395 4 Detached protect-mode process.
396 - If "priority" is 0 then the priority class could not be determined.
397 - If "executable-name" is "--" then the name could not be identified.
398
399REXX ARGUMENTS:
400 1. The name of the stem in which to return the results (REQUIRED)
401
402REXX RETURN VALUE: Number of processes found, or "" in case of error.
403
404
405-------------------------------------------------------------------------
[16]406Sys2Read
407
[17]408Read bytes from a previously-opened stream (wrapper to DosRead).
[16]409
410REXX ARGUMENTS:
[17]411 1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
412 (REQUIRED)
[16]413 2. Number of bytes to read. (REQUIRED)
414
415REXX RETURN VALUE:
416 String containing the bytes read, or "" in case of error.
417
418
419-------------------------------------------------------------------------
[4]420Sys2ReplaceModule
421
422Unlocks and optionally replaces an in-use (locked) DLL or EXE.
423
424REXX ARGUMENTS:
425 1. The filespec of the module to be replaced. (REQUIRED)
426 2. The filespec of the new module to replace it with. (DEFAULT: none)
427 3. The filespec of the backup file to be created. (DEFAULT: none)
428
429REXX RETURN VALUE:
430 1 on success, or 0 if an error occurred.
431
432
433-------------------------------------------------------------------------
[17]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-------------------------------------------------------------------------
[4]453Sys2Version
454
455Returns the current library version.
456
457REXX ARGUMENTS: None
458REXX RETURN VALUE: Current version in the form "major.minor.refresh"
459
[17]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
Note: See TracBrowser for help on using the repository browser.