惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
雷峰网
雷峰网
S
Securelist
V
Vulnerabilities – Threatpost
S
SegmentFault 最新的问题
T
The Exploit Database - CXSecurity.com
A
About on SuperTechFans
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
V2EX
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
L
Lohrmann on Cybersecurity
S
Security Affairs
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
H
Heimdal Security Blog
L
LINUX DO - 热门话题
月光博客
月光博客
Apple Machine Learning Research
Apple Machine Learning Research
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
N
Netflix TechBlog - Medium
The Hacker News
The Hacker News
N
News and Events Feed by Topic
C
Check Point Blog
博客园_首页
Scott Helme
Scott Helme
T
Troy Hunt's Blog
U
Unit 42

博客园 - sun@live

两段代码 <收藏>提高Web性能的14条法则(详细版) MOSS与业务系统的集成 之 单点登录 MOSS与业务系统的集成 之 自定义Membership实现Forms方式验证 手机归属地数据—采集 .Net数据源自定义参数 JavaScript和CSS速查手册 序列化一个字符串到CDATA元素(.NET 1.1) Sandcastle工具SandcastleBuilder 清除字符串数组中,重复元素 - sun@live - 博客园 Windows Live Writer 写的一个双向选择器(JS) 论坛中,用户权限解决方法 Web2.0用户注册,激活,密码找回模块 [学习日志]EyasBlog控件部分已基本完成-2005-12-03 学习日志(blog日历控件)-2005年11月12日 学习日志(Blog架构)-2005年11月09日 学习日志-2005年11月09日 学习计划-2005年11月07日
(原创)一个改自java的代码统计工具
sun@live · 2006-03-08 · via 博客园 - sun@live

2006-03-08 21:41  sun@live  阅读(851)  评论()    收藏  举报

  1using System;
  2using System.IO;
  3
  4namespace CodeTell{
  5    /// <summary>
  6    ///  CodeTell 的摘要说明。
  7    /// </summary>

  8
  9    class  CodeTell
 10    {
 11        private int codeLines = 0, commentLines = 0, fileCount = 0, floderCount = 0,characterCount = 0;
 12        private long totalFileLength = 0;
 13        /// <summary>
 14        /// 应用程序的主入口点。
 15        /// </summary>

 16        [STAThread]
 17        static void Main(string[] args)
 18        {
 19            //
 20            // TODO: 在此处添加代码以启动应用程序
 21            //
 22            (new CodeTell()).Start();
 23            
 24        }

 25
 26        public void Start()
 27        {
 28            DirectoryInfo folder = new DirectoryInfo(".");
 29
 30            examineList(folder);
 31
 32            //输出信息
 33            Console.WriteLine("Folder:\t\t{0}",floderCount);
 34            Console.WriteLine("Files:\t\t{0}",fileCount);
 35            Console.WriteLine("Comment Lines:\t{0}",commentLines);
 36            Console.WriteLine("Code Lines:\t{0}",codeLines);
 37            Console.WriteLine("Char Count:\t{0}",characterCount);
 38            Console.WriteLine("Files Length:\t{0}",totalFileLength);
 39        
 40            Console.Read();
 41        }

 42
 43        protected void examineList(DirectoryInfo dir)
 44        {
 45            FileInfo[] finfo = dir.GetFiles();
 46            DirectoryInfo[] dinfo = dir.GetDirectories();
 47        
 48            floderCount += dinfo.Length;
 49
 50            for(int i = 0; i<finfo.Length; i++)
 51            {
 52                calcFile(finfo[i]);
 53            }

 54            //遍历目录
 55            for(int i = 0; i< dinfo.Length; i++)
 56            {
 57                examineList(dinfo[i]);
 58            }

 59        }

 60
 61
 62        private void calcFile(FileInfo file)
 63        {
 64            StreamReader sreader;
 65            string fname,line;
 66            bool insideComment;
 67
 68            fname = file.FullName;
 69
 70            if(fname == null)
 71            {
 72                Console.WriteLine("Somehow the file was null");
 73            }

 74                //对.cs文件进行分析
 75            else if(fname.ToLower().EndsWith(".cs"))
 76            {
 77                totalFileLength += file.Length;
 78                fileCount++;
 79
 80                try
 81                {
 82                    sreader = new StreamReader(fname);
 83                    Console.WriteLine("    {0}",fname);
 84                    line = sreader.ReadLine();
 85                    if( line != null)
 86                        line = line.Trim();
 87                    insideComment = false;
 88                    int temp;
 89                    while(line != null)
 90                    {
 91                        characterCount += line.Length;
 92                        if(line.Length == 0)
 93                        {
 94                            if((temp = line.IndexOf("*/")) >= 0)
 95                            {
 96                                insideComment = false;
 97                                if(line.Length > temp)
 98                                    codeLines++;
 99                                if(temp > 2)
100                                    commentLines++;
101                            }

102                        }

103                        else
104                        {
105                            if(!line.StartsWith("//"))
106                                codeLines++;
107                            if(line.StartsWith("/*"))
108                                insideComment = true;
109                            if(line.IndexOf("//")>=0)
110                                commentLines++;
111                        }

112
113                        line = sreader.ReadLine();
114                        if(line != null)
115                            line = line.Trim();
116
117                    }
//end while
118                }

119                catch(Exception e)
120                {
121                    Console.WriteLine(e.Message);
122                }

123            }

124        }

125
126    }

127}

128