使用indent命令对代码进行格式化处理

来源:互联网 发布:怎样注销淘宝账号 编辑:程序博客网 时间:2024/05/18 20:06

indent命令是在linux源码script目录下的一个脚本,linux也可以安装indent命令:apt-get install indent

indent命令的使用方法很简单:

indent [options] [input-files]
indent [options] [single-input-file] [-o output-file]
indent --version


详细的options用法查看man手册即可,经常使用的是将源码文件转为linux内核的编码风格,可以这样使用:

sudo indent -linux pinctrl-hi3519.c


上面这个命令是将pinctrl-hi3519.c文件转成linux风格,man手册对linux风格的解释

The  Linux style is used in the linux kernel code and drivers. Code generally has to fol‐
       low the Linux coding style to be accepted.  This style is  equivalent  to  the  following
       settings:


            -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
            -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
            -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1


使用上面命令之后会生成一个pinctrl-hi3519.c~文件,这个文件是源文件的备份。


或者使用命令:

sudo indent -linux pinctrl-hi3519.c -o out.c

指定输出文件的文件名。




原创粉丝点击