File: parse_version.bat

package info (click to toggle)
dlt-viewer 2.23.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,432 kB
  • sloc: cpp: 27,832; ansic: 4,454; xml: 491; sh: 154; makefile: 75
file content (46 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (4)
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
@echo off

set "missingArguments="
if "%~1" EQU "" set "missingArguments=1"
if "%~2" NEQ "PACKAGE_MAJOR_VERSION" (
    if "%~2" NEQ "PACKAGE_MINOR_VERSION" (
        if "%~2" NEQ "PACKAGE_PATCH_LEVEL" (
            set "missingArguments=1"
        )
    )
)

if defined missingArguments (
    call :printUsage
    goto :eof
)

set findFile="%1"
set findText="#define %2"

setlocal DisableDelayedExpansion
for /f "usebackq delims=" %%a in (`"findstr /C:%findText% %findFile%"`) do (
    set "foundLine=%%a"
    call :processLine foundLine findText
)
endlocal
goto :eof

:processLine
    setlocal EnableDelayedExpansion
    set "foundLine=!%1!"
    set findText=!%2:"=!
    set "foundValue=!foundLine:%findText%=!"
    call :trimString %foundValue% foundValue
    echo %foundValue%
    endlocal
goto :eof

:trimString
    set %2=%1
goto :eof

:printUsage
    echo Parse DLT Viewer version.h and return version number depending on requested part.
    echo Usage: parse_version.bat ^<path to version.h^> ^<PACKAGE_MAJOR_VERSION ^| PACKAGE_MINOR_VERSION ^| PACKAGE_PATCH_LEVEL^>
    exit /b 1