<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Count your SLOC: Source Lines of Code</title>
	<atom:link href="http://stereointeractive.com/blog/2007/05/26/count-your-sloc-source-lines-of-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog/2007/05/26/count-your-sloc-source-lines-of-code/</link>
	<description>Development Blog</description>
	<lastBuildDate>Thu, 17 Jun 2010 09:37:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: P Mc</title>
		<link>http://stereointeractive.com/blog/2007/05/26/count-your-sloc-source-lines-of-code/comment-page-1/#comment-349</link>
		<dc:creator>P Mc</dc:creator>
		<pubDate>Sat, 13 Dec 2008 20:56:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stereodevelopment.com/2007/05/26/count-your-sloc-source-lines-of-code/#comment-349</guid>
		<description>The following script does a little better job. Try it. If you don&#039;t have biterScripting, download it from http://biterscripting.com/
&lt;pre lang=&quot;bash&quot;&gt;
#####################################################################
# SCRIPT: SS_CountLines
#
# This script counts the number of lines in files whose names match a given
# criterion in a given directory.
#
# The file name criterion is assigned using FVA (Forward Variable Assignment)
# for str variable $files. The value of $files is of form
#	&quot;*.html&quot;, &quot;*.js&quot;, &quot;*.cpp&quot;, &quot;*.h&quot;, etc.
#
# The directory name is assigned using FVA
# for str variable $dir. The value of $dir is of form
#	&quot;C:/ABC/DEF&quot;, &quot;.&quot;, etc.
#
# This script can be stored and edited as necessary, in a text file
# called SS_CounteLines.txt in a directory in your $path . The script can then be called as
#
#	script SS_CountLines.txt dir(&quot;C:/myproject&quot;) files(&quot;*.cpp&quot;)
# 
#####################################################################

# Declare FVA variables.
var str files
var str dir

# Get the list of files in variable fileList.
var str fileList
script SS_ListFiles.txt dir($dir) files($files) &gt; $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&quot;&quot;)
do
  # Extract the next file.
  lex &quot;1&quot; $fileList &gt;$file

  # Check if this is a flat file. We are not interested in directries.
  af $file &gt;null	# We don&#039;t want to see the output.
			# We only want to set the $ftype variable.
  if ($ftype==&quot;f&quot;)
  do
    # Yes, this is a flat file.

    # Increment file count.
    set $fileCount = $fileCount+1

    # Collect the content of $file in $content
    var str content	# Content of one file at a time
    repro $file &gt;$content

    # Get count and non-blank count.
    set $c={len -e $content}
    set $nb={len $content}

    # Update total counts.
    set $totalc = $totalc + $c
    set $totalnb = $totalnb + $nb

    done
  endif

  done

