home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxalgo.zip
/
RexxAlgo.INF
(
.txt
)
< prev
next >
Wrap
OS/2 Help File
|
1997-08-28
|
62KB
|
1,700 lines
ΓòÉΓòÉΓòÉ 1. About ... ΓòÉΓòÉΓòÉ
RexxAlgo is a collection of various REXX source codes routines.
Refer to the chapters:
REXX Algorithms,
Available source code or
Using and testing
for more information, please .
ΓòÉΓòÉΓòÉ 2. Notices ΓòÉΓòÉΓòÉ
This chapter refers to:
Disclaimer,
Copyright,
Author.
ΓòÉΓòÉΓòÉ 2.1. Disclaimer. ΓòÉΓòÉΓòÉ
This package is provided as is, without any guarantees or warrantees
whatsoever. The author is not liable or responsible for any loss or
damage of any kind whatsoever, including, but not limited to, losses
of a financial, physical, emotional, marital, social, or mental
nature that may result from the use or the purported use of anything
in this package, for any purpose whatsoever.
Thanks to Michael Shillingford for this wording.
ΓòÉΓòÉΓòÉ 2.2. Copyright. ΓòÉΓòÉΓòÉ
(C) Copyright Janosch R. Kowalczyk, 1996, 1997. All rights reserved.
You may distribute this document in the original format to any one.
You can use this document and software for all non-commercial
purposes only. Commercial users must obtain the permission of the
author first.
You aren't allowed to distribute this document in printed form
without the written permission of the author
ΓòÉΓòÉΓòÉ 2.3. Author. ΓòÉΓòÉΓòÉ
Janosch R. Kowalczyk
Oberwaldstrasse 42
D-63538 Grosskrotzenburg
GERMANY
Telephone 0049 6186 201676
CompuServe 101572,2160 Please send your improvement suggestions
Internet 101572.2160@compuserve.com and your bug reports via email.
ΓòÉΓòÉΓòÉ 3. Current version. ΓòÉΓòÉΓòÉ
The current version of Rexx Algorithms is 1.31.
The current source files are:
RXALG131.CMD
RXALG131.FNC (for Greed)
Last revision date: July 2, 1997
ΓòÉΓòÉΓòÉ 4. REXX algorithms - introduction. ΓòÉΓòÉΓòÉ
I work as a systems programmer for MVS security systems and I work
quite often under both the TSO and OS/2 environments. That's why I'm
so happy to have Rexx - I can write my programs only once and they
work on these two systems.
I've written already a lot of Rexx programs. Doing this I wrote many
simple but rather useful Rexx subroutines. They are both common
well-known algorithms and my own solutions for Rexx or OS specific
problems.
I think that many Rexx programmers can use these subroutines to solve
their problems and not have to develop these things for themselves.
The file RXALGxxx.* contains the collection of my useful Rexx
algorithms. These algorithms are at the Release 1.31 level and are
subdivided into the following thematic groups:
1. Searching and sorting.
Binary search (BiSearch)
Bubble sort (BubSort)
Insertion sort (InsSort)
Quick sort (QSort)
Shell sort (ShlSort)
2. Date and time.
Gregorian date to Julian date (G2J)
Julian date to Gregorian date (J2G)
Date with century (Date2000)
3. Strings.
Translate umlauts to lower case (ToLower)
Recursive formatting (Combine)
Replace a string (ReplaceString)
Remove umlaut characters (NoUmlaut). This is a sample for
using ReplaceString.
4. Mathematical functions.
Square root evolution (SqrRoot)
Cube root evolution (CubeRoot)
Greatest common divisor (EuclidGCD)
5. File system.
Recursive creating directory path (MakePath)
Delete directory path (ErasePath)
6. Multimedia.
Digital Audio Player with mciRexx (PlayFile)
7. Miscellaneous.
Exclude multiple items (NoMult)
All these code templates are written as internal subroutines. I
have placed the same subroutines into two files:
first, as plain text into the Rexx command file named
RXALGxxx.CMD
secondly, as code templates in the function file for GREED's
Templates Controller, named RXALGxxx.FNC (INI format).
where xxx is the release number, e.g. : for 1.31, xxx is 131.
ΓòÉΓòÉΓòÉ 5. Searching and sorting. ΓòÉΓòÉΓòÉ
This chapter describes several classical search and sort algorithms,
as follows:
Binary search,
Bubble sort,
Insertion sort,
Quick sort,
Shell sort.
ΓòÉΓòÉΓòÉ 5.1. Binary search ΓòÉΓòÉΓòÉ
Function name:
BiSearch
Syntax:
foundIndex = BiSearch( value )
Function:
Binary search a stem variable for a value
Calling parameter:
Searched-for value
Returns:
index of the found value,
0 if nothing found.
Notes:
The elements to search for must be saved in the stem named in this
procedure (default name "STEM."). stem.0 contains the number of
elements in stem. The stem variable must be in sorted order.
Sample call:
foundIndex = BiSearch(value)
If foundIndex = 0 Then
Say 'Value' value 'not found!'
Else
Say stem.foundIndex
Source code:
BiSearch
ΓòÉΓòÉΓòÉ 5.2. Bubble sort. ΓòÉΓòÉΓòÉ
Function name:
BubSort
Syntax:
Call BubSort
Function:
Sort of a stem variable using the Bubble sort algorithm.
Call parameter:
No
Returns:
nothing (NULL string)
Notes:
The elements to sort for must be saved in the stem named so as the
stem in this procedure (in this case "STEM."). stem.0 must contain
the number of elements in stem.
Source code:
BubSort
ΓòÉΓòÉΓòÉ 5.3. Insertion sort. ΓòÉΓòÉΓòÉ
Function name:
InsSort
Syntax:
Call InsSort
Function:
Sort of a stem variable using the Insertion sort algorithm.
Call parameter:
No
Returns:
nothing (NULL string)
Notes:
The elements to sort for must be saved in the stem named in this
procedure (in this case "STEM."). stem.0 contains the number of
elements in stem.
Source code:
InsSort
ΓòÉΓòÉΓòÉ 5.4. Quick sort. ΓòÉΓòÉΓòÉ
Function name:
QSort
Syntax:
Call QSort
Function:
Sort of a stem variable using the Quick sort algorithm.
Call parameter:
No
Returns:
Left-Right span
Notes:
The elements to sort for must be saved in the stem named in this
procedure (in this case "STEM."). stem.0 contains the number of
elements in stem.
Source code:
QSort
ΓòÉΓòÉΓòÉ 5.5. Shell sort. ΓòÉΓòÉΓòÉ
Function name:
ShlSort
Syntax:
Call ShlSort
Function:
Sort of a stem variable using the Shell sort algorithm.
Call parameter:
No
Returns:
nothing (NULL string)
Notes:
The elements to sort for must be saved in the stem named in this
procedure (in this case "STEM."). stem.0 contains the number of
elements in stem.
Source code:
ShlSort
ΓòÉΓòÉΓòÉ 6. Date and time. ΓòÉΓòÉΓòÉ
This chapter describes useful date algorithms:
translate Gregorian date to Julian date,
translate Julian date to Gregorian date,
get Year with century.
ΓòÉΓòÉΓòÉ 6.1. Translate Gregorian date to Julian date. ΓòÉΓòÉΓòÉ
Function name:
G2J
Syntax:
julDate = G2J( yyyy.mm.dd )
Function:
Translates Gregorian date to the Julian date.
Call parameter:
Gregorian date in format yyyy.mm.dd
Returns:
Julian date in format yyyy.ddd
Source code:
G2J
ΓòÉΓòÉΓòÉ 6.2. Translate Julian date to Gregorian date. ΓòÉΓòÉΓòÉ
Function name:
J2G
Syntax:
gregDate = J2G( yyyy.ddd )
Function:
Translates Julian date to the Gregorian date.
Call parameter:
Julian date in format yyyy.ddd
Returns:
Gregorian date in format yyyy.mm.dd
Source code:
J2G
ΓòÉΓòÉΓòÉ 6.3. Year with century. ΓòÉΓòÉΓòÉ
Function name:
Date2000
Syntax:
Date = Date2000( Option )
Function:
Same output as the Rexx built-in function Date() but includes the
century with the year. Has also an additional option, J.
Call options and Returns:
blank - Returns dd Mmm yyyy
B - Returns dddddd days since 01.01.0001
D - Returns ddd - days in the current year
E - Returns dd/mm/yyyy
J - Returns yyyy.ddd - Julian date
L - Returns dd Month yyyy
M - Returns Month
N - Returns dd Mmm yyyy
O - Returns yyyy/mm/dd
S - Returns yyyymmdd
U - Returns mm/dd/yyyy
W - Returns Weekday
Source code:
Date2000
ΓòÉΓòÉΓòÉ 7. String functions. ΓòÉΓòÉΓòÉ
This chapter details some useful algorithms to:
format a string recursively,
translate umlauts to lower case,
replace a substring by another.
remove umlaut characters,
ΓòÉΓòÉΓòÉ 7.1. Format a string recursively. ΓòÉΓòÉΓòÉ
Function name:
Combine
Syntax:
formStr = Combine( _combStr, _combLen, [_combTooth], [_combRep] )
Function:
Recursive formatting of a string with a constant interval.
Call parameter:
_combStr - string to be formated,
_combLen - string's length,
_combTooth - new format string (optinal),
_combRep - format interval (optional)
Returns:
Formated string
Notes:
Default value for _combTooth is a blank, default value for _combRep
is 1. _combTooth will be inserted into the _combStr at the position
computed as follows:
_combLen = _combLen - _combRep
Sample call:
formStr = Combine( '10000000000', 11, ',', 3 )
/* Input string = '10000000000' */
/* String length = 11 */
/* Format string = ',' */
/* Interval = 3 */
/* Output string = '10,000,000,000' */
Source code:
Combine
ΓòÉΓòÉΓòÉ 7.2. Translate umlauts to lower case. ΓòÉΓòÉΓòÉ
Function name:
ToLower
Syntax:
lowString = ToLower( upperString )
Function:
Translate entire string to lower case.
Call parameter:
String to translate
Returns:
Translated string
Notes:
Simply change variables 'Lowers' and 'Uppers' to get the function
ToUpper
Source code:
ToLower
ΓòÉΓòÉΓòÉ 7.3. Replace a substring by an another. ΓòÉΓòÉΓòÉ
Function name:
ReplaceString
Syntax:
tranStr = ReplaceString( _string, _origin, _replStr )
Function:
Find all occurrences of a substring and replace it by an another
(such as built-in functions Overlay and Insert together).
Call parameter:
_string - input string,
_origin - substring to be replaced,
_replStr - replace substring.
Returns:
Translated string
Source code:
ReplaceString
ΓòÉΓòÉΓòÉ 7.4. Remove umlaut characters. ΓòÉΓòÉΓòÉ
Function name:
NoUmlaut
Syntax:
tranStr = NoUmlaut( uString,['U'] )
Function:
Replace umlaut characters with double character strings (Д -> ae, Ф
-> oe, Б -> ue, с -> ss)
Call parameter:
_string - string with umlauts,
_upper - ('U') upper case return string (optional)
Returns:
Translated string
Notes:
This function calls the function ReplaceString.
Source code:
NoUmlaut
ΓòÉΓòÉΓòÉ 8. Mathematical functions. ΓòÉΓòÉΓòÉ
In this chapter you will find the following algorithms:
Square root evaluation.
Cube root evaluation.
Greatest common divisor.
ΓòÉΓòÉΓòÉ 8.1. Square root evaluation. ΓòÉΓòÉΓòÉ
Function name:
SqrRoot
Syntax:
sqrt = SqrRoot( number, [precision] )
Function:
Square root evaluation for the called parameter.
Call parameter:
evaluation number,
precision (optional)
Returns:
Square root of the called parameter
Notes:
Precision is the highest possible error for the evaluation. Default
Value of the precision is 0.00001. You are responsible for the valid
number values.
Source code:
SqrRoot
ΓòÉΓòÉΓòÉ 8.2. Cube root evaluation. ΓòÉΓòÉΓòÉ
Function name:
Cube root
Syntax:
gcd = CubeRoot( _digit, _precision )
Function:
Cube root evolution.
Call parameter: Call parameters are two digits. The first one is the
digit for which you want to compute the cube root, the second is the
precision of the calculation. The precision is a decimal fraction
number e.g.: 0.00000001.
Returns:
cube root.
Notes:
You are responsible for the valid number values
Source code:
Cube root
ΓòÉΓòÉΓòÉ 8.3. Greatest common divisor. ΓòÉΓòÉΓòÉ
Function name:
EuclidGCD
Syntax:
gcd = EuclidGCD( _counter, _denuminator )
Function:
Euclid's algorithm to obtain the greatest common divisor.
Call parameter: Call parameters are two digits, for which the
function computes the greatest common divisor.
Returns:
greatest common divisor.
Notes:
You are responsible for the valid number values
Source code:
Euclid
ΓòÉΓòÉΓòÉ 9. File system. ΓòÉΓòÉΓòÉ
This chapter describes algorithms to:
recursively create a directory path,
delete a directory path.
ΓòÉΓòÉΓòÉ 9.1. Recursively create a directory path. ΓòÉΓòÉΓòÉ
Function name:
MakePath
Syntax:
_destPath = MakePath( _destPath )
Function:
Recursive creating of the directory path
Call parameter:
_destPath - directory path
Returns:
directory path Source code:
MakePath
ΓòÉΓòÉΓòÉ 9.2. Delete a directory path. ΓòÉΓòÉΓòÉ
Function name:
ErasePath
Syntax:
_erasePath = ErasePath( _erasePath )
Function:
Delete complete directory path
Call parameter:
_erasePath - directory path to be deleted
Returns:
_erasePath
Notes:
Only empty directories will be deleted.
Source code:
ErasePath
ΓòÉΓòÉΓòÉ 10. Multimedia. ΓòÉΓòÉΓòÉ
This chapter details an algorithm to:
Play a digital WAV/MID-audio file.
ΓòÉΓòÉΓòÉ 10.1. Play a digital audio file. ΓòÉΓòÉΓòÉ
Function name:
PlayFile
Syntax:
rc = PlayFile( audio_file_name )
Function:
Play digital WAV/MID file.
Call parameter:
Fully qualified file name to play
Returns:
RC from the last call of the mciRexx function
Source code:
PlayFile
ΓòÉΓòÉΓòÉ 11. Miscellaneous. ΓòÉΓòÉΓòÉ
In this chapter are described some useful algorithms to:
exclude multiple items from a stem.
ΓòÉΓòÉΓòÉ 11.1. Exclude multiple items from a stem. ΓòÉΓòÉΓòÉ
Function name:
NoMult
Syntax:
Call NoMult
Function:
Excludes multiple items from a sorted stem variable.
Call parameter:
no
Returns:
0
Notes:
The elements to exclude must be saved in the stem named in this
Procedure (in this case "STEM."). stem.0 contains the number of
elements in stem. The stem variable must be previously sorted
Source code:
NoMult
ΓòÉΓòÉΓòÉ 12. Source codes. ΓòÉΓòÉΓòÉ
This chapter describes all the Rexx functions currently available in
this product. Refer to the chapter Available source codes for more
information.
ΓòÉΓòÉΓòÉ 12.1. Available source codes. ΓòÉΓòÉΓòÉ
In this chapter is the source code of the following Rexx internal
procedures:
BiSearch
Binary search
BubSort
Bubble sort
Combine
Recursive string formatting
CubeRoot
Cube root
Date2000
Year with century
ErasePath
Delete directory path
EuclidGCD
Greatest common divisor
G2J
Gregorian to julian date
InsSort
Insertion sort
J2G
Julian to gregorian date
MakePath
Recursive directory path creating
NoMult
Exclude multiple items
NoUmlaut
Remove umlaut characters
PlayFile
Digital Audio Player (mciRexx)
QSort
Quick sort
ReplaceString
Replace a string
ShlSort
Shell sort
SqrRoot
Square root
ToLower
To lower case
ΓòÉΓòÉΓòÉ 12.2. BiSearch ΓòÉΓòÉΓòÉ
/*==================(Binary search)===================*/
/* :-D 1 */
/* Name.......: BiSearch */
/* */
/* Function...: Search a stem variable for a value */
/* Call parm..: Search value */
/* Returns....: 0 if nothing found */
/* index of the found value */
/* Sample call: found_index = BiSearch(value) */
/* If found_index = 0 Then */
/* Say 'Value' value 'not found!' */
/* Else */
/* Say stem.found_index */
/* */
/* Notes......: The elements to search for must be */
/* saved in the stem named in this */
/* procedure (default name "STEM."). */
/* stem.0 must contain the number of */
/* elements in stem. */
/* The stem variable must be in sorted */
/* order */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
BiSearch: Procedure Expose stem.
Parse Arg value /* Search value */
found = 0 /* Index of the found Item */
bottom = 1 /* Index of the first Item */
top = stem.0 /* Index of the last Item */
Do While found = 0 & top >= bottom
mean = (bottom + top) % 2
If value = stem.mean Then
found = mean
Else If value < stem.mean Then
top = mean - 1
Else
bottom = mean + 1
End /* Do While */
Return found
ΓòÉΓòÉΓòÉ 12.3. BubSort ΓòÉΓòÉΓòÉ
/*===================(Bubble sort)===================*/
/* :-I */
/* Name.......: BubSort */
/* */
/* Function...: Bubble Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call BubSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/*===================================================*/
BubSort: Procedure Expose stem.
/*------------(Bubble Sort for the Stem)-------------*/
Do i = stem.0 To 1 By -1 Until flip_flop = 1
flip_flop = 1
Do j = 2 To i
m = j - 1
If stem.m > stem.j Then Do
xchg = stem.m
stem.m = stem.j
stem.j = xchg
flip_flop = 0
End /* If stem.m ... */
End /* Do j = 2 ... */
End /* Do i = stem.0 ... */
Return ''
ΓòÉΓòÉΓòÉ 12.4. Combine ΓòÉΓòÉΓòÉ
/*==============( Recursive formatting )==============*/
/* 14 */
/* Name.......: Combine */
/* */
/* Function...: Format recursive a string */
/* */
/* Call parm..: _combStr - string to format, */
/* _combLen - string's length, */
/* _combTooth - format string (opt.), */
/* _combRep - format interval (opt.) */
/* */
/* Returns....: formated string */
/* */
/* Syntax.....: */
/* formStr = Combine( Str, Len, Tooth, Rep ) */
/* */
/* Notes......: Default value for _combTooth is a */
/* blank */
/* Default value for _combRep is 1 */
/* */
/* Method of working: */
/* _combTooth will be inserted into the */
/* _combStr at the position computed as */
/* follows: */
/* _combLen = _combLen - _combRep */
/* */
/* Sample.....: Input string = '10000000000' */
/* Format string = '.' */
/* Interval = 3 */
/* */
/* Output string = '10.000.000.000' */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
Combine: Procedure
Parse Arg _combStr, _combLen, _combTooth, _combRep
/*----(End processing and return formated string)-----*/
If _combLen < 1 | DataType(_combLen, 'N') = 0 Then
Return _combStr
/*---(Check call parameter and set default values)----*/
_combLen = Trunc( _combLen )
If _combTooth = '' Then
_combTooth = ' '
If _combRep < 1 | DataType(_combRep, 'N') = 0 Then
_combRep = 1
Else If _combRep >= _combLen Then
Return _combStr
_combRep = Trunc( _combRep )
/*---------(Set new value for Insert position)---------*/
_combLen = _combLen - _combRep
/*---------(Call recursive for the naxt step)----------*/
Return Combine( Insert( _combTooth, _combStr, _combLen ),,
_combLen,,
_combTooth,,
_combRep )
ΓòÉΓòÉΓòÉ 12.5. Date2000 ΓòÉΓòÉΓòÉ
/*=======(Translate year to year with century)========*/
/* 13 */
/* Name.......: Date2000 */
/* */
/* Function...: Translates year to year with century */
/* Call option: Returns dd Mmm yyyy */
/* B Returns dddddd days since 01.01.0001*/
/* D Returns ddd - days */
/* E Returns dd/mm/yyyy */
/* J Returns yyyy.ddd - julians date */
/* L Returns dd Month yyyy */
/* M Returns Month */
/* N Returns dd Mmm yyyy */
/* O Returns yyyy/mm/dd */
/* S Returns yyyymmdd */
/* U Returns mm/dd/yyyy */
/* W Returns Weekday */
/* */
/* Syntax.....: Date = Date2000(Option) */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
Date2000: Procedure
Parse Value Arg(1) With Option +1 .
If Option = '' Then Return Date()
If Verify('EJOU', Option, 'M') > 0 Then Do
Parse Value Date() With . . yyyy
If Option = 'J' Then Return yyyy || '.' || Date('D')
Else If Option = 'O' Then Do
Parse Value Date(Option) With . +2 Rest
Return yyyy || Rest
End
Else Do
Parse Value Date(Option) With Rest +6 .
Return Rest || yyyy
End
End
Else Return Date(Option)
ΓòÉΓòÉΓòÉ 12.6. ErasePath ΓòÉΓòÉΓòÉ
/*==============( Delete Directory Path )=============*/
/* 18 */
/* Name.......: ErasePath */
/* */
/* Function...: delete directory path */
/* */
/* Call parm..: _erasePath - directory path to be */
/* deleted */
/* */
/* Returns....: formated string */
/* */
/* Syntax.....: */
/* _erasePath = ErasePath( _erasePath ) */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
/*-------------(Delete Directory Path)------------*/
ErasePath: Procedure
Arg _erasePath
_erasePath = Strip( _erasePath, , '\' )
Do Until Pos('\', _erasePath) = 0
rc = SysRmDir( _erasePath )
If rc > 0 Then
Say 'Directory:' _erasePath 'not deleted. RC=' rc
Else
Say _erasePath 'successful deleted'
_erasePath = SubStr( _erasePath, 1, LastPos('\', _erasePath) - 1)
End
Return _erasePath
ΓòÉΓòÉΓòÉ 12.7. G2J ΓòÉΓòÉΓòÉ
/*==================(Translate date)=================*/
G2J: Procedure
/*---------------------------------------------------*/
/* */
/* Procedure name: G2J */
/* Function : translates gregorian date to the */
/* julian date */
/* Syntax : julDate = G2J(yyyy.mm.dd) */
/* Changes : */
/* */
/* Author : Janosch R. Kowalczyk */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/* Made use of GREED. 09 Jul 1996 / 13:21:56 JRK */
/*---------------------------------------------------*/
Arg gregDate
year = SubStr(gregDate,1,4)
mon = SubStr(gregDate,6,2) + 0
day = SubStr(gregDate,9,2)
mon.0 = 12
mon.1 = 0
mon.2 = 31
mon.3 = 59
mon.4 = 90
mon.5 = 120
mon.6 = 151
mon.7 = 181
mon.8 = 212
mon.9 = 243
mon.10 = 273
mon.11 = 304
mon.12 = 334
If (year // 400 = 0 | (year // 100 > 0 & year // 4 = 0)) & mon > 2 Then
leap = 1
Else leap = 0
julDay = mon.mon + day + leap
Return year'.'Right(julDay,3,'0')
ΓòÉΓòÉΓòÉ 12.8. InsSort ΓòÉΓòÉΓòÉ
/*=================(Insertion sort)===================*/
/* :-! 3 */
/* Name.......: InsSort */
/* */
/* Function...: Insertion Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call InsSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
InsSort: Procedure Expose stem.
Do x = 2 To stem.0
xchg = stem.x
Do y = x - 1 By -1 To 1 While stem.y > xchg
xchg = stem.x
stem.x = stem.y
stem.y = xchg
x = y
End /* Do y = x... */
stem.x = xchg
End /* Do x = 2 ... */
Return ''
ΓòÉΓòÉΓòÉ 12.9. J2G ΓòÉΓòÉΓòÉ
/*==========(Julian Date to Gregorian Date)==========*/
J2G: Procedure
/*---------------------------------------------------*/
/* */
/* Program name: J2G */
/* Function : translates julian to gregorian */
/* date */
/* Syntax : J2G yyyy.ddd */
/* Author : Janosch R. Kowalczyk */
/* Changes : */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/* Made use of GREED. 09 Jul 1996 / 18:08:30 JRK */
/*---------------------------------------------------*/
Arg julDate
Parse Var julDate year'.'jday
mon.0 = 12
mon.1 = 0
mon.2 = 31
mon.3 = 59
mon.4 = 90
mon.5 = 120
mon.6 = 151
mon.7 = 181
mon.8 = 212
mon.9 = 243
mon.10 = 273
mon.11 = 304
mon.12 = 334
If year // 400 = 0 | (year // 100 > 0 & year // 4 = 0) Then
leap = 1
Else
leap = 0
Do i = 1 To mon.0
If i > 2 Then mon.i = mon.i + leap
If jday > mon.i Then mon = i
End
day = jday - mon.mon
gregDate = year'.'Right(mon,2,'0')'.'Right(day,2,'0')
return gregDate
ΓòÉΓòÉΓòÉ 12.10. MakePath ΓòÉΓòÉΓòÉ
/*=============( Recursive Path Creating )============*/
/* 17 */
/* Name.......: MakePath */
/* */
/* Function...: Create recursive directory path */
/* */
/* Call parm..: _destPath - directory path */
/* */
/* Returns....: formated string */
/* */
/* Syntax.....: */
/* _destPath = MakePath( _destPath ) */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
/*---------------(Create Directory Path)--------------*/
MakePath: Procedure
Arg _destPath
_destPath = Strip(_destPath,,'\')
If Pos('\', _destPath) = 0 Then Return _destPath
/*--------------( Check Directory Path )--------------*/
rc = SysFileTree( _destPath, fileList, 'DO' )
If fileList.0 = 0 Then Do
/*------------(Directory path not exists)-----------*/
Call MakePath SubStr(_destPath, 1, LastPos('\', _destPath))
rc = SysMkDir( _destPath )
If rc > 0 & rc \= 5 Then
Say 'Destination directory:' _destPath 'not created. RC=' rc
Else
Say _destPath 'successful created'
End
Return _destPath
ΓòÉΓòÉΓòÉ 12.11. NoMult ΓòÉΓòÉΓòÉ
/*=============( Exclude multiple items )=============*/
/* 13 */
/* Name.......: NoMult */
/* */
/* Function...: Excludes multiple lines from a sorted */
/* file */
/* Call parm..: Nothing */
/* Returns....: Nothing (0). The result will be placed*/
/* on the stack! */
/* */
/* Syntax.....: Call NoMult / y = NoMult() */
/* */
/* Notes......: The elements to exclude must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* The stem variable must be previously */
/* sorted */
/* The result will be placed on the */
/* stack! */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
NoMult: Procedure Expose stem.
Do i = 1 To stem.0
Queue stem.i
Do j = i + 1 while stem.i = stem.j
End
i = j - 1
End
Return 0
ΓòÉΓòÉΓòÉ 12.12. NoUmlaut ΓòÉΓòÉΓòÉ
/*============( Remove umlaut characters )============*/
/* 15 */
/* Name.......: NoUmlaut */
/* */
/* Function...: Replace umlaut characters with double */
/* character strings (Д -> ae, Ф -> oe, */
/* Б -> ue, с -> ss) */
/* */
/* Call parm..: _string - string with umlauts, */
/* _upper - upper case return string */
/* (optional) */
/* */
/* Returns....: translated string */
/* */
/* Syntax.....: */
/* tranStr = NoUmlaut( uString,['U'] ) */
/* */
/* Changes....: No */
/* */
/* Note.......: This function calls the function */
/* ReplaceUmlaut */
/* */
/* Author.....: Janosch R. Kowalczyk, 1996. */
/*====================================================*/
NoUmlaut: Procedure
Parse Arg _string, _upper
/*---------(Replace 'Д' 'О' by 'ae' 'Ae')-----------*/
_string = ReplaceUmlaut( _string, 'Д', 'ae' )
_string = ReplaceUmlaut( _string, 'О', 'Ae' )
/*---------(Replace 'Ф' 'Щ' by 'oe' 'Oe')-----------*/
_string = ReplaceUmlaut( _string, 'Ф', 'oe' )
_string = ReplaceUmlaut( _string, 'Щ', 'Oe' )
/*---------(Replace 'Б' 'Ъ' by 'ue' 'Ue')-----------*/
_string = ReplaceUmlaut( _string, 'Б', 'ue' )
_string = ReplaceUmlaut( _string, 'Ъ', 'Ue' )
/*-------------(Replace 'с' by 'ss')----------------*/
_string = ReplaceUmlaut( _string, 'с', 'ss' )
If Abbrev('UPPER', _upper, 1) = 1 Then
Return Translate( _string )
Return _string
/*========( Replace a string with an another )========*/
/* 14a */
/* Name.......: ReplaceUmlaut */
/* */
/* Function...: Find all occurences of a substring */
/* and replace it by an another */
/* */
/* Call parm..: _string - input string, */
/* _origin - substring to be replaced */
/* _replStr - replace substring */
/* */
/* Returns....: translated string */
/* */
/* Syntax.....: */
/* tranStr = ReplaceUmlaut( String, origin, repl ) */
/* */
/* Changes....: No */
/* */
/* Note.......: This function is called from NoUmlaut */
/* and was developed for this purpose */
/* only. It isn't able to replace sub- */
/* strings that have same characters in */
/* both - origin and replace string! */
/* */
/* Author.....: Janosch R. Kowalczyk, 1996. */
/*====================================================*/
ReplaceUmlaut: Procedure
Parse Arg _string, _origin, _replStr
/*---( Same characters in the input and output strings )---*/
If Verify( _origin, _replStr, 'M' ) > 0 Then Return _string
/*-----(Replace umlaut by combined characters)-----*/
Do While Pos( _origin, _string ) > 0
Parse Var _string _prefix_ (_origin) _suffix_
_string = _prefix_ || _replStr || _suffix_
End
Return _string
ΓòÉΓòÉΓòÉ 12.13. PlayFile ΓòÉΓòÉΓòÉ
/*================(Play digital file)================*/
/* :-) OS/2 Only!!! 8 */
/* Name.......: PlayFile */
/* */
/* Function...: Play digital WAV/MID file */
/* */
/* Call parms.: File name to play */
/* Returns....: RC from the last mciRexx function */
/* */
/* Sample call: rc = PlayFile('bach.mid') */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*===================================================*/
PlayFile: Procedure
Arg CmdObject
If CmdObject = '' Then Return -1
loudness = 70 /* % */
/*--------------(Prepare MCI-commands)---------------*/
CmdStr.1 = 'OPEN' CmdObject 'ALIAS W WAIT'
CmdStr.2 = 'SET W TIME FORMAT MS WAIT'
CmdStr.3 = 'SET W AUDIO VOLUME' loudness 'WAIT'
CmdStr.4 = 'PLAY W WAIT'
/*------------(Play digital WAV/MID file)------------*/
Do i = 1 To 4
/*-----------(Send MCI command strings)------------*/
rc = mciRxSendString(CmdStr.i, 'retstrvar', '0','0')
If rc > 0 Then Leave
End
CmdStr = 'CLOSE W WAIT'
/*--------------(Send MCI command string)--------------*/
rc = mciRxSendString(CmdStr, 'retstrvar', '0','0')
Return rc
ΓòÉΓòÉΓòÉ 12.14. QSort ΓòÉΓòÉΓòÉ
/*====================(Quick sort)====================*/
/* :-D 4 */
/* Name.......: QSort */
/* */
/* Function...: Quick Sort for a stem variable */
/* Call parm..: No */
/* Returns....: Left-Right span */
/* */
/* Sample call: Call QSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*====================================================*/
QSort: Procedure Expose stem.
Arg left, right
If left = '' Then left = 1
If right = '' Then right = stem.0
If right > left Then Do
i = left
j = right
k = (left+right)%2
x = stem.k
Do Until i > j
Do While stem.i < x; i = i + 1; End
Do While stem.j > x; j = j - 1; End
If i <= j Then Do
xchg = stem.i
stem.i = stem.j
stem.j = xchg
i = i + 1
j = j - 1
End
End
y = QSort(left,j)
y = QSort(i,right)
End
Return right - left
ΓòÉΓòÉΓòÉ 12.15. ReplaceString ΓòÉΓòÉΓòÉ
/*========( Replace a string with an another )========*/
/* 16 */
/* Name.......: StrRepl */
/* */
/* Function...: Find all occurences of a substring */
/* and replace it by an another */
/* */
/* Call parm..: _string - input string, */
/* _origin - substring to be replaced */
/* _replStr - replace substring */
/* */
/* Returns....: translated string */
/* */
/* Syntax.....: */
/* tranStr = ReplaceString(_string,_origin,_replStr) */
/* */
/* Changes....: No */
/* */
/* Author.....: Janosch R. Kowalczyk, 1996. */
/*====================================================*/
StrRepl: Procedure
Parse Arg _string, _origin, _replStr
/*---( Find a substring to replace? )---*/
_lastPos = LastPos( _origin, _string )
If _lastPos > 0 Then Do
/*---( Get prefix to the substring )---*/
If _lastPos = 1 Then _prefix = ''
Else _prefix = SubStr( _string, 1, _lastPos - 1 )
/*---( Get suffix of the substring )---*/
_suffix = SubStr( _string, _lastPos + Length( _origin ))
/*---( Find next substring to replace )---*/
Return StrRepl( _prefix, _origin, _replStr ) || _replStr || _suffix
End
Else
Return _string
ΓòÉΓòÉΓòÉ 12.16. ShlSort ΓòÉΓòÉΓòÉ
/*====================(Shell sort)=====================*/
/* :-) 5 */
/* Name.......: ShlSort */
/* */
/* Function...: Shell Sort for a stem variable */
/* Call parm..: No */
/* Returns....: nothing (NULL string) */
/* */
/* Sample call: Call ShlSort */
/* */
/* Notes......: The elements to sort for must be */
/* saved in the stem named so as the */
/* stem in this Procedure (in this case */
/* "STEM.") */
/* stem.0 must contain the number of */
/* elements in stem. */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*=====================================================*/
ShlSort: Procedure Expose stem.
parts = 3 /* adjust to your necessities ( >1 ) */
Do n = 1 To parts
incr = 2**n - 1
Do j = incr + 1 To stem.0
i = j - incr
xchg = stem.j
Do While xchg < stem.i & i > 0
m = i + incr
stem.m = stem.i
i = i - incr
End /* Do While xchg ... */
m = i + incr
stem.m = xchg
End /* Do j = incr ... */
End /* Do n = 1 ... */
Return ''
ΓòÉΓòÉΓòÉ 12.17. ToLower ΓòÉΓòÉΓòÉ
/*=============(Translate To Lower Case)===============*/
/* :-) 9 */
/* Name.......: ToLower */
/* */
/* Function...: Translate entired string to lower */
/* case */
/* Call parms.: String to translate */
/* Returns....: Translated string */
/* */
/* Syntax.....: lowString = ToLower(upperString) */
/* */
/* Changes....: 27.12.1996 - XRange used */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*=====================================================*/
ToLower: Procedure
/*------------(Lower Case entired string)--------------*/
Parse Arg Upper_String
Lowers = XRange('a', 'z') || 'ДФБ'
Uppers = XRange('A', 'Z') || 'ОЩЪ'
Return Translate(Upper_String, Lowers, Uppers)
ΓòÉΓòÉΓòÉ 12.18. SqrRoot ΓòÉΓòÉΓòÉ
/*====================(Square root)====================*/
/* :-) 6 */
/* Name.......: SqrRoot */
/* */
/* Function...: Square root evolution for the call */
/* parameter */
/* Call parms.: Evolution number, precision */
/* Returns....: Square root */
/* */
/* Syntax.....: sqrt = SqrRoot(number, [precision]) */
/* */
/* Notes......: precision is the highest possible */
/* error for the evaluation. */
/* Default Value is 0.00001 */
/* You are responsible for the valid */
/* number value */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1996. */
/* All rights reserved. */
/*=====================================================*/
SqrRoot: Procedure
Arg number, precision
If Datatype(number) \= 'NUM' Then Return -1
If precision <= 0 | precision > 1 Then precision = 0.000001
sqrt = 1
Do Until Abs(sqrt_old - sqrt) < precision
sqrt_old = sqrt
sqrt = (sqrt_old * sqrt_old + number) / (2 * sqrt_old)
End /* Do Until ... */
Return sqrt
ΓòÉΓòÉΓòÉ 12.19. CubeRoot ΓòÉΓòÉΓòÉ
/*====================( Cube root )====================*/
/* :-) 7 */
/* Name.......: CubeRoot */
/* */
/* Function...: Cube root evolution for the calling */
/* parameter */
/* Call parms.: Evolution number, precision (optional) */
/* Returns....: Cube root */
/* */
/* Syntax.....: cbrt = CubeRoot(_digit, [precision]) */
/* */
/* Notes......: precision is the highest possible */
/* error for the evaluation. */
/* Default Value is 0.00001 */
/* You are responsible for the valid */
/* number value */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1997. */
/* All rights reserved. */
/*=====================================================*/
CubeRoot: Procedure
Arg _digit, precision
If Datatype(_digit) \= 'NUM' Then Return -1
If precision <= 0 | precision > 1 Then precision = 0.000001
cbrt = 1
Do Until Abs(cbrt_old - cbrt) < precision
cbrt_old = cbrt
cbrt = ( 2 * cbrt_old ** 3 + _digit ) / ( 3 * cbrt_old ** 2 )
End /* Do Until ... */
Return cbrt
ΓòÉΓòÉΓòÉ 12.20. Euclid ΓòÉΓòÉΓòÉ
/*=============( Greatest common divisor )============*/
/* 19 */
/* Name.......: EuclidGCD */
/* */
/* Function...: Get greatest common divisor (Euclids */
/* algorithm) */
/* Call parm..: _counter */
/* _denuminator */
/* Returns....: gcd */
/* */
/* Syntax.....: */
/* gcd = EuclidGCD( _counter, _denuminator ) */
/* */
/* Changes....: No */
/* */
/* (C) Copyright Janosch R. Kowalczyk, 1997. */
/* All rights reserved. */
/*====================================================*/
/*--------------(Greatest common divisor)-------------*/
EuclidGCD: Procedure
Arg _counter, _denuminator
Do Until _counter = 0
If _counter < _denuminator Then Do
_Xchange = _counter
_counter = _denuminator
_denuminator = _Xchange
End
_counter = _counter - _denuminator
End
Return _denuminator
ΓòÉΓòÉΓòÉ 13. Using and testing. ΓòÉΓòÉΓòÉ
All here described routines are written either as internal REXX
subroutins (return no value) or as internal REXX functions (return a
value).
You can simply copy a required code template at end of your REXX
program (after exit statement) to use it. To do it use either Cut and
Paste options of your text edtitor or use the code template from the
Greed's Templates Controller.
To work with the option Cut of a text editor you should use templates
contained in the file RXALGxxx.CMD.
To work with the Templates Controller use templates from the file
RXALGxxx.FNC.
They are test command files for all these routines. You can find them
in the subdirectory named TESTALGO. It is one test command file for
each soubroutine from this package. Click twice the command files
icon to start the test.
To keep the code templates simply, I've not (in most cases)
implemented error checking. That is why you are responsible for all
call parameters and resources used from these routines.
ΓòÉΓòÉΓòÉ 14. Tips. ΓòÉΓòÉΓòÉ
There are many diverse publications about programming language REXX,
but my personal preference stands for two publications:
Rexx Tips & Trics of Bernd Schemmer.
Rexx Sourcebook of Dirk Terrell.
These books are the collections of REXX informations gotten from
various places on the Internet and from various Authors.
ΓòÉΓòÉΓòÉ 14.1. REXX Tips & Tricks ΓòÉΓòÉΓòÉ
REXX Tips & Tricks (INF file)
Bernd Schemmer
Team OS/2, Certfied LAN Server Engineer, Certfied OS/2 Engineer
Baeckerweg 48
D-60316 Frankfurt
Germany
CompuServe: 100104,613
Internet: 100104.613@compuserve.com
Source of supply: CIS, Forum OS2DF1, Library REXX/Other Languages.
File name RXTTxxx.* (where xxx stands for the version number, i.e.:
250)
ΓòÉΓòÉΓòÉ 14.2. REXX Sourcebook ΓòÉΓòÉΓòÉ
REXX Sourcebook (INF file)
Dirk Terrell
terrell@astro.ufl.edu
Source of supply: BBS.
File name RS960115.*
ΓòÉΓòÉΓòÉ 15. Greed. ΓòÉΓòÉΓòÉ
Greed - General Rexx Extended Editor - is a small PM developing
environment to write, store and control of code templates. It can be
used to control the code sections for all programming languages. You
can find it in the CompuServe forum OS2USER (library: Open forum)
under the name GREED.ZIP.
Greed is a universal source code generator to work with user defined
code templates.
Greed has a modular structure and consists of four independent
modules:
Greed Editor, the small Rexx editor.
Templates Controller, the universal code controller.
Template Editor to edit the templates for Greed and Greed
Templates Controller.
Browser - the small file viewer with both text and hexadecimal
mode.