113498266Sopenharmony_ci@echo off
213498266Sopenharmony_cirem ***************************************************************************
313498266Sopenharmony_cirem *                                  _   _ ____  _
413498266Sopenharmony_cirem *  Project                     ___| | | |  _ \| |
513498266Sopenharmony_cirem *                             / __| | | | |_) | |
613498266Sopenharmony_cirem *                            | (__| |_| |  _ <| |___
713498266Sopenharmony_cirem *                             \___|\___/|_| \_\_____|
813498266Sopenharmony_cirem *
913498266Sopenharmony_cirem * Copyright (C) Steve Holme, <steve_holme@hotmail.com>.
1013498266Sopenharmony_cirem *
1113498266Sopenharmony_cirem * This software is licensed as described in the file COPYING, which
1213498266Sopenharmony_cirem * you should have received as part of this distribution. The terms
1313498266Sopenharmony_cirem * are also available at https://curl.se/docs/copyright.html.
1413498266Sopenharmony_cirem *
1513498266Sopenharmony_cirem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1613498266Sopenharmony_cirem * copies of the Software, and permit persons to whom the Software is
1713498266Sopenharmony_cirem * furnished to do so, under the terms of the COPYING file.
1813498266Sopenharmony_cirem *
1913498266Sopenharmony_cirem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2013498266Sopenharmony_cirem * KIND, either express or implied.
2113498266Sopenharmony_cirem *
2213498266Sopenharmony_cirem * SPDX-License-Identifier: curl
2313498266Sopenharmony_cirem *
2413498266Sopenharmony_cirem ***************************************************************************
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci:begin
2713498266Sopenharmony_ci  rem Check we are running on a Windows NT derived OS
2813498266Sopenharmony_ci  if not "%OS%" == "Windows_NT" goto nodos
2913498266Sopenharmony_ci
3013498266Sopenharmony_ci  rem Set our variables
3113498266Sopenharmony_ci  setlocal
3213498266Sopenharmony_ci  set CHECK_LIB=TRUE
3313498266Sopenharmony_ci  set CHECK_SRC=TRUE
3413498266Sopenharmony_ci  set CHECK_TESTS=TRUE
3513498266Sopenharmony_ci  set CHECK_EXAMPLES=TRUE
3613498266Sopenharmony_ci  set SRC_DIR=
3713498266Sopenharmony_ci  set CUR_DIR=%cd%
3813498266Sopenharmony_ci  set ARG0_DIR=%~dp0
3913498266Sopenharmony_ci
4013498266Sopenharmony_ci:parseArgs
4113498266Sopenharmony_ci  if "%~1" == "" goto prerequisites
4213498266Sopenharmony_ci
4313498266Sopenharmony_ci  if /i "%~1" == "-?" (
4413498266Sopenharmony_ci    goto syntax
4513498266Sopenharmony_ci  ) else if /i "%~1" == "-h" (
4613498266Sopenharmony_ci    goto syntax
4713498266Sopenharmony_ci  ) else if /i "%~1" == "-help" (
4813498266Sopenharmony_ci    goto syntax
4913498266Sopenharmony_ci  ) else if /i "%~1" == "lib" (
5013498266Sopenharmony_ci    set CHECK_LIB=TRUE
5113498266Sopenharmony_ci    set CHECK_SRC=FALSE
5213498266Sopenharmony_ci    set CHECK_TESTS=FALSE
5313498266Sopenharmony_ci    set CHECK_EXAMPLES=FALSE
5413498266Sopenharmony_ci  ) else if /i "%~1" == "src" (
5513498266Sopenharmony_ci    set CHECK_LIB=FALSE
5613498266Sopenharmony_ci    set CHECK_SRC=TRUE
5713498266Sopenharmony_ci    set CHECK_TESTS=FALSE
5813498266Sopenharmony_ci    set CHECK_EXAMPLES=FALSE
5913498266Sopenharmony_ci  ) else if /i "%~1" == "tests" (
6013498266Sopenharmony_ci    set CHECK_LIB=FALSE
6113498266Sopenharmony_ci    set CHECK_SRC=FALSE
6213498266Sopenharmony_ci    set CHECK_TESTS=TRUE
6313498266Sopenharmony_ci    set CHECK_EXAMPLES=FALSE
6413498266Sopenharmony_ci  ) else if /i "%~1" == "examples" (
6513498266Sopenharmony_ci    set CHECK_LIB=FALSE
6613498266Sopenharmony_ci    set CHECK_SRC=FALSE
6713498266Sopenharmony_ci    set CHECK_TESTS=FALSE
6813498266Sopenharmony_ci    set CHECK_EXAMPLES=TRUE
6913498266Sopenharmony_ci  ) else (
7013498266Sopenharmony_ci    if not defined SRC_DIR (
7113498266Sopenharmony_ci      set SRC_DIR=%~1%
7213498266Sopenharmony_ci    ) else (
7313498266Sopenharmony_ci      goto unknown
7413498266Sopenharmony_ci    )
7513498266Sopenharmony_ci  )
7613498266Sopenharmony_ci
7713498266Sopenharmony_ci  shift & goto parseArgs
7813498266Sopenharmony_ci
7913498266Sopenharmony_ci:prerequisites
8013498266Sopenharmony_ci  rem Check we have Perl in our path
8113498266Sopenharmony_ci  perl --version <NUL 1>NUL 2>&1
8213498266Sopenharmony_ci  if errorlevel 1 (
8313498266Sopenharmony_ci    rem It isn't so check we have it installed and set the path if it is
8413498266Sopenharmony_ci    if exist "%SystemDrive%\Perl" (
8513498266Sopenharmony_ci      set "PATH=%SystemDrive%\Perl\bin;%PATH%"
8613498266Sopenharmony_ci    ) else (
8713498266Sopenharmony_ci      if exist "%SystemDrive%\Perl64" (
8813498266Sopenharmony_ci        set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
8913498266Sopenharmony_ci      ) else (
9013498266Sopenharmony_ci        goto noperl
9113498266Sopenharmony_ci      )
9213498266Sopenharmony_ci    )
9313498266Sopenharmony_ci  )
9413498266Sopenharmony_ci
9513498266Sopenharmony_ci:configure
9613498266Sopenharmony_ci  if "%SRC_DIR%" == "" (
9713498266Sopenharmony_ci    rem Are we being executed from the "projects" or main directory?
9813498266Sopenharmony_ci    if "%CUR_DIR%\" == "%ARG0_DIR%" (
9913498266Sopenharmony_ci      set SRC_DIR=..
10013498266Sopenharmony_ci    ) else if exist projects (
10113498266Sopenharmony_ci      if exist docs (
10213498266Sopenharmony_ci        if exist lib (
10313498266Sopenharmony_ci          if exist src (
10413498266Sopenharmony_ci            if exist tests (
10513498266Sopenharmony_ci              set SRC_DIR=.
10613498266Sopenharmony_ci            )
10713498266Sopenharmony_ci          )
10813498266Sopenharmony_ci        )
10913498266Sopenharmony_ci      )
11013498266Sopenharmony_ci    )
11113498266Sopenharmony_ci  )
11213498266Sopenharmony_ci  if not exist "%SRC_DIR%" goto nosrc
11313498266Sopenharmony_ci
11413498266Sopenharmony_ci:start
11513498266Sopenharmony_ci  if "%CHECK_SRC%" == "TRUE" (
11613498266Sopenharmony_ci    rem Check the src directory
11713498266Sopenharmony_ci    if exist %SRC_DIR%\src (
11813498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\src\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\src" -Wtool_hugehelp.c "%%i"
11913498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\src\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\src" "%%i"
12013498266Sopenharmony_ci    )
12113498266Sopenharmony_ci  )
12213498266Sopenharmony_ci
12313498266Sopenharmony_ci  if "%CHECK_LIB%" == "TRUE" (
12413498266Sopenharmony_ci    rem Check the lib directory
12513498266Sopenharmony_ci    if exist %SRC_DIR%\lib (
12613498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib" "%%i"
12713498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib" -Wcurl_config.h.cmake -Wcurl_config.h.in -Wcurl_config.h "%%i"
12813498266Sopenharmony_ci    )
12913498266Sopenharmony_ci
13013498266Sopenharmony_ci    rem Check the lib\vauth directory
13113498266Sopenharmony_ci    if exist %SRC_DIR%\lib\vauth (
13213498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vauth\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vauth" "%%i"
13313498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vauth\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vauth" "%%i"
13413498266Sopenharmony_ci    )
13513498266Sopenharmony_ci
13613498266Sopenharmony_ci    rem Check the lib\vquic directory
13713498266Sopenharmony_ci    if exist %SRC_DIR%\lib\vquic (
13813498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vquic\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vquic" "%%i"
13913498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vquic\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vquic" "%%i"
14013498266Sopenharmony_ci    )
14113498266Sopenharmony_ci
14213498266Sopenharmony_ci    rem Check the lib\vssh directory
14313498266Sopenharmony_ci    if exist %SRC_DIR%\lib\vssh (
14413498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vssh\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vssh" "%%i"
14513498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vssh\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vssh" "%%i"
14613498266Sopenharmony_ci    )
14713498266Sopenharmony_ci
14813498266Sopenharmony_ci    rem Check the lib\vtls directory
14913498266Sopenharmony_ci    if exist %SRC_DIR%\lib\vtls (
15013498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vtls\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vtls" "%%i"
15113498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vtls\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vtls" "%%i"
15213498266Sopenharmony_ci    )
15313498266Sopenharmony_ci  )
15413498266Sopenharmony_ci
15513498266Sopenharmony_ci  if "%CHECK_TESTS%" == "TRUE" (
15613498266Sopenharmony_ci    rem Check the tests\libtest directory
15713498266Sopenharmony_ci    if exist %SRC_DIR%\tests\libtest (
15813498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\libtest\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\libtest" "%%i"
15913498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\libtest\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\libtest" "%%i"
16013498266Sopenharmony_ci    )
16113498266Sopenharmony_ci
16213498266Sopenharmony_ci    rem Check the tests\unit directory
16313498266Sopenharmony_ci    if exist %SRC_DIR%\tests\unit (
16413498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\unit\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\unit" "%%i"
16513498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\unit\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\unit" "%%i"
16613498266Sopenharmony_ci    )
16713498266Sopenharmony_ci
16813498266Sopenharmony_ci    rem Check the tests\server directory
16913498266Sopenharmony_ci    if exist %SRC_DIR%\tests\server (
17013498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\server\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\server" "%%i"
17113498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\server\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\server" "%%i"
17213498266Sopenharmony_ci    )
17313498266Sopenharmony_ci  )
17413498266Sopenharmony_ci
17513498266Sopenharmony_ci  if "%CHECK_EXAMPLES%" == "TRUE" (
17613498266Sopenharmony_ci    rem Check the docs\examples directory
17713498266Sopenharmony_ci    if exist %SRC_DIR%\docs\examples (
17813498266Sopenharmony_ci      for /f "delims=" %%i in ('dir "%SRC_DIR%\docs\examples\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\docs\examples" -ASNPRINTF "%%i"
17913498266Sopenharmony_ci    )
18013498266Sopenharmony_ci  )
18113498266Sopenharmony_ci
18213498266Sopenharmony_ci  goto success
18313498266Sopenharmony_ci
18413498266Sopenharmony_ci:syntax
18513498266Sopenharmony_ci  rem Display the help
18613498266Sopenharmony_ci  echo.
18713498266Sopenharmony_ci  echo Usage: checksrc [what] [directory]
18813498266Sopenharmony_ci  echo.
18913498266Sopenharmony_ci  echo What to scan:
19013498266Sopenharmony_ci  echo.
19113498266Sopenharmony_ci  echo lib       - Scan the libcurl source
19213498266Sopenharmony_ci  echo src       - Scan the command-line tool source
19313498266Sopenharmony_ci  echo tests     - Scan the library tests and unit tests
19413498266Sopenharmony_ci  echo examples  - Scan the examples
19513498266Sopenharmony_ci  echo.
19613498266Sopenharmony_ci  echo directory - Specifies the curl source directory
19713498266Sopenharmony_ci  goto success
19813498266Sopenharmony_ci
19913498266Sopenharmony_ci:unknown
20013498266Sopenharmony_ci  echo.
20113498266Sopenharmony_ci  echo Error: Unknown argument '%1'
20213498266Sopenharmony_ci  goto error
20313498266Sopenharmony_ci
20413498266Sopenharmony_ci:nodos
20513498266Sopenharmony_ci  echo.
20613498266Sopenharmony_ci  echo Error: Only a Windows NT based Operating System is supported
20713498266Sopenharmony_ci  goto error
20813498266Sopenharmony_ci
20913498266Sopenharmony_ci:noperl
21013498266Sopenharmony_ci  echo.
21113498266Sopenharmony_ci  echo Error: Perl is not installed
21213498266Sopenharmony_ci  goto error
21313498266Sopenharmony_ci
21413498266Sopenharmony_ci:nosrc
21513498266Sopenharmony_ci  echo.
21613498266Sopenharmony_ci  echo Error: "%SRC_DIR%" does not exist
21713498266Sopenharmony_ci  goto error
21813498266Sopenharmony_ci
21913498266Sopenharmony_ci:error
22013498266Sopenharmony_ci  if "%OS%" == "Windows_NT" endlocal
22113498266Sopenharmony_ci  exit /B 1
22213498266Sopenharmony_ci
22313498266Sopenharmony_ci:success
22413498266Sopenharmony_ci  endlocal
22513498266Sopenharmony_ci  exit /B 0
226