博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

程序代码美化工具[转]

Posted on 2005-04-30 23:47  天下一菜  阅读(703)  评论(0编辑  收藏  举报

工具名: indent  ::URL::http://www.gnu.org/software/indent/indent.html
适用语言: c 
indent几乎成为代码美化工具的代名词。 indent是gcc附带的一个工具,
indent [options] [input-files]
indent [options] [single-input-file] [-o output-file] 

工具名:perltidy  ::URL::http://sourceforge.net/projects/perltidy/
适用语言:perl  
perltidy本身也是perl写的。以前写的一个使用简介。 下载后直接运行perltidy脚本
perltidy [ options ] file1 file2 file3 ...
(output goes to file1.tdy, file2.tdy, file3.tdy, ...)
perltidy [ options ] file1 -o outfile
perltidy [ options ] file1 -st >outfile
perltidy [ options ] <infile >outfile 

工具名:astyle ::URL::http://sourceforge.net/projects/astyle
适用语言:c c++ java (php) 
一个速度很快的C/C++/Java源代码美化工具。
astyle比indent好在有很多成套的的风格定义:ansi java linux...不必记住复杂的缩进具体选项。  下载源代码解包后,make, 生成astyle可执行文件
astyle [options] < Original > Beautified
astyle [options] Foo.cpp Bar.cpp [...]
astyle --style=ansi *.cpp
我尝试过用它来格式化PHP程序也很有效(当然是不合HTML代码混在一起的纯PHP代码)。 

工具名:pydent ::URL::http://sourceforge.net/projects/pythius/
适用语言:python 
pythius包含了2个工具:一个就是缩进整理
pydent: 代码缩进工具
pystat: 代码统计工具 下载源代码解包后:
Run "python setup.py build"
Run "python setup.py install" 

工具名:htmltidy ::URL::http://tidy.sourceforge.net/
适用语言:html/xml 
HTML代码的纠错工具,可以帮助你的HTML代码更好的符合W3C规范,页面中如果包含ASP PHP JSP等程序,HTMLTIDY都会尽量忽略。
HTMLTIDY也支持对XML的格式美化
使用选项:-xml 下载源代码后 make 生成tidy可执行文件:tidy: file1 file2 ...
注意:对于含有中文的页面要使用 -raw选项 
tidy.exe -raw -imuq -wrap 132 -f %f.err %f 
选项说明:
-raw: 不修改中文字符 (output values above 127 without conversion to entities)
-i     indend 缺省HTML按2个空格缩进
-m     覆盖原文件
-u     强制所有HTML标记大写(这个可以不加)
-wrap  页面代码宽度大于132行强制换行
-f %f.err 将错误输出到“相应文件名.err”文件中 

--------------------------------------
代码规范可以参考文档:
GNU Coding Standards
::URL::http://www.gnu.org/prep/standards_toc.html

Code Conventions for the Java(TM) Programming Language
::URL::http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

PHP Coding Standard
::URL::http://utvikler.start.no/code/php_coding_standard.html

perlstyle
::URL::http://www.perldoc.com/perl5.6/pod/perlstyle.html

HTML XML XHTML CSS...
::URL::http://www.w3c.org/