您的位置:首页 > 编程语言

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

2017-08-24 13:41 281 查看
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

指定输出文件的文件名。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: