-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcs.cmd
129 lines (112 loc) · 2.84 KB
/
vcs.cmd
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@echo off
if DEFINED _VCS_DEBUG echo DEBUG: %0 %* >con
if not defined VCS_BAT (
echo VCS_BAT variable must be set!
goto :EOF
)
if not defined VCS_CMD (
echo VCS_CMD variable must be set!
goto :EOF
)
:begin
rem MODE CON: CP SELECT=1251 >nul
setlocal
call :stamp2ticks %TIME%
call :push %_TIMETICKS%
if defined VCS_IGNORE_NUMERIC goto skip_numbering
set VCS_IGNORE_NUMERIC=1
if "%~2" == "" (set num=all) else (set /a num=%~2 2>nul )
if not "%~n1" == "n" if "%num%" == "%~2" %0 num %*
:skip_numbering
if "%~1" == "" goto err
if "%~1" == "?" goto showCommands
set filename=%~dp0%VCS_BAT%\%~1
if exist "%filename%" goto par
set filename=%~dp0%VCS_BAT%\%~1.cmd
if exist "%filename%" goto par
set filename=%~dp0vcs\%~1
if exist "%filename%" goto par
set filename=%~dp0vcs\%~1.cmd
if exist "%filename%" goto par
goto nofile
:par
shift
set param=
:loop
if "%~1" == "" goto endloop
set param=%param% "%~1"
shift
goto loop
:endloop
call %filename% %param%
goto ok
:nofile
%VCS_CMD% %*
goto ok
:err
call %0 ? | sort | more
goto ok
:showCommands
(
for %%i in (%~dp0%VCS_BAT%\*.cmd) do call :showCommand %%i
for %%i in (%~dp0vcs\*.cmd) do call :showCommand %%i
echo.
echo Run "%0 help <command> for full help.
)
goto :EOF
:showCommand
set hlp= (no help)
for /F "tokens=1,* delims=:" %%i in (%1) do if "%%i" == "REM " (
set hlp=%%j
goto :showCommandBreak
)
:showCommandBreak
echo "%~n1" %hlp%
goto :EOF
:stamp2ticks
for /f "tokens=1,2,3,4 delims=:.," %%i in ("%~1") do (set _TTHOUR=%%i)&(set _TTMIN=%%j)&(set _TTSEC=%%k)&(set _TTMSEC=%%l)
set /a _TIMETICKS=((_TTHOUR*60 + _TTMIN)*60 + _TTSEC)*100 + _TTMSEC
goto :EOF
:ticks2stamp
set /a _TIMESTAMP=%*
if %_TIMESTAMP% LSS 0 set /a _TIMESTAMP=_TIMESTAMP+8640000
if %_TIMESTAMP% GEQ 8639999 set _TIMESTAMP=0
set /a _TIMESTAMP=1000000000+(_TIMESTAMP/360000) * 1000000 + (_TIMESTAMP-(_TIMESTAMP/360000)*360000)/6000 * 10000 + (_TIMESTAMP-(_TIMESTAMP/6000)*6000)/100 * 100 + (_TIMESTAMP-(_TIMESTAMP/100)*100)
set _TIMESTAMP=%_TIMESTAMP:~-9,3%:%_TIMESTAMP:~-6,2%:%_TIMESTAMP:~-4,2%.%_TIMESTAMP:~-2,2%
goto :EOF
:push
call :push_shift 1
set _stack0=%*
goto :EOF
:push_shift
set /a _stack_pos=%*
if defined _stack%_stack_pos% call :push_shift %_stack_pos%+1
set /a _stack_pos=%*
set /a _stack_prev=%*-1
call set _stack%_stack_pos%=%%_stack%_stack_prev%%%
goto :EOF
:pop
set %1=%_stack0%
call :pop_shift 0
goto :EOF
:pop_shift
set /a _stack_pos=%*
set /a _stack_next=%*+1
call set _stack%_stack_pos%=%%_stack%_stack_next%%%
if defined _stack%_stack_next% call :pop_shift %_stack_pos%+1
goto :EOF
:length
set %~1=0
:length_loop
set _TEST=%~2
call call set _TEST=%%%%_TEST:~%%%~1%%,1%%%%
if "%_TEST%" == "" exit /b 1
set /a %~1=%~1+1
goto length_loop
:ok
call :stamp2ticks %TIME%
call :pop ROUTINE_START_TIME
call :ticks2stamp %_TIMETICKS%-%ROUTINE_START_TIME%
echo -=^("%*": Execution time: %_TIMESTAMP%^)=- >con
endlocal
goto :EOF