source: rxutilex/trunk/FUNCTIONS@ 29

Last change on this file since 29 was 29, checked in by Alex Taylor, 10 years ago

Added optional second parameter to Sys2LocateDLL, and updated/clarified function documentation.

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