一行代码统计工程的代码注释率

老板搞了个竞赛,统计工程的注释率,因为平时大家工作都很忙,没什么时间整这个,为了节省时间,我用最短的时间写了最少的代码来完成,记录一下。

支持6种语言 c/c++/php/oc/swift/java

使用说明:

HOW TO USE:

bash annotation.sh [你的工程目录]

EXAMPLE:

bash annotation.sh ./  #当前目录

bash annotation.sh ~/Documents/zhidaoapp/    #指定某目录

SUPPORTED LANGUAGE:

C/C++/OC/SWIFT/JAVA/PHP

OUTPUT:

/***************Result***************/

Code Annotation Rate: 代码注释率(注释行数/有效代码行数)

Code Lines without blank lines: 去掉空行的代码行数

Code Annotation Lines NO.: 注释行数

All Lines NO.: 所有代码行数(包括空行)

PS:

注释行包括以下三种注释

1、

/////

2、

/*....*/

3、

/*

a

b

c

*/

#!/bin/sh

find $1 -name "*.c" -o -name "*.cpp" -o -name "*.java" -o -name "*.h" -o -name "*.swift" -o -name "*.php" -o -name "*.m" | xargs  awk '{a++;}; /(.+)/{l++;}; /\*\//{i=i+NR;}; /\/\*/{n=n+NR; m++}; /\/\//{x++}; END {print "/***************Result***************/"; print "Code Annotation Rate: "(i-n+m+x)/l; print "Code Lines without blank lines: "l; print "Code Annotation Lines NO.: "i-n+m+x; print "All Lines NO.: "a}'

你可能感兴趣的:(一行代码统计工程的代码注释率)