Today, I found a good tool, which is the indent tool. It can be a "messy" tool written by VI.Code.
Run the command: rpm-Qa | grep indent to check whether the indent tool is installed.
Indent
The tool can format the code into a certain style.
Use commands
Indent-Kr-i8 main. c
-KR
Option indicates K & R style,-I8
It indicates the length of 8 spaces. If no-Nut
Option, a tab is automatically used for every eight indentions. Note:Indent
The command directly modifies the original file instead of printing it on the screen or outputting it to another file, which is different from many UNIX commands. As you can see,-KR
-I8
The Code formatted by the two options already conforms to the Code style described in this chapter. After necessary indentation and blank spaces are added, long lines of code are automatically folded. In the US, we do not add proper blank lines becauseIndent
The tool does not know which lines of code are logically a group. Empty lines must be added by yourself. Of course, the original empty lines will not beIndent
Deleted.
If you adopt the kernel encoding style described in this chapter-Kr-i8
These two parameters are enough.Indent
The tool also supports other encoding styles. For more information, see man page. SometimesIndent
Tools are indeed very useful. For example, a project decides to change the encoding style (which is rare) in the middle, or several code files added to a project come from another project with different encoding styles, but it must not be becauseIndent
The tool is reckless. At first, the code was written in disorder and finally relied onIndent
To clean up.
Hurry up and try this command ~~~