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.
IndentThe tool can format the code into a certain style.
Use commands
Indent-Kr-i8 main. c
-KROption indicates K & R style,-I8It indicates the length of 8 spaces. If no-NutOption, a tab is automatically used for every eight indentions. Note:IndentThe 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
-I8The 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 becauseIndentThe 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 beIndentDeleted.
If you adopt the kernel encoding style described in this chapter-Kr-i8These two parameters are enough.IndentThe tool also supports other encoding styles. For more information, see man page. SometimesIndentTools 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 becauseIndentThe tool is reckless. At first, the code was written in disorder and finally relied onIndentTo clean up.
Hurry up and try this command ~~~