bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / support / list_hooks.pl
1 #!/usr/bin/perl -w
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements.  See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License.  You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 use strict;
19
20 use Carp;
21
22 my $path=shift || '.';
23
24 findInDir($path);
25
26 foreach my $hook (sort keys %::Hooks) {
27     my $h=$::Hooks{$hook};
28     for my $x (qw(declared implemented type args)) {
29         print "$hook datum '$x' missing\n" if !exists $h->{$x};
30     }
31     print "$hook\n";
32     print "  declared in $h->{declared}\n" if defined $h->{declared};
33     print "  implemented in $h->{implemented}\n" if defined $h->{implemented};
34     print "  type is $h->{type}\n" if defined $h->{type};
35     print "  $h->{ret} $hook($h->{args})\n" if defined $h->{args};
36     print "\n";
37 }
38
39 sub findInDir {
40     my $path=shift;
41
42     local(*D);
43     opendir(D,$path) || croak "Can't open $path: $!";
44     while(my $f=readdir D) {
45         next if $f=~/^\./;
46         my $file="$path/$f";
47
48         if(-d $file) {
49             findInDir($file);
50             next;
51         }
52         next if $file !~ /\.[ch]$/;
53
54         scanFile($file);
55     }
56     closedir D;
57 }
58
59 sub scanFile {
60     my $file=shift;
61
62 #    print "scanning $file\n";
63
64     open(F,$file) || croak "Can't open $file: $!";
65     while(<F>) {
66         next if /\#define/;
67         next if /\@deffunc/;
68         if(/AP_DECLARE_HOOK\((.*)\)/) {
69             my $def=$1;
70             my($ret,$name,$args)=$def=~/([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*\((.*)\)/;
71             croak "Don't understand $def in $file" if !defined $args;
72 #           print "found $ret $name($args) in $file\n";
73
74             croak "$name declared twice! ($_)"
75                 if exists $::Hooks{$name}->{declared};
76             $::Hooks{$name}->{declared}=$file;
77             $::Hooks{$name}->{ret}=$ret;
78             $::Hooks{$name}->{args}=$args;
79         } elsif(/AP_DECLARE_HOOK\((\s*[^,\s]+)\s*,\s*([^,\s]+)/) {
80 # really we should swallow subsequent lines to get the arguments...
81             my $name=$2;
82             my $ret=$1;
83             croak "$name declared twice! ($_)"
84                 if exists $::Hooks{$name}->{declared};
85             $::Hooks{$name}->{declared}=$file;
86             $::Hooks{$name}->{ret}=$ret;
87             $::Hooks{$name}->{args}='???';
88         }
89         if(/AP_IMPLEMENT_HOOK_()(VOID)\(([^,\s]+)/
90            || /AP_IMPLEMENT(_OPTIONAL|)_HOOK_(.*?)\([^,]+?\s*,\s*([^,\s]+)/) {
91             my($type,$name)=($1 ? "OPTIONAL $2" : $2,$3);
92
93 #           print "found $name $type in $file\n";
94
95             croak "$name implemented twice ($::Hooks{$name}->{implemented} and $file) ($_)"
96                 if exists $::Hooks{$name}->{implemented};
97             $::Hooks{$name}->{implemented}=$file;
98             $::Hooks{$name}->{type}=$type;
99         }
100     }
101 }