Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adisak committed Sep 19, 2020
1 parent 326787a commit ccef012
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/EvalBat.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM "EvalBat" can be used to add floating point support and complex math support to batch files
REM Copyright (c) 2020 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details

REM :EvalBat
REM Parameters: (VBS) Expression to evaluate
REM Returns: EVALBAT_RESULT - result of evaluating input expression

REM cscript.exe /nologo "%~p0\EvalBat_vbs.vbs" "%*"
for /f "usebackq" %%t in (`cscript.exe /nologo "%~p0\EvalBat_vbs.vbs" "%*"`) do (
SET EVALBAT_RESULT=%%t
)
REM echo Result: %EVALBAT_RESULT%
10 changes: 10 additions & 0 deletions scripts/EvalBat_Echo.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM "EvalBat" can be used to add floating point support and complex math support to batch files
REM Copyright (c) 2020 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details

echo Input: %*
call EvalBat.bat %*
echo Result: %EVALBAT_RESULT%
25 changes: 25 additions & 0 deletions scripts/EvalBat_License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM "EvalBat" can be used to add floating point support and complex math support to batch files
REM Copyright (c) 2020 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions scripts/EvalBat_vbs.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
REM "EvalBat" is a helper that lets you evaluate (vbscript) expressions in a batch file
REM "EvalBat" can be used to add floating point support and complex math support to batch files
REM Copyright (c) 2020 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See EvalBat_License.txt for details

Set objArgs = WScript.Arguments
If objArgs.Count > 1 Then
allArgs = objArgs(0)
For i = 1 to (objArgs.Count-1)
allArgs = allArgs + " " + objArgs(i)
Next
wscript.echo eval(allArgs)
ElseIf 1 = objArgs.Count Then
wscript.echo eval(objArgs(0))
Else
wscript.echo "0"
End If

21 changes: 21 additions & 0 deletions test/Eval_Test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off
REM "Multi" is a thread-pool emulation helper library for controlling multi-threaded windows batch [*.BAT] files
REM Copyright (c) 2020 Adisak Pochanayon
REM Contact: adisak@gmail.com
REM See Multi_License.txt for details

REM TEST Multi
REM :TestMultithreading
SETLOCAL
SET PATH=%PATH%;..\scripts

call EvalBat_Echo.bat 1 + 2 / 5

echo.
call EvalBat_Echo.bat Abs(1 - 2)

echo.
call EvalBat_Echo.bat Int((100 / 3)*100)/100

ENDLOCAL
goto:EOF

0 comments on commit ccef012

Please sign in to comment.