Debian Codegraph @

utils/codestats

raw
1 #!/usr/bin/env perl
2
3 use warnings qw(all);
4 use strict;
5 use autodie;
6
7 my @cfiles = @ARGV;
8 my $fns = {};
9
10 sub funname($$) {
11 my ($cf, $fn) = @_;
12
13 return undef if ($fn =~ /^#/);
14 return undef if ($fn =~ /^\//);
15 return $cf . '/' . $1 if ($fn =~ /^static \S.*?([A-Za-z0-9_]+)\(.*\)(\s*{)?$/);
16 return $1 if ($fn =~ /^\S.*?([A-Za-z0-9_]+)\(.*\)(\s*{)?$/);
17 return undef;
18 }
19
20 for my $cfile (@cfiles) {
21 open(my $fh, '<', $cfile);
22 my @lines = <$fh>;
23 close($fh);
24 my $curfn = undef;
25 my $lineno = 0;
26 foreach my $line (@lines) {
27 $lineno++;
28 my $fn = funname($cfile, $line);
29 if (not defined $curfn and defined $fn) {
30 if (exists $fns->{$fn}) {
31 printf("redef %s %s:%d %s:%d\n", $fn,
32 $fns->{$fn}->{file},
33 $fns->{$fn}->{start},
34 $cfile, $lineno);
35 next;
36 }
37 $curfn = $fn;
38 $fns->{$curfn} = {
39 file => $cfile,
40 start => $lineno,
41 };
42 } elsif (defined $curfn and $line =~ /^}/) {
43 $fns->{$curfn}->{end} = $lineno;
44 $curfn = undef;
45 }
46 }
47 }
48
49 for my $fn (keys %$fns) {
50 $fns->{$fn}->{len} = $fns->{$fn}->{end} - $fns->{$fn}->{start};
51 printf("%d %d %s\n", $fns->{$fn}->{len}, $fns->{$fn}->{start}, $fn);
52 }