forked from cheshirekow/openbookfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countlines.pl
executable file
·62 lines (48 loc) · 1.3 KB
/
countlines.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
my @extensions = ("cpp","h","hpp");
my @directories = ("src");
my @filelist;
foreach $directory( @directories )
{
print "searching $directory\n";
foreach $extension( @extensions )
{
print " for *.$extension\n";
open INLIST, " find $directory -name '*.$extension' |";
while(<INLIST>)
{
chomp;
push(@filelist, $_);
}
close INLIST;
}
}
$totallines = 0;
$written = 0;
$noncomment = 0;
my $blockcomment = 0;
my $comment = 0;
print "parsing files\n";
foreach $file( @filelist )
{
print " $file\n";
open INFILE, "./" . $file or die "failed to open" . $file . "\n";
while(<INFILE>)
{
chomp;
s/\s//g;
$totallines++;
$comment = 0;
if( /^(\/\/)/ ) {$comment = 1; }
if( /(\/\*)/ ) {$blockcomment = 1; }
if( /(\*\/)/ ) {$blockcomment = 0; }
$noncomment++ unless( length($_) == 0 || $comment || $blockcomment );
$written++ unless( length($_) == 0 );
}
close INFILE;
}
print "\n";
print "total: " . $totallines . "\n";
print "written: " . $written . "\n";
print "noncomment: " . $noncomment . "\n";
$dummy = <>;