<?xml version="1.0" encoding="windows-1252"?>
<node id="25478" title="list_call" created="2000-08-01 15:29:06" updated="2005-08-11 10:35:53">
<type id="1748">
sourcecode</type>
<author id="3131">
mikfire</author>
<data>
<field name="doctext">
&lt;code&gt;
#!/usr/bin/perl -w
use strict;
#------------
# This code is provided as is.  There is no implied warrenty
# and it may do anything from nothing to causing the end
# of the world as we know it.  I take no responsibilty for
# and such cause.
#
# It is under the Artistic license, but if you use it and
# fix it, I sure would appreciate the patch.
#
# Mik Firestone, Aug 1 2000
#
# mik@speed.stdio.com
#-------------

die "$0 &lt;source&gt; &lt;target&gt; ..." unless @ARGV &gt; 1;
my %keyword = ();

my ( $source, @targets ) = @ARGV;

my $package = '';
#---
# Try to extract the keywords, precompile the regex and store
#---
open SRC, $source or die "Couldn't open $source : $!";
while( &lt;SRC&gt; ) {
    $package = $1 if ( ! $package &amp;&amp; /^package\s+(.+);/ );
    next unless ( /^sub\s+(.+){\s*$/ );

    my $name;
    $name = $1;
    next if ( substr($name,0,1) eq "_" );

    $name =~ s/\s+$//;
    $keyword{$name} = qr/([\w:{}]+)-&gt;$name/;
}
close SRC;

for my $file ( @targets ) {
    my ( $line );

    open FILE, $file or die "Couldn't open $file : $!";

    LINE:
        while( $line = &lt;FILE&gt; ) {
            next LINE if ( $line =~ /^\s*#/ || $line =~ /^\s*$/ );
            last LINE if $line =~ /__END__/;


            for ( keys %keyword ) {
                my $regex = $keyword{$_};
                if ( $line =~ /$regex/ ) {
                    my $starts_at = $.;
                    my $lpack = $1 || '';

                    next LINE if ( $file eq $source ) &amp;&amp; ( $line =~ /^sub/ );
                    next LINE if ( $line =~ /Usage/ );
                    next LINE if ( $lpack =~ /::/ &amp;&amp; $lpack ne $package );

                    while( $line !~ /;/ &amp;&amp; ! eof(FILE) ) {
                        $line .= &lt;FILE&gt;;
                        next LINE if $line =~ /^EOF/m;
                    }
                    $line =~ s/^\s*//;
                    printf "%s (%d) %s", uc $file, $starts_at, $line;
                    next LINE;
                }
            }
        }
    #LINE
    close FILE;
}
&lt;/code&gt;</field>
<field name="codedescription">
A down and dirty little script that reads a file, looking
for subroutine definitions.  It extracts these and then 
parses through a whole bunch of other files looking
for calls to those functions.  It isn't perfect, but
it works pretty well.
&lt;p&gt;
&lt;code&gt;
Usage:
list_call source file [ ...]
&lt;/code&gt;
where source is the file from which to extract the calls
and file is the file to be searched.</field>
<field name="codecategory">
text processing</field>
<field name="codeauthor">
Mik Firestone
mik@speed.stdio.com
This code is provided as is.  If it causes
the end of the world as we know it, 
it is not</field>
</data>
</node>
