简单的脚本计数NLOC? [英] Simple script to count NLOC?

查看:131
本文介绍了简单的脚本计数NLOC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道一个简单的脚本来计算NLOCs(netto代码行)。脚本应该计算C代码行。它不应该计数空行或带有大括号的行。

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.

推荐答案

我会使用 awk & cpp (预处理器)& wc 。 awk删除所有大括号和空格,预处理器删除所有注释,wc计数行:

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

如果您想要包含评论:

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

这篇关于简单的脚本计数NLOC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