Home > Backend Development > C++ > Create a C/C++ code formatting tool using Clang tool

Create a C/C++ code formatting tool using Clang tool

WBOY
Release: 2023-08-26 13:09:18
forward
1439 people have browsed it

Create a C/C++ code formatting tool using Clang tool

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
Copy after login

We will then create a Python file in a location where the current user has read and write permissions.

Example

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)
Copy after login

Creates a file format file in the current user's top-level directory.

Output

clang-format-3.5 -style=google -dump-config > .clang-format
Copy after login

Finally copy this file to the top-level directory of the current project.

Now you can use your own code formatting tool. Just run the created Python file and you're ready to go!

The above is the detailed content of Create a C/C++ code formatting tool using Clang tool. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template