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!")