]> granicus.if.org Git - apache/blob - support/list_hooks.pl
6de9b41d12ec3600af9c438826b4097ef68ee51f
[apache] / support / list_hooks.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Carp;
6
7 my $path=shift || '.';
8
9 findInDir($path);
10
11 foreach my $hook (sort keys %::Hooks) {
12     my $h=$::Hooks{$hook};
13     for my $x (qw(declared implemented type args)) {
14         print "$hook datum '$x' missing\n" if !exists $h->{$x};
15     }
16     print "$hook\n";
17     print "  declared in $h->{declared}\n" if defined $h->{declared};
18     print "  implemented in $h->{implemented}\n" if defined $h->{implemented};
19     print "  type is $h->{type}\n" if defined $h->{type};
20     print "  $h->{ret} $hook($h->{args})\n" if defined $h->{args};
21     print "\n";
22 }
23
24 sub findInDir {
25     my $path=shift;
26
27     local(*D);
28     opendir(D,$path) || croak "Can't open $path: $!";
29     while(my $f=readdir D) {
30         next if $f=~/^\./;
31         my $file="$path/$f";
32
33         if(-d $file) {
34             findInDir($file);
35             next;
36         }
37         next if $file !~ /\.[ch]$/;
38
39         scanFile($file);
40     }
41     closedir D;
42 }
43
44 sub scanFile {
45     my $file=shift;
46
47 #    print "scanning $file\n";
48
49     open(F,$file) || croak "Can't open $file: $!";
50     while(<F>) {
51         next if /\#define/;
52         next if /\@deffunc/;
53         if(/AP_DECLARE_HOOK\((.*)\)/) {
54             my $def=$1;
55             my($ret,$name,$args)=$def=~/([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*\((.*)\)/;
56             croak "Don't understand $def in $file" if !defined $args;
57 #           print "found $ret $name($args) in $file\n";
58
59             croak "$name declared twice! ($_)"
60                 if exists $::Hooks{$name}->{declared};
61             $::Hooks{$name}->{declared}=$file;
62             $::Hooks{$name}->{ret}=$ret;
63             $::Hooks{$name}->{args}=$args;
64         } elsif(/AP_DECLARE_HOOK\(([^,]+),([^,]+)/) {
65 # really we should swallow subsequent lines to get the arguments...
66             my $name=$2;
67             my $ret=$1;
68             croak "$name declared twice! ($_)"
69                 if exists $::Hooks{$name}->{declared};
70             $::Hooks{$name}->{declared}=$file;
71             $::Hooks{$name}->{ret}=$ret;
72             $::Hooks{$name}->{args}='???';
73         }
74         if(/AP_IMPLEMENT_HOOK_()(VOID)\(([^,\s]+)/
75            || /AP_IMPLEMENT(_OPTIONAL|)_HOOK_(.*?)\([^,]+?\s*,\s*([^,\s]+)/) {
76             my($type,$name)=($1 ? "OPTIONAL $2" : $2,$3);
77
78 #           print "found $name $type in $file\n";
79
80             croak "$name implemented twice ($::Hooks{$name}->{implemented} and $file) ($_)"
81                 if exists $::Hooks{$name}->{implemented};
82             $::Hooks{$name}->{implemented}=$file;
83             $::Hooks{$name}->{type}=$type;
84         }
85     }
86 }