ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมสร้าง C/C++ code formatting tool ด้วย clang tools
SETUP
sudo apt install python sudo apt install clang-format-3.5
จากนั้นสร้าง python file ใน location ที่ user ปัจจุบันมี read/write permissions
ตัวอย่าง
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)
สร้างไฟล์ formatting ใน top directory ของ current user
Output
clang-format-3.5 -style=google -dump-config > .clang-format
สุดท้าย copy ไฟล์นี้ไปยัง top directory ของ current project
ตอนนี้คุณสามารถใช้ code formatting tool ของตัวเองได้ แค่รัน python ที่สร้างไว้!