From cffcb7b21d39a9204693405c5fdb5f2e26155a0c Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 6 Mar 2025 23:34:24 -0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=B7=A5=E7=A8=8B=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 2 ++ script/format.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 build.sh create mode 100644 script/format.lua diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..b51d3ea --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +cmake -Bbuild -DCMAKE_BUILD_TYPE=Release +cmake --build build --config Release diff --git a/script/format.lua b/script/format.lua new file mode 100644 index 0000000..b5cee24 --- /dev/null +++ b/script/format.lua @@ -0,0 +1,37 @@ +local fs = require("lua_fs") + +-- 定义 clang-format 的路径和目标文件夹 +local clang_format_path = "/home/xx/.vscode-server/extensions/ms-vscode.cpptools-1.23.6/LLVM/bin/clang-format" -- 替换为你的 clang-format 路径 +local target_folder = "/home/xx/xxx-mirror" -- 替换为你要处理的文件夹路径 + +-- 检查目标文件夹是否存在 .clang-format 文件 +local clang_format_config = fs.append_path(target_folder, ".clang-format") +local style_option = "-style=LLVM" -- 默认使用 LLVM 风格 +if fs.exists(clang_format_config) then + style_option = "-style=file:" .. clang_format_config +end + +-- 递归遍历文件夹并格式化文件 +local function format_files_in_directory(dir_path) + local files = fs.get_dir_files(dir_path) + for _, file in ipairs(files) do + local full_path = fs.append_path(dir_path, file) + if fs.is_regular_file(full_path) then + -- 检查文件扩展名 + local ext = fs.get_extension(full_path) + if ext == ".h" or ext == ".cc" or ext == ".cpp" or ext == ".cxx" or ext == ".hpp" then + -- 格式化文件 + local command = string.format("%s %s -i %s", clang_format_path, style_option, full_path) + os.execute(command) + print("Formatted: " .. full_path) + end + else + -- 如果是文件夹,递归处理 + format_files_in_directory(full_path) + end + end +end + +-- 开始格式化 +format_files_in_directory(target_folder) +print("Formatting complete!")