Python C代码统计工具代码的效果验证

发布时间:2022-04-22 09:55:50 人气:222 作者:多测师

  为验证上篇文章的代码实现,建立lctest调试目录。该目录下包含line.c及和《为C函数自动添加跟踪语句》一文中的test.c文件。其中,line.c内容如下:

  #include

  /* {{{ comment */

  /***********

  Multiline

  Comment

  ***********/

  int test(int a/*comment*/, int b)

  {

  int a2; int b2; //comment

  a2 = 1;

  b2 = 2;

  }

  /* {{{ test3 */

  int test3(int a,

  int b) /*test2 has been deleted,

  so this is test3. */

  {int a3 = 1; int b3 = 2;

  if(a3)

  {/*comment*/

  a3 = 0;

  }

PythonC代码统计工具代码的效果验证

  //comment

  b3 = 0;

  }

  /* }}} */

  //comment //comment

  /*FALSE*/ #if M_DEFINED

  #error Defination!

  #endif

  以不同的命令行参数运行CLineCounter.py,输出如下:

  E:\PyTest>CLineCounter.py

  FileLines CodeLines CommentLines EmptyLines

  77 53 18 11

  E:\PyTest>CLineCounter.py 0

  FileLines CodeLines CommentLines EmptyLines

  77 53 18 11

  E:\PyTest>CLineCounter.py 1

  FileLines CodeLines CommentLines EmptyLines FileName

  33 19 15 4 E:\PyTest\lctest\line.c

  44 34 3 7 E:\PyTest\lctest\test.c

  77 53 18 11

  经人工校验,统计信息正确。

  接着,在实际工程中运行python CLineCounter.py 1,截取部分运行输出如下:

  [wangxiaoyuan_@localhost ~]$ python CLineCounter.py 1

  FileLines CodeLines CommentLines EmptyLines FileName

  99 21 58 24 /sdb1/wangxiaoyuan/include/Dsl_Alloc.h

  120 79 28 24 /sdb1/wangxiaoyuan/include/Dsl_Backtrace.h

  ... ... ... ... ... ... ... ...

  139 89 24 26 /sdb1/wangxiaoyuan/source/Dsl_Tbl_Map.c

  617 481 64 78 /sdb1/wangxiaoyuan/source/Dsl_Test_Suite.c

  797 569 169 82 /sdb1/wangxiaoyuan/source/xDSL_Common.c

  15450 10437 3250 2538

  以上内容为大家介绍了PythonC代码统计工具代码的效果验证,希望对大家有所帮助,如果想要了解更多Python相关知识,请关注多测师。https://www.e70w.com/xwzx/


返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线