hypertensiune / ccloc

Fastest lines of code counting tool
MIT License
5 stars 1 forks source link

On a directory of C files ccloc counts code lines as negative #2

Open csrabak opened 2 months ago

csrabak commented 2 months ago

In a project folder with 58 C files and two C header files, ccloc called as follows D:\> ccloc . -l C "C Header" reports:

--------------------------+------------+------------+------------+------------
Language                  |      Total |       Code |   Comments |      Files
--------------------------+------------+------------+------------+------------
C Header                  |        129 |          7 |        120 |          2
C                         |       8863 |       -210 |       8974 |         58
--------------------------+------------+------------+------------+------------
TOTAL                     |       8992 |       -203 |       9094 |         60
--------------------------+------------+------------+------------+------------

As a comparison, when the same set of files is counted with cloc, this is summary obtained:

github.com/AlDanial/cloc v 2.02  T=1.41 s (91.6 files/s, 8368.6 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                               58           1071           2421           5371
C/C++ Header                     2             15             66             34
-------------------------------------------------------------------------------
SUM:                            60           1086           2485           5405
-------------------------------------------------------------------------------

The total lines of the two counters match for C files, and within ten lines of the wc utility, however the rest of the metrics are very discrepant and the negative counts for code seems to be a bug of some sort.

hypertensiune commented 2 months ago

Hey, could you run it by file and add the content of a file that gives a negative count. Or maybe the headers.

The problem seems to be from the comment count. I guess there are some comment cases that I didn't account for. Like if there is a single line comment but marked with /* comment */ instead of // comment the counting will break as it will look for the ending */ on the next line and miss it.

csrabak commented 2 months ago

As the files are of a project I've no authorization to publicize, I'll investigate the corner cases you mention and report back asap.

csrabak commented 1 month ago

Using the regexp ^\/\*.*\*\/$ I've got two C files and one header that have more than one line that fits this case you mention.

More specifically, the header file has nine of such lines, and the C files 13 lines each (one of them includes one with /**/ .

So I think this diagnostic of yours is confirmed for this project case.

As an example of code you can inspect, I did the same experiment with Fabrizzio's wav https://github.com/fabrizzio-gz/wav, getting the following results:

D:\>\wav-master\src>ccloc . -l C "C Header"
--------------------------+------------+------------+------------+------------
Language                  |      Total |       Code |   Comments |      Files
--------------------------+------------+------------+------------+------------
C                         |        456 |        183 |        220 |          5
C Header                  |         73 |         56 |          0 |          5
--------------------------+------------+------------+------------+------------
TOTAL                     |        529 |        239 |        220 |         10
--------------------------+------------+------------+------------+------------

D:\>\wav-master\src>cloc .
      10 text files.
      10 unique files.
       0 files ignored.

github.com/AlDanial/cloc v 2.02  T=0.03 s (306.5 files/s, 16214.1 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                5             82             15            359
C/C++ Header                     5             17              0             56
-------------------------------------------------------------------------------
SUM:                            10             99             15            415
-------------------------------------------------------------------------------

Even if the blattant negative number don't appear still the difference is noticeable.