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.)
5 # (IZ: to be a happier jumper: install 'imenu-go.el' from
6 # ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.)
8 # (Some tags should probably live in their own subdirs, like those in x2p/,
9 # but I have never been interested in x2p anyway.)
11 # Hallvard B Furuseth <h.b.furuseth@usit.uio.no>, Aug -96.
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.
17 # Avoid builtin on OS/2:
18 if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi
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:
24 topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ / /g' | sed 's/ embedvar\.h\|embed\.h\|obj\(pp\|XSUB\)\.h\|\(globals\|perlapi\)\.c / /g'`"
25 subdirs="`find ./* -maxdepth 0 -type d`"
26 subdirfiles="`find $subdirs -name '*.[cy]' -print | sort`"
27 subdirfiles1="`find $subdirs -name '*.[hH]' -print | sort`"
28 xsfiles="`find . -name '*.xs' -print | sort`"
30 # etags -d : process defines too (default now)
32 # These are example lines for global variables and PP-code:
33 ## IEXT SV * Iparsehook;
34 ## IEXT char * Isplitstr IINIT(" ");
35 ## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
37 ## PERLVARI(Grsfp, PerlIO *, Nullfp)
38 ## PERLVAR(cvcache, HV *)
40 # Putting PL_\1 in the substitution line makes etags dump core
41 # Thus we do it later (but 20.2.92 does it OK).
43 -r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \
44 -r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/' \
45 -r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*[\[,]/\1/' \
46 -r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/'
50 rm -f TAGS.tmp TAGS.tm2
52 # Process lines like this: #define MEM_ALIGNBYTES $alignbytes /**/
54 -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
56 # Process lines like this: Mcc (Loc.U):
57 etags -o TAGS.tmp -a \
58 -l none -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\$\1/' \
59 -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' Porting/Glossary
61 etags -o TAGS.tmp -a "$@" $topfiles
64 perl -w014pe 'if (s/^( .* PERLVAR A?I? # 1: TAG group
67 \x7F # End of description
69 ( .* \x01 ) # 2: Exact group
70 /${1}PL_$2/mgx) { # Add PL_
72 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
73 $_ .= ("\f" x $chars);
74 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
77 # Now remove these Perl_, add empty- and perl_-flavors:
78 perl -w014pe 'if (s/^(Perl_ # 1: First group
79 (\w+) \( # 2: Stripped name
80 \x7F # End of description
81 ) # End of description
82 (\d+,\d+\n) # 3: TAGS Trail
83 /$1$3$1$2\x01$3$1perl_$2\x01$3/mgx) { # Repeat, add empty and perl_ flavors
85 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
86 $_ .= ("\f" x $chars);
87 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
89 # Now remove these S_, add empty-flavor:
90 perl -w014pe 'if (s/^(S_ # 1: First group
91 (\w+) \( # 2: Stripped name
92 \x7F # End of description
93 ) # End of description
94 (\d+,\d+\n) # 3: TAGS Trail
95 /$1$3$1$2\x01$3/mgx) { # Repeat, add empty_ flavor
97 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
98 $_ .= ("\f" x $chars);
99 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
101 etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' embed.h
102 etags -o TAGS.tmp -a globals.c embedvar.h objXSUB.h perlapi.c
104 # The above processes created a lot of descriptions with an
105 # an explicitly specified tag. Such descriptions have higher
106 # precedence than descriptions without an explicitely specified tag.
107 # To restore the justice, make all the descriptions explicit.
108 perl -w014pe 'if (s/^( [^\n\x7F\x01]*\b # 1: TAG group
110 [^\w\x7F\x01\n]* # Most anything
111 \x7F # End of description
113 (\d+,\d+\n) # 3: TAGS Trail
114 /$1$2\x01$3/mgx) { # Add specific marking
116 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
117 $_ .= ("\f" x $chars);
118 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
120 # Add MODULE lines to TAG files (to be postprocessed later),
121 # and BOOT: lines (in DynaLoader processed twice?)
123 # This skips too many XSUBs:
125 # etags -o TAGS.tmp -a -d -l c \
126 # -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
127 # -r '/[ \t]*BOOT:/' \
130 etags -o TAGS.tmp -a -d -l c \
131 -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
133 -r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \
136 # -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \
137 # -r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/' \
140 etags -o TAGS.tmp -a "$@" $subdirfiles
141 etags -o TAGS.tmp -a "$@" $subdirfiles1
143 if test ! -f emacs/cperl-mode.elc ; then
144 ( cd emacs; emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
147 # This should work with newer Emaxen
150 if emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f cperl-add-tags-recurse-noxs ; then
155 $update = s/^PP\(\177\d+,\d+\n//gm;
156 $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm;
157 if (/^\n*[^\s,]+\.xs,/s) {
158 $mod = $cmod = $bmod = $pref = "";
159 s/^(.*\n)\1+/$1/mg; # Remove duplicate lines
161 if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) {
163 ($bmod = $mod) =~ tr/:/_/;
164 $cmod = "XS_${bmod}_";
166 if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) {
168 $pref =~ s/([^\w\s])/\\$1/g;
169 $pref = "(?:$pref)?";
171 } elsif ($mod ne "") {
172 # Ref points for Module::subr, XS_Module_subr, subr
173 s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm;
174 # Ref for Module::bootstrap bootstrap boot_Module
175 s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm;
178 } split(/(\nMODULE[ \t]*=[^\n\177]+\177)/));
184 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
185 $_ .= ("\f" x $chars);
186 }' TAGS.tmp > TAGS.tm2