(view source code of clcalc.rex as plain text)
/* Command line calculator */
/* Check command line validity */
Parse Arg params
params = Translate( params, "/.", ":," )
If params = "" Then Call Syntax
If Pos( "?", params ) > 0 Then Call Syntax
/* Parse command line and check each individual parameter */
parmstr = params
param.0 = 0
Do i = 1 by 1 Until parmstr = ""
Parse Value parmstr With param.i parmstr
If param.i <> "" Then Do
param.0 = i
param.i = Strip( param.i, "B", '"' )
End
End
If param.0 = 0 Then Call Syntax
Do i = 1 to param.0
If DataType( param.i, "N" ) = 1 Then Iterate
If Pos( param.i, "**//%+-:()" ) = 0 Then Call Syntax
End
/* Perform the actual calculation, truncate to whole integer */
Interpret "result = ("||params||") % 1"
/* Display the result on screen */
Say result
/* Return code is the result, but limited to range 0..255 */
EXIT Max( Min( result, 255 ), 0 )
Syntax:
Say
Say "CLCalc, Version 1.00"
Say "Command Line Calculator for use in batch files"
Say
Say "Usage: <REXX> CLCALC.REX <expression>"
Say
Say 'Where: "<REXX>" is your Rexx interpreter:'
Say " - Windows: REGINA.EXE or REXX.EXE,"
Say " whichever is installed"
Say " - OS/2: no need to specify, just"
Say " rename script to *.cmd"
Say ' "<expression>" is a valid Rexx expression:'
Say " Operators +, -, /, //, %, *, ** and : are allowed"
Say " Both dots and commas are allowed as decimal delimiters"
Say " Numbers and operators should be separated by spaces"
Say
Say "Returns: Result of <expression> on screen, and as a return code"
Say " (minimum return code is 0, maximum is 255)"
Say
Say "Written by Rob van der Woude"
Say "http://www.robvanderwoude.com"
EXIT 0
return
page last modified: 2024-04-16; loaded in 0.0065 seconds