一款linux下用来格式化代码的工具
本来以为很好用,但却发现一个致命缺点,无法识别typedef重定义类型,必须一个个加"-T"参数来识别,看来无法通用
还是把研究的成果记录下,做个备忘吧
使用方法:
indent -kr -i8 test.c -o out.c ##按照linux内核代码风格,并且设置缩进为8,输出代码out.c
自己喜欢风格的参数定义:
-nbad -bap -bbo -nbc -bl -bli0 -bls -c33 -cd33 -ncdb -nce -ci4 -cli0 -cp33 -ncs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l80 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nut
可以将这些参数保存到当前用户下 ".indent.pro"作为默认参数
参数含义:
-nbad: --no-blank-lines-after-declarations 变量声明后不加空行
-bap: --blank-lines-after-procedures 函数结束后加空行
-bbo: --break-before-boolean-operator 较长的行,在逻辑运算符前分行
-nbc: --no-blank-lines-after-commas 变量声明中,逗号分割的变量不分行
-bl: --braces-after-if-line 'if' 和 '{' 分作两行
-bli0: --brace-indentn '{' 不继续缩进
-bls: --braces-after-struct-decl-line 定义结构体时, 'struct' 和 '{' 分行
-c33: --comment-indentationn 单行语句的注释,如果该行语句未超过33列,则注释位置从33列起
-cd33: --declaration-comment-column 变量声明后的注释,如果未超过33列,从33列起
-ncdb: --no-comment-delimiters-on-blank-lines 不将单行注释变为块注释
-nce: --dont-cuddle-else "else"和前面的"}"分行
-ci4: --continuation-indentationn 续行从上一行首字符缩进4个空格
-cli0: --case-indentation case和switch对齐
-cp33: --else-endif-column #else, #endif后面的注释开始于33列
-ncs: --no-space-after-casts 强制类型转换后不加空格
-d0: ???
-di1: --declaration-indentation 变量声明不对齐
-nfc1: --dont-format-first-column-comments 不格式化从第一列起的注释
-nfca: --dont-format-comments 不格式化注释
-hnl: --honour-newlines Prefer to break long lines at the position of newlines in the input
-i4: --indent-leveln 缩进为4个字符
-ip0: --parameter-indentation 旧风格的函数定义,参数缩进0个字符
-l80: --line-lengthn 非注释行最长80字符
-npcs: --no-space-after-function-call-names 调用函数时,不在函数名和其后的 ( 间加空格
-nprs: --no-space-after-parentheses '(' 后和 ')' 前不加空格
-npsl: --dont-break-procedure-type 函数返回类型和函数名不分行
-saf: --space-after-for 'for' 后加一个空格
-sai: --space-after-if 'if' 后加一个空格
-saw: --space-after-while 'while' 后加一个空格
-nsc: --dont-star-comments 单独一行的 '/* */'注释不要分行
-nsob: --leave-optional-blank-lines 不去除可有可无的空行
-nss: --dont-space-special-semicolon 一行的for或while语句,在 ';' 前不加空格
-nut: --no-tabs 空格替换Tab制表符