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

推荐订阅源

T
Threatpost
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
T
Tenable Blog
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
T
The Exploit Database - CXSecurity.com
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
H
Help Net Security
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
S
Schneier on Security
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
S
Secure Thoughts
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
C
Cybersecurity and Infrastructure Security Agency CISA
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
博客园 - Franky
T
Tor Project blog
G
GRAHAM CLULEY
博客园 - 【当耐特】
Jina AI
Jina AI
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 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 构造过程。

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