diff --git a/DateAndTime/DateParts.bat b/DateAndTime/DateParts.bat deleted file mode 100644 index 7709d32..0000000 --- a/DateAndTime/DateParts.bat +++ /dev/null @@ -1,24 +0,0 @@ -@echo off -rem gets Date Parts -rem by Vasil "npocmaka" Arnaudov -rem 21.01.15 - improvement was proposed by Ildar Shaimordanov - a.k.a siberia-man -rem - to use empty folder to increase performance -for /f "skip=10 tokens=2,3,4,5,6,7,8 delims=: " %%D in (' - robocopy /l * "%windir%\System32\wbem\MOF\bad" "%windir%\System32\wbem\MOF\bad" /ns /nc /ndl /nfl /np /njh /XF * /XD * -') do ( - set "dow=%%D" - set "month=%%E" - set "day=%%F" - set "HH=%%G" - set "MM=%%H" - set "SS=%%I" - set "year=%%J" -) - -echo Day of the week: %dow% -echo Day of the month : %day% -echo Month : %month% -echo hour : %HH% -echo minutes : %MM% -echo seconds : %SS% -echo year : %year% diff --git a/DateAndTime/W32DOW.bat b/DateAndTime/W32DOW.bat deleted file mode 100644 index 20498b2..0000000 --- a/DateAndTime/W32DOW.bat +++ /dev/null @@ -1,31 +0,0 @@ -@echo off -setlocal -rem :: prints the day of the week -rem :: works on Vista and above -rem :: by Vasil "npocmaka" Arnaudov - - rem :: getting ansi date ( days passed from 1st jan 1601 ) , timer server hour and current hour - FOR /F "skip=16 tokens=4,5 delims=:( " %%D in ('w32tm /stripchart /computer:localhost /samples:1 /period:1 /dataonly /packetinfo') do ( - set "ANSI_DATE=%%D" - set "TIMESERVER_HOURS=%%E" - goto :end_for ) - :end_for - set "LOCAL_HOURS=%TIME:~0,2%" - if "%TIMESERVER_HOURS:~0,1%0" EQU "00" set TIMESERVER_HOURS=%TIMESERVER_HOURS:~1,1% - if "%LOCAL_HOURS:~0,1%0" EQU "00" set LOCAL_HOURS=%LOCAL_HOURS:~1,1% - set /a OFFSET=TIMESERVER_HOURS-LOCAL_HOURS - - rem :: day of the week will be the modulus of 7 of local ansi date +1 - rem :: we need need +1 because Monday will be calculated as 0 - rem :: 1st jan 1601 was Monday - - rem :: if abs(offset)>12 we are in different days with the time server - - IF %OFFSET%0 GTR 120 set /a DOW=(ANSI_DATE+1)%%7+1 - IF %OFFSET%0 LSS -120 set /a DOW=(ANSI_DATE-1)%%7+1 - IF %OFFSET%0 LEQ 120 IF %OFFSET%0 GEQ -120 set /a DOW=ANSI_DATE%%7+1 - - - echo Day of the week: %DOW% - exit /b 2147483648 -endlocal diff --git a/DateAndTime/W32tmSleep.bat b/DateAndTime/W32tmSleep.bat deleted file mode 100644 index 2933d57..0000000 --- a/DateAndTime/W32tmSleep.bat +++ /dev/null @@ -1,24 +0,0 @@ -@echo off -:: yet another sleep emulator working on everything from NT and above -if "%~1"=="" goto :help -ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL || goto :help -IF %~1 LSS 0 goto :help - -setLocal - set /a adj=%~1/2+1 - w32tm /stripchart /computer:localhost /period:1 /dataonly /samples:%adj% >nul 2>&1 -endLocal - -goto :eof -:help -echo. -echo %~n0 -echo Sleep emulator -echo Wait for a specified number of seconds. -echo. -echo Usage: CALL %~n0 seconds -echo. -echo seconds - seconds to wait -echo. -echo. -echo by Vasil "npocmaka" Arnaudov diff --git a/DateAndTime/getTime.bat b/DateAndTime/getTime.bat deleted file mode 100644 index ee91982..0000000 --- a/DateAndTime/getTime.bat +++ /dev/null @@ -1,25 +0,0 @@ -@echo off - -:: gets time using typePerf command -:: with put some effort to be made fast and maximum compatible - -setlocal -::check if windows is XP and use XP valid counter for UDP performance -if defined USERDOMAIN_roamingprofile (set "v=v4") else (set "v=") -set "mon=" -for /f "skip=2 delims=," %%# in ('typeperf "\UDP%v%\*" -si 0 -sc 1') do ( - if not defined mon ( - for /f "tokens=1-7 delims=.:/ " %%a in (%%#) do ( - set mon=%%a - set date=%%b - set year=%%c - set hour=%%d - set minute=%%e - set sec=%%f - set ms=%%g - ) - ) -) -echo %year%.%mon%.%date% -echo %hour%:%minute%:%sec%.%ms% -endlocal diff --git a/DateAndTime/sleeptp.bat b/DateAndTime/sleeptp.bat deleted file mode 100644 index 6a2405e..0000000 --- a/DateAndTime/sleeptp.bat +++ /dev/null @@ -1,18 +0,0 @@ -@echo off -:: yet another sleep emulator working on everything from NT and above -if "%~1"=="" goto :help -ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL 2>NUL || goto :help -IF %~1 LSS 0 goto :help - -typeperf "\System\Processor Queue Length" -si %~1 -sc 1 >nul - -goto :eof -:help -echo. -echo %~n0 -echo Sleep emulator -echo Wait for a specified number of seconds. -echo. -echo Usage: CALL %~n0 seconds -echo. -echo seconds - seconds to wait diff --git a/README.md b/README.md index 92c23df..1edeaa8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -batch.scripts -============= +# Batch Script Utils and Examples + +## 1. Naming Conventions + +### 1.1. Functions + +Function names are capitalized and begin with the 'F' character. For example: + +```bash +CALL :FFUNCTION +GOTO :EOF + +:FFUNCTION + ECHO The FFUNCTION function has been executed! + EXIT /B 0 +``` + +### 1.2. Variables + +Variables are written in pascal case and begin with the 'V' character. For example: + +```bash +SET /A VResultData=1 +``` diff --git a/[01].DataStructures/BinaryTree.bat b/[01].DataStructures/BinaryTree.bat new file mode 100644 index 0000000..8b4d837 --- /dev/null +++ b/[01].DataStructures/BinaryTree.bat @@ -0,0 +1,166 @@ +:: =========================================================================================================== +:: @file BinaryTree.bat +:: @brief Binary tree implementation in batch file +:: @usage BinaryTree.bat +:: @see https://github.com/sebetci/batch.script/[01].DataStructures/BinaryTree.bat +:: @reference https://en.wikipedia.org/wiki/Binary_tree +:: @reference https://github.com/npocmaka/batch.scripts/tree/master/dataStructures +:: @reference https://www.dostips.com/forum/viewtopic.php?t=7642 +:: @todo The FFIND method does not search after the first level of the tree. +:: @todo The FDELETE method will be developed. +:: =========================================================================================================== + +@ECHO OFF +CALL :FMAIN +GOTO :EOF + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function inserts new values to the tree and then finds for some values in the tree. +:: @parameter None +:: @return None +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FMAIN + SETLOCAL ENABLEDELAYEDEXPANSION + + :: This variable must be assigned a value of 1 or 0. + :: If this variable is set to 1, the echo command in its sub-methods will work. + SET /A VDebug=1 + + :: The following commands add new nodes to the tree. + CALL :FINSERT VTreeName 1 + CALL :FINSERT VTreeName 3 + CALL :FINSERT VTreeName 5 + + :: The following commands find for the value 1 in the tree. + :: If the FFIND method finds the value 1, the variable %ERRORLEVEL% has the value 1. + ECHO. + ECHO [VDebug:MAIN] Searching for value 1 + CALL :FFIND VTreeName 1 + ECHO [VDebug:MAIN] Return Value: %ERRORLEVEL% + IF %ERRORLEVEL% EQU 0 (ECHO [VDebug:MAIN] 1 was found in the three.) ELSE (ECHO [VDebug:MAIN] 1 not found in tree.) + + :: The following commands find for the value 1 in the tree. + :: If the FFIND method does not find the value 8, the variable %ERRORLEVEL% will have the value 0. + ECHO. + ECHO [VDebug:MAIN] Searching for value 8 + CALL :FFIND VTreeName 8 + ECHO [VDebug:MAIN] Return Value: %ERRORLEVEL% + IF %ERRORLEVEL% EQU 0 (ECHO [VDebug:MAIN] 8 was found in the three.) ELSE (ECHO [VDebug:MAIN] 8 not found in tree.) + + :: The tree content is printed to the console. + CALL :FPRINT VTreeName + + :: This method content will be developed. + CALL :FDELETE VTreeName + EXIT /B 0 + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function searches the Value value in the VTreeName tree. It returns 0 if the +:: searched value is found in the tree. +:: @parameter VTreeName This parameter is the name of the node. +:: @parameter VValue This parameter is the value of the node. +:: @return Returns 0 if value is found in the tree. +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FFIND VTreeName VValue + :: SETLOCAL ENABLEDELAYEDEXPANSION + SET /A VValue=%~2 + + IF %VDebug% EQU 1 ECHO [VDebug:FIND] Content-1: %VTreeName% + IF %VDebug% EQU 1 ECHO [VDebug:FIND] Content-2: %VValue% + IF %VDebug% EQU 1 ECHO [VDebug:FIND] Param-1: %1 + IF %VDebug% EQU 1 ECHO [VDebug:FIND] Param-2: %2 + + IF %VTreeName% EQU %2 ( + ENDLOCAL & ( + EXIT /B 0 + ) + ) + + IF %VValue% GTR %1 ( + IF DEFINED %1R ( + ENDLOCAL & ( + CALL :FFIND %1R %VValue% + ) + ) ELSE ( + ENDLOCAL & ( + EXIT /B 1 + ) + ) + ) + + IF %VValue% LSS %1 ( + IF DEFINED %1L ( + ENDLOCAL & ( + CALL :FFIND %1L %VValue% + ) + ) ELSE ( + ENDLOCAL & ( + EXIT /B 1 + ) + ) + ) + + EXIT /B + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function adds a new node to the tree. +:: @parameter VTreeName This parameter is the name of the node. +:: @parameter VValue This parameter is the value of the node. +:: @return None +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FINSERT VTreeName VValue + SETLOCAL + SET /A VValue=%~2 + + IF NOT DEFINED %~1 ( + ENDLOCAL & ( + SET "%~1=%VValue%" + EXIT /B 0 + ) + ) + + IF %VValue% GEQ %~1R ( + IF NOT DEFINED %~1R ( + ENDLOCAL & ( + SET %~1R=%VValue% + EXIT /B 0 + ) + ) ELSE ( + ENDLOCAL & ( + CALL :FINSERT %~1R %VValue% + ) + ) + ) + + IF %VValue% LSS %~1L ( + IF NOT DEFINED %~1L ( + ENDLOCAL & ( + SET %~1L=%VValue% + EXIT /B 0 + ) + ) ELSE ( + ENDLOCAL & ( + CALL :FINSERT %~1R %VValue% + ) + ) + ) + EXIT /B 0 + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function prints the names and values of the node nodes in the tree. +:: @parameter VTreeName This parameter is the name of the node. +:: @return None +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FPRINT VTreeName + ECHO. + SET VTreeName + EXIT /B 0 + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function deletes all nodes in a tree. +:: @parameter VTreeName This parameter is the name of the node. +:: @return None +:: @todo Investigate the feasibility of this method. +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FDELETE VTreeName + EXIT /B 0 \ No newline at end of file diff --git a/[02].DateAndTime/DateParts.bat b/[02].DateAndTime/DateParts.bat new file mode 100644 index 0000000..18c83e8 --- /dev/null +++ b/[02].DateAndTime/DateParts.bat @@ -0,0 +1,26 @@ +:: =========================================================================================================== +:: @file DateParts.bat +:: @brief Gets date parts +:: @usage DateParts.bat +:: @see https://github.com/sebetci/batch.script/[02].DateAndTime/DateParts.bat +:: @reference https://stackoverflow.com/a/28250863/15032688 +:: @reference https://www.dostips.com/forum/viewtopic.php?f=3&t=4555 +:: @reference https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/makecab +:: @todo +:: =========================================================================================================== + +@ECHO OFF +PUSHD "%TEMP%" + +MAKECAB /D RPTFILENAME=~.RPT /D INFFILENAME=~.INF /F NUL >NUL + +FOR /F "TOKENS=3-7" %%A IN ('FIND /I "MAKECAB"^<~.RPT') DO ( + SET "VWeekDay=%%A" + SET "VCurrentDate=%%E-%%B-%%C" + SET "VCurrentTime=%%D" +) + +DEL ~.* +POPD +ECHO %VWeekDay% %VCurrentDate% %VCurrentTime% +GOTO :EOF \ No newline at end of file diff --git a/[02].DateAndTime/GetTime.bat b/[02].DateAndTime/GetTime.bat new file mode 100644 index 0000000..8f3fbfe --- /dev/null +++ b/[02].DateAndTime/GetTime.bat @@ -0,0 +1,35 @@ +:: =========================================================================================================== +:: @file GetTime.bat +:: @brief Gets time using typeperf command with put some effort to be made fast and +:: maximum compatible. +:: @usage GetTime.bat +:: @see https://github.com/sebetci/batch.script/[02].DateAndTime/GetTime.bat +:: @reference https://www.progress.com/blogs/understanding-iso-8601-date-and-time-format +:: @reference https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/typeperf +:: @todo +:: =========================================================================================================== + +@ECHO OFF +SETLOCAL + :: Check if Windows is XP and use XP valid counter for UDP performance + :: In Windows 10 the variable "USERDOMAIN_ROAMINGPROFILE" returns the device name. + IF DEFINED USERDOMAIN_ROAMINGPROFILE (SET "V=V4" & ECHO Device Name: %USERDOMAIN_ROAMINGPROFILE%) ELSE (SET "V=") + + :: The "typeperf" command writes performance counter data to the command window or to a supported log file format. + FOR /F "SKIP=2 DELIMS=," %%# IN ('TYPEPERF "\UDP%V%\*" -SI 0 -SC 1') DO ( + IF NOT DEFINED VMonth ( + FOR /F "TOKENS=1-7 DELIMS=.:/ " %%A IN (%%#) DO ( + SET VMonth=%%A + SET VDate=%%B + SET VYear=%%C + SET VHour=%%D + SET VMinute=%%E + SET VSecond=%%F + SET VMillisecond=%%G + ) + ) + ) + + :: ISO 8601 Date and Time Format + ECHO %VYear%-%VMonth%-%VDate% %VHour%:%VMinute%:%VSecond%.%VMillisecond% +ENDLOCAL \ No newline at end of file diff --git a/[02].DateAndTime/SleepEmulator.bat b/[02].DateAndTime/SleepEmulator.bat new file mode 100644 index 0000000..efe2539 --- /dev/null +++ b/[02].DateAndTime/SleepEmulator.bat @@ -0,0 +1,36 @@ +:: =========================================================================================================== +:: @file SleepEmulator.bat +:: @brief Yet another sleep emulator working on everything from NT and above +:: @syntax SleepEmulator.bat +:: @usage SleepEmulator.bat 10 +:: @description The above call provides a 10 second delay. +:: @see https://github.com/sebetci/batch.script/[02].DateAndTime/SleepEmulator.bat +:: @reference https://www.robvanderwoude.com/wait.php +:: @todo +:: =========================================================================================================== + +@ECHO OFF + +:: If there isn't first parameter, exit the script. +IF "%~1"=="" GOTO :FHELP + +:: If the first parameter isn't a number, exit the script. +ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL 2>NUL || GOTO :FHELP + +:: If the first parameter is less than 0, exit the script. +IF %~1 LSS 0 GOTO :FHELP + +:: The "typeperf" command writes performance counter data to the command window or to a supported log file format. +TYPEPERF "\SYSTEM\PROCESSOR QUEUE LENGTH" -SI %~1 -SC 1 >NUL +GOTO :EOF + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function prints the help menu on the screen. +:: @parameter None +:: @return None +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FHELP + ECHO Program Name: %~N0 + ECHO Description: Wait for a specifier number of seconds + ECHO Syntax: SleepEmulator.bat ^ + EXIT /B 0 \ No newline at end of file diff --git a/[02].DateAndTime/W32DOW.bat b/[02].DateAndTime/W32DOW.bat new file mode 100644 index 0000000..8260445 --- /dev/null +++ b/[02].DateAndTime/W32DOW.bat @@ -0,0 +1,49 @@ +:: =========================================================================================================== +:: @file W32DOW.bat +:: @brief Prints the day of the week +:: @syntax W32DOW.bat +:: @see https://github.com/sebetci/batch.script/[02].DateAndTime/W32DOW.bat +:: @reference https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/ff799054(v=ws.11) +:: @reference https://en.wikipedia.org/wiki/W32tm +:: @todo +:: =========================================================================================================== + +@ECHO OFF +SETLOCAL + :: Getting ANSI Date (Days passed from 1st Jan 1601), Timer Server Hour and Current Hour + :: In computing, W32TM is a command-line tool of Microsoft Windows operating systems used + :: to diagnose problems occurring with time setting or to troubleshoot any problems that might + :: occur during or after the configuration of the Windows Time service. + FOR /F "SKIP=16 TOKENS=4,5 DELIMS=:(" %%D IN ('W32TM /STRIPCHART /COMPUTER:LOCALHOST /SAMPLES:1 /PERIOD:1 /DATAONLY /PACKETINFO') DO ( + SET "VANSIDate=%%D" + ECHO [DEBUG:MAIN] ANSI Date: %VANSIDate% + + SET "VTimeServerHours=%%E" + ECHO [DEBUG:MAIN] Time Server Hours: %VTimeServerHours% + + GOTO :FENDFOR + ) + +:FENDFOR + ECHO [DEBUG:ENDFOR] Time: %TIME% + SET "VLocalHours=%TIME:~0,2%" + + IF "%VTimeServerHours:~0,1%0" EQU "00" SET VTimeServerHours=%VTimeServerHours:~1,1% + ECHO [DEBUG:ENDFOR] Time Server Hours: %VTimeServerHours% + + IF "%VLocalHours:~0,1%0" EQU "00" SET VLocalHours=%VLocalHours:~1,1% + ECHO [DEBUG:ENDFOR] Local Hours: %VLocalHours% + + SET /A VOffset=VTimeServerHours-VLocalHours + ECHO [DEBUG:ENDFOR] Offset: %VOffset% + + :: Day of the week will be the modulus of 7 of local ANSI date +1. + :: We need +1 because monday will be calculated as 0. 1st Jan 1601 was monday. + :: If ABS(VOffset)>12 we are in different days with the time server. + IF %VOffset%0 GTR 120 SET /A DOW=(VANSIDate+1)%%7+1 + IF %VOffset%0 LSS -120 SET /A DOW=(VANSIDate-1)%%7+1 + IF %VOffset%0 LEQ 120 IF %VOffset%0 GEQ -120 SET /A DOW=VANSIDate%%7+1 + + ECHO DAY OF THE WEEK: %DOW% + EXIT /B 2147483648 +ENDLOCAL \ No newline at end of file diff --git a/[02].DateAndTime/W32TMSleep.bat b/[02].DateAndTime/W32TMSleep.bat new file mode 100644 index 0000000..2aa3474 --- /dev/null +++ b/[02].DateAndTime/W32TMSleep.bat @@ -0,0 +1,43 @@ +:: =========================================================================================================== +:: @file W32TMSleep.bat +:: @brief Yet another sleep emulator working on everything from NT and above +:: @syntax W32TMSleep.bat +:: @usage W32TMSleep.bat 10 +:: @description The above call provides a 10 second delay. +:: @see https://github.com/sebetci/batch.script/[02].DateAndTime/W32TMSleep.bat +:: @reference https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/ff799054(v=ws.11) +:: @reference https://en.wikipedia.org/wiki/W32tm +:: @todo +:: =========================================================================================================== + +@ECHO OFF + +:: If there isn't first parameter, exit the script. +IF "%~1"=="" GOTO :FHELP + +:: If the first parameter isn't a number, exit the script. +ECHO.%*| FINDSTR /R /X /C:"[0-9][0-9]*" >NUL 2>NUL || GOTO :FHELP + +:: If the first parameter is less than 0, exit the script. +IF %~1 LSS 0 GOTO :FHELP + +SETLOCAL + SET /A VAdjust=%~1/2+1 + + :: In computing, W32TM is a command-line tool of Microsoft Windows operating systems used + :: to diagnose problems occurring with time setting or to troubleshoot any problems that might + :: occur during or after the configuration of the Windows Time service. + W32TM /STRIPCHART /COMPUTER:LOCALHOST /PERIOD:1 /DATAONLY /SAMPLES:%VAdjust% >NUL 2>&1 +ENDLOCAL +GOTO :EOF + +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: @function This function prints the help menu on the screen. +:: @parameter None +:: @return None +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:FHELP + ECHO Program Name: %~N0 + ECHO Description: Wait for a specifier number of seconds + ECHO Syntax: W32TMSleep.bat ^ + EXIT /B 0 \ No newline at end of file diff --git a/dataStructures/binaryTree.bat b/dataStructures/binaryTree.bat deleted file mode 100644 index 351a563..0000000 --- a/dataStructures/binaryTree.bat +++ /dev/null @@ -1,110 +0,0 @@ -@echo off -setlocal enableDelayedExpansion - -:: Binary tree implementation with pure batch -:: only insert and find methods are implmented so far -:: -:: it uses the binary tree name as the variable that holds -:: the root element and adds revursively to namer right elements -:: and namel the left elements. - -:::--- some tests ----- -call ::insert test_tree6 1 -call ::insert test_tree6 5 -call ::insert test_tree6 8 -call ::insert test_tree6 9999 - -color -echo searching for value 8 -call ::find test_tree6 8 -echo %errorlevel% - if 0 element is found -echo searching for value 123 -call ::find test_tree6 123 -echo %errorlevel% - if 1 element is not found -set test_tree6 -:::::::::::::::::::::::::::::: - -exit /b 0 - - -:find three_name value -setlocal enableDelayedExpansion -set /a value=%~2 -set node=%1 - -if %value% equ !%1! ( - endlocal & ( - echo %1 - exit /b 0 - ) -) - - -if %value% GTR !%1! ( - if defined %1r ( - endlocal & ( - call ::find %1r %value% - ) - ) else ( - endlocal & exit /b 1 - ) -) - -if %value% LSS !%1! ( - if defined %1l ( - endlocal & ( - call ::find %1l %value% - ) - ) else ( - endlocal & exit /b 1 - ) -) - - -exit /b - - - -:insert three_name value -setlocal -::set "three_name=%~1" -set /a value=%~2 - -if not defined %~1 ( - endlocal & ( - set "%~1=%value%" - exit /b 0 - ) -) - -if %value% GEQ %~1r ( - if not defined %~1r ( - endlocal & ( - set %~1r=%value% - exit /b 0 - ) - ) else ( - endlocal & ( - call ::insert %~1r %value% - rem exit /b 0 - ) - ) -) - -if %value% LSS %~1l ( - if not defined %~1l ( - endlocal & ( - set %~1l=%value% - exit /b 0 - ) - ) else ( - endlocal & ( - call ::insert %~1r %value% - rem exit /b 0 - ) - ) -) - -exit /b 0 - -:delete