source: rxutilex/trunk/FUNCTIONS@ 20

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

Sys2QueryProcess now accepts a PID of 0 for the current process. Version number increased to 0.1.0.

File size: 18.4 KB
RevLine 
[4]1FUNCTIONS IN RXUTILEX.DLL
2
3(See file 'TODO' for functions which are under consideration to be added.)
4
[19]5Sys2CheckNamedPipe - Check the status of a named pipe (server side)
[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
[19]39Checks the status of a named pipe that was previously created using
40Sys2CreateNamedPipe.
[16]41
[19]42This function is designed for use by the process that created the pipe
43(i.e. the server side). Clients which are accessing a named pipe should
44use the standard REXX STREAM and/or CHARS functions to determine the
45pipe's status.
46
[16]47REXX ARGUMENTS:
48 1. The pipe handle (from Sys2CreateNamedPipe or DosOpen). (REQUIRED)
49
50REXX RETURN VALUE:
51 String of the format "bytes status", where bytes is the number of bytes
52 currently waiting in the pipe, and status is one of: DISCONNECTED,
53 LISTENING, CONNECTED, or CLOSING.
54
55
56-------------------------------------------------------------------------
[17]57Sys2Close
58
59Close a file or stream (wrapper to DosClose).
60
61REXX ARGUMENTS:
62 1. File handle (returned by Sys2Open). (REQUIRED)
63
64REXX RETURN VALUE:
65 1 on success, or 0 if an error occurred.
66
67
68-------------------------------------------------------------------------
[16]69Sys2ConnectNamedPipe
70
71Start 'listening' by allowing clients to connect to a previously-created
72named pipe.
73
74REXX ARGUMENTS:
75 1. The pipe handle, as returned by Sys2CreateNamedPipe. (REQUIRED)
76
77REXX RETURN VALUE:
78 1 on success, or 0 if an error occurred.
79
80
81-------------------------------------------------------------------------
82Sys2CreateNamedPipe
83
[17]84Creates a named pipe with the specified name and parameters. Only byte
85mode is supported; message mode is not.
[16]86
87Note that the standard REXX functions such as CHARIN/OUT, which operate
88directly on file names, are not capable of using the pipe handle returned
[19]89from this function. While the client end can use such functions after
[17]90using STREAM to issue an OPEN WRITE or OPEN READ command, the server end
[16]91needs to use the pipe handle from this function, and must therefore use
92Sys2Read/Sys2Write in order to read and write data from the pipe.
93
[17]94Named pipes can be created in inbound-only, outbound-only, or duplex
95(inbound/outbound) mode. An error will result if attempting to write
96to an inbound-only pipe, or read from an outbound-only pipe.
97
98To activate a named pipe so that client processes can connect to it, use
99Sys2ConnectNamedPipe. To check the pipe's connection status, as well as
100the amount of data currently in the pipe, use Sys2CheckNamedPipe. To
101unlock a named pipe after a client has closed the connection, use
[19]102Sys2DisconnectNamedPipe. Finally, the pipe can be destroyed using
103Sys2Close.
[17]104
[16]105REXX ARGUMENTS:
106 1. The name of the pipe, in the form "\PIPE\something". (REQUIRED)
107 2. The size of the outbound buffer, in bytes. (REQUIRED)
108 3. The size of the inbound buffer, in bytes. (REQUIRED)
109 4. The pipe's timeout value, in milliseconds. (DEFAULT: 3000)
110 5. The number of simultaneous instances of this pipe which are allowed.
111 Must be between 1 and 254, or 0 indicating no limit. (DEFAULT: 1)
112 6. Pipe blocking mode, one of:
113 W = WAIT mode, read and write block waiting for data (DEFAULT)
114 N = NOWAIT mode, read and write return immediately
115 7. Pipe mode, one of:
116 I = Inbound pipe (DEFAULT)
117 O = Outbound pipe
118 D = Duplex (inbound/outbound) pipe
119 8. Privacy/inheritance flag, one of:
120 0 = The pipe handle is inherited by child processes (DEFAULT)
121 1 = The pipe handle is private to the current process
122 9. Write-through flag, one of:
123 0 = Allow delayed writes (write-behind) to remote pipes (DEFAULT)
124 1 = Force immediate writes (write-through) to remote pipes
125
126REXX RETURN VALUE: A four-byte pipe handle.
127
128
129-------------------------------------------------------------------------
130Sys2DisconnectNamedPipe
131
132Unlocks a named pipe after a client has closed its connection.
133
134REXX ARGUMENTS:
135 1. The pipe handle, as returned by Sys2CreateNamedPipe. (REQUIRED)
136
137REXX RETURN VALUE:
138 1 on success, or 0 if an error occurred.
139
140
141-------------------------------------------------------------------------
[4]142Sys2DropFuncs
143
144Deregisters all Sys2* REXX functions.
145
146REXX ARGUMENTS: None
147REXX RETURN VALUE: ""
148
149
150-------------------------------------------------------------------------
151Sys2FormatTime
152
153Converts a number of seconds from the epoch (1970-01-01 0:00:00 UTC) into
154a formatted date and time string.
155
156REXX ARGUMENTS:
157 1. Number of seconds (a positive integer) to be converted. (REQUIRED)
158 This value cannot be greater than 2,147,483,647.
159 2. Format type, one of:
160 D = return in the form 'yyyy-mm-dd hh:mm:ss (w)' where w
161 represents the weekday (0-6 where 0=Sunday) (DEFAULT)
162 I = return in ISO8601 combined form 'yyyy-mm-ddThh:mm:ss[Z]'
163 L = return in the form 'day month year (weekday) time' where month
164 and weekday are language-dependent abbreviations
165 Note: With D and I, time is returned in 24-hour format; L may vary.
166 3. TZ conversion flag (indicates whether to convert to UTC from local
167 time), one of:
168 U = return UTC or unconverted time
169 L = assume the input is in Coordinated Universal Time, and convert
170 to local time using the current TZ (DEFAULT)
171
172REXX RETURN VALUE: The formatted time string, or "" on error.
173
174
175-------------------------------------------------------------------------
176Sys2GetClipboardText
177
178Retrieves a plain-text string from the clipboard if one is available.
179
180This function requires Presentation Manager to be active, although the
181REXX program itself need not be running in a PM process.
182
183REXX ARGUMENTS:
184 None.
185
186REXX RETURN VALUE: The retrieved clipboard string
187
188
189-------------------------------------------------------------------------
190Sys2GetEpochTime
191
192Converts formatted date and time into a number of seconds (UTC) from the
193epoch (defined as 1970-01-01 0:00:00). The input time is assumed to
194refer to the current timezone as defined in the TZ environment variable.
195
196If no parameters are specified, the current system time is used. If at
197least one parameter is specified, then any missing parameter is assumed
198to be its minimum possible value (1 for day or month, 0 for all others).
199
200The time is formatted according to the C runtime's locale support, as
201configured via the LANG and LC_* environment variables.
202
[19]203NOTE: Any date prior to 1 January 1970, or later than 19 January 2038,
204 cannot be supported due to the limitations in how the C library
205 calculates epoch time. Specifying any date before 1970 will generate
206 a REXX error. Any time/date later than 12:14:07 on 19 January 2038
207 will return the latter value.
208
[4]209REXX ARGUMENTS:
210 1. The year (1970-2037)
[19]211 A 2-digit year can be specified, in which case the number will be
212 added to 1900 if it is 70 or higher, or to 2000 otherwise.
213 e.g. '20' ==> 2020
214 '75' ==> 1975
215 (This is subject to the limitation noted above.)
[4]216 2. The month (1-12)
217 3. The day (1-31)
218 4. Hours (0-23)
219 5. Minutes (0-59)
220 6. Seconds (0-61)
221
222REXX RETURN VALUE: The number of seconds since the epoch, or 0 on error.
223
224
225-------------------------------------------------------------------------
226Sys2KillProcess
227
228Terminates the (first) running process with the specified executable name
229or process-ID.
230
231REXX ARGUMENTS:
232 1. The process identifier (program name or process ID) (REQUIRED)
233 2. Flag indicicating the identifier type:
234 'P': decimal process ID
235 'H': hexadecimal process ID
236 'N': executable program name (with or without extension) (DEFAULT)
237
238REXX RETURN VALUE: 1 on success or 0 on failure.
239
240
241-------------------------------------------------------------------------
242Sys2LoadFuncs
243
244Registers all Sys2* REXX functions (except this one, obviously).
245
246REXX ARGUMENTS: None
247REXX RETURN VALUE: ""
248
249
250-------------------------------------------------------------------------
[16]251Sys2LocateDLL
[4]252
[16]253Searches for a DLL by name and returns its fully-qualified path.
254
[4]255If a DLL with the given name is currently loaded, that instance of the
256DLL will be returned. Otherwise, standard DLL loading rules (according
257to the current LIBPATH and/or extended LIBPATH configuration) are used to
[16]258search for a DLL whose module name matches the one specified.
[4]259
[16]260REXX ARGUMENTS:
261 1. The name of the DLL to search for. (REQUIRED)
[4]262
263
[16]264REXX RETURN VALUE:
265 The fully-qualified path of the DLL, if found; "" otherwise.
266
267
[4]268-------------------------------------------------------------------------
[17]269Sys2Open
[4]270
[17]271Opens a file or other stream; files larger than 2GB are supported (this
272function is a wrapper to DosOpenL). Direct-DASD mode is not supported by
273this function, nor is setting the initial extended attributes.
274
275REXX ARGUMENTS:
276 1. Name of file or stream to open. (REQUIRED)
277 2. Open action flags, must be either "O" (open if exists), "R" (replace
278 if exists), or nothing (fail if exists), optionally followed by "C"
279 (create if file does not exist). If "C" is not specified, the
280 operation will fail if the file does not exist. Note that a value
281 of "" alone will therefore fail automatically. (DEFAULT: "O")
282 In summary, the possible combinations are:
283 O = Open only (if file exists, open it; if not, fail)
284 OC= Open/create (if file exists, open it; if not, create it)
285 R = Replace only (if file exists, replace it; if not, fail)
286 RC= Replace/create (if file exists, replace it; if not, create it)
287 C = Create only (if file exists, fail; if not, create it)
288 (empty) = No-op (if file exists, fail; if not, fail)
289 3. Access mode flags, one or both of: (DEFAULT: "RW")
290 R = Open file with read access.
291 W = Open file with write access.
292 4. Sharing mode flags, any combination of: (DEFAULT: "W")
293 R = Deny read access to other processes
294 W = Deny write access to other processes
295 5. Deny legacy DosOpen access, one of:
296 0 = Allow DosOpen to access the file (DEFAULT)
297 1 = Deny access using the DosOpen API
298 6. Privacy/inheritance flag, one of:
299 0 = The file handle is inherited by child processes. (DEFAULT)
300 1 = The file handle is private to the current process.
301 7. Initial file attributes when creating a file: (DEFAULT: "")
302 A = Archive attribute set
303 D = Directory attribute set
304 S = System attribute set
305 H = Hidden attribute set
306 R = Read-only attribute set
307 8. Initial file size when creating or replacing a file; ignored if
308 access mode is read-only. (DEFAULT: 0)
309 9. I/O mode flags, any or all of: (DEFAULT: "")
310 T = Write-through mode (default is normal write)
311 N = No-cache mode (default is to use filesystem cache)
312 S = Sequential access
313 R = Random access
314 * S and R can combine as follows:
315 Neither: No locality known (default)
316 S only: Mainly sequential access
317 R only: Mainly random access
318 Both: Random/sequential (i.e. random with some locality)
319
320REXX RETURN VALUE:
321 File handle, or "" in case of error.
322
323
324-------------------------------------------------------------------------
[4]325Sys2PutClipboardText
326
327Writes a string to the clipboard in plain-text format. Specifying either
328no value or an empty string in the first argument will simply clear the
329clipboard of CF_TEXT data.
330
331This function requires Presentation Manager to be active, although the
332REXX program itself need not be running in a PM process.
333
334REXX ARGUMENTS:
335 1. String to be written to the clipboard (DEFAULT: "")
336 2. Flag indicating whether other clipboard formats should be cleared:
337 Y = yes, call WinEmptyClipbrd() before writing text (DEFAULT)
338 N = no, leave (non-CF_TEXT) clipboard data untouched
339
340REXX RETURN VALUE: 1 on success, 0 on failure
341
342
343-------------------------------------------------------------------------
344Sys2QueryForegroundProcess
345
[20]346Queries the PID of the current foreground process. (Note that this is not
347necessarily the same as the process which is calling this function, which
348could, for example, be running in the background and/or as a child of the
349foreground process.)
[4]350
351REXX ARGUMENTS: None
352
353REXX RETURN VALUE:
354 Integer representing the process ID (in decimal), or 0 if an error
355 occurred.
356
357
358-------------------------------------------------------------------------
359Sys2QueryPhysicalMemory
360
361Queries the amount of physical memory (RAM) installed in the system.
362
363REXX ARGUMENTS: None
364
365REXX RETURN VALUE:
366 Integer representing the amount of installed memory, in KiB, or 0 if an
367 error occurred.
368
369
370-------------------------------------------------------------------------
371Sys2QueryProcess
372
373Queries information about the specified process.
374
[20]375Specifying a process ID of 0 will return the information for the
376current process (that is, the process calling this function); note that
377this requires the second parameter to specify that the identifier is in
378fact a process ID ('P' or 'H') rather than an executable name.
379
[4]380REXX ARGUMENTS:
381 1. The process identifier (program name or process ID) (REQUIRED)
382 2. Flag indicicating the identifier type:
383 'P': decimal process ID
384 'H': hexadecimal process ID
385 'N': executable program name (with or without extension) (DEFAULT)
386
387REXX RETURN VALUE:
388 A string of the format
389 pid parent-pid process-type priority cpu-time executable-name
390 "priority" is in hexadecimal notation, all other numbers are decimal.
391 "" is returned if the process was not found or if an internal error
392 occurred.
393
394
395-------------------------------------------------------------------------
396Sys2QueryProcessList
397
398Gets a list of running processes. The results will be returned in a stem
[16]399variable, where stem.0 contains number of items, and each stem item is a
[4]400string of the form:
401 pid parent-pid process-type priority cpu-time executable-name
402"priority" is in hexadecimal notation, all other numbers are decimal.
403
404Notes:
405 - "process-type" will be one of:
406 0 Full screen protect-mode session
407 1 Requires real mode. Dos emulation.
408 2 VIO windowable protect-mode session
409 3 Presentation Manager protect-mode session
410 4 Detached protect-mode process.
411 - If "priority" is 0 then the priority class could not be determined.
412 - If "executable-name" is "--" then the name could not be identified.
413
414REXX ARGUMENTS:
415 1. The name of the stem in which to return the results (REQUIRED)
416
417REXX RETURN VALUE: Number of processes found, or "" in case of error.
418
419
420-------------------------------------------------------------------------
[16]421Sys2Read
422
[17]423Read bytes from a previously-opened stream (wrapper to DosRead).
[16]424
425REXX ARGUMENTS:
[17]426 1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
427 (REQUIRED)
[16]428 2. Number of bytes to read. (REQUIRED)
429
430REXX RETURN VALUE:
431 String containing the bytes read, or "" in case of error.
432
433
434-------------------------------------------------------------------------
[4]435Sys2ReplaceModule
436
437Unlocks and optionally replaces an in-use (locked) DLL or EXE.
438
439REXX ARGUMENTS:
440 1. The filespec of the module to be replaced. (REQUIRED)
441 2. The filespec of the new module to replace it with. (DEFAULT: none)
442 3. The filespec of the backup file to be created. (DEFAULT: none)
443
444REXX RETURN VALUE:
445 1 on success, or 0 if an error occurred.
446
447
448-------------------------------------------------------------------------
[17]449Sys2Seek
450
451Move the read/write pointer to the specified location in an open
452file/stream; files larger than 2GB are supported (this function is a
453wrapper to DosSetFilePtrL).
454
455REXX ARGUMENTS:
456 1. File handle (returned by Sys2Open). (REQUIRED)
457 2. The signed distance in bytes to move. (REQUIRED)
458 3. Move method, one of:
459 B = Beginning of file
460 C = Current position (DEFAULT)
461 E = End of file
462
463REXX RETURN VALUE:
464 The new file position, in bytes.
465
466
467-------------------------------------------------------------------------
[4]468Sys2Version
469
470Returns the current library version.
471
472REXX ARGUMENTS: None
473REXX RETURN VALUE: Current version in the form "major.minor.refresh"
474
[17]475
476-------------------------------------------------------------------------
477Sys2Write
478
479Write bytes to a previously-opened stream (wrapper to DosWrite).
480
481REXX ARGUMENTS:
482 1. File handle (as returned by Sys2Open or Sys2CreateNamedPipe).
483 (REQUIRED)
484 2. Data to be written. (REQUIRED)
485
486REXX RETURN VALUE:
487 The number of bytes successfully written.
488
Note: See TracBrowser for help on using the repository browser.