Astyle 给代码调整格式

本文介绍了如何使用Astyle工具对C语言代码进行格式化,包括各种选项的设置,如代码风格、括号处理、缩进、换行等,以实现代码的统一和整洁。
摘要由CSDN通过智能技术生成

1. 代码格式化,往往是程序员头疼的事情,不同公司代码格式不一样,风格也不一样。提供几种方法吧。

    1) astyle

astyle -A1 -z2 -xC100 -xL -j -O -o -s4 -K -m0 -M80 -w -c -H -U -p -Z -n -k3 *.c  短指令

-A1   

--style=allman / --style=bsd / --style=break / -A1

Allman style uses broken brackets.

int Foo(bool isBar)
{
   
    if (isBar)
    {
   
        bar();
        return 1;
    }
    else
        return 0;
}

--lineend=windows / -z1
--lineend=linux   / -z2
--lineend=macold  / -z3 

Force use of the specified line end style. Valid options are windows (CRLF), linux (LF), and macold (CR). MacOld style is the format for Mac OS 9 and earlier. OS X uses the Linux style. If one of these options is not used the line ends will be determined automatically from the input file.

--attach-classes / -xc
Attach brackets to a class statement. This is done regardless of the bracket style being used.

the bracket is always attached to a class statement:

class FooClass {
   
...
};

 

--attach-inlines / -xl
Attach brackets to class and struct inline function definitions. This is not done for run-in type brackets (Horstmann and Pico styles). This option is effective for C++ files only.

all brackets are always attached to class and struct inline function definitions:

class FooClass
{
   
    void Foo() {
   
    ...
    }
};

 

--add-brackets / -j 
Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...). The statement must be on a single line. The brackets will be added according to the currently requested predefined style or bracket type. If no style or bracket type is requested the brackets will be attached. If --add-one-line-brackets is also used the result will be one line brackets.

if (isFoo)
    isFoo = false;

becomes:

if (isFoo) {
   
    isFoo = false;
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值