This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Anton Berezin says that on FreeBSD we're wrong to be using -lc_r, and
[perl5.git] / emacs / ptags
... / ...
CommitLineData
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#
6# usage: sh emacs/ptags <options>
7#
8# options:
9#
10# fullpath - use full paths in TAGS (default: relative to the root)
11#
12# (IZ: to be a happier jumper: install 'imenu-go.el' from
13# ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.)
14#
15# (Some tags should probably live in their own subdirs, like those in x2p/,
16# but I have never been interested in x2p anyway.)
17#
18# Hallvard B Furuseth <h.b.furuseth@usit.uio.no>, Aug -96.
19#
20# Ilya Zakharevich, Oct 97: minor comments, add CPerl scan;
21# Use Hallvard's scan for XS files - since he processes the "C" part too -
22# but with a lot of improvements: now it is no worse than CPerl's one.
23
24# Avoid builtin on OS/2:
25if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi
26
27case "$1" in
28 fullpath)
29 cwd=`pwd`
30 cperl_add_tags='cperl-add-tags-recurse-noxs-fullpath'
31 echo "Building TAGS with full paths"
32 ;;
33 *)
34 cperl_add_tags='cperl-add-tags-recurse-noxs'
35 cwd='.'
36 echo "Building TAGS with relative paths"
37esac
38
39emacs=`(which emacs || which xemacs) 2>/dev/null`
40[ -x "$emacs" ] || { echo "can't find emacs or xemacs in PATH"; exit 1; }
41
42# Insure proper order (.h after .c, .xs before .c in subdirs):
43# Move autogenerated less-informative files to the end:
44# Hard to do embed.h and embedvar.h in one sweep:
45
46topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ / /g' | sed 's/ embedvar\.h\|embed\.h\|perlapi\.h\|os2ish\.h\|\(globals\|perlapi\| os2\)\.c / /g'| sed "s#\(^\| \)\([^ ]\)#\1$cwd/\2#g"`"
47subdirs="`find $cwd/* -maxdepth 0 -type d`"
48subdirfiles="`find $subdirs -name '*.[cy]' -print | sort`"
49subdirfiles1="`find $subdirs -name '*.[hH]' -print | sort`"
50xsfiles="`find $cwd/ -name '*.xs' -print | sort`"
51
52# etags -d : process defines too (default now)
53
54# These are example lines for global variables and PP-code:
55## IEXT SV * Iparsehook;
56## IEXT char * Isplitstr IINIT(" ");
57## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
58## PP(pp_const)
59## PERLVARI(Grsfp, PerlIO *, Nullfp)
60## PERLVAR(cvcache, HV *)
61
62# Putting PL_\1 in the substitution line makes etags dump core
63# Thus we do it later (but 20.2.92 does it OK).
64set x -d -l c \
65 -r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \
66 -r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/' \
67 -r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*[\[,]/\1/' \
68 -r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/'
69
70shift
71
72rm -f TAGS.tmp TAGS.tm2
73
74# Process lines like this: #define MEM_ALIGNBYTES $alignbytes /**/
75etags -o TAGS.tmp \
76 -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
77 $cwd/config_h.SH
78# Process lines like this: Mcc (Loc.U):
79etags -o TAGS.tmp -a \
80 -l none -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\$\1/' \
81 -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' $cwd/Porting/Glossary
82
83etags -o TAGS.tmp -a "$@" $topfiles
84
85# Now add these PL_:
86perl -w014pe 'if (s/^( .* PERLVAR A?I? # 1: TAG group
87 \s* \( \s* [GIT] #
88 .* #
89 \x7F # End of description
90 )
91 ( .* \x01 ) # 2: Exact group
92 /${1}PL_$2/mgx) { # Add PL_
93 $chars = chomp;
94 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
95 $_ .= ("\f" x $chars);
96 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
97
98
99# Now remove these Perl_, add empty- and perl_-flavors:
100perl -w014pe 'if (s/^(Perl_ # 1: First group
101 (\w+) \( # 2: Stripped name
102 \x7F # End of description
103 ) # End of description
104 (\d+,\d+\n) # 3: TAGS Trail
105 /$1$3$1$2\x01$3$1perl_$2\x01$3/mgx) { # Repeat, add empty and perl_ flavors
106 $chars = chomp;
107 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
108 $_ .= ("\f" x $chars);
109 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
110
111# Now remove these S_, add empty-flavor:
112perl -w014pe 'if (s/^(S_ # 1: First group
113 (\w+) \( # 2: Stripped name
114 \x7F # End of description
115 ) # End of description
116 (\d+,\d+\n) # 3: TAGS Trail
117 /$1$3$1$2\x01$3/mgx) { # Repeat, add empty_ flavor
118 $chars = chomp;
119 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
120 $_ .= ("\f" x $chars);
121 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
122
123etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' $cwd/embed.h
124etags -o TAGS.tmp -a $cwd/globals.c $cwd/embedvar.h $cwd/perlapi.c $cwd/perlapi.h
125
126# The above processes created a lot of descriptions with an
127# an explicitly specified tag. Such descriptions have higher
128# precedence than descriptions without an explicitely specified tag.
129# To restore the justice, make all the descriptions explicit.
130perl -w014pe 'if (s/^( [^\n\x7F\x01]*\b # 1: TAG group
131 (\w+) # 2: word
132 [^\w\x7F\x01\n]* # Most anything
133 \x7F # End of description
134 )
135 (\d+,\d+\n) # 3: TAGS Trail
136 /$1$2\x01$3/mgx) { # Add specific marking
137 $chars = chomp;
138 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
139 $_ .= ("\f" x $chars);
140 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
141
142# Add MODULE lines to TAG files (to be postprocessed later),
143# and BOOT: lines (in DynaLoader processed twice?)
144
145# This skips too many XSUBs:
146
147# etags -o TAGS.tmp -a -d -l c \
148# -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
149# -r '/[ \t]*BOOT:/' \
150# $xsfiles
151
152etags -o TAGS.tmp -a -d -l c \
153 -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
154 -r '/[ \t]*BOOT:/' \
155 -r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \
156 $xsfiles
157
158# -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \
159# -r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/' \
160# $xsfiles
161
162etags -o TAGS.tmp -a "$@" $subdirfiles
163etags -o TAGS.tmp -a "$@" $subdirfiles1
164
165if test ! -f emacs/cperl-mode.elc ; then
166 ( cd emacs; $emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
167fi
168
169# This should work with newer Emaxen
170
171cp TAGS.tmp TAGS
172if $emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f $cperl_add_tags ; then
173 mv TAGS TAGS.tmp
174fi
175
176perl -w014pe '
177 $update = s/^PP\(\177\d+,\d+\n//gm;
178 $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm;
179 if (/^\n*[^\s,]+\.xs,/s) {
180 $mod = $cmod = $bmod = $pref = "";
181 s/^(.*\n)\1+/$1/mg; # Remove duplicate lines
182 $_ = join("", map {
183 if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) {
184 $mod = $+;
185 ($bmod = $mod) =~ tr/:/_/;
186 $cmod = "XS_${bmod}_";
187 $pref = "";
188 if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) {
189 $pref = $1;
190 $pref =~ s/([^\w\s])/\\$1/g;
191 $pref = "(?:$pref)?";
192 }
193 } elsif ($mod ne "") {
194 # Ref points for Module::subr, XS_Module_subr, subr
195 s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm;
196 # Ref for Module::bootstrap bootstrap boot_Module
197 s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm;
198 }
199 $_;
200 } split(/(\nMODULE[ \t]*=[^\n\177]+\177)/));
201
202 $update = 1;
203 }
204 if ($update) {
205 $chars = chomp;
206 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
207 $_ .= ("\f" x $chars);
208 }' TAGS.tmp > TAGS.tm2
209
210rm -f TAGS
211mv TAGS.tm2 TAGS
212rm -f TAGS.tmp
213
214
215