home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxalgo.zip / rexxalgo.txt < prev    next >
Text File  |  1997-08-28  |  17KB  |  454 lines

  1. REXX Algorithms
  2. =============================================================
  3.  
  4. Table of Contents
  5. -----------------
  6.  
  7. 1.     Disclaimer.
  8. 2.     Copyright.
  9. 3.     Current version
  10. 4.     REXX Algorithms.
  11. 4.1.     Searching and sorting. 
  12. 4.1.1.     Binary search.
  13. 4.1.2.     Bubble sort.
  14. 4.1.3.     Insertion sort.
  15. 4.1.4.     Quick sort
  16. 4.1.5.     Shell sort.
  17. 4.2.     Date and time.
  18. 4.2.1.     Translate Gregorian date to Julian date.
  19. 4.2.2.     Julian date to Gregorian date.
  20. 4.2.3.     Date with century
  21. 4.3.     Strings.
  22. 4.3.1.     Translate umlauts to lower case.
  23. 4.3.2.     Recursive string formatting.
  24. 4.3.3.     Replace a substring by an another.
  25. 4.3.4.     Remove umlaut characters.
  26. 4.4.     Mathematical functions.  
  27. 4.4.1.     Square root evaluation.
  28. 4.4.2.     Cube root evolution
  29. 4.4.3.     Greatest common divisor
  30. 4.5.     File system.  
  31. 4.5.1.     Recursive creating directory path.
  32. 4.5.2.     Delete directory path.
  33. 4.6.     Multimedia.  
  34. 4.6.1.     Digital Audio Player (mciRexx)
  35. 4.7.     Miscellaneous. 
  36. 4.7.1.     Exclude multiple items from a stem.
  37. 5.     Author.
  38.  
  39.  
  40. =============================================================
  41.  
  42. 1. Disclaimer.
  43. --------------
  44.  
  45. This package is provided as is, without any guarantees or
  46. warrantees whatsoever. The author is not liable or responsible 
  47. for any loss or damage of any kind whatsoever, including, but
  48. not limited to, losses of a financial, physical, emotional,
  49. marital, social, or mental nature that may result from the
  50. use or the purported use of anything in this package, for any
  51. purpose whatsoever. 
  52.  
  53. Thanks to Michael Shillingford for this wording.
  54.  
  55. =============================================================
  56.  
  57. 2. Copyright.
  58. -------------
  59.  
  60. (C) Copyright Janosch R. Kowalczyk, 1996, 1997. All rights reserved. 
  61.  
  62. You may distribute this document and software in the original format to any one.
  63.  
  64. You can use this document and software for all non-commercial purposes only.
  65. Commercial users must obtain the permission of the author first. 
  66.  
  67. You aren't allowed to distribute this document and software in printed form 
  68. without the written permission of the author.
  69.  
  70. All the routines described in this document are implemented in Rexx by the 
  71. author and they are free of charge. 
  72.  
  73. =============================================================
  74.  
  75. 3. Current version.
  76. -------------------
  77.  
  78. The current version of Rexx Algorithms is 1.31.
  79. The current source files are:
  80.  
  81. - RXALG131.CMD
  82. - RXALG131.FNC (for Greed - OS/2 only)
  83.  
  84. Last revision date: July 2, 1997
  85.  
  86. =============================================================
  87.  
  88. 4. REXX Algorithms.
  89. -------------------
  90.  
  91. I work as a systems programmer for MVS security systems and I work
  92. quite often under both TSO and OS/2 systems (environments). That's
  93. why I'm so happy to have Rexx - I must write my programs only once
  94. and they work on these two systems.
  95.  
  96. I've written already a lot of Rexx programs. Doing this I wrote 
  97. many simple but rather useful Rexx subroutines. They are both 
  98. common well-known algorithms and my own solutions for Rexx specific
  99. problems.
  100.  
  101. RexxAlgo is a collection of various REXX source code (sub)routines.
  102. I think that many Rexx programmers can use these subroutines to solve 
  103. their problems and they do not have to develop these things once again.
  104.  
  105. These algorithms are at the Release 1.30 subdivided in the following 
  106. thematical groups:  
  107.  
  108. 1. Searching and sorting.  
  109.    - Binary search                       BiSearch
  110.    - Bubble sort                         BubSort
  111.    - Insertion sort                      InsSort
  112.    - Quick sort                          QSort
  113.    - Shell sort                          ShlSort
  114.  
  115. 2. Date and time.  
  116.    - Gregorian date to Julian date       G2J
  117.    - Julian date to Gregorian date       J2G
  118.    - Date with century                   Date2000
  119.  
  120. 3. Strings.  
  121.    - Translate umlauts to lower case     ToLower
  122.    - Recursive formatting                Combine 
  123.    - Replace a string                    ReplaceString
  124.    - Remove umlaut characters            NoUmlaut
  125.      This is a sample for using ReplaceString.
  126.  
  127. 4. Mathematical functions.  
  128.    - Square root evaluation              SqrRoot
  129.    - Cube root evaluation                CubeRoot
  130.    - Greatest common divisor             EuclidGCD
  131.  
  132. 5. File system.  
  133.    - Recursive creating directory path   MakePath
  134.    - Delete directory path               ErasePath
  135.  
  136. 6. Multimedia.  
  137.    - Digital Audio Player (mciRexx)      PlayFile
  138.  
  139. 7. Miscellaneous. 
  140.    - Exclude multiple items              NoMult
  141.  
  142. All these code templates are written as internal subroutines.
  143.  
  144. I have placed the same subroutines into two files:
  145. - first, as plain text into the Rexx command file named RXALGxxx.CMD
  146. - secondly, as code templates in the function file for GREED's Templates
  147.   Controller, named RXALGxxx.FNC (INI format).
  148.  
  149. Note: The abbreviation xxx is the current version number i.e. 131 for the
  150.       version 1.31 
  151.  
  152. GREED - General Rexx Extended Editor - is a small PM developing
  153. environment to write, store and control of code templates. It can
  154. be used to control the code sections for all programing languages.
  155. You can find it in the CompuServe forum OS2USER (library: Open forum)
  156. under the name GREED.ZIP.
  157.  
  158.  
  159. 4.1. Searching and sorting.
  160. ---------------------------  
  161. 4.1.1. Binary search.
  162.  
  163.        Function name: BiSearch
  164.        Syntax.......: foundIndex = BiSearch( value )
  165.        Function.....: Binary search a stem variable for a value
  166.        Call param...: Searched value
  167.        Returns......: index of the found value,
  168.                       0 if nothing found
  169.  
  170.        Notes........: The elements to search for must be saved
  171.                       in the stem named so as the stem in this
  172.                       procedure (default name "STEM.")
  173.                       stem.0 must contain the number of elements
  174.                       in stem.
  175.                       The stem-variable must be in the sorted order.
  176.  
  177.        Sample call..:
  178.                       foundIndex = BiSearch(value) 
  179.                       If foundIndex = 0 Then
  180.                         Say 'Value' value 'not found!'
  181.                       Else
  182.                         Say stem.foundIndex 
  183.  
  184. 4.1.2. Bubble sort.
  185.  
  186.        Function name: BubSort
  187.        Syntax.......: Call BubSort
  188.        Function.....: Sort of a stem variable using the Bubble sort
  189.                       algorithm.
  190.        Call parm....: No 
  191.        Returns......: nothing (NULL string)
  192.  
  193.        Notes........: The elements to sort for must be saved in the
  194.                       stem named so as the stem in this procedure 
  195.                       (in this case "STEM.").
  196.                       stem.0 must contain the number of elements in
  197.                       stem.
  198.  
  199. 4.1.3. Insertion sort.
  200.  
  201.        Function name: InsSort
  202.        Syntax.......: Call InsSort
  203.        Function.....: Sort of a stem variable using the Insertion sort
  204.                       algorithm.
  205.        Call parm....: No 
  206.        Returns......: nothing (NULL string)
  207.  
  208.        Notes........: The elements to sort for must be saved in the
  209.                       stem named so as the stem in this procedure 
  210.                       (in this case "STEM.").
  211.                       stem.0 must contain the number of elements in
  212.                       stem.
  213.  
  214. 4.1.4. Quick sort
  215.  
  216.        Function name: QSort
  217.        Syntax.......: Call QSort
  218.        Function.....: Sort of a stem variable using the Quick sort
  219.                       algorithm.
  220.        Call parm....: No 
  221.        Returns......: Left-Right span
  222.  
  223.        Notes........: The elements to sort for must be saved in the
  224.                       stem named so as the stem in this procedure 
  225.                       (in this case "STEM.").
  226.                       stem.0 must contain the number of elements in
  227.                       stem.
  228.  
  229. 4.1.5. Shell sort.
  230.  
  231.        Function name: ShlSort
  232.        Syntax.......: Call ShlSort
  233.        Function.....: Sort of a stem variable using the Shell sort
  234.                       algorithm.
  235.        Call parm....: No 
  236.        Returns......: nothing (NULL string)
  237.  
  238.        Notes........: The elements to sort for must be saved in the
  239.                       stem named so as the stem in this procedure 
  240.                       (in this case "STEM.").
  241.                       stem.0 must contain the number of elements in
  242.                       stem.
  243.  
  244.  
  245. 4.2. Date and time.
  246. -------------------  
  247. 4.2.1. Translate Gregorian date to Julian date.
  248.  
  249.        Function name: G2J
  250.        Syntax.......: julDate = G2J( yyyy.mm.dd )
  251.        Function.....: Translates Gregorian date to the Julian date
  252.        Call param...: Gregorian date in format yyyy.mm.dd
  253.        Returns......: Julian date in format yyyy.ddd
  254.  
  255. 4.2.2. Julian date to Gregorian date.
  256.  
  257.        Function name: J2G
  258.        Syntax.......: gregDate = J2G( yyyy.ddd )
  259.        Function.....: Translates Julian date to the Gregorian date
  260.        Call param...: Julian date in format yyyy.ddd
  261.        Returns......: Gregorian date in format yyyy.mm.dd
  262.  
  263. 4.2.3. Date with century
  264.  
  265.        Function name: Date2000
  266.        Syntax.......: Date = Date2000(Option)
  267.        Call option..:   Returns dd Mmm yyyy
  268.                       B Returns dddddd days since 01.01.0001
  269.                       D Returns ddd - days in the current year
  270.                       E Returns dd/mm/yyyy
  271.                       J Returns yyyy.ddd - Julian date
  272.                       L Returns dd Month yyyy
  273.                       M Returns Month
  274.                       N Returns dd Mmm yyyy
  275.                       O Returns yyyy/mm/dd
  276.                       S Returns yyyymmdd
  277.                       U Returns mm/dd/yyyy
  278.                       W Returns Weekday
  279.        Function.....: Same output as the Rexx built-in function Date() but
  280.                       includes the century with the year. Has also an additional 
  281.                       option, J.
  282.  
  283.  
  284. 4.3. Strings.
  285. ------------- 
  286. 4.3.1. Translate umlauts to lower case.
  287.  
  288.        Function name: ToLower
  289.        Syntax.......: lowString = ToLower(upperString)
  290.        Function.....: Translate entired string to lower case
  291.        Call param...: String to translate
  292.        Returns......: Translated string
  293.  
  294.        Notes........: Simply change variable 'Lowers' and 'Uppers'
  295.                       to get the function ToUpper
  296.  
  297. 4.3.2. Recursive string formatting.
  298.  
  299.        Function name: Combine 
  300.        Syntax.......: formStr = Combine( _combStr, _combLen, [_combTooth], [_combRep] )
  301.        Function.....: Recursive formatting of a string with a constant
  302.                       interval.
  303.        Call param...: _combStr   - string to be formated,
  304.                       _combLen   - string's length,
  305.                       _combTooth - new format string (optional),
  306.                       _combRep   - format interval (optional)
  307.        Returns......: formated string 
  308.  
  309.        Notes........: Default value for _combTooth is a blank
  310.                       Default value for _combRep is 1
  311.                       _combTooth will be inserted into the _combStr at
  312.                       the position computed as follows:
  313.                       _combLen = _combLen - _combRep
  314.  
  315.        Sample.......: formStr = Combine( '10000000000', 11, ',', 3 )
  316.                       Input string  = '10000000000'
  317.                       String length = 11
  318.                       Format string = ','
  319.                       Interval      = 3
  320.                       Output string = '10,000,000,000'
  321.  
  322. 4.3.3. Replace a substring by an another.
  323.  
  324.        Function name: ReplaceString
  325.        Syntax.......:    tranStr = ReplaceString( _string, _origin, _replStr )
  326.        Function.....: Replace in the input-string all found substrings
  327.                       by the another (so as built-in functions Overlay and
  328.                       Insert together).
  329.        Call param...: _string  - input string,
  330.                       _origin  - substring to be replaced,
  331.                       _replStr - replace substring
  332.        Returns......: translated string
  333.  
  334.        Note.........: This function is called from NoUmlaut
  335.  
  336. 4.3.4. Remove umlaut characters.
  337.  
  338.        Function name: NoUmlaut
  339.        Function.....: Replace umlaut characters with double character
  340.                       strings (ä -> ae, ö -> oe, ü -> ue, ß -> ss)
  341.        Call param...: _string - string with umlauts,
  342.                       _upper  - upper case return string (optional)
  343.        Returns......: translated string
  344.        Syntax.......: tranStr = NoUmlaut( uString,['U'] )
  345.  
  346.        Notes........: This function calls the function ReplaceString.
  347.  
  348.  
  349. 4.4. Mathematical functions.  
  350. ----------------------------
  351. 4.4.1. Square root evaluation.
  352.  
  353.        Function name: SqrRoot
  354.        Syntax.......: sqrt = SqrRoot(number, [precision])
  355.        Function.....: Square root evolution for the called parameter.
  356.        Call params..: evolution number,
  357.                       precision (optional)
  358.        Returns......: Square root of the called parameter
  359.        Notes........: precision is the highest possible error for the
  360.                       evaluation.
  361.                       Default Value of the precision is 0.00001
  362.                       You are responsible for the valid number values
  363.  
  364. 4.4.2. Cube root evaluation.
  365.  
  366.        Function name: CubeRoot
  367.        Syntax.......: gcd = CubeRoot(_digit, _precision)
  368.        Function.....: Cube root evolution.
  369.        Call params..: Call parameters are two digits. The first one is the digit 
  370.                       for which you want to compute the cube root, the second is 
  371.                       the precision of the calculation. The precision is a 
  372.                       decimal fraction number e.g. : 0.00000001.
  373.  
  374.        Returns......: cube root of the called parameter.
  375.        Notes........: You are responsible for the valid number values 
  376.  
  377. 4.4.3. Greatest common divisor
  378.  
  379.        Function name: EuclidGCD
  380.        Syntax.......: gcd = EuclidGCD(_counter, _denominator)
  381.        Function.....: Euclid's algorithm to obtain the greatest common divisor.
  382.        Call params..: Call parameters are two digits, for which the function 
  383.                       computes the greatest common divisor.
  384.  
  385.        Returns......: greatest common divisor.
  386.        Notes........: You are responsible for the valid number values
  387.  
  388. 4.5. File system.  
  389. -----------------
  390. 4.5.1. Recursive creating directory path (OS/2 only).
  391.  
  392.        Function name: MakePath
  393.        Syntax.......: _destPath = MakePath( _destPath )
  394.        Function.....: Recursive creating of the directory path
  395.        Call parm....: _destPath  - directory path
  396.        Returns......: directory path
  397.  
  398. 4.5.2. Delete directory path (OS/2 only).
  399.  
  400.        Function name: ErasePath
  401.        Syntax.......: _erasePath = MakePath( _erasePath )
  402.        Function.....: Delete fully directory path
  403.        Call parm....: _erasePath - directory path to be deleted
  404.        Returns......: formated string
  405.        Note.........: Only empty directories will be deleted.
  406.  
  407.  
  408. 4.6. Multimedia.  
  409. ----------------
  410. 4.6.1. Digital Audio Player (mciRexx)
  411.  
  412.        Function name: PlayFile
  413.        Syntax.......: rc = PlayFile( audio_file_name )
  414.        Function.....: Play digital WAV/MID file
  415.        Call params..: File name to play
  416.        Returns......: RC from the last mciRexx function
  417.  
  418.  
  419. 4.7. Miscellaneous. 
  420. -------------------
  421. 4.7.1. Exclude multiple items from a stem.
  422.  
  423.        Function name: NoMult
  424.        Syntax.......: Call NoMult
  425.        Function.....: Excludes multiple items from a sorted stem variable                         */
  426.        Call param...: no
  427.        Returns......: 0
  428.        Notes........: The elements to exclude must be saved in the stem
  429.                       named so as the stem in this Procedure (in this
  430.                       case "STEM.")
  431.                       stem.0 must contain the number of elements in stem.
  432.                       The stem variable must be previously sorted.
  433.  
  434. =============================================================
  435.  
  436. 5. Author.
  437. ----------
  438.  
  439. If you have any questions or suggestions, you can reach me under
  440. the following address:
  441.  
  442.   Janosch R. Kowalczyk
  443.   Oberwaldstr. 42
  444.   63538 Grosskrotzenburg / Germany
  445.   Tel: +49 (0)6186 201676
  446.   Compuserve: 101572,2160
  447.   Internet: 101572.2160@compuserve.com
  448.  
  449. =============================================================
  450.  
  451. Enjoy!
  452.  
  453. Janosch
  454.