home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / editcmd.zip / EDIT.CMD
OS/2 REXX Batch file  |  1993-07-30  |  3KB  |  48 lines

  1. /*----------------------------------------------------------------*/
  2. /*                                                                */
  3. /*                       EDIT REXX function                       */
  4. /*----------------------------------------------------------------*/
  5. /*                                                                */
  6. /*   The following REXX subroutine / function will return an      */
  7. /*   edited number, with or without an imbedded decimal point,    */
  8. /*   with commas inserted appropriately. For example:             */
  9. /*                                                                */
  10. /*        EDIT(12345)                                             */
  11. /*                                                                */
  12. /*   will return 12,345; and                                      */
  13. /*                                                                */
  14. /*        EDIT(12345.67)                                          */
  15. /*                                                                */
  16. /*   will return 12,345.67.                                       */
  17. /*                                                                */
  18. /*   The intent behind the creation of this function was speed.   */
  19. /*   it is being released to the public domain by the author,     */
  20. /*   Dick Goran (CompuServe PPN 72200,347).                       */
  21. /*                                                                */
  22. /*----------------------------------------------------------------*/
  23. EDIT:
  24. /* first time here, build translate tables */
  25. if LEFT(e1, 1) <> '01'x then
  26.     do
  27.         e1 = XRANGE('01'x, '19'x)
  28.         e2 = XRANGE('01'x, '03'x) || '19'x ||,
  29.              XRANGE('04'x, '06'x) || '19'x ||,
  30.              XRANGE('07'x, '09'x) || '19'x ||,
  31.              XRANGE('0A'x, '0C'x) || '19'x ||,
  32.              XRANGE('0D'x, '0F'x) || '19'x ||,
  33.              XRANGE('10'x, '12'x) || '19'x ||,
  34.              XRANGE('13'x, '15'x) || '19'x ||,
  35.              XRANGE('16'x, '18'x)
  36.     end
  37.  
  38. period_position = POS( '.', ARG(1) )
  39. if period_position = 0 then
  40.     source = RIGHT( ARG(1), LENGTH(e1) - 1 ) || ' '
  41. else
  42.     source = RIGHT( LEFT( ARG(1), period_position - 1 ), LENGTH(e1) - 1 ) || ' '
  43. if period_position = 0 then
  44.     return STRIP( TRANSLATE( TRANSLATE( e2, source, e1), ',', ' '), 'B', ',')
  45. else
  46.     return STRIP( TRANSLATE( TRANSLATE( e2, source, e1), ',', ' '), 'B', ','),
  47.                   || RIGHT( ARG(1), LENGTH(ARG(1)) - period_position + 1)
  48.