统计源代码行数的shell脚本
来源:互联网 发布:java rpc 框架比较 编辑:程序博客网 时间:2024/06/09 16:09
写了一个脚本,可以按模块统计源代码的行数,呵呵。
输出结果:
~ $ ./line-count [module] [lines] [%]FRED 4744 17.67%dataset 8591 32.00%core 9025 33.61%image 803 2.99%tape 1339 4.99%license 16 0.06%jni 1621 6.04%util 264 0.98%test 446 1.66%total 26849
脚本如下:
#!/bin/sh## $Id: line-count,v 1.2 2004/08/06 08:43:16 clkrst Exp $ ## a source-file line counter for C++/C/Java## i use the fixed module list instead of searching all sub-directory,# because it can give me an exact control.## clkrst@hotmail.com## count the lines of source files under the given directory# args: $1 the directory want to check.# $2 optionsfunction get_lines () { find $1/* $2 | xargs wc -l | tail -1 | cut -b1-7}# declare the arraysdeclare -a SOURCES # the directories to checkdeclare -a NAMES # the module namesdeclare -a LINES # the lines of each module# the following expresses the line-percentage # unit: 0.01declare -a PERS # the integer part declare -a FRAS # the fraction part# here you can add as more SOURCES/NAMES as possible# the source directorySOURCES=("src" "src/dataset" "src/core" "src/image" "src/tape" "src/license" "jni" "util") # the module name of each directoryNAMES=("FRED" "dataset" "core" "image" "tape" "license" "jni" "util")# how many modules?# should be equal to the sizeof(SOURCES) or sizeof(NAMES)N_MOD=8# extra modulesNAMES[$N_MOD]="test"SOURCES[$N_MOD]="test"LINES[$N_MOD]=`get_lines ${SOURCES[$N_MOD]} "-maxdepth 2 -name *.cpp -or -name *.h"` ;N_MOD=$(( $N_MOD+1 ))# count the lines of each moduleL_TOTAL=$(( 0 ))for (( i=0; $i<$N_MOD; i=$i+1 )) ; do LINES[$i]=`get_lines ${SOURCES[$i]} "-maxdepth 2 -name *.cpp -or -name *.h -or -name *.java"` ; L_TOTAL=$(( $L_TOTAL+${LINES[$i]} )) ; done# calculate the percentagefor (( i=0; $i<$N_MOD; i=$i+1 )) ; do # the formula is: # L_LINES/L_TOTAL * 100 + 0.5 # eliminate the float calculation # (L_LINES * 100 + L_TOTAL/2) / L_TOTAL # to get fraction part, we use # fra(X) = (X*100) - (X*100)/100*100 # int(X) = (X*100) / 100 PERS[$i]=$(( (${LINES[$i]}*10000 + $L_TOTAL/2) / $L_TOTAL )) ; FRAS[$i]=$(( ${PERS[$i]} - ${PERS[$i]}/100*100 )); PERS[$i]=$(( ${PERS[$i]} / 100 ));done# output resultprintf "[module]/t[lines]/t[%%]/n"for (( i=0; $i<$N_MOD; i=$i+1 )) ; do printf "%s/t/t%5d/t%2d.%02d%%/n" ${NAMES[$i]} ${LINES[$i]} ${PERS[$i]} ${FRAS[$i]};doneprintf "/ntotal/t/t%5d/n" $L_TOTAL unset SOURCES NAMES LINES PERSunset N_MOD L_TOTAL
- 统计源代码行数的shell脚本
- 统计源代码行数Shell脚本
- 统计源代码行数Shell脚本[00原创]
- 统计代码行数的shell脚本
- Linux下统计某个目录下所有源代码行数的Shell脚本;
- Linux下统计某个目录下所有源代码行数的Shell脚本
- Linux下统计当前目录下源代码行数的Shell脚本
- Shell脚本统计文件行数的8种方法
- Shell脚本统计文件行数的8种方法
- 统计python脚本中 shell命令输出文本的行数
- Shell脚本统计文件行数的8种方法
- 利用shell脚本统计代码行数
- shell脚本命令,统计文件行数
- 统计文件行数的shell
- 统计代码行数的脚本
- 统计项目源代码文件的行数
- 统计某文件夹下源代码行数 Python脚本
- 统计源代码行数
- csdn 的blog编辑器怎么那么土
- 大伙好,小泥人开始发贴了!
- 一个MATLAB 函数的规范化格式实例
- 今天星期几了?
- MISC平台接口改造开发完成
- 统计源代码行数的shell脚本
- delphi中的split函数
- 给blog上加个天气预报
- 仿windows登陆条 (转载)
- 缇
- 西山之秋
- ColSel、RowSel 属性
- 昨夜心雨
- 我的J2ME学习历程3