home *** CD-ROM | disk | FTP | other *** search
- *REM This batch file is Freeware, free to use and redistribute unmodified *
- *REM Jouni Miettunen * jon@stekt.oulu.fi * Oulu * Finland * Europe * 1992 *
-
- REM Convert a decimal number to a Roman numeral system.
- REM Timestamp 15-Nov-1992
-
- setlocal^break on^unalias *^if %#==0 .or. "%1"=="-?" goto info
-
- REM Did the user give a legal decimal string? Nothing but numbers?
-
- :input
- iff "%@substr[%1,%index,1]" lt "0" .or. "%@substr[%1,%index,1]" gt "9" then
- if "%_column" != "0" echo.^echo Error: "%1" NaN (Not a Number).^shift^goto next
- else^set dec=%dec%%%@substr[%1,%index,1]^set index=%@eval[%index+1]^endiff
- if %index lt %@len[%1] goto input^shift
-
- if "%_column" != "0" echo.^echos %dect-` `
-
- for %b in (M CM D CD C XC L XL X IX V IV I) (
- set a=%b
- gosub work
- )
- goto next
-
- REM Always end gosub with return, otherwise "4DOS internal stack overflow".
-
- :work
- iff %dec == 0 then^return
- elseiff %a==M then^set div=1000
- elseiff %a==CM then^set div=900
- elseiff %a==D then^set div=500
- elseiff %a==CD then^set div=400
- elseiff %a==C then^set div=100
- elseiff %a==XC then^set div=90
- elseiff %a==L then^set div=50
- elseiff %a==XL then^set div=40
- elseiff %a==X then^set div=10
- elseiff %a==IX then^set div=9
- elseiff %a==V then^set div=5
- elseiff %a==IV then^set div=4
- elseiff %a==I then^set div=1
- endiff
-
- :loop
- iff %@eval[%dec / %div] ge 1 then
- echos %a
- set dec=%@eval[%dec - %div]
- goto loop
- else
- return
- endiff
-
- REM Are there any more numbers to convert?
-
- :next
- iff "%1" != "" then^unset/q index dec div^goto input^else^goto end^endiff
-
- :info
- echo Usage: %@lower[%@name[%0]] [-number ...]
- text
-
- Convert a decimal number to the Roman numeral system.
-
- I 1 For example: 1992 - MCMXCII
- V 5
- X 10
- L 50
- C 100
- D 500
- M 1000
- endtext
-
- :end
- break off^quit
-