linux下面的代码格式化工具应该挺多的吧,我没自己找过,就推荐一下我找到的这款代码格式化工具吧——Artistic
下载地址:http://sourceforge.net/projects/astyle/
首先确定安装了编译工具 build-essential ,如没安装可通过一下命令安装
sudo apt-get installbuild-essential
使用方法,把上面网址的源码下载到本地,解压到当前目录,安装它,终端安装命令
1
2
3
4
5
|
cd
astyle
cd
build
cd
gcc
make
make
install
|
这样就把 astyle 安装到系统了。
简单的使用如下,我们对 test.c 代码进行格式化
test.c代码如下:
|
运行命令
1
|
astyle
test
.c
|
然后会生成一个 test.c.orig ,这个文件是备份文件,备份原来的代码,格式化后的代码存于了 test.c 文件中效果如下:
#include <stdio.h>
voidmain(void)
{
printf("\nHello World!");
}