卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16333本站已运行3317

使用Clang工具创建一个C/C++代码格式化工具

使用Clang工具创建一个C/C++代码格式化工具

In this tutorial, we will be discussing a program to create a C/C++ code formatting tool with the help of clang tools.

SETUP

sudo apt install python
sudo apt install clang-format-3.5

然后我们将在当前用户具有读写权限的位置创建一个Python文件。

示例

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)

在当前用户的顶级目录中创建一个文件格式化文件。

输出

clang-format-3.5 -style=google -dump-config > .clang-format

最后将此文件复制到当前项目的顶级目录。

现在,您可以使用自己的代码格式化工具。只需运行创建的Python文件,您就可以开始使用了!

卓越飞翔博客
上一篇: 如何解决golang报错:invalid use of 'x' (type T) as type U in map index,解决步骤
下一篇: 如何用Python开发CMS系统的报表生成功能
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