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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值