# Show sum-totals
echo &quot;**********************************************************************************************************************************&quot;
echo &quot;Total Count of all lines:\t&quot; $totalc &quot;,\tTotal Count of non-blank lines:\t&quot; $totalnb &quot;, Total files: &quot; $fileCount
echo &quot;**********************************************************************************************************************************&quot;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The following script does a little better job. Try it. If you don&#8217;t have biterScripting, download it from <a href="http://biterscripting.com/" rel="nofollow">http://biterscripting.com/</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span class="co0">#####################################################################</span>
<span class="co0"># SCRIPT: SS_CountLines</span>
<span class="co0">#</span>
<span class="co0"># This script counts the number of lines in files whose names match a given</span>
<span class="co0"># criterion in a given directory.</span>
<span class="co0">#</span>
<span class="co0"># The file name criterion is assigned using FVA (Forward Variable Assignment)</span>
<span class="co0"># for str variable $files. The value of $files is of form</span>
<span class="co0">#	&quot;*.html&quot;, &quot;*.js&quot;, &quot;*.cpp&quot;, &quot;*.h&quot;, etc.</span>
<span class="co0">#</span>
<span class="co0"># The directory name is assigned using FVA</span>
<span class="co0"># for str variable $dir. The value of $dir is of form</span>
<span class="co0">#	&quot;C:/ABC/DEF&quot;, &quot;.&quot;, etc.</span>
<span class="co0">#</span>
<span class="co0"># This script can be stored and edited as necessary, in a text file</span>
<span class="co0"># called SS_CounteLines.txt in a directory in your $path . The script can then be called as</span>
<span class="co0">#</span>
<span class="co0">#	script SS_CountLines.txt dir(&quot;C:/myproject&quot;) files(&quot;*.cpp&quot;)</span>
<span class="co0"># </span>
<span class="co0">#####################################################################</span>
&nbsp;
<span class="co0"># Declare FVA variables.</span>
var str files
var str <span class="kw2">dir</span>
&nbsp;
<span class="co0"># Get the list of files in variable fileList.</span>
var str fileList
script SS_ListFiles.txt <span class="kw2">dir</span><span class="br0">&#40;</span><span class="re1">$dir</span><span class="br0">&#41;</span> files<span class="br0">&#40;</span><span class="re1">$files</span><span class="br0">&#41;</span> <span class="sy0">&amp;</span>gt; <span class="re1">$fileList</span>
&nbsp;
<span class="co0"># Declare variables where we will save counts of individual files.</span>
var int c	<span class="co0"># all lines</span>
var int nb	<span class="co0"># non-blank lines</span>
&nbsp;
<span class="co0"># Declare variables where we will save total counts for all files.</span>
var int totalc	<span class="co0"># sum-total of all lines</span>
var int totalnb	<span class="co0"># sum-total of all non-blank lines</span>
&nbsp;
<span class="co0"># Declare variable where we will store file count.</span>
var int fileCount
&nbsp;
<span class="co0"># We will store the name of the file we are working on currently, in the following.</span>
var str <span class="kw2">file</span>
&nbsp;
<span class="co0"># Go thru the $fileList one by one file.</span>
<span class="kw1">while</span> <span class="br0">&#40;</span><span class="re1">$fileList</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="kw1">do</span>
  <span class="co0"># Extract the next file.</span>
  <span class="kw2">lex</span> <span class="st0">&quot;1&quot;</span> <span class="re1">$fileList</span> <span class="sy0">&amp;</span>gt;<span class="re1">$file</span>
&nbsp;
  <span class="co0"># Check if this is a flat file. We are not interested in directries.</span>
  af <span class="re1">$file</span> <span class="sy0">&amp;</span>gt;null	<span class="co0"># We don't want to see the output.</span>
			<span class="co0"># We only want to set the $ftype variable.</span>
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$ftype</span>==<span class="st0">&quot;f&quot;</span><span class="br0">&#41;</span>
  <span class="kw1">do</span>
    <span class="co0"># Yes, this is a flat file.</span>
&nbsp;
    <span class="co0"># Increment file count.</span>
    <span class="kw1">set</span> <span class="re1">$fileCount</span> = <span class="re1">$fileCount</span>+<span class="nu0">1</span>
&nbsp;
    <span class="co0"># Collect the content of $file in $content</span>
    var str content	<span class="co0"># Content of one file at a time</span>
    repro <span class="re1">$file</span> <span class="sy0">&amp;</span>gt;<span class="re1">$content</span>
&nbsp;
    <span class="co0"># Get count and non-blank count.</span>
    <span class="kw1">set</span> <span class="re1">$c</span>=<span class="br0">&#123;</span>len <span class="re5">-e</span> <span class="re1">$content</span><span class="br0">&#125;</span>
    <span class="kw1">set</span> <span class="re1">$nb</span>=<span class="br0">&#123;</span>len <span class="re1">$content</span><span class="br0">&#125;</span>
&nbsp;
    <span class="co0"># Update total counts.</span>
    <span class="kw1">set</span> <span class="re1">$totalc</span> = <span class="re1">$totalc</span> + <span class="re1">$c</span>
    <span class="kw1">set</span> <span class="re1">$totalnb</span> = <span class="re1">$totalnb</span> + <span class="re1">$nb</span>
&nbsp;
    <span class="kw1">done</span>
  endif
&nbsp;
  <span class="kw1">done</span>
&nbsp;
<span class="co0"># Show sum-totals</span>
<span class="kw3">echo</span> <span class="st0">&quot;**********************************************************************************************************************************&quot;</span>
<span class="kw3">echo</span> <span class="st0">&quot;Total Count of all lines:<span class="es1">\t</span>&quot;</span> <span class="re1">$totalc</span> <span class="st0">&quot;,<span class="es1">\t</span>Total Count of non-blank lines:<span class="es1">\t</span>&quot;</span> <span class="re1">$totalnb</span> <span class="st0">&quot;, Total files: &quot;</span> <span class="re1">$fileCount</span>
<span class="kw3">echo</span> <span class="st0">&quot;**********************************************************************************************************************************&quot;</span></pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>
