代码排版工具Uncrustify使用说明文档格式.docx

上传人:b****5 文档编号:21233817 上传时间:2023-01-28 格式:DOCX 页数:39 大小:89.66KB
下载 相关 举报
代码排版工具Uncrustify使用说明文档格式.docx_第1页
第1页 / 共39页
代码排版工具Uncrustify使用说明文档格式.docx_第2页
第2页 / 共39页
代码排版工具Uncrustify使用说明文档格式.docx_第3页
第3页 / 共39页
代码排版工具Uncrustify使用说明文档格式.docx_第4页
第4页 / 共39页
代码排版工具Uncrustify使用说明文档格式.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

代码排版工具Uncrustify使用说明文档格式.docx

《代码排版工具Uncrustify使用说明文档格式.docx》由会员分享,可在线阅读,更多相关《代码排版工具Uncrustify使用说明文档格式.docx(39页珍藏版)》请在冰豆网上搜索。

代码排版工具Uncrustify使用说明文档格式.docx

使用范围:

宽带产品部产品软件研发过程

2.3.执行标准

标准名称

版本号

发布单位

01

M2009015-软件编程规范

2.4.相关文档

文档名称

向忠清

2.5.参考资料

发表日期

出版单位/来源

3.代码排版工具使用说明

3.1.Uncrustify简介

Uncrustify是一个代码美化工具可用于C,C++,C#,ObjectiveC,D,Java,Pawn和VALA源代码的美化。

它能够利用空格,tab与空格或只有tab进行缩排,添加或删除换行,排列代码等,并且Uncrustify具有高配置性,易于修改的特点,可配合SourceInsight及MicrosoftVisualStudio进行使用。

3.2.安装Uncrustify

将文件解压缩即可,解压缩路径以“c:

\uncrustify”为例。

3.3.配置SourceInsight

1打开SourceInsight,选择菜单“Options-->

CustomCommands-->

Add”,输入uncrustify

2Run中输入:

C:

\uncrustify\-cC:

\uncrustify\–f%f–o%f

如果不想对源代码文件进行备份,可以输入:

C:

\uncrustify\--no-backup–f%f–o%f

3Dir不填写,将“File,thenLine”打上勾;

4然后点对话框中右侧的按钮“Keys...”设置快捷键“Ctrl+F8”;

5打开要格式化的文件,“Ctrl+F8”即可对当前文件格式化;

注1:

\uncrustify\–f%f–o%f命令中,-c表明需要调用配置文件,%f在SourceInsight中代表当前文件,–o表示将排版后的输出直接替换当前文件(需要当前文件已经保存,否则SourceInsight不会提示文件被外部编辑器改变,并重新载入)。

注2:

%f–o%f也可以使用%s来替换,表明输入的是当前文件中所选择的部分,即uncrustify只对当前所选择的代码进行排版。

如果要使用这种方式,请将“PasteOutput”进行勾选。

3.4.配置MicrosoftVisualStudio

1打开MicrosoftVisualStudio,选择菜单“工具-->

外部工具-->

添加”,在“标题”中输入输入uncrustify。

2命令中输入:

\uncrustify\

3参数中输入:

-cC:

\uncrustify\–f$(TargetName)–o$(TargetName)

如果不想对源代码文件进行备份,可以输入:

\uncrustify\--no-backup–f$(TargetName)–o$(TargetName)

4点击“确定”即可;

5打开要格式化的文件,选择菜单“工具-->

uncrustify”即可对当前文件格式化;

注:

$(TargetName)在MicrosoftVisualStudio中代表当前文件。

3.5.Uncrustify配置文件说明

1.缩进为4个空格,未使用Tab;

2.大括号不做缩进;

3.缩进Case;

4.对备注进行缩进;

5.运算符两端加空格;

6.赋值操作符两端加空格;

7.布尔操作符两端加空格;

8.比较操作符两端加空格;

9.'

if'

'

for'

switch'

及'

while'

与后面的'

