forked from PassingTheKnowledge/Batchography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds-stacks.bat
49 lines (39 loc) · 916 Bytes
/
ds-stacks.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@echo off
::
:: The Batchography book by Elias Bachaalany
::
setlocal enabledelayedexpansion
for /L %%a in (1, 1, 10) DO (
echo Push %%a
call :push STK %%a
)
echo.
echo.
:test-pop-more
call :pop STK V
if not defined V goto test-pop-no-more
echo Pop -^> %V%
goto test-pop-more
:test-pop-no-more
goto :eof
:push <1=variable> <2=value> [3=value, 4=value, ...]
:push-more
call set %~1=%~2~%%%1%%
shift /2
if "%2" NEQ "" goto push-more
goto :eof
:pop <1=variable> => <2=out-variable>
:: Clear previous output variable
set %~2=
setlocal
:: Expand the value of the input variable
call set VAL=%%%~1%%
:: Tokenize, take two tokens: first token and the remaining ones
for /F "usebackq tokens=1* delims=~" %%a in ('%VAL%') DO (
endlocal
:: Pop off the value
set %~1=%%b
:: Return the popped value
set %~2=%%a
)
goto :eof