From aa77332c19f9930c2a80223f5c09f44e1da89c3d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:12:02 -0400 Subject: [PATCH 1/9] chore: Ensure runastyle scripts can be executed from any location This change updates the runastyle scripts to set the working directory to the script's directory, ensuring consistent behavior regardless of the initial execution location. --- runastyle | 4 ++++ runastyle.bat | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/runastyle b/runastyle index 64298273..36e292d6 100755 --- a/runastyle +++ b/runastyle @@ -4,6 +4,10 @@ # different versions might have different output (this has happened in # the past). +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +cd $SCRIPT_DIR + # If project management wishes to take a newer astyle version into use # just change this string to match the start of astyle version string. ASTYLE_VERSION="Artistic Style Version 3.0.1" diff --git a/runastyle.bat b/runastyle.bat index b8f11561..80171222 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -4,6 +4,12 @@ @REM different versions might have different output (this has happened in @REM the past). +@REM Get the directory of the script +SET SCRIPT_DIR=%~dp0 + +@REM Change to that directory +CD /d %SCRIPT_DIR% + @REM If project management wishes to take a newer astyle version into use @REM just change this string to match the start of astyle version string. @SET ASTYLE_VERSION="Artistic Style Version 3.0.1" From 5c791a48b77a2dd3fe8640824a203c6b0c7fc067 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 15:21:56 -0400 Subject: [PATCH 2/9] chore: Support astyle IDE integration and de-duplicate settings This change introduces a `.astylerc` configuration file to centralize and simplify the astyle settings for both the runastyle script and IDE integration. --- .astylerc | 15 +++++++++++++++ runastyle | 7 ++----- runastyle.bat | 7 ++----- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .astylerc diff --git a/.astylerc b/.astylerc new file mode 100644 index 00000000..25414900 --- /dev/null +++ b/.astylerc @@ -0,0 +1,15 @@ +# style +--style=kr +--indent=spaces=4 +--indent-namespaces +--lineend=linux +--min-conditional-indent=0 + +# options +--pad-header +--unpad-paren +--suffix=none +--convert-tabs +--attach-inlines +--attach-classes +--attach-namespaces diff --git a/runastyle b/runastyle index 36e292d6..2f3f45ae 100755 --- a/runastyle +++ b/runastyle @@ -20,8 +20,5 @@ if [[ "$DETECTED_VERSION" != ${ASTYLE_VERSION}* ]]; then exit 1; fi -style="--style=kr --indent=spaces=4 --indent-namespaces --lineend=linux --min-conditional-indent=0" -options="--options=none --pad-header --unpad-paren --suffix=none --convert-tabs --attach-inlines --attach-classes --attach-namespaces" - -$ASTYLE $style $options *.cpp -$ASTYLE $style $options *.h +$ASTYLE --options="$SCRIPT_DIR/.astylerc" *.cpp +$ASTYLE --options="$SCRIPT_DIR/.astylerc" *.h diff --git a/runastyle.bat b/runastyle.bat index 80171222..a01bc69e 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -25,8 +25,5 @@ CD /d %SCRIPT_DIR% GOTO EXIT_ERROR ) -@SET STYLE=--style=kr --indent=spaces=4 --indent-namespaces --lineend=linux --min-conditional-indent=0 -@SET OPTIONS=--pad-header --unpad-paren --suffix=none --convert-tabs --attach-inlines --attach-classes --attach-namespaces - -%ASTYLE% %STYLE% %OPTIONS% *.cpp -%ASTYLE% %STYLE% %OPTIONS% *.h \ No newline at end of file +%ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.cpp +%ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.h From da16a44dab46d4a3bc5fdbfd4063eddb08e8378c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:00:56 -0400 Subject: [PATCH 3/9] style: Format sources using astyle 3.0.1 This change applies code formatting to the source files using astyle version 3.0.1 according to the project's style guidelines. --- simplecpp.cpp | 8 ++++---- test.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index fd327549..87c92aca 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -761,18 +761,18 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename, while (stream.good() && ch != '\n') { currentToken += ch; ch = stream.readChar(); - if(ch == '\\') { + if (ch == '\\') { TokenString tmp; char tmp_ch = ch; - while((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) { + while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) { tmp += tmp_ch; tmp_ch = stream.readChar(); } - if(!stream.good()) { + if (!stream.good()) { break; } - if(tmp_ch != '\n') { + if (tmp_ch != '\n') { currentToken += tmp; } else { const TokenString check_portability = currentToken + tmp; diff --git a/test.cpp b/test.cpp index ccb653ca..09c2ba92 100644 --- a/test.cpp +++ b/test.cpp @@ -438,14 +438,14 @@ static void comment_multiline() ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code)); const char code1[] = "#define ABC {// \\\r\n" - "}\n" - "void f() ABC\n"; + "}\n" + "void f() ABC\n"; ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1)); const char code2[] = "#define A 1// \\\r" - "\r" - "2\r" - "A\r"; + "\r" + "2\r" + "A\r"; ASSERT_EQUALS("\n\n2\n1", preprocess(code2)); const char code3[] = "void f() {// \\ \n}\n"; @@ -2100,7 +2100,7 @@ static void circularInclude() "#define TEST_H\n" "#include \"a/a.h\"\n" "#endif\n" - ; + ; cache.insert({path, makeTokenList(code, files, path)}); } @@ -2111,7 +2111,7 @@ static void circularInclude() "#define A_H\n" "#include \"../test.h\"\n" "#endif\n" - ; + ; cache.insert({path, makeTokenList(code, files, path)}); } @@ -3176,7 +3176,8 @@ static void fuzz_crash() "n\n"; (void)preprocess(code, simplecpp::DUI()); // do not crash } - { // #346 + { + // #346 const char code[] = "#define foo(intp)f##oo(intp\n" "foo(f##oo(intp))\n"; (void)preprocess(code, simplecpp::DUI()); // do not crash From 3bba884a014ef602cb9113ea70ecbf37e0352fe2 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 15:10:01 -0400 Subject: [PATCH 4/9] chore: Refactor runastyle scripts to support future runners (pipx, uvx) This refactor introduces a dedicated `ASTYLE_VERSION` variable (formatted as `X.Y.Z`) and derives `ASTYLE_VERSION_STR` automatically. This separation makes it clearer where to update the required version and ensures consistency across platforms. The change simplifies maintenance and prepares the scripts for use with command runners such as `pipx` or `uvx`. --- runastyle | 16 +++++++++------- runastyle.bat | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/runastyle b/runastyle index 2f3f45ae..0cdd4d63 100755 --- a/runastyle +++ b/runastyle @@ -8,15 +8,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd $SCRIPT_DIR -# If project management wishes to take a newer astyle version into use -# just change this string to match the start of astyle version string. -ASTYLE_VERSION="Artistic Style Version 3.0.1" +# To require a newer astyle version, update ASTYLE_VERSION below. +# ASTYLE_VERSION_STR is then constructed to match the beginning of the +# version string reported by "astyle --version". +ASTYLE_VERSION="3.0.1" +ASTYLE_VERSION_STR="Artistic Style Version ${ASTYLE_VERSION}" ASTYLE="astyle" -DETECTED_VERSION=`$ASTYLE --version 2>&1` -if [[ "$DETECTED_VERSION" != ${ASTYLE_VERSION}* ]]; then - echo "You should use: ${ASTYLE_VERSION}"; - echo "Detected: ${DETECTED_VERSION}" +DETECTED_VERSION_STR=`$ASTYLE --version 2>&1` +if [[ "$DETECTED_VERSION_STR" != ${ASTYLE_VERSION_STR}* ]]; then + echo "You should use: ${ASTYLE_VERSION_STR}"; + echo "Detected: ${DETECTED_VERSION_STR}" exit 1; fi diff --git a/runastyle.bat b/runastyle.bat index a01bc69e..57b2df5c 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -10,18 +10,20 @@ SET SCRIPT_DIR=%~dp0 @REM Change to that directory CD /d %SCRIPT_DIR% -@REM If project management wishes to take a newer astyle version into use -@REM just change this string to match the start of astyle version string. -@SET ASTYLE_VERSION="Artistic Style Version 3.0.1" +@REM To require a newer astyle version, update ASTYLE_VERSION below. +@REM ASTYLE_VERSION_STR is then constructed to match the beginning of the +@REM version string reported by "astyle --version". +@SET ASTYLE_VERSION="3.0.1" +@SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%" @SET ASTYLE="astyle" -@SET DETECTED_VERSION="" -@FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION=%%i -@ECHO %DETECTED_VERSION% | FINDSTR /B /C:%ASTYLE_VERSION% > nul && ( - ECHO "%DETECTED_VERSION%" matches %ASTYLE_VERSION% +@SET DETECTED_VERSION_STR="" +@FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION_STR=%%i +@ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( + ECHO "%DETECTED_VERSION_STR%" matches %ASTYLE_VERSION_STR% ) || ( - ECHO You should use: %ASTYLE_VERSION% - ECHO Detected: "%DETECTED_VERSION%" + ECHO You should use: %ASTYLE_VERSION_STR% + ECHO Detected: "%DETECTED_VERSION_STR%" GOTO EXIT_ERROR ) From ca3ed55764bff9a3e6ad167ceac2345d230f0be4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:22:20 -0400 Subject: [PATCH 5/9] chore: Simplify runastyle.bat by using "@ECHO OFF" This change simplifies the Windows batch script by using "@ECHO OFF" to reduce unnecessary output, making the script cleaner and easier to read. --- runastyle.bat | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/runastyle.bat b/runastyle.bat index 57b2df5c..332317fe 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -1,25 +1,26 @@ -@REM Script to run AStyle on the sources -@REM The version check in this script is used to avoid commit battles -@REM between different developers that use different astyle versions as -@REM different versions might have different output (this has happened in -@REM the past). +@ECHO off +REM Script to run AStyle on the sources +REM The version check in this script is used to avoid commit battles +REM between different developers that use different astyle versions as +REM different versions might have different output (this has happened in +REM the past). -@REM Get the directory of the script +REM Get the directory of the script SET SCRIPT_DIR=%~dp0 -@REM Change to that directory +REM Change to that directory CD /d %SCRIPT_DIR% -@REM To require a newer astyle version, update ASTYLE_VERSION below. -@REM ASTYLE_VERSION_STR is then constructed to match the beginning of the -@REM version string reported by "astyle --version". -@SET ASTYLE_VERSION="3.0.1" -@SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%" -@SET ASTYLE="astyle" +REM To require a newer astyle version, update ASTYLE_VERSION below. +REM ASTYLE_VERSION_STR is then constructed to match the beginning of the +REM version string reported by "astyle --version". +SET ASTYLE_VERSION="3.0.1" +SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%" +SET ASTYLE="astyle" -@SET DETECTED_VERSION_STR="" -@FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION_STR=%%i -@ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( +SET DETECTED_VERSION_STR="" +FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION_STR=%%i +ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( ECHO "%DETECTED_VERSION_STR%" matches %ASTYLE_VERSION_STR% ) || ( ECHO You should use: %ASTYLE_VERSION_STR% From e55ca9282585967694984006b2f38b1daccb53df Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:38:44 -0400 Subject: [PATCH 6/9] chore: Fix runastyle.bat by adding missing EXIT_ERROR label This change adds the missing `EXIT_ERROR` label to the `runastyle.bat` script, ensuring proper error handling and exit status. --- runastyle.bat | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runastyle.bat b/runastyle.bat index 332317fe..0fed4c9d 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -30,3 +30,7 @@ ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( %ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.cpp %ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.h +GOTO :EOF + +:EXIT_ERROR +EXIT /b 1 From 421b688910f08d62938e864fe0cbbb97c9f36a79 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:51:22 -0400 Subject: [PATCH 7/9] chore: Require astyle 3.4.13 and switch to --project - Bump required astyle from 3.0.1 to 3.4.13 to enable easy installs via pipx/uvx from PyPI. - Keep formatting stable: 3.4.13 matches our current output, whereas 3.6.9 changes continuation-line indentation (e.g., after &&). - Use `--project` (available since 3.2) instead of `--options` to simplify config discovery. No formatting diffs expected with the current `.astylerc` --- runastyle | 7 ++++--- runastyle.bat | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/runastyle b/runastyle index 0cdd4d63..c26b8c09 100755 --- a/runastyle +++ b/runastyle @@ -11,7 +11,7 @@ cd $SCRIPT_DIR # To require a newer astyle version, update ASTYLE_VERSION below. # ASTYLE_VERSION_STR is then constructed to match the beginning of the # version string reported by "astyle --version". -ASTYLE_VERSION="3.0.1" +ASTYLE_VERSION="3.4.13" ASTYLE_VERSION_STR="Artistic Style Version ${ASTYLE_VERSION}" ASTYLE="astyle" @@ -22,5 +22,6 @@ if [[ "$DETECTED_VERSION_STR" != ${ASTYLE_VERSION_STR}* ]]; then exit 1; fi -$ASTYLE --options="$SCRIPT_DIR/.astylerc" *.cpp -$ASTYLE --options="$SCRIPT_DIR/.astylerc" *.h +# Run astyle with the project config +$ASTYLE --project *.cpp +$ASTYLE --project *.h diff --git a/runastyle.bat b/runastyle.bat index 0fed4c9d..eab4518e 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -14,7 +14,7 @@ CD /d %SCRIPT_DIR% REM To require a newer astyle version, update ASTYLE_VERSION below. REM ASTYLE_VERSION_STR is then constructed to match the beginning of the REM version string reported by "astyle --version". -SET ASTYLE_VERSION="3.0.1" +SET ASTYLE_VERSION="3.4.13" SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%" SET ASTYLE="astyle" @@ -28,8 +28,9 @@ ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( GOTO EXIT_ERROR ) -%ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.cpp -%ASTYLE% --options="%SCRIPT_DIR%/.astylerc" *.h +REM Run astyle with the project config +%ASTYLE% --project *.cpp +%ASTYLE% --project *.h GOTO :EOF :EXIT_ERROR From b3d385dcfd6a61934da1050d0803190dfbfa8011 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 18:54:14 -0400 Subject: [PATCH 8/9] chore: Add fallback to run astyle via uvx or pipx if not found in PATH This change improves the runastyle scripts to support multiple ways of invoking astyle. --- runastyle | 11 +++++++++++ runastyle.bat | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/runastyle b/runastyle index c26b8c09..4585cebd 100755 --- a/runastyle +++ b/runastyle @@ -15,6 +15,17 @@ ASTYLE_VERSION="3.4.13" ASTYLE_VERSION_STR="Artistic Style Version ${ASTYLE_VERSION}" ASTYLE="astyle" +if command -v astyle &> /dev/null; then + ASTYLE="astyle" +elif command -v uvx &> /dev/null; then + ASTYLE="uvx --quiet ${ASTYLE}==${ASTYLE_VERSION}" +elif command -v pipx &> /dev/null; then + ASTYLE="pipx run --quiet ${ASTYLE}==${ASTYLE_VERSION}" +else + echo "Neither astyle, uvx, nor pipx found in PATH" + exit 1 +fi + DETECTED_VERSION_STR=`$ASTYLE --version 2>&1` if [[ "$DETECTED_VERSION_STR" != ${ASTYLE_VERSION_STR}* ]]; then echo "You should use: ${ASTYLE_VERSION_STR}"; diff --git a/runastyle.bat b/runastyle.bat index eab4518e..171464d0 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -16,7 +16,24 @@ REM ASTYLE_VERSION_STR is then constructed to match the beginning of the REM version string reported by "astyle --version". SET ASTYLE_VERSION="3.4.13" SET ASTYLE_VERSION_STR="Artistic Style Version %ASTYLE_VERSION%" -SET ASTYLE="astyle" + +REM Prefer system astyle; else try uvx; else pipx +SET "ASTYLE=astyle" +where astyle >nul 2>nul +IF %errorlevel% neq 0 ( + where uvx >nul 2>nul + IF %errorlevel% eq 0 ( + SET "ASTYLE=uvx --quiet astyle==%ASTYLE_VERSION%" + ) ELSE ( + where pipx >nul 2>nul + IF %errorlevel% eq 0 ( + SET "ASTYLE=pipx run --quiet astyle==%ASTYLE_VERSION%" + ) ELSE ( + ECHO ERROR: Neither astyle, uvx, nor pipx found in PATH. + GOTO EXIT_ERROR + ) + ) +) SET DETECTED_VERSION_STR="" FOR /F "tokens=*" %%i IN ('%ASTYLE% --version') DO SET DETECTED_VERSION_STR=%%i From 7e499d37bb6640f0795572e11891ec18e696fee9 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 25 Aug 2025 19:20:49 -0400 Subject: [PATCH 9/9] chore: Simplify runastyle script by invoking executable once This change simplifies the runastyle script by combining the invocation of the astyle executable for both .h and .cpp files into a single command. --- runastyle | 3 +-- runastyle.bat | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runastyle b/runastyle index 4585cebd..fc7094c5 100755 --- a/runastyle +++ b/runastyle @@ -34,5 +34,4 @@ if [[ "$DETECTED_VERSION_STR" != ${ASTYLE_VERSION_STR}* ]]; then fi # Run astyle with the project config -$ASTYLE --project *.cpp -$ASTYLE --project *.h +$ASTYLE --project *.h,*.cpp diff --git a/runastyle.bat b/runastyle.bat index 171464d0..905e898e 100644 --- a/runastyle.bat +++ b/runastyle.bat @@ -46,8 +46,7 @@ ECHO %DETECTED_VERSION_STR% | FINDSTR /B /C:%ASTYLE_VERSION_STR% > nul && ( ) REM Run astyle with the project config -%ASTYLE% --project *.cpp -%ASTYLE% --project *.h +%ASTYLE% --project *.h,*.cpp GOTO :EOF :EXIT_ERROR