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.
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
The following script will get count of all file matching a pattern in a given directory.
# START OF SCRIPT
var str files
var str dir
set $files = "*.cpp" # <===================== Set your file name pattern here.
set $dir = "C:/myproject" # <===================== Set your project directory here.
# Get the list of files in variable fileList.
var str fileList
find -rn files($files) dir($dir) > $fileList
# Declare variables where we will save counts of individual files.
var int c # all lines
var int nb # non-blank lines
# Declare variables where we will save total counts for all files.
var int totalc # sum-total of all lines
var int totalnb # sum-total of all non-blank lines
# Declare variable where we will store file count.
var int fileCount
# We will store the name of the file we are working on currently, in the following.
var str file
# Go thru the $fileList one by one file.
while ($fileList<>"")
do
# Extract the next file.
lex "1" $fileList >$file
# Check if this is a flat file. We are not interested in directories.
af $file >null # We don't want to see the output.
# We only want to set the $ftype variable.
if ($ftype=="f")
do
# Yes, this is a flat file.
done
endif
done
Show sum-totals
echo "**********************************************************************************************************************************"
echo "Total Count of all lines:\t" $totalc ",\tTotal Count of non-blank lines:\t" $totalnb ", Total files: " $fileCount
echo "**********************************************************************************************************************************"
# END OF SCRIPT
If you want line counts in files modified in year 2008 only, add ($fmtime >= "2008"), etc.
If you don't have biterscripting, get it from .com .
Not a simple script, but CCCC (C and C++ Code Counter) has been around for a while and it works great for me.