Astyle使用方法

Astyle是一个命令行工具,使用方法
astyle [options] SourceFile1 SourceFile2 SourceFile3 […]

example:

格式一个文件
astyle –style=linux /home/user/project/foo.cpp
递归地格式cpp和h文件
astyle –style=linux –recursive /home/user/project/.cpp /home/user/project/.h


在Windows下使用astyle.

astyle –style=linux –recursive E:\nceWorkStation\nce_0.1\SRC*.c E:\nceWorkStation\nce_0.1\INC*.h

astyle –style=linux –recursive E:\nceWorkStation\nce_0.2\SRC*.c E:\nceWorkStation\nce_0.2\INC*.h

===========================================================================

Linux 环境中使用AStyle

在vim中的命令模式下,可以使用下面的某一种方式来格式化代码。

1. %!astyle (simple case - astyle default mode is C/C++)

或者

1. %!astyle --mode=c --style=ansi -s2 (ansi C++ style, use two spaces per indent level)

或者

1. 1,40!astyle --mode=c --style=ansi (ansi C++ style, filter only lines 1-40)

为方便使用,可以把它写成一个脚本,代码如下:

1. #! /bin/bash

2. 

3. for f in $(find . -name '*.c' -or -name '*.cpp' -type f)

4. do

5.     astyle $f

6. done

在格式化完代码后,会生成一个后缀为orig的文件,将脚本更改如下:

1. #! /bin/bash
2. 

3. for f in $(find . -name '*.c' -or -name '*.cpp' -or -name '*.h' -type f)
4. do
5.      astyle $f
6. done
7. 

8. # after formate the code,we need to rm '*.orig' files
9. for f in $(find . -name '*.orig' -type f)
10. do
11.      rm $f
12. done
13. 

http://blog.chinaunix.net/uid-25885064-id-3363736.html

posted @ 2015-05-26 10:10  chenqiangzhishen  阅读(554)  评论(0编辑  收藏  举报