Scripts to extract documentation
authorDavid Schleef <ds@schleef.org>
Tue, 18 Sep 2001 22:51:01 +0000 (22:51 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 18 Sep 2001 22:51:01 +0000 (22:51 +0000)
scripts/call_trace [new file with mode: 0755]
scripts/doc_devlist [new file with mode: 0755]
scripts/dump_doc [new file with mode: 0755]

diff --git a/scripts/call_trace b/scripts/call_trace
new file mode 100755 (executable)
index 0000000..8e2971d
--- /dev/null
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+# vi: set ts=4:
+
+
+$ARGV=shift @ARGV;
+@output=`objdump -dr $ARGV`;
+
+$obj=$ARGV;
+
+$state=0;
+while($_=shift @output){
+       chomp;
+       if(m/^\w+\.o:\s+file format.*/){
+               $obj = $_;
+               $obj =~ s/^(\w+\.o):\s+file format.*/\1/
+       }
+       if(m/^0[0-9a-fA-F]+\s<\w+>:$/){
+               $func = $_;
+               $func =~ s/^0[0-9a-fA-F]+\s<(\w+)>:$/\1/;
+
+               $addr = $_;
+               $addr =~ s/^(0[0-9a-fA-F]+)\s<\w+>:$/\1/;
+
+               if(@cfuncs){
+                       @cfuncs = sort @cfuncs;
+                       @last="";
+                       foreach $f (@cfuncs) {
+                               if($f ne $last){
+                                       if($f ne "::_GLOBAL_OFFSET_TABLE_"){
+                                               print " $f\n";
+                                       }
+                               }
+                               $last=$f;
+                       }
+               }
+               @cfuncs=();
+               print "${obj}::$func:\n";
+
+               $state=0;
+       }
+       if(m/\scall\s/){
+               if(m/\scall\s.*<.*>/){
+                       $cfunc = $_;
+                       $cfunc =~ s/.*\scall\s.*<(.*)>$/\1/;
+       
+                       if($cfunc =~ m/$func\+0x/){
+                               # wait for a reloc
+                               $state=1;
+                       }else{
+                               push @cfuncs, "${obj}::$cfunc";
+                               $state=0;
+                       }
+               }else{
+                       if($state==2){
+                               push @cfuncs, "#$cfunc";
+                       }else{
+                               push @cfuncs, "#";
+                       }
+                       $state=0;
+               }
+       }
+       if(m/^\s+[0-9a-fA-F]+:\s\w+\s+\w+$/){
+               $cfunc = $_;
+               $cfunc =~ s/.*\s(\w+)$/\1/;
+               if($state==0){
+                       # it just showed up.  We might attach it to the next line.
+                       $state=2;
+               }elsif($state==1){
+                       # we're waiting for a reloc
+                       push @cfuncs, "::$cfunc";
+                       $state=0;
+               }
+       }
+}
+
diff --git a/scripts/doc_devlist b/scripts/doc_devlist
new file mode 100755 (executable)
index 0000000..6fd4459
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/perl -w
+# vi: set ts=4:
+
+sub parse_devices;
+
+@ARGV = ('-') unless @ARGV;
+
+$ARGV=shift @ARGV;
+if(!open(FILE,$ARGV)){
+       warn "Can't open $ARGV: $!\n";
+       exit 1;
+}
+
+while(<FILE>){
+       push @lines,$_;
+}
+
+$driver = "";
+while($_=shift @lines){
+       if( m/^[\w-]+: / ){
+               if($l){
+                       #print "$l\n";
+                       if($l =~ m/^Driver: /){
+                               $_ = $l;
+                               s/^Driver: //;
+                               $driver = $_;
+                       }
+               }
+               chomp;
+               $l=$_;
+       }elsif( m/^ / ){
+               s/^ +//;
+               chomp;
+               $l="$l $_";
+       }else{
+               if($l){
+                       #print "$l\n";
+                       if($l =~ m/^Driver: /){
+                               $_ = $l;
+                               s/^Driver: //;
+                               $driver = $_;
+                       }
+                       if($l =~ m/^Devices: /){
+                               $_ = $l;
+                               s/^Devices: //;
+                               parse_devices($_);
+                       }
+                       $l="";
+               }
+       }
+}
+
+
+sub parse_devices
+{
+       my $devs = $_[0];
+       my $mfr = "unknown";
+       my $dev = "unknown";
+       my $name = "unknown";
+
+       #print("parse_devices $devs\n");
+
+       while($devs){
+               $_=$devs;
+               if(m/^ *\[([^\]]+)\](.*)/){
+                       $mfr = $1;
+                       #print "recognized mfr $mfr\n";
+                       $devs = $2;
+               }elsif(m/^ *\(([^\)]+)\)(.*)/){
+                       $name = $1;
+                       #print "recognized name $name\n";
+                       $devs = $2;
+               }elsif(m/^ *([^\(,]+)(.*)/){
+                       $dev = $1;
+                       $devs = $2;
+                       $dev =~ s/ *$//;
+                       #print "recognized dev $dev\n";
+               }elsif(m/^ *,(.*)/){
+                       $devs = $1;
+                       printf "%-28s %-17s %-17s %-10s\n", $mfr, $dev, $driver, $name;
+               }else{
+                       print "parse error $_\n";
+                       $devs = "";
+               }
+       }
+       printf "%-28s %-17s %-17s %-10s\n", $mfr, $dev, $driver, $name;
+}
+
+
diff --git a/scripts/dump_doc b/scripts/dump_doc
new file mode 100755 (executable)
index 0000000..f790a90
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+# vi: set ts=4:
+
+@ARGV = ('-') unless @ARGV;
+
+$ARGV=shift @ARGV;
+if(!open(FILE,$ARGV)){
+       warn "Can't open $ARGV: $!\n";
+       exit 1;
+}
+
+$go=0;
+while(<FILE>) {
+       if( m/^Driver: / ){
+               $go=1;
+       }
+       if( m/\*\// ){
+               if($go){
+                       print "\n\n\n";
+               }
+               $go=0;
+       }
+       if( $go ){
+               #chomp;
+               print $_;
+       }
+}
+