Trong hướng dẫn này, tạo công cụ format code C/C++ với clang tools.
CÀI ĐẶT
sudo apt install python sudo apt install clang-format-3.5
Tạo file python ở thư mục người dùng có quyền đọc/ghi.
Ví dụ
import os
cpp_extensions = (".cxx",".cpp",".c", ".hxx", ".hh", ".cc", ".hpp")
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
if file.endswith(cpp_extensions):
os.system("clang-format-3.5 -i -style=file " + root + "/" + file)
Tạo file cấu hình format ở thư mục gốc dự án.
Kết quả
clang-format-3.5 -style=google -dump-config > .clang-format
Sao chép file này vào thư mục gốc dự án hiện tại.
Bây giờ có thể dùng công cụ format riêng. Chạy file python đã tạo!