|
|
发表于 2006-5-5 16:13:25
|
显示全部楼层
要写这个的确不容易,幸好神奇的indent已经能解决其中的几个难题。
1、TAB和N个空格互换的相关参数如下:- -nut, --no-tabs
- Use spaces instead of tabs.
- -tsn, --tab-sizen
- Set tab size to n spaces.
- -ut, --use-tabs
- Use tabs. This is the default.
复制代码 2、注释要在单独的一行也要随代码缩进- -cn, --comment-indentationn
- Put comments to the right of code in column n.
- -cdn, --declaration-comment-columnn
- Put comments to the right of the declarations in column n.
- -dn, --line-comments-indentationn
- Set indentation of comments not to the right of code to n spaces.
复制代码
3、注释最好有统一的格式,用“//”或“/**/”打印整齐的表头- -nsc, --dont-star-comments
- Do not put the `*´ character at the left of comments.
- -sc, --start-left-side-of-comments
- Put the `*´ character at the left of comments.
- -lcn, --comment-line-lengthn
- Set maximum line length for comment formatting to n.
复制代码
上面给出的这几个参数比较常用,应该可以基本满足你的要求了。关于注释的参数比较多,我一时也不是很清楚其具体作用,你可以在man indent里查找comment,看看能不能符合你的要求。
4、正确处理缩进。
这是indent的强项,有很多微调选项,看man吧。
这样一来,要自己编程解决的问题只剩下“二元运算符两边加空格,逗号后面加空格”了。 |
|