c6726122374ef627b396dca299f73ea03e6d43ea
[p5sagit/p5-mst-13.2.git] / emacs / ptags
1 # Make a TAGS file for emacs ``M-x find-tag'' from all <c,h,y,xs> source files.
2 # (``make realclean'' first to avoid generated files, or ``make'' first
3 # to get tags from all files.)
4 #
5 # (IZ: to be a happier jumper: install 'imenu-go.el' from
6 #      ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.)
7 #
8 # (Some tags should probably live in their own subdirs, like those in x2p/,
9 # but I have never been interested in x2p anyway.)
10 #
11 # Hallvard B Furuseth <h.b.furuseth@usit.uio.no>, Aug -96.
12 #
13 # Ilya Zakharevich, Oct 97: minor comments, add CPerl scan;
14 #   Use Hallvard's scan for XS files - since he processes the "C" part too -
15 #   but with a lot of improvements: now it is no worse than CPerl's one.
16
17 # Avoid builtin on OS/2:
18 if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi
19
20 # Insure proper order (.h after .c, .xs before .c in subdirs):
21 # Move autogenerated less-informative files to the end:
22 # Hard to do embed.h and embedvar.h in one sweep:
23
24 topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ \(embed\(var\|\)\.h\|obj\(pp\|XSUB\)\.h\|globals\.c\) \(\(embedvar\|objpp\).h \|\)/ /g'`"
25 subdirfiles="`( find ./*/* -name '*.[cy]' -print | sort ; find ./*/* -name '*.[hH]' -print | sort )`"
26 xsfiles="`find . -name '*.xs' -print | sort`"
27
28 # etags -d : process defines too (default now)
29
30 # These are example lines for global variables and PP-code:
31 ## IEXT SV *       Iparsehook;
32 ## IEXT char *     Isplitstr IINIT(" ");
33 ## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
34 ## PP(pp_const)
35 ## PERLVARI(Grsfp, PerlIO *, Nullfp)
36 ## PERLVAR(cvcache,      HV *)
37
38 # Putting PL_\1 in the substitution line makes etags dump core
39 # Thus we do it later (but 20.2.92 does it OK).
40 set x   -d -l c \
41         -r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \
42         -r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/'  \
43         -r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*[\[,]/\1/'  \
44         -r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/'
45
46 shift
47
48 rm -f TAGS.tmp TAGS.tm2
49
50 # Process lines like this: #define MEM_ALIGNBYTES $alignbytes      /**/
51 etags -o TAGS.tmp \
52         -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
53         config_h.SH
54 etags -o TAGS.tmp -a "$@" $topfiles
55
56 # Now add these PL_:
57 perl -w014pe 'if (s/^( .* PERLVAR I?    # 1:   TAG group
58                        \s* \( \s* [GIT] #
59                        .*               #
60                      \x7F               #      End of description
61                      ) 
62                      ( .* \x1 )         # 2:   Exact group
63                    /${1}PL_$2/mgx) {    # Add PL_
64                   $chars = chomp;
65                   s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
66                   $_ .= ("\f" x $chars);
67               }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
68
69
70
71 etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' embed.h
72 etags -o TAGS.tmp -a globals.c embedvar.h objXSUB.h objpp.h
73
74 perl -w014pe 'if (s/^( [^\n\x7F\x1]*\b  # 1:   TAG group
75                        (\w+)            #   2: word
76                        [^\w\x7X\x1\n]*  #      Most anything
77                        \x7F             #      End of description
78                      )
79                      (\d+,\d+\n)        # 3:   TAGS Trail
80                    /$1$2\x1$3/mgx) {    # Add specific marking
81                   $chars = chomp;
82                   s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
83                   $_ .= ("\f" x $chars);
84               }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
85
86 # Add MODULE lines to TAG files (to be postprocessed later),
87 #   and BOOT: lines (in DynaLoader processed twice?)
88
89 # This skips too many XSUBs:
90
91 # etags -o TAGS.tmp -a -d -l c \
92 #       -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
93 #       -r '/[ \t]*BOOT:/' \
94 #       $xsfiles
95
96 etags -o TAGS.tmp -a -d -l c \
97         -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
98         -r '/[ \t]*BOOT:/' \
99         -r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \
100         $xsfiles
101
102 #       -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \
103 #       -r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/'        \
104 #       $xsfiles
105
106 etags -o TAGS.tmp -a "$@" $subdirfiles
107
108 if test ! -f emacs/cperl-mode.elc ; then
109     ( cd emacs; emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
110 fi
111
112 # This should work with newer Emaxen
113
114 cp TAGS.tmp TAGS
115 if emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f cperl-add-tags-recurse-noxs ; then
116     mv TAGS TAGS.tmp
117 fi
118
119 perl -w014pe '
120     $update  = s/^PP\(\177\d+,\d+\n//gm;
121     $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm;
122     if (/^\n*[^\s,]+\.xs,/s) {
123         $mod = $cmod = $bmod = $pref = "";
124         s/^(.*\n)\1+/$1/mg;                     # Remove duplicate lines
125         $_ = join("", map {
126             if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) {
127                 $mod = $+;
128                 ($bmod = $mod) =~ tr/:/_/;
129                 $cmod = "XS_${bmod}_";
130                 $pref = "";
131                 if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) {
132                     $pref = $1;
133                     $pref =~ s/([^\w\s])/\\$1/g;
134                     $pref = "(?:$pref)?";
135                 }
136             } elsif ($mod ne "") {
137                 # Ref points for Module::subr, XS_Module_subr, subr
138                 s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm;
139                 # Ref for Module::bootstrap bootstrap boot_Module
140                 s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm;
141             }
142             $_;
143         } split(/(\nMODULE[ \t]*=[^\n\177]+\177)/));
144
145         $update = 1;
146     }
147     if ($update) {
148         $chars = chomp;
149         s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
150         $_ .= ("\f" x $chars);
151     }' TAGS.tmp > TAGS.tm2
152
153 rm -f TAGS
154 mv TAGS.tm2 TAGS
155 rm -f TAGS.tmp
156
157
158