[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / glafp-utils / scripts / perltags.prl
1 # perl tags, in perl.
2 # @(#)ptags 1.2 4/11/91, no copyright.  Bugfixes to lm@eng.sun.com.
3
4 #In the hack-of-the-hour catagory, a tags file generator for perl.  Differences
5 #from ctags:
6 #
7 #       1) Puts a tag in for the filename
8 #       2) Puts in multiple tags for the same symbol (I have a hacked version
9 #          of vi that groks this).
10
11 # tag   file    <vi expresion to find it>
12 # catch /u/lm/tmp/eintr.c       /^catch() {}$/
13
14 if ($#ARGV == -1) {
15         unshift(@ARGV, "-");
16 }
17 open(STDOUT, ">> TAGS") || die "can't create TAGS";     # partain: NB: APPEND
18 while ($_ = shift) {
19         next unless -f $_;
20         print STDERR "$_\n" if $v;
21         do file($_);
22 }
23 exit;
24
25 sub file
26 {
27         local($name) = $_[0];
28
29         open(F, $name) || return;
30         $entries = '';
31         $lcnt = 1;
32         $ccnt = 0;
33
34         while (<F>) {
35                 # skip the word sub in comments
36                 next unless /^[^#]*\bsub\b/;
37                 # skip the word sub in a string (one line only, I'm lazy)
38                 next if /"[^"]*sub/;
39 #               print "$name: $. $_" if $d;
40                 # demand that "sub" is first on the line (partain)
41                 # (the initial > is for some literate perl scripts...)
42                 next if ! /^>?\s*sub\s+/;
43                 chop;
44                 # rm comments
45                 s/#.*$//;
46                 # and here's the entry...
47                 $entries .= "$_\x7f$lcnt,$ccnt\n";
48                 $lcnt++;
49                 $ccnt += length($_);
50         }
51         # print tag for filename
52         print "\f\n$name,",length($entries),"\n";
53         print $entries;
54 }
55
56 ###I've always used this.  Don't recall whom I got it from...
57 ##
58 ##--tom
59 ##
60 ###!/usr/local/bin/perl
61 #open(OUTPUT, "| sort >> TAGS");
62 #while (<>) {
63 #    if (/\bsub\s+(\w+')?(\S+)/) {
64 #       $func = $2;
65 #       chop;
66 #       s,[\\\[\]/.*],\\$&,g;
67 #       print OUTPUT "$func\t", $ARGV, "\t/^$_\$/\n";
68 #    }
69 #}