list_hooks.pl revision a267a4bcefedcaa9fdf7cb26aa603525ec4853c3
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder#!/usr/bin/perl -w
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederuse strict;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederuse Carp;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maedermy $path=shift || '.';
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian MaederfindInDir($path);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maederforeach my $hook (sort keys %::Hooks) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $h=$::Hooks{$hook};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder for my $x (qw(declared implemented type args)) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder print "$hook datum '$x' missing\n" if !exists $h->{$x};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder print "$hook\n";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder print " declared in $h->{declared}\n" if defined $h->{declared};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder print " implemented in $h->{implemented}\n" if defined $h->{implemented};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder print " type is $h->{type}\n" if defined $h->{type};
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder print " $h->{ret} $hook($h->{args})\n" if defined $h->{args};
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian Maeder print "\n";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder}
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maedersub findInDir {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $path=shift;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder local(*D);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder opendir(D,$path) || croak "Can't open $path: $!";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder while(my $f=readdir D) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder next if $f=~/^\./;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $file="$path/$f";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if(-d $file) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder findInDir($file);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder next;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder next if $file !~ /\.[ch]$/;
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder scanFile($file);
ac4396c9f44a76c5c97925954ee49b4a91d8dd88Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder closedir D;
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder}
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maedersub scanFile {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $file=shift;
a38f3d84e592184830fa308c5dab3f7c71e4464fChristian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder# print "scanning $file\n";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder open(F,$file) || croak "Can't open $file: $!";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder while(<F>) {
329c739bc05b8ce8d54f81071d0826ff771d1f78Christian Maeder next if /\#define/;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder next if /\@deffunc/;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if(/AP_DECLARE_HOOK\((.*)\)/) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $def=$1;
4bbd808612c2580ae6e0495a155997a6bb47ecf3Christian Maeder my($ret,$name,$args)=$def=~/([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*\((.*)\)/;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder croak "Don't understand $def in $file" if !defined $args;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder# print "found $ret $name($args) in $file\n";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder croak "$name declared twice! ($_)"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if exists $::Hooks{$name}->{declared};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder $::Hooks{$name}->{declared}=$file;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder $::Hooks{$name}->{ret}=$ret;
c04cc42aa672aa49b45005e6eed77cc80e0d6ae0Christian Maeder $::Hooks{$name}->{args}=$args;
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder } elsif(/AP_DECLARE_HOOK\((\s*[^,\s]+)\s*,\s*([^,\s]+)/) {
d6c6b2543c509ec7f6213e4cba675d96304a7fd6Christian Maeder# really we should swallow subsequent lines to get the arguments...
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $name=$2;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my $ret=$1;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder croak "$name declared twice! ($_)"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if exists $::Hooks{$name}->{declared};
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder $::Hooks{$name}->{declared}=$file;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder $::Hooks{$name}->{ret}=$ret;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder $::Hooks{$name}->{args}='???';
d9be582b00d420e2fe0737fcb07c9aa3d235a774Christian Maeder }
19defe35cc864caeb98dd4ea1d429b1f989ecdffChristian Maeder if(/AP_IMPLEMENT_HOOK_()(VOID)\(([^,\s]+)/
7857a35e3af533dfbd0f0e18638ebd211e6358a0Christian Maeder || /AP_IMPLEMENT(_OPTIONAL|)_HOOK_(.*?)\([^,]+?\s*,\s*([^,\s]+)/) {
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder my($type,$name)=($1 ? "OPTIONAL $2" : $2,$3);
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder# print "found $name $type in $file\n";
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder croak "$name implemented twice ($::Hooks{$name}->{implemented} and $file) ($_)"
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder if exists $::Hooks{$name}->{implemented};
19defe35cc864caeb98dd4ea1d429b1f989ecdffChristian Maeder $::Hooks{$name}->{implemented}=$file;
19defe35cc864caeb98dd4ea1d429b1f989ecdffChristian Maeder $::Hooks{$name}->{type}=$type;
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder }
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder}
bff4b3f816be4c1e1d8ded76f1d5af786839e1a9Christian Maeder