@echo off
setlocal
REM ============================================================
REM Resolve script directory and astyle executable
REM ============================================================
set SCRIPT_DIR=%~dp0
set ASTYLE_EXE="%SCRIPT_DIR%astyle.exe"
REM ============================================================
REM Resolve BASELINE root
REM Script is in: Baseline\Tools\AStyle-...\AStyle-3.6.4
REM ============================================================
set BASELINE_DIR=%SCRIPT_DIR%..\..\
pushd "%BASELINE_DIR%" >nul
set BASELINE_DIR=%CD%
popd >nul
echo ============================================================
echo AStyle formatting started
echo Using: %ASTYLE_EXE%
echo Baseline root: %BASELINE_DIR%
echo ============================================================
echo.
REM ============================================================
REM Common AStyle flags
REM ============================================================
set ASTYLE_FLAGS=-A1 --indent=spaces=4 -C -S -N -w -m0 -M120 ^
-xW -xw -xg -p -H -U -k1 -y -xb -j -xy ^
-n -v -xC175 -xL ^
--pad-include --unpad-brackets --squeeze-lines=2 ^
--break-blocks=all --attach-return-type
REM ============================================================
REM 1) Client Source (recursive)
REM ============================================================
echo --- Formatting Client Source ---
pushd "%BASELINE_DIR%\Client\Source" || goto :error
for /r %%f in (*.h *.cpp) do (
echo Formatting: %%f
%ASTYLE_EXE% %ASTYLE_FLAGS% "%%f"
)
popd
echo.
REM ============================================================
REM 2) Server Source (recursive)
REM ============================================================
echo --- Formatting Server Source ---
pushd "%BASELINE_DIR%\Server\Source" || goto :error
for /r %%f in (*.h *.cpp) do (
echo Formatting: %%f
%ASTYLE_EXE% %ASTYLE_FLAGS% "%%f"
)
popd
echo.
REM ============================================================
REM 3) DumpProto (NON-recursive)
REM ============================================================
echo --- Formatting DumpProto ---
pushd "%BASELINE_DIR%\Tools\DumpProto\dump_proto" || goto :error
for %%f in (*.h *.cpp) do (
echo Formatting: %%f
%ASTYLE_EXE% %ASTYLE_FLAGS% "%%f"
)
popd
echo.
echo ============================================================
echo * * * * AStyle Job is Done! * * * *
echo ============================================================
pause
exit /b 0
:error
echo.
echo ERROR: One of the target directories was not found!
echo Please check your Baseline folder structure.
pause
exit /b 1