-> Home

REXX utilities beyond REXXUTIL for OS/2

This is a (growing) collection of miscellaneous REXX utility functions and code fragments. Some of them are coded in REXX others in C.

Version: 0.2 (4 Aug 2002)

Quick guide Download Reference (REXX) Reference (C-DLL) History Contact

This font indicates things you can type in.
Italic in addition indicates parameters, which have to be replaced by meaningful values.
Things in [braces] are optional.


Quick guide


Download

This utility functions are freeware.

ZIP file with source and this guide: Version 0.2


RXMMUTL.CMD Reference (REXX-Functions)

All of the following functions are part of the script RXMMUTL.CMD. You may copy them into your own REXX scripts.

ToUnixTime UnixTime StringMatchQ StringReplace

Parse command line

This code fragment will split a command line string into arguments, properly handling and removing quotion marks (").
params = STRIP(ARG(1))
DO WHILE params \= ''
   IF LEFT(params,1) = '"' THEN DO
      PARSE VAR params '"'param'"'params
      params = STRIP(params, 'L')
      END
    ELSE
      PARSE VAR params param params
   /* param is the next parameter to process ... */
   IF (LEFT(param, 1) = '/') | (LEFT(param, 1) = '-') THEN
      SELECT
         /* parsing options ... */

       OTHERWISE
         SAY "illegal option '"param"'"
         END

    ELSE DO
      /* any other arg ... */

      END
   END
  

ToUnixTime(year, mon, day, hour, min, sec)

Convert time to unix format (seconds since 01.01.1970 0:00).
year
Year (4 digits ! E.g. 1997)
mon
Month (1-12)
day
Day of month (1-31)
hour
Hours (0-23)
min
Minutes (0-59)
sec
Seconds (0-59)
Return value
Unix time
Notes:
  1. Be sure to set NUMERIC DIGITS at least to 10. The default of 9 overflowed on 9. Sep. 2001 1:46:40 (AM).
  2. Be careful with the function arguments as there are no consistency checks at all.
  3. This function will ignore time zones. It will only work correctly if the time is GMT.

UnixTime

Get current time in unix time format (seconds since 01.01.1970 0:00).
Parameter
None
Return value
Current time (Unix format)
This is similar to the C function time(NULL). However, the result is localtime rather than GMT.

StringMatchQ(string, template)

Check if string matches a template string containing wildcard characters (*,?).
string
String to check
template
Template string
? represents any character.
* represents any sequence of zero or more characters.
Return value
1 (true) string matched
0 (false) string does not match

StringReplace(string, find, replace[, find, replace[,...])

Replace substrings.
string
String to modify
find
Find find and ...
replace
... replace with replace
Return value
Modified string
This is the same than the Obeject REXX function CHANGESTR(find, string, replace), if you specify only one replacement rule and if you have Object REXX.


RXMMUTL.DLL Reference (external C Functions)

MMTranslateCp MMUpper MMTime MMSetFileSize MMFileMove MMHash

MMLoadFuncs

Register any function in rxmmutl.dll (except for MMLoadFuncs, of course).
Parameter
None
Return value
Empty string
Note: You usually want to register this function first:
IF RxFuncAdd("MMLoadFuncs", "RxMMutl", "MMLoadFuncs") = 0 THEN
   CALL MMLoadFuncs
  

MMDropFuncs

Deregister all functions from rxmmutl.dll.
Parameter
None
Return value
Empty string

MMTranslateCp(string, [sourceCP], [destinationCP], [substitutionchar])

Translate string from one codepage to another.
The source and destination codepage is not restricted to the ones prepared in the CONFIG.SYS with the CODEPAGE statement. See description of WinCpTranslateChar for a list of supported codepages.
string
String to translate
sourceCP
Source codepage
If ommitted the current active codepage is used.
destinationCP
Destination codepage
If ommitted the current active codepage is used.
substitutionchar
Substitution character for untranslatable characters.
This argument must be at most one character in length. By default D2C(255) is used. The null string, '', has a special meaning: it supresses the conversion of untranslatable characters at all. You should be careful with this option, because it usually results in bogus characters in the destination codepage. However, it may have useful side effects.
Return value
Translated string

MMUpper(string, [codepage], [country])

Translate string to uppercase.
In comparsion to TRANSLATE(string) this takes care of special characters like umlauts.
string
String to translate
codepage
codepage
If ommitted the current active codepage is used.
country
Country code
If ommitted the current country code defined in the CONFIG.SYS is used. I don't really know the influence of this parameter. Normally you can drop it.
Return value
Uppercase string
Note: This function is similar to the in Classic REXX undocumented REXXUTIL function SysMapCase.

MMTime

Return time in UNIX time format (seconds since 01.01.1970 0:00). This is the return value of the C library function time(NULL).
Parameter
None
Return value
UNIX time

MMSetFileSize(filename, newsize)

Modify size of file. The file can be truncated or extended.
filename
Name of the file to modify
newsize
New size of the file in bytes
Return value
0 - file size changed successfully
otherwise - OS/2 error code

MMFileMove(oldname, newname)

Move and/or rename a file or directory.
oldname
Current name of the file or directory to move/rename
newname
New path and/or name of the file or directory (The driveletter must be omitted or the same as before)
Return value
0 - file moved/renamed successfully
otherwise - OS/2 error code

MMHash(data, hashtype)

Create a hash value from data.
data
Input data
hashtype
One of: Adler32, CRC32, HAVAL, MD2, MD4, MD5, RIPEMD160, SHA, SHA256, SHA384, SHA512, Tiger
Return value
Hash value
The leghth of the hash value depends on the hash type.


History

Version 0.2 (4 Aug 2002)

Version 0.1 (first release)


Build instructions

Use the included makefile to biuld RXMMUTL.DLL. I used gcc 3.0 for EMX OS/2. However, it should work with other C++ compilers too. There should be no gcc specific elements in the code. In contrast, the makefile contains gcc specific parameters.

Since version 0.2 you must have libcryptopp, which is not included in this package. However, if you don't want to include this bulky library simply remove the compile time option -DHAVE_CRYPTLIB. (See the comment in the makefile.) Of course, the relating functions will not work in this case. (currently only MMHash)


Contact

Suggestions, help, complaints (but not too much:-): mueller@maazl.de

Original homepage: http://www.maazl.de/project/rxmmutl/index.html