Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1009342
  • 博文数量: 327
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4319
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 11:21
文章存档

2011年(31)

2010年(139)

2009年(157)

我的朋友

分类:

2010-06-11 13:18:19

很多时候,我们可能会在SI中直接编写代码,但是SI没有代码整理功能,比如整理符合c/c++规范 
这时候,很是郁闷...但是可以将astyle.exe外挂到SI中,详细步骤如下: 
 
1:从 上下载astyle.exe(开放源码,可以仔细阅读); 

2:将astyle.exe保存到磁盘,这里我放到C:\Program Files\astyle下 
     在SI菜单栏里,Options-->Custom Commands界面上选择:Add,在弹出对话框写入 Fomat with astyle,

3:在run中添加"C:\Program Files\astyle\astyle.exe" --style=ansi %f,其中,如果astyle.exe所在路径中有空格,务必用""括起来,参数--style=ansi(如果你需要格式化java代码,这个地方改为:--style=java),其它命令参数可以参考astyle的帮助参数"%f"是指作用于当前文件,这个必须的.

4:此外,在此界面上还可以为这个命令设置快捷键,点击"keys",添加你觉得方便的按钮; 

5:在SI菜单栏里,Options-->Menu Assignments界面上,将这个命令添加到某工具栏下,在左面的Command列表里找到我们刚才添加的"Fomat with astyle",在右面的Menu中选择你要加到那个菜单下,这里我加到"Edit"下,可以在"Menu Contents"选择适当位置,点击"insert"即可; 
OK,世界简单了...另外,如何在vc中外挂astyle的代码整理功能,可以参考这篇文档:
 
下面是标准的程序文档,如果你想了解更多用法,可以一读;如果你只是像我一样日常使用该工具,就可以不看了。
Artistic Style 1.15.3   ()
                       (created by Tal Davidson, )
Modified edition by Qiongzhu Wan, 2004.09
Usage  :  astyle [options] < original > Beautified
          astyle [options] Foo.cpp Bar.cpp  [...]
When indenting a specific file, the resulting indented file RETAINS the
original file-name. The original pre-indented file is renamed, with a
suffix of ".orig" added to the original filename.
By default, astyle is set up to indent C/C++/C# files, with 4 spaces per
indent, a maximal indentation of 40 spaces inside continuous statements,
and NO formatting.
Option's Format:
----------------
    Long options (starting with '--') must be written one at a time.
    Short options (starting with '-') may be appended together.
    Thus, -bps4 is the same as -b -p -s4.
Predefined Styling options:
--------------------
    --style=ansi
    ANSI style formatting/indenting.
    --style=kr
    Kernighan&Ritchie style formatting/indenting.
    --style=gnu
    GNU style formatting/indenting.
    --style=java
    Java mode, with standard java style formatting/indenting.
    --style=linux
    Linux mode (i.e. 8 spaces per indent, break definition-block
    brackets but attach command-block brackets.
Indentation options:
--------------------
    -c   or   --mode=c
    Indent a C, C++ or C# source file (default)
    -j   or   --mode=java
    Indent a Java(TM) source file
    -s   or   -s#   or   --indent=spaces=#
    Indent using # spaces per indent. Not specifying #
    will result in a default of 4 spacec per indent.
    -t   or   -t#   or   --indent=tab=#
    Indent using tab characters, assuming that each
    tab is # spaces long. Not specifying # will result
    in a default assumption of 4 spaces per tab.
    -T#   or   --force-indent=tab=#    Indent using tab characters, assuming tha
t each
    tab is # spaces long. Force tabs to be used in areas
    Astyle would prefer to use spaces.
    -C   or   --indent-classes
    Indent 'class' blocks, so that the inner 'public:',
    'protected:' and 'private: headers are indented in
    relation to the class block.
    -S   or   --indent-switches
    Indent 'switch' blocks, so that the inner 'case XXX:'
    headers are indented in relation to the switch block.
    -K   or   --indent-cases
    Indent 'case XXX:' lines, so that they are flush with
    their bodies..
    -N   or   --indent-namespaces
    Indent the contents of namespace blocks.
    -B   or   --indent-brackets
    Add extra indentation to '{' and '}' block brackets.
    -G   or   --indent-blocks
    Add extra indentation entire blocks (including brackets).
    -L   or   --indent-labels
    Indent labels so that they appear one indent less than
    the current indentation level, rather than being
    flushed completely to the left (which is the default).
    -m#  or  --min-conditional-indent=#
    Indent a minimal # spaces in a continuous conditional
    belonging to a conditional header.
    -M#  or  --max-instatement-indent=#
    Indent a maximal # spaces in a continuous statement,
    relatively to the previous line.
    -E  or  --fill-empty-lines
    Fill empty lines with the white space of their
    previous lines.
    --indent-preprocessor
    Indent multi-line #define statements
Formatting options:
-------------------
    -b  or  --brackets=break
    Break brackets from pre-block code (i.e. ANSI C/C++ style).
    -a  or  --brackets=attach
    Attach brackets to pre-block code (i.e. Java/K&R style).
    -l  or  --brackets=linux
    Break definition-block brackets and attach command-block
    brackets.
    --brackets=break-closing-headers
    Break brackets before closing headers (e.g. 'else', 'catch', ..).
    Should be appended to --brackets=attach or --brackets=linux.
    -o   or  --one-line=keep-statements
    Don't break lines containing multiple statements into
    multiple single-statement lines.
    -O   or  --one-line=keep-blocks
    Don't break blocks residing completely on one line
    -p   or  --pad=oper
    Insert space paddings around operators only.
    --pad=paren
    Insert space paddings around parenthesies only.
    -P   or  --pad=all
    Insert space paddings around operators AND parenthesies.
    --convert-tabs
    Convert tabs to spaces.
    --break-blocks
    Insert empty lines around unrelated blocks, labels, classes, ...
    --break-blocks=all
    Like --break-blocks, except also insert empty lines
    around closing headers (e.g. 'else', 'catch', ...).
    --break-elseifs
    Break 'else if()' statements into two different lines.
Other options:
-------------
    --suffix=####
    Append the suffix #### instead of '.orig' to original filename.
    -X   or  --errors-to-standard-output
    Print errors and help information to standard-output rather than
    to standard-error.
    -v   or   --version
    Print version number
    -h   or   -?   or   --help
    Print this help message
Default options file:
---------------------
    Artistic Style looks for a default options file in the
    following order:
    1. The contents of the ARTISTIC_STYLE_OPTIONS environment
       variable if it exists.
    2. The file called .astylerc in the directory pointed to by the
       HOME environment variable ( i.e. $HOME/.astylerc ).
    3. The file called .astylerc in the directory pointed to by the
       HOMEPATH environment variable ( i.e. %HOMEPATH%\.astylerc ).
    If a default options file is found, the options in this file
    will be parsed BEFORE the command-line options.
    Options within the default option file may be written without
    the preliminary '-' or '--'.
阅读(4390) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~