Simple script to count NLOC?

2019-03-28 13:15发布

Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either.

14条回答
Animai°情兽
2楼-- · 2019-03-28 13:33

Not a script, but you can try this command-line open source tool: NLOC

查看更多
在下西门庆
3楼-- · 2019-03-28 13:39

SLOCCOunt is not a simple script and does much more than what you need. However, it is a powerful alternative to the already mentioned Ohcount and NLOC. :)

查看更多
趁早两清
4楼-- · 2019-03-28 13:40

I usually just do this:

grep -vc '^$' (my files)

Works only if your empty lines are really empty (no spaces). Sufficient for me.

查看更多
做个烂人
5楼-- · 2019-03-28 13:41

Check out DPack plugin for Visual Studio. It has a stats report for any solution/project.

查看更多
SAY GOODBYE
6楼-- · 2019-03-28 13:41

Source monitor is freeware source analysis software. It is windows application but it also can be run with parameters from command line.

It can analyze C++, C, C#, VB.NET, Java, Delphi, Visual Basic (VB6) or HTML.

查看更多
叼着烟拽天下
7楼-- · 2019-03-28 13:42

I would do that using awk & cpp (preprocessor) & wc . awk removes all braces and blanks, the preprocessor removes all comments and wc counts the lines:

find . -name \*.cpp -o -name \*.h | xargs -n1 cpp -fpreprocessed -P | 
    awk '!/^[{[:space:]}]*$/' | wc -l

If you want to have comments included:

find . -name \*.cpp -o -name \*.h | xargs awk '!/^[{[:space:]}]*$/' | wc -l
查看更多
登录 后发表回答