Creating a C/C++ Code Formatting tool with help of Clang tools
Today we are going to discuss formatting files in the user’s workspace by their extension. For this we are going to make use of Clang’s format tools.
- Linux Machine
- Clang Tool
- Create a python file named format-code.py at any location where you have read and write permissions. In this example we are going to create it in /home/user/. It shall contain the following code:
root, dirs, files
"clang-format-3.5 -i -style=file "
- Create format specification file and copy it to project’s top level directory , e.g., /home/user/myproject/
- Create formatting file (in example, we are creating google coding style tool)
clang-format-3.5 -style=google -dump-config > .clang-format
- Copy it to project’s directory i.e., it’s location becomes: /home/user/myproject/.clang-format
How to use it?
- Navigate to the directory whose files you want to format, e.g.,
- Run the format-code file that you created earlier
This shall format all the files in our source directory with the extension same as that mentioned in the code.
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!