From 4d2ce215233f2ae47468e67264c9984bd8bfe390 Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Fri, 20 Oct 2023 16:38:02 +1000 Subject: [PATCH 1/9] Adding clang-format configuration and script --- tools/.clang-format | 7 +++++++ tools/format.sh | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 tools/.clang-format create mode 100755 tools/format.sh diff --git a/tools/.clang-format b/tools/.clang-format new file mode 100644 index 000000000..0b3e2c2c4 --- /dev/null +++ b/tools/.clang-format @@ -0,0 +1,7 @@ +BasedOnStyle: Google +ColumnLimit: 300 +IndentWidth: 4 +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Always diff --git a/tools/format.sh b/tools/format.sh new file mode 100755 index 000000000..8f7f83e91 --- /dev/null +++ b/tools/format.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +PP=$(dirname $0) +clang-format --style=file:$PP/.clang-format "$@" \ + | sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ + | sed -E 's| ([*/]) |\1|g' From 74f0bf98707b7ac0cc813546433b73ff5a1ab59a Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Thu, 26 Oct 2023 13:32:05 +1000 Subject: [PATCH 2/9] Adding left aligned pointers --- tools/.clang-format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/.clang-format b/tools/.clang-format index 0b3e2c2c4..2d15bd7aa 100644 --- a/tools/.clang-format +++ b/tools/.clang-format @@ -5,3 +5,5 @@ AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: InlineOnly AllowShortIfStatementsOnASingleLine: Always +DerivePointerAlignment: false +PointerAlignment: Left From c31a36a35786cca847036ab203495313afd3f57e Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 09:51:25 +1000 Subject: [PATCH 3/9] Adding RT tokenize to tools/format.sh --- tools/format.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/format.sh b/tools/format.sh index 8f7f83e91..a5e43817f 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -1,6 +1,9 @@ #!/bin/bash PP=$(dirname $0) -clang-format --style=file:$PP/.clang-format "$@" \ + +R -s -e 'rtemplate::RTtokenize()' \ + | clang-format --style=file:$PP/.clang-format "$@" \ | sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ - | sed -E 's| ([*/]) |\1|g' + | sed -E 's| ([*/]) |\1|g' \ + | R -s -e 'rtemplate::RTtokenize(inv=TRUE)' From 88c50a74824817736ac81a8513ce8e0f89c030fc Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 11:31:36 +1000 Subject: [PATCH 4/9] Making format script check checksums --- .gitignore | 1 + tools/format.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index bce41f311..140db3a05 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ p /*.txt .idea/* *.ipynb_checkpoint* +tools/.format/* diff --git a/tools/format.sh b/tools/format.sh index a5e43817f..0d7a16831 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -2,8 +2,48 @@ PP=$(dirname $0) -R -s -e 'rtemplate::RTtokenize()' \ - | clang-format --style=file:$PP/.clang-format "$@" \ - | sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ - | sed -E 's| ([*/]) |\1|g' \ - | R -s -e 'rtemplate::RTtokenize(inv=TRUE)' +function format { + clang-format --style=file:$PP/.clang-format \ + | sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ + | sed -E 's| ([*/]) |\1|g' +} + +function formatRT { + R -s -e 'rtemplate::RTtokenize()' | format | R -s -e 'rtemplate::RTtokenize(inv=TRUE)' +} + +function chsum { + sha256sum | cut -c 1-30 +} + +if test -z "$1" +then + formatRT +else + F=format + if [[ "$1" =~ \.[rR][tT]$ ]] + then + F=formatRT + fi + if test -z "$2" + then + cat "$1" | $F + else + mkdir -p $PP/.format + NAMESUM=$(echo "$1 $2" | sha256sum | cut -c 1-30) + SUMFILE="$PP/.format/$NAMESUM" + if test -f "$SUMFILE" + then + if sha256sum --check "$SUMFILE" >/dev/null + then + echo "Skipping $1" + exit 0 + fi + fi + echo "Running $F on $1" + cat "$1" | $F >tmp + mv tmp "$2" + sha256sum "$1" "$2" >"$SUMFILE" + fi +fi +exit 0 From f73a91de5e22cea6d43093ebbaeb49362762d78b Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 13:51:28 +1000 Subject: [PATCH 5/9] Adding nice options to tools/format.sh --- tools/format.sh | 146 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 120 insertions(+), 26 deletions(-) diff --git a/tools/format.sh b/tools/format.sh index 0d7a16831..eb8ee3aa4 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -1,9 +1,13 @@ #!/bin/bash +set -o pipefail + PP=$(dirname $0) +FORMATFILE="$PP/.clang-format" +PRINTSKIP=true function format { - clang-format --style=file:$PP/.clang-format \ + clang-format --style=file:$FORMATFILE \ | sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ | sed -E 's| ([*/]) |\1|g' } @@ -12,38 +16,128 @@ function formatRT { R -s -e 'rtemplate::RTtokenize()' | format | R -s -e 'rtemplate::RTtokenize(inv=TRUE)' } -function chsum { - sha256sum | cut -c 1-30 +function format_sel { + if [[ -z "$1" || "$1" =~ \.[rR][tT]$ ]] + then + echo formatRT + else + echo format + fi } -if test -z "$1" -then - formatRT -else - F=format - if [[ "$1" =~ \.[rR][tT]$ ]] +function format_to { + F="$(format_sel "$1")" + if test -z "$1" || test -z "$2" then - F=formatRT + echo "Something went wrong in format_to" + exit 5 + fi + mkdir -p $PP/.format + NAMESUM=$(echo "$1 $2" | sha256sum | cut -c 1-30) + SUMFILE="$PP/.format/$NAMESUM" + if test -f "$SUMFILE" + then + if sha256sum --status --check "$SUMFILE" + then + $PRINTSKIP && echo "Skipping $1" + return 0 + fi fi - if test -z "$2" + if [[ "$1" == "$2" ]] then - cat "$1" | $F + echo "Running $F on $1" else - mkdir -p $PP/.format - NAMESUM=$(echo "$1 $2" | sha256sum | cut -c 1-30) - SUMFILE="$PP/.format/$NAMESUM" - if test -f "$SUMFILE" + echo "Running $F on $1 -> $2" + fi + cat "$1" | $F >tmp + mv tmp "$2" + sha256sum "$1" "$2" "$FORMATFILE" >"$SUMFILE" +} + +OUTFILE="" +OUTSAME=false +while test -n "$1" +do + case "$1" in + --help) + echo "" + echo "$0 [--all] [-o output] [-x] [files]" + echo "" + echo " -o (--output) OUTPUT : put the formated output in OUTPUT" + echo " -x (--overwrite) : put the formated output in the same file" + echo " --all [FROM_DIR] [TO_DIR] : format all source files in DIR" + echo "" + exit 0; + ;; + -o|--output) + shift + OUTFILE="$1" + ;; + -x|--overwrite) + OUTSAME=true + ;; + -a|--all) + shift + FROM_DIR="src" + if ! test -z "$1" then - if sha256sum --check "$SUMFILE" >/dev/null + if ! test -d "$1" then - echo "Skipping $1" - exit 0 + echo "$1: not a directory" + exit 3 fi + FROM_DIR="$1" + shift fi - echo "Running $F on $1" - cat "$1" | $F >tmp - mv tmp "$2" - sha256sum "$1" "$2" >"$SUMFILE" - fi -fi -exit 0 + TO_DIR="$FROM_DIR" + if ! test -z "$1" + then + if ! test -d "$1" + then + echo "$1: not a directory" + exit 3 + fi + TO_DIR="$1" + shift + fi + if test "$FROM_DIR" == "$TO_DIR" && ! $OUTSAME + then + echo "Trying to format all file into the same directory. If you want to overwrite say '-x'" + exit 4 + fi + PRINTSKIP=false + find "$FROM_DIR" | grep -E '[.](cpp|h|hpp)([.]Rt|)$' | while read i + do + if test "$FROM_DIR" == "$TO_DIR" + then + j="$i" + else + j="$TO_DIR/${i#$FROM_DIR}" + fi + format_to "$i" "$j" + done + ;; + -p|--pipe) + formatRT + ;; + -*) + echo "Uknown option $1" + exit 1; + ;; + *) + INFILE="$1" + if $OUTSAME && test -z "$OUTFILE" + then + OUTFILE="$INFILE" + fi + if test -z $OUTFILE + then + cat "$INFILE" | $(format_sel "$INFILE") + else + format_to "$INFILE" "$OUTFILE" + OUTFILE="" + fi + esac + shift +done + From fc7bef53496b7cd92146ab3deca85b52523b1720 Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 14:00:51 +1000 Subject: [PATCH 6/9] Correcting exit status of format.sh --- tools/format.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/format.sh b/tools/format.sh index eb8ee3aa4..e4bb8ff6f 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -141,3 +141,4 @@ do shift done +exit 0 From fc84ef9912790a65bd49f86879821f43ad03243b Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 14:01:25 +1000 Subject: [PATCH 7/9] Correcting small issues causing problems when headers are reordered --- src/Factory.h | 2 +- src/Geometry.h | 1 + src/Region.h | 1 + src/SolidTree.h | 4 ---- src/def.h | 1 + src/types.h | 5 +++++ 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Factory.h b/src/Factory.h index bead2abcc..c356dd8b9 100644 --- a/src/Factory.h +++ b/src/Factory.h @@ -47,7 +47,7 @@ class Factory { ret = (*it)->Produce(input); if (ret) return ret; } - return NULL; + return nullptr; }; // Template class for registration of the worker functions template diff --git a/src/Geometry.h b/src/Geometry.h index 408f44129..9e1f99b86 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -2,6 +2,7 @@ #define GEOMETRY_H #include "unit.h" +#include "pugixml.hpp" #include /// STL triangle structure #ifdef _WIN32 diff --git a/src/Region.h b/src/Region.h index 9103b82fd..fdee2516a 100644 --- a/src/Region.h +++ b/src/Region.h @@ -1,6 +1,7 @@ #ifndef REGION_H #include +#include "cross.h" class lbRegion { public: int dx,dy,dz; diff --git a/src/SolidTree.h b/src/SolidTree.h index 4f04f8e0b..e8883b0f5 100644 --- a/src/SolidTree.h +++ b/src/SolidTree.h @@ -8,10 +8,6 @@ #include #include -typedef char tr_flag_t; -typedef int tr_addr_t; -typedef double tr_real_t; - struct tr_elem { tr_flag_t flag; tr_addr_t right; diff --git a/src/def.h b/src/def.h index 20bf73026..ff75c04bd 100644 --- a/src/def.h +++ b/src/def.h @@ -1,2 +1,3 @@ +#include "pugixml.hpp" extern pugi::xml_document xml_def; int xml_def_init(); diff --git a/src/types.h b/src/types.h index 84ebeb1e9..486f6a99e 100644 --- a/src/types.h +++ b/src/types.h @@ -28,6 +28,11 @@ #define CUT_MAX 65000 #define CUT_LEN(x__) (0.005f * (x__)) + typedef char tr_flag_t; + typedef int tr_addr_t; + typedef double tr_real_t; + + /* struct vector_t { real_t x,y,z; From 7891c109a900545c0e6b52d6e8e9e9639e9c20bd Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 14:11:03 +1000 Subject: [PATCH 8/9] Correcting header inclusion in SolidGrid and SolidTree --- src/SolidGrid.h | 1 + src/SolidTree.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/SolidGrid.h b/src/SolidGrid.h index fa345b74d..893517b27 100644 --- a/src/SolidGrid.h +++ b/src/SolidGrid.h @@ -7,6 +7,7 @@ #include #include #include +#include "types.h" typedef int gr_addr_t; diff --git a/src/SolidTree.h b/src/SolidTree.h index 9b34f80d6..fbeb9b28b 100644 --- a/src/SolidTree.h +++ b/src/SolidTree.h @@ -7,6 +7,7 @@ #include #include #include +#include "types.h" struct tr_elem { tr_flag_t flag; From 14d193a67437ceaf8a47bc84da68d71bbf61dec2 Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 13 Nov 2023 16:48:18 +1000 Subject: [PATCH 9/9] Small mods to format --- tools/.clang-format | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/.clang-format b/tools/.clang-format index 2d15bd7aa..848316a23 100644 --- a/tools/.clang-format +++ b/tools/.clang-format @@ -1,5 +1,5 @@ BasedOnStyle: Google -ColumnLimit: 300 +ColumnLimit: 160 IndentWidth: 4 AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: false @@ -7,3 +7,6 @@ AllowShortFunctionsOnASingleLine: InlineOnly AllowShortIfStatementsOnASingleLine: Always DerivePointerAlignment: false PointerAlignment: Left +BinPackArguments: false +BinPackParameters: false +ReflowComments: false