在windows下总是有很多源代码统计工具, 比如SourceCounter(源代码统计精灵)等工具

之前我总是使用如下命令统计源代码的信息, 繁琐而可读性差

find . -type f -name "*.[hc]" | xargs cat | wc -l

或者

find . -name "*.[hc]" | xargs -L 1 wc -l | awk '{print $1}' | while read num; do total=$((total+num)); echo $total; done

1、sloccount源代码行数统计工具

sloccount=Count Source Lines Of Code

官网 : http://www.dwheeler.com/sloccount/

1.1、Ubuntu安装

sudo apt-get install sloccount

1.2、使用

sloccount  [--version]  [--cached]  [--append]  [  --datadir directory ]

[--follow]  [--duplicates]  [--crossdups]  [--autogen]  [--multiproject]

[--filecount] [--wide] [--details] [ --effort F E ] [ --schedule F E ] [

--personcost cost ] [ --overhead overhead ] [  --addlang  language  ]  [

--addlangall ] [--] directories

--cached

跳过计算过程,直接使用上次结果

参数——描述

–multiproject——如果该文件夹包括一系列的子文件夹,而它们中的每一个都是相对独立开发的不同的项目,那么使用”–multiproject”选项,评估将会正确的考虑到这一点

–filecount——显示文件数目而非代码行数

–details——显示每个源文件的详细信息

–duplicates——算上所有重复的(默认情况下如果文件有相同的内容,则只算一个)

–crossdups——如果顶目录包含几个不同的项目,并且你想把不同的项目下重复的文件在每个项目中都算上一次,则使用该选项

1.3、转换成html文件

有一个sloc2html.py可以把生成的结果转换为带图形统计结果的html文件. 缺点是对中文支持不好

例如:

sloccount --wide --multiproject SourceDirectory > result.txt

sloc2html.py result.txt > result.html

再打开result.html即可看到结果形如:

下载地址 http://www.dwheeler.com/sloccount/sloc2html.py.txt

输出样例 http://www.dwheeler.com/sloccount/sloc2html-example.html

wget http://www.dwheeler.com/sloccount/sloc2html.py.txt -O sloc2html.py

sloc2html.py文件源代码如下:

#!/usr/bin/env python

# Written by Rasmus Toftdahl Olesen

# Modified slightly by David A. Wheeler

# Released under the GNU General Public License v. 2 or higher

from string import *

import sys

NAME = "sloc2html"

VERSION = "0.0.2"

if len(sys.argv) != 2:

print "Usage:"

print "\t" + sys.argv[0] + " "

print "\nThe output of sloccount should be with --wide and --multiproject formatting"

sys.exit()

colors = { "python" : "blue",

"ansic" : "yellow",

"perl" : "purple",

"cpp" : "green",

"sh" : "red",

"yacc" : "brown",

"lex" : "silver"

# Feel free to make more specific colors.

"ruby" : "maroon",

"cs" : "gray",

"java" : "navy",

"ada" : "olive",

"lisp" : "fuchsia",

"objc" : "purple",

"fortran" : "purple",

"cobol" : "purple",

"pascal" : "purple",

"asm" : "purple",

"csh" : "purple",

"tcl" : "purple",

"exp" : "purple",

"awk" : "purple",

"sed" : "purple",

"makefile" : "purple",

"sql" : "purple",

"php" : "purple",

"modula3" : "purple",

"ml" : "purple",

"haskell" : "purple"

}

print ""

print "

"

print "

Counted Source Lines of Code (SLOC)"

print ""

print "

"

print "

Counted Source Lines of Code

"

file = open ( sys.argv[1], "r" )

print "

Projects

"

line = ""

while line != "SLOC\tDirectory\tSLOC-by-Language (Sorted)\n":

line = file.readline()

print "

print "

LinesProjectLanguage distribution"

line = file.readline()

while line != "\n":

num, project, langs = split ( line )

print "

" + num + "" + project + ""

print "

for lang in split ( langs, "," ):

l, n = split ( lang, "=" )

print "

" + l + "=" + n + " (" + str(int(float(n) / float(num) * 100)) + "%)"

print "

"

print "

"

line = file.readline()

print "

"

print "

Languages

"

while line != "Totals grouped by language (dominant language first):\n":

line = file.readline()

print "

print "

LanguageLines"

line = file.readline()

while line != "\n":

lang, lines, per = split ( line )

lang = lang[:-1]

print "

" + lang + "" + lines + " " + per + ""

line = file.readline()

print "

"

print "

Totals

"

while line == "\n":

line = file.readline()

print "

print "

Total Physical Lines of Code (SLOC):" + strip(split(line,"=")[1]) + ""

line = file.readline()

print "

Estimated development effort:" + strip(split(line,"=")[1]) + " person-years (person-months)"

line = file.readline()

line = file.readline()

print "

Schedule estimate:" + strip(split(line,"=")[1]) + " years (months)"

line = file.readline()

line = file.readline()

print "

Total estimated cost to develop:" + strip(split(line,"=")[1]) + ""

print "

"

file.close()

