From 59cd0d6bb016bf596d35aa98a76319d013f04ceb Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 29 Jul 2024 01:10:46 +0800 Subject: [PATCH] .clang-format and code format script --- .clang-format | 12 ++++++++++++ code_format.sh | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 .clang-format create mode 100755 code_format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..51f3287f --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +BasedOnStyle: google +IndentWidth: 4 +TabWidth: 4 +ColumnLimit: 120 +UseTab: Never +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +BreakBeforeBraces: Allman +AccessModifierOffset: -4 +DerivePointerAlignment: false +PointerAlignment: Left diff --git a/code_format.sh b/code_format.sh new file mode 100755 index 00000000..3e2d3552 --- /dev/null +++ b/code_format.sh @@ -0,0 +1,18 @@ +#!/bin/bash +CLANG_FORMAT_PATH=$(which clang-format) + + if [ -z "$CLANG_FORMAT_PATH" ]; then + echo "clang-format not found." + exit 1 +fi + +PROJECT_ROOT=$(dirname "$0") + +cpp_files=$(find $PROJECT_ROOT -name '*.cpp' -or -name '*.h' ) + +for file in $cpp_files; do + echo "Formatting $file" + $CLANG_FORMAT_PATH -i $file +done + +echo "All .cpp or .h files have been formatted."