Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
csrabak opened this issue Sep 7, 2024 · 3 comments
Open

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

csrabak opened this issue Sep 7, 2024 · 3 comments

Comments

@csrabak
Copy link

csrabak commented Sep 7, 2024

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
Copy link
Owner

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
Copy link
Author

csrabak commented Sep 15, 2024

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
Copy link
Author

csrabak commented Sep 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants