summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamon Walsh <ewalsh@tycho.nsa.gov>2011-09-29 14:24:15 -0400
committerEamon Walsh <ewalsh@tycho.nsa.gov>2011-09-29 14:24:15 -0400
commitce4becaa4ec27b1046079a1198e7f20997005dbf (patch)
tree9a54a4621d0505c987d31d433c94c42a689c2311
parentca0bc3f5d72b3d8e9e2c8c2b97b189e658667714 (diff)
Add include file parsing and dependency graph scripts.
-rwxr-xr-xutil/incfind.pl25
-rwxr-xr-xutil/incgraph.pl22
2 files changed, 47 insertions, 0 deletions
diff --git a/util/incfind.pl b/util/incfind.pl
new file mode 100755
index 0000000..85bf1f5
--- /dev/null
+++ b/util/incfind.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+die "Usage: $0 <searchterm>\n" if @ARGV != 1;
+my $searchstr = shift @ARGV;
+
+chdir "/usr/include" or die "Failed to change directory: $!\n";
+
+my $cmd = "grep -RIlw $searchstr . | sort | uniq";
+
+open(FH, '-|', $cmd) or die "Failed to pipe command: $!\n";
+my @lines = <FH>;
+close(FH);
+
+if (@lines == 1) {
+ $cmd = "vim +/$searchstr $lines[0]";
+}
+else {
+ $cmd = "grep -RIHnw $searchstr . | less";
+}
+
+exec($cmd);
+die "Failed to exec command: $!\n";
diff --git a/util/incgraph.pl b/util/incgraph.pl
new file mode 100755
index 0000000..6530678
--- /dev/null
+++ b/util/incgraph.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+my @files = glob("*.[ch]");
+
+print "digraph G {\n";
+
+foreach my $file (@files) {
+ open FH, '<', $file or die "Failed to open '$file': $!\n";
+
+ while (<FH>) {
+ if (/^#include "(.*?)"/) {
+ print "\"$file\" -> \"$1\"\n";
+ }
+ }
+
+ close FH;
+}
+
+print "}\n";