print "Please credit this data as \"generated using 'SLOCCount' by David A. Wheeler.\"\n"

print ""

print ""

2、cloc代码行数统计工具

cloc也可以用来统计源代码的行数, 其本质是一个perl的脚本

安装

sudo apt-get install cloc

使用

进入到需要统计的目录执行

cloc .

其本质是一个perl的脚本, 可以用

file `which cloc`

可以使用

cat `which cloc`

查看其源代码的信息

cloc工具 linux,Linux下源代码行数统计工具(sloccount,cloc等)相关推荐

  1. cloc工具 linux,Linux下源代码行数统计工具(sloccount, cloc等)

    在windows下总是有很多源代码统计工具, 比如SourceCounter(源代码统计精灵)等工具 之前我总是使用如下命令统计源代码的信息, 繁琐而可读性差 find . -type f -name ...

  2. 源代码行数统计工具及方法

    1.VS2010中使用正则表达式查询代码行数 按CTRL+SHIFT+F (Find in files),勾上支持正则表达式,然后输入搜索内容: ^:b*[^:b#/]+.*$ 以上表达式的统计可做到 ...

  3. SAP CDS view源代码行数统计工具

    Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically gener ...

  4. python 代码行数统计工具_使用Python设计一个代码统计工具

    问题 设计一个程序,用于统计一个项目中的代码行数,包括文件个数,代码行数,注释行数,空行行数.尽量设计灵活一点可以通过输入不同参数来统计不同语言的项目,例如: # type用于指定文件类型 pytho ...

  5. python代码行数统计工具_Python实现代码行数统计工具的功能(实例)

    本篇文章给大家带来的内容是关于Python实现代码行数统计工具的功能(实例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 我们经常想要统计项目的代码行数,但是如果想统计功能比较完善 ...

  6. 源码行数统计工具——cloc

    cloc简介 cloc是一款用于统计源码信息行数的工具,可以针对许多编程语言中源代码的空白行.注释行和物理行进行计数.给定两个版本的代码库,cloc 可以计算空白行.注释行和源代码行的差异.它完全用  ...

  7. Svn的代码行数统计工具statsvn以及使用

    Svn代码行数统计 代码工具svnstat svnstat.jar的下载路径 使用方法 将下载好的jar文件放于本地svn版本库的根目录下,即.svn文件夹的同级目录下. 新增文本文件,内容为 svn ...

  8. linux代码行数统计工具,统计代码行数工具 用golang实现

    首先:修改conf文件,配置要查找什么后缀的文件代码行数 使用方法:countcodeliine filename or nothing(计算可执行程序所在目录) 实现功能: 1,统计代码行数 2,可 ...

  9. cloc JAVA文件_工具-cloc代码行数统计工具

    cloc 代码行统计工具 计算代码行.注释行.空行量的工具.支持多种语言. 例如统计一下vue项目里的src文件夹下的代码: 安装方式 npm install -g cloc # https://ww ...

最新文章

  1. JS --正则表达式验证、实战之邮箱模式
  2. iOS-UIViewController视图控制器跳转界面的几种常用方法
  3. java 静态方法上的泛型
  4. Django中配置自定义日志系统
  5. falsk-sqlalchemy 连接数据库出现 No module named ‘MySQLdb‘(笔记自用)
  6. 解决 | 此数据库文件跟当前sql server实例不兼容 sql server2008无法连接到(local)...
  7. 设计模式适配器模式_21世纪的设计模式:适配器模式
  8. FastCGI - Getting Request URI and Content in C++ FCGI
  9. 一次简单易懂的多态重构实践,让你理解条件逻辑
  10. go 的时间与时间戳计算
  11. c#范型编程系列一(非原创)
  12. hive与mysql的数据分区的异同
  13. read()/write()的生命旅程之五——第五章:从bio到media
  14. PHP开源旅游网站程序,PHP开源旅游网站源码下载
  15. Java学习路线:day6 数组
  16. html怎样设置图片的圆角矩形,css怎么画圆角矩形?
  17. js html等比例放大后生成图片 html2canvas
  18. python更新excel内容_[原创]使用 Python 读写 Excel 文件(一)更新
  19. 广义表的长度和深度计算
  20. 最新车载以太网解决方案

热门文章

  1. python电脑下载安装-Python的下载安装与Python编辑器的安装
  2. python爬虫步骤-Python爬虫详解,每一个步骤都给你细腻的讲解(附源码)
  3. python常用代码大全-Python 网络爬虫实战项目代码大全
  4. python小白从哪来开始-写给小白的工程师入门 - 从 Python 开始
  5. python是什么语言-python底层是什么语言
  6. python代码示例-《Python编程:从入门到实践》DEMO实例代码
  7. 怎么自学python-你是如何自学 Python 的?
  8. python从入门到精通需要多久-Python从入门到精通:一个月就够了
  9. python从入门到放弃pdf下载-《Python3从入门到放弃》视频教程
  10. 微信计步器怎么不计步_送我一顶圣诞帽@星尘StarDust,制作一个圣诞创意微信头像...