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

2023年 8月 29日 76.9k 0

使用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文件,您就可以开始使用了!

以上就是使用Clang工具创建一个C/C++代码格式化工具的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论