diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-09-29 14:24:15 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-09-29 14:24:15 -0400 |
commit | ce4becaa4ec27b1046079a1198e7f20997005dbf (patch) | |
tree | 9a54a4621d0505c987d31d433c94c42a689c2311 | |
parent | ca0bc3f5d72b3d8e9e2c8c2b97b189e658667714 (diff) |
Add include file parsing and dependency graph scripts.
-rwxr-xr-x | util/incfind.pl | 25 | ||||
-rwxr-xr-x | util/incgraph.pl | 22 |
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"; |