#!/usr/bin/perl use Getopt::Long; GetOptions('help' => \$opt{help}, 'tags' => \$opt{tags}, 'grep' => sub{ $style = 'grep' }, 'func' => sub{ $style = 'func' }); help() if($opt{help} == 1); if($opt{tags}){ open(TAGS,$opt{tags}); @tags = ; close(TAGS); }else{ @tags = <>; } if($style eq 'func'){ foreach(@tags){ chomp; my($file,$line,$func) = split(/ +/,$_); $index{$file} ||= {}; $index{$file}->{$line} = $func; } } foreach(@tags){ chomp; my($file,$line,$func) = split(/ +/,$_); print "\n" if($continue); print "$func($file:$line) called:\n"; open(GID,"gid $func |"); @result = ; close(GID); foreach(@result){ if($style eq 'grep'){ print " $_"; }elsif($style eq 'func'){ my($file,$line) = split(/:/,$_,3); my($result) = get_pos($file,$line); print " $file:$result\n" if($result); } } $continue = 1; } sub get_pos{ my($file,$line) = @_; my($prev); foreach(sort {$a <=> $b} keys %{$index{$file}}){ if($line > $_){ $prev = $index{$file}->{$_}; }elsif($line == $_){ return; }else{ return $prev; } } } sub help{ print "$0 [--help]\n"; print " --help : Show this message\n"; exit(0); }