1、使用范围:宽带产品部产品软件研发过程2.3.执行标准标准名称版本号发布单位01M2009015-软件编程规范2.4.相关文档文档名称向忠清2.5.参考资料发表日期出版单位/来源无3. 代码排版工具使用说明3.1.Uncrustify简介Uncrustify是一个代码美化工具可用于C,C+,C#,ObjectiveC,D,Java,Pawn和VALA源代码的美化。它能够利用空格,tab与空格或只有tab进行缩排,添加或删除换行,排列代码等,并且Uncrustify具有高配置性,易于修改的特点,可配合Source Insight及Microsoft Visual Studio进行使用。3.2.安装
2、Uncrustify将文件解压缩即可,解压缩路径以“c:uncrustify”为例。3.3.配置Source Insight1 打开SourceInsight, 选择菜单“Options-Custom Commands-Add”, 输入uncrustify2 Run中输入: C:uncrustify -c C:uncrustify f %f o %f 如果不想对源代码文件进行备份,可以输入:C:uncrustify -no-backup f %f o %f3 Dir不填写,将“File,then Line”打上勾;4 然后点对话框中右侧的按钮“Keys.”设置快捷键“Ctrl+F8”;5 打开
3、要格式化的文件,“Ctrl+F8”即可对当前文件格式化;注1:uncrustify f %f o %f命令中,-c表明需要调用配置文件,%f在Source Insight中代表当前文件,o表示将排版后的输出直接替换当前文件(需要当前文件已经保存,否则Source Insight不会提示文件被外部编辑器改变,并重新载入)。注2:%f o %f也可以使用%s来替换,表明输入的是当前文件中所选择的部分,即uncrustify只对当前所选择的代码进行排版。如果要使用这种方式,请将“Paste Output”进行勾选。3.4.配置Microsoft Visual Studio1 打开Microsoft
4、Visual Studio, 选择菜单“工具-外部工具-添加”, 在“标题”中输入输入uncrustify。2 命令中输入:uncrustify3 参数中输入:-c C:uncrustify f $(TargetName) o $(TargetName)如果不想对源代码文件进行备份,可以输入:uncrustify -no-backup f $(TargetName) o $(TargetName) 4 点击“确定”即可;5 打开要格式化的文件,选择菜单“工具- uncrustify”即可对当前文件格式化;注:$(TargetName)在Microsoft Visual Studio中代表当前文
5、件。3.5.Uncrustify配置文件说明1. 缩进为4个空格,未使用Tab;2. 大括号不做缩进;3. 缩进Case;4. 对备注进行缩进;5. 运算符两端加空格;6. 赋值操作符两端加空格;7. 布尔操作符两端加空格;8. 比较操作符两端加空格;9. if, forswitch, 及while与后面的(之间加空格;10. 移除;前面的空格;11. ,后面加空格;12. 移除13. 、ElseifElesTryFinallyForWhileDoSwitch语句单独占一行;14. 大括号单独占一行;15. 遇就换行,除了在for语句声明中;16. 非注释行最大字符数为80;17. 的语句强制
6、增加大括号;18. #if#else if#endif#define强制放在行首;19. 支持预编译指令的缩进及换行。3.6.软件编程规范排版要求的支持情况编程规范的要求是否支持全局变量的定义及函数声明应在头文件中给出;.C文件中如有main()函数,则应将main()放在最前面。不支持需要人工判断程序块要采用缩进风格编写。缩进方式应与所用开发工具生动自动生成的缩进相一致。缩进量要一致并以Tab键为单位,定义Tab 为 4个字节。支持未使用Tab键,用空格进行了替换。相对独立的程序块之间、变量说明之后必须加空行。较长的语句(80字符)要分成多行书写,长表达式要在低优先级操作符处划分新行,操作符
7、放在新行之首,划分出的新行要进行适当的缩进,使排版整齐,语句可读(注:一行程序以小于80字符为宜,不要写得过长)。循环、判断等语句中若有较长的表达式或语句,则要进行适应当的划分,长表达式要在低优先级操作符处划分新行,操作符放在新行之首。不完全支持长度以上条所定义的为准表达式中,若有多个操作符连写的情况,应使用空格对它们分隔。不允许把多个短语句写在一行中,即一行只写一条语句。if、for、do、while、case、switch、default等语句自占一行,且if、for、do、while等语句的执行语句部分无论多少都要加括号。若只有一条语句时,将强制增加。在两个以上的关键字、变量、常量进行对
8、等操作时,它们之间的操作符前后要加空格;进行非对等操作时,如果是关系密切的立即操作符(如),后不应加空格。除上述支持的排版功能以外,此排版工具还定义了如下排版规则:1. 强制移除,;前面的空格;2. 3. 对备注进行缩进;4. 附录 Uncrustify参数说明# General optionsnewlines Auto, LF, CR, CRLF The type of line endingsinput_tab_size Number The original size of tabs in the inputoutput_tab_size Number The size of tabs
9、in the output (only used if align_with_tabs=true)string_escape_char Number The ASCII value of the string escape char, usually 92 () or 94 (). (Pawn)string_escape_char2 Number Alternate string escape char for Pawn. Only works right before the quote char.tok_split_gte False, True Allow interpreting =
10、and as part of a template in void f(listlist=val);. If true (default), assert(x=3) will be broken. Improvements to template detection may make this option obsolete.utf8_bom Ignore, Add, Remove, Force Control what to do with the UTF-8 BOM (recommed remove)utf8_byte False, True If the file only contai
11、ns chars between 128 and 255 and is not UTF-8, then output as UTF-8utf8_force False, True Force the output encoding to UTF-8# Indentingindent_columns Number The number of columns to indent per level. Usually 2, 3, 4, or 8.indent_continue Number The continuation indent. If non-zero, this overrides th
12、e indent of continuation indents. For FreeBSD, this is set to 4.indent_with_tabs Number How to use tabs when indenting code 0=spaces only 1=indent with tabs to brace level, align with spaces 2=indent and align with tabs, using spaces when not on a tabstopindent_cmt_with_tabs False, True Comments tha
13、t are not a brace level are indented with tabs on a tabstop. Requires indent_with_tabs=2. If false, will use spaces.indent_align_string False, True Whether to indent strings broken by so that they line upindent_xml_string Number The number of spaces to indent multi-line XML strings. Requires indent_
14、align_string=Trueindent_brace Number Spaces to indent from levelindent_braces False, True Whether braces are indented to the body levelindent_braces_no_func False, True Disabled indenting function braces if indent_braces is trueindent_braces_no_class False, True Disabled indenting class braces if in
15、dent_braces is trueindent_braces_no_struct False, True Disabled indenting struct braces if indent_braces is trueindent_brace_parent False, True Indent based on the size of the brace parent, . = 3 spaces, 4 spaces, etc.indent_namespace False, True Whether the namespace body is indentedindent_namespac
16、e_level Number The number of spaces to indent a namespace blockindent_namespace_limit Number If the body of the namespace is longer than this number, it wont be indented. Requires indent_namespace=true. Default=0 (no limit)indent_extern False, True extern Cindent_class False, True classindent_class_
17、colon False, True Whether to indent the stuff after a leading class colonindent_ctor_init Number Additional indenting for constructor initializer listindent_else_if False, True False=treat elsenif as else if for indenting purposes True=indent the one level indent_var_def_blk Number Amount to indent
18、variable declarations after a open brace. neg=relative, pos=absoluteindent_var_def_cont False, True Indent continued variable declarations instead of aligning.indent_func_call_param False, True True: indent continued function call parameters one indent level False: align parameters under the open pa
19、renindent_func_def_param False, True Same as indent_func_call_param, but for function defsindent_func_proto_param False, True Same as indent_func_call_param, but for function protosindent_func_class_param False, True Same as indent_func_call_param, but for class declarationsindent_func_ctor_var_para
20、m False, True Same as indent_func_call_param, but for class variable constructorsindent_template_param False, True Same as indent_func_call_param, but for templatesindent_func_param_double False, True Double the indent for indent_func_xxx_param optionsindent_func_const Number Indentation column for
21、standalone const function decl/proto qualifierindent_func_throw Numberthrowindent_member Number The number of spaces to indent a continued - or . Usually set to 0, 1, or indent_columns.indent_sing_line_comments Number Spaces to indent single line (indent_case_shift Number Spaces to shift the case li
22、ne, without affecting any other lines Usually 0.indent_case_brace Number from By default, the brace will appear under the c in case. Usually set to 0 or indent_columns.indent_col1_comment False, True Whether to indent comments found in first columnindent_label Number How to indent goto labels 0 : ab
23、solute column where 1 is the leftmost column =0 : subtract from brace indentindent_access_spec Number Same as indent_label, but for access specifiers that are followed by a colonindent_access_spec_body False, True Indent the code after an access specifier by one level. If set, this option forces ind
24、ent_access_spec=0indent_paren_nl False, True If an open paren is followed by a newline, indent the next line so that it lines up after the open paren (not recommended)indent_paren_close Number Controls the indent of a close paren after a newline. 0: Indent to body level 1: Align under the open paren
25、 2: Indent to the brace levelindent_comma_paren False, True Controls the indent of a comma when inside a TRUE, aligns under the open parenindent_bool_paren False, True Controls the indent of a BOOL operator when inside a TRUE, aligns under the open parenindent_first_bool_expr False, True If indent_b
26、ool_paren is true, controls the indent of the first expression. If TRUE, aligns the first expression to the following onesindent_square_nl False, True If an open square is followed by a newline, indent the next line so that it lines up after the open square (not recommended)indent_preserve_sql False
27、, True Dont change the relative indent of ESQL/C EXEC SQL bodiesindent_align_assign False, True Align continued statements at the . Default=True If FALSE or the is followed by a newline, the next line is indent one tab.# Spacing optionssp_arith Ignore, Add, Remove, Force Add or remove space around arithmetic operator +-/*, etcsp_assign Ignor
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1