('

之间加空格;

10.移除'

;

'

前面的空格;

11.'

'

后面加空格;

12.移除'

13.'

、'

Elseif'

Eles'

Try'

Finally'

For'

While'

Do'

Switch'

语句单独占一行;

14.大括号单独占一行;

15.遇'

就换行,除了在for语句声明中;

16.非注释行最大字符数为80;

17.'

的语句强制增加大括号;

18.'

#if'

#elseif'

#endif'

#define'

强制放在行首;

19.支持预编译指令的缩进及换行。

3.6.软件编程规范排版要求的支持情况

编程规范的要求

是否支持

全局变量的定义及函数声明应在头文件中给出;

.C文件中如有main()函数,则应将main()放在最前面。

不支持

需要人工判断

程序块要采用缩进风格编写。

缩进方式应与所用开发工具生动自动生成的缩进相一致。

缩进量要一致并以Tab键为单位,定义Tab为4个字节。

支持

未使用Tab键,用空格进行了替换。

相对独立的程序块之间、变量说明之后必须加空行。

较长的语句(>

80字符)要分成多行书写,长表达式要在低优先级操作符处划分新行,操作符放在新行之首,划分出的新行要进行适当的缩进,使排版整齐,语句可读(注:

一行程序以小于80字符为宜,不要写得过长)。

循环、判断等语句中若有较长的表达式或语句,则要进行适应当的划分,长表达式要在低优先级操作符处划分新行,操作符放在新行之首。

不完全支持

长度以上条所定义的为准

表达式中,若有多个操作符连写的情况,应使用空格对它们分隔。

不允许把多个短语句写在一行中,即一行只写一条语句。

if、for、do、while、case、switch、default等语句自占一行,且if、for、do、while等语句的执行语句部分无论多少都要加括号{}。

若只有一条语句时,将强制增加。

在两个以上的关键字、变量、常量进行对等操作时,它们之间的操作符前后要加空格;

进行非对等操作时,如果是关系密切的立即操作符(如->

),后不应加空格。

除上述支持的排版功能以外,此排版工具还定义了如下排版规则:

1.强制移除‘,’,‘;

’前面的空格;

2.'

3.对备注进行缩进;

4.附录Uncrustify参数说明

#

#Generaloptions

newlines{Auto,LF,CR,CRLF}

Thetypeoflineendings

input_tab_sizeNumber

Theoriginalsizeoftabsintheinput

output_tab_sizeNumber

Thesizeoftabsintheoutput(onlyusedifalign_with_tabs=true)

string_escape_charNumber

TheASCIIvalueofthestringescapechar,usually92(\)or94(^).(Pawn)

string_escape_char2Number

AlternatestringescapecharforPawn.Onlyworksrightbeforethequotechar.

tok_split_gte{False,True}

Allowinterpreting'

>

='

and'

aspartofatemplatein'

voidf(list<

list<

B>

=val);

.

Iftrue(default),'

assert(x<

0&

&

y>

=3)'

willbebroken.

Improvementstotemplatedetectionmaymakethisoptionobsolete.

utf8_bom{Ignore,Add,Remove,Force}

ControlwhattodowiththeUTF-8BOM(recommed'

remove'

utf8_byte{False,True}

Ifthefileonlycontainscharsbetween128and255andisnotUTF-8,thenoutputasUTF-8

utf8_force{False,True}

ForcetheoutputencodingtoUTF-8

#Indenting

indent_columnsNumber

Thenumberofcolumnstoindentperlevel.

Usually2,3,4,or8.

indent_continueNumber

Thecontinuationindent.Ifnon-zero,thisoverridestheindentof'

continuationindents.

ForFreeBSD,thisissetto4.

indent_with_tabsNumber

Howtousetabswhenindentingcode

0=spacesonly

1=indentwithtabstobracelevel,alignwithspaces

2=indentandalignwithtabs,usingspaceswhennotonatabstop

indent_cmt_with_tabs{False,True}

Commentsthatarenotabracelevelareindentedwithtabsonatabstop.

Requiresindent_with_tabs=2.Iffalse,willusespaces.

indent_align_string{False,True}

Whethertoindentstringsbrokenby'

\'

sothattheylineup

indent_xml_stringNumber

Thenumberofspacestoindentmulti-lineXMLstrings.

Requiresindent_align_string=True

indent_braceNumber

Spacestoindent'

{'

fromlevel

indent_braces{False,True}

Whetherbracesareindentedtothebodylevel

indent_braces_no_func{False,True}

Disabledindentingfunctionbracesifindent_bracesistrue

indent_braces_no_class{False,True}

Disabledindentingclassbracesifindent_bracesistrue

indent_braces_no_struct{False,True}

Disabledindentingstructbracesifindent_bracesistrue

indent_brace_parent{False,True}

Indentbasedonthesizeofthebraceparent,.'

=>

3spaces,'

4spaces,etc.

indent_namespace{False,True}

Whetherthe'

namespace'

bodyisindented

indent_namespace_levelNumber

Thenumberofspacestoindentanamespaceblock

indent_namespace_limitNumber

Ifthebodyofthenamespaceislongerthanthisnumber,itwon'

tbeindented.

Requiresindent_namespace=true.Default=0(nolimit)

indent_extern{False,True}

extern"

C"

indent_class{False,True}

class'

indent_class_colon{False,True}

Whethertoindentthestuffafteraleadingclasscolon

indent_ctor_initNumber

Additionalindentingforconstructorinitializerlist

indent_else_if{False,True}

False=treat'

else\nif'

as'

elseif'

forindentingpurposes

True=indentthe'

onelevel

indent_var_def_blkNumber

Amounttoindentvariabledeclarationsafteraopenbrace.neg=relative,pos=absolute

indent_var_def_cont{False,True}

Indentcontinuedvariabledeclarationsinsteadofaligning.

indent_func_call_param{False,True}

True:

indentcontinuedfunctioncallparametersoneindentlevel

False:

alignparametersundertheopenparen

indent_func_def_param{False,True}

Sameasindent_func_call_param,butforfunctiondefs

indent_func_proto_param{False,True}

Sameasindent_func_call_param,butforfunctionprotos

indent_func_class_param{False,True}

Sameasindent_func_call_param,butforclassdeclarations

indent_func_ctor_var_param{False,True}

Sameasindent_func_call_param,butforclassvariableconstructors

indent_template_param{False,True}

Sameasindent_func_call_param,butfortemplates

indent_func_param_double{False,True}

Doubletheindentforindent_func_xxx_paramoptions

indent_func_constNumber

Indentationcolumnforstandalone'

const'

functiondecl/protoqualifier

indent_func_throwNumber

throw'

indent_memberNumber

Thenumberofspacestoindentacontinued'

->

or'

.'

Usuallysetto0,1,orindent_columns.

indent_sing_line_commentsNumber

Spacestoindentsingleline('

indent_case_shiftNumber

Spacestoshiftthe'

case'

line,withoutaffectinganyotherlines

Usually0.

indent_case_braceNumber

from'

Bydefault,thebracewillappearunderthe'

c'

incase.

Usuallysetto0orindent_columns.

indent_col1_comment{False,True}

Whethertoindentcommentsfoundinfirstcolumn

indent_labelNumber

Howtoindentgotolabels

>

0:

absolutecolumnwhere1istheleftmostcolumn

<

=0:

subtractfrombraceindent

indent_access_specNumber

Sameasindent_label,butforaccessspecifiersthatarefollowedbyacolon

indent_access_spec_body{False,True}

Indentthecodeafteranaccessspecifierbyonelevel.

Ifset,thisoptionforces'

indent_access_spec=0'

indent_paren_nl{False,True}

Ifanopenparenisfollowedbyanewline,indentthenextlinesothatitlinesupaftertheopenparen(notrecommended)

indent_paren_closeNumber

Controlstheindentofacloseparenafteranewline.

0:

Indenttobodylevel

1:

Alignundertheopenparen

2:

Indenttothebracelevel

indent_comma_paren{False,True}

ControlstheindentofacommawheninsideaTRUE,alignsundertheopenparen

indent_bool_paren{False,True}

ControlstheindentofaBOOLoperatorwheninsideaTRUE,alignsundertheopenparen

indent_first_bool_expr{False,True}

If'

indent_bool_paren'

istrue,controlstheindentofthefirstexpression.IfTRUE,alignsthefirstexpressiontothefollowingones

indent_square_nl{False,True}

Ifanopensquareisfollowedbyanewline,indentthenextlinesothatitlinesupaftertheopensquare(notrecommended)

indent_preserve_sql{False,True}

Don'

tchangetherelativeindentofESQL/C'

EXECSQL'

bodies

indent_align_assign{False,True}

Aligncontinuedstatementsatthe'

.Default=True

IfFALSEorthe'

isfollowedbyanewline,thenextlineisindentonetab.

#Spacingoptions

sp_arith{Ignore,Add,Remove,Force}

Addorremovespacearoundarithmeticoperator'

+'

-'

/'

*'

etc

sp_assign{Ignor

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1