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

推荐订阅源

月光博客
月光博客
博客园_首页
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
量子位
H
Help Net Security
D
Docker
小众软件
小众软件
Google DeepMind News
Google DeepMind News
U
Unit 42
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
S
SegmentFault 最新的问题
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
Martin Fowler
Martin Fowler
D
DataBreaches.Net
AI
AI
SecWiki News
SecWiki News
V
Visual Studio Blog
Google Online Security Blog
Google Online Security Blog
腾讯CDC
J
Java Code Geeks
Jina AI
Jina AI
O
OpenAI News
N
News | PayPal Newsroom
Help Net Security
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cloudbric
Cloudbric
S
Secure Thoughts
V
V2EX
N
News and Events Feed by Topic
F
Full Disclosure
MyScale Blog
MyScale Blog
The Cloudflare Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
WordPress大学
WordPress大学
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog
Engineering at Meta
Engineering at Meta
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

博客园 - Wisdom-zh

【关注】“诋毁” 一下博客园的模板 混淆器【修正版】 发一个混淆器, Nuva 写的 Win32Ole 演示【控制 Word】 Win32Api 演示【控制任务栏】 通用数据浏览示例 方便的 XML 数据绑定 Swap 函数 延迟计算 短路运算 语法兼容 之 运算符总结 这是什么语言的代码 Nuva 语法兼容 之 控制结构总结 设计模式 之 状态机模式 Nuva 示例代码(每日一帖)之 数据架构提取 Nuva 示例代码(每日一帖)之 ShowMessage Nuva 示例代码(每日一帖)之 异常处理 Nuva 示例代码(每日一帖)之 语法兼容 挑战 XSLT 最擅长的 XML 文档转换
Nuva 示例代码(每日一帖)之 源代码统计
Wisdom-zh · 2006-09-14 · via 博客园 - Wisdom-zh
<..========================================================
==                                                       ==
==                Macrobject Nuva Samples                ==
==                                                       ==
==      Copyright (c) 2004-2006 Macrobject Software      ==
==                                                       ==
==                  ALL RIGHTS RESERVED                  ==
==                                                       ==
==               http://www.macrobject.com               ==
==                                                       ==
========================================================..>
<.
var FilePattern   = System.Path.ProjectPath ~ '..\*.nuva*'
var IncludeSubDir = true

var htmlText = ''
assign(htmlText)
  var FileCount     = 0
  var CountCode     = 0
  var CountBlank    = 0
  var CountComment  = 0
  .>
  <style>
    td {font-size: 10.5pt}
  </style>
  <table align=center border=1 borderColor=#CCCCCC cellspacing=0>
    <tr align=center>
      <td width=30>No</td>
      <td width=60>Code</td>
      <td width=60>Blank</td>
      <td width=60>Comment</td>
      <td>FileName</td>
    </tr>
  <.
  // Count code for each file
  foreach(fileName = System.File.Find(FilePattern, 'F', IncludeSubDir)
      | not fileName.EndsWith('.nuvaproj')
    )
    FileCount++
    
    var codeCount    = 0
    var blankCount   = 0
    var commentCount = 0
    var inComment    = false
    
    // Load file for text
    var fileText = \n ~ System.File.Load(fileName)
    // Count code use Regex Expression
    fileText.RegexMatch('\n[^\n]*', Function = 'CountCode')
  .>
    <tr>
      <td align=center>[.=FileCount.]</td>
      <td align=right>[.=codeCount.]</td>
      <td align=right>[.=blankCount.]</td>
      <td align=right>[.=commentCount.]</td>
      <td>[.=fileName.]</td>
    </tr>
  <.
    // Do Count: Value <- for each Line
    function CountCode(Index, Length, Value)
      codeCount ++
      if( IsComment(Value) )
        commentCount++
      elseif(not Value.RegexIsMatch('\w+')) // [^\s] or \w+
        blankCount++
      end if
    end function
        
    /*
      Detect comment
    */
    function IsComment(lineText)
      result = true
      if(lineText.RegexIsMatch('^\s*//'))
        // do nothing
      elseif(inComment)
        inComment = not lineText.RegexIsMatch('\*/')
      elseif(lineText.RegexIsMatch('/\*'))
        inComment = not lineText.RegexIsMatch('\*/')
      else
        result = false
      end if
    end function
    
    CountCode    += codeCount
    CountBlank   += blankCount
    CountComment += commentCount
  end foreach
  .>
    <tr>
      <td align=center>Count</td>
      <td align=right>[.=CountCode.]</td>
      <td align=right>[.=CountBlank.]</td>
      <td align=right>[.=CountComment.]</td>
      <td>[.=CountCode-CountBlank-CountComment.]</td>
    </tr>
  </table>
<.
end assign

class Form1 = System.Ui.HtmlForm()
  Caption = 'Code Count'
  Width   = 800
  Height  = 600
  function Create()
    ? htmlText
  end function
end class

var f = Form1()
f.Show()

System.App.Run()
.>


<..
【简介】
    本例是一个实用的源代码统计程序。本例的程序针对给定的目录和文件通配符,对每个文件进行代码统计,统计指标包括代码行数、空行数、注释行数等。然后将其按照 Html 的形式显示出来。

【看点】
    1、本例演示了一个源代码统计程序,通过对每个文件的分析,统计出源代码行数、空行数以及注释行数。
       本例的重点在于注释的分析,见 IsComment 函数。
      
       其他的代码分析请参见<<每日一帖>>中的其他示例分析。
      
    2、本例最后通过一个 Html 窗口将统计结果显示出来,演示了 Nuva 语言的 GUI 构造过程。

【扩展】
    本例是一个源代码统计程序,可以对其进行扩充,从而统计出更多的信息。
..>