home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / batnmore.z!p / DEC2ROMA.BTM < prev    next >
Text File  |  1992-11-15  |  2KB  |  75 lines

  1. *REM This batch file is Freeware, free to use and redistribute unmodified *
  2. *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
  3.  
  4. REM Convert a decimal number to a Roman numeral system.
  5. REM Timestamp 15-Nov-1992
  6.  
  7. setlocal^break on^unalias *^if %#==0 .or. "%1"=="-?" goto info
  8.  
  9. REM Did the user give a legal decimal string? Nothing but numbers?
  10.  
  11. :input
  12. iff "%@substr[%1,%index,1]" lt "0" .or. "%@substr[%1,%index,1]" gt "9" then
  13. if "%_column" != "0" echo.^echo Error: "%1" NaN (Not a Number).^shift^goto next
  14. else^set dec=%dec%%%@substr[%1,%index,1]^set index=%@eval[%index+1]^endiff
  15. if %index lt %@len[%1] goto input^shift
  16.  
  17. if "%_column" != "0" echo.^echos %dect-` `
  18.  
  19. for %b in (M CM D CD C XC L XL X IX V IV I) (
  20.     set a=%b
  21.     gosub work
  22. )
  23. goto next
  24.  
  25. REM Always end gosub with return, otherwise "4DOS internal stack overflow".
  26.  
  27. :work
  28.     iff %dec == 0 then^return
  29. elseiff %a==M  then^set div=1000
  30. elseiff %a==CM then^set div=900
  31. elseiff %a==D  then^set div=500
  32. elseiff %a==CD then^set div=400
  33. elseiff %a==C  then^set div=100
  34. elseiff %a==XC then^set div=90
  35. elseiff %a==L  then^set div=50
  36. elseiff %a==XL then^set div=40
  37. elseiff %a==X  then^set div=10
  38. elseiff %a==IX then^set div=9
  39. elseiff %a==V  then^set div=5
  40. elseiff %a==IV then^set div=4
  41. elseiff %a==I  then^set div=1
  42. endiff
  43.  
  44. :loop
  45. iff %@eval[%dec / %div] ge 1 then
  46.     echos %a
  47.     set dec=%@eval[%dec - %div]
  48.     goto loop
  49. else
  50.     return
  51. endiff
  52.  
  53. REM Are there any more numbers to convert?
  54.  
  55. :next
  56. iff "%1" != "" then^unset/q index dec div^goto input^else^goto end^endiff
  57.  
  58. :info
  59. echo Usage: %@lower[%@name[%0]] [-number ...]
  60. text
  61.  
  62. Convert a decimal number to the Roman numeral system.
  63.  
  64.     I       1    For example: 1992 - MCMXCII
  65.     V       5
  66.     X      10
  67.     L      50
  68.     C     100
  69.     D     500
  70.     M    1000
  71. endtext
  72.  
  73. :end
  74. break off^quit
  75.