Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!exodus!appserv!slovax.Eng.Sun.COM!lm From: lm@slovax.Eng.Sun.COM (Larry McVoy) Newsgroups: comp.lang.perl Subject: ptags - perl tags in perl Message-ID: <543@appserv.Eng.Sun.COM> Date: 11 Apr 91 07:14:34 GMT Sender: news@appserv.Eng.Sun.COM Reply-To: lm@sun.UUCP (Larry McVoy) Organization: Sun Microsystems, Mountain View Lines: 62 In the hack-of-the-hour catagory, a tags file generator for perl. Differences from ctags: 1) Puts a tag in for the filename 2) Puts in multiple tags for the same symbol (I have a hacked version of vi that groks this). #!/bin/perl -s # perl tags, in perl. # @(#)ptags 1.2 4/11/91, no copyright. Bugfixes to lm@eng.sun.com. # tag file # catch /u/lm/tmp/eintr.c /^catch() {}$/ if ($#ARGV == -1) { unshift(@ARGV, "-"); } open(STDOUT, "|sort>tags") || die "can't create tags"; while ($_ = shift) { next unless -f $_; print STDERR "$_\n" if $v; do file($_); } exit; sub file { local($name) = $_[0]; local($basename) = $_[0]; open(F, $name) || return; if ($name =~ /\//o) { $basename =~ s|.*/([^/]+)$|\1|o; } # put tag in for filename print "$basename\t$name\t1\n"; while () { # skip the word sub in comments next unless /^[^#]*\bsub\b/; # skip the word sub in a string (one line only, I'm lazy) next if /"[^"]*sub/; print "$name: $. $_" if $d; # Find the name of the sub, it should be right after "sub". split; $subname = ""; for ($f = 0; $f <= $#_; $f++) { if ($_[$f] eq "sub") { $subname = $_[$f + 1]; last; } } if ($subname eq "") { print STDERR "No name: $name: $. $_\n"; } else { chop; print "$subname\t$name\t/^$_\$/\n"; } } } --- Larry McVoy, Sun Microsystems (415) 336-7627 ...!sun!lm or lm@sun.com